diff --git a/ape/ape.lds b/ape/ape.lds index 78b871bca..7f27a43d9 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -401,6 +401,7 @@ SECTIONS { /*BEGIN: NT FORK COPYING */ KEEP(*(.dataprologue)) *(.data .data.*) + *(.PyRuntime) /* for python */ *(.subrs) /* for emacs */ KEEP(*(SORT_BY_NAME(.sort.data.*))) . += . > 0 ? CODE_GRANULE : 0; diff --git a/libc/isystem/netinet/in.h b/libc/isystem/netinet/in.h index db7800149..85941618c 100644 --- a/libc/isystem/netinet/in.h +++ b/libc/isystem/netinet/in.h @@ -5,6 +5,7 @@ #include "libc/sock/struct/ip_mreq.h" #include "libc/sock/struct/sockaddr.h" #include "libc/sock/struct/sockaddr6.h" +#include "libc/sysv/consts/in.h" #include "libc/sysv/consts/inaddr.h" #include "libc/sysv/consts/inet6.h" #include "libc/sysv/consts/ip.h" diff --git a/libc/isystem/sys/syscall.h b/libc/isystem/sys/syscall.h index 8e5bce628..9a508f8c4 100644 --- a/libc/isystem/sys/syscall.h +++ b/libc/isystem/sys/syscall.h @@ -1,4 +1,4 @@ #ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYSCALL_H_ #define COSMOPOLITAN_LIBC_ISYSTEM_SYSCALL_H_ -#include "libc/calls/calls.h" +#include "libc/stdio/syscall.h" #endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYSCALL_H_ */ diff --git a/libc/isystem/sys/xattr.h b/libc/isystem/sys/xattr.h deleted file mode 100644 index 982b490a2..000000000 --- a/libc/isystem/sys/xattr.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYS_XATTR_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_SYS_XATTR_H_ -#include "libc/calls/xattr.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_XATTR_H_ */ diff --git a/libc/stdio/syscall.c b/libc/stdio/syscall.c new file mode 100644 index 000000000..7bee0f8ff --- /dev/null +++ b/libc/stdio/syscall.c @@ -0,0 +1,49 @@ +/*-*- 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/stdio/syscall.h" +#include "libc/calls/calls.h" +#include "libc/errno.h" +#include "libc/stdio/rand.h" + +/** + * Translation layer for some Linux system calls: + * + * - `SYS_gettid` + * - `SYS_getrandom` + * + * @return negative errno on error + */ +long syscall(long number, ...) { + switch (number) { + default: + return -ENOSYS; + case SYS_gettid: + return gettid(); + case SYS_getrandom: { + va_list va; + va_start(va, number); + void *buf = va_arg(va, void *); + size_t buflen = va_arg(va, size_t); + unsigned flags = va_arg(va, unsigned); + va_end(va); + ssize_t rc = getrandom(buf, buflen, flags); + return rc == -1 ? -errno : rc; + } + } +} diff --git a/libc/stdio/syscall.h b/libc/stdio/syscall.h new file mode 100644 index 000000000..7e0043ff9 --- /dev/null +++ b/libc/stdio/syscall.h @@ -0,0 +1,13 @@ +#ifndef COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_ +#define COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +#define SYS_gettid 186 +#define SYS_getrandom 318 + +long syscall(long, ...); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_ */ diff --git a/libc/sysv/consts/fio.h b/libc/sysv/consts/fio.h index e7fe4c9e1..69e03e15b 100644 --- a/libc/sysv/consts/fio.h +++ b/libc/sysv/consts/fio.h @@ -9,13 +9,18 @@ extern const uint32_t FIONBIO; extern const uint32_t FIONCLEX; extern const uint32_t FIONREAD; -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ - #define FIOASYNC FIOASYNC #define FIOCLEX FIOCLEX #define FIONBIO FIONBIO #define FIONCLEX FIONCLEX #define FIONREAD FIONREAD +#define __tmpcosmo_FIOASYNC -484047213 +#define __tmpcosmo_FIOCLEX -1198942590 +#define __tmpcosmo_FIONBIO 2035363853 +#define __tmpcosmo_FIONCLEX -25760400 +#define __tmpcosmo_FIONREAD 1333957726 + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_FIO_H_ */ diff --git a/libc/sysv/consts/in.h b/libc/sysv/consts/in.h index c43ccff39..2666a7f24 100644 --- a/libc/sysv/consts/in.h +++ b/libc/sysv/consts/in.h @@ -27,5 +27,6 @@ #define IN_OPEN 0x20 #define IN_Q_OVERFLOW 0x4000 #define IN_UNMOUNT 0x2000 +#define IN_CLASSA_NSHIFT 24 #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_IN_H_ */