From 55c6297e13b49387708208d86cd0fc5d23e01678 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Tue, 6 Sep 2022 07:04:13 -0700 Subject: [PATCH] Make more compatibility improvements --- ape/ape.lds | 1 + libc/calls/CPU_AND.c | 27 +++++++++++++ libc/calls/CPU_COUNT.c | 29 ++++++++++++++ libc/calls/CPU_EQUAL.c | 24 ++++++++++++ libc/calls/CPU_OR.c | 27 +++++++++++++ libc/calls/CPU_XOR.c | 27 +++++++++++++ libc/calls/CPU_ZERO.c | 24 ++++++++++++ libc/calls/calls.h | 4 +- libc/calls/getcpucount.c | 5 ++- libc/calls/sched_getaffinity.c | 46 ++++++++++++++++++----- libc/calls/sched_setaffinity.c | 16 +++++--- libc/calls/struct/cpuset.h | 29 ++++++++++++++ libc/calls/struct/sigset.h | 1 + libc/calls/termios.h | 2 - libc/calls/weirdtypes.h | 3 +- libc/fmt/stoa.c | 7 ++-- libc/integral/c.inc | 2 - libc/isystem/byteswap.h | 4 ++ libc/isystem/linux/xattr.h | 4 ++ libc/isystem/locale.h | 1 + libc/isystem/net/if.h | 7 ++++ libc/isystem/sched.h | 1 + libc/isystem/sys/event.h | 6 +++ libc/isystem/sys/stat.h | 1 + libc/isystem/sys/statfs.h | 4 ++ libc/isystem/sys/statvfs.h | 1 + libc/isystem/termios.h | 1 + libc/limits.h | 3 ++ libc/nt/process.h | 5 +-- libc/runtime/endutent.S | 24 ++++++++++++ libc/{stubs => runtime}/endutxent.S | 2 +- libc/runtime/getutent.S | 24 ++++++++++++ libc/runtime/getutid.S | 24 ++++++++++++ libc/{stubs => runtime}/getutxent.S | 1 - libc/{stubs => runtime}/getutxid.S | 1 - libc/{stubs => runtime}/getutxline.S | 0 libc/runtime/setutent.S | 24 ++++++++++++ libc/{stubs => runtime}/setutxent.S | 2 +- libc/runtime/updwtmp.S | 24 ++++++++++++ libc/{stubs => runtime}/updwtmpx.S | 2 +- libc/sock/if.h | 6 +++ libc/str/strwidth.c | 2 +- libc/str/strwidth.h | 13 +++++++ libc/str/strwidth16.c | 2 +- libc/str/unicode.h | 4 -- libc/sysv/consts.sh | 1 - libc/sysv/consts/SIG_ATOMIC_MIN.s | 2 - libc/sysv/consts/sig.h | 8 ++-- libc/thread/pthread_sigmask.c | 27 +++++++++++++ test/libc/calls/sched_getaffinity_test.c | 28 ++++++++++++-- test/libc/str/strnwidth_test.c | 2 +- test/libc/str/wcwidth_test.c | 3 +- tool/build/blinkenlights.c | 7 +++- tool/build/lib/message.c | 2 +- tool/build/lib/syscall.c | 1 - tool/decode/scrubdox.c | 2 +- tool/net/lfuncs.c | 1 + tool/net/redbean.c | 1 + tool/viz/lib/formatstringtable-assembly.c | 4 +- tool/viz/lib/formatstringtable.c | 2 +- tool/viz/life.c | 13 ++++--- tool/viz/printvideo.c | 15 ++++---- tool/viz/tabalign.c | 7 ++-- 63 files changed, 513 insertions(+), 80 deletions(-) create mode 100644 libc/calls/CPU_AND.c create mode 100644 libc/calls/CPU_COUNT.c create mode 100644 libc/calls/CPU_EQUAL.c create mode 100644 libc/calls/CPU_OR.c create mode 100644 libc/calls/CPU_XOR.c create mode 100644 libc/calls/CPU_ZERO.c create mode 100644 libc/calls/struct/cpuset.h create mode 100644 libc/isystem/byteswap.h create mode 100644 libc/isystem/linux/xattr.h create mode 100644 libc/isystem/net/if.h create mode 100644 libc/isystem/sys/event.h create mode 100644 libc/isystem/sys/statfs.h create mode 100644 libc/runtime/endutent.S rename libc/{stubs => runtime}/endutxent.S (98%) create mode 100644 libc/runtime/getutent.S create mode 100644 libc/runtime/getutid.S rename libc/{stubs => runtime}/getutxent.S (98%) rename libc/{stubs => runtime}/getutxid.S (98%) rename libc/{stubs => runtime}/getutxline.S (100%) create mode 100644 libc/runtime/setutent.S rename libc/{stubs => runtime}/setutxent.S (98%) create mode 100644 libc/runtime/updwtmp.S rename libc/{stubs => runtime}/updwtmpx.S (98%) create mode 100644 libc/sock/if.h create mode 100644 libc/str/strwidth.h delete mode 100644 libc/sysv/consts/SIG_ATOMIC_MIN.s create mode 100644 libc/thread/pthread_sigmask.c diff --git a/ape/ape.lds b/ape/ape.lds index 7c020c3ad..266b8cfb0 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -279,6 +279,7 @@ SECTIONS { KEEP(*(.keep.text)) *(.text .stub .text.*) KEEP(*(SORT_BY_NAME(.sort.text.*))) + *(.subrs) KEEP(*(.ape.pad.test)); *(.test.unlikely) diff --git a/libc/calls/CPU_AND.c b/libc/calls/CPU_AND.c new file mode 100644 index 000000000..9b7149748 --- /dev/null +++ b/libc/calls/CPU_AND.c @@ -0,0 +1,27 @@ +/*-*- 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/cpuset.h" +#include "libc/macros.internal.h" + +void CPU_AND(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) { + int i; + for (i = 0; i < ARRAYLEN(d->__bits); ++i) { + d->__bits[i] = x->__bits[i] & y->__bits[i]; + } +} diff --git a/libc/calls/CPU_COUNT.c b/libc/calls/CPU_COUNT.c new file mode 100644 index 000000000..1f2a27f66 --- /dev/null +++ b/libc/calls/CPU_COUNT.c @@ -0,0 +1,29 @@ +/*-*- 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/cpuset.h" +#include "libc/intrin/popcnt.h" +#include "libc/macros.internal.h" + +int CPU_COUNT(cpu_set_t *set) { + int i, c; + for (c = i = 0; i < ARRAYLEN(set->__bits); ++i) { + c += popcnt(set->__bits[i]); + } + return c; +} diff --git a/libc/calls/CPU_EQUAL.c b/libc/calls/CPU_EQUAL.c new file mode 100644 index 000000000..6fa76ee18 --- /dev/null +++ b/libc/calls/CPU_EQUAL.c @@ -0,0 +1,24 @@ +/*-*- 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/cpuset.h" +#include "libc/str/str.h" + +int CPU_EQUAL(cpu_set_t *x, cpu_set_t *y) { + return !memcmp(x, y, sizeof(*x)); +} diff --git a/libc/calls/CPU_OR.c b/libc/calls/CPU_OR.c new file mode 100644 index 000000000..d4431d010 --- /dev/null +++ b/libc/calls/CPU_OR.c @@ -0,0 +1,27 @@ +/*-*- 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/cpuset.h" +#include "libc/macros.internal.h" + +void CPU_OR(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) { + int i; + for (i = 0; i < ARRAYLEN(d->__bits); ++i) { + d->__bits[i] = x->__bits[i] | y->__bits[i]; + } +} diff --git a/libc/calls/CPU_XOR.c b/libc/calls/CPU_XOR.c new file mode 100644 index 000000000..5a128feed --- /dev/null +++ b/libc/calls/CPU_XOR.c @@ -0,0 +1,27 @@ +/*-*- 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/cpuset.h" +#include "libc/macros.internal.h" + +void CPU_XOR(cpu_set_t *d, cpu_set_t *x, cpu_set_t *y) { + int i; + for (i = 0; i < ARRAYLEN(d->__bits); ++i) { + d->__bits[i] = x->__bits[i] ^ y->__bits[i]; + } +} diff --git a/libc/calls/CPU_ZERO.c b/libc/calls/CPU_ZERO.c new file mode 100644 index 000000000..6d7994e75 --- /dev/null +++ b/libc/calls/CPU_ZERO.c @@ -0,0 +1,24 @@ +/*-*- 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/cpuset.h" +#include "libc/str/str.h" + +void CPU_ZERO(cpu_set_t *set) { + bzero(set, sizeof(*set)); +} diff --git a/libc/calls/calls.h b/libc/calls/calls.h index c7bf66975..61c24d183 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -159,8 +159,6 @@ int rename(const char *, const char *); int renameat(int, const char *, int, const char *); int renameat2(long, const char *, long, const char *, int); int rmdir(const char *); -int sched_getaffinity(int, uint64_t, void *); -int sched_setaffinity(int, uint64_t, const void *); int sched_yield(void); int seccomp(unsigned, unsigned, void *); int setegid(uint32_t); @@ -184,6 +182,7 @@ int symlinkat(const char *, int, const char *); int sync_file_range(int, int64_t, int64_t, unsigned); int sys_ptrace(int, ...); int sysctl(const int *, unsigned, void *, size_t *, void *, size_t); +int tcsetpgrp(int, int32_t); int tgkill(int, int, int); int tkill(int, int); int tmpfd(void); @@ -199,6 +198,7 @@ int usleep(unsigned); int vfork(void) returnstwice; int wait(int *); int waitpid(int, int *, int); +int32_t tcgetpgrp(int); intptr_t syscall(int, ...); long ptrace(int, ...); ssize_t copy_file_range(int, long *, int, long *, size_t, uint32_t); diff --git a/libc/calls/getcpucount.c b/libc/calls/getcpucount.c index 44958ee62..3021ffd12 100644 --- a/libc/calls/getcpucount.c +++ b/libc/calls/getcpucount.c @@ -17,10 +17,11 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/intrin/popcnt.h" #include "libc/calls/calls.h" +#include "libc/calls/sched-sysv.internal.h" #include "libc/calls/weirdtypes.h" #include "libc/dce.h" +#include "libc/intrin/popcnt.h" #include "libc/macros.internal.h" #include "libc/nt/dll.h" #include "libc/nt/struct/systeminfo.h" @@ -36,7 +37,7 @@ static unsigned GetCpuCountLinux(void) { uint64_t s[16]; unsigned i, c, n; - if (!sched_getaffinity(0, sizeof(s), s)) { + if (!sys_sched_getaffinity(0, sizeof(s), s)) { for (c = i = 0; i < ARRAYLEN(s); ++i) { c += popcnt(s[i]); } diff --git a/libc/calls/sched_getaffinity.c b/libc/calls/sched_getaffinity.c index 08065f0f0..8b6cdb3b2 100644 --- a/libc/calls/sched_getaffinity.c +++ b/libc/calls/sched_getaffinity.c @@ -16,28 +16,56 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" #include "libc/calls/sched-sysv.internal.h" #include "libc/calls/strace.internal.h" -#include "libc/calls/syscall-sysv.internal.h" +#include "libc/calls/struct/cpuset.h" +#include "libc/calls/syscall_support-nt.internal.h" +#include "libc/dce.h" +#include "libc/nt/process.h" +#include "libc/nt/runtime.h" +#include "libc/nt/thread.h" #include "libc/str/str.h" +#include "libc/sysv/errfuns.h" + +static textwindows int sys_sched_getaffinity_nt(int tid, size_t size, + cpu_set_t *bitset) { + uint64_t ProcessAffinityMask, SystemAffinityMask; + if (GetProcessAffinityMask(GetCurrentProcess(), &ProcessAffinityMask, + &SystemAffinityMask)) { + bzero(bitset, size); + bitset->__bits[0] = ProcessAffinityMask; + return 0; + } else { + return __winerr(); + } +} /** - * Gets kernel scheduling for particular CPUs. + * Gets CPU affinity for current thread. + * + * While Windows allows us to change the thread affinity mask, it's only + * possible to read the process affinity mask. Therefore this function + * won't reflect the changes made by sched_setaffinity() on Windows. * * @param pid is the process or thread id (or 0 for caller) - * @param size is byte length of bitset + * @param size is byte length of bitset, which should 128 * @param bitset receives bitset and should be uint64_t[16] in order to * work on older versions of Linux * @return 0 on success, or -1 w/ errno * @raise ENOSYS on non-Linux */ -int sched_getaffinity(int tid, size_t size, void *bitset) { - long rc; - rc = sys_sched_getaffinity(tid, size, bitset); - if (rc != -1) { +int sched_getaffinity(int tid, size_t size, cpu_set_t *bitset) { + int rc; + if (size != 128) { + rc = einval(); + } else if (IsWindows()) { + rc = sys_sched_getaffinity_nt(tid, size, bitset); + } else { + rc = sys_sched_getaffinity(tid, size, bitset); + } + if (rc > 0) { if (rc < size) { - memset((char *)bitset + rc, 0, size - rc); + bzero((char *)bitset + rc, size - rc); } rc = 0; } diff --git a/libc/calls/sched_setaffinity.c b/libc/calls/sched_setaffinity.c index 8979ff850..80647cf2d 100644 --- a/libc/calls/sched_setaffinity.c +++ b/libc/calls/sched_setaffinity.c @@ -16,13 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/sched-sysv.internal.h" #include "libc/calls/strace.internal.h" +#include "libc/calls/struct/cpuset.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" #include "libc/nt/enum/processaccess.h" #include "libc/nt/enum/threadaccess.h" @@ -30,6 +31,7 @@ #include "libc/nt/runtime.h" #include "libc/nt/thread.h" #include "libc/str/str.h" +#include "libc/sysv/errfuns.h" static textwindows dontinline int sys_sched_setaffinity_nt(int pid, uint64_t bitsetsize, @@ -67,16 +69,18 @@ static textwindows dontinline int sys_sched_setaffinity_nt(int pid, * Asks kernel to only schedule process on particular CPUs. * * @param tid is the process or thread id (or 0 for caller) - * @param bitsetsize is byte length of bitset + * @param bitsetsize is byte length of bitset, which should be 128 * @return 0 on success, or -1 w/ errno * @raise ENOSYS if not Linux or Windows */ -int sched_setaffinity(int tid, uint64_t bitsetsize, const void *bitset) { +int sched_setaffinity(int tid, size_t bitsetsize, const cpu_set_t *bitset) { int rc; - if (!IsWindows()) { - rc = sys_sched_setaffinity(tid, bitsetsize, bitset); - } else { + if (bitsetsize != 128) { + rc = einval(); + } else if (IsWindows()) { rc = sys_sched_setaffinity_nt(tid, bitsetsize, bitset); + } else { + rc = sys_sched_setaffinity(tid, bitsetsize, bitset); } STRACE("sched_setaffinity(%d, %'zu, %p) → %d% m", tid, bitsetsize, bitset); return rc; diff --git a/libc/calls/struct/cpuset.h b/libc/calls/struct/cpuset.h new file mode 100644 index 000000000..ef8ae6f1c --- /dev/null +++ b/libc/calls/struct/cpuset.h @@ -0,0 +1,29 @@ +#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_ +#define COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_ + +#define CPU_SETSIZE 1024 + +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +typedef struct cpu_set_t { + uint64_t __bits[16]; +} cpu_set_t; + +int sched_getcpu(void); +int sched_getaffinity(int, size_t, cpu_set_t *); +int sched_setaffinity(int, size_t, const cpu_set_t *); + +#define CPU_SET(i, s) ((s)->__bits[(i) / 64] |= 1ull << ((i) % 64)) +#define CPU_CLR(i, s) ((s)->__bits[(i) / 64] &= ~(1ull << ((i) % 64))) +#define CPU_ISSET(i, s) (!!((s)->__bits[(i) / 64] & (1ull << ((i) % 64)))) +void CPU_ZERO(cpu_set_t *); +int CPU_COUNT(cpu_set_t *); +int CPU_EQUAL(cpu_set_t *, cpu_set_t *); +void CPU_AND(cpu_set_t *, cpu_set_t *, cpu_set_t *); +void CPU_OR(cpu_set_t *, cpu_set_t *, cpu_set_t *); +void CPU_XOR(cpu_set_t *, cpu_set_t *, cpu_set_t *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_ */ diff --git a/libc/calls/struct/sigset.h b/libc/calls/struct/sigset.h index 6434dcd55..de3887938 100644 --- a/libc/calls/struct/sigset.h +++ b/libc/calls/struct/sigset.h @@ -14,6 +14,7 @@ int sigfillset(sigset_t *) paramsnonnull(); int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect; int sigprocmask(int, const sigset_t *, sigset_t *); int sigsuspend(const sigset_t *); +int pthread_sigmask(int, const sigset_t *, sigset_t *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/termios.h b/libc/calls/termios.h index 044f0c2af..19ad16c71 100644 --- a/libc/calls/termios.h +++ b/libc/calls/termios.h @@ -13,8 +13,6 @@ COSMOPOLITAN_C_START_ int tcgetattr(int, struct termios *); int tcsetattr(int, int, const struct termios *); -int tcsetpgrp(int, int32_t); -int32_t tcgetpgrp(int); int openpty(int *, int *, char *, const struct termios *, const struct winsize *) paramsnonnull((1, 2)); diff --git a/libc/calls/weirdtypes.h b/libc/calls/weirdtypes.h index 569e66226..14e83d6bf 100644 --- a/libc/calls/weirdtypes.h +++ b/libc/calls/weirdtypes.h @@ -9,8 +9,7 @@ #define blkcnt_t int64_t #define blksize_t int64_t /* int32_t on xnu */ #define cc_t uint8_t -#define clock_t int64_t /* uint64_t on xnu */ -#define cpu_set_t uint64_t +#define clock_t int64_t /* uint64_t on xnu */ #define dev_t uint64_t /* int32_t on xnu */ #define fsblkcnt_t int64_t #define fsfilcnt_t int64_t /* uint32_t on xnu */ diff --git a/libc/fmt/stoa.c b/libc/fmt/stoa.c index 26d999902..2494e72e3 100644 --- a/libc/fmt/stoa.c +++ b/libc/fmt/stoa.c @@ -17,17 +17,18 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" +#include "libc/fmt/fmt.internal.h" +#include "libc/fmt/internal.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" #include "libc/intrin/weaken.h" -#include "libc/fmt/fmt.internal.h" -#include "libc/fmt/internal.h" #include "libc/nexgen32e/bsr.h" #include "libc/str/str.h" +#include "libc/str/strwidth.h" #include "libc/str/thompike.h" #include "libc/str/tpenc.h" -#include "libc/str/utf16.h" #include "libc/str/unicode.h" +#include "libc/str/utf16.h" typedef int (*out_f)(const char *, void *, size_t); typedef int (*emit_f)(out_f, void *, uint64_t); diff --git a/libc/integral/c.inc b/libc/integral/c.inc index 4c1c96d00..f7d75c230 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -718,7 +718,6 @@ typedef struct { #pragma GCC diagnostic error "-Wpointer-arith" #pragma GCC diagnostic error "-Wnonnull" #pragma GCC diagnostic error "-Wunused-result" -#pragma GCC diagnostic error "-Wuninitialized" #pragma GCC diagnostic error "-Wstrict-aliasing" #pragma GCC diagnostic error "-Wshift-negative-value" #ifndef __cplusplus @@ -737,7 +736,6 @@ typedef struct { #if defined(__GNUC__) && !defined(__llvm__) #pragma GCC diagnostic error "-Wwrite-strings" #pragma GCC diagnostic error "-Wtrampolines" -#pragma GCC diagnostic error "-Wmaybe-uninitialized" #if __GNUC__ >= 6 #pragma GCC diagnostic error "-Wnonnull-compare" #if defined(COSMO) && !defined(MODE_DBG) && !defined(STACK_FRAME_UNLIMITED) diff --git a/libc/isystem/byteswap.h b/libc/isystem/byteswap.h new file mode 100644 index 000000000..37e93d38e --- /dev/null +++ b/libc/isystem/byteswap.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_BYTESWAP_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_BYTESWAP_H_ +#include "libc/intrin/bswap.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_BYTESWAP_H_ */ diff --git a/libc/isystem/linux/xattr.h b/libc/isystem/linux/xattr.h new file mode 100644 index 000000000..982b490a2 --- /dev/null +++ b/libc/isystem/linux/xattr.h @@ -0,0 +1,4 @@ +#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/isystem/locale.h b/libc/isystem/locale.h index 307fc6ab2..cbce7fdf3 100644 --- a/libc/isystem/locale.h +++ b/libc/isystem/locale.h @@ -1,4 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_ISYSTEM_LOCALE_H_ #define COSMOPOLITAN_LIBC_ISYSTEM_LOCALE_H_ #include "libc/str/locale.h" +#include "libc/str/unicode.h" #endif /* COSMOPOLITAN_LIBC_ISYSTEM_LOCALE_H_ */ diff --git a/libc/isystem/net/if.h b/libc/isystem/net/if.h new file mode 100644 index 000000000..2ed3eca67 --- /dev/null +++ b/libc/isystem/net/if.h @@ -0,0 +1,7 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NET_IF_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_NET_IF_H_ +#include "libc/sock/if.h" +#include "libc/sock/struct/ifconf.h" +#include "libc/sock/struct/ifreq.h" +#include "libc/sysv/consts/iff.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NET_IF_H_ */ diff --git a/libc/isystem/sched.h b/libc/isystem/sched.h index 2fb0d945a..b5381dd38 100644 --- a/libc/isystem/sched.h +++ b/libc/isystem/sched.h @@ -1,6 +1,7 @@ #ifndef LIBC_ISYSTEM_SCHED_H_ #define LIBC_ISYSTEM_SCHED_H_ #include "libc/calls/calls.h" +#include "libc/calls/struct/cpuset.h" #include "libc/calls/struct/sched_param.h" #include "libc/sysv/consts/sched.h" #endif diff --git a/libc/isystem/sys/event.h b/libc/isystem/sys/event.h new file mode 100644 index 000000000..2f8282ed2 --- /dev/null +++ b/libc/isystem/sys/event.h @@ -0,0 +1,6 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYS_EVENT_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_SYS_EVENT_H_ + +/* eventfd() is meh */ + +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_EVENT_H_ */ diff --git a/libc/isystem/sys/stat.h b/libc/isystem/sys/stat.h index d443c62f0..07b3951c9 100644 --- a/libc/isystem/sys/stat.h +++ b/libc/isystem/sys/stat.h @@ -3,6 +3,7 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/stat.macros.h" +#include "libc/calls/struct/timespec.h" #include "libc/calls/weirdtypes.h" #include "libc/sysv/consts/s.h" #include "libc/sysv/consts/utime.h" diff --git a/libc/isystem/sys/statfs.h b/libc/isystem/sys/statfs.h new file mode 100644 index 000000000..fabc9f3d3 --- /dev/null +++ b/libc/isystem/sys/statfs.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYS_STATFS_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_SYS_STATFS_H_ +#include "libc/calls/struct/statfs.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_STATFS_H_ */ diff --git a/libc/isystem/sys/statvfs.h b/libc/isystem/sys/statvfs.h index af486bbf9..9fca9a003 100644 --- a/libc/isystem/sys/statvfs.h +++ b/libc/isystem/sys/statvfs.h @@ -1,4 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_ISYSTEM_STATVFS_H_ #define COSMOPOLITAN_LIBC_ISYSTEM_STATVFS_H_ +#include "libc/calls/struct/statvfs.h" #include "libc/sysv/consts/st.h" #endif /* COSMOPOLITAN_LIBC_ISYSTEM_STATVFS_H_ */ diff --git a/libc/isystem/termios.h b/libc/isystem/termios.h index c2bce6b3c..a0c65572a 100644 --- a/libc/isystem/termios.h +++ b/libc/isystem/termios.h @@ -1,5 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_ISYSTEM_TERMIOS_H_ #define COSMOPOLITAN_LIBC_ISYSTEM_TERMIOS_H_ #include "libc/calls/termios.h" +#include "libc/sysv/consts/baud.h" #include "libc/sysv/consts/termios.h" #endif /* COSMOPOLITAN_LIBC_ISYSTEM_TERMIOS_H_ */ diff --git a/libc/limits.h b/libc/limits.h index 65ff9286a..20293aaaf 100644 --- a/libc/limits.h +++ b/libc/limits.h @@ -87,4 +87,7 @@ ((uint128_t)0xffffffffffffffff << 64 | (uint128_t)0xffffffffffffffff) #endif /* GCC 4.6+ */ +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + #endif /* COSMOPOLITAN_LIBC_LIMITS_H_ */ diff --git a/libc/nt/process.h b/libc/nt/process.h index 38745121e..2de6c6520 100644 --- a/libc/nt/process.h +++ b/libc/nt/process.h @@ -58,9 +58,8 @@ uint32_t GetEnvironmentVariable(const char16_t *lpName, char16_t *lpBuffer, uint32_t nSize); uint32_t SetEnvironmentVariable(const char16_t *lpName, char16_t *lpValue); int32_t SetEnvironmentStrings(char16_t *NewEnvironment); -bool32 GetProcessAffinityMask(int64_t hProcess, - uintptr_t *lpProcessAffinityMask, - uintptr_t *lpSystemAffinityMask); +bool32 GetProcessAffinityMask(int64_t hProcess, uint64_t *lpProcessAffinityMask, + uint64_t *lpSystemAffinityMask); uint64_t /*bool32*/ SetProcessAffinityMask(int64_t hProcess, uintptr_t dwProcessAffinityMask); diff --git a/libc/runtime/endutent.S b/libc/runtime/endutent.S new file mode 100644 index 000000000..0f154bb5c --- /dev/null +++ b/libc/runtime/endutent.S @@ -0,0 +1,24 @@ +/*-*- 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│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ 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/macros.internal.h" + +endutent: + xor %eax,%eax + ret + .endfn endutent,globl diff --git a/libc/stubs/endutxent.S b/libc/runtime/endutxent.S similarity index 98% rename from libc/stubs/endutxent.S rename to libc/runtime/endutxent.S index 4e7389cd3..9fcc3697a 100644 --- a/libc/stubs/endutxent.S +++ b/libc/runtime/endutxent.S @@ -21,6 +21,6 @@ // Closes user accounting database. // @note unsupported endutxent: + xor %eax,%eax ret .endfn endutxent,globl - .alias endutxent,endutent diff --git a/libc/runtime/getutent.S b/libc/runtime/getutent.S new file mode 100644 index 000000000..01975567a --- /dev/null +++ b/libc/runtime/getutent.S @@ -0,0 +1,24 @@ +/*-*- 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│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ 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/macros.internal.h" + +getutent: + xor %eax,%eax + ret + .endfn getutent,globl diff --git a/libc/runtime/getutid.S b/libc/runtime/getutid.S new file mode 100644 index 000000000..ccb471dec --- /dev/null +++ b/libc/runtime/getutid.S @@ -0,0 +1,24 @@ +/*-*- 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│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ 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/macros.internal.h" + +getutid: + xor %eax,%eax + ret + .endfn getutid,globl diff --git a/libc/stubs/getutxent.S b/libc/runtime/getutxent.S similarity index 98% rename from libc/stubs/getutxent.S rename to libc/runtime/getutxent.S index c4bff11ca..0258e492f 100644 --- a/libc/stubs/getutxent.S +++ b/libc/runtime/getutxent.S @@ -24,4 +24,3 @@ getutxent: xor %eax,%eax ret .endfn getutxent,globl - .alias getutxent,getutent diff --git a/libc/stubs/getutxid.S b/libc/runtime/getutxid.S similarity index 98% rename from libc/stubs/getutxid.S rename to libc/runtime/getutxid.S index 53b0870c3..448ff9b81 100644 --- a/libc/stubs/getutxid.S +++ b/libc/runtime/getutxid.S @@ -24,4 +24,3 @@ getutxid: xor %eax,%eax ret .endfn getutxid,globl - .alias getutxid,getutid diff --git a/libc/stubs/getutxline.S b/libc/runtime/getutxline.S similarity index 100% rename from libc/stubs/getutxline.S rename to libc/runtime/getutxline.S diff --git a/libc/runtime/setutent.S b/libc/runtime/setutent.S new file mode 100644 index 000000000..f46d0aea9 --- /dev/null +++ b/libc/runtime/setutent.S @@ -0,0 +1,24 @@ +/*-*- 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│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ 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/macros.internal.h" + +setutent: + xor %eax,%eax + ret + .endfn setutent,globl diff --git a/libc/stubs/setutxent.S b/libc/runtime/setutxent.S similarity index 98% rename from libc/stubs/setutxent.S rename to libc/runtime/setutxent.S index 53d72b071..49d2429e9 100644 --- a/libc/stubs/setutxent.S +++ b/libc/runtime/setutxent.S @@ -21,6 +21,6 @@ // Rewinds the user accounting database. // @note unsupported setutxent: + xor %eax,%eax ret .endfn setutxent,globl - .alias setutxent,setutent diff --git a/libc/runtime/updwtmp.S b/libc/runtime/updwtmp.S new file mode 100644 index 000000000..2af33f04d --- /dev/null +++ b/libc/runtime/updwtmp.S @@ -0,0 +1,24 @@ +/*-*- 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│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ 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/macros.internal.h" + +updwtmp: + xor %eax,%eax + ret + .endfn updwtmp,globl diff --git a/libc/stubs/updwtmpx.S b/libc/runtime/updwtmpx.S similarity index 98% rename from libc/stubs/updwtmpx.S rename to libc/runtime/updwtmpx.S index 025a35176..e20d729a3 100644 --- a/libc/stubs/updwtmpx.S +++ b/libc/runtime/updwtmpx.S @@ -21,6 +21,6 @@ // Does something to the user accounting database. // @note unsupported updwtmpx: + xor %eax,%eax ret .endfn updwtmpx,globl - .alias updwtmpx,updwtmp diff --git a/libc/sock/if.h b/libc/sock/if.h new file mode 100644 index 000000000..f0d21822a --- /dev/null +++ b/libc/sock/if.h @@ -0,0 +1,6 @@ +#ifndef COSMOPOLITAN_LIBC_SOCK_IF_H_ +#define COSMOPOLITAN_LIBC_SOCK_IF_H_ + +#define IFNAMSIZ 16 + +#endif /* COSMOPOLITAN_LIBC_SOCK_IF_H_ */ diff --git a/libc/str/strwidth.c b/libc/str/strwidth.c index cc5af4605..73fa99cf8 100644 --- a/libc/str/strwidth.c +++ b/libc/str/strwidth.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/str/unicode.h" +#include "libc/str/strwidth.h" /** * Returns monospace display width of UTF-8 string. diff --git a/libc/str/strwidth.h b/libc/str/strwidth.h new file mode 100644 index 000000000..1d220e336 --- /dev/null +++ b/libc/str/strwidth.h @@ -0,0 +1,13 @@ +#ifndef COSMOPOLITAN_LIBC_STR_STRWIDTH_H_ +#define COSMOPOLITAN_LIBC_STR_STRWIDTH_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int strwidth(const char *, size_t) strlenesque; +int strnwidth(const char *, size_t, size_t) strlenesque; +int strwidth16(const char16_t *, size_t) strlenesque; +int strnwidth16(const char16_t *, size_t, size_t) strlenesque; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_STR_STRWIDTH_H_ */ diff --git a/libc/str/strwidth16.c b/libc/str/strwidth16.c index e14700ffe..6b50b11e1 100644 --- a/libc/str/strwidth16.c +++ b/libc/str/strwidth16.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" -#include "libc/str/unicode.h" +#include "libc/str/strwidth.h" /** * Returns monospace display width of UTF-16 or UCS-2 string. diff --git a/libc/str/unicode.h b/libc/str/unicode.h index 4da460be3..07bb280ff 100644 --- a/libc/str/unicode.h +++ b/libc/str/unicode.h @@ -33,10 +33,6 @@ struct lconv { int wcwidth(wchar_t) pureconst; int wcswidth(const wchar_t *, size_t) strlenesque; int wcsnwidth(const wchar_t *, size_t, size_t) strlenesque; -int strwidth(const char *, size_t) strlenesque; -int strnwidth(const char *, size_t, size_t) strlenesque; -int strwidth16(const char16_t *, size_t) strlenesque; -int strnwidth16(const char16_t *, size_t, size_t) strlenesque; struct lconv *localeconv(void); COSMOPOLITAN_C_END_ diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 03a6ec850..379f0b372 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -302,7 +302,6 @@ syscon mremap MREMAP_FIXED 2 2 2 2 2 2 # faked non-linux (b/c lin syscon misc SIG_BLOCK 0 1 1 1 1 0 # bsd consensus; faked nt syscon misc SIG_UNBLOCK 1 2 2 2 2 1 # bsd consensus; faked nt syscon misc SIG_SETMASK 2 3 3 3 3 2 # bsd consensus; faked nt -syscon misc SIG_ATOMIC_MIN -2147483648 -2147483648 -9223372036854775808 -2147483648 -2147483648 0 # lseek() whence # diff --git a/libc/sysv/consts/SIG_ATOMIC_MIN.s b/libc/sysv/consts/SIG_ATOMIC_MIN.s deleted file mode 100644 index 29c2f853a..000000000 --- a/libc/sysv/consts/SIG_ATOMIC_MIN.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/consts/syscon.internal.inc" -.syscon misc,SIG_ATOMIC_MIN,-2147483648,-2147483648,-9223372036854775808,-2147483648,-2147483648,0 diff --git a/libc/sysv/consts/sig.h b/libc/sysv/consts/sig.h index 980c5e457..46e58f763 100644 --- a/libc/sysv/consts/sig.h +++ b/libc/sysv/consts/sig.h @@ -43,7 +43,6 @@ extern const int SIGWINCH; extern const int SIGXCPU; extern const int SIGXFSZ; -extern const int SIG_ATOMIC_MIN; extern const int SIG_BLOCK; extern const int SIG_SETMASK; extern const int SIG_UNBLOCK; @@ -91,9 +90,8 @@ COSMOPOLITAN_C_END_ #define SIGUSR1 SYMBOLIC(SIGUSR1) #define SIGUSR2 SYMBOLIC(SIGUSR2) -#define SIG_ATOMIC_MIN SYMBOLIC(SIG_ATOMIC_MIN) -#define SIG_BLOCK SYMBOLIC(SIG_BLOCK) -#define SIG_SETMASK SYMBOLIC(SIG_SETMASK) -#define SIG_UNBLOCK SYMBOLIC(SIG_UNBLOCK) +#define SIG_BLOCK SYMBOLIC(SIG_BLOCK) +#define SIG_SETMASK SYMBOLIC(SIG_SETMASK) +#define SIG_UNBLOCK SYMBOLIC(SIG_UNBLOCK) #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_SIG_H_ */ diff --git a/libc/thread/pthread_sigmask.c b/libc/thread/pthread_sigmask.c new file mode 100644 index 000000000..20d87e802 --- /dev/null +++ b/libc/thread/pthread_sigmask.c @@ -0,0 +1,27 @@ +/*-*- 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/thread/thread.h" + +/** + * Examines and/or changes blocked signals on current thread. + */ +int pthread_sigmask(int how, const sigset_t *set, sigset_t *old) { + return sigprocmask(how, set, old); +} diff --git a/test/libc/calls/sched_getaffinity_test.c b/test/libc/calls/sched_getaffinity_test.c index bd0677535..053d0173b 100644 --- a/test/libc/calls/sched_getaffinity_test.c +++ b/test/libc/calls/sched_getaffinity_test.c @@ -16,10 +16,12 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/popcnt.h" #include "libc/calls/calls.h" +#include "libc/calls/struct/cpuset.h" #include "libc/dce.h" +#include "libc/intrin/popcnt.h" #include "libc/runtime/runtime.h" +#include "libc/runtime/sysconf.h" #include "libc/testlib/testlib.h" void SetUp(void) { @@ -28,7 +30,25 @@ void SetUp(void) { } } -TEST(sched_getaffinity, test) { - uint64_t s[16]; - EXPECT_SYS(0, 0, sched_getaffinity(0, sizeof(s), &s)); +TEST(sched_getaffinity, firstOnly) { + cpu_set_t x, y; + CPU_ZERO(&x); + CPU_SET(0, &x); + ASSERT_SYS(0, 0, sched_setaffinity(0, sizeof(x), &x)); + ASSERT_SYS(0, 0, sched_getaffinity(0, sizeof(y), &y)); + EXPECT_EQ(1, CPU_COUNT(&y)); + EXPECT_TRUE(CPU_ISSET(0, &y)); + EXPECT_FALSE(CPU_ISSET(1, &y)); +} + +TEST(sched_getaffinity, secondOnly) { + if (GetCpuCount() < 2) return; + cpu_set_t x, y; + CPU_ZERO(&x); + CPU_SET(1, &x); + ASSERT_SYS(0, 0, sched_setaffinity(0, sizeof(x), &x)); + ASSERT_SYS(0, 0, sched_getaffinity(0, sizeof(y), &y)); + EXPECT_EQ(1, CPU_COUNT(&y)); + EXPECT_FALSE(CPU_ISSET(0, &y)); + EXPECT_TRUE(CPU_ISSET(1, &y)); } diff --git a/test/libc/str/strnwidth_test.c b/test/libc/str/strnwidth_test.c index e6590267c..75d77a2a5 100644 --- a/test/libc/str/strnwidth_test.c +++ b/test/libc/str/strnwidth_test.c @@ -17,10 +17,10 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" +#include "libc/str/strwidth.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" -#include "libc/str/unicode.h" TEST(strwidth, test) { EXPECT_EQ(5, strwidth("hello", 0)); diff --git a/test/libc/str/wcwidth_test.c b/test/libc/str/wcwidth_test.c index 6b68f3e5e..27825e163 100644 --- a/test/libc/str/wcwidth_test.c +++ b/test/libc/str/wcwidth_test.c @@ -18,9 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" #include "libc/str/str.h" +#include "libc/str/strwidth.h" +#include "libc/str/unicode.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -#include "libc/str/unicode.h" TEST(wcwidth, test) { ASSERT_EQ(0, wcwidth(0)); diff --git a/tool/build/blinkenlights.c b/tool/build/blinkenlights.c index 3a932305d..1ea2d8210 100644 --- a/tool/build/blinkenlights.c +++ b/tool/build/blinkenlights.c @@ -21,6 +21,7 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" +#include "libc/calls/struct/cpuset.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/sigaction.h" @@ -56,11 +57,11 @@ #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" +#include "libc/str/strwidth.h" #include "libc/str/thompike.h" #include "libc/str/tpdecode.internal.h" #include "libc/str/tpenc.h" #include "libc/str/tpencode.internal.h" -#include "libc/str/unicode.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" @@ -3123,7 +3124,9 @@ int Emulator(int argc, char *argv[]) { } static void OnlyRunOnFirstCpu(void) { - uint64_t bs = 1; + cpu_set_t bs; + CPU_ZERO(&bs); + CPU_SET(0, &bs); sched_setaffinity(0, sizeof(bs), &bs); } diff --git a/tool/build/lib/message.c b/tool/build/lib/message.c index a6b3f62c7..20869d229 100644 --- a/tool/build/lib/message.c +++ b/tool/build/lib/message.c @@ -20,7 +20,7 @@ #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" -#include "libc/str/unicode.h" +#include "libc/str/strwidth.h" #include "tool/build/lib/buffer.h" #include "tool/build/lib/lines.h" #include "tool/build/lib/panel.h" diff --git a/tool/build/lib/syscall.c b/tool/build/lib/syscall.c index 545ab8208..437990ec3 100644 --- a/tool/build/lib/syscall.c +++ b/tool/build/lib/syscall.c @@ -1379,7 +1379,6 @@ void OpSyscall(struct Machine *m, uint32_t rde) { SYSCALL(0x09D, OpPrctl(m, di, si, dx, r0, r8)); SYSCALL(0x09E, OpArchPrctl(m, di, si)); SYSCALL(0x0BA, OpGetTid(m)); - SYSCALL(0x0CB, sched_setaffinity(di, si, P(dx))); SYSCALL(0x0D9, OpGetdents(m, di, si, dx)); SYSCALL(0x0DD, OpFadvise(m, di, si, dx, r0)); SYSCALL(0x0E4, OpClockGettime(m, di, si)); diff --git a/tool/decode/scrubdox.c b/tool/decode/scrubdox.c index 8638c68e9..9a302c926 100644 --- a/tool/decode/scrubdox.c +++ b/tool/decode/scrubdox.c @@ -76,7 +76,7 @@ #include "libc/runtime/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/unicode.h" +#include "libc/str/strwidth.h" #include "libc/x/x.h" #define IsSpace(C) ((C) == ' ') diff --git a/tool/net/lfuncs.c b/tool/net/lfuncs.c index 41b760658..2b548b5fe 100644 --- a/tool/net/lfuncs.c +++ b/tool/net/lfuncs.c @@ -43,6 +43,7 @@ #include "libc/sock/sock.h" #include "libc/stdio/rand.h" #include "libc/str/str.h" +#include "libc/str/strwidth.h" #include "libc/sysv/consts/af.h" #include "libc/sysv/consts/ipproto.h" #include "libc/sysv/consts/o.h" diff --git a/tool/net/redbean.c b/tool/net/redbean.c index afa9afd19..f9b2d5817 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -67,6 +67,7 @@ #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/slice.h" +#include "libc/str/strwidth.h" #include "libc/sysv/consts/af.h" #include "libc/sysv/consts/clone.h" #include "libc/sysv/consts/dt.h" diff --git a/tool/viz/lib/formatstringtable-assembly.c b/tool/viz/lib/formatstringtable-assembly.c index af2971b73..497d92497 100644 --- a/tool/viz/lib/formatstringtable-assembly.c +++ b/tool/viz/lib/formatstringtable-assembly.c @@ -16,12 +16,12 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/fmt/itoa.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" -#include "libc/fmt/itoa.h" #include "libc/runtime/gc.internal.h" #include "libc/str/str.h" -#include "libc/str/unicode.h" +#include "libc/str/strwidth.h" #include "libc/x/x.h" #include "tool/viz/lib/formatstringtable.h" diff --git a/tool/viz/lib/formatstringtable.c b/tool/viz/lib/formatstringtable.c index 236477f01..0dfe56549 100644 --- a/tool/viz/lib/formatstringtable.c +++ b/tool/viz/lib/formatstringtable.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/safemacros.internal.h" -#include "libc/str/unicode.h" +#include "libc/str/strwidth.h" #include "tool/viz/lib/formatstringtable.h" void *FreeStringTableCells(long yn, long xn, char *T[yn][xn]) { diff --git a/tool/viz/life.c b/tool/viz/life.c index 703e99af0..3e5975386 100644 --- a/tool/viz/life.c +++ b/tool/viz/life.c @@ -18,10 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/gamma.h" #include "dsp/scale/scale.h" -#include "libc/intrin/bits.h" -#include "libc/intrin/popcnt.h" -#include "libc/intrin/safemacros.internal.h" -#include "libc/intrin/xchg.internal.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/stat.h" @@ -32,6 +28,10 @@ #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/popcnt.h" +#include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/xchg.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" @@ -66,13 +66,15 @@ #include "libc/nt/struct/windowplacement.h" #include "libc/nt/struct/wndclass.h" #include "libc/nt/windows.h" -#include "libc/stdio/rand.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" +#include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" +#include "libc/str/strwidth.h" #include "libc/str/tpenc.h" +#include "libc/str/unicode.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/map.h" @@ -80,7 +82,6 @@ #include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/termios.h" #include "libc/time/time.h" -#include "libc/str/unicode.h" #include "libc/x/x.h" #include "third_party/getopt/getopt.h" diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index 434fc40e2..73fd186e0 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -23,12 +23,7 @@ #include "dsp/scale/scale.h" #include "dsp/tty/quant.h" #include "dsp/tty/tty.h" -#include "libc/mem/alg.h" -#include "libc/mem/arraylist.internal.h" #include "libc/assert.h" -#include "libc/intrin/bits.h" -#include "libc/intrin/safemacros.internal.h" -#include "libc/intrin/xchg.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/ioctl.h" @@ -46,24 +41,31 @@ #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/fmt/itoa.h" +#include "libc/intrin/bits.h" +#include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/xchg.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/alg.h" +#include "libc/mem/arraylist.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/bench.h" #include "libc/nexgen32e/x86feature.h" #include "libc/nt/console.h" #include "libc/nt/runtime.h" -#include "libc/stdio/rand.h" #include "libc/runtime/buffer.h" #include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" #include "libc/stdio/internal.h" +#include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" +#include "libc/str/strwidth.h" +#include "libc/str/unicode.h" #include "libc/sysv/consts/af.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/clock.h" @@ -89,7 +91,6 @@ #include "libc/sysv/consts/w.h" #include "libc/sysv/errfuns.h" #include "libc/time/time.h" -#include "libc/str/unicode.h" #include "libc/x/x.h" #include "third_party/getopt/getopt.h" #include "third_party/stb/stb_image_resize.h" diff --git a/tool/viz/tabalign.c b/tool/viz/tabalign.c index d94015871..c0579267e 100644 --- a/tool/viz/tabalign.c +++ b/tool/viz/tabalign.c @@ -16,19 +16,20 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/arraylist.internal.h" -#include "libc/intrin/safemacros.internal.h" #include "libc/fmt/conv.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" +#include "libc/mem/arraylist.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" +#include "libc/str/strwidth.h" +#include "libc/str/unicode.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" -#include "libc/str/unicode.h" #include "third_party/getopt/getopt.h" #define kOneTrueTabWidth 8