Make improvements

- Add rusage to redbean Lua API
- Add more redbean documentation
- Add pledge() to redbean Lua API
- Polyfill OpenBSD pledge() for Linux
- Increase PATH_MAX limit to 1024 characters
- Untrack sibling processes after fork() on Windows
This commit is contained in:
Justine Tunney 2022-04-28 09:42:36 -07:00
parent 9a6bd304a5
commit 47b3274665
212 changed files with 2251 additions and 834 deletions

View file

@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
char *exepath;
struct rusage r;
long double real;
char exebuf[PATH_MAX + 1];
char exebuf[PATH_MAX];
if (argc >= 2) {
if ((exepath = commandv(argv[1], exebuf, sizeof(exebuf)))) {
real = nowl();

View file

@ -17,6 +17,10 @@
#include "libc/sysv/consts/s.h"
#include "libc/sysv/consts/sig.h"
#define _POSIX_VERSION 200809L
#define _POSIX2_VERSION _POSIX_VERSION
#define _XOPEN_VERSION 700
#define EOF -1 /* end of file */
#define WEOF -1u /* end of file (multibyte) */
#define _IOFBF 0 /* fully buffered */
@ -48,14 +52,14 @@
#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)
#define WCOREDUMP(s) ((s)&0x80)
#define WEXITSTATUS(s) (((s)&0xff00) >> 8)
#define WCOREDUMP(s) (0x80 & (s))
#define WEXITSTATUS(s) ((0xff00 & (s)) >> 8)
#define WIFCONTINUED(s) ((s) == 0xffff)
#define WIFEXITED(s) (!WTERMSIG(s))
#define WIFSIGNALED(s) (((s)&0xffff) - 1u < 0xffu)
#define WIFSTOPPED(s) ((short)((((s)&0xffff) * 0x10001) >> 8) > 0x7f00)
#define WIFSIGNALED(s) ((0xffff & (s)) - 1u < 0xffu)
#define WIFSTOPPED(s) ((short)(((0xffff & (s)) * 0x10001) >> 8) > 0x7f00)
#define WSTOPSIG(s) WEXITSTATUS(s)
#define WTERMSIG(s) ((s)&0x7f)
#define WTERMSIG(s) (127 & (s))
#define W_STOPCODE(s) ((s) << 8 | 0177)
#if !(__ASSEMBLER__ + __LINKER__ + 0)
@ -182,6 +186,8 @@ int setpriority(int, unsigned, int);
int setregid(uint32_t, uint32_t);
int setresgid(uint32_t, uint32_t, uint32_t);
int setresuid(uint32_t, uint32_t, uint32_t);
int getresgid(uint32_t *, uint32_t *, uint32_t *);
int getresuid(uint32_t *, uint32_t *, uint32_t *);
int setreuid(uint32_t, uint32_t);
int setrlimit(int, const struct rlimit *);
int setsid(void);
@ -233,6 +239,7 @@ ssize_t write(int, const void *, size_t);
struct dirent *readdir(DIR *);
void rewinddir(DIR *);
void sync(void);
int pledge(const char *, const char *);
int clone(int (*)(void *), void *, size_t, int, void *, int *, void *, size_t,
int *);

View file

@ -109,6 +109,7 @@ o//libc/calls/fcntl.o: \
o/$(MODE)/libc/calls/execl.o \
o/$(MODE)/libc/calls/execle.o \
o/$(MODE)/libc/calls/execlp.o \
o/$(MODE)/libc/calls/copyfile.o \
o/$(MODE)/libc/calls/execve-nt.o \
o/$(MODE)/libc/calls/execve-sysv.o \
o/$(MODE)/libc/calls/readlinkat-nt.o \

View file

@ -29,7 +29,7 @@
textwindows int sys_chdir_nt(const char *path) {
uint32_t n;
int e, ms, err, len;
char16_t path16[PATH_MAX + 1], var[4];
char16_t path16[PATH_MAX], var[4];
if ((len = __mkntpath(path, path16)) == -1) return -1;
if (!len) return enoent();
if (len && path16[len - 1] != u'\\') {

View file

@ -28,6 +28,7 @@
#include "libc/nt/enum/filesharemode.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/nt/struct/filetime.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/o.h"
@ -37,7 +38,7 @@ static textwindows int sys_copyfile_nt(const char *src, const char *dst,
int flags) {
int64_t fhsrc, fhdst;
struct NtFileTime accessed, modified;
char16_t src16[PATH_MAX + 1], dst16[PATH_MAX + 1];
char16_t src16[PATH_MAX], dst16[PATH_MAX];
if (__mkntpath(src, src16) == -1) return -1;
if (__mkntpath(dst, dst16) == -1) return -1;
if (CopyFile(src16, dst16, !!(flags & COPYFILE_NOCLOBBER))) {

View file

@ -39,7 +39,7 @@ int execlp(const char *prog, const char *arg, ... /*, NULL*/) {
char *exe;
char **argv;
va_list va, vb;
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
if (!(exe = commandv(prog, pathbuf, sizeof(pathbuf)))) return -1;
va_copy(vb, va);
va_start(va, arg);

View file

@ -33,8 +33,8 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
shargs = alloca((i + 2) * sizeof(char *));
memcpy(shargs + 2, argv + 1, i * sizeof(char *));
if (IsFreebsd() || IsNetbsd()) {
shargs[0] = firstnonnull(
commandv("bash", alloca(PATH_MAX + 1), PATH_MAX + 1), _PATH_BSHELL);
shargs[0] = firstnonnull(commandv("bash", alloca(PATH_MAX), PATH_MAX),
_PATH_BSHELL);
} else {
shargs[0] = _PATH_BSHELL;
}

View file

@ -36,7 +36,7 @@
*/
int execvpe(const char *prog, char *const argv[], char *const *envp) {
char *exe;
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
if (IsAsan() && !__asan_is_valid(prog, 1)) return efault();
if (!(exe = commandv(prog, pathbuf, sizeof(pathbuf)))) return -1;
return execve(exe, argv, envp);

View file

@ -21,8 +21,9 @@
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
int sys_faccessat_nt(int dirfd, const char *path, int mode, uint32_t flags) {
char16_t path16[PATH_MAX + 1];
textwindows int sys_faccessat_nt(int dirfd, const char *path, int mode,
uint32_t flags) {
char16_t path16[PATH_MAX];
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
return __fix_enotdir(ntaccesscheck(path16, mode), path16);
}

View file

@ -24,7 +24,7 @@
textwindows int sys_fchdir_nt(int dirfd) {
uint32_t len;
char16_t dir[PATH_MAX + 1];
char16_t dir[PATH_MAX];
if (!__isfdkind(dirfd, kFdFile)) return ebadf();
len = GetFinalPathNameByHandle(g_fds.p[dirfd].handle, dir, ARRAYLEN(dir),
kNtFileNameNormalized | kNtVolumeNameDos);

View file

@ -23,7 +23,7 @@
textwindows int sys_fchmodat_nt(int dirfd, const char *path, uint32_t mode,
int flags) {
uint32_t attr;
uint16_t path16[PATH_MAX + 1];
uint16_t path16[PATH_MAX];
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
if ((attr = GetFileAttributes(path16)) != -1u) {
if (mode & 0200) {

View file

@ -48,7 +48,7 @@ bool fileexists(const char *path) {
bool res;
union metastat st;
struct ZiposUri zipname;
uint16_t path16[PATH_MAX + 1];
uint16_t path16[PATH_MAX];
e = errno;
if (IsAsan() && !__asan_is_valid(path, 1)) {
efault();

View file

@ -29,7 +29,7 @@ textwindows int sys_fstatat_nt(int dirfd, const char *path, struct stat *st,
int flags) {
int rc;
int64_t fh;
uint16_t path16[PATH_MAX + 1];
uint16_t path16[PATH_MAX];
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
if ((fh = CreateFile(
path16, kNtFileReadAttributes, 0, 0, kNtOpenExisting,

View file

@ -28,7 +28,7 @@ textwindows char *sys_getcwd_nt(char *buf, size_t size) {
uint64_t w;
wint_t x, y;
uint32_t n, i, j;
char16_t p[PATH_MAX + 1];
char16_t p[PATH_MAX];
if ((n = GetCurrentDirectory(ARRAYLEN(p), p))) {
if (4 + n + 1 <= size && 4 + n + 1 <= ARRAYLEN(p)) {
tprecode16to8(buf, size, p);

View file

@ -51,7 +51,7 @@ char *getcwd(char *buf, size_t size) {
}
} else if (weaken(malloc)) {
assert(!__vforked);
if (!size) size = PATH_MAX + 1;
if (!size) size = PATH_MAX;
if (!(p = weaken(malloc)(size))) {
STRACE("getcwd(%p, %'zu) %m", buf, size);
return 0;

View file

@ -32,7 +32,7 @@
#define KERN_PROC_PATHNAME_FREEBSD 12
#define KERN_PROC_PATHNAME_NETBSD 5
char program_executable_name[PATH_MAX + 1];
char program_executable_name[PATH_MAX];
static inline void GetProgramExecutableNameImpl(char *p, char *e) {
char *q;
@ -40,7 +40,7 @@ static inline void GetProgramExecutableNameImpl(char *p, char *e) {
size_t i, n;
union {
int cmd[4];
char16_t path16[PATH_MAX + 1];
char16_t path16[PATH_MAX];
} u;
if (IsWindows()) {

51
libc/calls/getresgid.c Normal file
View file

@ -0,0 +1,51 @@
/*-*- 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
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"
#include "libc/dce.h"
/**
* Gets real, effective, and "saved" group ids.
*
* @param real receives real user id, or null to do nothing
* @param effective receives effective user id, or null to do nothing
* @param saved receives saved user id, or null to do nothing
* @return 0 on success or -1 w/ errno
* @see setresuid()
*/
int getresgid(uint32_t *real, uint32_t *effective, uint32_t *saved) {
int rc, gid;
if (IsWindows()) {
gid = getgid();
if (real) *real = gid;
if (effective) *effective = gid;
if (saved) *saved = gid;
rc = 0;
} else if (saved) {
rc = sys_getresgid(real, effective, saved);
} else {
if (real) *real = sys_getgid();
if (effective) *effective = sys_getegid();
rc = 0;
}
STRACE("getresgid([%d], [%d], [%d]) → %d% m", real ? *real : 0,
effective ? *effective : 0, saved ? *saved : 0, rc);
return rc;
}

51
libc/calls/getresuid.c Normal file
View file

@ -0,0 +1,51 @@
/*-*- 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
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"
#include "libc/dce.h"
/**
* Gets real, effective, and "saved" user ids.
*
* @param real receives real user id, or null to do nothing
* @param effective receives effective user id, or null to do nothing
* @param saved receives saved user id, or null to do nothing
* @return 0 on success or -1 w/ errno
* @see setresuid()
*/
int getresuid(uint32_t *real, uint32_t *effective, uint32_t *saved) {
int rc, uid;
if (IsWindows()) {
uid = getuid();
if (real) *real = uid;
if (effective) *effective = uid;
if (saved) *saved = uid;
rc = 0;
} else if (saved) {
rc = sys_getresuid(real, effective, saved);
} else {
if (real) *real = sys_getuid();
if (effective) *effective = sys_geteuid();
rc = 0;
}
STRACE("getresuid([%d], [%d], [%d]) → %d% m", real ? *real : 0,
effective ? *effective : 0, saved ? *saved : 0, rc);
return rc;
}

View file

@ -25,7 +25,7 @@
#include "libc/str/str.h"
#include "libc/time/struct/timezone.h"
int sys_gettimeofday_nt(struct timeval *tv, struct timezone *tz) {
textwindows int sys_gettimeofday_nt(struct timeval *tv, struct timezone *tz) {
struct NtFileTime ft;
GetSystemTimeAsFileTime(&ft);
if (tv) *tv = FileTimeToTimeVal(ft);

View file

@ -163,6 +163,8 @@ i32 sys_getpgid(i32) hidden;
i32 sys_getpgrp(void) hidden;
i32 sys_getppid(void) hidden;
i32 sys_getpriority(i32, u32) hidden;
i32 sys_getresgid(u32 *, u32 *, u32 *);
i32 sys_getresuid(u32 *, u32 *, u32 *);
i32 sys_getrlimit(i32, struct rlimit *) hidden;
i32 sys_getrusage(i32, struct rusage *) hidden;
i32 sys_getsid(int) hidden;
@ -184,6 +186,7 @@ i32 sys_openat(i32, const char *, i32, u32) hidden;
i32 sys_pause(void) hidden;
i32 sys_pipe(i32[hasatleast 2]) hidden;
i32 sys_pipe2(i32[hasatleast 2], u32) hidden;
i32 sys_pledge(const char *, const char *) hidden;
i32 sys_posix_openpt(i32) hidden;
i32 sys_renameat(i32, const char *, i32, const char *) hidden;
i32 sys_sched_setaffinity(i32, u64, const void *) hidden;
@ -193,8 +196,8 @@ i32 sys_setitimer(i32, const struct itimerval *, struct itimerval *) hidden;
i32 sys_setpgid(i32, i32) hidden;
i32 sys_setpriority(i32, u32, i32) hidden;
i32 sys_setregid(u32, u32) hidden;
i32 sys_setresgid(uint32_t, uint32_t, uint32_t) hidden;
i32 sys_setresuid(uint32_t, uint32_t, uint32_t) hidden;
i32 sys_setresgid(u32, u32, u32) hidden;
i32 sys_setresuid(u32, u32, u32) hidden;
i32 sys_setreuid(u32, u32) hidden;
i32 sys_setrlimit(i32, const struct rlimit *) hidden;
i32 sys_setsid(void) hidden;
@ -330,6 +333,7 @@ int ioctl_tiocgwinsz_nt(struct Fd *, struct winsize *) hidden;
cosmopolitan § syscalls » windows nt » support
*/
bool __is_linux_2_6_23(void) hidden;
int64_t __fix_enotdir(int64_t, char16_t *) hidden;
int64_t __fix_enotdir3(int64_t, char16_t *, char16_t *) hidden;
bool _check_interrupts(bool, struct Fd *) hidden;
@ -341,10 +345,9 @@ bool isregularfile_nt(const char *) hidden;
bool issymlink_nt(const char *) hidden;
bool32 ntsetprivilege(i64, const char16_t *, u32) hidden;
char16_t *CreatePipeName(char16_t *) hidden;
int __mkntpath(const char *, char16_t[hasatleast PATH_MAX + 1]) hidden;
int __mkntpath2(const char *, char16_t[hasatleast PATH_MAX + 1], int) hidden;
int __mkntpathat(int, const char *, int,
char16_t[hasatleast PATH_MAX + 1]) hidden;
int __mkntpath(const char *, char16_t[hasatleast PATH_MAX]) hidden;
int __mkntpath2(const char *, char16_t[hasatleast PATH_MAX], int) hidden;
int __mkntpathat(int, const char *, int, char16_t[hasatleast PATH_MAX]) hidden;
int sys_clock_gettime_nt(int, struct timespec *) hidden;
int ntaccesscheck(const char16_t *, u32) paramsnonnull() hidden;
int sys_getsetpriority_nt(int, int, int, int (*)(int));

View file

@ -28,7 +28,7 @@
bool isdirectory_nt(const char *path) {
int e;
uint32_t x;
char16_t path16[PATH_MAX + 1];
char16_t path16[PATH_MAX];
e = errno;
if (__mkntpath(path, path16) == -1) return -1;
if ((x = GetFileAttributes(path16)) != -1u) {

32
libc/calls/islinux.c Normal file
View file

@ -0,0 +1,32 @@
/*-*- 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/dce.h"
#include "libc/errno.h"
#include "libc/sysv/consts/pr.h"
bool __is_linux_2_6_23(void) {
int rc;
if (!IsLinux()) return false;
asm volatile("syscall"
: "=a"(rc)
: "0"(157), "D"(PR_GET_SECCOMP)
: "rcx", "r11", "memory");
return rc != -EINVAL;
}

View file

@ -28,7 +28,7 @@
bool isregularfile_nt(const char *path) {
int e;
uint32_t x;
char16_t path16[PATH_MAX + 1];
char16_t path16[PATH_MAX];
e = errno;
if (__mkntpath(path, path16) == -1) return -1;
if ((x = GetFileAttributes(path16)) != -1u) {

View file

@ -28,7 +28,7 @@
bool issymlink_nt(const char *path) {
int e;
uint32_t x;
char16_t path16[PATH_MAX + 1];
char16_t path16[PATH_MAX];
e = errno;
if (__mkntpath(path, path16) == -1) return -1;
if ((x = GetFileAttributes(path16)) != -1u) {

View file

@ -23,8 +23,8 @@
textwindows int sys_linkat_nt(int olddirfd, const char *oldpath, int newdirfd,
const char *newpath) {
char16_t newpath16[PATH_MAX + 1];
char16_t oldpath16[PATH_MAX + 1];
char16_t newpath16[PATH_MAX];
char16_t oldpath16[PATH_MAX];
if (__mkntpathat(olddirfd, oldpath, 0, oldpath16) != -1 &&
__mkntpathat(newdirfd, newpath, 0, newpath16) != -1) {
if (CreateHardLink(newpath16, oldpath16, NULL)) {

View file

@ -23,7 +23,7 @@
textwindows int sys_mkdirat_nt(int dirfd, const char *path, uint32_t mode) {
int e;
char16_t *p, path16[PATH_MAX + 1];
char16_t *p, path16[PATH_MAX];
/* if (strlen(path) > 248) return enametoolong(); */
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
if (CreateDirectory(path16, 0)) return 0;

View file

@ -23,10 +23,12 @@
#include "libc/str/utf16.h"
#include "libc/sysv/errfuns.h"
#define APPEND(c) \
do { \
cmdline[k++] = c; \
if (k == ARG_MAX) return e2big(); \
#define APPEND(c) \
do { \
cmdline[k++] = c; \
if (k == ARG_MAX / 2) { \
return e2big(); \
} \
} while (0)
static noasan bool NeedsQuotes(const char *s) {
@ -52,8 +54,8 @@ static noasan bool NeedsQuotes(const char *s) {
* @return freshly allocated lpCommandLine or NULL w/ errno
* @see libc/runtime/dosargv.c
*/
textwindows noasan int mkntcmdline(char16_t cmdline[ARG_MAX], const char *prog,
char *const argv[]) {
textwindows noasan int mkntcmdline(char16_t cmdline[ARG_MAX / 2],
const char *prog, char *const argv[]) {
char *arg;
uint64_t w;
wint_t x, y;

View file

@ -55,9 +55,9 @@ static noasan void InsertString(char **a, size_t i, char *s) {
* @param envp is an a NULL-terminated array of UTF-8 strings
* @param extravar is a VAR=val string we consider part of envp or NULL
* @return 0 on success, or -1 w/ errno
* @error E2BIG if total number of shorts exceeded ARG_MAX (0x8000)
* @error E2BIG if total number of shorts exceeded ARG_MAX/2 (32767)
*/
textwindows noasan int mkntenvblock(char16_t envvars[ARG_MAX],
textwindows noasan int mkntenvblock(char16_t envvars[ARG_MAX / 2],
char *const envp[], const char *extravar) {
bool v;
char *t;
@ -98,7 +98,9 @@ textwindows noasan int mkntenvblock(char16_t envvars[ARG_MAX],
w = EncodeUtf16(x);
do {
envvars[k++] = w & 0xffff;
if (k == ARG_MAX) return e2big();
if (k == ARG_MAX / 2) {
return e2big();
}
} while ((w >>= 16));
} while (x);
}

View file

@ -50,7 +50,7 @@ textwindows static const char *FixNtMagicPath(const char *path,
}
textwindows int __mkntpath(const char *path,
char16_t path16[hasatleast PATH_MAX + 1]) {
char16_t path16[hasatleast PATH_MAX]) {
return __mkntpath2(path, path16, -1);
}
@ -68,8 +68,7 @@ textwindows int __mkntpath(const char *path,
* @error ENAMETOOLONG
*/
textwindows int __mkntpath2(const char *path,
char16_t path16[hasatleast PATH_MAX + 1],
int flags) {
char16_t path16[hasatleast PATH_MAX], int flags) {
/*
* 1. Need +1 for NUL-terminator
* 2. Need +1 for UTF-16 overflow
@ -101,7 +100,7 @@ textwindows int __mkntpath2(const char *path,
m = 0;
}
n = tprecode8to16(p, z, q).ax;
if (n == z - 1) {
if (n >= z - 1) {
STRACE("path too long for windows: %#s", path);
return enametoolong();
}

View file

@ -25,9 +25,9 @@
#include "libc/sysv/errfuns.h"
int __mkntpathat(int dirfd, const char *path, int flags,
char16_t file[hasatleast PATH_MAX + 1]) {
char16_t file[hasatleast PATH_MAX]) {
char16_t dir[PATH_MAX];
uint32_t dirlen, filelen;
char16_t dir[PATH_MAX + 1];
if ((filelen = __mkntpath2(path, file, flags)) == -1) return -1;
if (!filelen) return enoent();
if (file[0] != u'\\' && dirfd != AT_FDCWD) { /* ProTip: \\?\C:\foo */

View file

@ -32,8 +32,13 @@
#include "libc/nt/struct/startupinfo.h"
struct SpawnBlock {
char16_t cmdline[ARG_MAX];
char16_t envvars[ARG_MAX];
union {
struct {
char16_t cmdline[ARG_MAX / 2];
char16_t envvars[ARG_MAX / 2];
};
char __pad[ROUNDUP(ARG_MAX / 2 * 2 * sizeof(char16_t), FRAMESIZE)];
};
};
/**
@ -68,20 +73,15 @@ textwindows int ntspawn(
struct NtProcessInformation *opt_out_lpProcessInformation) {
int rc;
int64_t handle;
size_t blocksize;
struct SpawnBlock *block;
char16_t prog16[PATH_MAX + 1];
char16_t prog16[PATH_MAX];
rc = -1;
block = NULL;
if (__mkntpath(prog, prog16) == -1) return -1;
blocksize = ROUNDUP(sizeof(*block), FRAMESIZE);
if ((handle = CreateFileMapping(
-1,
&(struct NtSecurityAttributes){sizeof(struct NtSecurityAttributes),
NULL, false},
pushpop(kNtPageReadwrite), 0, blocksize, NULL)) &&
if ((handle = CreateFileMapping(-1, 0, pushpop(kNtPageReadwrite), 0,
sizeof(*block), 0)) &&
(block = MapViewOfFileEx(handle, kNtFileMapRead | kNtFileMapWrite, 0, 0,
blocksize, NULL)) &&
sizeof(*block), 0)) &&
mkntcmdline(block->cmdline, prog, argv) != -1 &&
mkntenvblock(block->envvars, envp, extravar) != -1 &&
CreateProcess(prog16, block->cmdline, opt_lpProcessAttributes,

View file

@ -6,8 +6,8 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int mkntcmdline(char16_t[ARG_MAX], const char *, char *const[]) hidden;
int mkntenvblock(char16_t[ARG_MAX], char *const[], const char *) hidden;
int mkntcmdline(char16_t[ARG_MAX / 2], const char *, char *const[]) hidden;
int mkntenvblock(char16_t[ARG_MAX / 2], char *const[], const char *) hidden;
int ntspawn(const char *, char *const[], char *const[], const char *,
struct NtSecurityAttributes *, struct NtSecurityAttributes *,
bool32, uint32_t, const char16_t *, const struct NtStartupInfo *,

View file

@ -38,7 +38,7 @@
static textwindows int64_t sys_open_nt_impl(int dirfd, const char *path,
uint32_t flags, int32_t mode) {
char16_t path16[PATH_MAX + 1];
char16_t path16[PATH_MAX];
uint32_t perm, share, disp, attr;
if (__mkntpathat(dirfd, path, flags, path16) == -1) return -1;
if (GetNtOpenFlags(flags, mode, &perm, &share, &disp, &attr) == -1) return -1;

View file

@ -8,8 +8,6 @@ COSMOPOLITAN_C_START_
typedef unsigned char u_char;
int pledge(const char *promises, const char *execpromises);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ */

View file

@ -40,7 +40,7 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf,
wint_t x, y;
volatile char *memory;
uint32_t i, j, n, mem;
char16_t path16[PATH_MAX + 1], *p;
char16_t path16[PATH_MAX], *p;
struct NtReparseDataBuffer *rdb;
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
mem = 16384;

View file

@ -81,7 +81,7 @@ char *realpath(const char *filename, char *resolved)
ssize_t rc;
int e, up, check_dir=0;
size_t k, p, q, l, l0, cnt=0, nup=0;
char output[PATH_MAX], stack[PATH_MAX+1], *z;
char output[PATH_MAX], stack[PATH_MAX], *z;
if (!filename) {
einval();

View file

@ -22,8 +22,8 @@
textwindows int sys_renameat_nt(int olddirfd, const char *oldpath, int newdirfd,
const char *newpath) {
char16_t oldpath16[PATH_MAX + 1];
char16_t newpath16[PATH_MAX + 1];
char16_t oldpath16[PATH_MAX];
char16_t newpath16[PATH_MAX];
if (__mkntpathat(olddirfd, oldpath, 0, oldpath16) == -1 ||
__mkntpathat(newdirfd, newpath, 0, newpath16) == -1) {
return -1;

View file

@ -29,8 +29,8 @@
#include "libc/str/str.h"
static textwindows dontinline int sys_sched_setaffinity_nt(int pid,
uint64_t bitsetsize,
const void *bitset) {
uint64_t bitsetsize,
const void *bitset) {
int rc;
uintptr_t mask;
int64_t handle;

View file

@ -18,6 +18,7 @@
*/
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/weaken.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/sigbits.h"
@ -34,6 +35,8 @@
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/spinlock.h"
#include "libc/limits.h"
#include "libc/log/backtrace.internal.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"

View file

@ -8,7 +8,7 @@
#define _KERNTRACE 0 /* not configurable w/ flag yet */
#define _POLLTRACE 0 /* not configurable w/ flag yet */
#define _DATATRACE 1 /* not configurable w/ flag yet */
#define _NTTRACE 1 /* not configurable w/ flag yet */
#define _NTTRACE 0 /* not configurable w/ flag yet */
#define STRACE_PROLOGUE "%rSYS %5P %'18T "

View file

@ -53,8 +53,8 @@ textwindows int sys_symlinkat_nt(const char *target, int newdirfd,
const char *linkpath) {
int targetlen;
uint32_t attrs, flags;
char16_t target16[PATH_MAX + 1];
char16_t linkpath16[PATH_MAX + 1];
char16_t target16[PATH_MAX];
char16_t linkpath16[PATH_MAX];
// convert the paths
if (__mkntpathat(newdirfd, linkpath, 0, linkpath16) == -1) return -1;

View file

@ -29,7 +29,7 @@
/**
* Flushes all open file handles and, if possible, all disk drives.
*/
int sys_sync_nt(void) {
textwindows int sys_sync_nt(void) {
unsigned i;
int64_t volume;
uint32_t drives;

View file

@ -28,7 +28,7 @@ textwindows int sys_truncate_nt(const char *path, uint64_t length) {
int rc;
bool32 ok;
int64_t fh;
uint16_t path16[PATH_MAX + 1];
uint16_t path16[PATH_MAX];
if (__mkntpath(path, path16) == -1) return -1;
if ((fh = CreateFile(path16, kNtGenericWrite, kNtFileShareRead, NULL,
kNtOpenExisting, kNtFileAttributeNormal, 0)) != -1) {

View file

@ -19,7 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/log/log.h"
static char ttyname_buf[PATH_MAX + 1];
static char ttyname_buf[PATH_MAX];
/**
* Returns name of terminal.

View file

@ -63,7 +63,7 @@ static int ttyname_freebsd(int fd, char *buf, size_t size) {
static int ttyname_linux(int fd, char *buf, size_t size) {
struct stat st1, st2;
if (!isatty(fd)) return errno;
char name[PATH_MAX + 1];
char name[PATH_MAX];
FormatInt32(stpcpy(name, "/proc/self/fd/"), fd);
ssize_t got;
got = readlink(name, buf, size);

View file

@ -39,8 +39,7 @@
* from failing for no reason at all. For example a unit test that
* repeatedly opens and unlinks the same filename.
*/
static textwindows int SyncDirectory(int df, char16_t path[PATH_MAX + 1],
int n) {
static textwindows int SyncDirectory(int df, char16_t path[PATH_MAX], int n) {
int rc;
int64_t fh;
char16_t *p;
@ -129,7 +128,7 @@ static textwindows int sys_unlink_nt(const char16_t *path) {
textwindows int sys_unlinkat_nt(int dirfd, const char *path, int flags) {
int n, rc;
char16_t path16[PATH_MAX + 1];
char16_t path16[PATH_MAX];
if ((n = __mkntpathat(dirfd, path, 0, path16)) == -1) {
rc = -1;
} else if (flags & AT_REMOVEDIR) {

View file

@ -35,7 +35,7 @@ textwindows int sys_utimensat_nt(int dirfd, const char *path,
const struct timespec ts[2], int flags) {
int i, rc;
int64_t fh;
uint16_t path16[PATH_MAX + 1];
uint16_t path16[PATH_MAX];
struct NtFileTime ft[2], *ftp[2];
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
if ((fh = CreateFile(path16, kNtFileWriteAttributes, kNtFileShareRead, NULL,

View file

@ -57,7 +57,7 @@ static textwindows dontinline char *GetNtHostsTxtPath(char *pathbuf,
const struct HostsTxt *GetHostsTxt(void) {
FILE *f;
const char *path;
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
struct HostsTxtInitialStaticMemory *init;
init = &g_hoststxt_init;
if (!g_hoststxt) {

View file

@ -51,7 +51,7 @@ int LookupProtoByName(const char *protoname, char *buf, size_t bufsize,
const char *path;
size_t linesize;
int found, result;
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
char *name, *number, *alias, *comment, *tok;
if (!(path = filepath)) {
path = "/etc/protocols";

View file

@ -55,7 +55,7 @@ int LookupProtoByNumber(const int protonum, char *buf, size_t bufsize,
int found;
size_t linesize;
const char *path;
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
char *name, *number, *comment, *tok;
if (!(path = filepath)) {
path = "/etc/protocols";

View file

@ -56,7 +56,7 @@ int LookupServicesByName(const char *servname, char *servproto,
const char *path;
size_t linesize;
int found, result;
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
char *name, *port, *proto, *alias, *comment, *tok;
if (!(path = filepath)) {
path = "/etc/services";

View file

@ -59,7 +59,7 @@ int LookupServicesByPort(const int servport, char *servproto,
const char *filepath) {
FILE *f;
char *line;
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
const char *path;
size_t linesize;
int found;

View file

@ -351,7 +351,7 @@ hidden int __fmt(void *fn, void *arg, const char *format, va_list va) {
// undocumented %r specifier
// used for good carriage return
// helps integrate loggers with repls
if (!__replmode) {
if (!__replstderr) {
break;
} else {
p = "\r\e[K";

View file

@ -70,13 +70,13 @@
#define BUFSIZ 0x1000 /* best stdio default */
#define CACHELINE 0x40 /* nexgen32e */
#define CHAR_BIT 8 /* b/c von neumann */
#define ARG_MAX 0x8000 /* b/c windows */
#define PATH_MAX 511 /* b/c bloat */
#define ARG_MAX 0xfffe /* for argv and envp; see CreateProcess (32767*2) */
#define PATH_MAX 1024 /* b/c _XOPEN_PATH_MAX */
#define NAME_MAX 63 /* b/c dns */
#define CHILD_MAX 25 /* only if malloc isn't linked */
#define CHILD_MAX 16 /* only if malloc isn't linked */
#define OPEN_MAX 16 /* only if malloc isn't linked */
#define ATEXIT_MAX 32 /* only if malloc isn't linked */
#define NSIG 128 /* it's complicated */
#define NSIG 128 /* b/c freebsd */
#if defined(__LP64__) && !defined(__INT64_TYPE__)
#include "libc/integral/lp64.inc"

View file

@ -565,7 +565,7 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, va_list va,
// undocumented %r specifier
// used for good carriage return
// helps integrate loggers with repls
if (!__replmode || __nocolor) {
if (!__replstderr || __nocolor) {
break;
} else {
s = "\r\033[K";

View file

@ -25,3 +25,4 @@
* @see kprintf(), vflogf(), linenoise()
*/
char __replmode;
char __replstderr;

View file

@ -3,7 +3,8 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern bool __replmode;
extern char __replmode;
extern char __replstderr;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/bits.h"
#include "libc/calls/struct/rusage.h"
#include "libc/fmt/itoa.h"
#include "libc/log/log.h"
@ -102,7 +103,11 @@ void AppendResourceReport(char **b, struct rusage *ru, const char *nl) {
}
if (ru->ru_nvcsw + ru->ru_nivcsw > 1) {
AppendInt(st, ru->ru_nvcsw + ru->ru_nivcsw);
appends(b, " context switch (");
appends(b, " context switch");
if ((ru->ru_nvcsw + ru->ru_nivcsw) > 1) {
appendw(b, READ16LE("es"));
}
appendw(b, READ16LE(" ("));
AppendInt(st,
(long double)ru->ru_nvcsw / (ru->ru_nvcsw + ru->ru_nivcsw) * 100);
appends(b, "% consensual)");

View file

@ -47,7 +47,7 @@
*/
const char *commandvenv(const char *var, const char *cmd) {
const char *exepath;
static char pathbuf[PATH_MAX + 1];
static char pathbuf[PATH_MAX];
if (*cmd == '/' || *cmd == '\\') return cmd;
if ((exepath = getenv(var))) {
if (isempty(exepath)) return NULL;

View file

@ -29,6 +29,7 @@ LIBC_MEM_A_CHECKS = \
LIBC_MEM_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_SYSV_CALLS \
LIBC_FMT \
LIBC_INTRIN \
LIBC_NEXGEN32E \

406
libc/mem/pledge.c Normal file
View file

@ -0,0 +1,406 @@
/*-*- 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"
#include "libc/calls/struct/filter.h"
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/nrlinux.h"
#include "libc/sysv/consts/pr.h"
#include "libc/sysv/errfuns.h"
#include "tool/net/sandbox.h"
static const uint16_t kPledgeLinuxDefault[] = {
__NR_linux_exit, //
__NR_linux_exit_group, //
0, //
};
static const uint16_t kPledgeLinuxStdio[] = {
__NR_linux_clock_getres, //
__NR_linux_clock_gettime, //
__NR_linux_close, //
__NR_linux_dup, //
__NR_linux_dup2, //
__NR_linux_dup3, //
__NR_linux_fchdir, //
/* __NR_linux_fcntl, // */
__NR_linux_fstat, //
__NR_linux_fsync, //
__NR_linux_ftruncate, //
__NR_linux_getdents, //
__NR_linux_getegid, //
__NR_linux_getrandom, //
__NR_linux_geteuid, //
__NR_linux_getgid, //
__NR_linux_getgroups, //
__NR_linux_getitimer, //
__NR_linux_getpgid, //
__NR_linux_getpgrp, //
__NR_linux_getpid, //
__NR_linux_getppid, //
__NR_linux_getresgid, //
__NR_linux_getresuid, //
__NR_linux_getrlimit, //
__NR_linux_getsid, //
__NR_linux_gettimeofday, //
__NR_linux_getuid, //
__NR_linux_lseek, //
__NR_linux_madvise, //
__NR_linux_brk, //
__NR_linux_mmap, //
__NR_linux_mprotect, //
__NR_linux_munmap, //
__NR_linux_nanosleep, //
__NR_linux_pipe, //
__NR_linux_pipe2, //
__NR_linux_poll, //
__NR_linux_pread, //
__NR_linux_preadv, //
__NR_linux_pwrite, //
__NR_linux_pwritev, //
__NR_linux_read, //
__NR_linux_readv, //
__NR_linux_recvfrom, //
__NR_linux_recvmsg, //
__NR_linux_select, //
__NR_linux_sendmsg, //
__NR_linux_sendto, //
__NR_linux_setitimer, //
__NR_linux_shutdown, //
__NR_linux_sigaction, //
__NR_linux_sigprocmask, //
__NR_linux_sigreturn, //
__NR_linux_socketpair, //
__NR_linux_umask, //
__NR_linux_wait4, //
__NR_linux_write, //
__NR_linux_writev, //
0, //
};
static const uint16_t kPledgeLinuxRpath[] = {
__NR_linux_chdir, //
__NR_linux_getcwd, //
__NR_linux_openat, //
__NR_linux_fstatat, //
__NR_linux_faccessat, //
__NR_linux_readlinkat, //
__NR_linux_lstat, //
__NR_linux_chmod, //
__NR_linux_fchmod, //
__NR_linux_fchmodat, //
__NR_linux_chown, //
__NR_linux_fchown, //
__NR_linux_fchownat, //
__NR_linux_fstat, //
0, //
};
static const uint16_t kPledgeLinuxWpath[] = {
__NR_linux_getcwd, //
__NR_linux_openat, //
__NR_linux_fstatat, //
__NR_linux_faccessat, //
__NR_linux_readlinkat, //
__NR_linux_lstat, //
__NR_linux_chmod, //
__NR_linux_fchmod, //
__NR_linux_fchmodat, //
__NR_linux_chown, //
__NR_linux_fchown, //
__NR_linux_fchownat, //
__NR_linux_fstat, //
0, //
};
static const uint16_t kPledgeLinuxCpath[] = {
__NR_linux_rename, //
__NR_linux_renameat, //
__NR_linux_link, //
__NR_linux_linkat, //
__NR_linux_symlink, //
__NR_linux_symlinkat, //
__NR_linux_unlink, //
__NR_linux_unlinkat, //
__NR_linux_mkdir, //
__NR_linux_mkdirat, //
__NR_linux_rmdir, //
0, //
};
static const uint16_t kPledgeLinuxDpath[] = {
__NR_linux_mknod, //
0, //
};
static const uint16_t kPledgeLinuxTmppath[] = {
__NR_linux_lstat, //
__NR_linux_chmod, //
__NR_linux_chown, //
__NR_linux_unlink, //
__NR_linux_fstat, //
0, //
};
static const uint16_t kPledgeLinuxInet[] = {
__NR_linux_socket, //
__NR_linux_listen, //
__NR_linux_bind, //
__NR_linux_connect, //
__NR_linux_accept4, //
__NR_linux_accept, //
__NR_linux_getpeername, //
__NR_linux_getsockname, //
__NR_linux_setsockopt, //
__NR_linux_getsockopt, //
0, //
};
static const uint16_t kPledgeLinuxFattr[] = {
__NR_linux_utimes, //
__NR_linux_utimensat, //
__NR_linux_chmod, //
__NR_linux_fchmod, //
__NR_linux_fchmodat, //
__NR_linux_chown, //
__NR_linux_fchownat, //
__NR_linux_lchown, //
__NR_linux_fchown, //
__NR_linux_utimes, //
0, //
};
static const uint16_t kPledgeLinuxUnix[] = {
__NR_linux_socket, //
__NR_linux_listen, //
__NR_linux_bind, //
__NR_linux_connect, //
__NR_linux_accept4, //
__NR_linux_accept, //
__NR_linux_getpeername, //
__NR_linux_getsockname, //
__NR_linux_setsockopt, //
__NR_linux_getsockopt, //
0, //
};
static const uint16_t kPledgeLinuxDns[] = {
__NR_linux_sendto, //
__NR_linux_recvfrom, //
__NR_linux_socket, //
__NR_linux_connect, //
0, //
};
static const uint16_t kPledgeLinuxProc[] = {
__NR_linux_fork, //
__NR_linux_vfork, //
__NR_linux_kill, //
__NR_linux_getpriority, //
__NR_linux_setpriority, //
__NR_linux_setrlimit, //
__NR_linux_setpgid, //
__NR_linux_setsid, //
0, //
};
static const uint16_t kPledgeLinuxExec[] = {
__NR_linux_execve, //
0, //
};
static const uint16_t kPledgeLinuxId[] = {
__NR_linux_setuid, //
__NR_linux_setreuid, //
__NR_linux_setresuid, //
__NR_linux_setgid, //
__NR_linux_setregid, //
__NR_linux_setresgid, //
__NR_linux_setgroups, //
__NR_linux_setrlimit, //
__NR_linux_getpriority, //
__NR_linux_setpriority, //
0, //
};
static const struct Pledges {
const char *name;
const uint16_t *syscalls;
} kPledgeLinux[] = {
{"default", kPledgeLinuxDefault}, //
{"stdio", kPledgeLinuxStdio}, //
{"rpath", kPledgeLinuxRpath}, //
{"wpath", kPledgeLinuxWpath}, //
{"cpath", kPledgeLinuxCpath}, //
{"dpath", kPledgeLinuxDpath}, //
{"tmppath", kPledgeLinuxTmppath}, //
{"inet", kPledgeLinuxInet}, //
{"fattr", kPledgeLinuxFattr}, //
{"unix", kPledgeLinuxUnix}, //
{"dns", kPledgeLinuxDns}, //
{"proc", kPledgeLinuxProc}, //
{"exec", kPledgeLinuxExec}, //
{"id", kPledgeLinuxId}, //
{0}, //
};
static const struct sock_filter kFilterStart[] = {
_SECCOMP_MACHINE(AUDIT_ARCH_X86_64), //
_SECCOMP_LOAD_SYSCALL_NR(), //
};
static const struct sock_filter kFilterEnd[] = {
_SECCOMP_LOG_AND_RETURN_ERRNO(1), // EPERM
};
struct Filter {
size_t n;
struct sock_filter *p;
};
static bool AppendFilter(struct Filter *f, struct sock_filter *p, size_t n) {
size_t m;
struct sock_filter *q;
m = f->n + n;
if (!(q = realloc(f->p, m * sizeof(*f->p)))) return false;
memcpy(q + f->n, p, n * sizeof(*q));
f->p = q;
f->n = m;
return true;
}
static bool AppendPledge(struct Filter *f, const uint16_t *p) {
int i;
for (i = 0; p[i]; ++i) {
struct sock_filter fragment[] = {_SECCOMP_ALLOW_SYSCALL(p[i])};
if (!AppendFilter(f, fragment, ARRAYLEN(fragment))) {
return false;
}
}
return true;
}
static const uint16_t *FindPledge(const struct Pledges *p, const char *name) {
int i;
for (i = 0; p[i].name; ++i) {
if (!strcasecmp(name, p[i].name)) {
return p[i].syscalls;
}
}
return 0;
}
static int sys_pledge_linux(const char *promises, const char *execpromises) {
bool ok;
int rc = -1;
struct Filter f = {0};
const uint16_t *pledge;
char *s, *tok, *state, *start;
if (execpromises) return einval();
if ((start = s = strdup(promises)) &&
AppendFilter(&f, kFilterStart, ARRAYLEN(kFilterStart)) &&
AppendPledge(&f, kPledgeLinuxDefault)) {
for (ok = true; (tok = strtok_r(start, " \t\r\n", &state)); start = 0) {
if (!(pledge = FindPledge(kPledgeLinux, tok)) ||
!AppendPledge(&f, pledge)) {
ok = false;
}
}
if (ok && AppendFilter(&f, kFilterEnd, ARRAYLEN(kFilterEnd)) &&
(rc = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) != -1) {
struct sock_fprog sandbox = {.len = f.n, .filter = f.p};
rc = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &sandbox);
}
}
free(f.p);
free(s);
return rc;
}
/**
* Restricts system operations.
*
* Only available on OpenBSD and Linux.
*
* By default exit and exit_group are always allowed. This is useful
* for processes that perform pure computation and interface with the
* parent via shared memory.
*
* `promises` is a string that may include any of the following groups
* delimited by spaces.
*
* - "stdio" allows clock_getres, clock_gettime, close, dup, dup2, dup3,
* fchdir, fstat, fsync, ftruncate, getdents, getegid, getrandom,
* geteuid, getgid, getgroups, getitimer, getpgid, getpgrp, getpid,
* getppid, getresgid, getresuid, getrlimit, getsid, gettimeofday,
* getuid, lseek, madvise, brk, mmap, mprotect, munmap, nanosleep,
* pipe, pipe2, poll, pread, preadv, pwrite, pwritev, read, readv,
* recvfrom, recvmsg, select, sendmsg, sendto, setitimer, shutdown,
* sigaction, sigprocmask, sigreturn, socketpair, umask, wait4, write,
* writev.
*
* - "rpath" allows chdir, getcwd, openat, fstatat, faccessat,
* readlinkat, lstat, chmod, fchmod, fchmodat, chown, fchown,
* fchownat, fstat.
*
* - "wpath" allows getcwd, openat, fstatat, faccessat, readlinkat,
* lstat, chmod, fchmod, fchmodat, chown, fchown, fchownat, fstat.
*
* - "cpath" allows rename, renameat, link, linkat, symlink, symlinkat,
* unlink, unlinkat, mkdir, mkdirat, rmdir.
*
* - "dpath" allows mknod
*
* - "tmppath" allows lstat, chmod, chown, unlink, fstat.
*
* - "inet" allows socket, listen, bind, connect, accept4, accept,
* getpeername, getsockname, setsockopt, getsockopt.
*
* - "fattr" allows utimes, utimensat, chmod, fchmod, fchmodat, chown,
* fchownat, lchown, fchown, utimes.
*
* - "unix" allows socket, listen, bind, connect, accept4, accept,
* getpeername, getsockname, setsockopt, getsockopt.
*
* - "dns" allows sendto, recvfrom, socket, connect.
*
* - "proc" allows fork, vfork, kill, getpriority, setpriority,
* setrlimit, setpgid, setsid.
*
* - "exec" allows execve.
*
* - "id" allows setuid, setreuid, setresuid, setgid, setregid,
* setresgid, setgroups, setrlimit, getpriority, setpriority.
*
*/
int pledge(const char *promises, const char *execpromises) {
int rc;
if (IsLinux()) {
rc = sys_pledge_linux(promises, execpromises);
} else {
rc = sys_pledge(promises, execpromises);
}
STRACE("pledge(%#s, %#s) → %d% m", promises, execpromises, rc);
return rc;
}

View file

@ -24,7 +24,7 @@
struct FindComBinary {
bool once;
const char *res;
char buf[PATH_MAX + 1];
char buf[PATH_MAX];
};
static struct FindComBinary g_findcombinary;

View file

@ -18,6 +18,7 @@
*/
#include "libc/bits/bits.h"
#include "libc/calls/calls.h"
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/str/str.h"
@ -30,7 +31,7 @@
const char *FindDebugBinary(void) {
static bool once;
static char *res;
static char buf[PATH_MAX + 1];
static char buf[PATH_MAX];
char *p;
size_t n;
if (!once) {
@ -40,12 +41,12 @@ const char *FindDebugBinary(void) {
if (n > 4 && READ32LE(p + n - 4) == READ32LE(".dbg")) {
res = p;
} else if (n > 4 && READ32LE(p + n - 4) == READ32LE(".com") &&
n + 4 <= PATH_MAX) {
n + 4 < ARRAYLEN(buf)) {
mempcpy(mempcpy(buf, p, n), ".dbg", 5);
if (fileexists(buf)) {
res = buf;
}
} else if (n + 8 <= PATH_MAX) {
} else if (n + 8 < ARRAYLEN(buf)) {
mempcpy(mempcpy(buf, p, n), ".com.dbg", 9);
if (fileexists(buf)) {
res = buf;

View file

@ -212,9 +212,18 @@ textwindows void WinMainForked(void) {
// since the handles closed on fork
if (weaken(ForkNtStdinWorker)) weaken(ForkNtStdinWorker)();
struct Fds *fds = VEIL("r", &g_fds);
fds->__init_p[0].handle = GetStdHandle(kNtStdInputHandle);
fds->__init_p[1].handle = GetStdHandle(kNtStdOutputHandle);
fds->__init_p[2].handle = GetStdHandle(kNtStdErrorHandle);
fds->p[0].handle = fds->__init_p[0].handle = GetStdHandle(kNtStdInputHandle);
fds->p[1].handle = fds->__init_p[1].handle = GetStdHandle(kNtStdOutputHandle);
fds->p[2].handle = fds->__init_p[2].handle = GetStdHandle(kNtStdErrorHandle);
// untrack the forked children of the parent since we marked the
// CreateProcess() process handle below as non-inheritable
for (i = 0; i < fds->n; ++i) {
if (fds->p[i].kind == kFdProcess) {
fds->p[i].kind = 0;
fds->f = MIN(i, fds->f);
}
}
// restore the crash reporting stuff
if (weaken(__wincrash_nt)) {
@ -269,9 +278,8 @@ textwindows int sys_fork_nt(void) {
args = args2;
}
#endif
if (ntspawn(GetProgramExecutableName(), args, environ, forkvar,
&kNtIsInheritable, NULL, true, 0, NULL, &startinfo,
&procinfo) != -1) {
if (ntspawn(GetProgramExecutableName(), args, environ, forkvar, 0, 0,
true, 0, 0, &startinfo, &procinfo) != -1) {
CloseHandle(procinfo.hThread);
ok = WriteAll(writer, jb, sizeof(jb)) &&
WriteAll(writer, &_mmi.i, sizeof(_mmi.i)) &&

33
libc/runtime/getargmax.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/dce.h"
#include "libc/runtime/runtime.h"
/**
* Returns `ARG_MAX` for host platform.
*/
int __arg_max(void) {
if (IsWindows()) return 32767;
if (IsLinux()) return 128 * 1024;
if (IsNetbsd()) return 256 * 1024;
if (IsFreebsd()) return 512 * 1024;
if (IsOpenbsd()) return 512 * 1024;
if (IsXnu()) return 1024 * 1024;
return ARG_MAX;
}

View file

@ -24,7 +24,7 @@
#define ADDR(x) ((char *)((int64_t)((uint64_t)(x) << 32) >> 16))
privileged int sys_mprotect_nt(void *addr, size_t size, int prot) {
textwindows int sys_mprotect_nt(void *addr, size_t size, int prot) {
int rc = 0;
unsigned i;
uint32_t op;

View file

@ -30,8 +30,8 @@
void __paginate(int fd, const char *s) {
int tfd, pid;
char *args[3] = {0};
char tmppath[PATH_MAX + 1];
char progpath[PATH_MAX + 1];
char tmppath[PATH_MAX];
char progpath[PATH_MAX];
if (strcmp(nulltoempty(getenv("TERM")), "dumb") && isatty(0) && isatty(1) &&
((args[0] = commandv("less", progpath, sizeof(progpath))) ||
(args[0] = commandv("more", progpath, sizeof(progpath))))) {

View file

@ -140,10 +140,13 @@ textstartup void __printargs(const char *prologue) {
uintptr_t *auxp;
struct utsname uts;
struct termios termios;
char path[PATH_MAX + 1];
int e, x, st, ft, flags;
struct pollfd pfds[128];
struct AuxiliaryValue *auxinfo;
union {
char path[PATH_MAX];
struct pollfd pfds[128];
} u;
st = __strace, __strace = 0;
ft = g_ftrace, g_ftrace = 0;
e = errno;
@ -240,15 +243,15 @@ textstartup void __printargs(const char *prologue) {
PRINT("");
PRINT("FILE DESCRIPTORS");
for (i = 0; i < ARRAYLEN(pfds); ++i) {
pfds[i].fd = i;
pfds[i].events = POLLIN;
for (i = 0; i < ARRAYLEN(u.pfds); ++i) {
u.pfds[i].fd = i;
u.pfds[i].events = POLLIN;
}
if ((n = poll(pfds, ARRAYLEN(pfds), 0)) != -1) {
for (i = 0; i < ARRAYLEN(pfds); ++i) {
if (i && (pfds[i].revents & POLLNVAL)) continue;
if ((n = poll(u.pfds, ARRAYLEN(u.pfds), 0)) != -1) {
for (i = 0; i < ARRAYLEN(u.pfds); ++i) {
if (i && (u.pfds[i].revents & POLLNVAL)) continue;
PRINT(" ☼ %d (revents=%#hx fcntl(F_GETFL)=%#x isatty()=%hhhd)", i,
pfds[i].revents, fcntl(i, F_GETFL), isatty(i));
u.pfds[i].revents, fcntl(i, F_GETFL), isatty(i));
}
} else {
PRINT(" poll() returned %d %m", n);
@ -298,8 +301,8 @@ textstartup void __printargs(const char *prologue) {
if (*__auxv) {
for (auxp = __auxv; *auxp; auxp += 2) {
if ((auxinfo = DescribeAuxv(auxp[0]))) {
ksnprintf(path, sizeof(path), auxinfo->fmt, auxp[1]);
PRINT(" ☼ %16s[%4ld] = %s", auxinfo->name, auxp[0], path);
ksnprintf(u.path, sizeof(u.path), auxinfo->fmt, auxp[1]);
PRINT(" ☼ %16s[%4ld] = %s", auxinfo->name, auxp[0], u.path);
} else {
PRINT(" ☼ %16s[%4ld] = %014p", "unknown", auxp[0], auxp[1]);
}
@ -326,7 +329,7 @@ textstartup void __printargs(const char *prologue) {
PRINT(" ☼ %s = %#s", "kNtWindowsDirectory", kNtWindowsDirectory);
PRINT(" ☼ %s = %#s", "GetProgramExecutableName", GetProgramExecutableName());
PRINT(" ☼ %s = %#s", "GetInterpreterExecutableName",
GetInterpreterExecutableName(path, sizeof(path)));
GetInterpreterExecutableName(u.path, sizeof(u.path)));
PRINT(" ☼ %s = %p", "RSP", __builtin_frame_address(0));
PRINT(" ☼ %s = %p", "GetStackAddr()", GetStackAddr(0));
PRINT(" ☼ %s = %p", "GetStaticStackAddr(0)", GetStaticStackAddr(0));

View file

@ -104,6 +104,7 @@ char *GetProgramExecutableName(void);
char *GetInterpreterExecutableName(char *, size_t);
void __printargs(const char *);
void __paginate(int, const char *);
int __arg_max(void);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -22,6 +22,7 @@
#include "libc/macros.internal.h"
#include "libc/runtime/clktck.h"
#include "libc/runtime/sysconf.h"
#include "libc/sysv/consts/limits.h"
#include "libc/sysv/consts/rlim.h"
#include "libc/sysv/consts/rlimit.h"
@ -42,7 +43,7 @@ long sysconf(int name) {
int n;
switch (name) {
case _SC_ARG_MAX:
return ARG_MAX;
return _ARG_MAX;
case _SC_CHILD_MAX:
return GetResourceLimit(RLIMIT_NPROC);
case _SC_CLK_TCK:

View file

@ -84,8 +84,8 @@ struct WinArgs {
char *argv[4096];
char *envp[4092];
intptr_t auxv[2][2];
char argblock[ARG_MAX];
char envblock[ARG_MAX];
char argblock[ARG_MAX / 2];
char envblock[ARG_MAX / 2];
};
extern uint32_t __winmainpid;

View file

@ -40,7 +40,7 @@ int posix_spawn(int *pid, const char *path,
unsigned mode;
sigset_t allsigs;
struct sigaction dfl;
char *p, *q, opath[PATH_MAX + 1];
char *p, *q, opath[PATH_MAX];
int s, fd, newfd, oflag, tempfd;
if (!(*pid = vfork())) {
if (attrp) {
@ -77,7 +77,7 @@ int posix_spawn(int *pid, const char *path,
if (sscanf(p + 5, "%d,", &fd) != 1) _Exit(127);
p = strchr(p, ',') + 1;
q = strchr(p, '*');
if (!q || q - p > PATH_MAX) _Exit(127);
if (!q || q - p >= PATH_MAX) _Exit(127);
strncpy(opath, p, q - p);
opath[q - p] = '\0';
if (sscanf(q + 1, "%o,%o)", &oflag, &mode) != 2) _Exit(127);

View file

@ -31,7 +31,7 @@ int posix_spawnp(int *pid, const char *path,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *attrp, char *const argv[],
char *const envp[]) {
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
if (!(path = commandv(path, pathbuf, sizeof(pathbuf)))) return errno;
return posix_spawn(pid, path, file_actions, attrp, argv, envp);
}

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/macros.internal.h"
#include "libc/paths.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
@ -29,14 +30,16 @@
*/
int systemexec(const char *cmdline) {
size_t n, m;
char *a, *b, *argv[4], comspec[PATH_MAX + 1];
char *a, *b, *argv[4], comspec[PATH_MAX];
if (!IsWindows()) {
argv[0] = _PATH_BSHELL;
argv[1] = "-c";
} else {
b = "cmd.exe";
a = kNtSystemDirectory;
if ((n = strlen(a)) + (m = strlen(b)) > PATH_MAX) return enametoolong();
if ((n = strlen(a)) + (m = strlen(b)) >= ARRAYLEN(comspec)) {
return enametoolong();
}
memcpy(mempcpy(comspec, a, n), b, m + 1);
argv[0] = comspec;
argv[1] = "/C";

View file

@ -32,10 +32,10 @@
*/
FILE *tmpfile(void) {
int fd;
char *tmp, *sep, tpl[PATH_MAX + 1];
char *tmp, *sep, tpl[PATH_MAX];
tmp = firstnonnull(getenv("TMPDIR"), kTmpPath);
sep = !isempty(tmp) && !endswith(tmp, "/") ? "/" : "";
if ((snprintf)(tpl, PATH_MAX + 1, "%s%stmp.%s.XXXXXX", tmp, sep,
if ((snprintf)(tpl, PATH_MAX, "%s%stmp.%s.XXXXXX", tmp, sep,
program_invocation_short_name) <= PATH_MAX) {
if ((fd = mkostemps(tpl, 0, 0)) != -1) {
return fdopen(fd, "w+");

View file

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

View file

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

View file

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

View file

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

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/macros.internal.inc"
.scall getresgid,0xfff11b169ffff078,globl
.scall sys_pledge,0xfff06cffffffffff,globl

View file

@ -1229,7 +1229,11 @@ syscon mount MNT_SNAPSHOT 0 0x40000000 0x01000000 0 0 0 # confusing
# limits
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon misc PIPE_BUF 4096 512 512 512 512 4096 # bsd consensus
syscon limits PIPE_BUF 4096 512 512 512 512 4096 # bsd consensus
syscon limits _ARG_MAX 128*1024 1024*1024 512*1024 512*1024 256*1024 32767*2 # bsd consensus
syscon limits _NAME_MAX 255 255 255 255 511 255 # probably higher on windows?
syscon limits _PATH_MAX 4096 1024 1024 1024 1024 512 # cosmopolitan libc imposes a lower 512 limit; nt theoretically goes up to 32767
syscon limits _NSIG 64 32 128 32 64 32 # _SIG_MAXSIG on FreeBSD
# unmount() flags
# a.k.a. umount2() on linux
@ -1299,6 +1303,14 @@ syscon prio PRIO_MIN -20 -20 -20 -20 -20 -20 # unix consensus / p
syscon prio PRIO_MAX 20 20 20 20 20 20 # unix consensus / poly nt
syscon prio NZERO 20 20 20 20 20 20 # unix consensus / polyfilled nt
# getrusage() who
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon rusage RUSAGE_SELF 0 0 0 0 0 0 # unix consensus & faked nt
syscon rusage RUSAGE_THREAD 1 99 1 1 1 1 # faked nt & unavailable on xnu
syscon rusage RUSAGE_CHILDREN -1 -1 -1 -1 -1 99 # unix consensus & unavailable on nt
syscon rusage RUSAGE_BOTH -2 99 99 99 99 99 # woop
# Teletypewriter Control, e.g.
#
# TCSETS → About 70,800 results (0.31 seconds)
@ -1733,11 +1745,6 @@ syscon misc NL_TEXTMAX 0x7fffffff 0x0800 0x0800 255 255 0
syscon misc NL_NMAX 0x7fffffff 1 1 0 0 0
syscon misc NL_SETD 1 1 0 1 1 0
syscon rusage RUSAGE_SELF 0 0 0 0 0 0 # unix consensus & faked nt
syscon rusage RUSAGE_THREAD 1 99 1 1 1 1 # faked nt & unavailable on xnu
syscon rusage RUSAGE_CHILDREN -1 -1 -1 -1 -1 99 # unix consensus & unavailable on nt
syscon rusage RUSAGE_BOTH -2 99 99 99 99 99 # woop
syscon misc FSETLOCKING_QUERY 0 0 0 0 0 0 # consensus
syscon misc FSETLOCKING_BYCALLER 2 0 0 0 0 0
syscon misc FSETLOCKING_INTERNAL 1 0 0 0 0 0
@ -3184,84 +3191,6 @@ syscon in IN_OPEN 0x20 0 0 0 0 0
syscon in IN_Q_OVERFLOW 0x4000 0 0 0 0 0
syscon in IN_UNMOUNT 0x2000 0 0 0 0 0
syscon posix _POSIX_ARG_MAX 0x1000 0x1000 0x1000 0x1000 0x1000 0 # unix consensus
syscon posix _POSIX_CHILD_MAX 25 25 25 25 25 0 # unix consensus
syscon posix _POSIX_HOST_NAME_MAX 255 255 255 255 255 0 # unix consensus
syscon posix _POSIX_LINK_MAX 8 8 8 8 8 0 # unix consensus
syscon posix _POSIX_LOGIN_NAME_MAX 9 9 9 9 9 0 # unix consensus
syscon posix _POSIX_MAX_CANON 255 255 255 255 255 0 # unix consensus
syscon posix _POSIX_MAX_INPUT 255 255 255 255 255 0 # unix consensus
syscon posix _POSIX_NAME_MAX 14 14 14 14 14 14 # forced consensus
syscon posix _POSIX_NGROUPS_MAX 8 8 8 8 8 0 # unix consensus
syscon posix _POSIX_OPEN_MAX 20 20 20 20 20 20 # forced consensus
syscon posix _POSIX_PATH_MAX 255 255 255 255 255 255 # forced consensus
syscon posix _POSIX_PIPE_BUF 0x0200 0x0200 0x0200 0x0200 0x0200 0 # unix consensus
syscon posix _POSIX_RE_DUP_MAX 255 255 255 255 255 0 # unix consensus
syscon posix _POSIX_SEM_NSEMS_MAX 0x0100 0x0100 0x0100 0x0100 0x0100 0 # unix consensus
syscon posix _POSIX_SEM_VALUE_MAX 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff 0 # unix consensus
syscon posix _POSIX_SSIZE_MAX 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff 0 # unix consensus
syscon posix _POSIX_STREAM_MAX 8 8 8 8 8 0 # unix consensus
syscon posix _POSIX_SYMLINK_MAX 255 255 255 255 255 0 # unix consensus
syscon posix _POSIX_SYMLOOP_MAX 8 8 8 8 8 0 # unix consensus
syscon posix _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 4 4 4 4 0 # unix consensus
syscon posix _POSIX_THREAD_KEYS_MAX 0x80 0x80 0x80 0x80 0x80 0 # unix consensus
syscon posix _POSIX_TTY_NAME_MAX 9 9 9 9 9 0 # unix consensus
syscon posix _POSIX_TZNAME_MAX 6 6 6 6 6 0 # unix consensus
syscon posix _POSIX_CLOCK_SELECTION 0x031069 -1 -1 -1 -1 0 # bsd consensus
syscon posix _POSIX_FSYNC 0x031069 0x030db0 0x030db0 0x030db0 0x030db0 0 # bsd consensus
syscon posix _POSIX_MAPPED_FILES 0x031069 0x030db0 0x030db0 0x030db0 0x030db0 0 # bsd consensus
syscon posix _POSIX_MEMORY_PROTECTION 0x031069 0x030db0 0x030db0 0x030db0 0x030db0 0 # bsd consensus
syscon posix _POSIX_READER_WRITER_LOCKS 0x031069 0x030db0 0x030db0 0x030db0 0x030db0 0 # bsd consensus
syscon posix _POSIX_THREADS 0x031069 0x030db0 0x030db0 0x030db0 0x030db0 0 # bsd consensus
syscon posix _POSIX_THREAD_ATTR_STACKADDR 0x031069 0x030db0 0x030db0 0x030db0 0x030db0 0 # bsd consensus
syscon posix _POSIX_THREAD_ATTR_STACKSIZE 0x031069 0x030db0 0x030db0 0x030db0 0x030db0 0 # bsd consensus
syscon posix _POSIX_ADVISORY_INFO 0x031069 -1 0x030db0 -1 -1 0
syscon posix _POSIX_ASYNCHRONOUS_IO 0x031069 -1 0x030db0 -1 -1 0
syscon posix _POSIX_BARRIERS 0x031069 -1 0x030db0 0x030db0 0x030db0 0
syscon posix _POSIX_JOB_CONTROL 1 0x030db0 1 1 1 0
syscon posix _POSIX_MEMLOCK 0x031069 -1 -1 0x030db0 0x030db0 0
syscon posix _POSIX_MEMLOCK_RANGE 0x031069 -1 0x030db0 0x030db0 0x030db0 0
syscon posix _POSIX_MESSAGE_PASSING 0x031069 -1 0x030db0 -1 -1 0
syscon posix _POSIX_NO_TRUNC 1 0x030db0 1 1 1 0
syscon posix _POSIX_RAW_SOCKETS 0x031069 -1 0x030db0 0x030db0 0x030db0 0
syscon posix _POSIX_REALTIME_SIGNALS 0x031069 -1 0x030db0 -1 -1 0
syscon posix _POSIX_REGEXP 1 0x030db0 1 1 1 0
syscon posix _POSIX_SEMAPHORES 0x031069 -1 0x030db0 0x030db0 0x030db0 0
syscon posix _POSIX_SHARED_MEMORY_OBJECTS 0x031069 -1 0x030db0 0x031069 0x031069 0
syscon posix _POSIX_SHELL 1 0x030db0 1 1 1 0
syscon posix _POSIX_SPAWN 0x031069 -1 0x030db0 0x030db0 0x030db0 0
syscon posix _POSIX_SPIN_LOCKS 0x031069 -1 0x030db0 0x030db0 0x030db0 0
syscon posix _POSIX_THREAD_PRIORITY_SCHEDULING 0x031069 -1 0x030db0 -1 -1 0
syscon posix _POSIX_THREAD_PROCESS_SHARED 0x031069 0x030db0 0x030db0 -1 -1 0
syscon posix _POSIX_THREAD_SAFE_FUNCTIONS 0x031069 0x030db0 -1 0x030db0 0x030db0 0
syscon posix _POSIX_THREAD_THREADS_MAX 0x40 0x40 0x40 4 4 0
syscon posix _POSIX_TIMEOUTS 0x031069 -1 0x030db0 0x030db0 0x030db0 0
syscon posix _POSIX_TIMERS 0x031069 -1 0x030db0 -1 -1 0
syscon posix _POSIX_VERSION 0x031069 0x030db0 0x030db0 0x031069 0x031069 0
syscon posix _POSIX_VDISABLE 0 255 255 255 255 0 # bsd consensus
syscon posix _POSIX_AIO_LISTIO_MAX 2 2 2 0 0 0
syscon posix _POSIX_AIO_MAX 1 1 1 0 0 0
syscon posix _POSIX_CHOWN_RESTRICTED 0 0x030db0 1 1 1 0
syscon posix _POSIX_CLOCKRES_MIN 0x01312d00 0 0x01312d00 0x01312d00 0x01312d00 0
syscon posix _POSIX_CPUTIME 0 -1 0x030db0 0x031069 0x031069 0
syscon posix _POSIX_DELAYTIMER_MAX 0x20 0x20 0x20 0 0 0
syscon posix _POSIX_MONOTONIC_CLOCK 0 -1 0x030db0 0x030db0 0x030db0 0
syscon posix _POSIX_MQ_OPEN_MAX 8 8 8 0 0 0
syscon posix _POSIX_MQ_PRIO_MAX 0x20 0x20 0x20 0 0 0
syscon posix _POSIX_RTSIG_MAX 8 8 8 0 0 0
syscon posix _POSIX_SAVED_IDS 1 0x030db0 0 1 1 0
syscon posix _POSIX_SIGQUEUE_MAX 0x20 0x20 0x20 0 0 0
syscon posix _POSIX_THREAD_CPUTIME 0 -1 0x030db0 0x031069 0x031069 0
syscon posix _POSIX_TIMER_MAX 0x20 0x20 0x20 0 0 0
syscon posix _POSIX_IPV6 0x031069 0x030db0 0 0 0 0
syscon posix _POSIX_SS_REPL_MAX 0 4 4 0 0 0
syscon posix _POSIX_TRACE_EVENT_NAME_MAX 0 30 30 0 0 0
syscon posix _POSIX_TRACE_NAME_MAX 0 8 8 0 0 0
syscon posix _POSIX_TRACE_SYS_MAX 0 8 8 0 0 0
syscon posix _POSIX_TRACE_USER_EVENT_MAX 0 0x20 0x20 0 0 0
syscon posix _POSIX_V6_LP64_OFF64 1 1 0 0 0 0
syscon posix _POSIX_V7_LP64_OFF64 1 1 0 0 0 0
syscon misc TYPE_DISK 0 0 0 0 0 0 # consensus
syscon misc TYPE_A 1 1 1 1 1 0 # unix consensus
syscon misc TYPE_E 2 2 2 2 2 0 # unix consensus
@ -3277,18 +3206,6 @@ syscon misc TYPE_SCANNER 6 0 0 0 0 0
syscon misc TYPE_TAPE 1 0 0 0 0 0
syscon misc TYPE_WORM 4 0 0 0 0 0
syscon misc _POSIX2_BC_BASE_MAX 99 99 99 99 99 0 # unix consensus
syscon misc _POSIX2_BC_DIM_MAX 0x0800 0x0800 0x0800 0x0800 0x0800 0 # unix consensus
syscon misc _POSIX2_BC_SCALE_MAX 99 99 99 99 99 0 # unix consensus
syscon misc _POSIX2_BC_STRING_MAX 0x03e8 0x03e8 0x03e8 0x03e8 0x03e8 0 # unix consensus
syscon misc _POSIX2_CHARCLASS_NAME_MAX 14 14 14 14 14 0 # unix consensus
syscon misc _POSIX2_COLL_WEIGHTS_MAX 2 2 2 2 2 0 # unix consensus
syscon misc _POSIX2_EXPR_NEST_MAX 0x20 0x20 0x20 0x20 0x20 0 # unix consensus
syscon misc _POSIX2_LINE_MAX 0x0800 0x0800 0x0800 0x0800 0x0800 0 # unix consensus
syscon misc _POSIX2_RE_DUP_MAX 255 255 255 255 255 0 # unix consensus
syscon misc _POSIX2_C_BIND 0x031069 0x030db0 0x030db0 0x030db0 0x030db0 0 # bsd consensus
syscon misc _POSIX2_VERSION 0x031069 0x030db0 0x030a2c 0x031069 0x031069 0
syscon nd ND_RA_FLAG_MANAGED 0x80 0x80 0x80 0x80 0x80 0x80 # consensus
syscon nd ND_RA_FLAG_OTHER 0x40 0x40 0x40 0x40 0x40 0x40 # consensus
syscon nd ND_NA_FLAG_OVERRIDE 0x20 0x20 0x20 0x20 0x20 0x20000000 # unix consensus

View file

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

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,PIPE_BUF,4096,512,512,512,512,4096
.syscon limits,PIPE_BUF,4096,512,512,512,512,4096

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon limits,_ARG_MAX,128*1024,1024*1024,512*1024,512*1024,256*1024,32767*2

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon limits,_NAME_MAX,255,255,255,255,511,255

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon exit,EXIT_SUCCESS,0,0,0,0,0,0
.syscon limits,_NSIG,64,32,128,32,64,32

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon limits,_PATH_MAX,4096,1024,1024,1024,1024,512

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_BC_BASE_MAX,99,99,99,99,99,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_BC_DIM_MAX,0x0800,0x0800,0x0800,0x0800,0x0800,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_BC_SCALE_MAX,99,99,99,99,99,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_BC_STRING_MAX,0x03e8,0x03e8,0x03e8,0x03e8,0x03e8,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_CHARCLASS_NAME_MAX,14,14,14,14,14,0

View file

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

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_C_BIND,0x031069,0x030db0,0x030db0,0x030db0,0x030db0,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_EXPR_NEST_MAX,0x20,0x20,0x20,0x20,0x20,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_LINE_MAX,0x0800,0x0800,0x0800,0x0800,0x0800,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_RE_DUP_MAX,255,255,255,255,255,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon misc,_POSIX2_VERSION,0x031069,0x030db0,0x030a2c,0x031069,0x031069,0

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon posix,_POSIX_ADVISORY_INFO,0x031069,-1,0x030db0,-1,-1,0

View file

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

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