Fix bugs and add security features to redbean

- Fix a regression with the previous change that broke redbean
- Add chroot(), resource limit, seccomp, and other stuff to redbean
- Write lots and lots of documentation
- Iron out more system call issues
This commit is contained in:
Justine Tunney 2022-04-18 00:01:26 -07:00
parent f1dfa4bdfa
commit 7166679620
182 changed files with 1855 additions and 918 deletions

View file

@ -155,7 +155,7 @@ int pipe(int[hasatleast 2]);
int pipe2(int[hasatleast 2], int); int pipe2(int[hasatleast 2], int);
int posix_fadvise(int, uint64_t, uint64_t, int); int posix_fadvise(int, uint64_t, uint64_t, int);
int posix_madvise(void *, uint64_t, int); int posix_madvise(void *, uint64_t, int);
int prctl(); int prctl(int, ...);
int raise(int); int raise(int);
int reboot(int); int reboot(int);
int remove(const char *); int remove(const char *);
@ -232,6 +232,7 @@ uint32_t umask(uint32_t);
void rewinddir(DIR *); void rewinddir(DIR *);
void sync(void); void sync(void);
int getloadavg(double *, int); int getloadavg(double *, int);
int seccomp(unsigned, unsigned, void *);
/*───────────────────────────────────────────────────────────────────────────│─╗ /*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » formatting cosmopolitan § system calls » formatting

View file

@ -83,6 +83,9 @@ o/$(MODE)/libc/calls/ntcontext2linux.o: \
-O3 -O3
# TODO(jart): make va_arg optimize well in default mode # TODO(jart): make va_arg optimize well in default mode
o//libc/calls/open.o \
o//libc/calls/openat.o \
o//libc/calls/prctl.o \
o//libc/calls/ioctl.o \ o//libc/calls/ioctl.o \
o//libc/calls/ioctl_default.o \ o//libc/calls/ioctl_default.o \
o//libc/calls/ioctl_fioclex-nt.o \ o//libc/calls/ioctl_fioclex-nt.o \

View file

@ -76,5 +76,5 @@ textwindows int sys_chdir_nt(const char *path) {
} }
} }
} }
return -1; return __fix_enotdir(-1, path16);
} }

View file

@ -32,7 +32,7 @@
*/ */
int chdir(const char *path) { int chdir(const char *path) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid(path, 1)) { if (!path || (IsAsan() && !__asan_is_valid(path, 1))) {
rc = efault(); rc = efault();
} else if (!IsWindows()) { } else if (!IsWindows()) {
rc = sys_chdir(path); rc = sys_chdir(path);

33
libc/calls/chroot.c Normal file
View file

@ -0,0 +1,33 @@
/*-*- 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 2022 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/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/strace.internal.h"
/**
* Changes root directory.
*
* @raise ENOSYS on Windows
*/
int chroot(const char *path) {
int rc;
rc = sys_chroot(path);
STRACE("chroot(%s) → %d% m", path, rc);
return rc;
}

View file

@ -22,7 +22,6 @@
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/runtime/directmap.internal.h" #include "libc/runtime/directmap.internal.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/str/str.h" #include "libc/str/str.h"
/** /**
@ -32,6 +31,9 @@
* support Windows NT and Address Sanitizer. That memory tracking can be * support Windows NT and Address Sanitizer. That memory tracking can be
* bypassed by calling this function. However the caller is responsible * bypassed by calling this function. However the caller is responsible
* for passing the magic memory handle on Windows NT to CloseHandle(). * for passing the magic memory handle on Windows NT to CloseHandle().
*
* @asyncsignalsafe
* @threadsafe
*/ */
struct DirectMap sys_mmap(void *addr, size_t size, int prot, int flags, int fd, struct DirectMap sys_mmap(void *addr, size_t size, int prot, int flags, int fd,
int64_t off) { int64_t off) {

View file

@ -24,5 +24,5 @@
int sys_faccessat_nt(int dirfd, const char *path, int mode, uint32_t flags) { int sys_faccessat_nt(int dirfd, const char *path, int mode, uint32_t flags) {
char16_t path16[PATH_MAX]; char16_t path16[PATH_MAX];
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
return ntaccesscheck(path16, mode); return __fix_enotdir(ntaccesscheck(path16, mode), path16);
} }

63
libc/calls/fixenotdir.c Normal file
View file

@ -0,0 +1,63 @@
/*-*- 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 2022 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/calls/internal.h"
#include "libc/errno.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/errors.h"
#include "libc/nt/files.h"
static textwindows bool SubpathExistsThatsNotDirectory(char16_t *path) {
int e;
char16_t *p;
uint32_t attrs;
e = errno;
while ((p = strrchr16(path, '\\'))) {
*p = u'\0';
if ((attrs = GetFileAttributes(path)) != -1u) {
if (attrs & kNtFileAttributeDirectory) {
return false;
} else {
return true;
}
} else {
errno = e;
}
}
return false;
}
// WIN32 doesn't distinguish between ENOTDIR and ENOENT. UNIX strictly
// requires that a directory component *exists* but is not a directory
// whereas WIN32 will return ENOTDIR if a dir label simply isn't found
//
// - ENOTDIR: A component used as a directory in pathname is not, in
// fact, a directory. -or- pathname is relative and dirfd is a file
// descriptor referring to a file other than a directory.
//
// - ENOENT: A directory component in pathname does not exist or is a
// dangling symbolic link.
//
textwindows int64_t __fix_enotdir(int64_t rc, char16_t *path) {
if (rc == -1 && errno == kNtErrorPathNotFound) {
if (!SubpathExistsThatsNotDirectory(path)) {
errno = kNtErrorFileNotFound;
}
}
return rc;
}

View file

@ -21,6 +21,7 @@
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
/** /**
@ -36,10 +37,16 @@ int getrlimit(int resource, struct rlimit *rlim) {
char buf[64]; char buf[64];
if (resource == 127) { if (resource == 127) {
rc = einval(); rc = einval();
} else if (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim))) { } else if (!rlim || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) {
rc = efault(); rc = efault();
} else { } else if (!IsWindows()) {
rc = sys_getrlimit(resource, rlim); rc = sys_getrlimit(resource, rlim);
} else if (resource == RLIMIT_AS) {
rlim->rlim_cur = __virtualmax;
rlim->rlim_max = __virtualmax;
rc = 0;
} else {
rc = einval();
} }
STRACE("getrlimit(%s, [%s]) → %d% m", __strace_rlimit_name(resource), STRACE("getrlimit(%s, [%s]) → %d% m", __strace_rlimit_name(resource),
__strace_rlimit(buf, sizeof(buf), rc, rlim), rc); __strace_rlimit(buf, sizeof(buf), rc, rlim), rc);

View file

@ -5,6 +5,7 @@
#include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/itimerval.h"
#include "libc/calls/struct/metastat.internal.h" #include "libc/calls/struct/metastat.internal.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h" #include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/sigaction-xnu.internal.h" #include "libc/calls/struct/sigaction-xnu.internal.h"
#include "libc/calls/struct/siginfo-xnu.internal.h" #include "libc/calls/struct/siginfo-xnu.internal.h"
@ -133,6 +134,7 @@ i32 __sys_pipe2(i32[hasatleast 2], u32) hidden;
i32 __sys_utimensat(i32, const char *, const struct timespec *, i32) hidden; i32 __sys_utimensat(i32, const char *, const struct timespec *, i32) hidden;
i32 __sys_wait4(i32, i32 *, i32, struct rusage *) hidden; i32 __sys_wait4(i32, i32 *, i32, struct rusage *) hidden;
i32 sys_chdir(const char *) hidden; i32 sys_chdir(const char *) hidden;
i32 sys_chroot(const char *) hidden;
i32 sys_clock_gettime(i32, struct timespec *) hidden; i32 sys_clock_gettime(i32, struct timespec *) hidden;
i32 sys_close(i32) hidden; i32 sys_close(i32) hidden;
i32 sys_dup(i32) hidden; i32 sys_dup(i32) hidden;
@ -310,6 +312,7 @@ int sys_sync_nt(void) hidden;
int sys_sysinfo_nt(struct sysinfo *) hidden; int sys_sysinfo_nt(struct sysinfo *) hidden;
int sys_truncate_nt(const char *, u64) hidden; int sys_truncate_nt(const char *, u64) hidden;
int sys_unlinkat_nt(int, const char *, int) hidden; int sys_unlinkat_nt(int, const char *, int) hidden;
int sys_setrlimit_nt(int, const struct rlimit *) hidden;
int sys_utimensat_nt(int, const char *, const struct timespec *, int) hidden; int sys_utimensat_nt(int, const char *, const struct timespec *, int) hidden;
int sys_utimes_nt(const char *, const struct timeval[2]) hidden; int sys_utimes_nt(const char *, const struct timeval[2]) hidden;
ssize_t sys_open_nt(int, const char *, u32, i32) dontdiscard hidden; ssize_t sys_open_nt(int, const char *, u32, i32) dontdiscard hidden;
@ -322,6 +325,7 @@ int ioctl_tiocgwinsz_nt(struct Fd *, struct winsize *) hidden;
cosmopolitan § syscalls » windows nt » support cosmopolitan § syscalls » windows nt » support
*/ */
int64_t __fix_enotdir(int64_t, char16_t *) hidden;
bool _check_interrupts(bool, struct Fd *) hidden; bool _check_interrupts(bool, struct Fd *) hidden;
void _check_sigchld(void) hidden; void _check_sigchld(void) hidden;
void _check_sigalrm(void) hidden; void _check_sigalrm(void) hidden;

10
libc/calls/issandboxed.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_ISSANDBOXED_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_ISSANDBOXED_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern bool __issandboxed;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_ISSANDBOXED_INTERNAL_H_ */

View file

@ -17,50 +17,12 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/errno.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/str/str.h"
static textwindows bool SubpathExistsThatsNotDirectory(char16_t *path) {
int e;
char16_t *p;
uint32_t attrs;
e = errno;
while ((p = strrchr16(path, '\\'))) {
*p = u'\0';
if ((attrs = GetFileAttributes(path)) != -1u) {
if (attrs & kNtFileAttributeDirectory) {
return false;
} else {
return true;
}
} else {
errno = e;
}
}
return false;
}
textwindows int sys_mkdirat_nt(int dirfd, const char *path, uint32_t mode) { textwindows int sys_mkdirat_nt(int dirfd, const char *path, uint32_t mode) {
int e; int e;
char16_t *p, path16[PATH_MAX]; char16_t *p, path16[PATH_MAX];
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
if (CreateDirectory(path16, 0)) return 0; if (CreateDirectory(path16, 0)) return 0;
return __fix_enotdir(-1, path16);
// WIN32 doesn't distinguish between ENOTDIR and ENOENT
//
// - ENOTDIR: A component used as a directory in pathname is not, in
// fact, a directory. -or- pathname is relative and dirfd is a file
// descriptor referring to a file other than a directory.
//
// - ENOENT: A directory component in pathname does not exist or is a
// dangling symbolic link.
if (errno == ENOTDIR) {
if (!SubpathExistsThatsNotDirectory(path16)) {
errno = ENOENT;
}
}
return -1;
} }

View file

@ -19,8 +19,16 @@
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/runtime/directmap.internal.h" #include "libc/runtime/directmap.internal.h"
#include "libc/runtime/memtrack.internal.h"
/**
* Unmaps memory directly with system.
*
* This function bypasses memtrack. Therefore it won't work on Windows,
* but it works on everything else including bare metal.
*
* @asyncsignalsafe
* @threadsafe
*/
int sys_munmap(void *p, size_t n) { int sys_munmap(void *p, size_t n) {
int rc; int rc;
if (!IsMetal()) { if (!IsMetal()) {

View file

@ -42,7 +42,9 @@ static textwindows int64_t sys_open_nt_impl(int dirfd, const char *path,
uint32_t perm, share, disp, attr; uint32_t perm, share, disp, attr;
if (__mkntpathat(dirfd, path, flags, path16) == -1) return -1; if (__mkntpathat(dirfd, path, flags, path16) == -1) return -1;
if (GetNtOpenFlags(flags, mode, &perm, &share, &disp, &attr) == -1) return -1; if (GetNtOpenFlags(flags, mode, &perm, &share, &disp, &attr) == -1) return -1;
return CreateFile(path16, perm, share, &kNtIsInheritable, disp, attr, 0); return __fix_enotdir(
CreateFile(path16, perm, share, &kNtIsInheritable, disp, attr, 0),
path16);
} }
static textwindows ssize_t sys_open_nt_console(int dirfd, static textwindows ssize_t sys_open_nt_console(int dirfd,

View file

@ -87,11 +87,13 @@ int poll(struct pollfd *fds, size_t nfds, int timeout_ms) {
if (rc == -1 && errno == EFAULT) { if (rc == -1 && errno == EFAULT) {
STRACE("poll(%p, %'lu, %'d) → %d% lm", fds, nfds, timeout_ms, rc); STRACE("poll(%p, %'lu, %'d) → %d% lm", fds, nfds, timeout_ms, rc);
} else { } else {
char flagbuf[2][64];
kprintf(STRACE_PROLOGUE "poll({"); kprintf(STRACE_PROLOGUE "poll({");
for (i = 0; i < MIN(5, nfds); ++i) { for (i = 0; i < MIN(5, nfds); ++i) {
kprintf("%s{%d,%s,%s}", i ? ", " : "", fds[i].fd, kprintf(
DescribePollFlags(fds[i].events), "%s{%d, %s, %s}", i ? ", " : "", fds[i].fd,
DescribePollFlags(fds[i].revents)); DescribePollFlags(flagbuf[0], sizeof(flagbuf[0]), fds[i].events),
DescribePollFlags(flagbuf[1], sizeof(flagbuf[1]), fds[i].revents));
} }
kprintf("%s}, %'zu, %'d) → %d% lm%n", i == 5 ? "..." : "", nfds, kprintf("%s}, %'zu, %'d) → %d% lm%n", i == 5 ? "..." : "", nfds,
timeout_ms, rc); timeout_ms, rc);

52
libc/calls/prctl.c Normal file
View file

@ -0,0 +1,52 @@
/*-*- 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 2022 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/calls/calls.h"
#include "libc/calls/strace.internal.h"
#include "libc/errno.h"
#include "libc/sysv/errfuns.h"
/**
* Tunes process on Linux.
*
* @raise ENOSYS on non-Linux.
*/
int prctl(int operation, ...) {
int rc;
va_list va;
intptr_t a, b;
register intptr_t c asm("r10");
register intptr_t d asm("r8");
va_start(va, operation);
a = va_arg(va, intptr_t);
b = va_arg(va, intptr_t);
c = va_arg(va, intptr_t);
d = va_arg(va, intptr_t);
va_end(va);
if (IsLinux()) {
asm volatile("syscall"
: "=a"(rc)
: "0"(157), "D"(operation), "S"(a), "d"(b), "r"(c), "r"(d)
: "rcx", "r11", "memory");
if (rc > -4096u) errno = -rc, rc = -1;
} else {
rc = enosys();
}
STRACE("seccomp(%d, %p, %p, %p, %p) → %d% m", operation, a, b, c, d, rc);
return rc;
}

View file

@ -56,7 +56,7 @@ ssize_t pread(int fd, void *buf, size_t size, int64_t offset) {
rc = ebadf(); rc = ebadf();
} }
assert(rc == -1 || (size_t)rc <= size); assert(rc == -1 || (size_t)rc <= size);
STRACE("pread(%d, [%#.*hhs%s], %'zu, %'zd) → %'zd% m", fd, DATATRACE("pread(%d, [%#.*hhs%s], %'zu, %'zd) → %'zd% m", fd,
MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, offset, rc); MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, offset, rc);
return rc; return rc;
} }

View file

@ -58,7 +58,7 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) {
assert(wrote <= size); assert(wrote <= size);
} }
} }
STRACE("pwrite(%d, %#.*hhs%s, %'zu, %'zd) → %'zd% m", fd, MAX(0, MIN(40, rc)), DATATRACE("pwrite(%d, %#.*hhs%s, %'zu, %'zd) → %'zd% m", fd,
buf, rc > 40 ? "..." : "", size, offset, rc); MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, offset, rc);
return rc; return rc;
} }

View file

@ -62,7 +62,7 @@ ssize_t read(int fd, void *buf, size_t size) {
} else { } else {
rc = einval(); rc = einval();
} }
STRACE("read(%d, [%#.*hhs%s], %'zu) → %'zd% m", fd, MAX(0, MIN(40, rc)), buf, DATATRACE("read(%d, [%#.*hhs%s], %'zu) → %'zd% m", fd, MAX(0, MIN(40, rc)),
rc > 40 ? "..." : "", size, rc); buf, rc > 40 ? "..." : "", size, rc);
return rc; return rc;
} }

View file

@ -22,6 +22,7 @@
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.h"
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/sock/internal.h" #include "libc/sock/internal.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h" #include "libc/zipos/zipos.internal.h"
@ -40,7 +41,9 @@
* @restartable * @restartable
*/ */
ssize_t readv(int fd, const struct iovec *iov, int iovlen) { ssize_t readv(int fd, const struct iovec *iov, int iovlen) {
ssize_t rc; int i;
ssize_t rc, rem;
if (fd >= 0 && iovlen >= 0) { if (fd >= 0 && iovlen >= 0) {
if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) { if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) {
rc = efault(); rc = efault();
@ -63,6 +66,27 @@ ssize_t readv(int fd, const struct iovec *iov, int iovlen) {
} else { } else {
rc = einval(); rc = einval();
} }
STRACE("readv(%d, %p, %d) → %'zd% m", fd, iov, iovlen, rc);
#if defined(SYSDEBUG) && _DATATRACE
if (__strace > 0) {
if (rc == -1 && errno == EFAULT) {
STRACE("readv(%d, %p, %d) → %'zd% m", fd, iov, iovlen, rc);
} else {
rem = rc != -1 ? rc : 0;
kprintf(STRACE_PROLOGUE "readv(%d, [{", fd);
for (i = 0; i < MIN(5, iovlen); ++i) {
kprintf("%s{%#.*hhs%s, %'zu}", i ? ", " : "",
MAX(0, MIN(40, MIN(rem, iov[i].iov_len))), iov[i].iov_base,
MAX(0, MIN(40, MIN(rem, iov[i].iov_len))) < iov[i].iov_len
? "..."
: "",
iov[i].iov_len);
rem -= iov[i].iov_len;
}
kprintf("%s}], %d) → %'ld% m%n", iovlen > 5 ? "..." : "", iovlen, rc);
}
}
#endif
return rc; return rc;
} }

69
libc/calls/seccomp.c Normal file
View file

@ -0,0 +1,69 @@
/*-*- 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 2022 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/calls/calls.h"
#include "libc/calls/issandboxed.h"
#include "libc/calls/strace.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/sysv/consts/pr.h"
#include "libc/sysv/consts/seccomp.h"
#include "libc/sysv/errfuns.h"
/**
* Tunes Linux security policy.
*
* This system call was first introduced in Linux 3.17. We polyfill
* automatically features like SECCOMP_SET_MODE_STRICT, for kernels
* dating back to 2.6.23, whenever possible.
*
* @raise ENOSYS on non-Linux.
*/
int seccomp(unsigned operation, unsigned flags, void *args) {
int rc;
if (IsLinux()) {
asm volatile("syscall"
: "=a"(rc)
: "0"(317), "D"(operation), "S"(flags), "d"(args)
: "rcx", "r11", "memory");
if (rc == -ENOSYS) {
if (operation == SECCOMP_SET_MODE_STRICT) {
asm volatile("syscall"
: "=a"(rc)
: "0"(157), "D"(PR_SET_SECCOMP), "S"(SECCOMP_MODE_STRICT)
: "rcx", "r11", "memory");
} else if (operation == SECCOMP_SET_MODE_FILTER && !flags) {
asm volatile("syscall"
: "=a"(rc)
: "0"(157), "D"(PR_SET_SECCOMP), "S"(SECCOMP_MODE_FILTER),
"d"(args)
: "rcx", "r11", "memory");
}
}
if (rc > -4096u) {
errno = -rc;
rc = -1;
}
} else {
rc = enosys();
}
STRACE("seccomp(%s, %#x, %p) → %d% m",
DescribeSeccompOperationFlags(operation), flags, args, rc);
return rc;
}

View file

@ -16,17 +16,39 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/assert.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
/** /**
* Sets resource limit for current process. * Sets resource limit for current process.
* *
* @param resource can be RLIMIT_{CPU,FSIZE,DATA,STACK,CORE,RSS,etc.} * The following resources are recommended:
*
* - `RLIMIT_AS` limits the size of the virtual address space. This will
* work on all platforms. It's emulated on XNU and Windows which means
* it won't propagate across execve() currently.
*
* - `RLIMIT_CPU` causes `SIGXCPU` to be sent to the process when the
* soft limit on CPU time is exceeded, and the process is destroyed
* when the hard limit is exceeded. It works everywhere but Windows
* where it should be possible to poll getrusage() with setitimer()
*
* - `RLIMIT_FSIZE` causes `SIGXFSZ` to sent to the process when the
* soft limit on file size is exceeded and the process is destroyed
* when the hard limit is exceeded. It works everywhere but Windows
*
* - `RLIMIT_NPROC` limits the number of simultaneous processes and it
* should work on all platforms except Windows.
*
* - `RLIMIT_NOFILE` limits the number of open file descriptors and it
* should work on all platforms except Windows (TODO)
*
* @param rlim specifies new resource limit * @param rlim specifies new resource limit
* @return 0 on success or -1 w/ errno * @return 0 on success or -1 w/ errno
* @see libc/sysv/consts.sh * @see libc/sysv/consts.sh
@ -37,10 +59,19 @@ int setrlimit(int resource, const struct rlimit *rlim) {
char buf[64]; char buf[64];
if (resource == 127) { if (resource == 127) {
rc = einval(); rc = einval();
} else if (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim))) { } else if (!rlim || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) {
rc = efault(); rc = efault();
} else { } else if (!IsWindows()) {
rc = sys_setrlimit(resource, rlim); rc = sys_setrlimit(resource, rlim);
if (IsXnu() && !rc && resource == RLIMIT_AS) {
// TODO(jart): What's up with XNU and NetBSD?
__virtualmax = rlim->rlim_cur;
}
} else if (resource == RLIMIT_AS) {
__virtualmax = rlim->rlim_cur;
rc = 0;
} else {
rc = einval();
} }
STRACE("setrlimit(%s, %s) → %d% m", __strace_rlimit_name(resource), STRACE("setrlimit(%s, %s) → %d% m", __strace_rlimit_name(resource),
__strace_rlimit(buf, sizeof(buf), 0, rlim), rc); __strace_rlimit(buf, sizeof(buf), 0, rlim), rc);

View file

@ -24,6 +24,10 @@ void __stat2cosmo(struct stat *restrict st, const union metastat *ms) {
if (st) { if (st) {
if (IsLinux()) { if (IsLinux()) {
st->st_birthtim = st->st_ctim; st->st_birthtim = st->st_ctim;
if (st->st_atim.tv_sec < st->st_ctim.tv_sec)
st->st_birthtim = st->st_atim;
if (st->st_mtim.tv_sec < st->st_ctim.tv_sec)
st->st_birthtim = st->st_mtim;
} else if (IsXnu()) { } else if (IsXnu()) {
st->st_dev = ms->xnu.st_dev; st->st_dev = ms->xnu.st_dev;
st->st_ino = ms->xnu.st_ino; st->st_ino = ms->xnu.st_ino;

View file

@ -7,6 +7,7 @@
#define _NT_RLIMIT_PWSS_MB 1000 /* nocommit */ #define _NT_RLIMIT_PWSS_MB 1000 /* nocommit */
#define _KERNTRACE 0 /* not configurable w/ flag yet */ #define _KERNTRACE 0 /* not configurable w/ flag yet */
#define _POLLTRACE 0 /* not configurable w/ flag yet */ #define _POLLTRACE 0 /* not configurable w/ flag yet */
#define _DATATRACE 1 /* not configurable w/ flag yet */
#define _NTTRACE 0 /* not configurable w/ flag yet */ #define _NTTRACE 0 /* not configurable w/ flag yet */
#define STRACE_PROLOGUE "%rSYS %5P %'18T " #define STRACE_PROLOGUE "%rSYS %5P %'18T "
@ -25,6 +26,12 @@ COSMOPOLITAN_C_START_
#define STRACE(FMT, ...) (void)0 #define STRACE(FMT, ...) (void)0
#endif #endif
#if defined(SYSDEBUG) && _DATATRACE
#define DATATRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__)
#else
#define DATATRACE(FMT, ...) (void)0
#endif
#if defined(SYSDEBUG) && _POLLTRACE #if defined(SYSDEBUG) && _POLLTRACE
#define POLLTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__) #define POLLTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__)
#else #else

View file

@ -0,0 +1,54 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SECCOMP_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SECCOMP_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct seccomp_data {
int32_t nr;
uint32_t arch;
uint64_t instruction_pointer;
uint64_t args[6];
};
struct seccomp_notif_sizes {
uint16_t seccomp_notif;
uint16_t seccomp_notif_resp;
uint16_t seccomp_data;
};
struct seccomp_notif {
uint64_t id;
uint32_t pid;
uint32_t flags;
struct seccomp_data data;
};
struct seccomp_notif_resp {
uint64_t id;
int64_t val;
int32_t error;
uint32_t flags;
};
struct seccomp_notif_addfd {
uint64_t id;
uint32_t flags;
uint32_t srcfd;
uint32_t newfd;
uint32_t newfd_flags;
};
#define SECCOMP_IOC_MAGIC '!'
#define SECCOMP_IO(nr) _IO(SECCOMP_IOC_MAGIC, nr)
#define SECCOMP_IOR(nr, type) _IOR(SECCOMP_IOC_MAGIC, nr, type)
#define SECCOMP_IOW(nr, type) _IOW(SECCOMP_IOC_MAGIC, nr, type)
#define SECCOMP_IOWR(nr, type) _IOWR(SECCOMP_IOC_MAGIC, nr, type)
#define SECCOMP_IOCTL_NOTIF_RECV SECCOMP_IOWR(0, struct seccomp_notif)
#define SECCOMP_IOCTL_NOTIF_SEND SECCOMP_IOWR(1, struct seccomp_notif_resp)
#define SECCOMP_IOCTL_NOTIF_ID_VALID SECCOMP_IOW(2, __u64)
#define SECCOMP_IOCTL_NOTIF_ADDFD SECCOMP_IOW(3, struct seccomp_notif_addfd)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SECCOMP_H_ */

28
libc/calls/virtualmax.c Normal file
View file

@ -0,0 +1,28 @@
/*-*- 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 2022 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/calls/calls.h"
/**
* Maximum amount of virtual memory in bytes.
*
* mmap() will return ENOMEM once this is reached.
*
* By default no limit is imposed.
*/
size_t __virtualmax;

View file

@ -51,6 +51,8 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size,
__sig_raise(SIGPIPE, SI_KERNEL); __sig_raise(SIGPIPE, SI_KERNEL);
return epipe(); return epipe();
} }
// kNtErrorInvalidHandle → EBADF (consts.sh)
// kNtErrorNotEnoughQuota → EDQUOT (consts.sh; SetProcessWorkingSetSize)
return __winerr(); return __winerr();
} }

View file

@ -59,7 +59,7 @@ ssize_t write(int fd, const void *buf, size_t size) {
} else { } else {
rc = einval(); rc = einval();
} }
STRACE("write(%d, %#.*hhs%s, %'zu) → %'zd% m", fd, MAX(0, MIN(40, rc)), buf, DATATRACE("write(%d, %#.*hhs%s, %'zu) → %'zd% m", fd, MAX(0, MIN(40, rc)),
rc > 40 ? "..." : "", size, rc); buf, rc > 40 ? "..." : "", size, rc);
return rc; return rc;
} }

View file

@ -20,7 +20,9 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/sock/internal.h" #include "libc/sock/internal.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h" #include "libc/zipos/zipos.internal.h"
@ -44,7 +46,9 @@
* @restartable * @restartable
*/ */
ssize_t writev(int fd, const struct iovec *iov, int iovlen) { ssize_t writev(int fd, const struct iovec *iov, int iovlen) {
ssize_t rc; int i;
ssize_t rc, rem;
if (fd >= 0 && iovlen >= 0) { if (fd >= 0 && iovlen >= 0) {
if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) { if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) {
rc = efault(); rc = efault();
@ -67,6 +71,27 @@ ssize_t writev(int fd, const struct iovec *iov, int iovlen) {
} else { } else {
rc = einval(); rc = einval();
} }
STRACE("writev(%d, %p, %d) → %'zd% m", fd, iov, iovlen, rc);
#if defined(SYSDEBUG) && _DATATRACE
if (__strace > 0) {
if (rc == -1 && errno == EFAULT) {
STRACE("writev(%d, %p, %d) → %'zd% m", fd, iov, iovlen, rc);
} else {
rem = rc != -1 ? rc : 0;
kprintf(STRACE_PROLOGUE "writev(%d, {", fd);
for (i = 0; i < MIN(5, iovlen); ++i) {
kprintf("%s{%#.*hhs%s, %'zu}", i ? ", " : "",
MAX(0, MIN(40, MIN(rem, iov[i].iov_len))), iov[i].iov_base,
MAX(0, MIN(40, MIN(rem, iov[i].iov_len))) < iov[i].iov_len
? "..."
: "",
iov[i].iov_len);
rem -= iov[i].iov_len;
}
kprintf("%s}, %d) → %'ld% m%n", iovlen > 5 ? "..." : "", iovlen, rc);
}
}
#endif
return rc; return rc;
} }

View file

@ -115,6 +115,7 @@ kErrorNames:
.e ENOTRECOVERABLE .e ENOTRECOVERABLE
.e ENONET .e ENONET
.e ERESTART .e ERESTART
.e ENODATA
.long 0 .long 0
.endobj kErrorNames,globl,hidden .endobj kErrorNames,globl,hidden
.overrun .overrun

View file

@ -14,8 +14,9 @@ const char *DescribeFlags(char *, size_t, struct DescribeFlags *, size_t,
const char *DescribeMapFlags(int); const char *DescribeMapFlags(int);
const char *DescribeProtFlags(int); const char *DescribeProtFlags(int);
const char *DescribePollFlags(int);
const char *DescribeRemapFlags(int); const char *DescribeRemapFlags(int);
const char *DescribeSeccompOperationFlags(int);
const char *DescribePollFlags(char *, size_t, int);
const char *DescribeNtPageFlags(uint32_t); const char *DescribeNtPageFlags(uint32_t);
const char *DescribeNtStartFlags(uint32_t); const char *DescribeNtStartFlags(uint32_t);

View file

@ -21,7 +21,7 @@
#include "libc/nt/enum/filemapflags.h" #include "libc/nt/enum/filemapflags.h"
#include "libc/sysv/consts/poll.h" #include "libc/sysv/consts/poll.h"
const char *DescribePollFlags(int x) { const char *DescribePollFlags(char *buf, size_t size, int x) {
const struct DescribeFlags kPollFlags[] = { const struct DescribeFlags kPollFlags[] = {
{POLLIN, "IN"}, // order matters {POLLIN, "IN"}, // order matters
{POLLOUT, "OUT"}, // order matters {POLLOUT, "OUT"}, // order matters
@ -35,7 +35,5 @@ const char *DescribePollFlags(int x) {
{POLLWRBAND, "WRBAND"}, // {POLLWRBAND, "WRBAND"}, //
{POLLWRNORM, "WRNORM"}, // {POLLWRNORM, "WRNORM"}, //
}; };
static char pollflags[64]; return DescribeFlags(buf, size, kPollFlags, ARRAYLEN(kPollFlags), "POLL", x);
return DescribeFlags(pollflags, sizeof(pollflags), kPollFlags,
ARRAYLEN(kPollFlags), "POLL", x);
} }

View file

@ -0,0 +1,35 @@
/*-*- 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 2022 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/intrin/describeflags.internal.h"
#include "libc/macros.internal.h"
#include "libc/sysv/consts/seccomp.h"
const struct DescribeFlags kSeccompOperationFlags[] = {
{SECCOMP_GET_NOTIF_SIZES, "GET_NOTIF_SIZES"}, // order matters
{SECCOMP_GET_ACTION_AVAIL, "GET_ACTION_AVAIL"}, //
{SECCOMP_SET_MODE_FILTER, "SET_MODE_FILTER"}, //
{SECCOMP_SET_MODE_STRICT, "SET_MODE_STRICT"}, //
};
const char *DescribeSeccompOperationFlags(int x) {
static char seccompflags[128];
return DescribeFlags(seccompflags, sizeof(seccompflags),
kSeccompOperationFlags, ARRAYLEN(kSeccompOperationFlags),
"SECCOMP_", x);
}

View file

@ -21,6 +21,7 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/nexgen32e/vendor.internal.h" #include "libc/nexgen32e/vendor.internal.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/nr.h" #include "libc/sysv/consts/nr.h"
/** /**
@ -31,17 +32,18 @@
* *
* @param exitcode is masked with 255 * @param exitcode is masked with 255
* @asyncsignalsafe * @asyncsignalsafe
* @threadsafe
* @vforksafe * @vforksafe
* @noreturn * @noreturn
*/ */
privileged noinstrument noasan noubsan wontreturn void _Exit(int exitcode) { privileged wontreturn void _Exit(int exitcode) {
int i; int i;
STRACE("_Exit(%d)", exitcode); STRACE("_Exit(%d)", exitcode);
if (!IsWindows() && !IsMetal()) { if (!IsWindows() && !IsMetal()) {
asm volatile("syscall" asm volatile("syscall"
: /* no outputs */ : /* no outputs */
: "a"(__NR_exit_group), "D"(exitcode) : "a"(__NR_exit_group), "D"(exitcode)
: "memory"); : "rcx", "r11", "memory");
} else if (IsWindows()) { } else if (IsWindows()) {
__imp_ExitProcess(exitcode & 0xff); __imp_ExitProcess(exitcode & 0xff);
} }

47
libc/intrin/exit1.greg.c Normal file
View file

@ -0,0 +1,47 @@
/*-*- 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
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/calls/strace.internal.h"
#include "libc/dce.h"
#include "libc/nt/runtime.h"
#include "libc/nt/thread.h"
#include "libc/sysv/consts/nr.h"
/**
* Terminates thread with raw system call.
*
* @param rc only works on Linux and Windows
* @see cthread_exit()
* @threadsafe
* @noreturn
*/
privileged wontreturn void _Exit1(int rc) {
STRACE("_Exit1(%d)", rc);
if (!IsWindows() && !IsMetal()) {
asm volatile("syscall"
: /* no outputs */
: "a"(__NR_exit), "D"(IsLinux() ? rc : 0)
: "rcx", "r11", "memory");
__builtin_unreachable();
} else if (IsWindows()) {
ExitThread(rc);
}
for (;;) {
asm("ud2");
}
}

View file

@ -64,6 +64,8 @@ o/$(MODE)/libc/intrin/kprintf.greg.o: \
-ffreestanding \ -ffreestanding \
$(NO_MAGIC) $(NO_MAGIC)
o/$(MODE)/libc/intrin/exit.greg.o \
o/$(MODE)/libc/intrin/exit1.greg.o \
o/$(MODE)/libc/intrin/createfile.greg.o \ o/$(MODE)/libc/intrin/createfile.greg.o \
o/$(MODE)/libc/intrin/reopenfile.greg.o \ o/$(MODE)/libc/intrin/reopenfile.greg.o \
o/$(MODE)/libc/intrin/deletefile.greg.o \ o/$(MODE)/libc/intrin/deletefile.greg.o \

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/issandboxed.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/log/libfatal.internal.h" #include "libc/log/libfatal.internal.h"
#include "libc/log/log.h" #include "libc/log/log.h"
@ -35,24 +36,20 @@ noasan noubsan int IsDebuggerPresent(bool force) {
int fd, res; int fd, res;
ssize_t got; ssize_t got;
char *p, buf[1024]; char *p, buf[1024];
if (!force) { if (!force && IsGenuineCosmo()) return 0;
if (IsGenuineCosmo()) return 0; if (!force && getenv("HEISENDEBUG")) return 0;
if (getenv("HEISENDEBUG")) return 0; if (IsWindows()) return NtGetPeb()->BeingDebugged; /* needs noasan */
} if (__issandboxed) return false;
if (IsWindows()) { res = 0;
return NtGetPeb()->BeingDebugged; /* needs noasan */ if ((fd = __sysv_open("/proc/self/status", O_RDONLY, 0)) >= 0) {
} else { if ((got = __sysv_read(fd, buf, sizeof(buf) - 1)) > 0) {
res = 0; buf[got] = '\0';
if ((fd = __sysv_open("/proc/self/status", O_RDONLY, 0)) >= 0) { if ((p = __strstr(buf, kPid))) {
if ((got = __sysv_read(fd, buf, sizeof(buf) - 1)) > 0) { p += sizeof(kPid) - 1;
buf[got] = '\0'; res = __atoul(p);
if ((p = __strstr(buf, kPid))) {
p += sizeof(kPid) - 1;
res = __atoul(p);
}
} }
__sysv_close(fd);
} }
return res; __sysv_close(fd);
} }
return res;
} }

22
libc/intrin/issandboxed.c Normal file
View file

@ -0,0 +1,22 @@
/*-*- 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 2022 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/calls/calls.h"
// SECCOMP_SET_MODE_STRICT
bool __issandboxed;

View file

@ -33,9 +33,12 @@ kDos2Errno:
// .e kNtErrorFileNotFound,ENOENT # in consts.sh // .e kNtErrorFileNotFound,ENOENT # in consts.sh
// .e kNtErrorPathNotFound,ENOTDIR # in consts.sh // .e kNtErrorPathNotFound,ENOTDIR # in consts.sh
// .e kNtErrorTooManyOpenFiles,EMFILE # in consts.sh // .e kNtErrorTooManyOpenFiles,EMFILE # in consts.sh
// .e kNtErrorTooManyDescriptors,ENFILE # in consts.sh
// .e kNtErrorTooManyLinks,EMLINK # in consts.sh
// .e kNtErrorAccessDenied,EACCES # in consts.sh // .e kNtErrorAccessDenied,EACCES # in consts.sh
// .e kNtErrorInvalidHandle,EBADF # in consts.sh // .e kNtErrorInvalidHandle,EBADF # in consts.sh
// .e kNtErrorInvalidAccess,EPERM # in consts.sh // .e kNtErrorInvalidAccess,EPERM # in consts.sh
// .e kNtErrorNotEnoughQuota,EDQUOT # in consts.sh
// .e kNtErrorSeek,ESPIPE # in consts.sh // .e kNtErrorSeek,ESPIPE # in consts.sh
// .e kNtErrorNotDosDisk,ENOTBLK # in consts.sh // .e kNtErrorNotDosDisk,ENOTBLK # in consts.sh
// .e kNtErrorFileExists,EEXIST # in consts.sh // .e kNtErrorFileExists,EEXIST # in consts.sh
@ -48,7 +51,6 @@ kDos2Errno:
// .e kNtErrorAlreadyExists,EEXIST # in consts.sh // .e kNtErrorAlreadyExists,EEXIST # in consts.sh
// .e kNtErrorBadExeFormat,ENOEXEC # in consts.sh // .e kNtErrorBadExeFormat,ENOEXEC # in consts.sh
// .e kNtErrorFileTooLarge,EFBIG # in consts.sh // .e kNtErrorFileTooLarge,EFBIG # in consts.sh
// .e kNtErrorTooManyDescriptors,ENFILE # in consts.sh
// .e kNtErrorDirectoryNotSupported,EISDIR # in consts.sh // .e kNtErrorDirectoryNotSupported,EISDIR # in consts.sh
// .e kNtErrorInvalidAddress,EFAULT # in consts.sh // .e kNtErrorInvalidAddress,EFAULT # in consts.sh
// .e kNtErrorThreadNotInProcess,ESRCH # in consts.sh // .e kNtErrorThreadNotInProcess,ESRCH # in consts.sh
@ -160,6 +162,7 @@ kDos2Errno:
.e WSAEDISCON,EPIPE .e WSAEDISCON,EPIPE
.e WSAEFAULT,EFAULT .e WSAEFAULT,EFAULT
.e WSAEINVAL,EINVAL .e WSAEINVAL,EINVAL
.e WSAEDQUOT,EDQUOT
.e WSAEPROCLIM,ENOMEM .e WSAEPROCLIM,ENOMEM
.e WSANOTINITIALISED,ENETDOWN .e WSANOTINITIALISED,ENETDOWN
.e WSASYSNOTREADY,ENETDOWN .e WSASYSNOTREADY,ENETDOWN

View file

@ -21,6 +21,7 @@
#include "libc/bits/safemacros.internal.h" #include "libc/bits/safemacros.internal.h"
#include "libc/bits/weaken.h" #include "libc/bits/weaken.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/issandboxed.h"
#include "libc/calls/sigbits.h" #include "libc/calls/sigbits.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
@ -159,7 +160,7 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
} }
static int PrintBacktrace(int fd, const struct StackFrame *bp) { static int PrintBacktrace(int fd, const struct StackFrame *bp) {
if (!IsTiny()) { if (!IsTiny() && !__issandboxed) {
if (PrintBacktraceUsingAddr2line(fd, bp) != -1) { if (PrintBacktraceUsingAddr2line(fd, bp) != -1) {
return 0; return 0;
} }

View file

@ -17,7 +17,9 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/bits/weaken.h" #include "libc/bits/weaken.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/issandboxed.h"
#include "libc/calls/sigbits.h" #include "libc/calls/sigbits.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
@ -198,8 +200,10 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si,
names.version[0] = 0; names.version[0] = 0;
names.nodename[0] = 0; names.nodename[0] = 0;
__stpcpy(host, "unknown"); __stpcpy(host, "unknown");
gethostname(host, sizeof(host)); if (!__issandboxed) {
uname(&names); gethostname(host, sizeof(host));
uname(&names);
}
p = buf; p = buf;
errno = err; errno = err;
kprintf("%n%serror%s: Uncaught %G (%s) on %s pid %d%n" kprintf("%n%serror%s: Uncaught %G (%s) on %s pid %d%n"
@ -211,8 +215,8 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si,
ctx->uc_mcontext.rsp <= GetStaticStackAddr(0) + PAGESIZE)) ctx->uc_mcontext.rsp <= GetStaticStackAddr(0) + PAGESIZE))
? "Stack Overflow" ? "Stack Overflow"
: GetSiCodeName(sig, si->si_code), : GetSiCodeName(sig, si->si_code),
host, __getpid(), program_invocation_name, names.sysname, host, getpid(), program_invocation_name, names.sysname, names.version,
names.version, names.nodename, names.release); names.nodename, names.release);
if (ctx) { if (ctx) {
kprintf("%n"); kprintf("%n");
ShowFunctionCalls(ctx); ShowFunctionCalls(ctx);
@ -288,7 +292,8 @@ relegated noinstrument void __oncrash(int sig, struct siginfo *si,
DebugBreak(); DebugBreak();
} else if (__nocolor || g_isrunningundermake) { } else if (__nocolor || g_isrunningundermake) {
gdbpid = -1; gdbpid = -1;
} else if (!IsTiny() && IsLinux() && FindDebugBinary()) { } else if (!IsTiny() && IsLinux() && FindDebugBinary() &&
!__issandboxed) {
RestoreDefaultCrashSignalHandlers(); RestoreDefaultCrashSignalHandlers();
gdbpid = AttachDebugger( gdbpid = AttachDebugger(
((sig == SIGTRAP || sig == SIGQUIT) && ((sig == SIGTRAP || sig == SIGQUIT) &&

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/issandboxed.h"
#include "libc/calls/struct/termios.h" #include "libc/calls/struct/termios.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/errno.h" #include "libc/errno.h"
@ -51,10 +52,12 @@ const void *const g_oldtermios_ctor[] initarray = {
void __restore_tty(int fd) { void __restore_tty(int fd) {
int e; int e;
e = errno; if (!__issandboxed) {
if (g_oldtermios.c_lflag && !__nocolor && isatty(fd)) { e = errno;
write(fd, ANSI_RESTORE, strlen(ANSI_RESTORE)); if (g_oldtermios.c_lflag && !__nocolor && isatty(fd)) {
tcsetattr(fd, TCSAFLUSH, &g_oldtermios); write(fd, ANSI_RESTORE, strlen(ANSI_RESTORE));
tcsetattr(fd, TCSAFLUSH, &g_oldtermios);
}
errno = e;
} }
errno = e;
} }

View file

@ -194,7 +194,7 @@
#define kNtErrorEaListInconsistent 255 #define kNtErrorEaListInconsistent 255
#define kNtErrorNoMoreItems 259 #define kNtErrorNoMoreItems 259
#define kNtErrorCannotCopy 266 #define kNtErrorCannotCopy 266
#define kNtErrorDirectory 267 #define kNtErrorDirectory 267 /* EISDIR */
#define kNtErrorEasDidntFit 275 #define kNtErrorEasDidntFit 275
#define kNtErrorEaFileCorrupt 276 #define kNtErrorEaFileCorrupt 276
#define kNtErrorEaTableFull 277 #define kNtErrorEaTableFull 277
@ -238,7 +238,7 @@
#define kNtErrorNotRedundantStorage 333 #define kNtErrorNotRedundantStorage 333
#define kNtErrorResidentFileNotSupported 334 #define kNtErrorResidentFileNotSupported 334
#define kNtErrorCompressedFileNotSupported 335 #define kNtErrorCompressedFileNotSupported 335
#define kNtErrorDirectoryNotSupported 336 /* EISDIR */ #define kNtErrorDirectoryNotSupported 336
#define kNtErrorNotReadFromCopy 337 #define kNtErrorNotReadFromCopy 337
#define kNtErrorFtWriteFailure 338 #define kNtErrorFtWriteFailure 338
#define kNtErrorFtDiScanRequired 339 #define kNtErrorFtDiScanRequired 339
@ -1102,7 +1102,7 @@
#define kNtErrorResourceTypeNotFound 1813 #define kNtErrorResourceTypeNotFound 1813
#define kNtErrorResourceNameNotFound 1814 #define kNtErrorResourceNameNotFound 1814
#define kNtErrorResourceLangNotFound 1815 #define kNtErrorResourceLangNotFound 1815
#define kNtErrorNotEnoughQuota 1816 #define kNtErrorNotEnoughQuota 1816 /* EDQUOT */
#define kNtErrorInvalidTime 1901 #define kNtErrorInvalidTime 1901
#define kNtErrorInvalidFormName 1902 #define kNtErrorInvalidFormName 1902
#define kNtErrorInvalidFormSize 1903 #define kNtErrorInvalidFormSize 1903

View file

@ -0,0 +1,15 @@
.include "o/libc/nt/codegen.inc"
.imp kernel32,__imp_ExitThread,ExitThread,0
.text.windows
ExitThread:
push %rbp
mov %rsp,%rbp
.profilable
mov %rdi,%rcx
sub $32,%rsp
call *__imp_ExitThread(%rip)
leave
ret
.endfn ExitThread,globl
.previous

View file

@ -303,6 +303,7 @@ imp 'EnumerateLocalComputerNamesA' EnumerateLocalComputerNamesA kernel32 3
imp 'EraseTape' EraseTape kernel32 352 imp 'EraseTape' EraseTape kernel32 352
imp 'EscapeCommFunction' EscapeCommFunction kernel32 0 imp 'EscapeCommFunction' EscapeCommFunction kernel32 0
imp 'ExecuteUmsThread' ExecuteUmsThread kernel32 354 imp 'ExecuteUmsThread' ExecuteUmsThread kernel32 354
imp 'ExitThread' ExitThread kernel32 0 1
imp 'ExitProcess' ExitProcess kernel32 0 1 # a.k.a. RtlExitUserProcess imp 'ExitProcess' ExitProcess kernel32 0 1 # a.k.a. RtlExitUserProcess
imp 'ExitVDM' ExitVDM kernel32 357 imp 'ExitVDM' ExitVDM kernel32 357
imp 'ExpandEnvironmentStrings' ExpandEnvironmentStringsW kernel32 0 imp 'ExpandEnvironmentStrings' ExpandEnvironmentStringsW kernel32 0

View file

@ -87,13 +87,11 @@ privileged int clone(int (*f)(void *), void *stack, int flags, void *arg, ...) {
if (ax) return ax; if (ax) return ax;
asm volatile("xor\t%%ebp,%%ebp\n\t" asm volatile("xor\t%%ebp,%%ebp\n\t"
"pop\t%%rdi\n\t" "pop\t%%rdi\n\t"
"call\t%1" "call\t%0\n\t"
: "=a"(ax) "xchg\t%%eax,%%edi\n\t"
: "r"(func) "call\t_Exit1"
: "memory");
asm volatile("syscall"
: /* no outputs */ : /* no outputs */
: "a"(__NR_exit), "D"(ax) : "r"(func)
: "memory"); : "memory");
unreachable; unreachable;
} else if (IsWindows()) { } else if (IsWindows()) {

View file

@ -19,6 +19,7 @@
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/bits/bits.h" #include "libc/bits/bits.h"
#include "libc/bits/weaken.h" #include "libc/bits/weaken.h"
#include "libc/calls/issandboxed.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
@ -117,7 +118,7 @@ static struct SymbolTable *GetSymbolTableFromElf(void) {
struct SymbolTable *GetSymbolTable(void) { struct SymbolTable *GetSymbolTable(void) {
int ft, st; int ft, st;
struct Zipos *z; struct Zipos *z;
if (!g_symtab) { if (!g_symtab && !__issandboxed) {
ft = g_ftrace, g_ftrace = 0; ft = g_ftrace, g_ftrace = 0;
st = __strace, __strace = 0; st = __strace, __strace = 0;
if (weaken(__zipos_get) && (z = weaken(__zipos_get)())) { if (weaken(__zipos_get) && (z = weaken(__zipos_get)())) {

View file

@ -112,6 +112,14 @@ noasan static bool Automap(int n, int *res) {
} }
} }
noasan static size_t GetMemtrackSize(struct MemoryIntervals *mm) {
size_t i, n;
for (n = i = 0; i < mm->i; ++i) {
n += ((size_t)(mm->p[i].y - mm->p[i].x) + 1) << 16;
}
return n;
}
static noasan void *MapMemory(void *addr, size_t size, int prot, int flags, static noasan void *MapMemory(void *addr, size_t size, int prot, int flags,
int fd, int64_t off, int f, int x, int n) { int fd, int64_t off, int f, int x, int n) {
struct DirectMap dm; struct DirectMap dm;
@ -225,6 +233,7 @@ noasan void *mmap(void *addr, size_t size, int prot, int flags, int fd,
void *res; void *res;
char *p = addr; char *p = addr;
struct DirectMap dm; struct DirectMap dm;
size_t virtualused, virtualneed;
int a, b, i, f, m, n, x; int a, b, i, f, m, n, x;
if (UNLIKELY(!size)) { if (UNLIKELY(!size)) {
STRACE("size=0"); STRACE("size=0");
@ -268,6 +277,13 @@ noasan void *mmap(void *addr, size_t size, int prot, int flags, int fd,
} else if (__isfdkind(fd, kFdZip)) { } else if (__isfdkind(fd, kFdZip)) {
STRACE("fd is zipos handle"); STRACE("fd is zipos handle");
res = VIP(einval()); res = VIP(einval());
} else if (__virtualmax &&
(__builtin_add_overflow((virtualused = GetMemtrackSize(&_mmi)),
size, &virtualneed) ||
virtualneed > __virtualmax)) {
STRACE("%'zu size + %'zu inuse exceeds virtual memory limit %'zu", size,
virtualused, __virtualmax);
res = VIP(enomem());
} else { } else {
if (fd == -1) { if (fd == -1) {
size = ROUNDUP(size, FRAMESIZE); size = ROUNDUP(size, FRAMESIZE);

View file

@ -38,6 +38,7 @@ extern unsigned char *__relo_end[]; /* αpε */
extern uint8_t __zip_start[]; /* αpε */ extern uint8_t __zip_start[]; /* αpε */
extern uint8_t __zip_end[]; /* αpε */ extern uint8_t __zip_end[]; /* αpε */
extern bool ftrace_enabled; extern bool ftrace_enabled;
extern size_t __virtualmax;
void mcount(void); void mcount(void);
unsigned long getauxval(unsigned long); unsigned long getauxval(unsigned long);
@ -49,6 +50,7 @@ void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
void exit(int) wontreturn; void exit(int) wontreturn;
void _exit(int) libcesque wontreturn; void _exit(int) libcesque wontreturn;
void _Exit(int) libcesque wontreturn; void _Exit(int) libcesque wontreturn;
void _Exit1(int) libcesque wontreturn;
void quick_exit(int) wontreturn; void quick_exit(int) wontreturn;
void abort(void) wontreturn noinstrument; void abort(void) wontreturn noinstrument;
int __cxa_atexit(void *, void *, void *) libcesque; int __cxa_atexit(void *, void *, void *) libcesque;

View file

@ -58,7 +58,7 @@ ssize_t recv(int fd, void *buf, size_t size, int flags) {
} else { } else {
rc = ebadf(); rc = ebadf();
} }
STRACE("recv(%d, [%#.*hhs%s], %'zu, %#x) → %'ld% lm", fd, MAX(0, MIN(40, rc)), DATATRACE("recv(%d, [%#.*hhs%s], %'zu, %#x) → %'ld% lm", fd,
buf, rc > 40 ? "..." : "", size, flags); MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, flags);
return rc; return rc;
} }

View file

@ -74,7 +74,7 @@ ssize_t recvfrom(int fd, void *buf, size_t size, uint32_t flags,
} else { } else {
rc = ebadf(); rc = ebadf();
} }
STRACE("recvfrom(%d, [%#.*hhs%s], %'zu, %#x) → %'ld% lm", fd, DATATRACE("recvfrom(%d, [%#.*hhs%s], %'zu, %#x) → %'ld% lm", fd,
MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, flags, rc); MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, flags, rc);
return rc; return rc;
} }

View file

@ -60,7 +60,7 @@ ssize_t send(int fd, const void *buf, size_t size, int flags) {
} else { } else {
rc = ebadf(); rc = ebadf();
} }
STRACE("send(%d, %#.*hhs%s, %'zu, %#x) → %'ld% lm", fd, MAX(0, MIN(40, rc)), DATATRACE("send(%d, %#.*hhs%s, %'zu, %#x) → %'ld% lm", fd,
buf, rc > 40 ? "..." : "", size, flags, rc); MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, flags, rc);
return rc; return rc;
} }

View file

@ -87,8 +87,8 @@ ssize_t sendto(int fd, const void *buf, size_t size, uint32_t flags,
rc = ebadf(); rc = ebadf();
} }
} }
STRACE("sendto(%d, %#.*hhs%s, %'zu, %#x, %p, %u) → %'ld% lm", fd, DATATRACE("sendto(%d, %#.*hhs%s, %'zu, %#x, %p, %u) → %'ld% lm", fd,
MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, flags, opt_addr, MAX(0, MIN(40, rc)), buf, rc > 40 ? "..." : "", size, flags,
addrsize, rc); opt_addr, addrsize, rc);
return rc; return rc;
} }

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/macros.internal.inc"
.scall chroot,0x03d03d03d203d0a1,globl

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/macros.internal.inc"
.scall prctl,0xfffffffffffff09d,globl

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/macros.internal.inc"
.scall seccomp,0xfffffffffffff13d,globl

View file

@ -0,0 +1,2 @@
.include "o/libc/sysv/macros.internal.inc"
.scall sys_chroot,0x03d03d03d203d0a1,globl,hidden

View file

@ -47,15 +47,15 @@ syscon errno ENOTDIR 20 20 20 20 20 3 # not a directory; unix co
syscon errno EISDIR 21 21 21 21 21 267 # is a a directory; unix consensus; kNtErrorDirectory; raised by acct(2), copy_file_range(2), execve(2), ioctl_ficlonerange(2), ioctl_fideduperange(2), open(2), read(2), rename(2), truncate(2), unlink(2) syscon errno EISDIR 21 21 21 21 21 267 # is a a directory; unix consensus; kNtErrorDirectory; raised by acct(2), copy_file_range(2), execve(2), ioctl_ficlonerange(2), ioctl_fideduperange(2), open(2), read(2), rename(2), truncate(2), unlink(2)
syscon errno EINVAL 22 22 22 22 22 87 # invalid argument; unix consensus; kNtErrorInvalidParameter; raised by accept(2), access(2), add_key(2), adjtimex(2), arch_prctl(2), bdflush(2), bind(2), bpf(2), cacheflush(2), capget(2), chmod(2), chown(2), clock_getres(2), clock_nanosleep(2), clone(2), copy_file_range(2), create_module(2), dup(2), epoll_create(2), epoll_ctl(2), epoll_wait(2), eventfd(2), execve(2), execveat(2), fallocate(2), fanotify_init(2), fanotify_mark(2), fcntl(2), flock(2), futex(2), get_mempolicy(2), get_robust_list(2), getdents(2), getdomainname(2), getgroups(2), gethostname(2), getitimer(2), getpeername(2), getpriority(2), getrandom(2), getrlimit(2), getrusage(2), getsockname(2), getsockopt(2), gettimeofday(2), init_module(2), inotify_add_watch(2), inotify_init(2), inotify_rm_watch(2), io_cancel(2), io_destroy(2), io_getevents(2), io_setup(2), io_submit(2), ioctl(2), ioctl_console(2), ioctl_ficlonerange(2), ioctl_fideduperange(2), ioctl_getfsmap(2), ioctl_ns(2), ioctl_tty(2), ioctl_userfaultfd(2), ioperm(2), iopl(2), ioprio_set(2), kcmp(2), kexec_load(2), keyctl(2), kill(2), link(2), llseek(2), lookup_dcookie(2), lseek(2), madvise(2), mbind(2), membarrier(2), memfd_create(2), migrate_pages(2), mincore(2), mkdir(2), mknod(2), mlock(2), mmap(2), mmap2(2), modify_ldt(2), mount(2), move_pages(2), mprotect(2), mremap(2), msgctl(2), msgop(2), msync(2), nanosleep(2), open(2), open_by_handle_at(2), openat2(2), pciconfig_read(2), perf_event_open(2), personality(2), pidfd_getfd(2), pidfd_open(2), pidfd_send_signal(2), pipe(2), pivot_root(2), pkey_alloc(2), poll(2), posix_fadvise(2), prctl(2), process_vm_readv(2), ptrace(2), query_module(2), quotactl(2), read(2), readahead(2), readdir(2), readlink(2), readv(2), reboot(2), recv(2), recvmmsg(2), remap_file_pages(2), rename(2), request_key(2), rmdir(2), rt_sigqueueinfo(2), s390_guarded_storage(2), s390_pci_mmio_write(2), s390_runtime_instr(2), s390_sthyi(2), sched_get_priority_max(2), sched_rr_get_interval(2), sched_setaffinity(2), sched_setattr(2), sched_setparam(2), sched_setscheduler(2), seccomp(2), select(2), semctl(2), semget(2), semop(2), send(2), sendfile(2), set_mempolicy(2), set_thread_area(2), seteuid(2), setfsgid(2), setfsuid(2), setgid(2), setns(2), setpgid(2), setresuid(2), setreuid(2), setuid(2), shmctl(2), shmget(2), shmop(2), shutdown(2), sigaction(2), sigaltstack(2), signal(2), signalfd(2), sigprocmask(2), sigsuspend(2), sigwaitinfo(2), socket(2), splice(2), spu_create(2), spu_run(2), stat(2), statx(2), subpage_prot(2), swapon(2), sync_file_range(2), sysfs(2), syslog(2), tee(2), timer_create(2), timer_delete(2), timer_getoverrun(2), timer_settime(2), timerfd_create(2), tkill(2), truncate(2), umount(2), unlink(2), unshare(2), userfaultfd(2), ustat(2), utimensat(2), vmsplice(2), wait(2), write(2), unix(7), ip(7) syscon errno EINVAL 22 22 22 22 22 87 # invalid argument; unix consensus; kNtErrorInvalidParameter; raised by accept(2), access(2), add_key(2), adjtimex(2), arch_prctl(2), bdflush(2), bind(2), bpf(2), cacheflush(2), capget(2), chmod(2), chown(2), clock_getres(2), clock_nanosleep(2), clone(2), copy_file_range(2), create_module(2), dup(2), epoll_create(2), epoll_ctl(2), epoll_wait(2), eventfd(2), execve(2), execveat(2), fallocate(2), fanotify_init(2), fanotify_mark(2), fcntl(2), flock(2), futex(2), get_mempolicy(2), get_robust_list(2), getdents(2), getdomainname(2), getgroups(2), gethostname(2), getitimer(2), getpeername(2), getpriority(2), getrandom(2), getrlimit(2), getrusage(2), getsockname(2), getsockopt(2), gettimeofday(2), init_module(2), inotify_add_watch(2), inotify_init(2), inotify_rm_watch(2), io_cancel(2), io_destroy(2), io_getevents(2), io_setup(2), io_submit(2), ioctl(2), ioctl_console(2), ioctl_ficlonerange(2), ioctl_fideduperange(2), ioctl_getfsmap(2), ioctl_ns(2), ioctl_tty(2), ioctl_userfaultfd(2), ioperm(2), iopl(2), ioprio_set(2), kcmp(2), kexec_load(2), keyctl(2), kill(2), link(2), llseek(2), lookup_dcookie(2), lseek(2), madvise(2), mbind(2), membarrier(2), memfd_create(2), migrate_pages(2), mincore(2), mkdir(2), mknod(2), mlock(2), mmap(2), mmap2(2), modify_ldt(2), mount(2), move_pages(2), mprotect(2), mremap(2), msgctl(2), msgop(2), msync(2), nanosleep(2), open(2), open_by_handle_at(2), openat2(2), pciconfig_read(2), perf_event_open(2), personality(2), pidfd_getfd(2), pidfd_open(2), pidfd_send_signal(2), pipe(2), pivot_root(2), pkey_alloc(2), poll(2), posix_fadvise(2), prctl(2), process_vm_readv(2), ptrace(2), query_module(2), quotactl(2), read(2), readahead(2), readdir(2), readlink(2), readv(2), reboot(2), recv(2), recvmmsg(2), remap_file_pages(2), rename(2), request_key(2), rmdir(2), rt_sigqueueinfo(2), s390_guarded_storage(2), s390_pci_mmio_write(2), s390_runtime_instr(2), s390_sthyi(2), sched_get_priority_max(2), sched_rr_get_interval(2), sched_setaffinity(2), sched_setattr(2), sched_setparam(2), sched_setscheduler(2), seccomp(2), select(2), semctl(2), semget(2), semop(2), send(2), sendfile(2), set_mempolicy(2), set_thread_area(2), seteuid(2), setfsgid(2), setfsuid(2), setgid(2), setns(2), setpgid(2), setresuid(2), setreuid(2), setuid(2), shmctl(2), shmget(2), shmop(2), shutdown(2), sigaction(2), sigaltstack(2), signal(2), signalfd(2), sigprocmask(2), sigsuspend(2), sigwaitinfo(2), socket(2), splice(2), spu_create(2), spu_run(2), stat(2), statx(2), subpage_prot(2), swapon(2), sync_file_range(2), sysfs(2), syslog(2), tee(2), timer_create(2), timer_delete(2), timer_getoverrun(2), timer_settime(2), timerfd_create(2), tkill(2), truncate(2), umount(2), unlink(2), unshare(2), userfaultfd(2), ustat(2), utimensat(2), vmsplice(2), wait(2), write(2), unix(7), ip(7)
syscon errno ENFILE 23 23 23 23 23 331 # too many open files in system; unix consensus; kNtErrorTooManyDescriptors; raised by accept(2), acct(2), epoll_create(2), eventfd(2), execve(2), futex(2), inotify_init(2), memfd_create(2), mmap(2), open(2), pidfd_getfd(2), pidfd_open(2), pipe(2), shmget(2), signalfd(2), socket(2), socketpair(2), spu_create(2), swapon(2), timerfd_create(2), uselib(2), userfaultfd(2) syscon errno ENFILE 23 23 23 23 23 331 # too many open files in system; unix consensus; kNtErrorTooManyDescriptors; raised by accept(2), acct(2), epoll_create(2), eventfd(2), execve(2), futex(2), inotify_init(2), memfd_create(2), mmap(2), open(2), pidfd_getfd(2), pidfd_open(2), pipe(2), shmget(2), signalfd(2), socket(2), socketpair(2), spu_create(2), swapon(2), timerfd_create(2), uselib(2), userfaultfd(2)
syscon errno EMFILE 24 24 24 24 24 336 # too many open files; unix consensus; kNtErrorTooManyOpenFiles; raised by accept(2), dup(2), epoll_create(2), eventfd(2), execve(2), fanotify_init(2), fcntl(2), inotify_init(2), memfd_create(2), mount(2), open(2), perf_event_open(2), pidfd_getfd(2), pidfd_open(2), pipe(2), signalfd(2), socket(2), socketpair(2), spu_create(2), timerfd_create(2) syscon errno EMFILE 24 24 24 24 24 4 # too many open files; unix consensus; kNtErrorTooManyOpenFiles; raised by accept(2), dup(2), epoll_create(2), eventfd(2), execve(2), fanotify_init(2), fcntl(2), inotify_init(2), memfd_create(2), mount(2), open(2), perf_event_open(2), pidfd_getfd(2), pidfd_open(2), pipe(2), signalfd(2), socket(2), socketpair(2), spu_create(2), timerfd_create(2)
syscon errno ENOTTY 25 25 25 25 25 1118 # inappropriate i/o control operation; unix consensus; kNtErrorSerialNoDevice; raised by ioctl(2), ioctl_console(2), ioctl_fat(2), ioctl_ns(2), ioctl_tty(2) syscon errno ENOTTY 25 25 25 25 25 1118 # inappropriate i/o control operation; unix consensus; kNtErrorSerialNoDevice; raised by ioctl(2), ioctl_console(2), ioctl_fat(2), ioctl_ns(2), ioctl_tty(2)
syscon errno ETXTBSY 26 26 26 26 26 148 # won't open executable that's executing in write mode; try UnlockExecutable(); unix consensus; kNtErrorPathBusy; raised by access(2), copy_file_range(2), execve(2), fallocate(2), ioctl_ficlonerange(2), ioctl_fideduperange(2), mmap(2), open(2), truncate(2) syscon errno ETXTBSY 26 26 26 26 26 148 # won't open executable that's executing in write mode; try UnlockExecutable(); unix consensus; kNtErrorPathBusy; raised by access(2), copy_file_range(2), execve(2), fallocate(2), ioctl_ficlonerange(2), ioctl_fideduperange(2), mmap(2), open(2), truncate(2)
syscon errno EFBIG 27 27 27 27 27 223 # file too large; unix consensus; kNtErrorFileTooLarge; raised by copy_file_range(2), fallocate(2), init_module(2), open(2), semop(2), truncate(2), write(2) syscon errno EFBIG 27 27 27 27 27 223 # file too large; unix consensus; kNtErrorFileTooLarge; raised by copy_file_range(2), fallocate(2), init_module(2), open(2), semop(2), truncate(2), write(2)
syscon errno ENOSPC 28 28 28 28 28 39 # no space left on device; unix consensus; kNtErrorDiskFull; raised by copy_file_range(2), epoll_ctl(2), fallocate(2), fanotify_mark(2), fsync(2), inotify_add_watch(2), link(2), mkdir(2), mknod(2), msgget(2), open(2), perf_event_open(2), pkey_alloc(2), query_module(2), rename(2), semget(2), setxattr(2), shmget(2), spu_create(2), symlink(2), sync_file_range(2), write(2) syscon errno ENOSPC 28 28 28 28 28 39 # no space left on device; unix consensus; kNtErrorDiskFull; raised by copy_file_range(2), epoll_ctl(2), fallocate(2), fanotify_mark(2), fsync(2), inotify_add_watch(2), link(2), mkdir(2), mknod(2), msgget(2), open(2), perf_event_open(2), pkey_alloc(2), query_module(2), rename(2), semget(2), setxattr(2), shmget(2), spu_create(2), symlink(2), sync_file_range(2), write(2)
syscon errno EDQUOT 122 69 69 69 69 10069 # disk quota exceeded; bsd consensus; raised by add_key(2), keyctl(2), link(2), mkdir(2), mknod(2), open(2), rename(2), request_key(2), setxattr(2), symlink(2), write(2) syscon errno EDQUOT 122 69 69 69 69 1816 # disk quota exceeded; bsd consensus; kNtErrorNotEnoughQuota; raised by add_key(2), keyctl(2), link(2), mkdir(2), mknod(2), open(2), rename(2), request_key(2), setxattr(2), symlink(2), write(2)
syscon errno ESPIPE 29 29 29 29 29 25 # invalid seek; unix consensus; kNtErrorSeek; raised by fallocate(2), lseek(2), posix_fadvise(2), sendfile(2), splice(2), sync_file_range(2) syscon errno ESPIPE 29 29 29 29 29 25 # invalid seek; unix consensus; kNtErrorSeek; raised by fallocate(2), lseek(2), posix_fadvise(2), sendfile(2), splice(2), sync_file_range(2)
syscon errno EROFS 30 30 30 30 30 6009 # read-only filesystem; unix consensus; kNtErrorFileReadOnly; raised by access(2), acct(2), bind(2), chmod(2), chown(2), link(2), mkdir(2), mknod(2), mount(2), open(2), rename(2), rmdir(2), symlink(2), truncate(2), unlink(2), utime(2), utimensat(2) syscon errno EROFS 30 30 30 30 30 6009 # read-only filesystem; unix consensus; kNtErrorFileReadOnly; raised by access(2), acct(2), bind(2), chmod(2), chown(2), link(2), mkdir(2), mknod(2), mount(2), open(2), rename(2), rmdir(2), symlink(2), truncate(2), unlink(2), utime(2), utimensat(2)
syscon errno EMLINK 31 31 31 31 31 4 # too many links; unix consensus; kNtErrorTooManyLinks; raised by link(2), mkdir(2), rename(2) syscon errno EMLINK 31 31 31 31 31 1142 # too many links; unix consensus; kNtErrorTooManyLinks; raised by link(2), mkdir(2), rename(2)
syscon errno EPIPE 32 32 32 32 32 109 # broken pipe; unix consensus; kNtErrorBrokenPipe; raised by send(2), write(2), tcp(7), unix(7), ip(7) syscon errno EPIPE 32 32 32 32 32 109 # broken pipe; unix consensus; kNtErrorBrokenPipe; raised by send(2), write(2), tcp(7), unix(7), ip(7)
syscon errno EDOM 33 33 33 33 33 33 # mathematics argument out of domain of function; bsd consensus; fudged on NT; returned by cos(3), fmod(3), log1p(3), sin(3), tan(3), tgamma(3) syscon errno EDOM 33 33 33 33 33 33 # mathematics argument out of domain of function; bsd consensus; fudged on NT; returned by cos(3), fmod(3), log1p(3), sin(3), tan(3), tgamma(3)
syscon errno ERANGE 34 34 34 34 34 34 # result too large; bsd consensus; fudged on NT; raised by getxattr(2), listxattr(2), lookup_dcookie(2), prctl(2), quotactl(2), semctl(2), semop(2), setxattr(2) syscon errno ERANGE 34 34 34 34 34 34 # result too large; bsd consensus; fudged on NT; raised by getxattr(2), listxattr(2), lookup_dcookie(2), prctl(2), quotactl(2), semctl(2), semop(2), setxattr(2)
@ -125,9 +125,9 @@ syscon errno EOWNERDEAD 130 105 96 94 97 0 # raised by pthread_co
syscon errno ENOTRECOVERABLE 131 104 95 93 98 0 # raised by pthread_cond_timedwait(3), pthread_mutex_consistent(3), pthread_mutex_getprioceiling(3), pthread_mutex_lock(3), pthread_mutex_timedlock(3), pthread_mutexattr_getrobust(3), pthread_mutexattr_setrobust(3) syscon errno ENOTRECOVERABLE 131 104 95 93 98 0 # raised by pthread_cond_timedwait(3), pthread_mutex_consistent(3), pthread_mutex_getprioceiling(3), pthread_mutex_lock(3), pthread_mutex_timedlock(3), pthread_mutexattr_getrobust(3), pthread_mutexattr_setrobust(3)
syscon errno ENONET 64 0 0 0 0 0 # unilateral; raised by accept(2) syscon errno ENONET 64 0 0 0 0 0 # unilateral; raised by accept(2)
syscon errno ERESTART 85 -1 -1 -1 -3 0 # should only be seen in ptrace() syscon errno ERESTART 85 -1 -1 -1 -3 0 # should only be seen in ptrace()
syscon errno ENODATA 61 96 0 0 89 232 # no message is available in xsi stream or named pipe is being closed; no data available; barely in posix; returned by ioctl; very close in spirit to EPIPE?
syscon errno ENOSR 63 98 0 90 90 0 # out of streams resources; something like EAGAIN; it's in POSIX; maybe some commercial UNIX returns it with openat, putmsg, putpmsg, posix_openpt, ioctl, open syscon errno ENOSR 63 98 0 90 90 0 # out of streams resources; something like EAGAIN; it's in POSIX; maybe some commercial UNIX returns it with openat, putmsg, putpmsg, posix_openpt, ioctl, open
syscon errno ENOSTR 60 99 0 0 91 0 # not a stream; returned by getmsg, putmsg, putpmsg, getpmsg syscon errno ENOSTR 60 99 0 0 91 0 # not a stream; returned by getmsg, putmsg, putpmsg, getpmsg
syscon errno ENODATA 61 96 0 0 89 232 # no message is available in xsi stream or named pipe is being closed; no data available; barely in posix; returned by ioctl; very close in spirit to EPIPE?
syscon errno EMULTIHOP 72 95 90 0 94 0 # barely in posix syscon errno EMULTIHOP 72 95 90 0 94 0 # barely in posix
syscon errno ENOLINK 67 97 91 0 95 0 # barely in posix syscon errno ENOLINK 67 97 91 0 95 0 # barely in posix
syscon errno ENOMEDIUM 123 0 0 85 0 0 # not posix; not documented syscon errno ENOMEDIUM 123 0 0 85 0 0 # not posix; not documented
@ -187,6 +187,7 @@ syscon open O_CREAT 0x00000040 0x00000200 0x00000200 0x00000200 0x000002
syscon open O_EXCL 0x00000080 0x00000800 0x00000800 0x00000800 0x00000800 0x00000080 # bsd consensus & NT faked as Linux [SYNC libc/calls/open-nt.c] syscon open O_EXCL 0x00000080 0x00000800 0x00000800 0x00000800 0x00000800 0x00000080 # bsd consensus & NT faked as Linux [SYNC libc/calls/open-nt.c]
syscon open O_TRUNC 0x00000200 0x00000400 0x00000400 0x00000400 0x00000400 0x00000200 # bsd consensus & NT faked as Linux [SYNC libc/calls/open-nt.c] syscon open O_TRUNC 0x00000200 0x00000400 0x00000400 0x00000400 0x00000400 0x00000200 # bsd consensus & NT faked as Linux [SYNC libc/calls/open-nt.c]
syscon open O_DIRECTORY 0x00010000 0x00100000 0x00020000 0x00020000 0x00200000 0x00010000 # useful hint on UNIX, but required on NT (see kNtFileFlagBackupSemantics) [SYNC libc/calls/open-nt.c] syscon open O_DIRECTORY 0x00010000 0x00100000 0x00020000 0x00020000 0x00200000 0x00010000 # useful hint on UNIX, but required on NT (see kNtFileFlagBackupSemantics) [SYNC libc/calls/open-nt.c]
syscon open O_NOFOLLOW 0x00020000 0x00000100 0x00000100 0x00000100 0x00000100 0x00020000 # bsd consensus; kNtFileFlagOpenReparsePoint
syscon open O_DIRECT 0x00004000 0 0x00010000 0 0x00080000 0x00004000 # kNtFileFlagNoBuffering [SYNC libc/calls/open-nt.c] syscon open O_DIRECT 0x00004000 0 0x00010000 0 0x00080000 0x00004000 # kNtFileFlagNoBuffering [SYNC libc/calls/open-nt.c]
syscon open O_NDELAY 0x00000800 0x00000004 0x00000004 0x00000004 0x00000004 0x00000800 # kNtFileFlagWriteThrough [SYNC libc/calls/open-nt.c] syscon open O_NDELAY 0x00000800 0x00000004 0x00000004 0x00000004 0x00000004 0x00000800 # kNtFileFlagWriteThrough [SYNC libc/calls/open-nt.c]
syscon open O_RANDOM 0 0 0 0 0 0x80000000 # kNtFileFlagRandomAccess [SYNC libc/calls/open-nt.c] syscon open O_RANDOM 0 0 0 0 0 0x80000000 # kNtFileFlagRandomAccess [SYNC libc/calls/open-nt.c]
@ -198,7 +199,6 @@ syscon open O_TMPFILE 0x00410000 0 0 0 0 0x00410000 # Linux 3.11+ (
syscon open O_SPARSE 0 0 0 0 0 0 # wut syscon open O_SPARSE 0 0 0 0 0 0 # wut
syscon open O_NONBLOCK 0x00000800 0x00000004 0x00000004 0x00000004 0x00000004 0x00000800 # bsd consensus syscon open O_NONBLOCK 0x00000800 0x00000004 0x00000004 0x00000004 0x00000004 0x00000800 # bsd consensus
syscon open O_ASYNC 0x00002000 0x00000040 0x00000040 0x00000040 0x00000040 0 # bsd consensus syscon open O_ASYNC 0x00002000 0x00000040 0x00000040 0x00000040 0x00000040 0 # bsd consensus
syscon open O_NOFOLLOW 0x00020000 0x00000100 0x00000100 0x00000100 0x00000100 0 # bsd consensus
syscon open O_NOFOLLOW_ANY 0 0x20000000 0 0 0 0 # syscon open O_NOFOLLOW_ANY 0 0x20000000 0 0 0 0 #
syscon open O_SYNC 0x00101000 0x00000080 0x00000080 0x00000080 0x00000080 0 # bsd consensus syscon open O_SYNC 0x00101000 0x00000080 0x00000080 0x00000080 0x00000080 0 # bsd consensus
syscon open O_NOCTTY 0x00000100 0x00020000 0x00008000 0x00008000 0x00008000 0 # used for remote viewing (default behavior on freebsd) syscon open O_NOCTTY 0x00000100 0x00020000 0x00008000 0x00008000 0x00008000 0 # used for remote viewing (default behavior on freebsd)
@ -512,7 +512,7 @@ syscon rlimit RLIMIT_RSS 5 5 5 5 5 127 # max physical memory size
syscon rlimit RLIMIT_NPROC 6 7 7 7 7 127 # max number of processes; see fork()→EAGAIN; bsd consensus syscon rlimit RLIMIT_NPROC 6 7 7 7 7 127 # max number of processes; see fork()→EAGAIN; bsd consensus
syscon rlimit RLIMIT_NOFILE 7 8 8 8 8 127 # max number of open files; see accept()→EMFILE/ENFILE; bsd consensus syscon rlimit RLIMIT_NOFILE 7 8 8 8 8 127 # max number of open files; see accept()→EMFILE/ENFILE; bsd consensus
syscon rlimit RLIMIT_MEMLOCK 8 6 6 6 6 127 # max locked-in-memory address space; bsd consensus syscon rlimit RLIMIT_MEMLOCK 8 6 6 6 6 127 # max locked-in-memory address space; bsd consensus
syscon rlimit RLIMIT_AS 9 5 10 127 10 127 # max virtual memory size in bytes; this one actually works; we set this to RLIMIT_DATA on OpenBSD syscon rlimit RLIMIT_AS 9 5 10 2 10 9 # max virtual memory size in bytes; this one actually works; fudged as RLIMIT_DATA on OpenBSD
syscon rlimit RLIMIT_LOCKS 10 127 127 127 127 127 # max flock() / fcntl() locks; bsd consensus syscon rlimit RLIMIT_LOCKS 10 127 127 127 127 127 # max flock() / fcntl() locks; bsd consensus
syscon rlimit RLIMIT_SIGPENDING 11 127 127 127 127 127 # max sigqueue() can enqueue; bsd consensus syscon rlimit RLIMIT_SIGPENDING 11 127 127 127 127 127 # max sigqueue() can enqueue; bsd consensus
syscon rlimit RLIMIT_MSGQUEUE 12 127 127 127 127 127 # meh posix message queues; bsd consensus syscon rlimit RLIMIT_MSGQUEUE 12 127 127 127 127 127 # meh posix message queues; bsd consensus
@ -953,109 +953,6 @@ syscon iproto IPPROTO_BEETPH 94 0 0 0 0 0
syscon iproto IPPROTO_COMP 108 0 0 0 0 0 syscon iproto IPPROTO_COMP 108 0 0 0 0 0
syscon iproto IPPROTO_DCCP 33 0 0 0 0 0 syscon iproto IPPROTO_DCCP 33 0 0 0 0 0
syscon pr PR_SET_PTRACER_ANY -1 0 0 0 0 0
syscon pr PR_ENDIAN_BIG 0 0 0 0 0 0 # consensus
syscon pr PR_FP_EXC_DISABLED 0 0 0 0 0 0 # consensus
syscon pr PR_MCE_KILL_CLEAR 0 0 0 0 0 0 # consensus
syscon pr PR_MCE_KILL_LATE 0 0 0 0 0 0 # consensus
syscon pr PR_SPEC_NOT_AFFECTED 0 0 0 0 0 0 # consensus
syscon pr PR_SPEC_STORE_BYPASS 0 0 0 0 0 0 # consensus
syscon pr PR_TIMING_STATISTICAL 0 0 0 0 0 0 # consensus
syscon pr PR_CAP_AMBIENT_IS_SET 1 0 0 0 0 0
syscon pr PR_ENDIAN_LITTLE 1 0 0 0 0 0
syscon pr PR_FPEMU_NOPRINT 1 0 0 0 0 0
syscon pr PR_FP_EXC_NONRECOV 1 0 0 0 0 0
syscon pr PR_FP_MODE_FR 1 0 0 0 0 0
syscon pr PR_MCE_KILL_EARLY 1 0 0 0 0 0
syscon pr PR_MCE_KILL_SET 1 0 0 0 0 0
syscon pr PR_SET_MM_START_CODE 1 0 0 0 0 0
syscon pr PR_SET_PDEATHSIG 1 0 0 0 0 0
syscon pr PR_SPEC_PRCTL 1 0 0 0 0 0
syscon pr PR_TIMING_TIMESTAMP 1 0 0 0 0 0
syscon pr PR_TSC_ENABLE 1 0 0 0 0 0
syscon pr PR_UNALIGN_NOPRINT 1 0 0 0 0 0
syscon pr PR_CAP_AMBIENT_RAISE 2 0 0 0 0 0
syscon pr PR_ENDIAN_PPC_LITTLE 2 0 0 0 0 0
syscon pr PR_FPEMU_SIGFPE 2 0 0 0 0 0
syscon pr PR_FP_EXC_ASYNC 2 0 0 0 0 0
syscon pr PR_FP_MODE_FRE 2 0 0 0 0 0
syscon pr PR_GET_PDEATHSIG 2 0 0 0 0 0
syscon pr PR_MCE_KILL_DEFAULT 2 0 0 0 0 0
syscon pr PR_SET_MM_END_CODE 2 0 0 0 0 0
syscon pr PR_SPEC_ENABLE 2 0 0 0 0 0
syscon pr PR_TSC_SIGSEGV 2 0 0 0 0 0
syscon pr PR_UNALIGN_SIGBUS 2 0 0 0 0 0
syscon pr PR_CAP_AMBIENT_LOWER 3 0 0 0 0 0
syscon pr PR_FP_EXC_PRECISE 3 0 0 0 0 0
syscon pr PR_GET_DUMPABLE 3 0 0 0 0 0
syscon pr PR_SET_MM_START_DATA 3 0 0 0 0 0
syscon pr PR_CAP_AMBIENT_CLEAR_ALL 4 0 0 0 0 0
syscon pr PR_SET_DUMPABLE 4 0 0 0 0 0
syscon pr PR_SET_MM_END_DATA 4 0 0 0 0 0
syscon pr PR_SPEC_DISABLE 4 0 0 0 0 0
syscon pr PR_GET_UNALIGN 5 0 0 0 0 0
syscon pr PR_SET_MM_START_STACK 5 0 0 0 0 0
syscon pr PR_SET_MM_START_BRK 6 0 0 0 0 0
syscon pr PR_SET_UNALIGN 6 0 0 0 0 0
syscon pr PR_GET_KEEPCAPS 7 0 0 0 0 0
syscon pr PR_SET_MM_BRK 7 0 0 0 0 0
syscon pr PR_SET_KEEPCAPS 8 0 0 0 0 0
syscon pr PR_SET_MM_ARG_START 8 0 0 0 0 0
syscon pr PR_SPEC_FORCE_DISABLE 8 0 0 0 0 0
syscon pr PR_GET_FPEMU 9 0 0 0 0 0
syscon pr PR_SET_MM_ARG_END 9 0 0 0 0 0
syscon pr PR_SET_FPEMU 10 0 0 0 0 0
syscon pr PR_SET_MM_ENV_START 10 0 0 0 0 0
syscon pr PR_GET_FPEXC 11 0 0 0 0 0
syscon pr PR_SET_MM_ENV_END 11 0 0 0 0 0
syscon pr PR_SET_FPEXC 12 0 0 0 0 0
syscon pr PR_SET_MM_AUXV 12 0 0 0 0 0
syscon pr PR_GET_TIMING 13 0 0 0 0 0
syscon pr PR_SET_MM_EXE_FILE 13 0 0 0 0 0
syscon pr PR_SET_MM_MAP 14 0 0 0 0 0
syscon pr PR_SET_TIMING 14 0 0 0 0 0
syscon pr PR_SET_MM_MAP_SIZE 15 0 0 0 0 0
syscon pr PR_SET_NAME 15 0 0 0 0 0
syscon pr PR_GET_NAME 0x10 0 0 0 0 0
syscon pr PR_GET_ENDIAN 19 0 0 0 0 0
syscon pr PR_SET_ENDIAN 20 0 0 0 0 0
syscon pr PR_GET_SECCOMP 21 0 0 0 0 0
syscon pr PR_SET_SECCOMP 22 0 0 0 0 0
syscon pr PR_CAPBSET_READ 23 0 0 0 0 0
syscon pr PR_CAPBSET_DROP 24 0 0 0 0 0
syscon pr PR_GET_TSC 25 0 0 0 0 0
syscon pr PR_SET_TSC 26 0 0 0 0 0
syscon pr PR_GET_SECUREBITS 27 0 0 0 0 0
syscon pr PR_SET_SECUREBITS 28 0 0 0 0 0
syscon pr PR_SET_TIMERSLACK 29 0 0 0 0 0
syscon pr PR_GET_TIMERSLACK 30 0 0 0 0 0
syscon pr PR_TASK_PERF_EVENTS_DISABLE 31 0 0 0 0 0
syscon pr PR_TASK_PERF_EVENTS_ENABLE 0x20 0 0 0 0 0
syscon pr PR_MCE_KILL 33 0 0 0 0 0
syscon pr PR_MCE_KILL_GET 34 0 0 0 0 0
syscon pr PR_SET_MM 35 0 0 0 0 0
syscon pr PR_SET_CHILD_SUBREAPER 36 0 0 0 0 0
syscon pr PR_GET_CHILD_SUBREAPER 37 0 0 0 0 0
syscon pr PR_SET_NO_NEW_PRIVS 38 0 0 0 0 0
syscon pr PR_GET_NO_NEW_PRIVS 39 0 0 0 0 0
syscon pr PR_GET_TID_ADDRESS 40 0 0 0 0 0
syscon pr PR_SET_THP_DISABLE 41 0 0 0 0 0
syscon pr PR_GET_THP_DISABLE 42 0 0 0 0 0
syscon pr PR_MPX_ENABLE_MANAGEMENT 43 0 0 0 0 0
syscon pr PR_MPX_DISABLE_MANAGEMENT 44 0 0 0 0 0
syscon pr PR_SET_FP_MODE 45 0 0 0 0 0
syscon pr PR_GET_FP_MODE 46 0 0 0 0 0
syscon pr PR_CAP_AMBIENT 47 0 0 0 0 0
syscon pr PR_GET_SPECULATION_CTRL 52 0 0 0 0 0
syscon pr PR_SET_SPECULATION_CTRL 53 0 0 0 0 0
syscon pr PR_FP_EXC_SW_ENABLE 0x80 0 0 0 0 0
syscon pr PR_FP_EXC_DIV 0x010000 0 0 0 0 0
syscon pr PR_FP_EXC_OVF 0x020000 0 0 0 0 0
syscon pr PR_FP_EXC_UND 0x040000 0 0 0 0 0
syscon pr PR_FP_EXC_RES 0x080000 0 0 0 0 0
syscon pr PR_FP_EXC_INV 0x100000 0 0 0 0 0
syscon pr PR_SET_PTRACER 0x59616d61 0 0 0 0 0
syscon sio SIOCADDMULTI 0x8931 0x80206931 0x80206931 0x80206931 0x80206931 0 # bsd consensus syscon sio SIOCADDMULTI 0x8931 0x80206931 0x80206931 0x80206931 0x80206931 0 # bsd consensus
syscon sio SIOCATMARK 0x8905 0x40047307 0x40047307 0x40047307 0x40047307 0 # bsd consensus syscon sio SIOCATMARK 0x8905 0x40047307 0x40047307 0x40047307 0x40047307 0 # bsd consensus
syscon sio SIOCDELMULTI 0x8932 0x80206932 0x80206932 0x80206932 0x80206932 0 # bsd consensus syscon sio SIOCDELMULTI 0x8932 0x80206932 0x80206932 0x80206932 0x80206932 0 # bsd consensus
@ -1987,8 +1884,8 @@ syscon misc FALLOC_FL_UNSHARE_RANGE 0x40 -1 -1 -1 -1 -1 # bsd cons
# System Call Numbers. # System Call Numbers.
# #
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology # group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology
syscon nr __NR_exit 0x003c 0x2000001 0x0001 0x0001 0x001 0xfff syscon nr __NR_exit 0x003c 0x2000169 0x01af 0x012e 0x136 0xfff # __bsdthread_terminate() on XNU, thr_exit() on FreeBSD, sys___threxit() on OpenBSD, __lwp_exit() on NetBSD
syscon nr __NR_exit_group 0x00e7 0x2000001 0x0001 0x0001 0x001 0xfff syscon nr __NR_exit_group 0x00e7 0x2000001 0x0001 0x0001 0x001 0xfff
syscon nr __NR_read 0x0000 0x2000003 0x0003 0x0003 0x003 0xfff syscon nr __NR_read 0x0000 0x2000003 0x0003 0x0003 0x003 0xfff
syscon nr __NR_write 0x0001 0x2000004 0x0004 0x0004 0x004 0xfff syscon nr __NR_write 0x0001 0x2000004 0x0004 0x0004 0x004 0xfff
syscon nr __NR_open 0x0002 0x2000005 0x0005 0x0005 0x005 0xfff syscon nr __NR_open 0x0002 0x2000005 0x0005 0x0005 0x005 0xfff

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h" #include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EDQUOT,122,69,69,69,69,10069 .syscon errno,EDQUOT,122,69,69,69,69,1816

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h" #include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EMFILE,24,24,24,24,24,336 .syscon errno,EMFILE,24,24,24,24,24,4

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h" #include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EMLINK,31,31,31,31,31,4 .syscon errno,EMLINK,31,31,31,31,31,1142

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h" #include "libc/sysv/consts/syscon.internal.h"
.syscon open,O_NOFOLLOW,0x00020000,0x00000100,0x00000100,0x00000100,0x00000100,0 .syscon open,O_NOFOLLOW,0x00020000,0x00000100,0x00000100,0x00000100,0x00000100,0x00020000

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_CAPBSET_DROP,24,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_CAPBSET_READ,23,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_CAP_AMBIENT,47,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_CAP_AMBIENT_CLEAR_ALL,4,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_CAP_AMBIENT_IS_SET,1,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_CAP_AMBIENT_LOWER,3,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_CAP_AMBIENT_RAISE,2,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_ENDIAN_BIG,0,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_ENDIAN_LITTLE,1,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_ENDIAN_PPC_LITTLE,2,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FPEMU_NOPRINT,1,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FPEMU_SIGFPE,2,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_ASYNC,2,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_DISABLED,0,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_DIV,0x010000,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_INV,0x100000,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_NONRECOV,1,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_OVF,0x020000,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_PRECISE,3,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_RES,0x080000,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_SW_ENABLE,0x80,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_EXC_UND,0x040000,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_MODE_FR,1,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_FP_MODE_FRE,2,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_CHILD_SUBREAPER,37,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_DUMPABLE,3,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_ENDIAN,19,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_FPEMU,9,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_FPEXC,11,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_FP_MODE,46,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_KEEPCAPS,7,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_NAME,0x10,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_NO_NEW_PRIVS,39,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_PDEATHSIG,2,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_SECCOMP,21,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_SECUREBITS,27,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_SPECULATION_CTRL,52,0,0,0,0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon pr,PR_GET_THP_DISABLE,42,0,0,0,0,0

Some files were not shown because too many files have changed in this diff Show more