mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-21 01:50:30 +00:00
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:
parent
9a6bd304a5
commit
47b3274665
212 changed files with 2251 additions and 834 deletions
|
@ -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 *);
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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'\\') {
|
||||
|
|
|
@ -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))) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
51
libc/calls/getresgid.c
Normal 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
51
libc/calls/getresuid.c
Normal 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;
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
32
libc/calls/islinux.c
Normal 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;
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 *,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 "
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue