From 807706a0996b9a85959f90605e0fddb9e02f5089 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sat, 13 Mar 2021 19:39:17 -0800 Subject: [PATCH] Perform minor fixups One of those fixups is making sure that AF_LOCAL is equal to AF_UNIX on the New Technology. See #122 --- libc/calls/calls.h | 3 -- libc/calls/calls.mk | 4 --- libc/calls/chown.c | 1 - libc/calls/{seteuid.S => setegid.c} | 28 +++++++----------- libc/calls/{setegid.S => seteuid.c} | 28 +++++++----------- libc/calls/sigprocmask.c | 7 +++-- libc/integral/c.inc | 2 +- libc/nexgen32e/ksigsetempty.S | 36 ---------------------- libc/nexgen32e/ksigsetfull.S | 39 ------------------------ libc/runtime/hook.greg.c | 6 ++-- libc/sysv/consts.sh | 2 +- libc/sysv/consts/AF_LOCAL.S | 2 +- test/libc/time/dsleep_test.c | 6 ++-- tool/viz/printvideo.c | 46 +++++++++++++++++++++++++---- 14 files changed, 76 insertions(+), 134 deletions(-) rename libc/calls/{seteuid.S => setegid.c} (77%) rename libc/calls/{setegid.S => seteuid.c} (76%) delete mode 100644 libc/nexgen32e/ksigsetempty.S delete mode 100644 libc/nexgen32e/ksigsetfull.S diff --git a/libc/calls/calls.h b/libc/calls/calls.h index 798b04bec..19e188607 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -64,9 +64,6 @@ COSMOPOLITAN_C_START_ typedef int sig_atomic_t; -extern const struct sigset kSigsetFull; -extern const struct sigset kSigsetEmpty; - DIR *fdopendir(int) nodiscard; DIR *opendir(const char *) nodiscard; bool fileexists(const char *); diff --git a/libc/calls/calls.mk b/libc/calls/calls.mk index ee041a1ca..7c14e3c42 100644 --- a/libc/calls/calls.mk +++ b/libc/calls/calls.mk @@ -64,10 +64,6 @@ o/$(MODE)/libc/calls/raise.o: \ OVERRIDE_COPTS += \ $(NO_MAGIC) -o/$(MODE)/libc/calls/siggy.o: \ - OVERRIDE_COPTS += \ - -ffunction-sections - o/$(MODE)/libc/calls/sigenter-freebsd.o \ o/$(MODE)/libc/calls/sigenter-netbsd.o \ o/$(MODE)/libc/calls/sigenter-openbsd.o \ diff --git a/libc/calls/chown.c b/libc/calls/chown.c index 28703169d..cceae5c5b 100644 --- a/libc/calls/chown.c +++ b/libc/calls/chown.c @@ -19,7 +19,6 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/sysv/consts/at.h" -#include "libc/sysv/errfuns.h" /** * Changes owner and/or group of pathname. diff --git a/libc/calls/seteuid.S b/libc/calls/setegid.c similarity index 77% rename from libc/calls/seteuid.S rename to libc/calls/setegid.c index c17239722..55113a93d 100644 --- a/libc/calls/seteuid.S +++ b/libc/calls/setegid.c @@ -1,7 +1,7 @@ -/*-*- 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│ +/*-*- 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 │ +│ 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 │ @@ -16,19 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" -.source __FILE__ +#include "libc/calls/calls.h" -// Sets effective user ID. -// -// @param %edi is user id -// @see setuid(), getauxval(AT_SECURE) -seteuid:push %rbp - mov %rsp,%rbp - .profilable - mov %edi,%esi - mov $-1,%edi - call setreuid - pop %rbp - ret - .endfn seteuid,globl +/** + * Sets effective group ID. + */ +int setegid(unsigned gid) { + return setregid(-1, gid); +} diff --git a/libc/calls/setegid.S b/libc/calls/seteuid.c similarity index 76% rename from libc/calls/setegid.S rename to libc/calls/seteuid.c index ad9713903..b89b8f3c7 100644 --- a/libc/calls/setegid.S +++ b/libc/calls/seteuid.c @@ -1,7 +1,7 @@ -/*-*- 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│ +/*-*- 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 │ +│ 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 │ @@ -16,19 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" -.source __FILE__ +#include "libc/calls/calls.h" -// Sets effective group ID. -// -// @param %edi is group id -// @see setgid(), getauxval(AT_SECURE) -setegid:push %rbp - mov %rsp,%rbp - .profilable - mov %edi,%esi - mov $-1,%edi - call setregid - pop %rbp - ret - .endfn setegid,globl +/** + * Sets effective user ID. + */ +int seteuid(unsigned euid) { + return setreuid(-1, euid); +} diff --git a/libc/calls/sigprocmask.c b/libc/calls/sigprocmask.c index 7df83de75..ab2c241c3 100644 --- a/libc/calls/sigprocmask.c +++ b/libc/calls/sigprocmask.c @@ -26,9 +26,10 @@ /** * Changes program signal blocking state, e.g.: * - * sigset_t oldmask; - * sigprocmask(SIG_BLOCK, &kSigsetFull, &oldmask); - * sigprocmask(SIG_SETMASK, &oldmask, NULL); + * sigset_t neu,old; + * sigfillset(&neu); + * sigprocmask(SIG_BLOCK, &neu, &old); + * sigprocmask(SIG_SETMASK, &old, NULL); * * @param how can be SIG_BLOCK (U), SIG_UNBLOCK (/), SIG_SETMASK (=) * @param set is the new mask content (optional) diff --git a/libc/integral/c.inc b/libc/integral/c.inc index 3ecf974aa..26f5ce007 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -585,7 +585,7 @@ typedef uint64_t uintmax_t; #endif #ifndef unreachable -#if defined(__GNUC__) && !defined(__STRICT_ANSI) +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) #define unreachable __builtin_unreachable() #else #define unreachable \ diff --git a/libc/nexgen32e/ksigsetempty.S b/libc/nexgen32e/ksigsetempty.S deleted file mode 100644 index a73f071bd..000000000 --- a/libc/nexgen32e/ksigsetempty.S +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- 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 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/macros.internal.h" - -// Signal mask constant w/ no signal bits set. - .initbss 300,_init_kSigsetEmpty -kSigsetEmpty: - .rept NSIG / 64 - .quad 0 - .endr - .if NSIG % 64 - .error "bad signal max" - .endif - .endobj kSigsetEmpty,globl - .previous - - .init.start 300,_init_kSigsetEmpty - add $NSIG/8,%rdi - .init.end 300,_init_kSigsetEmpty - .source __FILE__ diff --git a/libc/nexgen32e/ksigsetfull.S b/libc/nexgen32e/ksigsetfull.S deleted file mode 100644 index 4a973dbdb..000000000 --- a/libc/nexgen32e/ksigsetfull.S +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- 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 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/macros.internal.h" - -// Signal mask constant w/ every signal bit set. - .initbss 300,_init_kSigsetFull -kSigsetFull: - .rept NSIG / 64 - .quad 0 - .endr - .if NSIG % 64 - .error "bad signal max" - .endif - .endobj kSigsetFull,globl - .previous - - .init.start 300,_init_kSigsetFull - or $-1,%rax - .rept NSIG / 64 - stosq - .endr - .init.end 300,_init_kSigsetFull - .source __FILE__ diff --git a/libc/runtime/hook.greg.c b/libc/runtime/hook.greg.c index 6bc479d85..c009aca04 100644 --- a/libc/runtime/hook.greg.c +++ b/libc/runtime/hook.greg.c @@ -19,6 +19,7 @@ #include "libc/bits/bits.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" +#include "libc/calls/sigbits.h" #include "libc/calls/struct/sigset.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" @@ -45,14 +46,15 @@ privileged void __hook(void *ifunc, struct SymbolTable *symbols) { size_t i; intptr_t addr; - sigset_t oldmask; uint64_t code, mcode; unsigned char *p, *pe; + sigset_t mask, oldmask; const intptr_t kMcount = (intptr_t)&mcount; const intptr_t kProgramCodeStart = (intptr_t)&_ereal; const intptr_t kPrivilegedStart = (intptr_t)&__privileged_start; const bool kIsBinaryAligned = !(kPrivilegedStart & (PAGESIZE - 1)); - sigprocmask(SIG_BLOCK, &kSigsetFull, &oldmask); + sigfillset(&mask); + sigprocmask(SIG_BLOCK, &mask, &oldmask); if (mprotect((void *)symbols->addr_base, kPrivilegedStart - symbols->addr_base, kIsBinaryAligned ? PROT_READ | PROT_WRITE diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 195259c9f..59c3a5538 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -1105,7 +1105,7 @@ syscon sio SIOGIFINDEX 0x8933 0 0 0 0 0 syscon af AF_UNSPEC 0 0 0 0 0 0 # consensus syscon af AF_UNIX 1 1 1 1 1 1 # consensus -syscon af AF_LOCAL 1 1 1 1 1 0 # unix consensus +syscon af AF_LOCAL 1 1 1 1 1 1 # consensus syscon af AF_FILE 1 0 0 0 0 0 syscon af AF_INET 2 2 2 2 2 2 # consensus syscon af AF_AX25 3 0 0 0 0 0 diff --git a/libc/sysv/consts/AF_LOCAL.S b/libc/sysv/consts/AF_LOCAL.S index 7637a6e23..183ec49bf 100644 --- a/libc/sysv/consts/AF_LOCAL.S +++ b/libc/sysv/consts/AF_LOCAL.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon af,AF_LOCAL,1,1,1,1,1,0 +.syscon af,AF_LOCAL,1,1,1,1,1,1 diff --git a/test/libc/time/dsleep_test.c b/test/libc/time/dsleep_test.c index fa50d8ec6..ab0be4703 100644 --- a/test/libc/time/dsleep_test.c +++ b/test/libc/time/dsleep_test.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/sigbits.h" #include "libc/calls/struct/sigset.h" #include "libc/log/log.h" #include "libc/nexgen32e/nexgen32e.h" @@ -33,9 +34,10 @@ TEST(fastdiv, test) { } TEST(dsleep, test) { - sigset_t oldmask; long double t1, t2; - sigprocmask(SIG_BLOCK, &kSigsetFull, &oldmask); + sigset_t mask, oldmask; + sigfillset(&mask); + sigprocmask(SIG_BLOCK, &mask, &oldmask); sched_yield(); t1 = dtime(CLOCK_MONOTONIC); dsleep(0.001L); diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index 2b99559d8..9da3fefd9 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -1059,9 +1059,45 @@ static optimizesize void ReadKeyboard(void) { break; case '1': switch (b[i++]) { + case '1': + switch (b[i++]) { + case '~': /* \e[11~ is F1 */ + pf1_ = !pf1_; + break; + default: + break; + } + break; + case '2': + switch (b[i++]) { + case '~': /* \e[12~ is F2 */ + pf2_ = !pf2_; + break; + default: + break; + } + break; + case '3': + switch (b[i++]) { + case '~': /* \e[13~ is F3 */ + pf3_ = !pf3_; + break; + default: + break; + } + break; + case '4': + switch (b[i++]) { + case '~': /* \e[14~ is F4 */ + pf4_ = !pf4_; + break; + default: + break; + } + break; case '5': switch (b[i++]) { - case '~': /* \e[20~ is F5 */ + case '~': /* \e[15~ is F5 */ pf5_ = !pf5_; break; default: @@ -1070,7 +1106,7 @@ static optimizesize void ReadKeyboard(void) { break; case '7': switch (b[i++]) { - case '~': /* \e[21~ is F6 */ + case '~': /* \e[17~ is F6 */ pf6_ = !pf6_; break; default: @@ -1079,7 +1115,7 @@ static optimizesize void ReadKeyboard(void) { break; case '8': switch (b[i++]) { - case '~': /* \e[22~ is F7 */ + case '~': /* \e[18~ is F7 */ pf7_ = !pf7_; break; default: @@ -1088,7 +1124,7 @@ static optimizesize void ReadKeyboard(void) { break; case '9': switch (b[i++]) { - case '~': /* \e[23~ is F8 */ + case '~': /* \e[19~ is F8 */ pf8_ = !pf8_; break; default: @@ -1103,7 +1139,7 @@ static optimizesize void ReadKeyboard(void) { switch (b[i++]) { case '0': switch (b[i++]) { - case '~': /* \e[20~ is F10 */ + case '~': /* \e[20~ is F9 */ pf9_ = !pf9_; break; default: