mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 09:18:31 +00:00
Apply some touchups
This commit is contained in:
parent
9f149e1de3
commit
2f3bd90216
139 changed files with 1188 additions and 1154 deletions
|
@ -1,7 +1,14 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/sysinfo.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/tms.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/calls/typedef/sighandler_t.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/pflink.h"
|
||||
|
@ -54,17 +61,6 @@ COSMOPOLITAN_C_START_
|
|||
│ cosmopolitan § system calls ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
struct dirstream;
|
||||
struct iovec;
|
||||
struct rlimit;
|
||||
struct rusage;
|
||||
struct sigaction;
|
||||
struct sigset;
|
||||
struct stat;
|
||||
struct sysinfo;
|
||||
struct tms;
|
||||
struct utsname;
|
||||
|
||||
typedef int sig_atomic_t;
|
||||
typedef struct dirstream DIR;
|
||||
|
||||
|
@ -196,12 +192,12 @@ int wait(int *);
|
|||
int wait3(int *, int, struct rusage *);
|
||||
int wait4(int, int *, int, struct rusage *);
|
||||
int waitpid(int, int *, int);
|
||||
int64_t lseek(int, int64_t, int);
|
||||
int64_t pread(int, void *, size_t, int64_t);
|
||||
int64_t preadv(int, struct iovec *, int, int64_t);
|
||||
int64_t pwrite(int, const void *, size_t, int64_t);
|
||||
int64_t pwritev(int, const struct iovec *, int, int64_t);
|
||||
int64_t syscall();
|
||||
ssize_t lseek(int, int64_t, unsigned);
|
||||
ssize_t pread(int, void *, size_t, int64_t);
|
||||
ssize_t preadv(int, struct iovec *, int, int64_t);
|
||||
ssize_t pwrite(int, const void *, size_t, int64_t);
|
||||
ssize_t pwritev(int, const struct iovec *, int, int64_t);
|
||||
intptr_t syscall(int, ...);
|
||||
void sync(void);
|
||||
long telldir(DIR *);
|
||||
int getpid(void);
|
||||
|
|
|
@ -17,7 +17,6 @@ LIBC_CALLS = $(LIBC_CALLS_A_DEPS) $(LIBC_CALLS_A)
|
|||
LIBC_CALLS_A = o/$(MODE)/libc/calls/syscalls.a
|
||||
LIBC_CALLS_A_FILES := \
|
||||
$(wildcard libc/calls/typedef/*) \
|
||||
$(wildcard libc/calls/thunks/*) \
|
||||
$(wildcard libc/calls/struct/*) \
|
||||
$(wildcard libc/calls/*)
|
||||
LIBC_CALLS_A_HDRS = $(filter %.h,$(LIBC_CALLS_A_FILES))
|
||||
|
|
|
@ -44,6 +44,5 @@
|
|||
* @see fchmod()
|
||||
*/
|
||||
int chmod(const char *pathname, uint32_t mode) {
|
||||
if (!pathname) return efault();
|
||||
return sys_fchmodat(AT_FDCWD, pathname, mode, 0);
|
||||
}
|
||||
|
|
|
@ -16,22 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/mach.h"
|
||||
#include "libc/nt/struct/filetime.h"
|
||||
#include "libc/nt/struct/systemtime.h"
|
||||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
/**
|
||||
* Returns nanosecond time.
|
||||
|
@ -43,40 +33,34 @@
|
|||
* @param clockid can be CLOCK_REALTIME, CLOCK_MONOTONIC, etc. noting
|
||||
* that on Linux CLOCK_MONOTONIC is redefined to use the monotonic
|
||||
* clock that's actually monotonic lool
|
||||
* @param out_ts is where the nanoseconds are stored if non-NULL
|
||||
* @return 0 on success or -1 w/ errno on error
|
||||
* @param ts is where the result is stored
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
* @error ENOSYS if clockid isn't available; in which case this function
|
||||
* guarantees an ordinary timestamp is still stored to out_ts; and
|
||||
* guarantees an ordinary timestamp is still stored to ts; and
|
||||
* errno isn't restored to its original value, to detect prec. loss
|
||||
* @see strftime(), gettimeofday()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
int clock_gettime(int clockid, struct timespec *out_ts) {
|
||||
/* TODO(jart): Just ignore O/S for MONOTONIC and measure RDTSC on start */
|
||||
int clock_gettime(int clockid, struct timespec *ts) {
|
||||
int rc;
|
||||
axdx_t ad;
|
||||
struct NtFileTime ft;
|
||||
if (!ts) return efault();
|
||||
if (!IsWindows()) {
|
||||
if (!IsXnu()) {
|
||||
if (out_ts) {
|
||||
out_ts->tv_sec = 0;
|
||||
out_ts->tv_nsec = 0;
|
||||
if ((rc = sys_clock_gettime(clockid, ts)) == -1 && errno == ENOSYS) {
|
||||
ad = sys_gettimeofday((struct timeval *)ts, NULL, NULL);
|
||||
assert(ad.ax != -1);
|
||||
if (SupportsXnu() && ad.ax) {
|
||||
ts->tv_sec = ad.ax;
|
||||
ts->tv_nsec = ad.dx;
|
||||
}
|
||||
return sys_clock_gettime(clockid, out_ts);
|
||||
} else {
|
||||
int rc;
|
||||
_Static_assert(sizeof(struct timeval) == sizeof(struct timespec));
|
||||
if (out_ts) {
|
||||
out_ts->tv_sec = 0;
|
||||
out_ts->tv_nsec = 0;
|
||||
}
|
||||
rc = sys_gettimeofday((struct timeval *)out_ts, NULL);
|
||||
if (out_ts) {
|
||||
out_ts->tv_nsec *= 1000;
|
||||
}
|
||||
return rc;
|
||||
ts->tv_nsec *= 1000;
|
||||
rc = 0;
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
struct NtFileTime ft;
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
*out_ts = FileTimeToTimeSpec(ft);
|
||||
*ts = FileTimeToTimeSpec(ft);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
|
||||
size_t i;
|
||||
char **shargs;
|
||||
if (__sys_execve(prog, argv, envp) != -1) return 0;
|
||||
__sys_execve(prog, argv, envp);
|
||||
if (errno != ENOEXEC) return -1;
|
||||
for (i = 0; argv[i];) ++i;
|
||||
shargs = alloca((i + 2) * sizeof(char *));
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int faccessat(int dirfd, const char *path, int mode, uint32_t flags) {
|
||||
if (!path) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_faccessat(dirfd, path, mode, flags);
|
||||
} else {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*/
|
||||
int ftruncate(int fd, int64_t length) {
|
||||
if (!IsWindows()) {
|
||||
return sys_ftruncate(fd, length);
|
||||
return sys_ftruncate(fd, length, length);
|
||||
} else {
|
||||
return sys_ftruncate_nt(fd, length);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows char *sys_getcwd_nt(char *buf, size_t size) {
|
||||
uint16_t name16[PATH_MAX];
|
||||
char16_t name16[PATH_MAX];
|
||||
if (GetCurrentDirectory(ARRAYLEN(name16), name16)) {
|
||||
tprecode16to8(buf, size, name16);
|
||||
return buf;
|
||||
|
|
|
@ -24,9 +24,8 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
#define NETBSD_F_GETPATH 15
|
||||
#define XNU_F_GETPATH 50
|
||||
#define XNU_MAXPATHLEN 1024
|
||||
#define XNU_F_GETPATH 50
|
||||
#define XNU_MAXPATHLEN 1024
|
||||
|
||||
char *sys_getcwd_xnu(char *res, size_t size) {
|
||||
int fd;
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
/**
|
||||
* Returns value of environment variable, or NULL if not found.
|
||||
*
|
||||
* Environment variables can store empty string on Unix but not Windows.
|
||||
*/
|
||||
char *getenv(const char *s) {
|
||||
char **p;
|
||||
|
@ -29,7 +31,7 @@ char *getenv(const char *s) {
|
|||
for (j = 0;; ++j) {
|
||||
if (!s[j]) {
|
||||
if (p[i][j] == '=') {
|
||||
return &p[i][j + 1];
|
||||
return p[i] + j + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -16,26 +16,27 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/ Makes fork() kernel ABI consistent across UNIX systems.
|
||||
/
|
||||
/ @return 0 if parent, pid if child, or -1 on error
|
||||
sys_fork:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
call __sys_fork
|
||||
#if SupportsXnu()
|
||||
testb IsXnu()
|
||||
jz 1f
|
||||
cmp $-1,%rax
|
||||
je 1f
|
||||
neg %edx # edx is 0 for parent and 1 for child
|
||||
not %edx # eax always returned with childs pid
|
||||
and %edx,%eax
|
||||
#endif
|
||||
1: pop %rbp
|
||||
ret
|
||||
.endfn sys_fork,globl,hidden
|
||||
#define CTL_KERN 1
|
||||
#define KERN_HOSTNAME 10
|
||||
|
||||
int gethostname_bsd(char *name, size_t len) {
|
||||
char *p;
|
||||
int cmd[2];
|
||||
char buf[254];
|
||||
size_t buflen;
|
||||
cmd[0] = CTL_KERN;
|
||||
cmd[1] = KERN_HOSTNAME;
|
||||
buflen = sizeof(buf);
|
||||
if (sysctl(cmd, 2, buf, &buflen, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM) errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
strncpy(name, buf, len);
|
||||
name[len - 1] = '\0';
|
||||
if ((p = strchr(name, '.'))) *p = '\0';
|
||||
return 0;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -16,11 +16,16 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/ Directly calls pread() impl on host o/s if available.
|
||||
sys_pread:
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pread
|
||||
.endfn sys_pread,globl,hidden
|
||||
int gethostname_linux(char *name, size_t len) {
|
||||
struct utsname u;
|
||||
if (uname(&u) == -1) return -1;
|
||||
memccpy(name, u.nodename, '\0', len);
|
||||
name[len - 1] = '\0';
|
||||
return 0;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -16,22 +16,20 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/enum/computernameformat.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/ Directly calls lseek() impl on host o/s if available.
|
||||
sys_lseek:
|
||||
#if SupportsOpenbsd() || SupportsNetbsd()
|
||||
testb $OPENBSD|NETBSD,__hostos(%rip)
|
||||
cmovnz %rdx,%rcx # openbsd:evilpad
|
||||
cmovnz %rsi,%rdx
|
||||
cmovnz .Lzero(%rip),%rsi
|
||||
#endif
|
||||
jmp __sys_lseek
|
||||
.endfn sys_lseek,globl,hidden
|
||||
|
||||
.rodata.cst8
|
||||
.Lzero: .quad 0
|
||||
.endobj .Lzero
|
||||
.previous
|
||||
textwindows int gethostname_nt(char *name, size_t len) {
|
||||
uint32_t nSize;
|
||||
char16_t name16[256];
|
||||
nSize = ARRAYLEN(name16);
|
||||
if (GetComputerNameEx(kNtComputerNameDnsHostname, name16, &nSize)) {
|
||||
tprecode16to8(name, len, name16);
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
|
@ -18,20 +18,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nt/enum/computernameformat.h"
|
||||
#include "libc/nt/errors.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
#define CTL_KERN 1
|
||||
#define KERN_HOSTNAME 10
|
||||
|
||||
/**
|
||||
* Returns name of host system, e.g.
|
||||
*
|
||||
|
@ -42,38 +31,12 @@ int gethostname(char *name, size_t len) {
|
|||
if (len < 1) return einval();
|
||||
if (!name) return efault();
|
||||
if (!IsWindows()) {
|
||||
if (IsBsd()) {
|
||||
char *p;
|
||||
int cmd[2];
|
||||
char buf[254];
|
||||
size_t buflen;
|
||||
cmd[0] = CTL_KERN;
|
||||
cmd[1] = KERN_HOSTNAME;
|
||||
buflen = sizeof(buf);
|
||||
if (sysctl(cmd, 2, buf, &buflen, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM) errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
strncpy(name, buf, len);
|
||||
name[len - 1] = '\0';
|
||||
if ((p = strchr(name, '.'))) *p = '\0';
|
||||
return 0;
|
||||
if (!IsBsd()) {
|
||||
return gethostname_linux(name, len);
|
||||
} else {
|
||||
struct utsname u;
|
||||
if (uname(&u) == -1) return -1;
|
||||
memccpy(name, u.nodename, '\0', len);
|
||||
name[len - 1] = '\0';
|
||||
return 0;
|
||||
return gethostname_bsd(name, len);
|
||||
}
|
||||
} else {
|
||||
uint32_t nSize;
|
||||
char16_t name16[256];
|
||||
nSize = ARRAYLEN(name16);
|
||||
if (GetComputerNameEx(kNtComputerNameDnsHostname, name16, &nSize)) {
|
||||
tprecode16to8(name, len, name16);
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
return gethostname_nt(name, len);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,15 @@
|
|||
#include "libc/nt/thread.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/rusage.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows int sys_getrusage_nt(int who, struct rusage *usage) {
|
||||
struct NtFileTime CreationFileTime;
|
||||
struct NtFileTime ExitFileTime;
|
||||
struct NtFileTime KernelFileTime;
|
||||
struct NtFileTime UserFileTime;
|
||||
if (!usage) return efault();
|
||||
if (who == 99) return enosys(); /* @see libc/sysv/consts.sh */
|
||||
memset(usage, 0, sizeof(*usage));
|
||||
if ((who == RUSAGE_SELF ? GetProcessTimes : GetThreadTimes)(
|
||||
(who == RUSAGE_SELF ? GetCurrentProcess : GetCurrentThread)(),
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
* @return 0 on success, or -1 w/ errno
|
||||
*/
|
||||
int getrusage(int who, struct rusage *usage) {
|
||||
if (who == 99) return enosys(); /* @see libc/sysv/consts.sh */
|
||||
if (!usage) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_getrusage(who, usage);
|
||||
} else {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
/ Calls GetTempPathA() w/ different API.
|
||||
/
|
||||
/ @see GetSystemDirectoryA(), GetWindowsDirectoryA()
|
||||
GetTempPathA$flunk:
|
||||
GetTempPathA_flunk:
|
||||
xchg %rcx,%rdx
|
||||
jmp *__imp_GetTempPathA(%rip)
|
||||
.endfn GetTempPathA$flunk,globl,hidden
|
||||
.endfn GetTempPathA_flunk,globl,hidden
|
|
@ -1,53 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Returns system wall time in microseconds.
|
||||
/
|
||||
/ @param rdi points to timeval that receives result
|
||||
/ @param rsi receives UTC timezone if non-NULL
|
||||
/ @return always zero
|
||||
/ @see clock_gettime() for nanosecond precision
|
||||
/ @see strftime() for string formatting
|
||||
sys_gettimeofday:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
test %rsi,%rsi
|
||||
jz 1f
|
||||
push $0
|
||||
pop (%rsi)
|
||||
1: xor %esi,%esi # no one zones this way.
|
||||
xor %edx,%edx # i64*mach_absolute_time
|
||||
call __sys_gettimeofday
|
||||
#if SupportsXnu()
|
||||
testb IsXnu() # XNU might do %rax:%rdx
|
||||
jz 1f
|
||||
test %rdi,%rdi
|
||||
jz 1f
|
||||
test %rax,%rax
|
||||
jz 1f
|
||||
mov %rax,(%rdi)
|
||||
mov %rdx,8(%rdi)
|
||||
#endif
|
||||
1: xor %eax,%eax # nevar fail
|
||||
pop %rbp
|
||||
ret
|
||||
.endfn sys_gettimeofday,globl,hidden
|
|
@ -16,9 +16,11 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/struct/timezone.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
|
@ -32,8 +34,15 @@
|
|||
* @see strftime() for string formatting
|
||||
*/
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz) {
|
||||
axdx_t ad;
|
||||
if (!IsWindows()) {
|
||||
return sys_gettimeofday(tv, tz);
|
||||
ad = sys_gettimeofday(tv, tz, NULL);
|
||||
assert(ad.ax != -1);
|
||||
if (SupportsXnu() && ad.ax && tv) {
|
||||
tv->tv_sec = ad.ax;
|
||||
tv->tv_usec = ad.dx;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return sys_gettimeofday_nt(tv, tz);
|
||||
}
|
||||
|
|
|
@ -100,6 +100,10 @@ forceinline size_t clampio(size_t size) {
|
|||
│ cosmopolitan § syscalls » system five » synthetic jump slots ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
axdx_t __sys_pipe(i32[hasatleast 2], i32) hidden;
|
||||
axdx_t sys_fork(void) hidden;
|
||||
axdx_t sys_getpid(void) hidden;
|
||||
axdx_t sys_gettimeofday(struct timeval *, struct timezone *, void *) hidden;
|
||||
char *sys_getcwd(char *, u64) hidden;
|
||||
char *sys_getcwd_xnu(char *, u64) hidden;
|
||||
i32 __sys_dup3(i32, i32, i32) hidden;
|
||||
|
@ -127,11 +131,10 @@ i32 sys_fchownat(i32, const char *, u32, u32, u32) hidden;
|
|||
i32 sys_fcntl(i32, i32, ...) hidden;
|
||||
i32 sys_fdatasync(i32) hidden;
|
||||
i32 sys_flock(i32, i32) hidden;
|
||||
i32 sys_fork(void) hidden;
|
||||
i32 sys_fstat(i32, struct stat *) hidden;
|
||||
i32 sys_fstatat(i32, const char *, struct stat *, i32) hidden;
|
||||
i32 sys_fsync(i32) hidden;
|
||||
i32 sys_ftruncate(i32, i64) hidden;
|
||||
i32 sys_ftruncate(i32, i64, i64) hidden;
|
||||
i32 sys_futimes(i32, const struct timeval *) hidden;
|
||||
i32 sys_futimesat(i32, const char *, const struct timeval *) hidden;
|
||||
i32 sys_getitimer(i32, struct itimerval *) hidden;
|
||||
|
@ -139,11 +142,10 @@ i32 sys_getppid(void) hidden;
|
|||
i32 sys_getpriority(i32, u32) hidden;
|
||||
i32 sys_getrlimit(i32, struct rlimit *) hidden;
|
||||
i32 sys_getrusage(i32, struct rusage *) hidden;
|
||||
i32 sys_gettimeofday(struct timeval *, struct timezone *) hidden;
|
||||
i32 sys_ioctl(i32, u64, void *) hidden;
|
||||
i32 sys_kill(i32, i32, i32) hidden;
|
||||
i32 sys_linkat(i32, const char *, i32, const char *, i32) hidden;
|
||||
i32 sys_lseek(i32, i64, i32) hidden;
|
||||
i32 sys_lseek(i32, i64, i64, i64) hidden;
|
||||
i32 sys_lutimes(const char *, const struct timeval *) hidden;
|
||||
i32 sys_madvise(void *, size_t, i32) hidden;
|
||||
i32 sys_memfd_create(const char *, u32) hidden;
|
||||
|
@ -176,7 +178,7 @@ i32 sys_symlinkat(const char *, i32, const char *) hidden;
|
|||
i32 sys_sync(void) hidden;
|
||||
i32 sys_sync_file_range(i32, i64, i64, u32) hidden;
|
||||
i32 sys_sysinfo(struct sysinfo *) hidden;
|
||||
i32 sys_truncate(const char *, u64) hidden;
|
||||
i32 sys_truncate(const char *, u64, u64) hidden;
|
||||
i32 sys_uname(char *) hidden;
|
||||
i32 sys_unlinkat(i32, const char *, i32) hidden;
|
||||
i32 sys_utime(const char *, const struct utimbuf *) hidden;
|
||||
|
@ -185,22 +187,21 @@ i32 sys_utimes(const char *, const struct timeval *) hidden;
|
|||
i32 sys_wait4(i32, i32 *, i32, struct rusage *) hidden;
|
||||
i64 sys_copy_file_range(i32, long *, i32, long *, u64, u32) hidden;
|
||||
i64 sys_getrandom(void *, u64, u32) hidden;
|
||||
i64 sys_pread(i32, void *, u64, i64) hidden;
|
||||
i64 sys_preadv(i32, struct iovec *, i32, i64) hidden;
|
||||
i64 sys_pread(i32, void *, u64, i64, i64) hidden;
|
||||
i64 sys_preadv(i32, struct iovec *, i32, i64, i64) hidden;
|
||||
i64 sys_ptrace(int, i32, void *, void *) hidden;
|
||||
i64 sys_pwrite(i32, const void *, u64, i64) hidden;
|
||||
i64 sys_pwritev(i32, const struct iovec *, i32, i64) hidden;
|
||||
i64 sys_pwrite(i32, const void *, u64, i64, i64) hidden;
|
||||
i64 sys_pwritev(i32, const struct iovec *, i32, i64, i64) hidden;
|
||||
i64 sys_read(i32, void *, u64) hidden;
|
||||
i64 sys_sendfile(i32, i32, i64 *, u64) hidden;
|
||||
i64 sys_splice(i32, i64 *, i32, i64 *, u64, u32) hidden;
|
||||
i64 sys_vmsplice(i32, const struct iovec *, i64, u32) hidden;
|
||||
i64 sys_write(i32, const void *, u64) hidden;
|
||||
u32 sys_getgid(void) hidden;
|
||||
axdx_t sys_getpid(void) hidden;
|
||||
u32 sys_getsid(int) hidden;
|
||||
u32 sys_gettid(void) hidden;
|
||||
u32 sys_getuid(void) hidden;
|
||||
void *sys_mmap(void *, u64, u32, u32, i64, i64) hidden;
|
||||
void *sys_mmap(void *, u64, u32, u32, i64, i64, i64) hidden;
|
||||
void *sys_mremap(void *, u64, u64, i32, void *) hidden;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
|
@ -219,6 +220,9 @@ void __stat2linux(void *) hidden;
|
|||
void __restore_rt_netbsd(void) hidden;
|
||||
void __xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *,
|
||||
const struct __darwin_ucontext *) hidden wontreturn;
|
||||
int gethostname_linux(char *, size_t) hidden;
|
||||
int gethostname_bsd(char *, size_t) hidden;
|
||||
int gethostname_nt(char *, size_t) hidden;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § syscalls » windows nt » veneers ─╬─│┼
|
||||
|
|
|
@ -27,7 +27,7 @@ static int ioctl_tcgets_sysv(int fd, struct termios *tio) {
|
|||
int rc;
|
||||
union metatermios t;
|
||||
if ((rc = sys_ioctl(fd, TCGETS, &t)) != -1) {
|
||||
termios2linux(tio, &t);
|
||||
__termios2linux(tio, &t);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,14 @@
|
|||
#include "libc/calls/termios.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
int ioctl_tcsets_nt(int, uint64_t, const struct termios *);
|
||||
|
||||
static int ioctl_tcsets_sysv(int fd, uint64_t request,
|
||||
const struct termios *tio) {
|
||||
union metatermios t;
|
||||
return sys_ioctl(fd, request, termios2host(&t, tio));
|
||||
return sys_ioctl(fd, request, __termios2host(&t, tio));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,6 +39,7 @@ static int ioctl_tcsets_sysv(int fd, uint64_t request,
|
|||
* @see ioctl(fd, TIOCGETA{,W,F}, tio) dispatches here
|
||||
*/
|
||||
int ioctl_tcsets(int fd, uint64_t request, const struct termios *tio) {
|
||||
if (!tio) return efault();
|
||||
if (!IsWindows()) {
|
||||
return ioctl_tcsets_sysv(fd, request, tio);
|
||||
} else {
|
||||
|
|
|
@ -35,7 +35,7 @@ kTmpPath:
|
|||
movl $'/|'t<<010|'m<<020|'p<<030,(%rdi)
|
||||
movw $'/,4(%rdi)
|
||||
pushpop kTmpPathMax,%rdx
|
||||
ezlea GetTempPathA$flunk,ax
|
||||
ezlea GetTempPathA_flunk,ax
|
||||
call __getntsyspath
|
||||
.init.end 300,_init_kTmpPath
|
||||
.source __FILE__
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Creates hard filesystem link.
|
||||
|
@ -32,7 +32,6 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int link(const char *existingpath, const char *newpath) {
|
||||
if (!existingpath || !newpath) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_linkat(AT_FDCWD, existingpath, AT_FDCWD, newpath, 0);
|
||||
} else {
|
||||
|
|
|
@ -29,9 +29,11 @@
|
|||
* @return new position relative to beginning, or -1 on error
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
int64_t lseek(int fd, int64_t offset, int whence) {
|
||||
if (!IsWindows()) {
|
||||
return sys_lseek(fd, offset, whence);
|
||||
int64_t lseek(int fd, int64_t offset, unsigned whence) {
|
||||
if (!IsWindows() && !IsOpenbsd() && !IsNetbsd()) {
|
||||
return sys_lseek(fd, offset, whence, 0);
|
||||
} else if (IsOpenbsd() || IsNetbsd()) {
|
||||
return sys_lseek(fd, offset, offset, whence);
|
||||
} else {
|
||||
return sys_lseek_nt(fd, offset, whence);
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ textwindows int __mkntpath2(const char *path,
|
|||
* 5. Reserve ≥13 for mkdir() i.e. 1+8+3+1, e.g. "\\ffffffff.xxx\0"
|
||||
*/
|
||||
size_t i, n;
|
||||
if (!path) return efault();
|
||||
path = FixNtMagicPath(path, flags);
|
||||
n = tprecode8to16(path16, PATH_MAX - 16, path).ax;
|
||||
if (n == PATH_MAX - 16 - 1) return enametoolong();
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
*/
|
||||
int nanosleep(const struct timespec *req, struct timespec *rem) {
|
||||
if (!req) return efault();
|
||||
if (!IsWindows()) {
|
||||
if (!IsMetal()) {
|
||||
if (!IsXnu()) {
|
||||
return sys_nanosleep(req, rem);
|
||||
} else {
|
||||
return sys_nanosleep_xnu(req, rem);
|
||||
}
|
||||
} else {
|
||||
return enosys(); /* TODO: Sleep on Metal */
|
||||
}
|
||||
if (!IsWindows() && !IsMetal() && !IsXnu()) {
|
||||
return sys_nanosleep(req, rem);
|
||||
} else if (IsXnu()) {
|
||||
return sys_nanosleep_xnu(req, rem);
|
||||
} else if (IsMetal()) {
|
||||
return enosys(); /* TODO: Sleep on Metal */
|
||||
} else {
|
||||
return sys_nanosleep_nt(req, rem);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,14 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.windows
|
||||
.source __FILE__
|
||||
|
||||
__onntconsoleevent_nt:
|
||||
ezlea __onntconsoleevent,ax
|
||||
jmp __nt2sysv
|
||||
.endfn __onntconsoleevent_nt,globl,hidden
|
||||
|
||||
.init.start 300,_init_onntconsoleevent
|
||||
ezlea __onntconsoleevent_nt,cx
|
||||
pushpop 1,%rdx
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
nodiscard int openat(int dirfd, const char *file, int flags, ...) {
|
||||
int openat(int dirfd, const char *file, int flags, ...) {
|
||||
va_list va;
|
||||
unsigned mode;
|
||||
struct ZiposUri zipname;
|
||||
|
|
|
@ -78,9 +78,13 @@ textwindows int sys_pipe_nt(int pipefd[2], unsigned flags) {
|
|||
pipefd[1] = writer;
|
||||
return 0;
|
||||
} else {
|
||||
__winerr();
|
||||
CloseHandle(hin);
|
||||
}
|
||||
} else {
|
||||
__winerr();
|
||||
}
|
||||
__releasefd(writer);
|
||||
__releasefd(reader);
|
||||
return __winerr();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Creates file descriptors for IPC.
|
||||
/
|
||||
/ @param rdi points to int3[2] that gets (reader, writer)
|
||||
/ @return 0 on success or -1 w/ errno
|
||||
/ @asyncsignalsafe
|
||||
/ @see libc/sysv/syscalls.sh
|
||||
/ @see pipe2()
|
||||
sys_pipe:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
#if SupportsFreebsd()
|
||||
xor %esi,%esi
|
||||
#endif
|
||||
call __sys_pipe
|
||||
#if SupportsXnu() || SupportsNetbsd()
|
||||
testb $XNU|NETBSD,__hostos(%rip)
|
||||
jz 1f
|
||||
cmp $-1,%rax
|
||||
je 1f
|
||||
mov %eax,(%rdi)
|
||||
mov %edx,4(%rdi)
|
||||
xor %eax,%eax
|
||||
#endif
|
||||
1: pop %rbp
|
||||
ret
|
||||
.endfn sys_pipe,globl,hidden
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -16,19 +16,19 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Pauses process w/ standard ABI.
|
||||
sys_sigsuspend:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
#if SupportsOpenbsd()
|
||||
testb IsOpenbsd()
|
||||
jz 1f
|
||||
mov (%rdi),%edi # openbsd:byvalue
|
||||
#endif
|
||||
1: call __sys_sigsuspend
|
||||
pop %rbp
|
||||
ret
|
||||
.endfn sys_sigsuspend,globl
|
||||
int sys_pipe(int fds[2]) {
|
||||
axdx_t ad;
|
||||
int ax, dx;
|
||||
ad = __sys_pipe(fds, 0);
|
||||
ax = ad.ax;
|
||||
dx = ad.dx;
|
||||
if ((IsXnu() || IsNetbsd()) && ax != -1) {
|
||||
fds[0] = ax;
|
||||
fds[1] = dx;
|
||||
ax = 0;
|
||||
}
|
||||
return ax;
|
||||
}
|
|
@ -16,9 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,7 @@ ssize_t pread(int fd, void *buf, size_t size, int64_t offset) {
|
|||
rc = weaken(__zipos_read)(
|
||||
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, buf, size, offset);
|
||||
} else if (!IsWindows()) {
|
||||
rc = sys_pread(fd, buf, size, offset);
|
||||
rc = sys_pread(fd, buf, size, offset, offset);
|
||||
} else if (__isfdkind(fd, kFdFile)) {
|
||||
rc = sys_read_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset);
|
||||
} else {
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/sysv/consts/iov.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
@ -42,7 +42,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) {
|
|||
int olderr;
|
||||
ssize_t rc;
|
||||
if (!count) return 0;
|
||||
if ((count = min(count, IOV_MAX)) < 0) return einval();
|
||||
if ((count = MIN(count, IOV_MAX)) < 0) return einval();
|
||||
|
||||
/*
|
||||
* NT, XNU, and 2007-era Linux don't support this system call.
|
||||
|
@ -58,7 +58,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) {
|
|||
demodernize = true;
|
||||
} else {
|
||||
olderr = errno;
|
||||
rc = sys_preadv(fd, iovec, count, off);
|
||||
rc = sys_preadv(fd, iovec, count, off, off);
|
||||
if (rc == -1 && errno == ENOSYS) {
|
||||
errno = olderr;
|
||||
demodernize = true;
|
||||
|
@ -71,7 +71,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) {
|
|||
}
|
||||
|
||||
if (!demodernize) {
|
||||
return sys_preadv(fd, iovec, count, off);
|
||||
return sys_preadv(fd, iovec, count, off, off);
|
||||
} else {
|
||||
return pread(fd, iovec[0].iov_base, iovec[0].iov_len, off);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) {
|
|||
if (fd == -1 || offset < 0) return einval();
|
||||
size = MIN(size, 0x7ffff000);
|
||||
if (!IsWindows()) {
|
||||
rc = sys_pwrite(fd, buf, size, offset);
|
||||
rc = sys_pwrite(fd, buf, size, offset, offset);
|
||||
} else if (__isfdkind(fd, kFdFile)) {
|
||||
rc = sys_write_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset);
|
||||
} else {
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/sysv/consts/iov.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
@ -45,9 +45,8 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) {
|
|||
static bool once, demodernize;
|
||||
int olderr;
|
||||
ssize_t rc;
|
||||
|
||||
if (!count) return 0;
|
||||
if ((count = min(count, IOV_MAX)) < 0) return einval();
|
||||
if ((count = MIN(count, IOV_MAX)) < 0) return einval();
|
||||
|
||||
/*
|
||||
* NT, XNU, and 2007-era Linux don't support this system call.
|
||||
|
@ -63,7 +62,7 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) {
|
|||
demodernize = true;
|
||||
} else {
|
||||
olderr = errno;
|
||||
rc = sys_pwritev(fd, iovec, count, off);
|
||||
rc = sys_pwritev(fd, iovec, count, off, off);
|
||||
if (rc == -1 && errno == ENOSYS) {
|
||||
errno = olderr;
|
||||
demodernize = true;
|
||||
|
@ -77,7 +76,7 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) {
|
|||
}
|
||||
|
||||
if (!demodernize) {
|
||||
return sys_pwritev(fd, iovec, count, off);
|
||||
return sys_pwritev(fd, iovec, count, off, off);
|
||||
} else {
|
||||
return pwrite(fd, iovec[0].iov_base, iovec[0].iov_len, off);
|
||||
}
|
||||
|
|
|
@ -24,21 +24,37 @@
|
|||
#include "libc/nt/errors.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/struct/overlapped.h"
|
||||
#include "libc/nt/struct/teb.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov,
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
uint32_t got;
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
size_t i, total;
|
||||
uint32_t got, size;
|
||||
struct NtOverlapped overlap;
|
||||
while (iovlen && !iov[0].iov_len) iov++, iovlen--;
|
||||
if (ReadFile(fd->handle, iovlen ? iov[0].iov_base : NULL,
|
||||
iovlen ? clampio(iov[0].iov_len) : 0, &got,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
return got;
|
||||
} else if (NtGetErr() == kNtErrorBrokenPipe) {
|
||||
return 0; /* read() doesn't EPIPE lool */
|
||||
if (iovlen) {
|
||||
for (total = i = 0; i < iovlen; ++i) {
|
||||
size = clampio(iov[i].iov_len);
|
||||
if (ReadFile(fd->handle, iov[i].iov_base, size, &got,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
total += got;
|
||||
if (opt_offset != -1) opt_offset += got;
|
||||
if (got < iov[i].iov_len) break;
|
||||
} else if (GetLastError() == kNtErrorBrokenPipe) {
|
||||
break; /* read() doesn't EPIPE lool */
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
return total;
|
||||
} else {
|
||||
return __winerr();
|
||||
if (ReadFile(fd->handle, NULL, 0, &got,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
return got;
|
||||
} else if (GetLastError() == kNtErrorBrokenPipe) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
*/
|
||||
int renameat(int olddirfd, const char *oldpath, int newdirfd,
|
||||
const char *newpath) {
|
||||
if (!oldpath || !newpath) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_renameat(olddirfd, oldpath, newdirfd, newpath);
|
||||
} else {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
@ -37,8 +38,18 @@
|
|||
* @vforksafe
|
||||
*/
|
||||
int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) {
|
||||
if (!IsWindows()) {
|
||||
int32_t x;
|
||||
if (!IsWindows() && !IsOpenbsd()) {
|
||||
return sys_sigprocmask(how, opt_set, opt_out_oldset, 8);
|
||||
} else if (IsOpenbsd()) {
|
||||
if (!opt_set) how = 1;
|
||||
if (opt_set) opt_set = (sigset_t *)(uintptr_t)(*(uint32_t *)opt_set);
|
||||
if ((x = sys_sigprocmask(how, opt_set, 0, 0)) != -1) {
|
||||
if (opt_out_oldset) memcpy(opt_out_oldset, &x, sizeof(x));
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return 0; /* TODO(jart): Implement me! */
|
||||
}
|
||||
|
|
|
@ -30,8 +30,9 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
int sigsuspend(const sigset_t *ignore) {
|
||||
if (!ignore) return efault();
|
||||
unsigned x;
|
||||
if (!IsWindows()) {
|
||||
if (IsOpenbsd()) ignore = (sigset_t *)(uintptr_t)(*(uint32_t *)ignore);
|
||||
return sys_sigsuspend(ignore, 8);
|
||||
} else {
|
||||
return enosys(); /* TODO(jart): Implement me! */
|
||||
|
|
|
@ -82,13 +82,13 @@ static textstartup void __stat2linux_netbsd(union metastat *ms) {
|
|||
*/
|
||||
textstartup void __stat2linux(void *ms) {
|
||||
if (ms) {
|
||||
if (SupportsXnu() && IsXnu()) {
|
||||
if (IsXnu()) {
|
||||
__stat2linux_xnu((union metastat *)ms);
|
||||
} else if (SupportsFreebsd() && IsFreebsd()) {
|
||||
} else if (IsFreebsd()) {
|
||||
__stat2linux_freebsd((union metastat *)ms);
|
||||
} else if (SupportsOpenbsd() && IsOpenbsd()) {
|
||||
} else if (IsOpenbsd()) {
|
||||
__stat2linux_openbsd((union metastat *)ms);
|
||||
} else if (SupportsNetbsd() && IsNetbsd()) {
|
||||
} else if (IsNetbsd()) {
|
||||
__stat2linux_netbsd((union metastat *)ms);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_
|
||||
#ifndef __STRICT_ANSI__
|
||||
#include "libc/calls/struct/termios.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
@ -33,5 +32,4 @@ union metatermios {
|
|||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* !ANSI */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_ */
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "libc/dce.h"
|
||||
|
||||
/**
|
||||
* Flushes file system changes to disk to the greatest extent possible.
|
||||
* Flushes file system changes to disk by any means necessary.
|
||||
*/
|
||||
void sync(void) {
|
||||
if (!IsWindows()) {
|
||||
|
|
|
@ -21,8 +21,8 @@ COSMOPOLITAN_C_START_
|
|||
(TO)->c_ospeed = (FROM)->c_ospeed; \
|
||||
} while (0)
|
||||
|
||||
void *termios2host(union metatermios *, const struct termios *);
|
||||
void termios2linux(struct termios *, const union metatermios *);
|
||||
void *__termios2host(union metatermios *, const struct termios *) hidden;
|
||||
void __termios2linux(struct termios *, const union metatermios *) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
#include "libc/calls/termios.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
||||
void *termios2host(union metatermios *t, const struct termios *lt) {
|
||||
if (IsXnu()) {
|
||||
void *__termios2host(union metatermios *t, const struct termios *lt) {
|
||||
if (!IsXnu() && !IsFreebsd() && !IsOpenbsd() && !IsNetbsd()) {
|
||||
return lt;
|
||||
} else if (IsXnu()) {
|
||||
COPY_TERMIOS(&t->xnu, lt);
|
||||
return &t->xnu;
|
||||
} else if (IsFreebsd() || IsOpenbsd()) {
|
||||
} else {
|
||||
COPY_TERMIOS(&t->bsd, lt);
|
||||
return &t->bsd;
|
||||
} else {
|
||||
return lt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
#include "libc/calls/termios.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
||||
void termios2linux(struct termios *lt, const union metatermios *t) {
|
||||
void __termios2linux(struct termios *lt, const union metatermios *t) {
|
||||
if (IsXnu()) {
|
||||
COPY_TERMIOS(lt, &t->xnu);
|
||||
} else if (IsFreebsd() || IsOpenbsd()) {
|
||||
} else if (IsFreebsd() || IsOpenbsd() || IsNetbsd()) {
|
||||
COPY_TERMIOS(lt, &t->bsd);
|
||||
} else {
|
||||
memcpy(lt, &t->linux, sizeof(*lt));
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls ftruncate() impl on host o/s if available.
|
||||
sys_ftruncate:
|
||||
mov %rsi,%rdx # netbsd+openbsd:pad
|
||||
jmp __sys_ftruncate
|
||||
.endfn sys_ftruncate,globl,hidden
|
|
@ -1,30 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls mmap() on system five host o/s.
|
||||
sys_mmap:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %r9 # netbsd+openbsd:pad
|
||||
call __sys_mmap
|
||||
leave
|
||||
ret
|
||||
.endfn sys_mmap,globl,hidden
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls preadv() impl on host o/s if available.
|
||||
sys_preadv:
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_preadv
|
||||
.endfn sys_preadv,globl,hidden
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls pwrite() impl on host o/s if available.
|
||||
sys_pwrite:
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pwrite
|
||||
.endfn sys_pwrite,globl,hidden
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls pwritev() impl on host o/s if available.
|
||||
sys_pwritev:
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pwritev
|
||||
.endfn sys_pwritev,globl,hidden
|
|
@ -1,46 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Sets System Five process signal mask w/ standard ABI.
|
||||
sys_sigprocmask:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
#if SupportsOpenbsd()
|
||||
testb IsOpenbsd()
|
||||
jz 4f
|
||||
test %rsi,%rsi
|
||||
jnz 1f
|
||||
mov $1,%edi # SIG_BLOCK on BSDs
|
||||
jmp 2f
|
||||
1: mov (%rsi),%esi # openbsd:byvalue
|
||||
2: call __sys_sigprocmask
|
||||
cmp $-1,%eax
|
||||
je 5f
|
||||
test %rdx,%rdx # original param not a result
|
||||
jz 3f
|
||||
mov %eax,(%rdx) # openbsd:byvalue
|
||||
3: xor %eax,%eax
|
||||
jmp 5f
|
||||
#endif
|
||||
4: call __sys_sigprocmask
|
||||
5: pop %rbp
|
||||
ret
|
||||
.endfn sys_sigprocmask,globl
|
|
@ -1,26 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.source __FILE__
|
||||
|
||||
/ Directly calls truncate() impl on host o/s if available.
|
||||
sys_truncate:
|
||||
mov %rsi,%rdx # netbsd+openbsd:pad
|
||||
jmp __sys_truncate
|
||||
.endfn sys_truncate,globl,hidden
|
|
@ -32,9 +32,8 @@
|
|||
* @error ENOENT
|
||||
*/
|
||||
int truncate(const char *path, uint64_t length) {
|
||||
if (!path) return efault();
|
||||
if (!IsWindows()) {
|
||||
return sys_truncate(path, length);
|
||||
return sys_truncate(path, length, length);
|
||||
} else {
|
||||
return sys_truncate_nt(path, length);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -16,11 +16,32 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.windows
|
||||
.source __FILE__
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
__onntconsoleevent_nt:
|
||||
ezlea __onntconsoleevent,ax
|
||||
jmp __nt2sysv
|
||||
.endfn __onntconsoleevent_nt,globl,hidden
|
||||
/**
|
||||
* Removes environment variable.
|
||||
*/
|
||||
int unsetenv(const char *s) {
|
||||
char **p;
|
||||
size_t i, j, k;
|
||||
if (s && (p = environ)) {
|
||||
for (i = 0; p[i]; ++i) {
|
||||
for (j = 0;; ++j) {
|
||||
if (!s[j]) {
|
||||
if (p[i][j] == '=') {
|
||||
k = i + 1;
|
||||
do {
|
||||
p[k - 1] = p[k];
|
||||
} while (p[k++]);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (s[j] != p[i][j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -25,7 +25,7 @@
|
|||
#include "libc/nt/struct/overlapped.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static size_t SumIovecLen(const struct iovec *v, size_t n) {
|
||||
static textwindows size_t SumIovecLen(const struct iovec *v, size_t n) {
|
||||
size_t i, sum;
|
||||
for (sum = i = 0; i < n; ++i) {
|
||||
sum += v[i].iov_len;
|
||||
|
@ -34,16 +34,32 @@ static size_t SumIovecLen(const struct iovec *v, size_t n) {
|
|||
}
|
||||
|
||||
textwindows ssize_t sys_write_nt(struct Fd *fd, const struct iovec *iov,
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
uint32_t wrote;
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
size_t i, total;
|
||||
uint32_t size, wrote;
|
||||
struct NtOverlapped overlap;
|
||||
while (iovlen && !iov[0].iov_len) iov++, iovlen--;
|
||||
if (WriteFile(fd->handle, iovlen ? iov[0].iov_base : NULL,
|
||||
iovlen ? clampio(iov[0].iov_len) : 0, &wrote,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
if (!wrote) assert(!SumIovecLen(iov, iovlen));
|
||||
return wrote;
|
||||
if (iovlen) {
|
||||
for (total = i = 0; i < iovlen; ++i) {
|
||||
if (!iov[i].iov_len) continue;
|
||||
size = clampio(iov[0].iov_len);
|
||||
if (WriteFile(fd->handle, iov[i].iov_base, size, &wrote,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
total += wrote;
|
||||
if (opt_offset != -1) opt_offset += wrote;
|
||||
if (wrote < iov[i].iov_len) break;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
if (!total) assert(!SumIovecLen(iov, iovlen));
|
||||
return total;
|
||||
} else {
|
||||
return __winerr();
|
||||
if (WriteFile(fd->handle, NULL, 0, &wrote,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue