From 7486a2cd517a4fbe00e4d2fccd150cf895cdbc29 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Thu, 2 Feb 2023 00:32:30 -0800 Subject: [PATCH] Perform minor cleanups --- libc/calls/calls.h | 9 ++++----- libc/intrin/g_fds.c | 2 +- libc/sysv/consts.sh | 5 +++-- tool/emacs/cosmo-cpp-constants.el | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libc/calls/calls.h b/libc/calls/calls.h index 7ee4d2083..bc1e1ea12 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -35,11 +35,10 @@ #define WIFCONTINUED(s) ((s) == 0xffff) #define WIFEXITED(s) (!WTERMSIG(s)) #define WIFSIGNALED(s) ((0xffff & (s)) - 1u < 0xffu) -#define WIFSTOPPED(s) \ - ((short)(((0xffff & (unsigned)(s)) * 0x10001) >> 8) > 0x7f00) -#define WSTOPSIG(s) WEXITSTATUS(s) -#define WTERMSIG(s) (127 & (s)) -#define W_STOPCODE(s) ((s) << 8 | 0177) +#define WIFSTOPPED(s) ((255 & (s)) == 127) +#define WSTOPSIG(s) WEXITSTATUS(s) +#define WTERMSIG(s) (127 & (s)) +#define W_STOPCODE(s) ((s) << 8 | 0177) #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/intrin/g_fds.c b/libc/intrin/g_fds.c index ab89ca54c..287084620 100644 --- a/libc/intrin/g_fds.c +++ b/libc/intrin/g_fds.c @@ -55,7 +55,7 @@ textstartup void InitializeFileDescriptors(void) { kMemtrackFdsStart + kMemtrackFdsSize); if (IsMetal()) { extern const char vga_console[]; - pushmov(&fds->f, 3ull); + fds->f = 3; if (_weaken(vga_console)) { fds->p[0].kind = pushpop(kFdConsole); fds->p[1].kind = pushpop(kFdConsole); diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index e69c43010..853b3b4fd 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -359,6 +359,8 @@ syscon fcntl2 F_GETFL 3 3 3 3 3 3 # unix consensus & faked nt syscon fcntl2 F_SETFL 4 4 4 4 4 4 # unix consensus & faked nt syscon fcntl2 F_SETOWN 8 6 6 6 6 -1 # bsd consensus syscon fcntl2 F_GETOWN 9 5 5 5 5 -1 # bsd consensus +syscon fcntl2 F_SETOWN_EX 15 -1 -1 -1 -1 -1 # TODO(jart): polyfill +syscon fcntl2 F_GETOWN_EX 16 -1 -1 -1 -1 -1 # TODO(jart): polyfill syscon fcntl2 F_FULLFSYNC -1 51 -1 -1 -1 -1 # syscon fcntl2 F_BARRIERFSYNC -1 85 -1 -1 -1 -1 # syscon fcntl2 F_NOCACHE -1 48 -1 -1 -1 -1 # @@ -410,8 +412,6 @@ syscon ioctl FIOCLEX 0x5451 0x20006601 0x20006601 0x20006601 0x20006601 syscon ioctl FIONCLEX 0x5450 0x20006602 0x20006602 0x20006602 0x20006602 0x5450 # clears "close on exec" on file descriptor the fast way; faked nt #syscon ioctl FIONWRITE 0x0 0x0 0x40046677 0x0 0x0 -1 # [FreeBSD Generalization] bytes queued in FD's output buffer (same as TIOCOUTQ for TTY FDs; see also SO_SNDBUF) #syscon ioctl FIONSPACE 0x0 0x0 0x40046676 0x0 0x0 -1 # [FreeBSD Generalization] capacity of FD's output buffer, e.g. equivalent to TIOCGSERIAL w/ UART -syscon ioctl TIOCINQ 0x541b 0x4004667f 0x4004667f 0x4004667f 0x4004667f 0x4004667f # [Linuxism] same as FIONREAD -#syscon ioctl TIOCOUTQ 0x5411 0x40047473 0x40047473 0x40047473 0x40047473 -1 # bytes queued in TTY's output buffer # openat(), fstatat(), linkat(), etc. magnums # @@ -1340,6 +1340,7 @@ syscon compat TIOCSETAF 0x5404 0x80487416 0x802c7416 0x802c7416 0x802c74 #syscon compat TCSETAF 0x5404 0x80487416 0x802c7416 0x802c7416 0x802c7416 0x5402 # Drops input & drains output & sets console settings; ≈ ioctl(tty, TCSETAF, const struct termio *argp); polyfilled NT syscon termios TIOCGWINSZ 0x5413 1074295912 1074295912 1074295912 1074295912 0x5413 # ioctl(tty, TIOCGWINSZ, struct winsize *argp); polyfilled NT syscon termios TIOCSWINSZ 0x5414 0x80087467 0x80087467 0x80087467 0x80087467 0x5414 # ioctl(tty, TIOCSWINSZ, const struct winsize *argp) (faked NT) +syscon termios TIOCINQ 0x541b 0x4004667f 0x4004667f 0x4004667f 0x4004667f 0x4004667f # [Linuxism] same as FIONREAD syscon termios TIOCOUTQ 0x5411 0x40047473 0x40047473 0x40047473 0x40047473 0 # get # bytes queued in TTY's output buffer ioctl(tty, TIOCSWINSZ, const struct winsize *argp) syscon termios TIOCGPGRP 0x540f 0x40047477 0x40047477 0x40047477 0x40047477 0 # tcgetpgrp(): get pgrp of tty syscon termios TIOCSPGRP 0x5410 0x80047476 0x80047476 0x80047476 0x80047476 0 # tcsetpgrp(): set pgrp of tty diff --git a/tool/emacs/cosmo-cpp-constants.el b/tool/emacs/cosmo-cpp-constants.el index cbc2ca554..8805e040e 100644 --- a/tool/emacs/cosmo-cpp-constants.el +++ b/tool/emacs/cosmo-cpp-constants.el @@ -80,6 +80,7 @@ "__mips64" "__m68k__" "__riscv" + "__riscv_xlen" "__MICROBLAZE__" "__amd64__" "__WINT_MAX__"