path
stringlengths 14
112
| content
stringlengths 0
6.32M
| size
int64 0
6.32M
| max_lines
int64 1
100k
| repo_name
stringclasses 2
values | autogenerated
bool 1
class |
---|---|---|---|---|---|
cosmopolitan/libc/calls/uname.c | /*-*- 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/struct/utsname-linux.internal.h"
#include "libc/calls/struct/utsname.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/nt/enum/computernameformat.h"
#include "libc/nt/struct/teb.h"
#include "libc/nt/systeminfo.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h"
#define CTL_KERN 1
#define KERN_OSTYPE 1
#define KERN_OSRELEASE 2
#define KERN_VERSION 4
#define KERN_HOSTNAME 10
#define KERN_DOMAINNAME 22
#define CTL_HW 6
#define HW_MACHINE 1
// Gets BSD sysctl() string, guaranteeing NUL-terminator.
// We ignore errors since this syscall mutates on ENOMEM.
// In that case, sysctl() doesn't guarantee the nul term.
static void GetBsdStr(int c0, int c1, char *s) {
char *p;
int e = errno;
size_t n = SYS_NMLN;
int cmd[2] = {c0, c1};
bzero(s, n), --n;
sys_sysctl(cmd, 2, s, &n, NULL, 0);
errno = e;
// sysctl kern.version is too verbose for uname
if ((p = strchr(s, '\n'))) {
*p = 0;
}
}
// Gets NT name ignoring errors with guaranteed NUL-terminator.
static textwindows void GetNtName(char *name, int kind) {
uint32_t n = SYS_NMLN;
char16_t name16[256];
uint32_t size = ARRAYLEN(name16);
if (GetComputerNameEx(kind, name16, &size)) {
tprecode16to8(name, SYS_NMLN, name16);
} else {
name[0] = 0;
}
}
static inline textwindows noasan int GetNtMajorVersion(void) {
return NtGetPeb()->OSMajorVersion;
}
static inline textwindows noasan int GetNtMinorVersion(void) {
return NtGetPeb()->OSMinorVersion;
}
static inline textwindows noasan int GetNtBuildNumber(void) {
return NtGetPeb()->OSBuildNumber;
}
static textwindows void GetNtVersion(char *p) {
p = FormatUint32(p, GetNtMajorVersion()), *p++ = '.';
p = FormatUint32(p, GetNtMinorVersion()), *p++ = '-';
p = FormatUint32(p, GetNtBuildNumber());
}
static const char *Str(int rc, const char *s) {
return !rc ? s : "n/a";
}
/**
* Asks kernel to give us `uname -a` data.
*
* - `machine` should be one of:
* - `x86_64`
* - `amd64`
*
* - `sysname` should be one of:
* - `Linux`
* - `FreeBSD`
* - `NetBSD`
* - `OpenBSD`
* - `Darwin`
* - `Windows`
*
* - `version` contains the distro name, version, and release date. On
* FreeBSD/NetBSD/OpenBSD this may contain newline characters, which
* this polyfill hides by setting the first newline character to nul
* although the information can be restored by putting newline back.
* BSDs usually repeat the `sysname` and `release` in the `version`.
*
* - `nodename` *may* be the first label of the fully qualified hostname
* of the current host. This is equivalent to gethostname(), except we
* guarantee a NUL-terminator here with truncation, which should never
* happen unless the machine violates the DNS standard. If it has dots
* then it's fair to assume it's an FQDN. On Linux this is the same as
* the content of `/proc/sys/kernel/hostname`.
*
* - `domainname` *may* be the higher-order labels of the FQDN for this
* host. This is equivalent to getdomainname(), except we guarantee a
* NUL-terminator here with truncation, which should never happen w/o
* violating the DNS standard. If this field is not present, it'll be
* coerced to empty string. On Linux, this is the same as the content
* of `/proc/sys/kernel/domainname`.
*
* The returned fields are guaranteed to be nul-terminated.
*
* @return 0 on success, or -1 w/ errno
* @raise EFAULT if `buf` isn't valid
* @raise ENOSYS on metal
*/
int uname(struct utsname *uts) {
int rc;
if (!uts || (IsAsan() && !__asan_is_valid(uts, sizeof(*uts)))) {
rc = efault();
} else if (IsLinux()) {
struct utsname_linux linux;
if (!(rc = sys_uname_linux(&linux))) {
stpcpy(uts->sysname, linux.sysname);
stpcpy(uts->nodename, linux.nodename);
stpcpy(uts->release, linux.release);
stpcpy(uts->version, linux.version);
stpcpy(uts->machine, linux.machine);
stpcpy(uts->domainname, linux.domainname);
if (!strcmp(uts->domainname, "(none)")) {
uts->domainname[0] = 0;
}
}
} else if (IsBsd()) {
GetBsdStr(CTL_KERN, KERN_OSTYPE, uts->sysname);
GetBsdStr(CTL_KERN, KERN_HOSTNAME, uts->nodename);
GetBsdStr(CTL_KERN, KERN_DOMAINNAME, uts->domainname);
GetBsdStr(CTL_KERN, KERN_OSRELEASE, uts->release);
GetBsdStr(CTL_KERN, KERN_VERSION, uts->version);
GetBsdStr(CTL_HW, HW_MACHINE, uts->machine);
rc = 0;
} else if (IsWindows()) {
stpcpy(uts->sysname, "Windows");
stpcpy(uts->machine, "x86_64");
GetNtVersion(stpcpy(uts->version, "Windows "));
GetNtVersion(uts->release);
GetNtName(uts->nodename, kNtComputerNamePhysicalDnsHostname);
GetNtName(uts->domainname, kNtComputerNamePhysicalDnsDomain);
rc = 0;
} else {
rc = enosys();
}
STRACE("uname([{%#s, %#s, %#s, %#s, %#s, %#s}]) â %d% m",
Str(rc, uts->sysname), Str(rc, uts->nodename), Str(rc, uts->release),
Str(rc, uts->version), Str(rc, uts->machine), Str(rc, uts->domainname),
rc);
return rc;
}
| 7,314 | 184 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fmodl.S | /*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-â
âvi: set et ft=asm ts=8 sw=8 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2020 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/runtime/pc.internal.h"
#include "libc/macros.internal.h"
// fmod [sic] does (ð¥ rem ð¦) w/ round()-style rounding.
//
// @param ð¥ is an 80-bit long double passed on stack in 16-bytes
// @param ð¦ is the power, also pushed on stack, in reverse order
// @return remainder â (-|ð¦|,|ð¦|) in %st
// @define ð¥-truncl(ð¥/ð¦)*ð¦
// @see emod()
fmodl: push %rbp
mov %rsp,%rbp
.profilable
fldt 32(%rbp)
fldt 16(%rbp)
1: fprem
fnstsw
test $FPU_C2>>8,%ah
jnz 1b
fstp %st(1)
pop %rbp
ret
1: int3
pop %rbp
ret
.endfn fmodl,globl
| 2,405 | 45 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/readlinkat.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
/**
* Reads symbolic link.
*
* This does *not* nul-terminate the buffer.
*
* @param dirfd is normally AT_FDCWD but if it's an open directory and
* file is a relative path, then file is opened relative to dirfd
* @param path must be a symbolic link pathname
* @param buf will receive symbolic link contents, and won't be modified
* unless the function succeeds (with the exception of no-malloc nt)
* and this buffer will *not* be nul-terminated
* @return number of bytes written to buf, or -1 w/ errno; if the
* return is equal to bufsiz then truncation may have occurred
* @error EINVAL if path isn't a symbolic link
* @asyncsignalsafe
*/
ssize_t readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz) {
ssize_t bytes;
if ((IsAsan() && !__asan_is_valid(buf, bufsiz)) || (bufsiz && !buf)) {
bytes = efault();
} else if (_weaken(__zipos_notat) &&
(bytes = __zipos_notat(dirfd, path)) == -1) {
STRACE("TODO: zipos support for readlinkat");
} else if (!IsWindows()) {
bytes = sys_readlinkat(dirfd, path, buf, bufsiz);
} else {
bytes = sys_readlinkat_nt(dirfd, path, buf, bufsiz);
}
STRACE("readlinkat(%s, %#s, [%#.*s]) â %d% m", DescribeDirfd(dirfd), path,
MAX(0, bytes), buf, bytes);
return bytes;
}
| 3,508 | 62 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/timespec_mono.c | /*-*- 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/assert.h"
#include "libc/calls/struct/timespec.h"
#include "libc/sysv/consts/clock.h"
/**
* Returns current monotonic time.
*
* This function uses a `CLOCK_MONOTONIC` clock and never fails.
*
* @see timespec_real()
*/
struct timespec timespec_mono(void) {
struct timespec ts;
_npassert(!clock_gettime(CLOCK_MONOTONIC, &ts));
return ts;
}
| 2,202 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/landlock_create_ruleset.c | /*-*- 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/landlock.h"
#include "libc/intrin/strace.internal.h"
int sys_landlock_create_ruleset(const struct landlock_ruleset_attr *, size_t,
uint32_t);
/**
* Create new Landlock filesystem sandboxing ruleset.
*
* You may also use this function to query the current ABI version:
*
* landlock_create_ruleset(0, 0, LANDLOCK_CREATE_RULESET_VERSION);
*
* @return close exec file descriptor for new ruleset
* @error ENOSYS if not running Linux 5.13+
* @error EPERM if pledge() or seccomp bpf shut it down
* @error EOPNOTSUPP Landlock supported but disabled at boot
* @error EINVAL unknown flags, or unknown access, or too small size
* @error E2BIG attr or size inconsistencies
* @error EFAULT attr or size inconsistencies
* @error ENOMSG empty landlock_ruleset_attr::handled_access_fs
*/
int landlock_create_ruleset(const struct landlock_ruleset_attr *attr,
size_t size, uint32_t flags) {
int rc;
rc = sys_landlock_create_ruleset(attr, size, flags);
KERNTRACE("landlock_create_ruleset(%p, %'zu, %#x) â %d% m", attr, size, flags,
rc);
return rc;
}
| 2,991 | 49 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fexecve.c | /*-*- 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/assert.h"
#include "libc/calls/blockcancel.internal.h"
#include "libc/calls/blocksigs.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/cp.internal.h"
#include "libc/calls/execve-sysv.internal.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/stat.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/fd.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/mfd.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/consts/shm.h"
#include "libc/sysv/errfuns.h"
static bool IsAPEFd(const int fd) {
char buf[8];
bool res;
return (sys_pread(fd, buf, 8, 0, 0) == 8) && IsAPEMagic(buf);
}
static int fexecve_impl(const int fd, char *const argv[], char *const envp[]) {
int rc;
if (IsLinux()) {
char path[14 + 12];
FormatInt32(stpcpy(path, "/proc/self/fd/"), fd);
rc = __sys_execve(path, argv, envp);
} else if (IsFreebsd()) {
rc = sys_fexecve(fd, argv, envp);
} else {
rc = enosys();
}
return rc;
}
typedef enum {
PTF_NUM = 1 << 0,
PTF_NUM2 = 1 << 1,
PTF_NUM3 = 1 << 2,
PTF_ANY = 1 << 3
} PTF_PARSE;
static bool ape_to_elf(void *ape, const size_t apesize) {
static const char printftok[] = "printf '";
static const size_t printftoklen = sizeof(printftok) - 1;
const char *tok = memmem(ape, apesize, printftok, printftoklen);
if (tok) {
tok += printftoklen;
uint8_t *dest = ape;
PTF_PARSE state = PTF_ANY;
uint8_t value = 0;
for (; tok < (const char *)(dest + apesize); tok++) {
if ((state & (PTF_NUM | PTF_NUM2 | PTF_NUM3)) &&
(*tok >= '0' && *tok <= '7')) {
value = (value << 3) | (*tok - '0');
state <<= 1;
if (state & PTF_ANY) {
*dest++ = value;
}
} else if (state & PTF_NUM) {
break;
} else {
if (state & (PTF_NUM2 | PTF_NUM3)) {
*dest++ = value;
}
if (*tok == '\\') {
state = PTF_NUM;
value = 0;
} else if (*tok == '\'') {
return true;
} else {
*dest++ = *tok;
state = PTF_ANY;
}
}
}
}
errno = ENOEXEC;
return false;
}
/**
* Creates a memfd and copies fd to it.
*
* This does an inplace conversion of APE to ELF when detected!!!!
*/
static int fd_to_mem_fd(const int infd, char *path) {
if (!IsLinux() && !IsFreebsd() || !_weaken(mmap) || !_weaken(munmap)) {
return enosys();
}
struct stat st;
if (fstat(infd, &st) == -1) {
return -1;
}
int fd;
if (IsLinux()) {
fd = sys_memfd_create(__func__, MFD_CLOEXEC);
} else if (IsFreebsd()) {
fd = sys_shm_open(SHM_ANON, O_CREAT | O_RDWR, 0);
} else {
return enosys();
}
if (fd == -1) {
return -1;
}
void *space;
if ((sys_ftruncate(fd, st.st_size, st.st_size) != -1) &&
((space = _weaken(mmap)(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0)) != MAP_FAILED)) {
ssize_t readRc;
readRc = pread(infd, space, st.st_size, 0);
bool success = readRc != -1;
if (success && (st.st_size > 8) && IsAPEMagic(space)) {
int flags = fcntl(fd, F_GETFD);
if (success = (flags != -1) &&
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
ape_to_elf(space, st.st_size)) {
const int newfd = fcntl(fd, F_DUPFD, 9001);
if (newfd != -1) {
close(fd);
fd = newfd;
}
}
}
const int e = errno;
if ((_weaken(munmap)(space, st.st_size) != -1) && success) {
if (path) {
FormatInt32(stpcpy(path, "COSMOPOLITAN_INIT_ZIPOS="), fd);
}
_unassert(readRc == st.st_size);
return fd;
} else if (!success) {
errno = e;
}
}
const int e = errno;
close(fd);
errno = e;
return -1;
}
/**
* Executes binary executable at file descriptor.
*
* This is only supported on Linux and FreeBSD. APE binaries are
* supported. Zipos is supported. Zipos fds or FD_CLOEXEC APE fds or
* fds that fail fexecve with ENOEXEC are copied to a new memfd (with
* in-memory APE to ELF conversion) and fexecve is (re)attempted.
*
* @param fd is opened executable and current file position is ignored
* @return doesn't return on success, otherwise -1 w/ errno
* @raise ENOEXEC if file at `fd` isn't an assimilated ELF executable
* @raise ENOSYS on Windows, XNU, OpenBSD, NetBSD, and Metal
*/
int fexecve(int fd, char *const argv[], char *const envp[]) {
int rc = 0;
if (!argv || !envp ||
(IsAsan() &&
(!__asan_is_valid_strlist(argv) || !__asan_is_valid_strlist(envp)))) {
rc = efault();
} else {
STRACE("fexecve(%d, %s, %s) â ...", fd, DescribeStringList(argv),
DescribeStringList(envp));
int savedErr = 0;
do {
if (!IsLinux() && !IsFreebsd()) {
rc = enosys();
break;
}
if (!__isfdkind(fd, kFdZip)) {
bool memfdReq;
BEGIN_CANCELLATION_POINT;
BLOCK_SIGNALS;
strace_enabled(-1);
memfdReq = ((rc = fcntl(fd, F_GETFD)) != -1) && (rc & FD_CLOEXEC) &&
IsAPEFd(fd);
strace_enabled(+1);
ALLOW_SIGNALS;
END_CANCELLATION_POINT;
if (rc == -1) {
break;
} else if (!memfdReq) {
fexecve_impl(fd, argv, envp);
if (errno != ENOEXEC) {
break;
}
savedErr = ENOEXEC;
}
}
int newfd;
char *path = alloca(PATH_MAX);
BEGIN_CANCELLATION_POINT;
BLOCK_SIGNALS;
strace_enabled(-1);
newfd = fd_to_mem_fd(fd, path);
strace_enabled(+1);
ALLOW_SIGNALS;
END_CANCELLATION_POINT;
if (newfd == -1) {
break;
}
size_t numenvs;
for (numenvs = 0; envp[numenvs];) ++numenvs;
const size_t desenvs = min(500, max(numenvs + 1, 2));
static _Thread_local char *envs[500];
memcpy(envs, envp, numenvs * sizeof(char *));
envs[numenvs] = path;
envs[numenvs + 1] = NULL;
fexecve_impl(newfd, argv, envs);
if (!savedErr) {
savedErr = errno;
}
BEGIN_CANCELLATION_POINT;
BLOCK_SIGNALS;
strace_enabled(-1);
close(newfd);
strace_enabled(+1);
ALLOW_SIGNALS;
END_CANCELLATION_POINT;
} while (0);
if (savedErr) {
errno = savedErr;
}
rc = -1;
}
STRACE("fexecve(%d) failed %d% m", fd, rc);
return rc;
}
| 8,659 | 260 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/sched_getparam.c | /*-*- 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/sched-sysv.internal.h"
#include "libc/calls/struct/sched_param.h"
#include "libc/calls/struct/sched_param.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h"
/**
* Gets scheduler policy parameter.
*
* @return 0 on success, or -1 w/ errno
* @raise ENOSYS on XNU, Windows, OpenBSD
*/
int sched_getparam(int pid, struct sched_param *param) {
int rc;
struct sched_param p;
if (!param || (IsAsan() && !__asan_is_valid(param, sizeof(*param)))) {
rc = efault();
} else if (IsNetbsd()) {
if (!(rc = sys_sched_getscheduler_netbsd(pid, &p))) {
*param = p;
}
} else {
rc = sys_sched_getparam(pid, param);
}
STRACE("sched_getparam(%d, [%s]) â %d% m", pid, DescribeSchedParam(param),
rc);
return rc;
}
| 2,694 | 49 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fchmodat-nt.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/files.h"
textwindows int sys_fchmodat_nt(int dirfd, const char *path, uint32_t mode,
int flags) {
uint32_t attr;
uint16_t path16[PATH_MAX];
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
if ((attr = GetFileAttributes(path16)) != -1u) {
if (mode & 0200) {
attr &= ~kNtFileAttributeReadonly;
} else {
attr |= kNtFileAttributeReadonly;
}
if (SetFileAttributes(path16, attr)) {
return 0;
}
}
return __winerr();
}
| 2,458 | 40 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/futimes.c | /*-*- 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/asan.internal.h"
#include "libc/calls/struct/itimerval.internal.h"
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timespec.internal.h"
#include "libc/calls/struct/timeval.h"
#include "libc/dce.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h"
/**
* Sets atime/mtime on file descriptor.
*
* @param ts is atime/mtime, or null for current time
* @return 0 on success, or -1 w/ errno
* @raise ENOTSUP if `fd` is on zip filesystem
* @raise EBADF if `fd` isn't an open file descriptor
* @raise EPERM if pledge() is in play without `fattr` promise
* @raise EINVAL if `tv` specifies a microsecond value that's out of range
* @raise ENOSYS on RHEL5 or bare metal
* @see futimens() for modern version
* @asyncsignalsafe
* @threadsafe
*/
int futimes(int fd, const struct timeval tv[2]) {
int rc;
struct timespec ts[2];
if (tv) {
ts[0].tv_sec = tv[0].tv_sec;
ts[0].tv_nsec = tv[0].tv_usec * 1000;
ts[1].tv_sec = tv[1].tv_sec;
ts[1].tv_nsec = tv[1].tv_usec * 1000;
rc = __utimens(fd, 0, ts, 0);
} else {
rc = __utimens(fd, 0, 0, 0);
}
STRACE("futimes(%d, {%s, %s}) â %d% m", fd, DescribeTimeval(0, tv),
DescribeTimeval(0, tv ? tv + 1 : 0), rc);
return rc;
}
| 3,114 | 61 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/ftruncate.c | /*-*- 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/cp.internal.h"
#include "libc/calls/internal.h"
#include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h"
/**
* Changes size of open file.
*
* If the file size is increased, the extended area shall appear as if
* it were zero-filled. If your file size is decreased, the extra data
* shall be lost.
*
* This function never changes the file position. This is true even if
* ftruncate() causes the position to become beyond the end of file in
* which case, the rules described in the lseek() documentation apply.
*
* Some operating systems implement an optimization, where `length` is
* treated as a logical size and the requested physical space won't be
* allocated until non-zero values get written into it. Our tests show
* this happens on Linux (usually with 4096 byte granularity), FreeBSD
* (which favors 512-byte granularity), and MacOS (prefers 4096 bytes)
* however Windows, OpenBSD, and NetBSD always reserve physical space.
* This may be inspected using fstat() and consulting stat::st_blocks.
*
* @param fd must be open for writing
* @param length may be greater than current current file size
* @return 0 on success, or -1 w/ errno
* @raise EINVAL if `length` is negative
* @raise EINTR if signal was delivered instead
* @raise ECANCELED if thread was cancelled in masked mode
* @raise EIO if a low-level i/o error happened
* @raise EFBIG or EINVAL if `length` is too huge
* @raise ENOTSUP if `fd` is a zip file descriptor
* @raise EBADF if `fd` isn't an open file descriptor
* @raise EINVAL if `fd` is a non-file, e.g. pipe, socket
* @raise EINVAL if `fd` wasn't opened in a writeable mode
* @raise ENOSYS on bare metal
* @cancellationpoint
* @asyncsignalsafe
* @threadsafe
*/
int ftruncate(int fd, int64_t length) {
int rc;
BEGIN_CANCELLATION_POINT;
if (fd < 0) {
rc = ebadf();
} else if (__isfdkind(fd, kFdZip)) {
rc = enotsup();
} else if (IsMetal()) {
rc = enosys();
} else if (!IsWindows()) {
rc = sys_ftruncate(fd, length, length);
if (IsNetbsd() && rc == -1 && errno == ENOSPC) {
errno = EFBIG; // POSIX doesn't specify ENOSPC for ftruncate()
}
} else if (__isfdopen(fd)) {
rc = sys_ftruncate_nt(g_fds.p[fd].handle, length);
} else {
rc = ebadf();
}
END_CANCELLATION_POINT;
STRACE("ftruncate(%d, %'ld) â %d% m", fd, length, rc);
return rc;
}
| 4,400 | 90 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/termios.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
#include "libc/calls/struct/metatermios.internal.h"
#include "libc/calls/struct/termios.h"
#define COPY_TERMIOS(TO, FROM) \
do { \
uint32_t Cc3; \
uint64_t Cc1, Cc2; \
autotype((TO)->c_iflag) c_iflag = (FROM)->c_iflag; \
autotype((TO)->c_oflag) c_oflag = (FROM)->c_oflag; \
autotype((TO)->c_cflag) c_cflag = (FROM)->c_cflag; \
autotype((TO)->c_lflag) c_lflag = (FROM)->c_lflag; \
__builtin_memcpy(&Cc1, (FROM)->c_cc + 000, 8); \
__builtin_memcpy(&Cc2, (FROM)->c_cc + 010, 8); \
__builtin_memcpy(&Cc3, (FROM)->c_cc + 020, 4); \
autotype((TO)->c_ispeed) c_ispeed = (FROM)->c_ispeed; \
autotype((TO)->c_ospeed) c_ospeed = (FROM)->c_ospeed; \
(TO)->c_iflag = c_iflag; \
(TO)->c_oflag = c_oflag; \
(TO)->c_cflag = c_cflag; \
(TO)->c_lflag = c_lflag; \
__builtin_memcpy((TO)->c_cc + 000, &Cc1, 8); \
__builtin_memcpy((TO)->c_cc + 010, &Cc2, 8); \
__builtin_memcpy((TO)->c_cc + 020, &Cc3, 4); \
(TO)->c_ispeed = c_ispeed; \
(TO)->c_ospeed = c_ospeed; \
} while (0)
void *__termios2host(union metatermios *, const struct termios *);
#endif /* COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_ */
| 1,656 | 33 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fstatat64.S | /*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-â
âvi: set et ft=asm ts=8 tw=8 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â This is free and unencumbered software released into the public domain. â
â â
â Anyone is free to copy, modify, publish, use, compile, sell, or â
â distribute this software, either in source code form or as a compiled â
â binary, for any purpose, commercial or non-commercial, and by any â
â means. â
â â
â In jurisdictions that recognize copyright laws, the author or authors â
â of this software dedicate any and all copyright interest in the â
â software to the public domain. We make this dedication for the benefit â
â of the public at large and to the detriment of our heirs and â
â successors. We intend this dedication to be an overt act of â
â relinquishment in perpetuity of all present and future rights to this â
â software under copyright law. â
â â
â THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, â
â EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF â
â MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. â
â IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR â
â OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, â
â ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR â
â OTHER DEALINGS IN THE SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/macros.internal.h"
fstatat64:
jmp fstatat
.endfn fstatat64,globl
| 2,599 | 32 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fileexists.c | /*-*- 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/struct/metastat.internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/nt/files.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
/**
* Returns true if file exists at path.
*
* This function is equivalent to:
*
* struct stat st;
* return stat(path, &st) != -1;
*
* Please note that things which aren't strictly files, e.g. directories
* or sockets, could be considered files for the purposes of this
* function. The stat() function may be used to differentiate them.
*/
bool fileexists(const char *path) {
int e;
bool res;
union metastat st;
struct ZiposUri zipname;
uint16_t path16[PATH_MAX];
e = errno;
if (IsAsan() && !__asan_is_valid_str(path)) {
efault();
res = false;
} else if (_weaken(__zipos_open) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) {
res = true;
} else {
res = false;
}
} else if (IsMetal()) {
res = false;
} else if (!IsWindows()) {
if (__sys_fstatat(AT_FDCWD, path, &st, 0) != -1) {
res = true;
} else {
res = false;
}
} else if (__mkntpath(path, path16) != -1) {
res = GetFileAttributes(path16) != -1u;
} else {
res = false;
}
STRACE("%s(%#s) â %hhhd% m", "fileexists", path, res);
if (!res && (errno == ENOENT || errno == ENOTDIR)) {
errno = e;
}
return res;
}
| 3,622 | 83 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/ttyname_r.c | /*-*- 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/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/strace.internal.h"
#include "libc/log/log.h"
#include "libc/nt/console.h"
#include "libc/nt/enum/consolemodeflags.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"
static textwindows dontinline int sys_ttyname_nt(int fd, char *buf,
size_t size) {
uint32_t mode;
if (GetConsoleMode(g_fds.p[fd].handle, &mode)) {
if (mode & kNtEnableVirtualTerminalInput) {
strncpy(buf, "CONIN$", size);
return 0;
} else {
strncpy(buf, "CONOUT$", size);
return 0;
}
} else {
return enotty();
}
}
static int ttyname_freebsd(int fd, char *buf, size_t size) {
const unsigned FIODGNAME = 2148558456;
struct fiodgname_arg {
int len;
void *buf;
} fg;
fg.buf = buf;
fg.len = size;
if (sys_ioctl(fd, FIODGNAME, &fg) != -1) return 0;
return enotty();
}
static int ttyname_linux(int fd, char *buf, size_t size) {
struct stat st1, st2;
if (!isatty(fd)) return errno;
char name[PATH_MAX];
FormatInt32(stpcpy(name, "/proc/self/fd/"), fd);
ssize_t got;
got = readlink(name, buf, size);
if (got == -1) return errno;
if ((size_t)got >= size) return erange();
buf[got] = 0;
if (stat(buf, &st1) || fstat(fd, &st2)) return errno;
if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) return enodev();
return 0;
}
/**
* Returns name of terminal, reentrantly.
*/
int ttyname_r(int fd, char *buf, size_t size) {
int rc;
if (IsLinux()) {
rc = ttyname_linux(fd, buf, size);
} else if (IsFreebsd()) {
rc = ttyname_freebsd(fd, buf, size);
} else if (IsWindows()) {
if (__isfdkind(fd, kFdFile)) {
rc = sys_ttyname_nt(fd, buf, size);
} else {
rc = ebadf();
}
} else {
rc = enosys();
}
STRACE("ttyname_r(%d, %s) â %d% m", fd, buf, rc);
return rc;
}
| 3,945 | 99 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/usleep.c | /*-*- 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/struct/timespec.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/errfuns.h"
#include "libc/time/time.h"
/**
* Sleeps for particular number of microseconds.
*
* @return 0 on success, or -1 w/ errno
* @raise EINTR if a signal was delivered while sleeping
* @raise ECANCELED if thread was cancelled in masked mode
* @see clock_nanosleep()
* @cancellationpoint
* @norestart
*/
int usleep(uint32_t micros) {
struct timespec ts = timespec_frommicros(micros);
if (clock_nanosleep(CLOCK_REALTIME, 0, &ts, 0)) return eintr();
return 0;
}
| 2,412 | 39 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/cfspeed.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/termios.h"
#include "libc/sysv/consts/termios.h"
#include "libc/sysv/errfuns.h"
/**
* Returns input baud rate.
* @asyncsignalsafe
*/
uint32_t cfgetispeed(const struct termios *t) {
if (CBAUD) {
return t->c_cflag & CBAUD;
} else {
return t->c_ispeed;
}
}
/**
* Returns output baud rate.
* @asyncsignalsafe
*/
uint32_t cfgetospeed(const struct termios *t) {
if (CBAUD) {
return t->c_cflag & CBAUD;
} else {
return t->c_ospeed;
}
}
/**
* Sets input baud rate.
*
* @return 0 on success, or -1 w/ errno
* @asyncsignalsafe
*/
int cfsetispeed(struct termios *t, unsigned speed) {
if (speed) {
if (CBAUD) {
if (!(speed & ~CBAUD)) {
t->c_cflag &= ~CBAUD;
t->c_cflag |= speed;
} else {
return einval();
}
} else {
t->c_ispeed = speed;
}
}
return 0;
}
/**
* Sets output baud rate.
*
* @return 0 on success, or -1 w/ errno
* @asyncsignalsafe
*/
int cfsetospeed(struct termios *t, unsigned speed) {
if (CBAUD) {
if (!(speed & ~CBAUD)) {
t->c_cflag &= ~CBAUD;
t->c_cflag |= speed;
return 0;
} else {
return einval();
}
} else {
t->c_ospeed = speed;
return 0;
}
}
| 3,070 | 89 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/ntsetprivilege.c | /*-*- 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/nt/privilege.h"
#include "libc/nt/struct/tokenprivileges.h"
/**
* Sets NT permission thing, e.g.
*
* int64_t htoken;
* if (OpenProcessToken(GetCurrentProcess(),
* kNtTokenAdjustPrivileges | kNtTokenQuery,
* &htoken)) {
* ntsetprivilege(htoken, u"SeManageVolumePrivilege",
* kNtSePrivilegeEnabled);
* CloseHandle(htoken);
* }
*/
textwindows bool32 ntsetprivilege(int64_t token, const char16_t *name,
uint32_t attrs) {
struct NtTokenPrivileges tp;
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = attrs;
return LookupPrivilegeValue(NULL, name, &tp.Privileges[0].Luid) &&
AdjustTokenPrivileges(token, false, &tp,
sizeof(struct NtTokenPrivileges), NULL, NULL);
}
| 2,703 | 43 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/rmdir.c | /*-*- 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/sysv/consts/at.h"
/**
* Deletes empty directory.
*
* @return 0 on success, or -1 w/ errno
*/
int rmdir(const char *path) {
return unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
}
| 2,060 | 30 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/ttyname.c | /*-*- 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/log/log.h"
static char ttyname_buf[PATH_MAX];
/**
* Returns name of terminal.
*/
char *ttyname(int fd) {
int rc = ttyname_r(fd, ttyname_buf, sizeof(ttyname_buf));
if (rc != 0) return NULL;
return &ttyname_buf[0];
}
| 2,106 | 32 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/clock.c | /*-*- 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/sysv/consts/clock.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h"
#include "libc/errno.h"
#include "libc/sysv/consts/rusage.h"
#include "libc/time/time.h"
/**
* Returns sum of CPU time consumed by current process since birth.
*
* This function provides a basic idea of how computationally expensive
* your program is, in terms of both the userspace and kernel processor
* resources it's hitherto consumed. Here's an example of how you might
* display this information:
*
* printf("consumed %g seconds of cpu time\n",
* (double)clock() / CLOCKS_PER_SEC);
*
* This function offers at best microsecond accuracy on all supported
* platforms. Please note the reported values might be a bit chunkier
* depending on the kernel scheduler sampling interval see `CLK_TCK`.
*
* @return units of CPU time consumed, where each unit's time length
* should be `1./CLOCKS_PER_SEC` seconds; Cosmopolitan currently
* returns the unit count in microseconds, i.e. `CLOCKS_PER_SEC`
* is hard-coded as 1000000. On failure this returns -1 / errno.
* @raise ENOSYS should be returned currently if run on Bare Metal
* @see clock_gettime() which polyfills this on Linux and BSDs
* @see getrusage() which polyfills this on XNU and NT
*/
int64_t clock(void) {
int e;
struct rusage ru;
struct timespec ts;
e = errno;
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1) {
errno = e;
if (getrusage(RUSAGE_SELF, &ru) != -1) {
ts = timeval_totimespec(timeval_add(ru.ru_utime, ru.ru_stime));
} else {
return -1;
}
}
// convert nanoseconds to microseconds w/ ceil rounding
// this would need roughly ~7,019,309 years to overflow
return ts.tv_sec * 1000000 + (ts.tv_nsec + 999) / 1000;
}
| 3,675 | 67 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/sigcount.c | /*-*- 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/sig.internal.h"
atomic_long __sig_count;
| 1,899 | 22 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/clock_gettime-xnu.c | /*-*- 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/clock_gettime.internal.h"
#include "libc/calls/struct/timeval.internal.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/errfuns.h"
int sys_clock_gettime_xnu(int clock, struct timespec *ts) {
axdx_t ad;
if (clock == CLOCK_REALTIME) {
ad = sys_gettimeofday((struct timeval *)ts, 0, 0);
if (ad.ax != -1) {
if (ad.ax) {
ts->tv_sec = ad.ax;
ts->tv_nsec = ad.dx;
}
ts->tv_nsec *= 1000;
return 0;
} else {
return -1;
}
} else if (clock == CLOCK_MONOTONIC) {
return sys_clock_gettime_mono(ts);
} else {
return einval();
}
}
| 2,464 | 44 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fstatfs-nt.c | /*-*- 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/struct/fsid.h"
#include "libc/calls/struct/statfs.h"
#include "libc/calls/struct/statfs.internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/intrin/tpenc.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/nt/enum/fsinformationclass.h"
#include "libc/nt/enum/status.h"
#include "libc/nt/files.h"
#include "libc/nt/ntdll.h"
#include "libc/nt/struct/byhandlefileinformation.h"
#include "libc/nt/struct/filefsfullsizeinformation.h"
#include "libc/nt/struct/iostatusblock.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"
textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) {
uint64_t w;
NtStatus st;
uint32_t type;
uint32_t h, i, j;
struct NtIoStatusBlock io;
struct NtFileFsFullSizeInformation fs;
char16_t VolumeNameBuffer[261];
uint32_t VolumeSerialNumber;
uint32_t MaximumComponentLength;
uint32_t FileSystemFlags;
char16_t FileSystemNameBuffer[261];
if (!GetVolumeInformationByHandle(
handle, VolumeNameBuffer, ARRAYLEN(VolumeNameBuffer),
&VolumeSerialNumber, &MaximumComponentLength, &FileSystemFlags,
FileSystemNameBuffer, ARRAYLEN(FileSystemNameBuffer))) {
return __winerr();
}
st = NtQueryVolumeInformationFile(handle, &io, &fs, sizeof(fs),
kNtFileFsFullSizeInformation);
if (!NtSuccess(st)) {
if (st == kNtStatusDllNotFound) return enosys();
return eio();
}
for (h = j = i = 0; FileSystemNameBuffer[i]; i++) {
w = _tpenc(FileSystemNameBuffer[i]);
do {
if (j + 1 < sizeof(f->f_fstypename)) {
h = ((unsigned)(w & 255) + h) * 0x9e3779b1u;
f->f_fstypename[j++] = w;
}
} while ((w >>= 8));
}
f->f_fstypename[j] = 0;
f->f_type = h;
f->f_fsid = (fsid_t){{VolumeSerialNumber}};
f->f_flags = FileSystemFlags;
f->f_bsize = fs.BytesPerSector;
f->f_bsize *= fs.SectorsPerAllocationUnit;
f->f_frsize = f->f_bsize;
f->f_blocks = fs.TotalAllocationUnits;
f->f_bfree = fs.ActualAvailableAllocationUnits;
f->f_bavail = fs.CallerAvailableAllocationUnits;
f->f_files = INT64_MAX;
f->f_ffree = INT64_MAX;
f->f_namelen = 255;
f->f_owner = 0;
return 0;
}
| 4,119 | 87 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/setresuid.c | /*-*- 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/syscall-sysv.internal.h"
#include "libc/intrin/strace.internal.h"
/**
* Sets real, effective, and "saved" user ids.
*
* @param real sets real user id or -1 to do nothing
* @param effective sets effective user id or -1 to do nothing
* @param saved sets saved user id or -1 to do nothing
* @see setresgid(), getauxval(AT_SECURE)
* @raise ENOSYS on Windows NT
*/
int setresuid(uint32_t real, uint32_t effective, uint32_t saved) {
int rc;
if (saved != -1) {
rc = sys_setresuid(real, effective, saved);
} else {
// polyfill xnu and netbsd
rc = sys_setreuid(real, effective);
}
STRACE("setresuid(%d, %d, %d) â %d% m", real, effective, saved, rc);
return rc;
}
| 2,576 | 43 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/ntspawn.h | #ifndef COSMOPOLITAN_LIBC_CALLS_NTSPAWN_H_
#define COSMOPOLITAN_LIBC_CALLS_NTSPAWN_H_
#include "libc/nt/struct/processinformation.h"
#include "libc/nt/struct/securityattributes.h"
#include "libc/nt/struct/startupinfo.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int mkntcmdline(char16_t[ARG_MAX / 2], char *const[]) _Hide;
int mkntenvblock(char16_t[ARG_MAX / 2], char *const[], const char *,
char[ARG_MAX]) _Hide;
int ntspawn(const char *, char *const[], char *const[], const char *,
struct NtSecurityAttributes *, struct NtSecurityAttributes *,
bool32, uint32_t, const char16_t *, const struct NtStartupInfo *,
struct NtProcessInformation *) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_NTSPAWN_H_ */
| 838 | 20 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/touch.c | /*-*- 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/blockcancel.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/timeval.h"
#include "libc/errno.h"
#include "libc/sysv/consts/o.h"
/**
* Creates new file or changes modified time on existing one.
*
* @param file is a UTF-8 string, which may or may not exist
* @param mode is an octal user/group/other permission, e.g. 0755
* @return 0 on success, or -1 w/ errno
* @see creat()
*/
int touch(const char *file, uint32_t mode) {
int rc, fd, olderr;
olderr = errno;
if ((rc = utimes(file, 0)) == -1 && errno == ENOENT) {
errno = olderr;
BLOCK_CANCELLATIONS;
fd = open(file, O_CREAT | O_WRONLY, mode);
ALLOW_CANCELLATIONS;
if (fd == -1) return -1;
return close(fd);
}
return rc;
}
| 2,592 | 46 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/mkntcmdline.c | /*-*- 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/ntspawn.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/str/thompike.h"
#include "libc/str/utf16.h"
#include "libc/sysv/errfuns.h"
#define APPEND(c) \
do { \
cmdline[k++] = c; \
if (k == ARG_MAX / 2) { \
return e2big(); \
} \
} while (0)
static bool NeedsQuotes(const char *s) {
if (!*s) return true;
do {
switch (*s) {
case '"':
case ' ':
case '\t':
case '\v':
case '\n':
return true;
default:
break;
}
} while (*s++);
return false;
}
static inline int IsAlpha(int c) {
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
}
// Converts System V argv to Windows-style command line.
//
// Escaping is performed and it's designed to round-trip with
// GetDosArgv() or GetDosArgv(). This function does NOT escape
// command interpreter syntax, e.g. $VAR (sh), %VAR% (cmd).
//
// TODO(jart): this needs fuzzing and security review
//
// @param cmdline is output buffer
// @param argv is an a NULL-terminated array of UTF-8 strings
// @return 0 on success, or -1 w/ errno
// @raise E2BIG if everything is too huge
// @see "Everyone quotes command line arguments the wrong way" MSDN
// @see libc/runtime/getdosargv.c
textwindows int mkntcmdline(char16_t cmdline[ARG_MAX / 2], char *const argv[]) {
uint64_t w;
wint_t x, y;
int slashes, n;
bool needsquote;
char16_t cbuf[2];
char *ansiargv[2];
size_t i, j, k, s;
if (!argv[0]) {
bzero(ansiargv, sizeof(ansiargv));
argv = ansiargv;
}
for (k = i = 0; argv[i]; ++i) {
if (i) APPEND(u' ');
if ((needsquote = NeedsQuotes(argv[i]))) APPEND(u'"');
for (slashes = j = 0;;) {
x = argv[i][j++] & 255;
if (x >= 0300) {
n = ThomPikeLen(x);
x = ThomPikeByte(x);
while (--n) {
if ((y = argv[i][j++] & 255)) {
x = ThomPikeMerge(x, y);
} else {
x = 0;
break;
}
}
}
if (!x) break;
if (x == '/' || x == '\\') {
if (!i) {
// turn / into \ for first argv[i]
x = '\\';
// turn \c\... into c:\ for first argv[i]
if (k == 2 && IsAlpha(cmdline[1]) && cmdline[0] == '\\') {
cmdline[0] = cmdline[1];
cmdline[1] = ':';
}
} else {
// turn stuff like `less /c/...`
// into `less c:/...`
// turn stuff like `more <"/c/..."`
// into `more <"c:/..."`
if (k > 3 && IsAlpha(cmdline[k - 1]) &&
(cmdline[k - 2] == '/' || cmdline[k - 2] == '\\') &&
(cmdline[k - 3] == '"' || cmdline[k - 3] == ' ')) {
cmdline[k - 2] = cmdline[k - 1];
cmdline[k - 1] = ':';
}
}
}
if (x == '\\') {
++slashes;
} else if (x == '"') {
APPEND(u'"');
APPEND(u'"');
APPEND(u'"');
} else {
for (s = 0; s < slashes; ++s) {
APPEND(u'\\');
}
slashes = 0;
w = EncodeUtf16(x);
do {
APPEND(w);
} while ((w >>= 16));
}
}
for (s = 0; s < (slashes << needsquote); ++s) {
APPEND(u'\\');
}
if (needsquote) {
APPEND(u'"');
}
}
cmdline[k] = u'\0';
return 0;
}
| 5,240 | 148 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/poll.c | /*-*- 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/cp.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/sock/struct/pollfd.internal.h"
#include "libc/sysv/errfuns.h"
/**
* Waits for something to happen on multiple file descriptors at once.
*
* Warning: XNU has an inconsistency with other platforms. If you have
* pollfds with fdâ¥0 and none of the meaningful events flags are added
* e.g. POLLIN then XNU won't check for POLLNVAL. This matters because
* one of the use-cases for poll() is quickly checking for open files.
*
* Note: Polling works best on Windows for sockets. We're able to poll
* input on named pipes. But for anything that isn't a socket, or pipe
* with POLLIN, (e.g. regular file) then POLLIN/POLLOUT are always set
* into revents if they're requested, provided they were opened with a
* mode that permits reading and/or writing.
*
* Note: Windows has a limit of 64 file descriptors and ENOMEM with -1
* is returned if that limit is exceeded. In practice the limit is not
* this low. For example, pollfds with fd<0 don't count. So the caller
* could flip the sign bit with a short timeout, to poll a larger set.
*
* @param fds[ð].fd should be a socket, input pipe, or conosle input
* and if it's a negative number then the entry is ignored
* @param fds[ð].events flags can have POLLIN, POLLOUT, POLLPRI,
* POLLRDNORM, POLLWRNORM, POLLRDBAND, POLLWRBAND as well as
* POLLERR, POLLHUP, and POLLNVAL although the latter are
* always implied (assuming fdâ¥0) so they're ignored here
* @param timeout_ms if 0 means don't wait and -1 means wait forever
* @return number of items fds whose revents field has been set to
* nonzero to describe its events, or 0 if the timeout elapsed,
* or -1 w/ errno
* @return fds[ð].revents is always zero initializaed and then will
* be populated with POLL{IN,OUT,PRI,HUP,ERR,NVAL} if something
* was determined about the file descriptor
* @raise ECANCELED if thread was cancelled in masked mode
* @raise EINTR if signal was delivered
* @cancellationpoint
* @asyncsignalsafe
* @threadsafe
* @norestart
*/
int poll(struct pollfd *fds, size_t nfds, int timeout_ms) {
int rc;
size_t n;
uint64_t millis;
BEGIN_CANCELLATION_POINT;
if (IsAsan() && (__builtin_mul_overflow(nfds, sizeof(struct pollfd), &n) ||
!__asan_is_valid(fds, n))) {
rc = efault();
} else if (!IsWindows()) {
if (!IsMetal()) {
rc = sys_poll(fds, nfds, timeout_ms);
} else {
rc = sys_poll_metal(fds, nfds, timeout_ms);
}
} else {
millis = timeout_ms;
rc = sys_poll_nt(fds, nfds, &millis, 0);
}
END_CANCELLATION_POINT;
STRACE("poll(%s, %'zu, %'d) â %d% lm", DescribePollFds(rc, fds, nfds), nfds,
timeout_ms, rc);
return rc;
}
| 4,729 | 91 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/tcsetattr.c | /*-*- 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/ioctl.h"
#include "libc/calls/termios.h"
#include "libc/sysv/consts/termios.h"
#include "libc/sysv/errfuns.h"
/**
* Sets struct on teletypewriter w/ drains and flushes.
*
* @param fd open file descriptor that isatty()
* @param opt can be:
* - TCSANOW: sets console settings
* - TCSADRAIN: drains output, and sets console settings
* - TCSAFLUSH: drops input, drains output, and sets console settings
* @return 0 on success, -1 w/ errno
* @asyncsignalsafe
*/
int(tcsetattr)(int fd, int opt, const struct termios *tio) {
switch (opt) {
case TCSANOW:
return ioctl(fd, TCSETS, (void *)tio);
case TCSADRAIN:
return ioctl(fd, TCSETSW, (void *)tio);
case TCSAFLUSH:
return ioctl(fd, TCSETSF, (void *)tio);
default:
return einval();
}
}
| 2,699 | 47 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/sigprocmask-sysv.c | /*-*- 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/struct/sigset.h"
#include "libc/calls/struct/sigset.internal.h"
#include "libc/dce.h"
#include "libc/str/str.h"
int sys_sigprocmask(int how, const sigset_t *opt_set,
sigset_t *opt_out_oldset) {
int res, rc, arg1;
sigset_t old = {0};
const sigset_t *arg2;
if (!IsOpenbsd()) {
rc = __sys_sigprocmask(how, opt_set, opt_out_oldset ? &old : 0, 8);
} else {
if (opt_set) {
// openbsd only supports 32 signals so it passses them in a reg
arg1 = how;
arg2 = (sigset_t *)(uintptr_t)(*(uint32_t *)opt_set);
} else {
arg1 = how; // SIG_BLOCK
arg2 = 0; // changes nothing
}
if ((res = __sys_sigprocmask(arg1, arg2, 0, 0)) != -1) {
memcpy(&old, &res, sizeof(res));
rc = 0;
} else {
rc = -1;
}
}
if (rc != -1 && opt_out_oldset) {
*opt_out_oldset = old;
}
return rc;
}
| 2,734 | 52 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fixenotdir.c | /*-*- 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/errno.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/errors.h"
#include "libc/nt/files.h"
#include "libc/str/str.h"
static textwindows bool SubpathExistsThatsNotDirectory(char16_t *path) {
int e;
char16_t *p;
uint32_t attrs;
e = errno;
while ((p = strrchr16(path, '\\'))) {
*p = u'\0';
if ((attrs = GetFileAttributes(path)) != -1u) {
if (attrs & kNtFileAttributeDirectory) {
return false;
} else {
return true;
}
} else {
errno = e;
}
}
return false;
}
textwindows dontinline int64_t __fix_enotdir3(int64_t rc, char16_t *path1,
char16_t *path2) {
if (rc == -1 && errno == kNtErrorPathNotFound) {
if ((!path1 || !SubpathExistsThatsNotDirectory(path1)) &&
(!path2 || !SubpathExistsThatsNotDirectory(path2))) {
errno = kNtErrorFileNotFound;
}
}
return rc;
}
// WIN32 doesn't distinguish between ENOTDIR and ENOENT. UNIX strictly
// requires that a directory component *exists* but is not a directory
// whereas WIN32 will return ENOTDIR if a dir label simply isn't found
//
// - ENOTDIR: A component used as a directory in pathname is not, in
// fact, a directory. -or- pathname is relative and dirfd is a file
// descriptor referring to a file other than a directory.
//
// - ENOENT: A directory component in pathname does not exist or is a
// dangling symbolic link.
//
textwindows int64_t __fix_enotdir(int64_t rc, char16_t *path) {
return __fix_enotdir3(rc, path, 0);
}
| 3,399 | 70 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/wincrashearly.c | /*-*- 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. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
int64_t __wincrashearly;
| 1,862 | 21 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/sigenter-xnu.c | /*-*- 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 "ape/sections.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/struct/metasigaltstack.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo-meta.internal.h"
#include "libc/calls/struct/siginfo-xnu.internal.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/ucontext.h"
#include "libc/intrin/repstosb.h"
#include "libc/log/libfatal.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sa.h"
/**
* @fileoverview XNU kernel callback normalization.
*/
struct __darwin_mmst_reg {
char __mmst_reg[10];
char __mmst_rsrv[6];
};
struct __darwin_xmm_reg {
char __xmm_reg[16];
};
struct __darwin_ymm_reg {
char __ymm_reg[32];
};
struct __darwin_zmm_reg {
char __zmm_reg[64];
};
struct __darwin_opmask_reg {
char __opmask_reg[8];
};
struct __darwin_x86_thread_state64 {
uint64_t __rax;
uint64_t __rbx;
uint64_t __rcx;
uint64_t __rdx;
uint64_t __rdi;
uint64_t __rsi;
uint64_t __rbp;
uint64_t __rsp;
uint64_t __r8;
uint64_t __r9;
uint64_t __r10;
uint64_t __r11;
uint64_t __r12;
uint64_t __r13;
uint64_t __r14;
uint64_t __r15;
uint64_t __rip;
uint64_t __rflags;
uint64_t __cs;
uint64_t __fs;
uint64_t __gs;
};
struct __darwin_x86_thread_full_state64 {
struct __darwin_x86_thread_state64 ss64;
uint64_t __ds;
uint64_t __es;
uint64_t __ss;
uint64_t __gsbase;
};
struct __darwin_x86_float_state64 {
int32_t __fpu_reserved[2];
uint16_t __fpu_fcw;
uint16_t __fpu_fsw;
uint8_t __fpu_ftw;
uint8_t __fpu_rsrv1;
uint16_t __fpu_fop;
uint32_t __fpu_ip;
uint16_t __fpu_cs;
uint16_t __fpu_rsrv2;
uint32_t __fpu_dp;
uint16_t __fpu_ds;
uint16_t __fpu_rsrv3;
uint32_t __fpu_mxcsr;
uint32_t __fpu_mxcsrmask;
struct __darwin_mmst_reg __fpu_stmm0;
struct __darwin_mmst_reg __fpu_stmm1;
struct __darwin_mmst_reg __fpu_stmm2;
struct __darwin_mmst_reg __fpu_stmm3;
struct __darwin_mmst_reg __fpu_stmm4;
struct __darwin_mmst_reg __fpu_stmm5;
struct __darwin_mmst_reg __fpu_stmm6;
struct __darwin_mmst_reg __fpu_stmm7;
struct __darwin_xmm_reg __fpu_xmm0;
struct __darwin_xmm_reg __fpu_xmm1;
struct __darwin_xmm_reg __fpu_xmm2;
struct __darwin_xmm_reg __fpu_xmm3;
struct __darwin_xmm_reg __fpu_xmm4;
struct __darwin_xmm_reg __fpu_xmm5;
struct __darwin_xmm_reg __fpu_xmm6;
struct __darwin_xmm_reg __fpu_xmm7;
struct __darwin_xmm_reg __fpu_xmm8;
struct __darwin_xmm_reg __fpu_xmm9;
struct __darwin_xmm_reg __fpu_xmm10;
struct __darwin_xmm_reg __fpu_xmm11;
struct __darwin_xmm_reg __fpu_xmm12;
struct __darwin_xmm_reg __fpu_xmm13;
struct __darwin_xmm_reg __fpu_xmm14;
struct __darwin_xmm_reg __fpu_xmm15;
char __fpu_rsrv4[96];
int32_t __fpu_reserved1;
};
struct __darwin_x86_avx_state64 {
int32_t __fpu_reserved[2];
uint16_t __fpu_fcw;
uint16_t __fpu_fsw;
uint8_t __fpu_ftw;
uint8_t __fpu_rsrv1;
uint16_t __fpu_fop;
uint32_t __fpu_ip;
uint16_t __fpu_cs;
uint16_t __fpu_rsrv2;
uint32_t __fpu_dp;
uint16_t __fpu_ds;
uint16_t __fpu_rsrv3;
uint32_t __fpu_mxcsr;
uint32_t __fpu_mxcsrmask;
struct __darwin_mmst_reg __fpu_stmm0;
struct __darwin_mmst_reg __fpu_stmm1;
struct __darwin_mmst_reg __fpu_stmm2;
struct __darwin_mmst_reg __fpu_stmm3;
struct __darwin_mmst_reg __fpu_stmm4;
struct __darwin_mmst_reg __fpu_stmm5;
struct __darwin_mmst_reg __fpu_stmm6;
struct __darwin_mmst_reg __fpu_stmm7;
struct __darwin_xmm_reg __fpu_xmm0;
struct __darwin_xmm_reg __fpu_xmm1;
struct __darwin_xmm_reg __fpu_xmm2;
struct __darwin_xmm_reg __fpu_xmm3;
struct __darwin_xmm_reg __fpu_xmm4;
struct __darwin_xmm_reg __fpu_xmm5;
struct __darwin_xmm_reg __fpu_xmm6;
struct __darwin_xmm_reg __fpu_xmm7;
struct __darwin_xmm_reg __fpu_xmm8;
struct __darwin_xmm_reg __fpu_xmm9;
struct __darwin_xmm_reg __fpu_xmm10;
struct __darwin_xmm_reg __fpu_xmm11;
struct __darwin_xmm_reg __fpu_xmm12;
struct __darwin_xmm_reg __fpu_xmm13;
struct __darwin_xmm_reg __fpu_xmm14;
struct __darwin_xmm_reg __fpu_xmm15;
char __fpu_rsrv4[6 * 16];
int32_t __fpu_reserved1;
char __avx_reserved1[64];
struct __darwin_xmm_reg __fpu_ymmh0;
struct __darwin_xmm_reg __fpu_ymmh1;
struct __darwin_xmm_reg __fpu_ymmh2;
struct __darwin_xmm_reg __fpu_ymmh3;
struct __darwin_xmm_reg __fpu_ymmh4;
struct __darwin_xmm_reg __fpu_ymmh5;
struct __darwin_xmm_reg __fpu_ymmh6;
struct __darwin_xmm_reg __fpu_ymmh7;
struct __darwin_xmm_reg __fpu_ymmh8;
struct __darwin_xmm_reg __fpu_ymmh9;
struct __darwin_xmm_reg __fpu_ymmh10;
struct __darwin_xmm_reg __fpu_ymmh11;
struct __darwin_xmm_reg __fpu_ymmh12;
struct __darwin_xmm_reg __fpu_ymmh13;
struct __darwin_xmm_reg __fpu_ymmh14;
struct __darwin_xmm_reg __fpu_ymmh15;
};
struct __darwin_x86_avx512_state64 {
int32_t __fpu_reserved[2];
uint16_t __fpu_fcw;
uint16_t __fpu_fsw;
uint8_t __fpu_ftw;
uint8_t __fpu_rsrv1;
uint16_t __fpu_fop;
uint32_t __fpu_ip;
uint16_t __fpu_cs;
uint16_t __fpu_rsrv2;
uint32_t __fpu_dp;
uint16_t __fpu_ds;
uint16_t __fpu_rsrv3;
uint32_t __fpu_mxcsr;
uint32_t __fpu_mxcsrmask;
struct __darwin_mmst_reg __fpu_stmm0;
struct __darwin_mmst_reg __fpu_stmm1;
struct __darwin_mmst_reg __fpu_stmm2;
struct __darwin_mmst_reg __fpu_stmm3;
struct __darwin_mmst_reg __fpu_stmm4;
struct __darwin_mmst_reg __fpu_stmm5;
struct __darwin_mmst_reg __fpu_stmm6;
struct __darwin_mmst_reg __fpu_stmm7;
struct __darwin_xmm_reg __fpu_xmm0;
struct __darwin_xmm_reg __fpu_xmm1;
struct __darwin_xmm_reg __fpu_xmm2;
struct __darwin_xmm_reg __fpu_xmm3;
struct __darwin_xmm_reg __fpu_xmm4;
struct __darwin_xmm_reg __fpu_xmm5;
struct __darwin_xmm_reg __fpu_xmm6;
struct __darwin_xmm_reg __fpu_xmm7;
struct __darwin_xmm_reg __fpu_xmm8;
struct __darwin_xmm_reg __fpu_xmm9;
struct __darwin_xmm_reg __fpu_xmm10;
struct __darwin_xmm_reg __fpu_xmm11;
struct __darwin_xmm_reg __fpu_xmm12;
struct __darwin_xmm_reg __fpu_xmm13;
struct __darwin_xmm_reg __fpu_xmm14;
struct __darwin_xmm_reg __fpu_xmm15;
char __fpu_rsrv4[6 * 16];
int32_t __fpu_reserved1;
char __avx_reserved1[64];
struct __darwin_xmm_reg __fpu_ymmh0;
struct __darwin_xmm_reg __fpu_ymmh1;
struct __darwin_xmm_reg __fpu_ymmh2;
struct __darwin_xmm_reg __fpu_ymmh3;
struct __darwin_xmm_reg __fpu_ymmh4;
struct __darwin_xmm_reg __fpu_ymmh5;
struct __darwin_xmm_reg __fpu_ymmh6;
struct __darwin_xmm_reg __fpu_ymmh7;
struct __darwin_xmm_reg __fpu_ymmh8;
struct __darwin_xmm_reg __fpu_ymmh9;
struct __darwin_xmm_reg __fpu_ymmh10;
struct __darwin_xmm_reg __fpu_ymmh11;
struct __darwin_xmm_reg __fpu_ymmh12;
struct __darwin_xmm_reg __fpu_ymmh13;
struct __darwin_xmm_reg __fpu_ymmh14;
struct __darwin_xmm_reg __fpu_ymmh15;
struct __darwin_opmask_reg __fpu_k0;
struct __darwin_opmask_reg __fpu_k1;
struct __darwin_opmask_reg __fpu_k2;
struct __darwin_opmask_reg __fpu_k3;
struct __darwin_opmask_reg __fpu_k4;
struct __darwin_opmask_reg __fpu_k5;
struct __darwin_opmask_reg __fpu_k6;
struct __darwin_opmask_reg __fpu_k7;
struct __darwin_ymm_reg __fpu_zmmh0;
struct __darwin_ymm_reg __fpu_zmmh1;
struct __darwin_ymm_reg __fpu_zmmh2;
struct __darwin_ymm_reg __fpu_zmmh3;
struct __darwin_ymm_reg __fpu_zmmh4;
struct __darwin_ymm_reg __fpu_zmmh5;
struct __darwin_ymm_reg __fpu_zmmh6;
struct __darwin_ymm_reg __fpu_zmmh7;
struct __darwin_ymm_reg __fpu_zmmh8;
struct __darwin_ymm_reg __fpu_zmmh9;
struct __darwin_ymm_reg __fpu_zmmh10;
struct __darwin_ymm_reg __fpu_zmmh11;
struct __darwin_ymm_reg __fpu_zmmh12;
struct __darwin_ymm_reg __fpu_zmmh13;
struct __darwin_ymm_reg __fpu_zmmh14;
struct __darwin_ymm_reg __fpu_zmmh15;
struct __darwin_zmm_reg __fpu_zmm16;
struct __darwin_zmm_reg __fpu_zmm17;
struct __darwin_zmm_reg __fpu_zmm18;
struct __darwin_zmm_reg __fpu_zmm19;
struct __darwin_zmm_reg __fpu_zmm20;
struct __darwin_zmm_reg __fpu_zmm21;
struct __darwin_zmm_reg __fpu_zmm22;
struct __darwin_zmm_reg __fpu_zmm23;
struct __darwin_zmm_reg __fpu_zmm24;
struct __darwin_zmm_reg __fpu_zmm25;
struct __darwin_zmm_reg __fpu_zmm26;
struct __darwin_zmm_reg __fpu_zmm27;
struct __darwin_zmm_reg __fpu_zmm28;
struct __darwin_zmm_reg __fpu_zmm29;
struct __darwin_zmm_reg __fpu_zmm30;
struct __darwin_zmm_reg __fpu_zmm31;
};
struct __darwin_x86_exception_state64 {
uint16_t __trapno;
uint16_t __cpu;
uint32_t __err;
uint64_t __faultvaddr;
};
struct __darwin_x86_debug_state64 {
uint64_t __dr0;
uint64_t __dr1;
uint64_t __dr2;
uint64_t __dr3;
uint64_t __dr4;
uint64_t __dr5;
uint64_t __dr6;
uint64_t __dr7;
};
struct __darwin_x86_cpmu_state64 {
uint64_t __ctrs[16];
};
struct __darwin_mcontext64_full {
struct __darwin_x86_exception_state64 __es;
struct __darwin_x86_thread_full_state64 __ss;
struct __darwin_x86_float_state64 __fs;
};
struct __darwin_mcontext_avx64 {
struct __darwin_x86_exception_state64 __es;
struct __darwin_x86_thread_state64 __ss;
struct __darwin_x86_avx_state64 __fs;
};
struct __darwin_mcontext_avx64_full {
struct __darwin_x86_exception_state64 __es;
struct __darwin_x86_thread_full_state64 __ss;
struct __darwin_x86_avx_state64 __fs;
};
struct __darwin_mcontext_avx512_64 {
struct __darwin_x86_exception_state64 __es;
struct __darwin_x86_thread_state64 __ss;
struct __darwin_x86_avx512_state64 __fs;
};
struct __darwin_mcontext_avx512_64_full {
struct __darwin_x86_exception_state64 __es;
struct __darwin_x86_thread_full_state64 __ss;
struct __darwin_x86_avx512_state64 __fs;
};
struct __darwin_arm_exception_state64 {
uint64_t far;
uint32_t esr;
uint32_t exception;
};
struct __darwin_arm_thread_state64 {
uint64_t __x[29];
uint64_t __fp;
uint64_t __lr;
uint64_t __sp;
uint64_t __pc;
uint32_t __cpsr;
uint32_t __pad;
};
struct __darwin_arm_vfp_state {
uint32_t __r[64];
uint32_t __fpscr;
};
struct __darwin_mcontext64 {
#ifdef __x86_64__
struct __darwin_x86_exception_state64 __es;
struct __darwin_x86_thread_state64 __ss;
struct __darwin_x86_float_state64 __fs;
#elif defined(__aarch64__)
struct __darwin_arm_exception_state64 __es;
struct __darwin_arm_thread_state64 __ss;
struct __darwin_arm_vfp_state __fs;
#endif
};
struct __darwin_ucontext {
int32_t uc_onstack;
uint32_t uc_sigmask;
struct sigaltstack_bsd uc_stack;
struct __darwin_ucontext *uc_link;
uint64_t uc_mcsize;
struct __darwin_mcontext64 *uc_mcontext;
};
#ifdef __x86_64__
static privileged void xnuexceptionstate2linux(
mcontext_t *mc, struct __darwin_x86_exception_state64 *xnues) {
mc->trapno = xnues->__trapno;
mc->err = xnues->__err;
}
static privileged void linuxexceptionstate2xnu(
struct __darwin_x86_exception_state64 *xnues, mcontext_t *mc) {
xnues->__trapno = mc->trapno;
xnues->__err = mc->err;
}
static privileged void xnuthreadstate2linux(
mcontext_t *mc, struct __darwin_x86_thread_state64 *xnuss) {
mc->rdi = xnuss->__rdi;
mc->rsi = xnuss->__rsi;
mc->rbp = xnuss->__rbp;
mc->rbx = xnuss->__rbx;
mc->rdx = xnuss->__rdx;
mc->rax = xnuss->__rax;
mc->rcx = xnuss->__rcx;
mc->rsp = xnuss->__rsp;
mc->rip = xnuss->__rip;
mc->cs = xnuss->__cs;
mc->gs = xnuss->__gs;
mc->fs = xnuss->__fs;
mc->eflags = xnuss->__rflags;
mc->r8 = xnuss->__r8;
mc->r9 = xnuss->__r9;
mc->r10 = xnuss->__r10;
mc->r11 = xnuss->__r11;
mc->r12 = xnuss->__r12;
mc->r13 = xnuss->__r13;
mc->r14 = xnuss->__r14;
mc->r15 = xnuss->__r15;
}
static privileged void linuxthreadstate2xnu(
struct __darwin_x86_thread_state64 *xnuss, ucontext_t *uc, mcontext_t *mc) {
xnuss->__rdi = mc->rdi;
xnuss->__rsi = mc->rsi;
xnuss->__rbp = mc->rbp;
xnuss->__rbx = mc->rbx;
xnuss->__rdx = mc->rdx;
xnuss->__rax = mc->rax;
xnuss->__rcx = mc->rcx;
xnuss->__rsp = mc->rsp;
xnuss->__rip = mc->rip;
xnuss->__cs = mc->cs;
xnuss->__gs = mc->gs;
xnuss->__fs = mc->fs;
xnuss->__rflags = mc->eflags;
xnuss->__r8 = mc->r8;
xnuss->__r9 = mc->r9;
xnuss->__r10 = mc->r10;
xnuss->__r11 = mc->r11;
xnuss->__r12 = mc->r12;
xnuss->__r13 = mc->r13;
xnuss->__r14 = mc->r14;
xnuss->__r15 = mc->r15;
}
static privileged void CopyFpXmmRegs(void *d, const void *s) {
size_t i;
for (i = 0; i < (8 + 16) * 16; i += 16) {
__builtin_memcpy((char *)d + i, (const char *)s + i, 16);
}
}
static privileged void xnussefpustate2linux(
struct FpuState *fs, struct __darwin_x86_float_state64 *xnufs) {
fs->cwd = xnufs->__fpu_fcw;
fs->swd = xnufs->__fpu_fsw;
fs->ftw = xnufs->__fpu_ftw;
fs->fop = xnufs->__fpu_fop;
fs->rip = xnufs->__fpu_ip;
fs->rdp = xnufs->__fpu_dp;
fs->mxcsr = xnufs->__fpu_mxcsr;
fs->mxcr_mask = xnufs->__fpu_mxcsrmask;
CopyFpXmmRegs(fs->st, &xnufs->__fpu_stmm0);
}
static privileged void linuxssefpustate2xnu(
struct __darwin_x86_float_state64 *xnufs, struct FpuState *fs) {
xnufs->__fpu_fcw = fs->cwd;
xnufs->__fpu_fsw = fs->swd;
xnufs->__fpu_ftw = fs->ftw;
xnufs->__fpu_fop = fs->fop;
xnufs->__fpu_ip = fs->rip;
xnufs->__fpu_dp = fs->rdp;
xnufs->__fpu_mxcsr = fs->mxcsr;
xnufs->__fpu_mxcsrmask = fs->mxcr_mask;
CopyFpXmmRegs(&xnufs->__fpu_stmm0, fs->st);
}
#endif /* __x86_64__ */
privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
struct siginfo_xnu *xnuinfo,
struct __darwin_ucontext *xnuctx) {
intptr_t ax;
int rva, flags;
struct Goodies {
ucontext_t uc;
siginfo_t si;
} g;
rva = __sighandrvas[sig & (NSIG - 1)];
if (rva >= kSigactionMinRva) {
flags = __sighandflags[sig & (NSIG - 1)];
if (~flags & SA_SIGINFO) {
((sigaction_f)(__executable_start + rva))(sig, 0, 0);
} else {
__repstosb(&g, 0, sizeof(g));
if (xnuctx) {
g.uc.uc_sigmask.__bits[0] = xnuctx->uc_sigmask;
g.uc.uc_sigmask.__bits[1] = 0;
g.uc.uc_stack.ss_sp = xnuctx->uc_stack.ss_sp;
g.uc.uc_stack.ss_flags = xnuctx->uc_stack.ss_flags;
g.uc.uc_stack.ss_size = xnuctx->uc_stack.ss_size;
#ifdef __x86_64__
g.uc.uc_mcontext.fpregs = &g.uc.__fpustate;
if (xnuctx->uc_mcontext) {
if (xnuctx->uc_mcsize >=
sizeof(struct __darwin_x86_exception_state64)) {
xnuexceptionstate2linux(&g.uc.uc_mcontext,
&xnuctx->uc_mcontext->__es);
}
if (xnuctx->uc_mcsize >=
(sizeof(struct __darwin_x86_exception_state64) +
sizeof(struct __darwin_x86_thread_state64))) {
xnuthreadstate2linux(&g.uc.uc_mcontext, &xnuctx->uc_mcontext->__ss);
}
if (xnuctx->uc_mcsize >= sizeof(struct __darwin_mcontext64)) {
xnussefpustate2linux(&g.uc.__fpustate, &xnuctx->uc_mcontext->__fs);
}
}
#elif defined(__aarch64__)
if (xnuctx->uc_mcontext) {
memcpy(g.uc.uc_mcontext.regs, &xnuctx->uc_mcontext->__ss.__x, 33 * 8);
}
#endif /* __x86_64__ */
}
if (xnuinfo) {
__siginfo2cosmo(&g.si, (void *)xnuinfo);
}
((sigaction_f)(__executable_start + rva))(sig, &g.si, &g.uc);
if (xnuctx) {
xnuctx->uc_stack.ss_sp = g.uc.uc_stack.ss_sp;
xnuctx->uc_stack.ss_flags = g.uc.uc_stack.ss_flags;
xnuctx->uc_stack.ss_size = g.uc.uc_stack.ss_size;
xnuctx->uc_sigmask = g.uc.uc_sigmask.__bits[0];
#ifdef __x86_64__
if (xnuctx->uc_mcontext) {
if (xnuctx->uc_mcsize >=
sizeof(struct __darwin_x86_exception_state64)) {
linuxexceptionstate2xnu(&xnuctx->uc_mcontext->__es,
&g.uc.uc_mcontext);
}
if (xnuctx->uc_mcsize >=
(sizeof(struct __darwin_x86_exception_state64) +
sizeof(struct __darwin_x86_thread_state64))) {
linuxthreadstate2xnu(&xnuctx->uc_mcontext->__ss, &g.uc,
&g.uc.uc_mcontext);
}
if (xnuctx->uc_mcsize >= sizeof(struct __darwin_mcontext64)) {
linuxssefpustate2xnu(&xnuctx->uc_mcontext->__fs, &g.uc.__fpustate);
}
}
#elif defined(__aarch64__)
if (xnuctx->uc_mcontext) {
memcpy(&xnuctx->uc_mcontext->__ss.__x, g.uc.uc_mcontext.regs, 33 * 8);
}
#endif /* __x86_64__ */
}
}
}
#ifdef __x86_64__
asm volatile("syscall"
: "=a"(ax)
: "0"(0x20000b8 /* sigreturn */), "D"(xnuctx), "S"(infostyle)
: "rcx", "r11", "memory", "cc");
#else
register long r0 asm("x0") = (long)xnuctx;
register long r1 asm("x1") = (long)infostyle;
asm volatile("mov\tx16,%0\n\t"
"svc\t0"
: /* no outputs */
: "i"(0x0b8 /* sigreturn */), "r"(r0), "r"(r1)
: "x16", "memory");
#endif /* __x86_64__ */
notpossible;
}
| 18,804 | 588 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fstat.c | /*-*- 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/struct/stat.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
/**
* Returns information about file, via open()'d descriptor.
*
* @return 0 on success or -1 w/ errno
* @raise EBADF if `fd` isn't a valid file descriptor
* @raise EIO if an i/o error happens while reading from file system
* @raise EOVERFLOW shouldn't be possible on 64-bit systems
* @asyncsignalsafe
*/
int fstat(int fd, struct stat *st) {
int rc;
if (__isfdkind(fd, kFdZip)) {
rc = _weaken(__zipos_fstat)(
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st);
} else if (!IsWindows() && !IsMetal()) {
rc = sys_fstat(fd, st);
} else if (IsMetal()) {
rc = sys_fstat_metal(fd, st);
} else if (!__isfdkind(fd, kFdFile)) {
rc = ebadf();
} else {
rc = sys_fstat_nt(__getfdhandleactual(fd), st);
}
STRACE("fstat(%d, [%s]) â %d% m", fd, DescribeStat(rc, st), rc);
return rc;
}
| 3,028 | 56 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/ptsname_r.c | /*-*- 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/syscall_support-sysv.internal.h"
#include "libc/calls/termios.h"
#include "libc/errno.h"
/**
* Gets name subordinate pseudoteletypewriter.
*
* @return 0 on success, or errno on error
*/
errno_t ptsname_r(int fd, char *buf, size_t size) {
int rc, e = errno;
if (!_ptsname(fd, buf, size)) {
rc = 0;
} else {
rc = errno;
errno = e;
}
return rc;
}
| 2,228 | 38 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/dup2.c | /*-*- 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/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h"
/**
* Duplicates file descriptor, granting it specific number.
*
* The `O_CLOEXEC` flag shall be cleared from the resulting file
* descriptor; see dup3() to preserve it.
*
* Unlike dup3(), the dup2() function permits oldfd and newfd to be the
* same, in which case the only thing this function does is test if
* oldfd is open.
*
* @param oldfd isn't closed afterwards
* @param newfd if already assigned, is silently closed beforehand;
* unless it's equal to oldfd, in which case dup2() is a no-op
* @return new file descriptor, or -1 w/ errno
* @raise EPERM if pledge() is in play without stdio
* @raise EMFILE if `RLIMIT_NOFILE` has been reached
* @raise ENOTSUP if `oldfd` is on zip file system
* @raise EINTR if a signal handler was called
* @raise EBADF is `newfd` negative or too big
* @raise EBADF is `oldfd` isn't open
* @asyncsignalsafe
* @vforksafe
*/
int dup2(int oldfd, int newfd) {
int rc;
if (__isfdkind(oldfd, kFdZip)) {
rc = enotsup();
#ifdef __aarch64__
} else if (oldfd == newfd) {
// linux aarch64 defines dup3() but not dup2(), which wasn't such a
// great decision, since the two syscalls don't behave the same way
if (!(rc = read(oldfd, 0, 0))) rc = oldfd;
#endif
} else if (!IsWindows()) {
rc = sys_dup2(oldfd, newfd, 0);
} else if (newfd < 0) {
rc = ebadf();
} else if (oldfd == newfd) {
if (__isfdopen(oldfd)) {
rc = newfd;
} else {
rc = ebadf();
}
} else {
rc = sys_dup_nt(oldfd, newfd, 0, -1);
}
STRACE("dup2(%d, %d) â %d% m", oldfd, newfd, rc);
return rc;
}
| 3,669 | 76 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/onntconsoleevent.c | /*-*- 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/sig.internal.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nexgen32e/nt2sysv.h"
#include "libc/nt/enum/ctrlevent.h"
#include "libc/nt/thread.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/sig.h"
#include "libc/thread/tls.h"
#include "libc/thread/tls2.h"
#ifdef __x86_64__
textwindows bool32 __onntconsoleevent(uint32_t dwCtrlType) {
struct CosmoTib tib;
struct StackFrame *fr;
// win32 spawns a thread on its own just to deliver sigint
// TODO(jart): make signal code lockless so we can delete!
if (__tls_enabled && !__get_tls_win32()) {
bzero(&tib, sizeof(tib));
tib.tib_self = &tib;
tib.tib_self2 = &tib;
atomic_store_explicit(&tib.tib_tid, GetCurrentThreadId(),
memory_order_relaxed);
__set_tls_win32(&tib);
}
STRACE("__onntconsoleevent(%u)", dwCtrlType);
switch (dwCtrlType) {
case kNtCtrlCEvent:
__sig_add(0, SIGINT, SI_KERNEL);
return true;
case kNtCtrlBreakEvent:
__sig_add(0, SIGQUIT, SI_KERNEL);
return true;
case kNtCtrlCloseEvent:
case kNtCtrlLogoffEvent: // only received by services
case kNtCtrlShutdownEvent: // only received by services
__sig_add(0, SIGHUP, SI_KERNEL);
return true;
default:
return false;
}
}
#endif /* __x86_64__ */
| 3,236 | 67 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/vdsofunc.greg.c | /*-*- 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/elf/scalar.h"
#include "libc/elf/struct/ehdr.h"
#include "libc/elf/struct/phdr.h"
#include "libc/elf/struct/shdr.h"
#include "libc/elf/struct/sym.h"
#include "libc/elf/struct/verdaux.h"
#include "libc/elf/struct/verdef.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/auxv.h"
static inline int CompareStrings(const char *l, const char *r) {
size_t i = 0;
while (l[i] == r[i] && r[i]) ++i;
return (l[i] & 255) - (r[i] & 255);
}
static inline int CheckDsoSymbolVersion(Elf64_Verdef *vd, int sym,
const char *name, char *strtab) {
Elf64_Verdaux *aux;
for (;; vd = (Elf64_Verdef *)((char *)vd + vd->vd_next)) {
if (!(vd->vd_flags & VER_FLG_BASE) &&
(vd->vd_ndx & 0x7fff) == (sym & 0x7fff)) {
aux = (Elf64_Verdaux *)((char *)vd + vd->vd_aux);
return !CompareStrings(name, strtab + aux->vda_name);
}
if (!vd->vd_next) {
return 0;
}
}
}
/**
* Returns address of vDSO function.
*/
void *__vdsosym(const char *version, const char *name) {
void *p;
size_t i;
Elf64_Ehdr *ehdr;
Elf64_Phdr *phdr;
char *strtab = 0;
size_t *dyn, base;
unsigned long *ap;
Elf64_Sym *symtab = 0;
uint16_t *versym = 0;
Elf_Symndx *hashtab = 0;
Elf64_Verdef *verdef = 0;
for (ehdr = 0, ap = __auxv; ap[0]; ap += 2) {
if (ap[0] == AT_SYSINFO_EHDR) {
ehdr = (void *)ap[1];
break;
}
}
if (!ehdr || READ32LE(ehdr->e_ident) != READ32LE("\177ELF")) {
KERNTRACE("__vdsosym() â AT_SYSINFO_EHDR ELF not found");
return 0;
}
phdr = (void *)((char *)ehdr + ehdr->e_phoff);
for (base = -1, dyn = 0, i = 0; i < ehdr->e_phnum;
i++, phdr = (void *)((char *)phdr + ehdr->e_phentsize)) {
switch (phdr->p_type) {
case PT_LOAD:
// modern linux uses the base address zero, but elders
// e.g. rhel7 uses the base address 0xffffffffff700000
base = (size_t)ehdr + phdr->p_offset - phdr->p_vaddr;
break;
case PT_DYNAMIC:
dyn = (void *)((char *)ehdr + phdr->p_offset);
break;
default:
break;
}
}
if (!dyn || base == -1) {
KERNTRACE("__vdsosym() â missing program headers");
return 0;
}
for (i = 0; dyn[i]; i += 2) {
p = (void *)(base + dyn[i + 1]);
switch (dyn[i]) {
case DT_STRTAB:
strtab = p;
break;
case DT_SYMTAB:
symtab = p;
break;
case DT_HASH:
hashtab = p;
break;
case DT_VERSYM:
versym = p;
break;
case DT_VERDEF:
verdef = p;
break;
}
}
if (!strtab || !symtab || !hashtab) {
KERNTRACE("__vdsosym() â tables not found");
return 0;
}
if (!verdef) {
versym = 0;
}
for (i = 0; i < hashtab[1]; i++) {
if (ELF64_ST_TYPE(symtab[i].st_info) != STT_FUNC &&
ELF64_ST_TYPE(symtab[i].st_info) != STT_OBJECT &&
ELF64_ST_TYPE(symtab[i].st_info) != STT_NOTYPE) {
continue;
}
if (ELF64_ST_BIND(symtab[i].st_info) != STB_GLOBAL) {
continue;
}
if (!symtab[i].st_shndx) {
continue;
}
if (CompareStrings(name, strtab + symtab[i].st_name)) {
continue;
}
if (versym && !CheckDsoSymbolVersion(verdef, versym[i], version, strtab)) {
continue;
}
return (void *)(base + symtab[i].st_value);
}
KERNTRACE("__vdsosym() â symbol not found");
return 0;
}
| 5,361 | 153 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/openat-sysv.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/fd.h"
#include "libc/sysv/consts/o.h"
int sys_openat(int dirfd, const char *file, int flags, unsigned mode) {
static bool once, modernize;
int d, e, f;
/*
* RHEL5 doesn't support O_CLOEXEC. It's hard to test for this.
* Sometimes the system call succeeds and it just doesn't set the
* flag. Other times, it return -530 which makes no sense.
*/
if (!IsLinux() || !(flags & O_CLOEXEC) || modernize) {
d = __sys_openat(dirfd, file, flags, mode);
} else if (once) {
if ((d = __sys_openat(dirfd, file, flags & ~O_CLOEXEC, mode)) != -1) {
e = errno;
if (__sys_fcntl(d, F_SETFD, FD_CLOEXEC) == -1) {
errno = e;
}
}
} else {
e = errno;
if ((d = __sys_openat(dirfd, file, flags, mode)) != -1) {
if ((f = __sys_fcntl(d, F_GETFD)) != -1) {
if (f & FD_CLOEXEC) {
modernize = true;
} else {
__sys_fcntl(d, F_SETFD, FD_CLOEXEC);
}
}
errno = e;
once = true;
} else if (errno > 255) {
once = true;
d = sys_openat(dirfd, file, flags, mode);
}
}
return d;
}
| 3,116 | 63 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/getcwd.greg.c | /*-*- 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/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/log/backtrace.internal.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"
/**
* Returns current working directory, e.g.
*
* const char *dirname = gc(getcwd(0,0)); // if malloc is linked
* const char *dirname = getcwd(alloca(PATH_MAX),PATH_MAX);
*
* @param buf is where UTF-8 NUL-terminated path string gets written,
* which may be NULL to ask this function to malloc a buffer
* @param size is number of bytes available in buf, e.g. PATH_MAX+1,
* which may be 0 if buf is NULL
* @return buf containing system-normative path or NULL w/ errno
* @error ERANGE, EINVAL, ENOMEM
*/
char *getcwd(char *buf, size_t size) {
char *p, *r;
if (buf) {
p = buf;
if (!size) {
einval();
STRACE("getcwd(%p, %'zu) %m", buf, size);
return 0;
}
} else if (_weaken(malloc)) {
_unassert(!__vforked);
if (!size) size = PATH_MAX;
if (!(p = _weaken(malloc)(size))) {
STRACE("getcwd(%p, %'zu) %m", buf, size);
return 0;
}
} else {
einval();
STRACE("getcwd() needs bufâ 0 or STATIC_YOINK(\"malloc\")");
return 0;
}
*p = '\0';
if (!IsWindows()) {
if (IsMetal()) {
r = size >= 5 ? strcpy(p, "/zip") : 0;
} else if (IsXnu()) {
r = sys_getcwd_xnu(p, size);
} else if (sys_getcwd(p, size) != (void *)-1) {
r = p;
} else {
r = 0;
}
} else {
r = sys_getcwd_nt(p, size);
}
if (!buf) {
if (!r) {
if (_weaken(free)) {
_weaken(free)(p);
}
} else {
if (_weaken(realloc)) {
if ((p = _weaken(realloc)(r, strlen(r) + 1))) {
r = p;
}
}
}
}
STRACE("getcwd(%p, %'zu) â %#s", buf, size, r);
return r;
}
| 3,867 | 96 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/fsync.c | /*-*- 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/cp.internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h"
/**
* Blocks until kernel flushes buffers for fd to disk.
*
* @return 0 on success, or -1 w/ errno
* @raise ECANCELED if thread was cancelled in masked mode
* @raise EINTR if signal was delivered
* @see fdatasync(), sync_file_range()
* @see __nosync to secretly disable
* @cancellationpoint
* @asyncsignalsafe
*/
int fsync(int fd) {
int rc;
struct stat st;
if (__nosync != 0x5453455454534146) {
BEGIN_CANCELLATION_POINT;
if (!IsWindows()) {
rc = sys_fsync(fd);
} else {
rc = sys_fdatasync_nt(fd);
}
END_CANCELLATION_POINT;
STRACE("fsync(%d) â %d% m", fd, rc);
} else {
rc = fstat(fd, &st);
STRACE("fsync_fake(%d) â %d% m", fd, rc);
}
return rc;
}
| 2,843 | 57 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/reboot.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/framebuffervirtualscreeninfo.h"
#include "libc/dce.h"
#include "libc/nt/enum/version.h"
#include "libc/nt/system.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/errfuns.h"
#define kNtShutdownForceOthers 1
#define kNtShutdownForceSelf 2
#define kNtShutdownGraceOverride 0x20
#define kNtShutdownHybrid 0x200
int32_t sys_reboot_linux(int32_t, int32_t, int32_t) asm("sys_reboot");
int32_t sys_reboot_bsd(int32_t, const char *) asm("sys_reboot");
/**
* Reboots system.
*
* The `howto` argument may be one of the following:
*
* - `RB_AUTOBOOT`
* - `RB_POWER_OFF`
* - `RB_HALT_SYSTEM`
* - `RB_SW_SUSPEND` (linux and windows only)
* - `RB_KEXEC` (linux only)
* - `RB_ENABLE_CAD` (linux only)
* - `RB_DISABLE_CAD` (linux only)
*
* There's an implicit `sync()` operation before the reboot happens.
* This can be prevented by or'ing `howto` with `RB_NOSYNC`. Setting
* this option will also prevent apps on Windows from having time to
* close themselves.
*/
int reboot(int howto) {
bool ok, immediately;
if (howto != -1) {
if (!(howto & 0x20000000)) {
sync();
immediately = false;
} else {
howto &= ~0x20000000;
immediately = true;
}
if (!IsWindows()) {
if (IsLinux()) {
return sys_reboot_linux(0xFEE1DEAD, 0x28121969, howto);
} else {
return sys_reboot_bsd(howto, 0);
}
} else {
if (howto == 0xD000FCE2u) {
ok = !!SetSuspendState(0, 0, 0);
} else {
howto |= kNtShutdownForceSelf;
howto |= kNtShutdownForceOthers;
if (NtGetVersion() >= kNtVersionWindows8) {
howto |= kNtShutdownHybrid;
}
if (immediately) {
ok = !!InitiateShutdown(0, 0, 0, howto | kNtShutdownGraceOverride, 0);
} else {
ok = !!InitiateShutdown(0, 0, 20, howto, 0);
}
}
if (ok) {
return 0;
} else {
return -1;
}
}
} else {
return einval();
}
}
| 3,875 | 94 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/setpgrp.c | /*-*- 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"
/**
* Sets the process group ID.
*/
int setpgrp(void) {
return setpgid(0, 0);
}
| 1,951 | 27 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/ischardev.c | /*-*- 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/struct/metastat.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/nt/enum/filetype.h"
#include "libc/nt/files.h"
#include "libc/sysv/consts/s.h"
/**
* Returns true if file descriptor is backed by character i/o.
*
* This function is equivalent to:
*
* struct stat st;
* return stat(path, &st) != -1 && S_ISCHR(st.st_mode);
*
* Except faster and with fewer dependencies.
*
* @see isregularfile(), isdirectory(), issymlink(), fileexists()
*/
bool32 ischardev(int fd) {
int e;
union metastat st;
if (__isfdkind(fd, kFdZip)) {
return false;
} else if (IsMetal()) {
return true;
} else if (!IsWindows()) {
e = errno;
if (__sys_fstat(fd, &st) != -1) {
return S_ISCHR(METASTAT(st, st_mode));
} else {
errno = e;
return false;
}
} else {
return __isfdkind(fd, kFdConsole) ||
(__isfdkind(fd, kFdFile) &&
GetFileType(__getfdhandleactual(fd)) == kNtFileTypeChar);
}
}
| 2,948 | 62 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/syscall_support-sysv.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_SYSCALL_SUPPORT_SYSV_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_SYSCALL_SUPPORT_SYSV_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/*ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â cosmopolitan § syscalls » system five » structless support ââ¬âââ¼
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
bool __is_linux_2_6_23(void) _Hide;
bool32 sys_isatty_metal(int);
int __fixupnewfd(int, int) _Hide;
int __notziposat(int, const char *);
int __tkill(int, int, void *) _Hide;
int _fork(uint32_t) _Hide;
int _isptmaster(int) _Hide;
int _ptsname(int, char *, size_t) _Hide;
int getdomainname_linux(char *, size_t) _Hide;
int gethostname_bsd(char *, size_t, int) _Hide;
int gethostname_linux(char *, size_t) _Hide;
int gethostname_nt(char *, size_t, int) _Hide;
int sys_msyscall(void *, size_t);
long sys_bogus(void);
ssize_t __getrandom(void *, size_t, unsigned) _Hide;
void *__vdsosym(const char *, const char *) _Hide;
void __onfork(void) _Hide;
void __restore_rt() _Hide;
void __restore_rt_netbsd(void) _Hide;
void cosmo2flock(uintptr_t) _Hide;
void flock2cosmo(uintptr_t) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_SYSCALL_SUPPORT_SYSV_INTERNAL_H_ */
| 1,678 | 34 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/calls.mk | #-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-â
#âââvi: set et ft=make ts=8 tw=8 fenc=utf-8 :viââââââââââââââââââââââââ
#
# SYNOPSIS
#
# System Call Compatibility Layer
#
# DESCRIPTION
#
# This package exports a familiar system call interface that works
# across platforms.
PKGS += LIBC_CALLS
LIBC_CALLS_ARTIFACTS += LIBC_CALLS_A
LIBC_CALLS = $(LIBC_CALLS_A_DEPS) $(LIBC_CALLS_A)
LIBC_CALLS_A = o/$(MODE)/libc/calls/syscalls.a
LIBC_CALLS_A_FILES := \
$(wildcard libc/calls/typedef/*) \
$(wildcard libc/calls/struct/*) \
$(wildcard libc/calls/*)
LIBC_CALLS_A_HDRS = $(filter %.h,$(LIBC_CALLS_A_FILES))
LIBC_CALLS_A_INCS = $(filter %.inc,$(LIBC_CALLS_A_FILES))
LIBC_CALLS_A_SRCS_S = $(filter %.S,$(LIBC_CALLS_A_FILES))
LIBC_CALLS_A_SRCS_C = $(filter %.c,$(LIBC_CALLS_A_FILES))
LIBC_CALLS_A_SRCS = \
$(LIBC_CALLS_A_SRCS_S) \
$(LIBC_CALLS_A_SRCS_C)
LIBC_CALLS_A_OBJS = \
$(LIBC_CALLS_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(LIBC_CALLS_A_SRCS_C:%.c=o/$(MODE)/%.o)
LIBC_CALLS_A_CHECKS = \
$(LIBC_CALLS_A).pkg \
$(LIBC_CALLS_A_HDRS:%=o/$(MODE)/%.ok)
LIBC_CALLS_A_DIRECTDEPS = \
LIBC_FMT \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_NT_ADVAPI32 \
LIBC_NT_IPHLPAPI \
LIBC_NT_KERNEL32 \
LIBC_NT_NTDLL \
LIBC_NT_PDH \
LIBC_NT_PSAPI \
LIBC_NT_POWRPROF \
LIBC_NT_WS2_32 \
LIBC_STR \
LIBC_STUBS \
LIBC_SYSV_CALLS \
LIBC_SYSV \
THIRD_PARTY_COMPILER_RT
LIBC_CALLS_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_CALLS_A_DIRECTDEPS),$($(x))))
$(LIBC_CALLS_A): \
libc/calls/ \
$(LIBC_CALLS_A).pkg \
$(LIBC_CALLS_A_OBJS)
$(LIBC_CALLS_A).pkg: \
$(LIBC_CALLS_A_OBJS) \
$(foreach x,$(LIBC_CALLS_A_DIRECTDEPS),$($(x)_A).pkg)
# we can't use asan because:
# siginfo_t memory is owned by kernels
o/$(MODE)/libc/calls/siginfo2cosmo.o: private \
OVERRIDE_COPTS += \
-ffreestanding \
-fno-sanitize=address
# we can't use asan because:
# ucontext_t memory is owned by xnu kernel
o/$(MODE)/libc/calls/sigenter-xnu.o: private \
OVERRIDE_COPTS += \
-ffreestanding \
-fno-sanitize=address
# we can't use asan because:
# vdso memory is owned by linux kernel
o/$(MODE)/libc/calls/vdsofunc.greg.o: private \
OVERRIDE_COPTS += \
-ffreestanding \
-fno-sanitize=address
# we can't use asan because:
# ntspawn allocates 128kb of heap memory via win32
o/$(MODE)/libc/calls/ntspawn.o \
o/$(MODE)/libc/calls/mkntcmdline.o \
o/$(MODE)/libc/calls/mkntenvblock.o: private \
OVERRIDE_COPTS += \
-ffreestanding \
-fno-sanitize=address
# we can't use sanitizers because:
# windows owns the data structure
o/$(MODE)/libc/calls/wincrash.o \
o/$(MODE)/libc/calls/ntcontext2linux.o: private \
OVERRIDE_COPTS += \
-fno-sanitize=all
# we always want -O3 because:
# it makes the code size smaller too
o/$(MODE)/libc/calls/termios2host.o \
o/$(MODE)/libc/calls/sigenter-freebsd.o \
o/$(MODE)/libc/calls/sigenter-netbsd.o \
o/$(MODE)/libc/calls/sigenter-openbsd.o \
o/$(MODE)/libc/calls/sigenter-xnu.o \
o/$(MODE)/libc/calls/ntcontext2linux.o: private \
OVERRIDE_COPTS += \
-O3
# we must disable static stack safety because:
# these functions use alloca(n)
o/$(MODE)/libc/calls/execl.o \
o/$(MODE)/libc/calls/execle.o \
o/$(MODE)/libc/calls/execlp.o \
o/$(MODE)/libc/calls/statfs.o \
o/$(MODE)/libc/calls/fstatfs.o \
o/$(MODE)/libc/calls/execve-sysv.o \
o/$(MODE)/libc/calls/readlinkat-nt.o \
o/$(MODE)/libc/calls/execve-nt.greg.o \
o/$(MODE)/libc/calls/mkntenvblock.o: private \
OVERRIDE_CPPFLAGS += \
-DSTACK_FRAME_UNLIMITED
# we must segregate codegen because:
# file contains multiple independently linkable apis
o/$(MODE)/libc/calls/ioctl-siocgifconf.o \
o/$(MODE)/libc/calls/ioctl-siocgifconf-nt.o: private \
OVERRIDE_COPTS += \
-ffunction-sections \
-fdata-sections
# we always want -Os because:
# va_arg codegen is very bloated in default mode
o//libc/calls/open.o \
o//libc/calls/openat.o \
o//libc/calls/prctl.o \
o//libc/calls/ioctl.o \
o//libc/calls/ioctl_default.o \
o//libc/calls/ioctl_fioclex-nt.o \
o//libc/calls/ioctl_fioclex.o \
o//libc/calls/ioctl_siocgifconf-nt.o \
o//libc/calls/ioctl_siocgifconf.o \
o//libc/calls/ioctl_tcgets-nt.o \
o//libc/calls/ioctl_tcgets.o \
o//libc/calls/ioctl_tcsets-nt.o \
o//libc/calls/ioctl_tcsets.o \
o//libc/calls/ioctl_tiocgwinsz-nt.o \
o//libc/calls/ioctl_tiocgwinsz.o \
o//libc/calls/ioctl_tiocswinsz-nt.o \
o//libc/calls/ioctl_tiocswinsz.o \
o//libc/calls/fcntl.o: private \
OVERRIDE_CFLAGS += \
-Os
# we always want -Os because:
# it's early runtime mandatory and quite huge without it
o//libc/calls/getcwd.greg.o \
o//libc/calls/getcwd-nt.greg.o \
o//libc/calls/getcwd-xnu.greg.o \
o//libc/calls/statfs2cosmo.o: private \
OVERRIDE_CFLAGS += \
-Os
# we always want -O2 because:
# division is expensive if not optimized
o/$(MODE)/libc/calls/clock.o \
o/$(MODE)/libc/calls/timespec_tomillis.o \
o/$(MODE)/libc/calls/timespec_tomicros.o \
o/$(MODE)/libc/calls/timespec_totimeval.o \
o/$(MODE)/libc/calls/timespec_fromnanos.o \
o/$(MODE)/libc/calls/timespec_frommillis.o \
o/$(MODE)/libc/calls/timespec_frommicros.o \
o/$(MODE)/libc/calls/timeval_tomillis.o \
o/$(MODE)/libc/calls/timeval_frommillis.o \
o/$(MODE)/libc/calls/timeval_frommicros.o: private \
OVERRIDE_CFLAGS += \
-O2
o/$(MODE)/libc/calls/pledge-linux.o \
o/$(MODE)/libc/calls/unveil.o: private \
OVERRIDE_CFLAGS += \
-DSTACK_FRAME_UNLIMITED
ifeq ($(ARCH), aarch64)
o/$(MODE)/libc/calls/sigaction.o: private OVERRIDE_CFLAGS += -mcmodel=large
endif
# we want -Os because:
# it makes a big difference
# we need pic because:
# so it can be an LD_PRELOAD payload
o/$(MODE)/libc/calls/pledge-linux.o: private \
OVERRIDE_CFLAGS += \
-Os \
-fPIC
LIBC_CALLS_LIBS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)))
LIBC_CALLS_SRCS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_SRCS))
LIBC_CALLS_HDRS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_HDRS))
LIBC_CALLS_INCS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_INCS))
LIBC_CALLS_BINS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_BINS))
LIBC_CALLS_CHECKS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_CHECKS))
LIBC_CALLS_OBJS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_OBJS))
LIBC_CALLS_TESTS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_TESTS))
.PHONY: o/$(MODE)/libc/calls
o/$(MODE)/libc/calls: $(LIBC_CALLS_CHECKS)
| 6,617 | 215 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/makedirs.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
#include "libc/str/path.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
/**
* Creates directory and parent components.
*
* This function is similar to mkdir() except it iteratively creates
* parent directories and it won't fail if the directory already exists.
*
* @param path is a UTF-8 string, preferably relative w/ forward slashes
* @param mode can be, for example, 0755
* @return 0 on success or -1 w/ errno
* @raise EEXIST if named file already exists as non-directory
* @raise ENOTDIR if directory component in `path` existed as non-directory
* @raise ENAMETOOLONG if symlink-resolved `path` length exceeds `PATH_MAX`
* @raise ENAMETOOLONG if component in `path` exists longer than `NAME_MAX`
* @raise EROFS if parent directory is on read-only filesystem
* @raise ENOSPC if file system or parent directory is full
* @raise EACCES if write permission was denied on parent directory
* @raise EACCES if search permission was denied on component in `path`
* @raise ENOENT if `path` is an empty string
* @raise ELOOP if loop was detected resolving components of `path`
* @asyncsignalsafe
* @threadsafe
*/
int makedirs(const char *path, unsigned mode) {
int c, e, i, n;
struct stat st;
char buf[PATH_MAX];
e = errno;
n = strlen(path);
if (n >= PATH_MAX) return enametoolong();
memcpy(buf, path, n + 1);
i = n;
// descend
while (i) {
if (!mkdir(buf, mode)) break;
if (errno == EEXIST) {
if (i == n) goto CheckTop;
break;
}
if (errno != ENOENT) return -1;
while (i && _isdirsep(buf[i - 1])) buf[--i] = 0;
while (i && !_isdirsep(buf[i - 1])) buf[--i] = 0;
}
// ascend
for (;;) {
if (mkdir(buf, mode)) {
if (errno != EEXIST) return -1;
if (i == n) goto CheckTop;
}
if (i == n) break;
while (i < n && !_isdirsep((c = path[i]))) buf[i++] = c;
while (i < n && _isdirsep((c = path[i]))) buf[i++] = c;
}
Finish:
errno = e;
return 0;
CheckTop:
if (stat(path, &st)) return -1;
if (S_ISDIR(st.st_mode)) goto Finish;
return eexist();
}
| 4,027 | 92 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/execle.c | /*-*- 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/mem/alloca.h"
/**
* Executes program, with custom environment.
*
* The current process is replaced with the executed one.
*
* @param prog will not be PATH searched, see commandv()
* @param arg[0] is the name of the program to run
* @param arg[1,n-3] optionally specify program arguments
* @param arg[n-2] is NULL
* @param arg[n-1] is a pointer to a ["key=val",...,NULL] array
* @return doesn't return on success, otherwise -1 w/ errno
* @asyncsignalsafe
* @vforksafe
*/
int execle(const char *exe, const char *arg,
... /*, NULL, char *const envp[] */) {
int i;
va_list va, vb;
char **argv, **envp;
va_copy(vb, va);
va_start(va, arg);
for (i = 0; va_arg(va, const char *); ++i) donothing;
envp = va_arg(va, char **);
va_end(va);
argv = alloca((i + 2) * sizeof(char *));
va_start(vb, arg);
argv[0] = arg;
for (i = 1;; ++i) {
if (!(argv[i] = va_arg(vb, const char *))) break;
}
va_end(vb);
return execve(exe, argv, envp);
}
| 2,861 | 55 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/munlock.c | /*-*- 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 2023 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/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/nt/memory.h"
#include "libc/runtime/runtime.h"
static textwindows int sys_munlock_nt(const void *addr, size_t len) {
if (VirtualUnlock(addr, len)) {
return 0;
} else {
return __winerr();
}
}
/**
* Unlocks virtual memory interval from RAM, to permit swapping.
*
* @return 0 on success, or -1 w/ errno
*/
int munlock(const void *addr, size_t len) {
if (!IsWindows()) {
return sys_munlock(addr, len);
} else {
return sys_munlock_nt(addr, len);
}
}
| 2,434 | 45 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/landlock_restrict_self.c | /*-*- 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/landlock.h"
#include "libc/intrin/strace.internal.h"
int sys_landlock_restrict_self(int, uint32_t);
/**
* Enforces Landlock ruleset on calling thread.
*
* @error EOPNOTSUPP if Landlock supported but disabled at boot time
* @error EINVAL if flags isn't zero
* @error EBADF if `fd` isn't file descriptor for the current thread
* @error EBADFD if `fd` is not a ruleset file descriptor
* @error EPERM if `fd` has no read access to underlying ruleset, or
* current thread is not running with no_new_privs, or it doesnât
* have CAP_SYS_ADMIN in its namespace
* @error E2BIG if the maximum number of stacked rulesets is
* reached for current thread
*/
int landlock_restrict_self(int fd, uint32_t flags) {
int rc;
rc = sys_landlock_restrict_self(fd, flags);
KERNTRACE("landlock_create_ruleset(%d, %#x) â %d% m", fd, flags, rc);
return rc;
}
| 2,728 | 43 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/lutimes.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h"
#include "libc/dce.h"
#include "libc/sysv/consts/at.h"
/**
* Changes file timestamps, the legacy way.
*/
int lutimes(const char *filename, const struct timeval tv[2]) {
struct timespec ts[2];
if (tv) {
ts[0].tv_sec = tv[0].tv_sec;
ts[0].tv_nsec = tv[0].tv_usec * 1000;
ts[1].tv_sec = tv[1].tv_sec;
ts[1].tv_nsec = tv[1].tv_usec * 1000;
return utimensat(AT_FDCWD, filename, ts, AT_SYMLINK_NOFOLLOW);
} else {
return utimensat(AT_FDCWD, filename, 0, AT_SYMLINK_NOFOLLOW);
}
}
| 2,424 | 39 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/pledge.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_PLEDGE_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_PLEDGE_INTERNAL_H_
#include "libc/calls/pledge.h"
#include "libc/intrin/promises.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct Pledges {
const char *name;
const uint16_t *syscalls;
const size_t len;
};
_Hide extern const struct Pledges kPledge[PROMISE_LEN_];
int sys_pledge_linux(unsigned long, int) _Hide;
int ParsePromises(const char *, unsigned long *) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_PLEDGE_INTERNAL_H_ */
| 612 | 22 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/pipe-sysv.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
int sys_pipe(int fds[2]) {
axdx_t ad;
int ax, dx;
ad = __sys_pipe(fds, 0);
ax = ad.ax;
dx = ad.dx;
if ((IsXnu() || IsNetbsd()) && ax != -1) {
fds[0] = ax;
fds[1] = dx;
ax = 0;
}
return ax;
}
| 2,124 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/linkat-nt.c | /*-*- 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/syscall_support-nt.internal.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
textwindows int sys_linkat_nt(int olddirfd, const char *oldpath, int newdirfd,
const char *newpath) {
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)) {
return 0;
} else {
return __fix_enotdir3(__winerr(), newpath16, oldpath16);
}
} else {
return -1;
}
}
| 2,477 | 39 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/getloadavg-nt.c | /*-*- 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/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/fmt/conv.h"
#include "libc/macros.internal.h"
#include "libc/nt/accounting.h"
#include "libc/runtime/runtime.h"
#include "libc/thread/thread.h"
#define FT(x) (x.dwLowDateTime | (uint64_t)x.dwHighDateTime << 32)
static int cpus;
static double load;
static pthread_spinlock_t lock;
static struct NtFileTime idle1, kern1, user1;
textwindows int sys_getloadavg_nt(double *a, int n) {
int i, rc;
uint64_t elapsed, used;
struct NtFileTime idle, kern, user;
pthread_spin_lock(&lock);
if (GetSystemTimes(&idle, &kern, &user)) {
elapsed = (FT(kern) - FT(kern1)) + (FT(user) - FT(user1));
if (elapsed) {
used = elapsed - (FT(idle) - FT(idle1));
load = (double)used / elapsed * cpus;
load = MIN(MAX(load, 0), cpus * 2);
idle1 = idle, kern1 = kern, user1 = user;
}
for (i = 0; i < n; ++i) {
a[i] = load;
}
rc = n;
} else {
rc = __winerr();
}
pthread_spin_unlock(&lock);
return rc;
}
static textstartup void sys_getloadavg_nt_init(void) {
double a[3];
if (IsWindows()) {
load = 1;
cpus = _getcpucount() / 2;
cpus = MAX(1, cpus);
GetSystemTimes(&idle1, &kern1, &user1);
}
}
const void *const sys_getloadavg_nt_ctor[] initarray = {
sys_getloadavg_nt_init,
};
| 3,206 | 72 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/madvise-nt.c | /*-*- 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/syscall_support-nt.internal.h"
#include "libc/macros.internal.h"
#include "libc/nt/enum/offerpriority.h"
#include "libc/nt/memory.h"
#include "libc/nt/runtime.h"
#include "libc/nt/struct/memoryrangeentry.h"
#include "libc/sysv/consts/madv.h"
#include "libc/sysv/errfuns.h"
forceinline typeof(PrefetchVirtualMemory) *GetPrefetchVirtualMemory(void) {
static bool once;
static typeof(PrefetchVirtualMemory) *PrefetchVirtualMemory_;
if (!once) {
PrefetchVirtualMemory_ = /* win8.1+ */
GetProcAddressModule("Kernel32.dll", "PrefetchVirtualMemory");
once = true;
}
return PrefetchVirtualMemory_;
}
forceinline typeof(OfferVirtualMemory) *GetOfferVirtualMemory(void) {
static bool once;
static typeof(OfferVirtualMemory) *OfferVirtualMemory_;
if (!once) {
OfferVirtualMemory_ = /* win8.1+ */
GetProcAddressModule("Kernel32.dll", "OfferVirtualMemory");
once = true;
}
return OfferVirtualMemory_;
}
textwindows int sys_madvise_nt(void *addr, size_t length, int advice) {
uint32_t rangecount;
struct NtMemoryRangeEntry ranges[1];
if (advice == MADV_WILLNEED || advice == MADV_SEQUENTIAL) {
typeof(PrefetchVirtualMemory) *fn = GetPrefetchVirtualMemory();
if (fn) {
ranges[0].VirtualAddress = addr;
ranges[0].NumberOfBytes = length;
rangecount = ARRAYLEN(ranges);
if (fn(GetCurrentProcess(), &rangecount, ranges, 0)) {
return 0;
} else {
return __winerr();
}
} else {
return enosys();
}
} else if (advice == MADV_FREE) {
typeof(OfferVirtualMemory) *fn = GetOfferVirtualMemory();
if (fn) {
if (fn(addr, length, kNtVmOfferPriorityNormal)) {
return 0;
} else {
return __winerr();
}
} else {
return enosys();
}
} else {
return einval();
}
}
| 3,683 | 82 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/utimensat-sysv.c | /*-*- 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/struct/timespec.internal.h"
#include "libc/calls/struct/timeval.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/sysv/consts/at.h"
#include "libc/time/time.h"
#include "libc/zipos/zipos.internal.h"
int sys_utimensat(int dirfd, const char *path, const struct timespec ts[2],
int flags) {
int rc, olderr;
struct timeval tv[2];
if (!IsXnu()) {
if (!path && (IsFreebsd() || IsNetbsd() || IsOpenbsd())) {
rc = sys_futimens(dirfd, ts);
} else {
olderr = errno;
rc = __sys_utimensat(dirfd, path, ts, flags);
// TODO(jart): How does RHEL5 do futimes()?
if (rc == -1 && errno == ENOSYS && path) {
errno = olderr;
if (ts) {
tv[0] = timespec_totimeval(ts[0]);
tv[1] = timespec_totimeval(ts[1]);
rc = sys_utimes(path, tv);
} else {
rc = sys_utimes(path, NULL);
}
}
}
return rc;
} else {
return sys_utimensat_xnu(dirfd, path, ts, flags);
}
}
| 2,894 | 55 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/getprogramexecutablename.greg.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/calls/calls.h"
#include "libc/calls/metalfile.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/ok.h"
#define SIZE 1024
#define CTL_KERN 1
#define KERN_PROC 14
#define KERN_PROC_PATHNAME_FREEBSD 12
#define KERN_PROC_PATHNAME_NETBSD 5
char program_executable_name[PATH_MAX];
static inline int IsAlpha(int c) {
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
}
static inline char *StrCat(char buf[PATH_MAX], const char *a, const char *b) {
char *p, *e;
p = buf;
e = buf + PATH_MAX;
while (*a && p < e) *p++ = *a++;
while (*b && p < e) *p++ = *b++;
return buf;
}
static inline void GetProgramExecutableNameImpl(char *p, char *e) {
char *q;
ssize_t rc;
size_t i, n;
union {
int cmd[4];
char path[PATH_MAX];
char16_t path16[PATH_MAX];
} u;
if (IsWindows()) {
n = GetModuleFileName(0, u.path16, ARRAYLEN(u.path16));
for (i = 0; i < n; ++i) {
// turn c:\foo\bar into c:/foo/bar
if (u.path16[i] == '\\') {
u.path16[i] = '/';
}
}
if (IsAlpha(u.path16[0]) && u.path16[1] == ':' && u.path16[2] == '/') {
// turn c:/... into /c/...
u.path16[1] = u.path16[0];
u.path16[0] = '/';
u.path16[2] = '/';
}
tprecode16to8(p, e - p, u.path16);
return;
}
if (IsMetal()) {
if (!memccpy(p, APE_COM_NAME, 0, e - p - 1)) e[-1] = 0;
return;
}
// if argv[0] exists then turn it into an absolute path. we also try
// adding a .com suffix since the ape auto-appends it when resolving
if (__argc && (((q = __argv[0]) && !sys_faccessat(AT_FDCWD, q, F_OK, 0)) ||
((q = StrCat(u.path, __argv[0], ".com")) &&
!sys_faccessat(AT_FDCWD, q, F_OK, 0)))) {
if (*q != '/') {
if (q[0] == '.' && q[1] == '/') {
q += 2;
}
if (getcwd(p, e - p)) {
while (*p) ++p;
*p++ = '/';
}
}
for (i = 0; *q && p + 1 < e; ++p, ++q) {
*p = *q;
}
*p = 0;
return;
}
// if argv[0] doesn't exist, then fallback to interpreter name
if ((rc = sys_readlinkat(AT_FDCWD, "/proc/self/exe", p, e - p - 1)) > 0 ||
(rc = sys_readlinkat(AT_FDCWD, "/proc/curproc/file", p, e - p - 1)) > 0) {
p[rc] = 0;
return;
}
if (IsFreebsd() || IsNetbsd()) {
u.cmd[0] = CTL_KERN;
u.cmd[1] = KERN_PROC;
if (IsFreebsd()) {
u.cmd[2] = KERN_PROC_PATHNAME_FREEBSD;
} else {
u.cmd[2] = KERN_PROC_PATHNAME_NETBSD;
}
u.cmd[3] = -1; // current process
n = e - p;
if (sys_sysctl(u.cmd, ARRAYLEN(u.cmd), p, &n, 0, 0) != -1) {
return;
}
}
}
/**
* Returns absolute path of program.
*/
char *GetProgramExecutableName(void) {
int e;
static bool once;
if (!once) {
e = errno;
GetProgramExecutableNameImpl(
program_executable_name,
program_executable_name + sizeof(program_executable_name));
errno = e;
once = true;
}
return program_executable_name;
}
/* const void *const GetProgramExecutableNameCtor[] initarray = { */
/* GetProgramExecutableName, */
/* }; */
| 5,199 | 148 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/isatty-nt.c | /*-*- 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/internal.h"
#include "libc/nt/enum/filetype.h"
#include "libc/nt/files.h"
#include "libc/sysv/errfuns.h"
textwindows bool32 sys_isatty_nt(int fd) {
if (__isfdopen(fd)) {
if (__isfdkind(fd, kFdConsole) ||
(__isfdkind(fd, kFdFile) &&
GetFileType(g_fds.p[fd].handle) == kNtFileTypeChar)) {
return true;
} else {
enotty();
return false;
}
} else {
ebadf();
return false;
}
}
| 2,290 | 39 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/sigval.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
union sigval {
int32_t sival_int;
void *sival_ptr;
};
int sigqueue(int, int, const union sigval);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_ */
| 384 | 16 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/timeval.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_
#include "libc/calls/struct/timespec.h"
#include "libc/time/struct/timezone.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct timeval {
int64_t tv_sec;
int64_t tv_usec; /* microseconds */
};
int futimes(int, const struct timeval[2]);
int futimesat(int, const char *, const struct timeval[2]);
int gettimeofday(struct timeval *, struct timezone *);
int lutimes(const char *, const struct timeval[2]);
int utimes(const char *, const struct timeval[2]);
int timeval_cmp(struct timeval, struct timeval) pureconst;
struct timeval timeval_frommicros(int64_t) pureconst;
struct timeval timeval_frommillis(int64_t) pureconst;
struct timeval timeval_add(struct timeval, struct timeval) pureconst;
struct timeval timeval_sub(struct timeval, struct timeval) pureconst;
struct timeval timespec_totimeval(struct timespec) pureconst;
struct timespec timeval_totimespec(struct timeval) pureconst;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_ */
| 1,132 | 30 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/stat.macros.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_MACROS_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_MACROS_H_
#define STAT_HAVE_NSEC 1
#define st_atime st_atim.tv_sec
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec
#define st_atime_nsec st_atim.tv_nsec
#define st_mtime_nsec st_mtim.tv_nsec
#define st_ctime_nsec st_ctim.tv_nsec
#define st_atimensec st_atim.tv_nsec
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
#define st_birthtime st_birthtim.tv_sec
#define st_file_attributes st_flags
#define INIT_STRUCT_STAT_PADDING(st) (void)st
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_MACROS_H_ */
| 642 | 24 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/ucontext.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_INTERNAL_H_
#include "libc/calls/ucontext.h"
#include "libc/nt/struct/context.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
void _ntcontext2linux(struct ucontext *, const struct NtContext *) _Hide;
void _ntlinux2context(struct NtContext *, const ucontext_t *) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_INTERNAL_H_ */
| 526 | 14 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/sysinfo.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sysinfo {
int64_t uptime; /* seconds since boot */
uint64_t loads[3]; /* 1-5-15 min active process averages */
uint64_t totalram; /* system physical memory */
uint64_t freeram; /* amount of ram currently going to waste */
uint64_t sharedram; /* bytes w/ pages mapped into multiple progs */
uint64_t bufferram; /* lingering disk pages; see fadvise */
uint64_t totalswap; /* size of emergency memory */
uint64_t freeswap; /* hopefully equal to totalswap */
int16_t procs; /* number of processes */
int16_t __ignore1; /* padding */
int32_t __ignore2; /* padding */
uint64_t totalhigh; /* wut */
uint64_t freehigh; /* wut */
uint32_t mem_unit; /* ram stuff above is multiples of this */
};
int sysinfo(struct sysinfo *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_ */
| 1,055 | 28 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/metastat.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_METASTAT_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METASTAT_H_
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/timespec.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define METASTAT(x, field) \
(IsLinux() || IsMetal() ? x.linux.field \
: IsXnu() ? x.xnu.field \
: IsFreebsd() ? x.freebsd.field \
: IsOpenbsd() ? x.openbsd.field \
: IsNetbsd() ? x.netbsd.field \
: 0)
struct stat_linux {
uint64_t st_dev;
uint64_t st_ino;
#ifdef __x86_64__
uint64_t st_nlink;
uint32_t st_mode;
uint32_t st_uid;
uint32_t st_gid;
uint32_t __pad0;
uint64_t st_rdev;
int64_t st_size;
int64_t st_blksize;
int64_t st_blocks;
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
int64_t __unused[3];
#elif defined(__aarch64__)
uint32_t st_mode;
uint32_t st_nlink;
uint32_t st_uid;
uint32_t st_gid;
uint64_t st_rdev;
uint64_t __pad1;
int64_t st_size;
int32_t st_blksize;
int32_t __pad2;
int64_t st_blocks;
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
uint32_t __unused4;
uint32_t __unused5;
#endif
};
struct stat_xnu {
int32_t st_dev;
uint16_t st_mode, st_nlink;
uint64_t st_ino;
uint32_t st_uid, st_gid;
int32_t st_rdev;
struct timespec st_atim, st_mtim, st_ctim, st_birthtim;
int64_t st_size, st_blocks;
int32_t st_blksize;
uint32_t st_flags, st_gen;
int32_t st_lspare;
int64_t st_qspare[2];
};
struct stat_freebsd {
uint64_t st_dev, st_ino, st_nlink;
uint16_t st_mode;
int16_t st_padding0;
uint32_t st_uid, st_gid;
int32_t st_padding1;
uint64_t st_rdev;
struct timespec st_atim, st_mtim, st_ctim, st_birthtim;
int64_t st_size, st_blocks;
int32_t st_blksize;
uint32_t st_flags;
uint64_t st_gen;
unsigned long st_spare[10];
};
struct stat_openbsd {
uint32_t st_mode;
int32_t st_dev;
uint64_t st_ino;
uint32_t st_nlink, st_uid, st_gid;
int32_t st_rdev;
struct timespec st_atim, st_mtim, st_ctim;
int64_t st_size, st_blocks;
int32_t st_blksize;
uint32_t st_flags, st_gen;
struct timespec st_birthtim;
};
struct stat_netbsd {
uint64_t st_dev;
uint32_t st_mode;
uint64_t st_ino;
uint32_t st_nlink, st_uid, st_gid;
uint64_t st_rdev;
struct timespec st_atim, st_mtim, st_ctim, st_birthtim;
int64_t st_size, st_blocks;
int32_t st_blksize;
uint32_t st_flags, st_gen, st_spare[2];
};
union metastat {
struct stat cosmo;
struct stat_linux linux;
struct stat_xnu xnu;
struct stat_freebsd freebsd;
struct stat_openbsd openbsd;
struct stat_netbsd netbsd;
};
void __stat2cosmo(struct stat *restrict, const union metastat *) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_METASTAT_H_ */
| 2,910 | 120 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/metatermios.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_
#include "libc/calls/struct/termios.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct termios_xnu {
uint64_t c_iflag;
uint64_t c_oflag;
uint64_t c_cflag;
uint64_t c_lflag;
uint8_t c_cc[20];
uint64_t c_ispeed;
uint64_t c_ospeed;
};
struct termios_bsd {
uint32_t c_iflag;
uint32_t c_oflag;
uint32_t c_cflag;
uint32_t c_lflag;
uint8_t c_cc[20];
uint32_t c_ispeed;
uint32_t c_ospeed;
};
union metatermios {
struct termios linux;
struct termios_xnu xnu;
struct termios_bsd bsd;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_METATERMIOS_H_ */
| 768 | 36 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/iovec.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_INTERNAL_H_
#include "libc/calls/struct/fd.internal.h"
#include "libc/calls/struct/iovec.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int64_t sys_preadv(int, struct iovec *, int, int64_t, int64_t) _Hide;
int64_t sys_pwritev(int, const struct iovec *, int, int64_t, int64_t) _Hide;
int64_t sys_readv(int32_t, const struct iovec *, int32_t) _Hide;
int64_t sys_vmsplice(int, const struct iovec *, int64_t, uint32_t) _Hide;
int64_t sys_writev(int32_t, const struct iovec *, int32_t) _Hide;
size_t __iovec_size(const struct iovec *, size_t) _Hide;
ssize_t WritevUninterruptible(int, struct iovec *, int);
ssize_t sys_read_nt(struct Fd *, const struct iovec *, size_t, ssize_t) _Hide;
ssize_t sys_readv_metal(struct Fd *, const struct iovec *, int) _Hide;
ssize_t sys_readv_nt(struct Fd *, const struct iovec *, int) _Hide;
ssize_t sys_readv_serial(struct Fd *, const struct iovec *, int) _Hide;
ssize_t sys_write_nt(int, const struct iovec *, size_t, ssize_t) _Hide;
ssize_t sys_writev_metal(struct Fd *, const struct iovec *, int) _Hide;
ssize_t sys_writev_nt(int, const struct iovec *, int) _Hide;
ssize_t sys_writev_serial(struct Fd *, const struct iovec *, int) _Hide;
ssize_t sys_send_nt(int, const struct iovec *, size_t, uint32_t) _Hide;
ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, void *,
uint32_t) _Hide;
const char *DescribeIovec(char[300], ssize_t, const struct iovec *, int);
#define DescribeIovec(x, y, z) DescribeIovec(alloca(300), x, y, z)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_INTERNAL_H_ */
| 1,776 | 34 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/winsize.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct winsize {
uint16_t ws_row;
uint16_t ws_col;
uint16_t ws_xpixel;
uint16_t ws_ypixel;
};
int _getttysize(int, struct winsize *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_ */
| 427 | 18 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/sysinfo.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_INTERNAL_H_
#include "libc/calls/struct/sysinfo.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int sys_sysinfo(struct sysinfo *) _Hide;
int sys_sysinfo_nt(struct sysinfo *) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_INTERNAL_H_ */
| 435 | 13 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/flock.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_FLOCK_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FLOCK_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct flock { /* cosmopolitan abi */
int16_t l_type; /* F_RDLCK, F_WRLCK, F_UNLCK */
int16_t l_whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
int64_t l_start; /* starting offset */
int64_t l_len; /* no. bytes (0 means to end of file) */
int32_t l_pid; /* lock owner */
int32_t l_sysid; /* remote system id or zero for local (freebsd) */
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_FLOCK_H_ */
| 642 | 18 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/timespec.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define timespec_zero ((struct timespec){0})
#define timespec_max ((struct timespec){0x7fffffffffffffff, 999999999})
struct timespec {
int64_t tv_sec;
int64_t tv_nsec; /* nanoseconds */
};
int clock_getres(int, struct timespec *);
int clock_gettime(int, struct timespec *);
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int futimens(int, const struct timespec[2]);
int nanosleep(const struct timespec *, struct timespec *);
int sys_futex(int *, int, int, const struct timespec *, int *);
int utimensat(int, const char *, const struct timespec[2], int);
int timespec_get(struct timespec *, int);
int timespec_getres(struct timespec *, int);
int timespec_cmp(struct timespec, struct timespec) pureconst;
int64_t timespec_tomicros(struct timespec) pureconst;
int64_t timespec_tomillis(struct timespec) pureconst;
int64_t timespec_tonanos(struct timespec) pureconst;
struct timespec timespec_add(struct timespec, struct timespec) pureconst;
struct timespec timespec_fromnanos(int64_t) pureconst;
struct timespec timespec_frommicros(int64_t) pureconst;
struct timespec timespec_frommillis(int64_t) pureconst;
struct timespec timespec_real(void);
struct timespec timespec_mono(void);
struct timespec timespec_sleep(struct timespec);
int timespec_sleep_until(struct timespec);
struct timespec timespec_sub(struct timespec, struct timespec) pureconst;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_ */
| 1,668 | 41 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/ucontext-netbsd.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_NETBSD_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_NETBSD_INTERNAL_H_
#include "libc/calls/ucontext.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
// clang-format off
#ifdef __x86_64__
#define __UCONTEXT_SIZE 784
#define _UC_SIGMASK 0x01
#define _UC_STACK 0x02
#define _UC_CPU 0x04
#define _UC_FPU 0x08
#define _UC_TLSBASE 0x00080000
#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
union sigval_netbsd {
int32_t sival_int;
void *sival_ptr;
};
struct sigset_netbsd {
uint32_t __bits[4];
};
struct stack_netbsd {
void *ss_sp;
size_t ss_size;
int32_t ss_flags;
};
struct mcontext_netbsd {
union {
struct {
uint64_t rdi;
uint64_t rsi;
uint64_t rdx;
uint64_t rcx;
uint64_t r8;
uint64_t r9;
uint64_t r10;
uint64_t r11;
uint64_t r12;
uint64_t r13;
uint64_t r14;
uint64_t r15;
uint64_t rbp;
uint64_t rbx;
uint64_t rax;
uint64_t gs;
uint64_t fs;
uint64_t es;
uint64_t ds;
uint64_t trapno;
uint64_t err;
uint64_t rip;
uint64_t cs;
uint64_t rflags;
uint64_t rsp;
uint64_t ss;
};
int64_t __gregs[26];
};
int64_t _mc_tlsbase;
struct FpuState __fpregs;
};
struct ucontext_netbsd {
union {
struct {
uint32_t uc_flags; /* see _UC_* above */
struct ucontext_netbsd *uc_link;
struct sigset_netbsd uc_sigmask;
struct stack_netbsd uc_stack;
struct mcontext_netbsd uc_mcontext;
};
char __pad[__UCONTEXT_SIZE];
};
};
#endif /* __x86_64__ */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_NETBSD_INTERNAL_H_ */
| 1,833 | 88 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/framebufferfixedscreeninfo.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERFIXEDSCREENINFO_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERFIXEDSCREENINFO_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct FrameBufferFixedScreenInfo {
char id[16];
uint64_t smem_start;
uint32_t smem_len;
uint32_t type;
uint32_t type_aux;
uint32_t visual;
uint16_t xpanstep;
uint16_t ypanstep;
uint16_t ywrapstep;
uint32_t line_length;
uint64_t mmio_start;
uint32_t mmio_len;
uint32_t accel;
uint16_t capabilities;
uint16_t reserved[2];
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERFIXEDSCREENINFO_H_ */
| 653 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/rlimit.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_INTERNAL_H_
#include "libc/calls/struct/rlimit.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int sys_getrlimit(int, struct rlimit *) _Hide;
int sys_setrlimit(int, const struct rlimit *) _Hide;
int sys_setrlimit_nt(int, const struct rlimit *) _Hide;
const char *DescribeRlimit(char[64], int, const struct rlimit *);
#define DescribeRlimit(rc, rl) DescribeRlimit(alloca(64), rc, rl)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_INTERNAL_H_ */
| 664 | 18 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/dirent.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct dirent { /* linux getdents64 abi */
uint64_t d_ino; /* inode number */
int64_t d_off; /* implementation-dependent location number */
uint16_t d_reclen; /* byte length of this whole struct and string */
uint8_t d_type; /* DT_REG, DT_DIR, DT_UNKNOWN, DT_BLK, etc. */
char d_name[256]; /* NUL-terminated basename */
};
struct dirstream;
typedef struct dirstream DIR;
DIR *fdopendir(int) dontdiscard;
DIR *opendir(const char *) dontdiscard;
int closedir(DIR *);
int dirfd(DIR *);
long telldir(DIR *);
struct dirent *readdir(DIR *);
int readdir_r(DIR *, struct dirent *, struct dirent **);
void rewinddir(DIR *);
void seekdir(DIR *, long);
int alphasort(const struct dirent **, const struct dirent **);
int versionsort(const struct dirent **, const struct dirent **);
int scandir(const char *, struct dirent ***, int (*)(const struct dirent *),
int (*)(const struct dirent **, const struct dirent **));
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_ */
| 1,226 | 34 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/siginfo-netbsd.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_NETBSD_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_NETBSD_H_
#include "libc/calls/struct/sigval.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct siginfo_netbsd {
int32_t si_signo;
int32_t si_code;
int32_t si_errno;
int32_t __pad;
union {
struct { /* RT */
int32_t si_pid;
int32_t si_uid;
union sigval si_value;
};
struct { /* chld */
int32_t _pid;
int32_t _uid;
int32_t si_status;
int64_t si_utime;
int64_t si_stime;
};
struct { /* fault */
void *si_addr;
int32_t si_trap;
int32_t si_trap2;
int32_t si_trap3;
};
struct { /* poll */
int64_t si_band;
int32_t si_fd;
};
struct { /* syscall */
int32_t si_sysnum;
int32_t si_retval[2];
int32_t si_error;
uint64_t si_args[8];
};
struct { /* ptrace */
int32_t si_pe_report_event;
union {
int32_t si_pe_other_pid;
int32_t si_pe_lwp;
};
};
};
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_NETBSD_H_ */
| 1,194 | 54 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/iovec.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct iovec {
void *iov_base;
size_t iov_len;
};
ssize_t preadv(int, struct iovec *, int, int64_t);
ssize_t pwritev(int, const struct iovec *, int, int64_t);
ssize_t readv(int, const struct iovec *, int);
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t);
ssize_t writev(int, const struct iovec *, int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_ */
| 601 | 20 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/framebuffercolormap.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERCOLORMAP_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERCOLORMAP_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct FrameBufferColorMap {
uint32_t start;
uint32_t len;
uint16_t *red;
uint16_t *green;
uint16_t *blue;
uint16_t *transp;
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERCOLORMAP_H_ */
| 418 | 16 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/framebuffervirtualscreeninfo.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERVIRTUALSCREENINFO_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERVIRTUALSCREENINFO_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct FrameBufferBitField {
uint32_t offset;
uint32_t length;
uint32_t msb_right;
};
struct FrameBufferVirtualScreenInfo {
uint32_t xres;
uint32_t yres;
uint32_t xres_virtual;
uint32_t yres_virtual;
uint32_t xoffset;
uint32_t yoffset;
uint32_t bits_per_pixel;
uint32_t grayscale;
struct FrameBufferBitField red;
struct FrameBufferBitField green;
struct FrameBufferBitField blue;
struct FrameBufferBitField transp;
uint32_t nonstd;
uint32_t activate;
uint32_t height;
uint32_t width;
uint32_t accel_flags;
uint32_t pixclock;
uint32_t left_margin;
uint32_t right_margin;
uint32_t upper_margin;
uint32_t lower_margin;
uint32_t hsync_len;
uint32_t vsync_len;
uint32_t sync;
uint32_t vmode;
uint32_t rotate;
uint32_t colorspace;
uint32_t reserved[4];
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERVIRTUALSCREENINFO_H_ */
| 1,120 | 45 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/statvfs.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct statvfs {
unsigned long f_bsize; /* Filesystem block size */
unsigned long f_frsize; /* Fragment size */
uint64_t f_blocks; /* Size of fs in f_frsize units */
uint64_t f_bfree; /* Number of free blocks */
uint64_t f_bavail; /* Number of free blocks for unprivileged users */
uint64_t f_files; /* Number of inodes */
uint64_t f_ffree; /* Number of free inodes */
uint64_t f_favail; /* Number of free inodes for unprivileged users */
unsigned long f_fsid; /* Filesystem ID */
unsigned long f_flag; /* Mount flags */
unsigned long f_namemax; /* Maximum filename length */
};
int statvfs(const char *, struct statvfs *);
int fstatvfs(int, struct statvfs *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_ */
| 1,016 | 26 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/statfs-meta.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_META_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_META_INTERNAL_H_
#include "libc/calls/struct/statfs-freebsd.internal.h"
#include "libc/calls/struct/statfs-linux.internal.h"
#include "libc/calls/struct/statfs-netbsd.internal.h"
#include "libc/calls/struct/statfs-openbsd.internal.h"
#include "libc/calls/struct/statfs-xnu.internal.h"
#include "libc/calls/struct/statfs.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
union statfs_meta {
struct statfs_linux linux;
struct statfs_xnu xnu;
struct statfs_freebsd freebsd;
struct statfs_openbsd openbsd;
struct statfs_netbsd netbsd;
};
void statfs2cosmo(struct statfs *, const union statfs_meta *) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_META_INTERNAL_H_ */
| 873 | 25 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/statfs-netbsd.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct statfs_netbsd {
int16_t f_type; /* type of file system */
uint16_t f_oflags; /* deprecated copy of mount flags */
int64_t f_bsize; /* fundamental file system block size */
int64_t f_iosize; /* optimal transfer block size */
int64_t f_blocks; /* total data blocks in file system */
int64_t f_bfree; /* free blocks in fs */
int64_t f_bavail; /* free blocks avail to non-superuser */
int64_t f_files; /* total file nodes in file system */
int64_t f_ffree; /* free file nodes in fs */
fsid_t f_fsid; /* file system id */
uint32_t f_owner; /* user that mounted the file system */
int64_t f_flags; /* copy of mount flags */
int64_t f_syncwrites; /* count of sync writes since mount */
int64_t f_asyncwrites; /* count of async writes since mount */
int64_t f_spare[1]; /* spare for later */
char f_fstypename[16]; /* fs type name */
char f_mntonname[90]; /* directory on which mounted */
char f_mntfromname[90]; /* mounted file system */
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_ */
| 1,406 | 31 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/itimerval.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_INTERNAL_H_
#include "libc/calls/struct/itimerval.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int sys_getitimer(int, struct itimerval *) _Hide;
int sys_setitimer(int, const struct itimerval *, struct itimerval *) _Hide;
int sys_setitimer_nt(int, const struct itimerval *, struct itimerval *) _Hide;
const char *DescribeTimeval(char[45], int, const struct timeval *);
#define DescribeTimeval(rc, ts) DescribeTimeval(alloca(45), rc, ts)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_INTERNAL_H_ */
| 729 | 18 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/siginfo-openbsd.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_OPENBSD_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_OPENBSD_H_
#include "libc/calls/struct/sigval.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct siginfo_openbsd {
int32_t si_signo;
int32_t si_code;
int32_t si_errno;
union {
int32_t _pad[(128 / 4) - 3];
struct {
int32_t si_pid;
union {
struct {
int32_t si_uid;
union sigval si_value;
};
struct {
int64_t si_utime;
int64_t si_stime;
int32_t si_status;
};
};
};
struct {
void *si_addr;
int32_t si_trapno;
};
};
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_OPENBSD_H_ */
| 812 | 37 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/statfs.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_INTERNAL_H_
#include "libc/calls/struct/statfs-meta.internal.h"
#include "libc/calls/struct/statfs.h"
#include "libc/calls/struct/statvfs.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int sys_statfs(const char *, union statfs_meta *);
int sys_fstatfs(int, union statfs_meta *);
int sys_fstatfs_nt(int64_t, struct statfs *);
int sys_statfs_nt(const char *, struct statfs *);
void statfs2statvfs(struct statvfs *, const struct statfs *);
const char *DescribeStatfs(char[300], int, const struct statfs *);
#define DescribeStatfs(rc, sf) DescribeStatfs(alloca(300), rc, sf)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_INTERNAL_H_ */
| 853 | 22 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/timespec.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_INTERNAL_H_
#include "libc/calls/struct/timespec.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* clang-format off */
int __sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *) _Hide;
int __sys_utimensat(int, const char *, const struct timespec[2], int) _Hide;
int __utimens(int, const char *, const struct timespec[2], int) _Hide;
int sys_clock_getres(int, struct timespec *) _Hide;
int sys_clock_gettime(int, struct timespec *) _Hide;
int sys_clock_gettime_nt(int, struct timespec *) _Hide;
int sys_clock_gettime_m1(int, struct timespec *) _Hide;
int sys_clock_gettime_xnu(int, struct timespec *) _Hide;
int sys_clock_nanosleep_nt(int, int, const struct timespec *, struct timespec *) _Hide;
int sys_clock_nanosleep_openbsd(int, int, const struct timespec *, struct timespec *) _Hide;
int sys_clock_nanosleep_xnu(int, int, const struct timespec *, struct timespec *) _Hide;
int sys_futimens(int, const struct timespec[2]) _Hide;
int sys_nanosleep(const struct timespec *, struct timespec *) _Hide;
int sys_nanosleep_nt(const struct timespec *, struct timespec *) _Hide;
int sys_nanosleep_xnu(const struct timespec *, struct timespec *) _Hide;
int sys_sem_timedwait(int64_t, const struct timespec *) _Hide;
int sys_utimensat(int, const char *, const struct timespec[2], int) _Hide;
int sys_utimensat_nt(int, const char *, const struct timespec[2], int) _Hide;
int sys_utimensat_xnu(int, const char *, const struct timespec[2], int) _Hide;
const char *DescribeTimespec(char[45], int, const struct timespec *);
#define DescribeTimespec(rc, ts) DescribeTimespec(alloca(45), rc, ts)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_INTERNAL_H_ */
| 1,890 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/ucontext-freebsd.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_FREEBSD_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_FREEBSD_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct stack_freebsd {
void *ss_sp;
uint64_t ss_size;
int32_t ss_flags;
};
struct mcontext_freebsd {
int64_t mc_onstack;
int64_t mc_rdi;
int64_t mc_rsi;
int64_t mc_rdx;
int64_t mc_rcx;
int64_t mc_r8;
int64_t mc_r9;
int64_t mc_rax;
int64_t mc_rbx;
int64_t mc_rbp;
int64_t mc_r10;
int64_t mc_r11;
int64_t mc_r12;
int64_t mc_r13;
int64_t mc_r14;
int64_t mc_r15;
uint32_t mc_trapno;
uint16_t mc_fs;
uint16_t mc_gs;
int64_t mc_addr;
uint32_t mc_flags;
uint16_t mc_es;
uint16_t mc_ds;
int64_t mc_err;
int64_t mc_rip;
int64_t mc_cs;
int64_t mc_rflags;
int64_t mc_rsp;
int64_t mc_ss;
int64_t mc_len;
int64_t mc_fpformat;
int64_t mc_ownedfp;
int64_t mc_fpstate[64];
int64_t mc_fsbase;
int64_t mc_gsbase;
int64_t mc_xfpustate;
int64_t mc_xfpustate_len;
int64_t mc_spare[4];
};
struct ucontext_freebsd {
uint32_t uc_sigmask[4];
struct mcontext_freebsd uc_mcontext;
struct ucontext_freebsd *uc_link;
struct stack_freebsd uc_stack;
int32_t uc_flags;
int32_t __spare__[4];
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_FREEBSD_INTERNAL_H_ */
| 1,396 | 65 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/tms.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct tms {
int64_t tms_utime; /* userspace time */
int64_t tms_stime; /* kernelspace time */
int64_t tms_cutime; /* children userspace time */
int64_t tms_cstime; /* children kernelspace time */
};
long times(struct tms *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_ */
| 509 | 18 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/metasigaltstack.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_METASIGALTSTACK_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METASIGALTSTACK_H_
#include "libc/calls/struct/sigaltstack.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sigaltstack_bsd {
void *ss_sp;
uint64_t ss_size;
int32_t ss_flags;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_METASIGALTSTACK_H_ */
| 434 | 16 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/itimerval.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_H_
#include "libc/calls/struct/timeval.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct itimerval {
struct timeval it_interval; /* {0,0} means singleshot */
struct timeval it_value; /* {0,0} means disarm */
};
int getitimer(int, struct itimerval *);
int setitimer(int, const struct itimerval *, struct itimerval *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_H_ */
| 572 | 18 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/rusage.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_
#include "libc/calls/struct/timeval.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct rusage {
struct timeval ru_utime; /* user CPU time used */
struct timeval ru_stime; /* system CPU time used */
int64_t ru_maxrss; /* maximum resident set size in (kb) */
int64_t ru_ixrss; /* shared memory size (integral kb CLK_TCK) */
int64_t ru_idrss; /* unshared data size (integral kb CLK_TCK) */
int64_t ru_isrss; /* unshared stack size (integral kb CLK_TCK) */
int64_t ru_minflt; /* page reclaims */
int64_t ru_majflt; /* page faults */
int64_t ru_nswap; /* swaps */
int64_t ru_inblock; /* block input operations */
int64_t ru_oublock; /* block output operations */
int64_t ru_msgsnd; /* IPC messages sent */
int64_t ru_msgrcv; /* IPC messages received */
int64_t ru_nsignals; /* signals received */
int64_t ru_nvcsw; /* voluntary context switches */
int64_t ru_nivcsw; /* involuntary context switches */
};
int getrusage(int, struct rusage *);
int wait3(int *, int, struct rusage *);
int wait4(int, int *, int, struct rusage *);
void rusage_add(struct rusage *, const struct rusage *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_ */
| 1,437 | 34 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/seccomp.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SECCOMP_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SECCOMP_H_
#define SECCOMP_SET_MODE_STRICT 0
#define SECCOMP_SET_MODE_FILTER 1
#define SECCOMP_GET_ACTION_AVAIL 2
#define SECCOMP_GET_NOTIF_SIZES 3
#define SECCOMP_FILTER_FLAG_TSYNC (1UL << 0)
#define SECCOMP_FILTER_FLAG_LOG (1UL << 1)
#define SECCOMP_FILTER_FLAG_SPEC_ALLOW (1UL << 2)
#define SECCOMP_FILTER_FLAG_NEW_LISTENER (1UL << 3)
#define SECCOMP_FILTER_FLAG_TSYNC_ESRCH (1UL << 4)
#define SECCOMP_RET_KILL_PROCESS 0x80000000U
#define SECCOMP_RET_KILL_THREAD 0x00000000U
#define SECCOMP_RET_KILL SECCOMP_RET_KILL_THREAD
#define SECCOMP_RET_TRAP 0x00030000U
#define SECCOMP_RET_ERRNO 0x00050000U
#define SECCOMP_RET_USER_NOTIF 0x7fc00000U
#define SECCOMP_RET_TRACE 0x7ff00000U
#define SECCOMP_RET_LOG 0x7ffc0000U
#define SECCOMP_RET_ALLOW 0x7fff0000U
#define SECCOMP_RET_ACTION_FULL 0xffff0000U
#define SECCOMP_RET_ACTION 0x7fff0000U
#define SECCOMP_RET_DATA 0x0000ffffU
#define SECCOMP_USER_NOTIF_FLAG_CONTINUE (1UL << 0)
#define SECCOMP_ADDFD_FLAG_SETFD (1UL << 0)
#define SECCOMP_ADDFD_FLAG_SEND (1UL << 1)
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define SECCOMP_IOC_MAGIC '!'
#define SECCOMP_IO(nr) _IO(SECCOMP_IOC_MAGIC, nr)
#define SECCOMP_IOR(nr, type) _IOR(SECCOMP_IOC_MAGIC, nr, type)
#define SECCOMP_IOW(nr, type) _IOW(SECCOMP_IOC_MAGIC, nr, type)
#define SECCOMP_IOWR(nr, type) _IOWR(SECCOMP_IOC_MAGIC, nr, type)
#define SECCOMP_IOCTL_NOTIF_RECV SECCOMP_IOWR(0, struct seccomp_notif)
#define SECCOMP_IOCTL_NOTIF_SEND SECCOMP_IOWR(1, struct seccomp_notif_resp)
#define SECCOMP_IOCTL_NOTIF_ID_VALID SECCOMP_IOW(2, __u64)
#define SECCOMP_IOCTL_NOTIF_ADDFD SECCOMP_IOW(3, struct seccomp_notif_addfd)
struct seccomp_data {
int32_t nr;
uint32_t arch;
uint64_t instruction_pointer;
uint64_t args[6];
};
struct seccomp_notif_sizes {
uint16_t seccomp_notif;
uint16_t seccomp_notif_resp;
uint16_t seccomp_data;
};
struct seccomp_notif {
uint64_t id;
uint32_t pid;
uint32_t flags;
struct seccomp_data data;
};
struct seccomp_notif_resp {
uint64_t id;
int64_t val;
int32_t error;
uint32_t flags;
};
struct seccomp_notif_addfd {
uint64_t id;
uint32_t flags;
uint32_t srcfd;
uint32_t newfd;
uint32_t newfd_flags;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SECCOMP_H_ */
| 2,657 | 81 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/statfs-xnu.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct statfs_xnu {
uint32_t f_bsize; /* fundamental file system block size */
int32_t f_iosize; /* optimal transfer block size */
uint64_t f_blocks; /* total data blocks in file system */
uint64_t f_bfree; /* free blocks in fs */
uint64_t f_bavail; /* free blocks avail to non-superuser */
uint64_t f_files; /* total file nodes in file system */
uint64_t f_ffree; /* free file nodes in fs */
fsid_t f_fsid; /* file system id */
uint32_t f_owner; /* user that mounted the filesystem */
uint32_t f_type; /* type of filesystem */
uint32_t f_flags; /* copy of mount exported flags */
uint32_t f_fssubtype; /* fs sub-type (flavor) */
char f_fstypename[16]; /* fs type name */
char f_mntonname[4096]; /* directory on which mounted */
char f_mntfromname[4096]; /* mounted filesystem */
uint32_t f_flags_ext; /* extended flags */
uint32_t f_reserved[7]; /* For future use */
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_ */
| 1,366 | 30 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/filter.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_FILTER_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FILTER_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define BPF_MAJOR_VERSION 1
#define BPF_MINOR_VERSION 1
struct sock_filter {
uint16_t code;
uint8_t jt;
uint8_t jf;
uint32_t k;
};
struct sock_fprog {
unsigned short len;
struct sock_filter *filter;
};
#define BPF_RVAL(code) ((code)&0x18)
#define BPF_A 0x10
#define BPF_MISCOP(code) ((code)&0xf8)
#define BPF_TAX 0x00
#define BPF_TXA 0x80
#define BPF_STMT(code, k) \
{ (unsigned short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jumptrue, jumpfalse) \
{ (unsigned short)(code), jumptrue, jumpfalse, k }
#define BPF_MEMWORDS 16
#define SKF_AD_OFF (-0x1000)
#define SKF_AD_PROTOCOL 0
#define SKF_AD_PKTTYPE 4
#define SKF_AD_IFINDEX 8
#define SKF_AD_NLATTR 12
#define SKF_AD_NLATTR_NEST 16
#define SKF_AD_MARK 20
#define SKF_AD_QUEUE 24
#define SKF_AD_HATYPE 28
#define SKF_AD_RXHASH 32
#define SKF_AD_CPU 36
#define SKF_AD_ALU_XOR_X 40
#define SKF_AD_VLAN_TAG 44
#define SKF_AD_VLAN_TAG_PRESENT 48
#define SKF_AD_PAY_OFFSET 52
#define SKF_AD_RANDOM 56
#define SKF_AD_VLAN_TPID 60
#define SKF_AD_MAX 64
#define SKF_NET_OFF (-0x100000)
#define SKF_LL_OFF (-0x200000)
#define BPF_NET_OFF SKF_NET_OFF
#define BPF_LL_OFF SKF_LL_OFF
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_FILTER_H_ */
| 1,670 | 60 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/statfs-freebsd.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct statfs_freebsd {
uint32_t f_version; /* structure version number */
uint32_t f_type; /* type of filesystem */
uint64_t f_flags; /* copy of mount exported flags */
uint64_t f_bsize; /* filesystem fragment size */
uint64_t f_iosize; /* optimal transfer block size */
uint64_t f_blocks; /* total data blocks in filesystem */
uint64_t f_bfree; /* free blocks in filesystem */
int64_t f_bavail; /* free blocks avail to non-superuser */
uint64_t f_files; /* total file nodes in filesystem */
int64_t f_ffree; /* free nodes avail to non-superuser */
uint64_t f_syncwrites; /* count of sync writes since mount */
uint64_t f_asyncwrites; /* count of async writes since mount */
uint64_t f_syncreads; /* count of sync reads since mount */
uint64_t f_asyncreads; /* count of async reads since mount */
uint64_t f_spare[10]; /* unused spare */
uint32_t f_namemax; /* maximum filename length */
uint32_t f_owner; /* user that mounted the filesystem */
fsid_t f_fsid; /* filesystem id */
char f_charspare[80]; /* spare string space */
char f_fstypename[16]; /* filesystem type name */
char f_mntfromname[1024]; /* mounted filesystem */
char f_mntonname[1024]; /* directory on which mounted */
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_ */
| 1,729 | 35 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/rusage.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_INTERNAL_H_
#include "libc/calls/struct/rusage.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int __sys_getrusage(int, struct rusage *) _Hide;
int __sys_wait4(int, int *, int, struct rusage *) _Hide;
int sys_getrusage(int, struct rusage *) _Hide;
int sys_wait4(int, int *, int, struct rusage *) _Hide;
void __rusage2linux(struct rusage *) _Hide;
int sys_getrusage_nt(int, struct rusage *) _Hide;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_INTERNAL_H_ */
| 648 | 17 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/stat.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_INTERNAL_H_
#include "libc/calls/struct/stat.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int sys_fstat(int, struct stat *) _Hide;
int sys_fstatat(int, const char *, struct stat *, int) _Hide;
int sys_fstat_nt(int64_t, struct stat *) _Hide;
int sys_fstatat_nt(int, const char *, struct stat *, int) _Hide;
int sys_lstat_nt(const char *, struct stat *) _Hide;
int sys_fstat_metal(int, struct stat *);
const char *DescribeStat(char[300], int, const struct stat *);
#define DescribeStat(rc, st) DescribeStat(alloca(300), rc, st)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_INTERNAL_H_ */
| 804 | 21 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/rlimit.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct rlimit {
uint64_t rlim_cur; /* current (soft) limit in bytes */
uint64_t rlim_max; /* maximum limit in bytes */
};
int getrlimit(int, struct rlimit *);
int setrlimit(int, const struct rlimit *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_ */
| 488 | 17 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/bpf.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_BPF_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_BPF_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define BPF_MAXINSNS 4096
#define BPF_CLASS(code) ((code)&0x07)
#define BPF_LD 0x00 /* load into accumulator */
#define BPF_LDX 0x01 /* load into index register */
#define BPF_ST 0x02 /* store from immediate */
#define BPF_STX 0x03 /* store from register */
#define BPF_ALU 0x04 /* 32-bit arithmetic */
#define BPF_JMP 0x05
#define BPF_RET 0x06
#define BPF_MISC 0x07
#define BPF_SIZE(code) ((code)&0x18)
#define BPF_W 0x00 /* 32-bit */
#define BPF_H 0x08 /* 16-bit */
#define BPF_B 0x10 /* 8-bit */
#define BPF_DW 0x18 /* 64-bit (eBPF only) */
#define BPF_MODE(code) ((code)&0xe0)
#define BPF_IMM 0x00 /* 64-bit immediate */
#define BPF_ABS 0x20
#define BPF_IND 0x40
#define BPF_MEM 0x60
#define BPF_LEN 0x80
#define BPF_MSH 0xa0
#define BPF_OP(code) ((code)&0xf0)
#define BPF_ADD 0x00
#define BPF_SUB 0x10
#define BPF_MUL 0x20
#define BPF_DIV 0x30
#define BPF_OR 0x40
#define BPF_AND 0x50
#define BPF_LSH 0x60
#define BPF_RSH 0x70
#define BPF_NEG 0x80
#define BPF_MOD 0x90
#define BPF_XOR 0xa0
#define BPF_SRC(code) ((code)&0x08)
#define BPF_JA 0x00
#define BPF_JEQ 0x10
#define BPF_JGT 0x20
#define BPF_JGE 0x30
#define BPF_JSET 0x40
#define BPF_K 0x00
#define BPF_X 0x08
#define BPF_JMP32 0x06
#define BPF_ALU64 0x07
#define BPF_ATOMIC 0xc0
#define BPF_XADD 0xc0
#define BPF_MOV 0xb0
#define BPF_ARSH 0xc0
#define BPF_END 0xd0
#define BPF_TO_LE 0x00
#define BPF_TO_BE 0x08
#define BPF_FROM_LE BPF_TO_LE
#define BPF_FROM_BE BPF_TO_BE
#define BPF_JNE 0x50 /* != */
#define BPF_JLT 0xa0 /* unsigned < */
#define BPF_JLE 0xb0 /* unsigned <= */
#define BPF_JSGT 0x60 /* signed > */
#define BPF_JSGE 0x70 /* signed >= */
#define BPF_JSLT 0xc0 /* signed < */
#define BPF_JSLE 0xd0 /* signed <= */
#define BPF_CALL 0x80 /* call */
#define BPF_EXIT 0x90 /* ret */
#define BPF_FETCH 0x01
#define BPF_XCHG (0xe0 | BPF_FETCH)
#define BPF_CMPXCHG (0xf0 | BPF_FETCH)
#define MAX_BPF_REG __MAX_BPF_REG
#define BPF_REG_0 0
#define BPF_REG_1 1
#define BPF_REG_2 2
#define BPF_REG_3 3
#define BPF_REG_4 4
#define BPF_REG_5 5
#define BPF_REG_6 6
#define BPF_REG_7 7
#define BPF_REG_8 8
#define BPF_REG_9 9
#define BPF_REG_10 10
#define __MAX_BPF_REG 11
#define BPF_MAP_CREATE 0
#define BPF_MAP_LOOKUP_ELEM 1
#define BPF_MAP_UPDATE_ELEM 2
#define BPF_MAP_DELETE_ELEM 3
#define BPF_MAP_GET_NEXT_KEY 4
#define BPF_PROG_LOAD 5
#define BPF_OBJ_PIN 6
#define BPF_OBJ_GET 7
#define BPF_PROG_ATTACH 8
#define BPF_PROG_DETACH 9
#define BPF_PROG_TEST_RUN 10
#define BPF_PROG_GET_NEXT_ID 11
#define BPF_MAP_GET_NEXT_ID 12
#define BPF_PROG_GET_FD_BY_ID 13
#define BPF_MAP_GET_FD_BY_ID 14
#define BPF_OBJ_GET_INFO_BY_FD 15
#define BPF_PROG_QUERY 16
#define BPF_RAW_TRACEPOINT_OPEN 17
#define BPF_BTF_LOAD 18
#define BPF_BTF_GET_FD_BY_ID 19
#define BPF_TASK_FD_QUERY 20
#define BPF_MAP_LOOKUP_AND_DELETE_ELEM 21
#define BPF_MAP_FREEZE 22
#define BPF_BTF_GET_NEXT_ID 23
#define BPF_MAP_LOOKUP_BATCH 24
#define BPF_MAP_LOOKUP_AND_DELETE_BATCH 25
#define BPF_MAP_UPDATE_BATCH 26
#define BPF_MAP_DELETE_BATCH 27
#define BPF_LINK_CREATE 28
#define BPF_LINK_UPDATE 29
#define BPF_LINK_GET_FD_BY_ID 30
#define BPF_LINK_GET_NEXT_ID 31
#define BPF_ENABLE_STATS 32
#define BPF_ITER_CREATE 33
#define BPF_LINK_DETACH 34
#define BPF_PROG_BIND_MAP 35
#define BPF_PROG_RUN BPF_PROG_TEST_RUN
#define BPF_MAP_TYPE_UNSPEC 0
#define BPF_MAP_TYPE_HASH 1
#define BPF_MAP_TYPE_ARRAY 2
#define BPF_MAP_TYPE_PROG_ARRAY 3
#define BPF_MAP_TYPE_PERF_EVENT_ARRAY 4
#define BPF_MAP_TYPE_PERCPU_HASH 5
#define BPF_MAP_TYPE_PERCPU_ARRAY 6
#define BPF_MAP_TYPE_STACK_TRACE 7
#define BPF_MAP_TYPE_CGROUP_ARRAY 8
#define BPF_MAP_TYPE_LRU_HASH 9
#define BPF_MAP_TYPE_LRU_PERCPU_HASH 10
#define BPF_MAP_TYPE_LPM_TRIE 11
#define BPF_MAP_TYPE_ARRAY_OF_MAPS 12
#define BPF_MAP_TYPE_HASH_OF_MAPS 13
#define BPF_MAP_TYPE_DEVMAP 14
#define BPF_MAP_TYPE_SOCKMAP 15
#define BPF_MAP_TYPE_CPUMAP 16
#define BPF_MAP_TYPE_XSKMAP 17
#define BPF_MAP_TYPE_SOCKHASH 18
#define BPF_MAP_TYPE_CGROUP_STORAGE 19
#define BPF_MAP_TYPE_REUSEPORT_SOCKARRAY 20
#define BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE 21
#define BPF_MAP_TYPE_QUEUE 22
#define BPF_MAP_TYPE_STACK 23
#define BPF_MAP_TYPE_SK_STORAGE 24
#define BPF_MAP_TYPE_DEVMAP_HASH 25
#define BPF_MAP_TYPE_STRUCT_OPS 26
#define BPF_MAP_TYPE_RINGBUF 27
#define BPF_MAP_TYPE_INODE_STORAGE 28
#define BPF_MAP_TYPE_TASK_STORAGE 29
#define BPF_PROG_TYPE_UNSPEC 0
#define BPF_PROG_TYPE_SOCKET_FILTER 1
#define BPF_PROG_TYPE_KPROBE 2
#define BPF_PROG_TYPE_SCHED_CLS 3
#define BPF_PROG_TYPE_SCHED_ACT 4
#define BPF_PROG_TYPE_TRACEPOINT 5
#define BPF_PROG_TYPE_XDP 6
#define BPF_PROG_TYPE_PERF_EVENT 7
#define BPF_PROG_TYPE_CGROUP_SKB 8
#define BPF_PROG_TYPE_CGROUP_SOCK 9
#define BPF_PROG_TYPE_LWT_IN 10
#define BPF_PROG_TYPE_LWT_OUT 11
#define BPF_PROG_TYPE_LWT_XMIT 12
#define BPF_PROG_TYPE_SOCK_OPS 13
#define BPF_PROG_TYPE_SK_SKB 14
#define BPF_PROG_TYPE_CGROUP_DEVICE 15
#define BPF_PROG_TYPE_SK_MSG 16
#define BPF_PROG_TYPE_RAW_TRACEPOINT 17
#define BPF_PROG_TYPE_CGROUP_SOCK_ADDR 18
#define BPF_PROG_TYPE_LWT_SEG6LOCAL 19
#define BPF_PROG_TYPE_LIRC_MODE2 20
#define BPF_PROG_TYPE_SK_REUSEPORT 21
#define BPF_PROG_TYPE_FLOW_DISSECTOR 22
#define BPF_PROG_TYPE_CGROUP_SYSCTL 23
#define BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE 24
#define BPF_PROG_TYPE_CGROUP_SOCKOPT 25
#define BPF_PROG_TYPE_TRACING 26
#define BPF_PROG_TYPE_STRUCT_OPS 27
#define BPF_PROG_TYPE_EXT 28
#define BPF_PROG_TYPE_LSM 29
#define BPF_PROG_TYPE_SK_LOOKUP 30
#define BPF_PROG_TYPE_SYSCALL 31
#define BPF_CGROUP_INET_INGRESS 0
#define BPF_CGROUP_INET_EGRESS 1
#define BPF_CGROUP_INET_SOCK_CREATE 2
#define BPF_CGROUP_SOCK_OPS 3
#define BPF_SK_SKB_STREAM_PARSER 4
#define BPF_SK_SKB_STREAM_VERDICT 5
#define BPF_CGROUP_DEVICE 6
#define BPF_SK_MSG_VERDICT 7
#define BPF_CGROUP_INET4_BIND 8
#define BPF_CGROUP_INET6_BIND 9
#define BPF_CGROUP_INET4_CONNECT 10
#define BPF_CGROUP_INET6_CONNECT 11
#define BPF_CGROUP_INET4_POST_BIND 12
#define BPF_CGROUP_INET6_POST_BIND 13
#define BPF_CGROUP_UDP4_SENDMSG 14
#define BPF_CGROUP_UDP6_SENDMSG 15
#define BPF_LIRC_MODE2 16
#define BPF_FLOW_DISSECTOR 17
#define BPF_CGROUP_SYSCTL 18
#define BPF_CGROUP_UDP4_RECVMSG 19
#define BPF_CGROUP_UDP6_RECVMSG 20
#define BPF_CGROUP_GETSOCKOPT 21
#define BPF_CGROUP_SETSOCKOPT 22
#define BPF_TRACE_RAW_TP 23
#define BPF_TRACE_FENTRY 24
#define BPF_TRACE_FEXIT 25
#define BPF_MODIFY_RETURN 26
#define BPF_LSM_MAC 27
#define BPF_TRACE_ITER 28
#define BPF_CGROUP_INET4_GETPEERNAME 29
#define BPF_CGROUP_INET6_GETPEERNAME 30
#define BPF_CGROUP_INET4_GETSOCKNAME 31
#define BPF_CGROUP_INET6_GETSOCKNAME 32
#define BPF_XDP_DEVMAP 33
#define BPF_CGROUP_INET_SOCK_RELEASE 34
#define BPF_XDP_CPUMAP 35
#define BPF_SK_LOOKUP 36
#define BPF_XDP 37
#define BPF_SK_SKB_VERDICT 38
#define BPF_SK_REUSEPORT_SELECT 39
#define BPF_SK_REUSEPORT_SELECT_OR_MIGRATE 40
#define __MAX_BPF_ATTACH_TYPE 41
#define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
#define BPF_LINK_TYPE_UNSPEC 0
#define BPF_LINK_TYPE_RAW_TRACEPOINT 1
#define BPF_LINK_TYPE_TRACING 2
#define BPF_LINK_TYPE_CGROUP 3
#define BPF_LINK_TYPE_ITER 4
#define BPF_LINK_TYPE_NETNS 5
#define BPF_LINK_TYPE_XDP 6
#define MAX_BPF_LINK_TYPE 7
#define BPF_F_ALLOW_OVERRIDE (1U << 0)
#define BPF_F_ALLOW_MULTI (1U << 1)
#define BPF_F_REPLACE (1U << 2)
#define BPF_F_STRICT_ALIGNMENT (1U << 0)
#define BPF_F_ANY_ALIGNMENT (1U << 1)
#define BPF_F_TEST_RND_HI32 (1U << 2)
#define BPF_F_TEST_STATE_FREQ (1U << 3)
#define BPF_F_SLEEPABLE (1U << 4)
#define BPF_PSEUDO_MAP_FD 1
#define BPF_PSEUDO_MAP_IDX 5
#define BPF_PSEUDO_MAP_VALUE 2
#define BPF_PSEUDO_MAP_IDX_VALUE 6
#define BPF_PSEUDO_BTF_ID 3
#define BPF_PSEUDO_FUNC 4
#define BPF_PSEUDO_CALL 1
#define BPF_PSEUDO_KFUNC_CALL 2
#define BPF_ANY 0
#define BPF_NOEXIST 1
#define BPF_EXIST 2
#define BPF_F_LOCK 4
#define BPF_F_NO_PREALLOC (1U << 0)
#define BPF_F_NO_COMMON_LRU (1U << 1)
#define BPF_F_NUMA_NODE (1U << 2)
#define BPF_F_RDONLY (1U << 3)
#define BPF_F_WRONLY (1U << 4)
#define BPF_F_STACK_BUILD_ID (1U << 5)
#define BPF_F_ZERO_SEED (1U << 6)
#define BPF_F_RDONLY_PROG (1U << 7)
#define BPF_F_WRONLY_PROG (1U << 8)
#define BPF_F_CLONE (1U << 9)
#define BPF_F_MMAPABLE (1U << 10)
#define BPF_F_PRESERVE_ELEMS (1U << 11)
#define BPF_F_INNER_MAP (1U << 12)
#define BPF_F_QUERY_EFFECTIVE (1U << 0)
#define BPF_F_TEST_RUN_ON_CPU (1U << 0)
#define BPF_STATS_RUN_TIME 0
#define BPF_STACK_BUILD_ID_EMPTY 0
#define BPF_STACK_BUILD_ID_VALID 1
#define BPF_STACK_BUILD_ID_IP 2
#define BPF_BUILD_ID_SIZE 20
#define BPF_OBJ_NAME_LEN 16U
#define BPF_F_RECOMPUTE_CSUM (1ULL << 0)
#define BPF_F_INVALIDATE_HASH (1ULL << 1)
#define BPF_F_HDR_FIELD_MASK 0xfULL
#define BPF_F_PSEUDO_HDR (1ULL << 4)
#define BPF_F_MARK_MANGLED_0 (1ULL << 5)
#define BPF_F_MARK_ENFORCE (1ULL << 6)
#define BPF_F_INGRESS (1ULL << 0)
#define BPF_F_TUNINFO_IPV6 (1ULL << 0)
#define BPF_F_SKIP_FIELD_MASK 0xffULL
#define BPF_F_USER_STACK (1ULL << 8)
#define BPF_F_FAST_STACK_CMP (1ULL << 9)
#define BPF_F_REUSE_STACKID (1ULL << 10)
#define BPF_F_USER_BUILD_ID (1ULL << 11)
#define BPF_F_ZERO_CSUM_TX (1ULL << 1)
#define BPF_F_DONT_FRAGMENT (1ULL << 2)
#define BPF_F_SEQ_NUMBER (1ULL << 3)
#define BPF_F_INDEX_MASK 0xffffffffULL
#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
#define BPF_F_CTXLEN_MASK (0xfffffULL << 32)
#define BPF_F_CURRENT_NETNS (-1L)
#define BPF_CSUM_LEVEL_QUERY 0
#define BPF_CSUM_LEVEL_INC 1
#define BPF_CSUM_LEVEL_DEC 2
#define BPF_CSUM_LEVEL_RESET 3
#define BPF_F_ADJ_ROOM_FIXED_GSO (1ULL << 0)
#define BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 (1ULL << 1)
#define BPF_F_ADJ_ROOM_ENCAP_L3_IPV6 (1ULL << 2)
#define BPF_F_ADJ_ROOM_ENCAP_L4_GRE (1ULL << 3)
#define BPF_F_ADJ_ROOM_ENCAP_L4_UDP (1ULL << 4)
#define BPF_F_ADJ_ROOM_NO_CSUM_RESET (1ULL << 5)
#define BPF_F_ADJ_ROOM_ENCAP_L2_ETH (1ULL << 6)
#define BPF_ADJ_ROOM_ENCAP_L2_MASK 0xff
#define BPF_ADJ_ROOM_ENCAP_L2_SHIFT 56
#define BPF_F_ADJ_ROOM_ENCAP_L2(len) \
(((uint64_t)len & BPF_ADJ_ROOM_ENCAP_L2_MASK) << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
#define BPF_F_SYSCTL_BASE_NAME (1ULL << 0)
#define BPF_LOCAL_STORAGE_GET_F_CREATE (1ULL << 0)
#define BPF_SK_STORAGE_GET_F_CREATE BPF_LOCAL_STORAGE_GET_F_CREATE
#define BPF_F_GET_BRANCH_RECORDS_SIZE (1ULL << 0)
#define BPF_RB_NO_WAKEUP (1ULL << 0)
#define BPF_RB_FORCE_WAKEUP (1ULL << 1)
#define BPF_RB_AVAIL_DATA 0
#define BPF_RB_RING_SIZE 1
#define BPF_RB_CONS_POS 2
#define BPF_RB_PROD_POS 3
#define BPF_RINGBUF_BUSY_BIT (1U << 31)
#define BPF_RINGBUF_DISCARD_BIT (1U << 30)
#define BPF_RINGBUF_HDR_SZ 8
#define BPF_SK_LOOKUP_F_REPLACE (1ULL << 0)
#define BPF_SK_LOOKUP_F_NO_REUSEPORT (1ULL << 1)
#define BPF_ADJ_ROOM_NET 0
#define BPF_ADJ_ROOM_MAC 1
#define BPF_HDR_START_MAC 0
#define BPF_HDR_START_NET 1
#define BPF_LWT_ENCAP_SEG6 0
#define BPF_LWT_ENCAP_SEG6_INLINE 1
#define BPF_LWT_ENCAP_IP 2
#define BPF_F_BPRM_SECUREEXEC (1ULL << 0)
#define BPF_F_BROADCAST (1ULL << 3)
#define BPF_F_EXCLUDE_INGRESS (1ULL << 4)
#define XDP_PACKET_HEADROOM 256
#define BPF_TAG_SIZE 8
#define BPF_SOCK_OPS_RTO_CB_FLAG (1 << 0)
#define BPF_SOCK_OPS_RETRANS_CB_FLAG (1 << 1)
#define BPF_SOCK_OPS_STATE_CB_FLAG (1 << 2)
#define BPF_SOCK_OPS_RTT_CB_FLAG (1 << 3)
#define BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG (1 << 4)
#define BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG (1 << 5)
#define BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG (1 << 6)
#define BPF_SOCK_OPS_ALL_CB_FLAGS 0x7F
#define BPF_SOCK_OPS_VOID 0
#define BPF_SOCK_OPS_TIMEOUT_INIT 1
#define BPF_SOCK_OPS_RWND_INIT 2
#define BPF_SOCK_OPS_TCP_CONNECT_CB 3
#define BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB 4
#define BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB 5
#define BPF_SOCK_OPS_NEEDS_ECN 6
#define BPF_SOCK_OPS_BASE_RTT 7
#define BPF_SOCK_OPS_RTO_CB 8
#define BPF_SOCK_OPS_RETRANS_CB 9
#define BPF_SOCK_OPS_STATE_CB 10
#define BPF_SOCK_OPS_TCP_LISTEN_CB 11
#define BPF_SOCK_OPS_RTT_CB 12
#define BPF_SOCK_OPS_PARSE_HDR_OPT_CB 13
#define BPF_SOCK_OPS_HDR_OPT_LEN_CB 14
#define BPF_SOCK_OPS_WRITE_HDR_OPT_CB 15
#define BPF_TCP_ESTABLISHED 1
#define BPF_TCP_SYN_SENT 2
#define BPF_TCP_SYN_RECV 3
#define BPF_TCP_FIN_WAIT1 4
#define BPF_TCP_FIN_WAIT2 5
#define BPF_TCP_TIME_WAIT 6
#define BPF_TCP_CLOSE 7
#define BPF_TCP_CLOSE_WAIT 8
#define BPF_TCP_LAST_ACK 9
#define BPF_TCP_LISTEN 10
#define BPF_TCP_CLOSING 11
#define BPF_TCP_NEW_SYN_RECV 12
#define BPF_TCP_MAX_STATES 13
#define TCP_BPF_IW 1001
#define TCP_BPF_SNDCWND_CLAMP 1002
#define TCP_BPF_DELACK_MAX 1003
#define TCP_BPF_RTO_MIN 1004
#define TCP_BPF_SYN 1005
#define TCP_BPF_SYN_IP 1006
#define TCP_BPF_SYN_MAC 1007
#define BPF_LOAD_HDR_OPT_TCP_SYN (1ULL << 0)
#define BPF_WRITE_HDR_TCP_CURRENT_MSS 1
#define BPF_WRITE_HDR_TCP_SYNACK_COOKIE 2
#define BPF_DEVCG_ACC_MKNOD (1ULL << 0)
#define BPF_DEVCG_ACC_READ (1ULL << 1)
#define BPF_DEVCG_ACC_WRITE (1ULL << 2)
#define BPF_DEVCG_DEV_BLOCK (1ULL << 0)
#define BPF_DEVCG_DEV_CHAR (1ULL << 1)
#define BPF_FIB_LOOKUP_DIRECT (1U << 0)
#define BPF_FIB_LOOKUP_OUTPUT (1U << 1)
#define BPF_FIB_LKUP_RET_SUCCESS 0
#define BPF_FIB_LKUP_RET_BLACKHOLE 1
#define BPF_FIB_LKUP_RET_UNREACHABLE 2
#define BPF_FIB_LKUP_RET_PROHIBIT 3
#define BPF_FIB_LKUP_RET_NOT_FWDED 4
#define BPF_FIB_LKUP_RET_FWD_DISABLED 5
#define BPF_FIB_LKUP_RET_UNSUPP_LWT 6
#define BPF_FIB_LKUP_RET_NO_NEIGH 7
#define BPF_FIB_LKUP_RET_FRAG_NEEDED 8
#define BPF_MTU_CHK_SEGS (1U << 0)
#define BPF_MTU_CHK_RET_SUCCESS 0
#define BPF_MTU_CHK_RET_FRAG_NEEDED 1
#define BPF_MTU_CHK_RET_SEGS_TOOBIG 2
#define BPF_FD_TYPE_RAW_TRACEPOINT 0
#define BPF_FD_TYPE_TRACEPOINT 1
#define BPF_FD_TYPE_KPROBE 2
#define BPF_FD_TYPE_KRETPROBE 3
#define BPF_FD_TYPE_UPROBE 4
#define BPF_FD_TYPE_URETPROBE 5
#define BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG (1U << 0)
#define BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL (1U << 1)
#define BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP (1U << 2)
#define BPF_LINE_INFO_LINE_NUM(line_col) ((line_col) >> 10)
#define BPF_LINE_INFO_LINE_COL(line_col) ((line_col)&0x3ff)
#define BTF_F_COMPACT (1ULL << 0)
#define BTF_F_NONAME (1ULL << 1)
#define BTF_F_PTR_RAW (1ULL << 2)
#define BTF_F_ZERO (1ULL << 3)
#define BPF_OK 0
#define BPF_DROP 2
#define BPF_REDIRECT 7
#define BPF_LWT_REROUTE 128
#define BPF_FUNC_unspec 0
#define BPF_FUNC_map_lookup_elem 1
#define BPF_FUNC_map_update_elem 2
#define BPF_FUNC_map_delete_elem 3
#define BPF_FUNC_probe_read 4
#define BPF_FUNC_ktime_get_ns 5
#define BPF_FUNC_trace_printk 6
#define BPF_FUNC_get_prandom_u32 7
#define BPF_FUNC_get_smp_processor_id 8
#define BPF_FUNC_skb_store_bytes 9
#define BPF_FUNC_l3_csum_replace 10
#define BPF_FUNC_l4_csum_replace 11
#define BPF_FUNC_tail_call 12
#define BPF_FUNC_clone_redirect 13
#define BPF_FUNC_get_current_pid_tgid 14
#define BPF_FUNC_get_current_uid_gid 15
#define BPF_FUNC_get_current_comm 16
#define BPF_FUNC_get_cgroup_classid 17
#define BPF_FUNC_skb_vlan_push 18
#define BPF_FUNC_skb_vlan_pop 19
#define BPF_FUNC_skb_get_tunnel_key 20
#define BPF_FUNC_skb_set_tunnel_key 21
#define BPF_FUNC_perf_event_read 22
#define BPF_FUNC_redirect 23
#define BPF_FUNC_get_route_realm 24
#define BPF_FUNC_perf_event_output 25
#define BPF_FUNC_skb_load_bytes 26
#define BPF_FUNC_get_stackid 27
#define BPF_FUNC_csum_diff 28
#define BPF_FUNC_skb_get_tunnel_opt 29
#define BPF_FUNC_skb_set_tunnel_opt 30
#define BPF_FUNC_skb_change_proto 31
#define BPF_FUNC_skb_change_type 32
#define BPF_FUNC_skb_under_cgroup 33
#define BPF_FUNC_get_hash_recalc 34
#define BPF_FUNC_get_current_task 35
#define BPF_FUNC_probe_write_user 36
#define BPF_FUNC_current_task_under_cgroup 37
#define BPF_FUNC_skb_change_tail 38
#define BPF_FUNC_skb_pull_data 39
#define BPF_FUNC_csum_update 40
#define BPF_FUNC_set_hash_invalid 41
#define BPF_FUNC_get_numa_node_id 42
#define BPF_FUNC_skb_change_head 43
#define BPF_FUNC_xdp_adjust_head 44
#define BPF_FUNC_probe_read_str 45
#define BPF_FUNC_get_socket_cookie 46
#define BPF_FUNC_get_socket_uid 47
#define BPF_FUNC_set_hash 48
#define BPF_FUNC_setsockopt 49
#define BPF_FUNC_skb_adjust_room 50
#define BPF_FUNC_redirect_map 51
#define BPF_FUNC_sk_redirect_map 52
#define BPF_FUNC_sock_map_update 53
#define BPF_FUNC_xdp_adjust_meta 54
#define BPF_FUNC_perf_event_read_value 55
#define BPF_FUNC_perf_prog_read_value 56
#define BPF_FUNC_getsockopt 57
#define BPF_FUNC_override_return 58
#define BPF_FUNC_sock_ops_cb_flags_set 59
#define BPF_FUNC_msg_redirect_map 60
#define BPF_FUNC_msg_apply_bytes 61
#define BPF_FUNC_msg_cork_bytes 62
#define BPF_FUNC_msg_pull_data 63
#define BPF_FUNC_bind 64
#define BPF_FUNC_xdp_adjust_tail 65
#define BPF_FUNC_skb_get_xfrm_state 66
#define BPF_FUNC_get_stack 67
#define BPF_FUNC_skb_load_bytes_relative 68
#define BPF_FUNC_fib_lookup 69
#define BPF_FUNC_sock_hash_update 70
#define BPF_FUNC_msg_redirect_hash 71
#define BPF_FUNC_sk_redirect_hash 72
#define BPF_FUNC_lwt_push_encap 73
#define BPF_FUNC_lwt_seg6_store_bytes 74
#define BPF_FUNC_lwt_seg6_adjust_srh 75
#define BPF_FUNC_lwt_seg6_action 76
#define BPF_FUNC_rc_repeat 77
#define BPF_FUNC_rc_keydown 78
#define BPF_FUNC_skb_cgroup_id 79
#define BPF_FUNC_get_current_cgroup_id 80
#define BPF_FUNC_get_local_storage 81
#define BPF_FUNC_sk_select_reuseport 82
#define BPF_FUNC_skb_ancestor_cgroup_id 83
#define BPF_FUNC_sk_lookup_tcp 84
#define BPF_FUNC_sk_lookup_udp 85
#define BPF_FUNC_sk_release 86
#define BPF_FUNC_map_push_elem 87
#define BPF_FUNC_map_pop_elem 88
#define BPF_FUNC_map_peek_elem 89
#define BPF_FUNC_msg_push_data 90
#define BPF_FUNC_msg_pop_data 91
#define BPF_FUNC_rc_pointer_rel 92
#define BPF_FUNC_spin_lock 93
#define BPF_FUNC_spin_unlock 94
#define BPF_FUNC_sk_fullsock 95
#define BPF_FUNC_tcp_sock 96
#define BPF_FUNC_skb_ecn_set_ce 97
#define BPF_FUNC_get_listener_sock 98
#define BPF_FUNC_skc_lookup_tcp 99
#define BPF_FUNC_tcp_check_syncookie 100
#define BPF_FUNC_sysctl_get_name 101
#define BPF_FUNC_sysctl_get_current_value 102
#define BPF_FUNC_sysctl_get_new_value 103
#define BPF_FUNC_sysctl_set_new_value 104
#define BPF_FUNC_strtol 105
#define BPF_FUNC_strtoul 106
#define BPF_FUNC_sk_storage_get 107
#define BPF_FUNC_sk_storage_delete 108
#define BPF_FUNC_send_signal 109
#define BPF_FUNC_tcp_gen_syncookie 110
#define BPF_FUNC_skb_output 111
#define BPF_FUNC_probe_read_user 112
#define BPF_FUNC_probe_read_kernel 113
#define BPF_FUNC_probe_read_user_str 114
#define BPF_FUNC_probe_read_kernel_str 115
#define BPF_FUNC_tcp_send_ack 116
#define BPF_FUNC_send_signal_thread 117
#define BPF_FUNC_jiffies64 118
#define BPF_FUNC_read_branch_records 119
#define BPF_FUNC_get_ns_current_pid_tgid 120
#define BPF_FUNC_xdp_output 121
#define BPF_FUNC_get_netns_cookie 122
#define BPF_FUNC_get_current_ancestor_cgroup_id 123
#define BPF_FUNC_sk_assign 124
#define BPF_FUNC_ktime_get_boot_ns 125
#define BPF_FUNC_seq_printf 126
#define BPF_FUNC_seq_write 127
#define BPF_FUNC_sk_cgroup_id 128
#define BPF_FUNC_sk_ancestor_cgroup_id 129
#define BPF_FUNC_ringbuf_output 130
#define BPF_FUNC_ringbuf_reserve 131
#define BPF_FUNC_ringbuf_submit 132
#define BPF_FUNC_ringbuf_discard 133
#define BPF_FUNC_ringbuf_query 134
#define BPF_FUNC_csum_level 135
#define BPF_FUNC_skc_to_tcp6_sock 136
#define BPF_FUNC_skc_to_tcp_sock 137
#define BPF_FUNC_skc_to_tcp_timewait_sock 138
#define BPF_FUNC_skc_to_tcp_request_sock 139
#define BPF_FUNC_skc_to_udp6_sock 140
#define BPF_FUNC_get_task_stack 141
#define BPF_FUNC_load_hdr_opt 142
#define BPF_FUNC_store_hdr_opt 143
#define BPF_FUNC_reserve_hdr_opt 144
#define BPF_FUNC_inode_storage_get 145
#define BPF_FUNC_inode_storage_delete 146
#define BPF_FUNC_d_path 147
#define BPF_FUNC_copy_from_user 148
#define BPF_FUNC_snprintf_btf 149
#define BPF_FUNC_seq_printf_btf 150
#define BPF_FUNC_skb_cgroup_classid 151
#define BPF_FUNC_redirect_neigh 152
#define BPF_FUNC_per_cpu_ptr 153
#define BPF_FUNC_this_cpu_ptr 154
#define BPF_FUNC_redirect_peer 155
#define BPF_FUNC_task_storage_get 156
#define BPF_FUNC_task_storage_delete 157
#define BPF_FUNC_get_current_task_btf 158
#define BPF_FUNC_bprm_opts_set 159
#define BPF_FUNC_ktime_get_coarse_ns 160
#define BPF_FUNC_ima_inode_hash 161
#define BPF_FUNC_sock_from_file 162
#define BPF_FUNC_check_mtu 163
#define BPF_FUNC_for_each_map_elem 164
#define BPF_FUNC_snprintf 165
#define BPF_FUNC_sys_bpf 166
#define BPF_FUNC_btf_find_by_name_kind 167
#define BPF_FUNC_sys_close 168
#define __BPF_FUNC_MAX_ID 169
#define __bpf_md_ptr(type, name) \
union { \
type name; \
uint64_t : 64; \
} forcealign(8)
struct bpf_insn {
uint8_t code;
uint8_t dst_reg : 4;
uint8_t src_reg : 4;
int16_t off;
int32_t imm;
};
struct bpf_lpm_trie_key {
uint32_t prefixlen;
uint8_t data[0];
};
struct bpf_cgroup_storage_key {
uint64_t cgroup_inode_id;
uint32_t attach_type;
};
union bpf_iter_link_info {
struct {
uint32_t map_fd;
} map;
};
struct bpf_stack_build_id {
int32_t status;
unsigned char build_id[BPF_BUILD_ID_SIZE];
union {
uint64_t offset;
uint64_t ip;
};
};
union bpf_attr {
struct {
uint32_t map_type;
uint32_t key_size;
uint32_t value_size;
uint32_t max_entries;
uint32_t map_flags;
uint32_t inner_map_fd;
uint32_t numa_node;
char map_name[BPF_OBJ_NAME_LEN];
uint32_t map_ifindex;
uint32_t btf_fd;
uint32_t btf_key_type_id;
uint32_t btf_value_type_id;
uint32_t btf_vmlinux_value_type_id;
};
struct {
uint32_t map_fd;
uint64_t key;
union {
uint64_t value;
uint64_t next_key;
};
uint64_t flags;
};
struct {
uint64_t in_batch;
uint64_t out_batch;
uint64_t keys;
uint64_t values;
uint32_t count;
uint32_t map_fd;
uint64_t elem_flags;
uint64_t flags;
} batch;
struct {
uint32_t prog_type;
uint32_t insn_cnt;
uint64_t insns;
uint64_t license;
uint32_t log_level;
uint32_t log_size;
uint64_t log_buf;
uint32_t kern_version;
uint32_t prog_flags;
char prog_name[BPF_OBJ_NAME_LEN];
uint32_t prog_ifindex;
uint32_t expected_attach_type;
uint32_t prog_btf_fd;
uint32_t func_info_rec_size;
uint64_t func_info;
uint32_t func_info_cnt;
uint32_t line_info_rec_size;
uint64_t line_info;
uint32_t line_info_cnt;
uint32_t attach_btf_id;
union {
uint32_t attach_prog_fd;
uint32_t attach_btf_obj_fd;
};
uint32_t : 32;
uint64_t fd_array;
};
struct {
uint64_t pathname;
uint32_t bpf_fd;
uint32_t file_flags;
};
struct {
uint32_t target_fd;
uint32_t attach_bpf_fd;
uint32_t attach_type;
uint32_t attach_flags;
uint32_t replace_bpf_fd;
};
struct {
uint32_t prog_fd;
uint32_t retval;
uint32_t data_size_in;
uint32_t data_size_out;
uint64_t data_in;
uint64_t data_out;
uint32_t repeat;
uint32_t duration;
uint32_t ctx_size_in;
uint32_t ctx_size_out;
uint64_t ctx_in;
uint64_t ctx_out;
uint32_t flags;
uint32_t cpu;
} test;
struct {
union {
uint32_t start_id;
uint32_t prog_id;
uint32_t map_id;
uint32_t btf_id;
uint32_t link_id;
};
uint32_t next_id;
uint32_t open_flags;
};
struct {
uint32_t bpf_fd;
uint32_t info_len;
uint64_t info;
} info;
struct {
uint32_t target_fd;
uint32_t attach_type;
uint32_t query_flags;
uint32_t attach_flags;
uint64_t prog_ids;
uint32_t prog_cnt;
} query;
struct {
uint64_t name;
uint32_t prog_fd;
} raw_tracepoint;
struct {
uint64_t btf;
uint64_t btf_log_buf;
uint32_t btf_size;
uint32_t btf_log_size;
uint32_t btf_log_level;
};
struct {
uint32_t pid;
uint32_t fd;
uint32_t flags;
uint32_t buf_len;
uint64_t buf;
uint32_t prog_id;
uint32_t fd_type;
uint64_t probe_offset;
uint64_t probe_addr;
} task_fd_query;
struct {
uint32_t prog_fd;
union {
uint32_t target_fd;
uint32_t target_ifindex;
};
uint32_t attach_type;
uint32_t flags;
union {
uint32_t target_btf_id;
struct {
uint64_t iter_info;
uint32_t iter_info_len;
};
};
} link_create;
struct {
uint32_t link_fd;
uint32_t new_prog_fd;
uint32_t flags;
uint32_t old_prog_fd;
} link_update;
struct {
uint32_t link_fd;
} link_detach;
struct {
uint32_t type;
} enable_stats;
struct {
uint32_t link_fd;
uint32_t flags;
} iter_create;
struct {
uint32_t prog_fd;
uint32_t map_fd;
uint32_t flags;
} prog_bind_map;
} forcealign(8);
struct __sk_buff {
uint32_t len;
uint32_t pkt_type;
uint32_t mark;
uint32_t queue_mapping;
uint32_t protocol;
uint32_t vlan_present;
uint32_t vlan_tci;
uint32_t vlan_proto;
uint32_t priority;
uint32_t ingress_ifindex;
uint32_t ifindex;
uint32_t tc_index;
uint32_t cb[5];
uint32_t hash;
uint32_t tc_classid;
uint32_t data;
uint32_t data_end;
uint32_t napi_id;
uint32_t family;
uint32_t remote_ip4;
uint32_t local_ip4;
uint32_t remote_ip6[4];
uint32_t local_ip6[4];
uint32_t remote_port;
uint32_t local_port;
uint32_t data_meta;
__bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
uint64_t tstamp;
uint32_t wire_len;
uint32_t gso_segs;
__bpf_md_ptr(struct bpf_sock *, sk);
uint32_t gso_size;
};
struct bpf_tunnel_key {
uint32_t tunnel_id;
union {
uint32_t remote_ipv4;
uint32_t remote_ipv6[4];
};
uint8_t tunnel_tos;
uint8_t tunnel_ttl;
uint16_t tunnel_ext;
uint32_t tunnel_label;
};
struct bpf_xfrm_state {
uint32_t reqid;
uint32_t spi;
uint16_t family;
uint16_t ext;
union {
uint32_t remote_ipv4;
uint32_t remote_ipv6[4];
};
};
struct bpf_sock {
uint32_t bound_dev_if;
uint32_t family;
uint32_t type;
uint32_t protocol;
uint32_t mark;
uint32_t priority;
uint32_t src_ip4;
uint32_t src_ip6[4];
uint32_t src_port;
uint32_t dst_port;
uint32_t dst_ip4;
uint32_t dst_ip6[4];
uint32_t state;
int32_t rx_queue_mapping;
};
struct bpf_tcp_sock {
uint32_t snd_cwnd;
uint32_t srtt_us;
uint32_t rtt_min;
uint32_t snd_ssthresh;
uint32_t rcv_nxt;
uint32_t snd_nxt;
uint32_t snd_una;
uint32_t mss_cache;
uint32_t ecn_flags;
uint32_t rate_delivered;
uint32_t rate_interval_us;
uint32_t packets_out;
uint32_t retrans_out;
uint32_t total_retrans;
uint32_t segs_in;
uint32_t data_segs_in;
uint32_t segs_out;
uint32_t data_segs_out;
uint32_t lost_out;
uint32_t sacked_out;
uint64_t bytes_received;
uint64_t bytes_acked;
uint32_t dsack_dups;
uint32_t delivered;
uint32_t delivered_ce;
uint32_t icsk_retransmits;
};
struct bpf_sock_tuple {
union {
struct {
uint32_t saddr; /* big endian */
uint32_t daddr; /* big endian */
uint16_t sport; /* big endian */
uint16_t dport; /* big endian */
} ipv4;
struct {
uint32_t saddr[4]; /* big endian */
uint32_t daddr[4]; /* big endian */
uint16_t sport; /* big endian */
uint16_t dport; /* big endian */
} ipv6;
};
};
struct bpf_xdp_sock {
uint32_t queue_id;
};
enum xdp_action {
XDP_ABORTED = 0,
XDP_DROP,
XDP_PASS,
XDP_TX,
XDP_REDIRECT,
};
struct xdp_md {
uint32_t data;
uint32_t data_end;
uint32_t data_meta;
uint32_t ingress_ifindex;
uint32_t rx_queue_index;
uint32_t egress_ifindex;
};
struct bpf_devmap_val {
uint32_t ifindex;
union {
int fd;
uint32_t id;
} bpf_prog;
};
struct bpf_cpumap_val {
uint32_t qsize;
union {
int fd;
uint32_t id;
} bpf_prog;
};
enum sk_action {
SK_DROP = 0,
SK_PASS,
};
struct sk_msg_md {
__bpf_md_ptr(void *, data);
__bpf_md_ptr(void *, data_end);
uint32_t family;
uint32_t remote_ip4;
uint32_t local_ip4;
uint32_t remote_ip6[4];
uint32_t local_ip6[4];
uint32_t remote_port;
uint32_t local_port;
uint32_t size;
__bpf_md_ptr(struct bpf_sock *, sk);
};
struct sk_reuseport_md {
__bpf_md_ptr(void *, data);
__bpf_md_ptr(void *, data_end);
uint32_t len;
uint32_t eth_protocol;
uint32_t ip_protocol;
uint32_t bind_inany;
uint32_t hash;
__bpf_md_ptr(struct bpf_sock *, sk);
__bpf_md_ptr(struct bpf_sock *, migrating_sk);
};
struct bpf_prog_info {
uint32_t type;
uint32_t id;
uint8_t tag[BPF_TAG_SIZE];
uint32_t jited_prog_len;
uint32_t xlated_prog_len;
uint64_t jited_prog_insns;
uint64_t xlated_prog_insns;
uint64_t load_time;
uint32_t created_by_uid;
uint32_t nr_map_ids;
uint64_t map_ids;
char name[BPF_OBJ_NAME_LEN];
uint32_t ifindex;
uint32_t gpl_compatible : 1;
uint32_t : 31;
uint64_t netns_dev;
uint64_t netns_ino;
uint32_t nr_jited_ksyms;
uint32_t nr_jited_func_lens;
uint64_t jited_ksyms;
uint64_t jited_func_lens;
uint32_t btf_id;
uint32_t func_info_rec_size;
uint64_t func_info;
uint32_t nr_func_info;
uint32_t nr_line_info;
uint64_t line_info;
uint64_t jited_line_info;
uint32_t nr_jited_line_info;
uint32_t line_info_rec_size;
uint32_t jited_line_info_rec_size;
uint32_t nr_prog_tags;
uint64_t prog_tags;
uint64_t run_time_ns;
uint64_t run_cnt;
uint64_t recursion_misses;
} forcealign(8);
struct bpf_map_info {
uint32_t type;
uint32_t id;
uint32_t key_size;
uint32_t value_size;
uint32_t max_entries;
uint32_t map_flags;
char name[BPF_OBJ_NAME_LEN];
uint32_t ifindex;
uint32_t btf_vmlinux_value_type_id;
uint64_t netns_dev;
uint64_t netns_ino;
uint32_t btf_id;
uint32_t btf_key_type_id;
uint32_t btf_value_type_id;
} forcealign(8);
struct bpf_btf_info {
uint64_t btf;
uint32_t btf_size;
uint32_t id;
uint64_t name;
uint32_t name_len;
uint32_t kernel_btf;
} forcealign(8);
struct bpf_link_info {
uint32_t type;
uint32_t id;
uint32_t prog_id;
union {
struct {
uint64_t tp_name;
uint32_t tp_name_len;
} raw_tracepoint;
struct {
uint32_t attach_type;
uint32_t target_obj_id;
uint32_t target_btf_id;
} tracing;
struct {
uint64_t cgroup_id;
uint32_t attach_type;
} cgroup;
struct {
uint64_t target_name;
uint32_t target_name_len;
union {
struct {
uint32_t map_id;
} map;
};
} iter;
struct {
uint32_t netns_ino;
uint32_t attach_type;
} netns;
struct {
uint32_t ifindex;
} xdp;
};
} forcealign(8);
struct bpf_sock_addr {
uint32_t user_family;
uint32_t user_ip4;
uint32_t user_ip6[4];
uint32_t user_port;
uint32_t family;
uint32_t type;
uint32_t protocol;
uint32_t msg_src_ip4;
uint32_t msg_src_ip6[4];
__bpf_md_ptr(struct bpf_sock *, sk);
};
struct bpf_sock_ops {
uint32_t op;
union {
uint32_t args[4];
uint32_t reply;
uint32_t replylong[4];
};
uint32_t family;
uint32_t remote_ip4;
uint32_t local_ip4;
uint32_t remote_ip6[4];
uint32_t local_ip6[4];
uint32_t remote_port;
uint32_t local_port;
uint32_t is_fullsock;
uint32_t snd_cwnd;
uint32_t srtt_us;
uint32_t bpf_sock_ops_cb_flags;
uint32_t state;
uint32_t rtt_min;
uint32_t snd_ssthresh;
uint32_t rcv_nxt;
uint32_t snd_nxt;
uint32_t snd_una;
uint32_t mss_cache;
uint32_t ecn_flags;
uint32_t rate_delivered;
uint32_t rate_interval_us;
uint32_t packets_out;
uint32_t retrans_out;
uint32_t total_retrans;
uint32_t segs_in;
uint32_t data_segs_in;
uint32_t segs_out;
uint32_t data_segs_out;
uint32_t lost_out;
uint32_t sacked_out;
uint32_t sk_txhash;
uint64_t bytes_received;
uint64_t bytes_acked;
__bpf_md_ptr(struct bpf_sock *, sk);
__bpf_md_ptr(void *, skb_data);
__bpf_md_ptr(void *, skb_data_end);
uint32_t skb_len;
uint32_t skb_tcp_flags;
};
struct bpf_perf_event_value {
uint64_t counter;
uint64_t enabled;
uint64_t running;
};
struct bpf_cgroup_dev_ctx {
uint32_t access_type;
uint32_t major;
uint32_t minor;
};
struct bpf_raw_tracepoint_args {
uint64_t args[0];
};
struct bpf_fib_lookup {
uint8_t family;
uint8_t l4_protocol;
uint16_t sport; /* big endian */
uint16_t dport; /* big endian */
union {
uint16_t tot_len;
uint16_t mtu_result;
};
uint32_t ifindex;
union {
uint8_t tos;
uint32_t flowinfo; /* big endian */
uint32_t rt_metric;
};
union {
uint32_t ipv4_src; /* big endian */
uint32_t ipv6_src[4];
};
union {
uint32_t ipv4_dst; /* big endian */
uint32_t ipv6_dst[4];
};
uint16_t h_vlan_proto; /* big endian */
uint16_t h_vlan_TCI; /* big endian */
uint8_t smac[6];
uint8_t dmac[6];
};
struct bpf_redir_neigh {
uint32_t nh_family;
union {
uint32_t ipv4_nh; /* big endian */
uint32_t ipv6_nh[4];
};
};
struct bpf_flow_keys {
uint16_t nhoff;
uint16_t thoff;
uint16_t addr_proto;
uint8_t is_frag;
uint8_t is_first_frag;
uint8_t is_encap;
uint8_t ip_proto;
uint16_t n_proto; /* big endian */
uint16_t sport; /* big endian */
uint16_t dport; /* big endian */
union {
struct {
uint32_t ipv4_src; /* big endian */
uint32_t ipv4_dst; /* big endian */
};
struct {
uint32_t ipv6_src[4];
uint32_t ipv6_dst[4];
};
};
uint32_t flags;
uint32_t flow_label;
};
struct bpf_func_info {
uint32_t insn_off;
uint32_t type_id;
};
struct bpf_line_info {
uint32_t insn_off;
uint32_t file_name_off;
uint32_t line_off;
uint32_t line_col;
};
struct bpf_spin_lock {
uint32_t val;
};
struct bpf_sysctl {
uint32_t write_;
uint32_t file_pos;
};
struct bpf_sockopt {
__bpf_md_ptr(struct bpf_sock *, sk);
__bpf_md_ptr(void *, optval);
__bpf_md_ptr(void *, optval_end);
int32_t level;
int32_t optname;
int32_t optlen;
int32_t retval;
};
struct bpf_pidns_info {
uint32_t pid;
uint32_t tgid;
};
struct bpf_sk_lookup {
union {
__bpf_md_ptr(struct bpf_sock *, sk);
uint64_t cookie;
};
uint32_t family;
uint32_t protocol;
uint32_t remote_ip4;
uint32_t remote_ip6[4];
uint32_t remote_port;
uint32_t local_ip4;
uint32_t local_ip6[4];
uint32_t local_port;
};
struct btf_ptr {
void *ptr;
uint32_t type_id;
uint32_t flags;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_BPF_H_ */
| 40,095 | 1,333 | jart/cosmopolitan | false |
cosmopolitan/libc/calls/struct/sigset.internal.h | #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_INTERNAL_H_
#include "libc/calls/struct/sigset.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int __sys_sigprocmask(int, const struct sigset *, struct sigset *,
uint64_t) _Hide;
int sys_sigprocmask(int, const struct sigset *, struct sigset *) _Hide;
int sys_sigsuspend(const struct sigset *, uint64_t) _Hide;
int sys_sigpending(struct sigset *, size_t) _Hide;
const char *DescribeSigset(char[128], int, const sigset_t *);
#define DescribeSigset(rc, ss) DescribeSigset(alloca(128), rc, ss)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_INTERNAL_H_ */
| 793 | 20 | jart/cosmopolitan | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.