From 4778cd4d27131374053ea797e14021fea7bb3d55 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Wed, 14 Jun 2023 17:02:57 -0700 Subject: [PATCH] Fix bugs in termios library and cleanup code This change fixes an issue with the tcflow() magic numbers that was causing bash to freeze up on Linux. While auditing termios polyfills, several other issues were identified with XNU/BSD compatibility. Out of an abundance of caution this change undefines as much surface area from libc/calls/struct/termios.h as possible, so that autoconf scripts are less likely to detect non-POSIX teletypewriter APIs that haven't been polyfilled by Cosmopolitan. This is a *breaking change* for your static archives in /opt/cosmos if you use the cosmocc toolchain. That's because this change disables the ioctl() undiamonding trick for code outside the monorepo, specifically because it'll lead to brittle ABI breakages like this. If you're using the cosmocc toolchain, you'll need to rebuild libraries like ncurses, readline, etc. Yes diamonds cause bloat. To work around that, consider using tcgetwinsize() instead of ioctl(TIOCGWINSZ) since it'll help you avoid pulling every single ioctl-related polyfill into the linkage. The cosmocc script was specifying -DNDEBUG for some reason. It's fixed. --- Makefile | 2 - ape/ape.lds | 5 +- build/config.mk | 64 +- build/definitions.mk | 7 +- dsp/tty/hidecursor.c | 1 - examples/kilo.c | 2 +- examples/nesemu1.cc | 3 +- examples/panels.c | 9 +- examples/script.c | 2 +- examples/ttyinfo.c | 8 +- libc/calls/_ptsname.c | 6 +- libc/calls/calls.mk | 13 +- libc/calls/cfspeed.c | 63 +- libc/calls/fcntl.c | 2 +- libc/calls/getttysize.c | 45 -- libc/calls/grantpt.c | 2 +- libc/calls/ioctl.c | 4 + libc/calls/ioctl.h | 21 +- libc/calls/ioctl_tcgets.c | 94 --- libc/calls/ioctl_tcsets.c | 85 --- libc/calls/ioctl_tiocgwinsz.c | 57 -- libc/calls/isptmaster.c | 2 + libc/calls/ntspawn.c | 2 +- libc/calls/openpty.c | 7 +- libc/{intrin => calls}/restoretty.c | 12 +- libc/calls/sigwinch-nt.c | 2 +- libc/calls/struct/metatermios.internal.h | 8 +- libc/calls/struct/termios.h | 21 +- libc/calls/struct/winsize.h | 2 - libc/calls/struct/winsize.internal.h | 5 +- libc/calls/tcdrain.c | 19 +- libc/calls/tcflow.c | 86 ++- libc/calls/tcflush.c | 13 +- .../{ioctl_tcgets-nt.c => tcgetattr-nt.c} | 2 +- libc/calls/tcgetattr.c | 70 +- libc/calls/tcgetpgrp.c | 11 +- libc/calls/tcgetsid.c | 15 +- ...octl_tiocgwinsz-nt.c => tcgetwinsize-nt.c} | 9 +- libc/calls/tcgetwinsize.c | 28 +- libc/calls/tcsendbreak.c | 16 +- .../{ioctl_tcsets-nt.c => tcsetattr-nt.c} | 5 +- libc/calls/tcsetattr.c | 83 ++- ...octl_tiocswinsz-nt.c => tcsetwinsize-nt.c} | 2 +- libc/calls/tcsetwinsize.c | 30 +- libc/calls/termios.internal.h | 45 +- libc/calls/termios2host.c | 2 +- libc/calls/ttyname_r.c | 3 +- libc/calls/unlockpt.c | 2 +- libc/calls/vdsofunc.greg.c | 12 +- libc/dns/gethoststxt.c | 2 +- libc/dns/getresolvconf.c | 2 +- libc/intrin/bits.h | 208 +++--- .../describewinsize.c} | 57 +- libc/intrin/g_fds.c | 2 +- libc/intrin/kopenflags.S | 4 - libc/intrin/{pushpop.h => pushpop.internal.h} | 6 +- libc/intrin/ubsan.c | 2 +- libc/runtime/clone.c | 2 +- libc/runtime/finddebugbinary.c | 2 +- libc/runtime/mprotect.c | 7 +- libc/runtime/openexecutable.S | 5 +- libc/runtime/opensymboltable.greg.c | 2 +- libc/runtime/printargs.c | 74 ++- libc/stdio/fflush_unlocked.c | 2 +- libc/str/lz4cpy.c | 2 +- libc/str/setlocale.c | 18 +- libc/sysv/consts.sh | 104 +-- libc/sysv/consts/BS0.S | 2 - libc/sysv/consts/BUSY.S | 2 - libc/sysv/consts/CBAUD.S | 2 - libc/sysv/consts/CBAUDEX.S | 2 - libc/sysv/consts/CIBAUD.S | 2 - libc/sysv/consts/CLOCAL.S | 2 +- libc/sysv/consts/CR0.S | 2 - libc/sysv/consts/CRTSCTS.S | 2 + libc/sysv/consts/EMPTY.S | 2 - libc/sysv/consts/ENDRUNDISC.S | 2 - libc/sysv/consts/ERA.S | 2 - libc/sysv/consts/EXTA.S | 2 - libc/sysv/consts/EXTB.S | 2 - libc/sysv/consts/FF0.S | 2 - libc/sysv/consts/FIODGNAME.S | 2 - libc/sysv/consts/H4DISC.S | 2 - libc/sysv/consts/NCCS.S | 2 - libc/sysv/consts/NETGRAPHDISC.S | 2 - libc/sysv/consts/NL0.S | 2 - libc/sysv/consts/NMEADISC.S | 2 - libc/sysv/consts/O_ACCMODE.S | 2 - libc/sysv/consts/O_RDONLY.S | 2 - libc/sysv/consts/O_WRONLY.S | 2 - libc/sysv/consts/PPPDISC.S | 2 - libc/sysv/consts/PTMGET.S | 2 - libc/sysv/consts/SLIPDISC.S | 2 - libc/sysv/consts/STRIPDISC.S | 2 - libc/sysv/consts/TAB0.S | 2 - libc/sysv/consts/TABLDISC.S | 2 - libc/sysv/consts/TCFLSH.S | 2 - libc/sysv/consts/TCGETS.S | 2 - libc/sysv/consts/TCIOFF.S | 2 - libc/sysv/consts/TCION.S | 2 - libc/sysv/consts/TCOOFF.S | 2 - libc/sysv/consts/TCOON.S | 2 - libc/sysv/consts/TCSADRAIN.S | 2 - libc/sysv/consts/TCSAFLUSH.S | 2 - libc/sysv/consts/TCSANOW.S | 2 - libc/sysv/consts/TCSBRK.S | 2 - libc/sysv/consts/TCSETS.S | 2 - libc/sysv/consts/TCSETSF.S | 2 - libc/sysv/consts/TCSETSW.S | 2 - libc/sysv/consts/TCXONC.S | 2 - libc/sysv/consts/TIOCCBRK.S | 2 - libc/sysv/consts/TIOCCDTR.S | 2 - libc/sysv/consts/TIOCCHKVERAUTH.S | 2 - libc/sysv/consts/TIOCEXT.S | 2 - libc/sysv/consts/TIOCFLAG_CLOCAL.S | 2 - libc/sysv/consts/TIOCFLAG_MDMBUF.S | 2 - libc/sysv/consts/TIOCFLAG_PPS.S | 2 - libc/sysv/consts/TIOCFLAG_SOFTCAR.S | 2 - libc/sysv/consts/TIOCFLUSH.S | 2 - libc/sysv/consts/TIOCGDRAINWAIT.S | 2 - libc/sysv/consts/TIOCGETA.S | 2 - libc/sysv/consts/TIOCGFLAGS.S | 2 - libc/sysv/consts/TIOCGPGRP.S | 2 - libc/sysv/consts/TIOCGSID.S | 2 - libc/sysv/consts/TIOCGTSTAMP.S | 2 - libc/sysv/consts/TIOCPTMASTER.S | 2 - libc/sysv/consts/TIOCPTSNAME.S | 2 - libc/sysv/consts/TIOCPTYGNAME.S | 2 - libc/sysv/consts/TIOCPTYGRANT.S | 2 - libc/sysv/consts/TIOCPTYUNLK.S | 2 - libc/sysv/consts/TIOCREMOTE.S | 2 - libc/sysv/consts/TIOCSBRK.S | 2 - libc/sysv/consts/TIOCSDRAINWAIT.S | 2 - libc/sysv/consts/TIOCSDTR.S | 2 - libc/sysv/consts/TIOCSERGETLSR.S | 2 - libc/sysv/consts/TIOCSERGETMULTI.S | 2 - libc/sysv/consts/TIOCSERSETMULTI.S | 2 - libc/sysv/consts/TIOCSER_TEMT.S | 2 - libc/sysv/consts/TIOCSETA.S | 2 - libc/sysv/consts/TIOCSETAF.S | 2 - libc/sysv/consts/TIOCSETAW.S | 2 - libc/sysv/consts/TIOCSETVERAUTH.S | 2 - libc/sysv/consts/TIOCSFLAGS.S | 2 - libc/sysv/consts/TIOCSTART.S | 2 - libc/sysv/consts/TIOCSTAT.S | 2 - libc/sysv/consts/TIOCSTI.S | 2 +- libc/sysv/consts/TIOCSTOP.S | 2 - libc/sysv/consts/TIOCSTSTAMP.S | 2 - libc/sysv/consts/TIOCTIMESTAMP.S | 2 - libc/sysv/consts/TIOCUCNTL_CBRK.S | 2 - libc/sysv/consts/TTYDISC.S | 2 - libc/sysv/consts/VERIFY.S | 2 - libc/sysv/consts/VT0.S | 2 - libc/sysv/consts/_POSIX_VDISABLE.S | 2 + libc/sysv/consts/o.h | 20 +- libc/sysv/consts/pty.h | 3 - libc/sysv/consts/termios.h | 624 +++++++----------- libc/zip.internal.h | 21 +- test/libc/fmt/palandprintf_test.c | 2 +- test/libc/runtime/grow_test.c | 2 +- test/net/https/argon2_test.c | 2 +- third_party/linenoise/linenoise.c | 2 +- third_party/lua/lunix.c | 8 +- third_party/python/Lib/test/test_ioctl.py | 98 --- third_party/python/Modules/posixmodule.c | 2 +- third_party/python/Modules/termios.c | 32 - third_party/python/Python/pystate.c | 2 +- third_party/python/python.mk | 3 - third_party/quickjs/quickjs-libc.c | 4 +- third_party/unzip/ttyio.c | 2 + tool/build/compile.c | 5 +- tool/build/lib/bits.h | 166 ----- tool/build/mv.c | 96 +-- tool/build/zipcopy.c | 3 - tool/emacs/cosmo-stuff.el | 7 +- tool/net/help.txt | 4 +- tool/net/redbean.c | 9 +- tool/scripts/cosmoc++ | 14 +- tool/scripts/cosmocc | 14 +- tool/viz/basicidea.c | 5 +- tool/viz/derasterize.c | 4 +- tool/viz/fontspace.c | 3 +- tool/viz/life.c | 9 +- tool/viz/memzoom.c | 9 +- tool/viz/printansi.c | 5 +- tool/viz/printimage.c | 5 +- tool/viz/printvideo.c | 4 +- 187 files changed, 1025 insertions(+), 1848 deletions(-) delete mode 100644 libc/calls/getttysize.c delete mode 100644 libc/calls/ioctl_tcgets.c delete mode 100644 libc/calls/ioctl_tcsets.c delete mode 100644 libc/calls/ioctl_tiocgwinsz.c rename libc/{intrin => calls}/restoretty.c (90%) rename libc/calls/{ioctl_tcgets-nt.c => tcgetattr-nt.c} (98%) rename libc/calls/{ioctl_tiocgwinsz-nt.c => tcgetwinsize-nt.c} (94%) rename libc/calls/{ioctl_tcsets-nt.c => tcsetattr-nt.c} (96%) rename libc/calls/{ioctl_tiocswinsz-nt.c => tcsetwinsize-nt.c} (97%) rename libc/{calls/ioctl_tiocswinsz.c => intrin/describewinsize.c} (68%) rename libc/intrin/{pushpop.h => pushpop.internal.h} (96%) delete mode 100644 libc/sysv/consts/BS0.S delete mode 100644 libc/sysv/consts/BUSY.S delete mode 100644 libc/sysv/consts/CBAUD.S delete mode 100644 libc/sysv/consts/CBAUDEX.S delete mode 100644 libc/sysv/consts/CIBAUD.S delete mode 100644 libc/sysv/consts/CR0.S create mode 100644 libc/sysv/consts/CRTSCTS.S delete mode 100644 libc/sysv/consts/EMPTY.S delete mode 100644 libc/sysv/consts/ENDRUNDISC.S delete mode 100644 libc/sysv/consts/ERA.S delete mode 100644 libc/sysv/consts/EXTA.S delete mode 100644 libc/sysv/consts/EXTB.S delete mode 100644 libc/sysv/consts/FF0.S delete mode 100644 libc/sysv/consts/FIODGNAME.S delete mode 100644 libc/sysv/consts/H4DISC.S delete mode 100644 libc/sysv/consts/NCCS.S delete mode 100644 libc/sysv/consts/NETGRAPHDISC.S delete mode 100644 libc/sysv/consts/NL0.S delete mode 100644 libc/sysv/consts/NMEADISC.S delete mode 100644 libc/sysv/consts/O_ACCMODE.S delete mode 100644 libc/sysv/consts/O_RDONLY.S delete mode 100644 libc/sysv/consts/O_WRONLY.S delete mode 100644 libc/sysv/consts/PPPDISC.S delete mode 100644 libc/sysv/consts/PTMGET.S delete mode 100644 libc/sysv/consts/SLIPDISC.S delete mode 100644 libc/sysv/consts/STRIPDISC.S delete mode 100644 libc/sysv/consts/TAB0.S delete mode 100644 libc/sysv/consts/TABLDISC.S delete mode 100644 libc/sysv/consts/TCFLSH.S delete mode 100644 libc/sysv/consts/TCGETS.S delete mode 100644 libc/sysv/consts/TCIOFF.S delete mode 100644 libc/sysv/consts/TCION.S delete mode 100644 libc/sysv/consts/TCOOFF.S delete mode 100644 libc/sysv/consts/TCOON.S delete mode 100644 libc/sysv/consts/TCSADRAIN.S delete mode 100644 libc/sysv/consts/TCSAFLUSH.S delete mode 100644 libc/sysv/consts/TCSANOW.S delete mode 100644 libc/sysv/consts/TCSBRK.S delete mode 100644 libc/sysv/consts/TCSETS.S delete mode 100644 libc/sysv/consts/TCSETSF.S delete mode 100644 libc/sysv/consts/TCSETSW.S delete mode 100644 libc/sysv/consts/TCXONC.S delete mode 100644 libc/sysv/consts/TIOCCBRK.S delete mode 100644 libc/sysv/consts/TIOCCDTR.S delete mode 100644 libc/sysv/consts/TIOCCHKVERAUTH.S delete mode 100644 libc/sysv/consts/TIOCEXT.S delete mode 100644 libc/sysv/consts/TIOCFLAG_CLOCAL.S delete mode 100644 libc/sysv/consts/TIOCFLAG_MDMBUF.S delete mode 100644 libc/sysv/consts/TIOCFLAG_PPS.S delete mode 100644 libc/sysv/consts/TIOCFLAG_SOFTCAR.S delete mode 100644 libc/sysv/consts/TIOCFLUSH.S delete mode 100644 libc/sysv/consts/TIOCGDRAINWAIT.S delete mode 100644 libc/sysv/consts/TIOCGETA.S delete mode 100644 libc/sysv/consts/TIOCGFLAGS.S delete mode 100644 libc/sysv/consts/TIOCGPGRP.S delete mode 100644 libc/sysv/consts/TIOCGSID.S delete mode 100644 libc/sysv/consts/TIOCGTSTAMP.S delete mode 100644 libc/sysv/consts/TIOCPTMASTER.S delete mode 100644 libc/sysv/consts/TIOCPTSNAME.S delete mode 100644 libc/sysv/consts/TIOCPTYGNAME.S delete mode 100644 libc/sysv/consts/TIOCPTYGRANT.S delete mode 100644 libc/sysv/consts/TIOCPTYUNLK.S delete mode 100644 libc/sysv/consts/TIOCREMOTE.S delete mode 100644 libc/sysv/consts/TIOCSBRK.S delete mode 100644 libc/sysv/consts/TIOCSDRAINWAIT.S delete mode 100644 libc/sysv/consts/TIOCSDTR.S delete mode 100644 libc/sysv/consts/TIOCSERGETLSR.S delete mode 100644 libc/sysv/consts/TIOCSERGETMULTI.S delete mode 100644 libc/sysv/consts/TIOCSERSETMULTI.S delete mode 100644 libc/sysv/consts/TIOCSER_TEMT.S delete mode 100644 libc/sysv/consts/TIOCSETA.S delete mode 100644 libc/sysv/consts/TIOCSETAF.S delete mode 100644 libc/sysv/consts/TIOCSETAW.S delete mode 100644 libc/sysv/consts/TIOCSETVERAUTH.S delete mode 100644 libc/sysv/consts/TIOCSFLAGS.S delete mode 100644 libc/sysv/consts/TIOCSTART.S delete mode 100644 libc/sysv/consts/TIOCSTAT.S delete mode 100644 libc/sysv/consts/TIOCSTOP.S delete mode 100644 libc/sysv/consts/TIOCSTSTAMP.S delete mode 100644 libc/sysv/consts/TIOCTIMESTAMP.S delete mode 100644 libc/sysv/consts/TIOCUCNTL_CBRK.S delete mode 100644 libc/sysv/consts/TTYDISC.S delete mode 100644 libc/sysv/consts/VERIFY.S delete mode 100644 libc/sysv/consts/VT0.S create mode 100644 libc/sysv/consts/_POSIX_VDISABLE.S delete mode 100644 third_party/python/Lib/test/test_ioctl.py delete mode 100755 tool/build/lib/bits.h diff --git a/Makefile b/Makefile index b25412dab..3c367066a 100644 --- a/Makefile +++ b/Makefile @@ -201,8 +201,6 @@ include tool/build/lib/buildlib.mk include third_party/chibicc/chibicc.mk include third_party/chibicc/test/test.mk include third_party/python/python.mk -include tool/build/emucrt/emucrt.mk -include tool/build/emubin/emubin.mk include tool/build/build.mk include tool/curl/curl.mk include third_party/qemu/qemu.mk diff --git a/ape/ape.lds b/ape/ape.lds index 8bb10ad86..ebc6c81ae 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -356,6 +356,7 @@ SECTIONS { PROVIDE_HIDDEN(__fini_array_start = .); KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) + KEEP(*(.fini_array)) KEEP(*(.dtors)) PROVIDE_HIDDEN(__fini_array_end = .); @@ -376,7 +377,7 @@ SECTIONS { /* initialization image for thread-local storage, this is copied */ /* out to actual TLS areas at runtime, so just make it read-only */ - .tdata . : { + .tdata : { _tdata_start = .; *(SORT_BY_ALIGNMENT(.tdata)) *(SORT_BY_ALIGNMENT(.tdata.*)) @@ -387,7 +388,7 @@ SECTIONS { /* this only tells the linker about the layout of uninitialized */ /* TLS data, and does not advance the linker's location counter */ - .tbss . : { + .tbss : { _tbss_start = .; *(SORT_BY_ALIGNMENT(.tbss)) *(SORT_BY_ALIGNMENT(.tbss.*)) diff --git a/build/config.mk b/build/config.mk index bafe076cc..db149cd81 100644 --- a/build/config.mk +++ b/build/config.mk @@ -13,12 +13,14 @@ # ifeq ($(MODE),) ENABLE_FTRACE = 1 +CONFIG_OFLAGS ?= -g CONFIG_CCFLAGS += $(BACKTRACES) -O2 CONFIG_CPPFLAGS += -DSYSDEBUG TARGET_ARCH ?= -msse3 endif ifeq ($(MODE), aarch64) ENABLE_FTRACE = 1 +CONFIG_OFLAGS ?= -g CONFIG_CCFLAGS += -O2 $(BACKTRACES) CONFIG_CPPFLAGS += -DSYSDEBUG endif @@ -31,11 +33,13 @@ endif # - Better GDB debugging # ifeq ($(MODE), zero) +CONFIG_OFLAGS ?= -g OVERRIDE_CFLAGS += -O0 OVERRIDE_CXXFLAGS += -O0 CONFIG_CPPFLAGS += -DSYSDEBUG endif ifeq ($(MODE), aarch64-zero) +CONFIG_OFLAGS ?= -g OVERRIDE_CFLAGS += -O0 OVERRIDE_CXXFLAGS += -O0 CONFIG_CPPFLAGS += -DSYSDEBUG @@ -55,7 +59,6 @@ ifeq ($(MODE), fastbuild) ENABLE_FTRACE = 1 CONFIG_CCFLAGS += $(BACKTRACES) -O CONFIG_CPPFLAGS += -DSYSDEBUG -DDWARFLESS -CONFIG_OFLAGS += -g0 CONFIG_LDFLAGS += -S TARGET_ARCH ?= -msse3 endif @@ -74,9 +77,10 @@ endif # ifeq ($(MODE), opt) ENABLE_FTRACE = 1 +CONFIG_OFLAGS ?= -g CONFIG_CPPFLAGS += -DNDEBUG -DSYSDEBUG -msse2avx -Wa,-msse2avx CONFIG_CCFLAGS += $(BACKTRACES) -O3 -fmerge-all-constants -TARGET_ARCH ?= -march=native +TARGET_ARCH ?= -march=skylake endif # Optimized Linux Mode @@ -89,6 +93,7 @@ endif # - Turns off support for other operating systems # ifeq ($(MODE), optlinux) +CONFIG_OFLAGS ?= -g CONFIG_CPPFLAGS += -DNDEBUG -msse2avx -Wa,-msse2avx -DSUPPORT_VECTOR=1 CONFIG_CCFLAGS += -O3 -fmerge-all-constants CONFIG_COPTS += -mred-zone @@ -103,6 +108,7 @@ endif # - More optimized # - Reasonably small # - Numeric backtraces +# - No DWARF data bloat # - Toilsome debuggability # - assert() statements removed # - DCHECK_xx() statements removed @@ -129,6 +135,7 @@ endif # ifeq ($(MODE), asan) ENABLE_FTRACE = 1 +CONFIG_OFLAGS ?= -g CONFIG_CCFLAGS += $(BACKTRACES) -O2 -DSYSDEBUG CONFIG_COPTS += -fsanitize=address TARGET_ARCH ?= -msse3 @@ -147,6 +154,7 @@ endif # ifeq ($(MODE), dbg) ENABLE_FTRACE = 1 +CONFIG_OFLAGS ?= -g CONFIG_CPPFLAGS += -DMODE_DBG CONFIG_CCFLAGS += $(BACKTRACES) -DSYSDEBUG -O0 -fno-inline CONFIG_COPTS += -fsanitize=address -fsanitize=undefined @@ -156,6 +164,7 @@ QUOTA ?= -C64 -L300 endif ifeq ($(MODE), aarch64-dbg) ENABLE_FTRACE = 1 +CONFIG_OFLAGS ?= -g CONFIG_CPPFLAGS += -DMODE_DBG CONFIG_CCFLAGS += $(BACKTRACES) -DSYSDEBUG -O0 -fno-inline CONFIG_COPTS += -fsanitize=undefined @@ -174,6 +183,7 @@ endif # ifeq ($(MODE), sysv) ENABLE_FTRACE = 1 +CONFIG_OFLAGS ?= -g CONFIG_CCFLAGS += $(BACKTRACES) -O2 CONFIG_CPPFLAGS += -DSYSDEBUG -DSUPPORT_VECTOR=121 TARGET_ARCH ?= -msse3 @@ -206,10 +216,6 @@ CONFIG_CCFLAGS += \ -momit-leaf-frame-pointer \ -foptimize-sibling-calls \ -DDWARFLESS -CONFIG_OFLAGS += \ - -g0 -CONFIG_LDFLAGS += \ - -S TARGET_ARCH ?= \ -msse3 PYFLAGS += \ @@ -232,10 +238,6 @@ CONFIG_CCFLAGS += \ -momit-leaf-frame-pointer \ -foptimize-sibling-calls \ -DDWARFLESS -CONFIG_OFLAGS += \ - -g0 -CONFIG_LDFLAGS += \ - -S PYFLAGS += \ -O2 \ -B @@ -261,10 +263,6 @@ CONFIG_CPPFLAGS += \ -DTRUSTWORTHY \ -DSUPPORT_VECTOR=1 \ -DDWARFLESS -CONFIG_OFLAGS += \ - -g0 -CONFIG_LDFLAGS += \ - -S CONFIG_CCFLAGS += \ -Os \ -fno-align-functions \ @@ -296,10 +294,6 @@ CONFIG_CPPFLAGS += \ -DTRUSTWORTHY \ -DSUPPORT_VECTOR=113 \ -DDWARFLESS -CONFIG_OFLAGS += \ - -g0 -CONFIG_LDFLAGS += \ - -S CONFIG_CCFLAGS += \ -Os \ -fno-align-functions \ @@ -336,10 +330,6 @@ CONFIG_CCFLAGS += \ -fno-align-jumps \ -fno-align-labels \ -fno-align-loops -CONFIG_OFLAGS += \ - -g0 -CONFIG_LDFLAGS += \ - -S TARGET_ARCH ?= \ -msse3 endif @@ -370,37 +360,10 @@ CONFIG_CCFLAGS += \ -fno-align-jumps \ -fno-align-labels \ -fno-align-loops -CONFIG_OFLAGS += \ - -g0 -CONFIG_LDFLAGS += \ - -S TARGET_ARCH ?= \ -msse3 endif -# GCC11 Mode -# https://justine.lol/compilers/x86_64-linux-musl__x86_64-linux-musl__g++-11.2.0.tar.xz -ifeq ($(MODE), gcc11) -ENABLE_FTRACE = 1 -.UNVEIL += rx:/opt/gcc11 -CONFIG_CCFLAGS += $(BACKTRACES) -DSYSDEBUG -O2 -AS = /opt/gcc11/bin/x86_64-linux-musl-as -CC = /opt/gcc11/bin/x86_64-linux-musl-gcc -CXX = /opt/gcc11/bin/x86_64-linux-musl-g++ -CXXFILT = /opt/gcc11/bin/x86_64-linux-musl-c++filt -LD = /opt/gcc11/bin/x86_64-linux-musl-ld.bfd -NM = /opt/gcc11/bin/x86_64-linux-musl-nm -GCC = /opt/gcc11/bin/x86_64-linux-musl-gcc -STRIP = /opt/gcc11/bin/x86_64-linux-musl-strip -OBJCOPY = /opt/gcc11/bin/x86_64-linux-musl-objcopy -OBJDUMP = /opt/gcc11/bin/x86_64-linux-musl-objdump -ADDR2LINE = /opt/gcc11/bin/x86_64-linux-musl-addr2line -CONFIG_CCFLAGS += $(BACKTRACES) -O2 -Wno-stringop-overread -CONFIG_CFLAGS += -Wno-old-style-definition -CONFIG_CPPFLAGS += -DNDEBUG -DSYSDEBUG -TARGET_ARCH ?= -msse3 -endif - # LLVM Mode ifeq ($(MODE), llvm) TARGET_ARCH ?= -msse3 @@ -442,14 +405,11 @@ endif # such as MSVC or XCode. You can run your binary objects through a tool # like objconv to convert them to COFF or MachO. Then use ANSI mode to # rollup one header file that'll enable linkage with minimal issues. - ifeq ($(MODE), ansi) - CONFIG_CFLAGS += -std=c11 #CONFIG_CPPFLAGS += -ansi CONFIG_CXXFLAGS += -std=c++11 TARGET_ARCH ?= -msse3 - endif ifneq ($(ENABLE_FTRACE),) diff --git a/build/definitions.mk b/build/definitions.mk index 41d958c38..cd4d9f430 100644 --- a/build/definitions.mk +++ b/build/definitions.mk @@ -175,11 +175,6 @@ DEFAULT_CCFLAGS += \ -fdebug-prefix-map='$(PWD)'= \ -frecord-gcc-switches -DEFAULT_OFLAGS ?= \ - -g \ - -gdwarf-4 \ - -gdescribe-dies - DEFAULT_COPTS ?= \ -fno-math-errno \ -fno-ident \ @@ -246,7 +241,7 @@ DEFAULT_LDFLAGS = \ -nostdlib \ --gc-sections \ --build-id=none \ - --no-dynamic-linker #--cref -Map=$@.map + --no-dynamic-linker --cref -Map=$@.map ifeq ($(ARCH), aarch64) DEFAULT_LDFLAGS += \ diff --git a/dsp/tty/hidecursor.c b/dsp/tty/hidecursor.c index 9d9353fc0..be3460e9c 100644 --- a/dsp/tty/hidecursor.c +++ b/dsp/tty/hidecursor.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/tty.h" -#include "libc/intrin/pushpop.h" #include "libc/dce.h" #include "libc/log/internal.h" #include "libc/log/log.h" diff --git a/examples/kilo.c b/examples/kilo.c index f64321df2..eeed5cb3c 100644 --- a/examples/kilo.c +++ b/examples/kilo.c @@ -355,7 +355,7 @@ int getCursorPosition(int64_t ifd, int64_t ofd, int *rows, int *cols) { * Returns 0 on success, -1 on error. */ int getWindowSize(int64_t ifd, int64_t ofd, int *rows, int *cols) { struct winsize ws; - if (_getttysize(1, &ws) == -1 || ws.ws_col == 0) { + if (tcgetwinsize(1, &ws) == -1 || ws.ws_col == 0) { /* ioctl() failed. Try to query the terminal itself. */ int orig_row, orig_col, retval; diff --git a/examples/nesemu1.cc b/examples/nesemu1.cc index 1f4417de4..e3984adfb 100644 --- a/examples/nesemu1.cc +++ b/examples/nesemu1.cc @@ -14,6 +14,7 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" @@ -287,7 +288,7 @@ void GetTermSize(void) { struct winsize wsize_; wsize_.ws_row = 25; wsize_.ws_col = 80; - _getttysize(0, &wsize_); + tcgetwinsize(0, &wsize_); FreeSamplingSolution(ssy_); FreeSamplingSolution(ssx_); tyn_ = wsize_.ws_row * 2; diff --git a/examples/panels.c b/examples/panels.c index ebb62c81b..8ae42a697 100644 --- a/examples/panels.c +++ b/examples/panels.c @@ -12,6 +12,7 @@ #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/termios.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/dce.h" #include "libc/log/check.h" #include "libc/log/gdb.h" @@ -77,7 +78,7 @@ void GetTtySize(void) { struct winsize wsize; wsize.ws_row = tyn; wsize.ws_col = txn; - _getttysize(1, &wsize); + tcgetwinsize(1, &wsize); tyn = wsize.ws_row; txn = wsize.ws_col; } @@ -87,7 +88,7 @@ int Write(const char *s) { } void Setup(void) { - CHECK_NE(-1, ioctl(1, TCGETS, &oldterm)); + CHECK_NE(-1, tcgetattr(1, &oldterm)); } void Enter(void) { @@ -100,13 +101,13 @@ void Enter(void) { term.c_cflag &= ~(CSIZE | PARENB); term.c_cflag |= CS8; term.c_iflag |= IUTF8; - CHECK_NE(-1, ioctl(1, TCSETS, &term)); + CHECK_NE(-1, tcsetattr(1, TCSANOW, &term)); Write("\e[?25l"); } void Leave(void) { Write(gc(xasprintf("\e[?25h\e[%d;%dH\e[S\r\n", tyn, txn))); - ioctl(1, TCSETS, &oldterm); + tcsetattr(1, TCSANOW, &oldterm); } void Clear(void) { diff --git a/examples/script.c b/examples/script.c index bf280ff0c..eae4f65b1 100644 --- a/examples/script.c +++ b/examples/script.c @@ -177,7 +177,7 @@ main(int argc, char *argv[]) playback(fscript); if (tcgetattr(STDIN_FILENO, &tt) == -1 || - ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) { + tcgetwinsize(STDIN_FILENO, &win) == -1) { if (errno != ENOTTY) /* For debugger. */ err(1, "tcgetattr/ioctl"); if (openpty(&master, &slave, NULL, NULL, NULL) == -1) diff --git a/examples/ttyinfo.c b/examples/ttyinfo.c index a1a2bbe28..fd8b73a17 100644 --- a/examples/ttyinfo.c +++ b/examples/ttyinfo.c @@ -48,14 +48,14 @@ void onkilled(int sig) { void restoretty(void) { WRITE(1, DISABLE_MOUSE_TRACKING); - ioctl(1, TCSETS, &oldterm); + tcsetattr(1, TCSANOW, &oldterm); } int rawmode(void) { static bool once; struct termios t; if (!once) { - if (ioctl(1, TCGETS, &oldterm) != -1) { + if (tcgetattr(1, &oldterm) != -1) { atexit(restoretty); } else { return -1; @@ -72,7 +72,7 @@ int rawmode(void) { t.c_oflag &= ~OPOST; t.c_cflag |= CS8; t.c_iflag |= IUTF8; - ioctl(1, TCSETS, &t); + tcsetattr(1, TCSANOW, &t); WRITE(1, ENABLE_SAFE_PASTE); WRITE(1, ENABLE_MOUSE_TRACKING); WRITE(1, PROBE_DISPLAY_SIZE); @@ -80,7 +80,7 @@ int rawmode(void) { } void getsize(void) { - if (_getttysize(1, &wsize) != -1) { + if (tcgetwinsize(1, &wsize) != -1) { printf("termios says terminal size is %hu×%hu\r\n", wsize.ws_col, wsize.ws_row); } else { diff --git a/libc/calls/_ptsname.c b/libc/calls/_ptsname.c index 5a6809899..93f870c3e 100644 --- a/libc/calls/_ptsname.c +++ b/libc/calls/_ptsname.c @@ -25,9 +25,11 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" -extern const unsigned FIODGNAME; extern const unsigned TIOCPTSNAME; -extern const unsigned TIOCPTYGNAME; + +#define TIOCPTYGNAME 0x40807453 // xnu +#define TIOCPTSNAME 0x48087448 // netbsd +#define FIODGNAME 0x80106678 // freebsd struct fiodgname_arg { int len; diff --git a/libc/calls/calls.mk b/libc/calls/calls.mk index 5d1f08c8f..2cb92d6cf 100644 --- a/libc/calls/calls.mk +++ b/libc/calls/calls.mk @@ -105,6 +105,8 @@ o/$(MODE)/libc/calls/ntcontext2linux.o: private \ # we always want -O3 because: # it makes the code size smaller too +# we need -mstringop-strategy=loop because: +# privileged code might generate memcpy call o/$(MODE)/libc/calls/termios2host.o \ o/$(MODE)/libc/calls/sigenter-freebsd.o \ o/$(MODE)/libc/calls/sigenter-netbsd.o \ @@ -112,7 +114,8 @@ o/$(MODE)/libc/calls/sigenter-openbsd.o \ o/$(MODE)/libc/calls/sigenter-xnu.o \ o/$(MODE)/libc/calls/ntcontext2linux.o: private \ COPTS += \ - -O3 + -O3 \ + -mstringop-strategy=loop # we must disable static stack safety because: # these functions use alloca(n) @@ -147,14 +150,6 @@ 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 \ CFLAGS += \ -Os diff --git a/libc/calls/cfspeed.c b/libc/calls/cfspeed.c index e6a388a1d..1afe618ac 100644 --- a/libc/calls/cfspeed.c +++ b/libc/calls/cfspeed.c @@ -17,18 +17,22 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/termios.h" +#include "libc/dce.h" #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" +#define CBAUD 0x100f +#define CBAUDEX 0x1000 + /** * Returns input baud rate. * @asyncsignalsafe */ uint32_t cfgetispeed(const struct termios *t) { - if (CBAUD) { + if (IsLinux()) { return t->c_cflag & CBAUD; } else { - return t->c_ispeed; + return t->_c_ispeed; } } @@ -37,43 +41,23 @@ uint32_t cfgetispeed(const struct termios *t) { * @asyncsignalsafe */ uint32_t cfgetospeed(const struct termios *t) { - if (CBAUD) { + if (IsLinux()) { return t->c_cflag & CBAUD; } else { - return t->c_ospeed; + 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. * + * @param speed can be `B0`, `B50`, `B38400`, `B4000000`, etc. * @return 0 on success, or -1 w/ errno + * @raise EINVAL if `speed` isn't valid * @asyncsignalsafe */ -int cfsetospeed(struct termios *t, unsigned speed) { - if (CBAUD) { +int cfsetospeed(struct termios *t, uint32_t speed) { + if (IsLinux()) { if (!(speed & ~CBAUD)) { t->c_cflag &= ~CBAUD; t->c_cflag |= speed; @@ -82,7 +66,28 @@ int cfsetospeed(struct termios *t, unsigned speed) { return einval(); } } else { - t->c_ospeed = speed; + t->_c_ospeed = speed; + return 0; + } +} + +/** + * Sets input baud rate. + * + * @param speed can be `B0`, `B50`, `B38400`, `B4000000`, etc. + * @return 0 on success, or -1 w/ errno + * @raise EINVAL if `speed` isn't valid + * @asyncsignalsafe + */ +int cfsetispeed(struct termios *t, uint32_t speed) { + if (IsLinux()) { + if (speed) { + return cfsetospeed(t, speed); + } else { + return 0; + } + } else { + t->_c_ispeed = speed; return 0; } } diff --git a/libc/calls/fcntl.c b/libc/calls/fcntl.c index e77c4f1ce..45630aefb 100644 --- a/libc/calls/fcntl.c +++ b/libc/calls/fcntl.c @@ -158,7 +158,7 @@ int fcntl(int fd, int cmd, ...) { STRACE("fcntl(%d, %s, %s) → %d% m", fd, DescribeFcntlCmd(cmd), DescribeDnotifyFlags(arg), rc); } else { - STRACE("fcntl(%d, %s, %ld) → %#x% m", fd, DescribeFcntlCmd(cmd), arg, rc); + STRACE("fcntl(%d, %s, %ld) → %d% m", fd, DescribeFcntlCmd(cmd), arg, rc); } #endif diff --git a/libc/calls/getttysize.c b/libc/calls/getttysize.c deleted file mode 100644 index e1a5048c2..000000000 --- a/libc/calls/getttysize.c +++ /dev/null @@ -1,45 +0,0 @@ -/*-*- 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/struct/winsize.h" -#include "libc/fmt/conv.h" -#include "libc/intrin/safemacros.internal.h" -#include "libc/log/internal.h" -#include "libc/sysv/consts/termios.h" - -/** - * Returns dimensions of controlling terminal. - * - * It is recommended that programs err on the side of showing more - * information, if this value can't be obtained with certainty. - * - * @param out stores determined dimensions, only on success - * @returns -1 on error or something else on success - */ -int _getttysize(int fd, struct winsize *out) { - if (__nocolor) { - out->ws_col = atoi(firstnonnull(getenv("COLUMNS"), "80")); - out->ws_row = atoi(firstnonnull(getenv("ROWS"), "40")); - out->ws_xpixel = 0; - out->ws_ypixel = 0; - return 0; - } else { - return ioctl(fd, TIOCGWINSZ, out); - } -} diff --git a/libc/calls/grantpt.c b/libc/calls/grantpt.c index 9e221efdd..c1bb1d495 100644 --- a/libc/calls/grantpt.c +++ b/libc/calls/grantpt.c @@ -22,7 +22,7 @@ #include "libc/dce.h" #include "libc/intrin/strace.internal.h" -extern const unsigned TIOCPTYGRANT; +#define TIOCPTYGRANT 0x20007454 /** * Grants access to subordinate pseudoteletypewriter. diff --git a/libc/calls/ioctl.c b/libc/calls/ioctl.c index 0f6e4685c..82dcb029d 100644 --- a/libc/calls/ioctl.c +++ b/libc/calls/ioctl.c @@ -20,6 +20,8 @@ #undef __STRICT_ANSI__ #endif #include "libc/calls/ioctl.h" +#include "libc/calls/termios.h" +#include "libc/sysv/consts/termios.h" #define EQUAL(X, Y) ((X) == (Y)) @@ -34,5 +36,7 @@ int(ioctl)(int fd, uint64_t request, ...) { va_start(va, request); arg = va_arg(va, void *); va_end(va); + if (request == TIOCGWINSZ) return tcgetwinsize(fd, arg); + if (request == TIOCSWINSZ) return tcsetwinsize(fd, arg); return __IOCTL_DISPATCH(EQUAL, -1, fd, request, arg); } diff --git a/libc/calls/ioctl.h b/libc/calls/ioctl.h index 0ce6246b2..af78342ef 100644 --- a/libc/calls/ioctl.h +++ b/libc/calls/ioctl.h @@ -1,5 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_IOCTL_H_ #define COSMOPOLITAN_LIBC_CALLS_IOCTL_H_ +#include "libc/calls/termios.h" #include "libc/sysv/consts/fio.h" #include "libc/sysv/consts/sio.h" #include "libc/sysv/consts/termios.h" @@ -12,7 +13,7 @@ COSMOPOLITAN_C_START_ int ioctl(int, uint64_t, ...); -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(COSMO) /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § system calls » ioctl » undiamonding ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ @@ -26,19 +27,7 @@ int ioctl(int, uint64_t, ...); #define __IOCTL_DISPATCH(CMP, DEFAULT, FD, REQUEST, ...) \ ({ \ int ReZ; \ - if (CMP(REQUEST, TIOCGWINSZ)) { \ - ReZ = ioctl_tiocgwinsz(FD, ##__VA_ARGS__); \ - } else if (CMP(REQUEST, TIOCSWINSZ)) { \ - ReZ = ioctl_tiocswinsz(FD, ##__VA_ARGS__); \ - } else if (CMP(REQUEST, TCGETS)) { \ - ReZ = ioctl_tcgets(FD, ##__VA_ARGS__); \ - } else if (CMP(REQUEST, TCSETS)) { \ - ReZ = ioctl_tcsets(FD, REQUEST, ##__VA_ARGS__); \ - } else if (CMP(REQUEST, TCSETSW)) { \ - ReZ = ioctl_tcsets(FD, REQUEST, ##__VA_ARGS__); \ - } else if (CMP(REQUEST, TCSETSF)) { \ - ReZ = ioctl_tcsets(FD, REQUEST, ##__VA_ARGS__); \ - } else if (CMP(REQUEST, SIOCGIFCONF)) { \ + if (CMP(REQUEST, SIOCGIFCONF)) { \ ReZ = ioctl_siocgifconf(FD, ##__VA_ARGS__); \ } else if (CMP(REQUEST, SIOCGIFADDR)) { \ ReZ = ioctl_siocgifaddr(FD, ##__VA_ARGS__); \ @@ -70,10 +59,6 @@ int ioctl_siocgifconf(int, ...); int ioctl_siocgifdstaddr(int, ...); int ioctl_siocgifflags(int, ...); int ioctl_siocgifnetmask(int, ...); -int ioctl_tcgets(int, ...); -int ioctl_tcsets(int, uint64_t, ...); -int ioctl_tiocgwinsz(int, ...); -int ioctl_tiocswinsz(int, ...); #endif /* GNUC && !ANSI */ COSMOPOLITAN_C_END_ diff --git a/libc/calls/ioctl_tcgets.c b/libc/calls/ioctl_tcgets.c deleted file mode 100644 index c705f818f..000000000 --- a/libc/calls/ioctl_tcgets.c +++ /dev/null @@ -1,94 +0,0 @@ -/*-*- 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/calls/ioctl.h" -#include "libc/calls/struct/metatermios.internal.h" -#include "libc/calls/syscall-sysv.internal.h" -#include "libc/calls/termios.internal.h" -#include "libc/calls/ttydefaults.h" -#include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/strace.internal.h" -#include "libc/str/str.h" -#include "libc/sysv/consts/termios.h" -#include "libc/sysv/errfuns.h" - -int ioctl_tcgets_nt(int, struct termios *) _Hide; - -static int ioctl_tcgets_metal(int fd, struct termios *tio) { - bzero(tio, sizeof(*tio)); - tio->c_iflag = TTYDEF_IFLAG; - tio->c_oflag = TTYDEF_OFLAG; - tio->c_lflag = TTYDEF_LFLAG; - tio->c_cflag = TTYDEF_CFLAG; - return 0; -} - -static int ioctl_tcgets_sysv(int fd, struct termios *tio) { - int rc; - union metatermios mt; - if (IsLinux()) { - if (IsAsan() && !__asan_is_valid(tio, sizeof(*tio))) return efault(); - return sys_ioctl(fd, TCGETS, tio); - } else { - if ((rc = sys_ioctl(fd, TCGETS, &mt)) != -1) { - if (IsXnu()) { - COPY_TERMIOS(tio, &mt.xnu); - } else if (IsFreebsd() || IsOpenbsd() || IsNetbsd()) { - COPY_TERMIOS(tio, &mt.bsd); - } else { - __builtin_unreachable(); - } - } - return rc; - } -} - -/** - * Returns information about terminal. - * - * @see tcgetattr(fd, tio) dispatches here - * @see ioctl(fd, TCGETS, tio) dispatches here - * @see ioctl(fd, TIOCGETA, tio) dispatches here - */ -int ioctl_tcgets(int fd, ...) { - int rc; - va_list va; - struct termios *tio; - va_start(va, fd); - tio = va_arg(va, struct termios *); - va_end(va); - if (fd >= 0) { - if (!tio || (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) { - rc = efault(); - } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = enotty(); - } else if (IsMetal()) { - rc = ioctl_tcgets_metal(fd, tio); - } else if (!IsWindows()) { - rc = ioctl_tcgets_sysv(fd, tio); - } else { - rc = ioctl_tcgets_nt(fd, tio); - } - } else { - rc = einval(); - } - STRACE("ioctl_tcgets(%d, %p) → %d% m", fd, tio, rc); - return rc; -} diff --git a/libc/calls/ioctl_tcsets.c b/libc/calls/ioctl_tcsets.c deleted file mode 100644 index 94099bd14..000000000 --- a/libc/calls/ioctl_tcsets.c +++ /dev/null @@ -1,85 +0,0 @@ -/*-*- 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/calls/ioctl.h" -#include "libc/calls/struct/metatermios.internal.h" -#include "libc/calls/syscall-sysv.internal.h" -#include "libc/calls/termios.internal.h" -#include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/nomultics.internal.h" -#include "libc/intrin/strace.internal.h" -#include "libc/intrin/weaken.h" -#include "libc/sysv/consts/termios.h" -#include "libc/sysv/errfuns.h" - -void __on_ioctl_tcsets(int); -int ioctl_tcsets_nt(int, uint64_t, const struct termios *); - -static int ioctl_tcsets_metal(int fd, uint64_t request, - const struct termios *tio) { - return 0; -} - -static int ioctl_tcsets_sysv(int fd, uint64_t request, - const struct termios *tio) { - union metatermios mt; - if (IsAsan() && !__asan_is_valid(tio, sizeof(*tio))) return efault(); - return sys_ioctl(fd, request, __termios2host(&mt, tio)); -} - -/** - * Changes terminal behavior. - * - * @see tcsetattr(fd, TCSA{NOW,DRAIN,FLUSH}, tio) dispatches here - * @see ioctl(fd, TCSETS{,W,F}, tio) dispatches here - * @see ioctl(fd, TIOCGETA{,W,F}, tio) dispatches here - */ -int ioctl_tcsets(int fd, uint64_t request, ...) { - int rc; - va_list va; - static bool once; - const struct termios *tio; - va_start(va, request); - tio = va_arg(va, const struct termios *); - va_end(va); - if (0 <= fd && fd <= 2 && _weaken(__on_ioctl_tcsets)) { - if (!once) { - _weaken(__on_ioctl_tcsets)(fd); - once = true; - } - } - if (!tio || (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) { - rc = efault(); - } else if (fd >= 0) { - if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = enotty(); - } else if (IsMetal()) { - rc = ioctl_tcsets_metal(fd, request, tio); - } else if (!IsWindows()) { - rc = ioctl_tcsets_sysv(fd, request, tio); - } else { - rc = ioctl_tcsets_nt(fd, request, tio); - } - } else { - rc = einval(); - } - STRACE("ioctl_tcsets(%d, %p, %p) → %d% m", fd, request, tio, rc); - return rc; -} diff --git a/libc/calls/ioctl_tiocgwinsz.c b/libc/calls/ioctl_tiocgwinsz.c deleted file mode 100644 index c5a53fc3c..000000000 --- a/libc/calls/ioctl_tiocgwinsz.c +++ /dev/null @@ -1,57 +0,0 @@ -/*-*- 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/calls/ioctl.h" -#include "libc/calls/struct/winsize.h" -#include "libc/calls/struct/winsize.internal.h" -#include "libc/calls/syscall-sysv.internal.h" -#include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/strace.internal.h" -#include "libc/sysv/consts/termios.h" -#include "libc/sysv/errfuns.h" - -/** - * Returns width and height of terminal. - * - * @see ioctl(fd, TIOCGWINSZ, ws) dispatches here - */ -int ioctl_tiocgwinsz(int fd, ...) { - int rc; - va_list va; - struct winsize *ws; - va_start(va, fd); - ws = va_arg(va, struct winsize *); - va_end(va); - if (IsAsan() && !__asan_is_valid(ws, sizeof(*ws))) { - rc = efault(); - } else if (fd >= 0) { - if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - rc = enotty(); - } else if (!IsWindows()) { - rc = sys_ioctl(fd, TIOCGWINSZ, ws); - } else { - rc = ioctl_tiocgwinsz_nt(g_fds.p + fd, ws); - } - } else { - rc = einval(); - } - STRACE("%s(%d) → %d% m", "ioctl_tiocgwinsz", fd, rc); - return rc; -} diff --git a/libc/calls/isptmaster.c b/libc/calls/isptmaster.c index 0b4c2eb58..57e342b5f 100644 --- a/libc/calls/isptmaster.c +++ b/libc/calls/isptmaster.c @@ -22,6 +22,8 @@ #include "libc/errno.h" #include "libc/sysv/consts/termios.h" +#define TIOCPTMASTER 0x2000741c + int _isptmaster(int fd) { if (IsFreebsd()) { if (!sys_ioctl(fd, TIOCPTMASTER)) { diff --git a/libc/calls/ntspawn.c b/libc/calls/ntspawn.c index 5632d33ec..cdcc07e76 100644 --- a/libc/calls/ntspawn.c +++ b/libc/calls/ntspawn.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/ntspawn.h" #include "libc/calls/syscall_support-nt.internal.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/macros.internal.h" #include "libc/nt/enum/filemapflags.h" #include "libc/nt/enum/pageflags.h" diff --git a/libc/calls/openpty.c b/libc/calls/openpty.c index bbd6944c2..3ea8300c8 100644 --- a/libc/calls/openpty.c +++ b/libc/calls/openpty.c @@ -38,6 +38,8 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" +#define PTMGET 0x40287401 // openbsd + struct IoctlPtmGet { int m; int s; @@ -49,7 +51,6 @@ static int openpty_impl(int *mfd, int *sfd, char *name, const struct termios *tio, // const struct winsize *wsz) { int m, s, p; - union metatermios mt; struct IoctlPtmGet t; RETURN_ON_ERROR((m = posix_openpt(O_RDWR | O_NOCTTY))); if (!IsOpenbsd()) { @@ -66,8 +67,8 @@ static int openpty_impl(int *mfd, int *sfd, char *name, *mfd = m; *sfd = s; if (name) strcpy(name, t.sname); - if (tio) _npassert(!sys_ioctl(s, TCSETSF, __termios2host(&mt, tio))); - if (wsz) _npassert(!sys_ioctl(s, TIOCGWINSZ, wsz)); + if (tio) _npassert(!tcsetattr(s, TCSAFLUSH, tio)); + if (wsz) _npassert(!tcgetwinsize(s, wsz)); return 0; OnError: if (m != -1) sys_close(m); diff --git a/libc/intrin/restoretty.c b/libc/calls/restoretty.c similarity index 90% rename from libc/intrin/restoretty.c rename to libc/calls/restoretty.c index afe274162..ad69f2cf4 100644 --- a/libc/intrin/restoretty.c +++ b/libc/calls/restoretty.c @@ -17,7 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/metatermios.internal.h" +#include "libc/calls/struct/termios.h" #include "libc/calls/syscall-sysv.internal.h" +#include "libc/calls/termios.h" #include "libc/errno.h" #include "libc/log/internal.h" #include "libc/runtime/runtime.h" @@ -36,7 +38,7 @@ #define ANSI_RESTORE RESET_COLOR SHOW_CURSOR DISABLE_MOUSE static bool __isrestorable; -static union metatermios __oldtermios; +static struct termios __oldtermios; static size_t __strlen(const char *s) { size_t i = 0; @@ -44,11 +46,11 @@ static size_t __strlen(const char *s) { return i; } -// called weakly by libc/calls/ioctl_tcsets.c to avoid pledge("tty") -void __on_ioctl_tcsets(int fd) { +// called weakly by libc/calls/tcsetattr.c to avoid pledge("tty") +void __on_tcsetattr(int fd) { int e; e = errno; - if (sys_ioctl(fd, TCGETS, &__oldtermios) != -1) { + if (tcgetattr(fd, &__oldtermios) != -1) { __isrestorable = true; } errno = e; @@ -59,7 +61,7 @@ void __restore_tty(void) { if (__isrestorable && !__isworker && !__nocolor) { e = errno; sys_write(0, ANSI_RESTORE, __strlen(ANSI_RESTORE)); - sys_ioctl(0, TCSETSF, &__oldtermios); + tcsetattr(0, TCSAFLUSH, &__oldtermios); errno = e; } } diff --git a/libc/calls/sigwinch-nt.c b/libc/calls/sigwinch-nt.c index dc4330d96..b1d6ec731 100644 --- a/libc/calls/sigwinch-nt.c +++ b/libc/calls/sigwinch-nt.c @@ -45,7 +45,7 @@ textwindows void _check_sigwinch(struct Fd *fd) { old = __ws; e = errno; if (old.ws_row != 0xffff) { - if (ioctl_tiocgwinsz_nt(fd, &ws) != -1) { + if (tcgetwinsize_nt(fd, &ws) != -1) { if (old.ws_col != ws.ws_col || old.ws_row != ws.ws_row) { __ws = ws; if (old.ws_col | old.ws_row) { diff --git a/libc/calls/struct/metatermios.internal.h b/libc/calls/struct/metatermios.internal.h index fa2653281..2bb2f2685 100644 --- a/libc/calls/struct/metatermios.internal.h +++ b/libc/calls/struct/metatermios.internal.h @@ -10,8 +10,8 @@ struct termios_xnu { uint64_t c_cflag; uint64_t c_lflag; uint8_t c_cc[20]; - uint64_t c_ispeed; - uint64_t c_ospeed; + uint64_t _c_ispeed; + uint64_t _c_ospeed; }; struct termios_bsd { @@ -20,8 +20,8 @@ struct termios_bsd { uint32_t c_cflag; uint32_t c_lflag; uint8_t c_cc[20]; - uint32_t c_ispeed; - uint32_t c_ospeed; + uint32_t _c_ispeed; + uint32_t _c_ospeed; }; union metatermios { diff --git a/libc/calls/struct/termios.h b/libc/calls/struct/termios.h index 74e9fbc18..66cf7c2f5 100644 --- a/libc/calls/struct/termios.h +++ b/libc/calls/struct/termios.h @@ -1,20 +1,21 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TERMIOS_H_ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_TERMIOS_H_ + +#define NCCS 20 + #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct termios { /* GNU/Systemd ABI */ - uint32_t c_iflag; /* input modes */ - uint32_t c_oflag; /* output modes */ - uint32_t c_cflag; /* control modes */ - uint32_t c_lflag; /* local modes */ - uint8_t c_cc[20]; /* code mappings */ - uint32_t c_ispeed; /* input speed */ - uint32_t c_ospeed; /* output speed */ +struct termios { /* cosmo abi */ + uint32_t c_iflag; /* input modes */ + uint32_t c_oflag; /* output modes */ + uint32_t c_cflag; /* control modes */ + uint32_t c_lflag; /* local modes */ + uint8_t c_cc[NCCS]; /* code mappings */ + uint32_t _c_ispeed; /* use cfgetispeed() and cfsetispeed() */ + uint32_t _c_ospeed; /* use cfgetospeed() and cfsetospeed() */ }; -#define c_line c_cc[0] /* line discipline */ - COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TERMIOS_H_ */ diff --git a/libc/calls/struct/winsize.h b/libc/calls/struct/winsize.h index cb3fd652e..328b25a63 100644 --- a/libc/calls/struct/winsize.h +++ b/libc/calls/struct/winsize.h @@ -10,8 +10,6 @@ struct winsize { uint16_t ws_ypixel; }; -int _getttysize(int, struct winsize *); - COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_ */ diff --git a/libc/calls/struct/winsize.internal.h b/libc/calls/struct/winsize.internal.h index f59ebc89e..91d1b4d47 100644 --- a/libc/calls/struct/winsize.internal.h +++ b/libc/calls/struct/winsize.internal.h @@ -2,10 +2,13 @@ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_INTERNAL_H_ #include "libc/calls/struct/fd.internal.h" #include "libc/calls/struct/winsize.h" +#include "libc/mem/alloca.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -int ioctl_tiocgwinsz_nt(struct Fd *, struct winsize *) _Hide; +int tcgetwinsize_nt(struct Fd *, struct winsize *) _Hide; +const char *DescribeWinsize(char[64], int, struct winsize *); +#define DescribeWinsize(rc, ws) DescribeWinsize(alloca(12), rc, ws) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/tcdrain.c b/libc/calls/tcdrain.c index f368b2c26..aa4d774ce 100644 --- a/libc/calls/tcdrain.c +++ b/libc/calls/tcdrain.c @@ -27,7 +27,10 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" -static textwindows int sys_tcdrain_nt(int fd) { +#define TCSBRK 0x5409 // linux +#define TIOCDRAIN 0x2000745e // xnu, freebsd, openbsd, netbsd + +static dontinline textwindows int sys_tcdrain_nt(int fd) { if (!__isfdopen(fd)) return ebadf(); if (_check_interrupts(false, g_fds.p)) return -1; if (!FlushFileBuffers(g_fds.p[fd].handle)) return __winerr(); @@ -40,7 +43,7 @@ static textwindows int sys_tcdrain_nt(int fd) { * @param fd is file descriptor of tty * @raise EBADF if `fd` isn't an open file descriptor * @raise ENOTTY if `fd` is open but not a teletypewriter - * @raise EIO if process group of writer is orphoned, calling thread is + * @raise EIO if process group of writer is orphaned, calling thread is * not blocking `SIGTTOU`, and process isn't ignoring `SIGTTOU` * @raise ECANCELED if thread was cancelled in masked mode * @raise EINTR if signal was delivered @@ -51,12 +54,14 @@ static textwindows int sys_tcdrain_nt(int fd) { int tcdrain(int fd) { int rc; BEGIN_CANCELLATION_POINT; - if (IsMetal()) { - rc = enosys(); - } else if (!IsWindows()) { - rc = sys_ioctl_cp(fd, TCSBRK, (void *)(intptr_t)1); - } else { + if (IsLinux()) { + rc = sys_ioctl_cp(fd, TCSBRK, (uintptr_t)1); + } else if (IsBsd()) { + rc = sys_ioctl_cp(fd, TIOCDRAIN, 0); + } else if (IsWindows()) { rc = sys_tcdrain_nt(fd); + } else { + rc = enosys(); } END_CANCELLATION_POINT; STRACE("tcdrain(%d) → %d% m", fd, rc); diff --git a/libc/calls/tcflow.c b/libc/calls/tcflow.c index 8015c7abe..4df150e6b 100644 --- a/libc/calls/tcflow.c +++ b/libc/calls/tcflow.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" +#include "libc/calls/struct/metatermios.internal.h" #include "libc/calls/struct/termios.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" @@ -32,6 +33,13 @@ #define kNtPurgeTxabort 1 #define kNtPurgeRxabort 2 +#define TCXONC 0x0000540A // linux +#define TIOCGETA 0x40487413 // bsd +#define TIOCSTOP 0x2000746f // bsd +#define TIOCSTART 0x2000746e // bsd +#define TIOCIXON 0x20007481 // xnu +#define TIOCIXOFF 0x20007480 // xnu + static const char *DescribeFlow(char buf[12], int action) { if (action == TCOOFF) return "TCOOFF"; if (action == TCOON) return "TCOON"; @@ -41,33 +49,61 @@ static const char *DescribeFlow(char buf[12], int action) { return buf; } -static int sys_tcflow_bsd(int fd, int action) { - int rc; - uint8_t c; - struct termios t; - if (action == TCOOFF) return sys_ioctl(fd, TIOCSTOP, 0); - if (action == TCOON) return sys_ioctl(fd, TIOCSTART, 0); - if (action != TCIOFF && action != TCION) return einval(); - if (sys_ioctl(fd, TCGETS, &t) == -1) return -1; - c = t.c_cc[action == TCIOFF ? VSTOP : VSTART]; - if (c == 255) return 0; // code is disabled - if (sys_write(fd, &c, 1) == -1) return -1; +static int sys_tcflow_bsd_write(int fd, int cc) { + unsigned char c; + struct termios_bsd term; + if (sys_ioctl(fd, TIOCGETA, &term) == -1) { + return -1; + } + if ((c = term.c_cc[cc]) != _POSIX_VDISABLE && + sys_write(fd, &c, sizeof(c)) == -1) { + return -1; + } return 0; } +static int sys_tcflow_bsd(int fd, int action) { + switch (action) { + case TCOOFF: + return sys_ioctl(fd, TIOCSTOP, 0); + case TCOON: + return sys_ioctl(fd, TIOCSTART, 0); + case TCION: + if (IsXnu()) { + return sys_ioctl(fd, TIOCIXON, 0); + } else { + return sys_tcflow_bsd_write(fd, VSTART); + } + case TCIOFF: + if (IsXnu()) { + return sys_ioctl(fd, TIOCIXOFF, 0); + } else { + return sys_tcflow_bsd_write(fd, VSTOP); + } + return 0; + default: + return einval(); + } +} + static dontinline textwindows int sys_tcflow_nt(int fd, int action) { bool32 ok; int64_t h; if (!__isfdopen(fd)) return ebadf(); h = g_fds.p[fd].handle; - if (action == TCOOFF) { - ok = PurgeComm(h, kNtPurgeTxabort); - } else if (action == TCIOFF) { - ok = PurgeComm(h, kNtPurgeRxabort); - } else if (action == TCOON || action == TCION) { - ok = ClearCommBreak(h); - } else { - return einval(); + switch (action) { + case TCOON: + case TCION: + ok = ClearCommBreak(h); + break; + case TCOOFF: + ok = PurgeComm(h, kNtPurgeTxabort); + break; + case TCIOFF: + ok = PurgeComm(h, kNtPurgeRxabort); + break; + default: + return einval(); } return ok ? 0 : __winerr(); } @@ -92,14 +128,14 @@ static dontinline textwindows int sys_tcflow_nt(int fd, int action) { */ int tcflow(int fd, int action) { int rc; - if (IsMetal()) { - rc = enosys(); + if (IsLinux()) { + rc = sys_ioctl(fd, TCXONC, action); } else if (IsBsd()) { - rc = sys_ioctl(fd, TCXONC, action); - } else if (!IsWindows()) { - rc = sys_ioctl(fd, TCXONC, action); - } else { + rc = sys_tcflow_bsd(fd, action); + } else if (IsWindows()) { rc = sys_tcflow_nt(fd, action); + } else { + rc = enosys(); } STRACE("tcflow(%d, %s) → %d% m", fd, DescribeFlow(alloca(12), action), rc); return rc; diff --git a/libc/calls/tcflush.c b/libc/calls/tcflush.c index d23033985..8094eda85 100644 --- a/libc/calls/tcflush.c +++ b/libc/calls/tcflush.c @@ -29,6 +29,9 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" +#define TCFLSH 0x0000540b +#define TIOCFLUSH 0x80047410 + #define kNtPurgeTxclear 4 #define kNtPurgeRxclear 8 @@ -73,12 +76,14 @@ static dontinline textwindows int sys_tcflush_nt(int fd, int queue) { */ int tcflush(int fd, int queue) { int rc; - if (IsMetal()) { - rc = enosys(); - } else if (!IsWindows()) { + if (IsLinux()) { rc = sys_ioctl(fd, TCFLSH, queue); - } else { + } else if (IsBsd()) { + rc = sys_ioctl(fd, TIOCFLUSH, &queue); + } else if (IsWindows()) { rc = sys_tcflush_nt(fd, queue); + } else { + rc = enosys(); } STRACE("tcflush(%d, %s) → %d% m", fd, DescribeFlush(alloca(12), queue), rc); return rc; diff --git a/libc/calls/ioctl_tcgets-nt.c b/libc/calls/tcgetattr-nt.c similarity index 98% rename from libc/calls/ioctl_tcgets-nt.c rename to libc/calls/tcgetattr-nt.c index ac04c84f5..a64e55f88 100644 --- a/libc/calls/ioctl_tcgets-nt.c +++ b/libc/calls/tcgetattr-nt.c @@ -28,7 +28,7 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" -textwindows int ioctl_tcgets_nt(int ignored, struct termios *tio) { +textwindows int tcgetattr_nt(int ignored, struct termios *tio) { int64_t in, out; bool32 inok, outok; uint32_t inmode, outmode; diff --git a/libc/calls/tcgetattr.c b/libc/calls/tcgetattr.c index 28f3eddd1..c51eb6c95 100644 --- a/libc/calls/tcgetattr.c +++ b/libc/calls/tcgetattr.c @@ -16,21 +16,56 @@ │ 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/calls/internal.h" +#include "libc/calls/struct/metatermios.internal.h" +#include "libc/calls/struct/termios.h" +#include "libc/calls/syscall-sysv.internal.h" +#include "libc/calls/termios.internal.h" +#include "libc/calls/ttydefaults.h" +#include "libc/dce.h" +#include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/str/str.h" +#include "libc/sysv/errfuns.h" + +#define TCGETS 0x00005401 // linux +#define TIOCGETA 0x40487413 // bsd + +int tcgetattr_nt(int, struct termios *); + +static int tcgetattr_metal(int fd, struct termios *tio) { + bzero(tio, sizeof(*tio)); + tio->c_iflag = TTYDEF_IFLAG; + tio->c_oflag = TTYDEF_OFLAG; + tio->c_lflag = TTYDEF_LFLAG; + tio->c_cflag = TTYDEF_CFLAG; + return 0; +} + +static int tcgetattr_bsd(int fd, struct termios *tio) { + int rc; + union metatermios mt; + if ((rc = sys_ioctl(fd, TIOCGETA, &mt)) != -1) { + if (IsXnu()) { + COPY_TERMIOS(tio, &mt.xnu); + } else { + COPY_TERMIOS(tio, &mt.bsd); + } + } + return rc; +} /** * Obtains the termios struct. * - * Here are the general defaults you can expect across platforms: + * Here are the approximate defaults you can expect across platforms: * * c_iflag = ICRNL IXON * c_oflag = OPOST ONLCR NL0 CR0 TAB0 BS0 VT0 FF0 * c_cflag = ISIG CREAD CS8 * c_lflag = ISIG ICANON ECHO ECHOE ECHOK IEXTEN ECHOCTL ECHOKE - * c_ispeed = 38400 - * c_ospeed = 38400 + * cfgetispeed() = B38400 + * cfgetospeed() = B38400 * c_cc[VINTR] = CTRL-C * c_cc[VQUIT] = CTRL-\ # ignore this comment * c_cc[VERASE] = CTRL-? @@ -54,6 +89,25 @@ * @return 0 on success, or -1 w/ errno * @asyncsignalsafe */ -int(tcgetattr)(int fd, struct termios *tio) { - return ioctl(fd, TCGETS, tio); +int tcgetattr(int fd, struct termios *tio) { + int rc; + if (fd < 0) { + rc = einval(); + } else if (!tio || (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) { + rc = efault(); + } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + rc = enotty(); + } else if (IsLinux()) { + rc = sys_ioctl(fd, TCGETS, tio); + } else if (IsBsd()) { + rc = tcgetattr_bsd(fd, tio); + } else if (IsMetal()) { + rc = tcgetattr_metal(fd, tio); + } else if (IsWindows()) { + rc = tcgetattr_nt(fd, tio); + } else { + rc = enosys(); + } + STRACE("tcgetattr(%d, %p) → %d% m", fd, tio, rc); + return rc; } diff --git a/libc/calls/tcgetpgrp.c b/libc/calls/tcgetpgrp.c index 3ccf7e446..4107f149f 100644 --- a/libc/calls/tcgetpgrp.c +++ b/libc/calls/tcgetpgrp.c @@ -23,6 +23,9 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" +#define TIOCGPGRP_linux 0x0000540f +#define TIOCGPGRP_bsd 0x40047477 + /** * Returns which process group controls terminal. * @@ -34,10 +37,12 @@ */ int tcgetpgrp(int fd) { int rc, pgrp; - if (IsWindows() || IsMetal()) { - rc = enosys(); + if (IsLinux()) { + rc = sys_ioctl(fd, TIOCGPGRP_linux, &pgrp); + } else if (IsBsd()) { + rc = sys_ioctl(fd, TIOCGPGRP_bsd, &pgrp); } else { - rc = sys_ioctl(fd, TIOCGPGRP, &pgrp); + rc = enosys(); } STRACE("tcgetpgrp(%d) → %d% m", fd, rc == -1 ? rc : pgrp); return rc == -1 ? rc : pgrp; diff --git a/libc/calls/tcgetsid.c b/libc/calls/tcgetsid.c index d69a1aa6e..72da3f89c 100644 --- a/libc/calls/tcgetsid.c +++ b/libc/calls/tcgetsid.c @@ -18,10 +18,17 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/termios.h" -#include "libc/sysv/consts/termios.h" +#include "libc/dce.h" +#include "libc/intrin/strace.internal.h" +#define TIOCGSID (IsLinux() ? 0x5429 : 0x40047463) + +/** + * Returns session id controlling terminal. + */ int tcgetsid(int fd) { - int sid; - if (sys_ioctl(fd, TIOCGSID, &sid) < 0) return -1; - return sid; + int rc, sid; + rc = sys_ioctl(fd, TIOCGSID, &sid); + STRACE("tcgetsid(%d) → %d% m", fd, rc); + return rc != -1 ? sid : -1; } diff --git a/libc/calls/ioctl_tiocgwinsz-nt.c b/libc/calls/tcgetwinsize-nt.c similarity index 94% rename from libc/calls/ioctl_tiocgwinsz-nt.c rename to libc/calls/tcgetwinsize-nt.c index 6d912a36d..b72a3cf75 100644 --- a/libc/calls/ioctl_tiocgwinsz-nt.c +++ b/libc/calls/tcgetwinsize-nt.c @@ -16,24 +16,23 @@ │ 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/state.internal.h" #include "libc/calls/struct/fd.internal.h" -#include "libc/calls/struct/termios.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/struct/winsize.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/errno.h" -#include "libc/intrin/strace.internal.h" -#include "libc/log/log.h" +#include "libc/macros.internal.h" #include "libc/nt/console.h" #include "libc/nt/enum/startf.h" #include "libc/nt/startupinfo.h" #include "libc/nt/struct/consolescreenbufferinfoex.h" +#include "libc/nt/struct/startupinfo.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -textwindows int ioctl_tiocgwinsz_nt(struct Fd *fd, struct winsize *ws) { +textwindows int tcgetwinsize_nt(struct Fd *fd, struct winsize *ws) { int i, e, rc; uint32_t mode; struct Fd *fds[3]; diff --git a/libc/calls/tcgetwinsize.c b/libc/calls/tcgetwinsize.c index 60df5b240..32eb6f63c 100644 --- a/libc/calls/tcgetwinsize.c +++ b/libc/calls/tcgetwinsize.c @@ -16,13 +16,37 @@ │ 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/ioctl.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/struct/winsize.internal.h" +#include "libc/calls/syscall-sysv.internal.h" +#include "libc/calls/termios.h" +#include "libc/dce.h" +#include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/sysv/consts/termios.h" +#include "libc/sysv/errfuns.h" /** * Gets terminal window size. */ int tcgetwinsize(int fd, struct winsize *ws) { - return ioctl_tiocgwinsz(fd, ws); + int rc; + if (IsAsan() && !__asan_is_valid(ws, sizeof(*ws))) { + ws = 0; + rc = efault(); + } else if (fd >= 0) { + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + rc = enotty(); + } else if (IsWindows()) { + rc = tcgetwinsize_nt(g_fds.p + fd, ws); + } else { + rc = sys_ioctl(fd, TIOCGWINSZ, ws); + } + } else { + rc = einval(); + } + STRACE("tcgetwinsize(%d, [%s]) → %d% m", fd, DescribeWinsize(rc, ws), rc); + return rc; } diff --git a/libc/calls/tcsendbreak.c b/libc/calls/tcsendbreak.c index f4c4000c0..687db424c 100644 --- a/libc/calls/tcsendbreak.c +++ b/libc/calls/tcsendbreak.c @@ -20,13 +20,15 @@ #include "libc/calls/internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" -#include "libc/calls/termios.h" #include "libc/dce.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/comms.h" -#include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" +#define TCSBRK 0x5409 // linux +#define TIOCSBRK 0x2000747b // bsd +#define TIOCCBRK 0x2000747a // bsd + static int sys_tcsendbreak_bsd(int fd) { if (sys_ioctl(fd, TIOCSBRK, 0) == -1) return -1; usleep(400000); @@ -55,14 +57,14 @@ static textwindows int sys_tcsendbreak_nt(int fd) { */ int tcsendbreak(int fd, int duration) { int rc; - if (IsMetal()) { - rc = enosys(); + if (IsLinux()) { + rc = sys_ioctl(fd, TCSBRK, 0); } else if (IsBsd()) { rc = sys_tcsendbreak_bsd(fd); - } else if (!IsWindows()) { - rc = sys_ioctl(fd, TCSBRK, 0); - } else { + } else if (IsWindows()) { rc = sys_tcsendbreak_nt(fd); + } else { + rc = enosys(); } STRACE("tcsendbreak(%d, %u) → %d% m", fd, duration, rc); return rc; diff --git a/libc/calls/ioctl_tcsets-nt.c b/libc/calls/tcsetattr-nt.c similarity index 96% rename from libc/calls/ioctl_tcsets-nt.c rename to libc/calls/tcsetattr-nt.c index a31ff27cd..d52c24949 100644 --- a/libc/calls/ioctl_tcsets-nt.c +++ b/libc/calls/tcsetattr-nt.c @@ -29,8 +29,7 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" -textwindows int ioctl_tcsets_nt(int ignored, uint64_t request, - const struct termios *tio) { +textwindows int tcsetattr_nt(int ignored, int opt, const struct termios *tio) { int64_t in, out; bool32 ok, inok, outok; uint32_t inmode, outmode; @@ -39,7 +38,7 @@ textwindows int ioctl_tcsets_nt(int ignored, uint64_t request, if (inok | outok) { if (inok) { - if (request == TCSETSF) { + if (opt == TCSAFLUSH) { FlushConsoleInputBuffer(in); } inmode &= diff --git a/libc/calls/tcsetattr.c b/libc/calls/tcsetattr.c index c392b02eb..9899e1b1a 100644 --- a/libc/calls/tcsetattr.c +++ b/libc/calls/tcsetattr.c @@ -16,11 +16,77 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" #include "libc/calls/ioctl.h" +#include "libc/calls/struct/metatermios.internal.h" +#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/termios.h" +#include "libc/calls/termios.internal.h" +#include "libc/dce.h" +#include "libc/fmt/itoa.h" +#include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/intrin/weaken.h" +#include "libc/mem/alloca.h" #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" +#define TCSETS 0x5402 +#define TCSETSW 0x5403 +#define TCSETSF 0x5404 +#define TIOCSETA 0x80487414 +#define TIOCSETAW 0x80487415 +#define TIOCSETAF 0x80487416 + +void __on_tcsetattr(int); +int tcsetattr_nt(int, int, const struct termios *); + +static const char *DescribeTcsa(char buf[12], int opt) { + if (opt == TCSANOW) return "TCSANOW"; + if (opt == TCSADRAIN) return "TCSADRAIN"; + if (opt == TCSAFLUSH) return "TCSAFLUSH"; + FormatInt32(buf, opt); + return buf; +} + +static int tcsetattr_impl(int fd, int opt, const struct termios *tio) { + if (fd < 0) { + return einval(); + } + + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + return enotty(); + } + + if (0 <= fd && fd <= 2 && _weaken(__on_tcsetattr)) { + static bool once; + if (!once) { + _weaken(__on_tcsetattr)(fd); + once = true; + } + } + + if (IsAsan() && !__asan_is_valid(tio, sizeof(*tio))) { + return efault(); + } + + if (IsMetal()) { + return 0; + } + + if (IsWindows()) { + return tcsetattr_nt(fd, opt, tio); + } + + if (IsLinux() || IsBsd()) { + union metatermios mt; + return sys_ioctl(fd, (IsLinux() ? TCSETS : TIOCSETA) + opt, + __termios2host(&mt, tio)); + } + + return enosys(); +} + /** * Sets struct on teletypewriter w/ drains and flushes. * @@ -32,15 +98,10 @@ * @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(); - } +int tcsetattr(int fd, int opt, const struct termios *tio) { + int rc; + rc = tcsetattr_impl(fd, opt, tio); + STRACE("tcsetattr(%d, %s, %p) → %d% m", fd, DescribeTcsa(alloca(12), opt), + tio, rc); + return rc; } diff --git a/libc/calls/ioctl_tiocswinsz-nt.c b/libc/calls/tcsetwinsize-nt.c similarity index 97% rename from libc/calls/ioctl_tiocswinsz-nt.c rename to libc/calls/tcsetwinsize-nt.c index 658638c7f..f21dafda3 100644 --- a/libc/calls/ioctl_tiocswinsz-nt.c +++ b/libc/calls/tcsetwinsize-nt.c @@ -25,7 +25,7 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -textwindows int ioctl_tiocswinsz_nt(int fd, const struct winsize *ws) { +textwindows int tcsetwinsize_nt(int fd, const struct winsize *ws) { uint32_t mode; struct NtCoord coord; if (!ws) return efault(); diff --git a/libc/calls/tcsetwinsize.c b/libc/calls/tcsetwinsize.c index 534e72b9e..81dcf1003 100644 --- a/libc/calls/tcsetwinsize.c +++ b/libc/calls/tcsetwinsize.c @@ -16,13 +16,37 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/calls/ioctl.h" +#include "libc/calls/internal.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/struct/winsize.internal.h" +#include "libc/calls/syscall-sysv.internal.h" +#include "libc/calls/termios.h" +#include "libc/dce.h" +#include "libc/intrin/asan.internal.h" +#include "libc/intrin/strace.internal.h" +#include "libc/sysv/consts/termios.h" +#include "libc/sysv/errfuns.h" + +int tcsetwinsize_nt(int, const struct winsize *); /** * Sets terminal window size attributes. */ int tcsetwinsize(int fd, const struct winsize *ws) { - return ioctl_tiocswinsz(fd, ws); + int rc; + if (IsAsan() && !__asan_is_valid(ws, sizeof(*ws))) { + rc = efault(); + } else if (fd >= 0) { + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + rc = enotty(); + } else if (!IsWindows()) { + rc = sys_ioctl(fd, TIOCSWINSZ, ws); + } else { + rc = tcsetwinsize_nt(fd, ws); + } + } else { + rc = einval(); + } + STRACE("tcsetwinsize(%d, %s) → %d% m", fd, DescribeWinsize(rc, ws), rc); + return rc; } diff --git a/libc/calls/termios.internal.h b/libc/calls/termios.internal.h index 21efaf2bf..e284126ff 100644 --- a/libc/calls/termios.internal.h +++ b/libc/calls/termios.internal.h @@ -3,28 +3,29 @@ #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; \ +#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; \ + /* null c_ospeed causes bsd to hangup terminal */ \ + (TO)->_c_ospeed = _c_ospeed ? _c_ospeed : 9600; \ } while (0) void *__termios2host(union metatermios *, const struct termios *); diff --git a/libc/calls/termios2host.c b/libc/calls/termios2host.c index 68bf333b0..1ddf34ee5 100644 --- a/libc/calls/termios2host.c +++ b/libc/calls/termios2host.c @@ -20,7 +20,7 @@ #include "libc/dce.h" void *__termios2host(union metatermios *mt, const struct termios *lt) { - if (!IsXnu() && !IsFreebsd() && !IsOpenbsd() && !IsNetbsd()) { + if (!IsBsd()) { return (/*unconst*/ void *)lt; } else if (IsXnu()) { COPY_TERMIOS(&mt->xnu, lt); diff --git a/libc/calls/ttyname_r.c b/libc/calls/ttyname_r.c index f44302360..7235735cc 100644 --- a/libc/calls/ttyname_r.c +++ b/libc/calls/ttyname_r.c @@ -32,6 +32,8 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" +#define FIODGNAME 0x80106678 // freebsd + static textwindows dontinline int sys_ttyname_nt(int fd, char *buf, size_t size) { uint32_t mode; @@ -49,7 +51,6 @@ static textwindows dontinline int sys_ttyname_nt(int fd, char *buf, } static int ttyname_freebsd(int fd, char *buf, size_t size) { - const unsigned FIODGNAME = 2148558456; struct fiodgname_arg { int len; void *buf; diff --git a/libc/calls/unlockpt.c b/libc/calls/unlockpt.c index e33d35335..1b3b01582 100644 --- a/libc/calls/unlockpt.c +++ b/libc/calls/unlockpt.c @@ -25,7 +25,7 @@ #include "libc/sysv/consts/pty.h" #include "libc/sysv/errfuns.h" -extern const uint32_t TIOCPTYUNLK; +#define TIOCPTYUNLK 0x20007452 /** * Unlocks pseudoteletypewriter pair. diff --git a/libc/calls/vdsofunc.greg.c b/libc/calls/vdsofunc.greg.c index 88c869133..21a561b18 100644 --- a/libc/calls/vdsofunc.greg.c +++ b/libc/calls/vdsofunc.greg.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/dce.h" #include "libc/elf/scalar.h" #include "libc/elf/struct/ehdr.h" #include "libc/elf/struct/phdr.h" @@ -30,6 +31,13 @@ #include "libc/str/str.h" #include "libc/sysv/consts/auxv.h" +// needed to avoid asan restrictions on strcmp +static int StrCmp(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; @@ -37,7 +45,7 @@ static inline int CheckDsoSymbolVersion(Elf64_Verdef *vd, int sym, if (!(vd->vd_flags & VER_FLG_BASE) && (vd->vd_ndx & 0x7fff) == (sym & 0x7fff)) { aux = (Elf64_Verdaux *)((char *)vd + vd->vd_aux); - return !strcmp(name, strtab + aux->vda_name); + return !StrCmp(name, strtab + aux->vda_name); } if (!vd->vd_next) { return 0; @@ -133,7 +141,7 @@ void *__vdsosym(const char *version, const char *name) { if (!symtab[i].st_shndx) { continue; } - if (strcmp(name, strtab + symtab[i].st_name)) { + if (StrCmp(name, strtab + symtab[i].st_name)) { continue; } if (versym && !CheckDsoSymbolVersion(verdef, versym[i], version, strtab)) { diff --git a/libc/dns/gethoststxt.c b/libc/dns/gethoststxt.c index 5cf805fd2..bfa04bf7c 100644 --- a/libc/dns/gethoststxt.c +++ b/libc/dns/gethoststxt.c @@ -21,7 +21,7 @@ #include "libc/dns/hoststxt.h" #include "libc/fmt/fmt.h" #include "libc/intrin/bits.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" diff --git a/libc/dns/getresolvconf.c b/libc/dns/getresolvconf.c index 1d19de199..09a61be08 100644 --- a/libc/dns/getresolvconf.c +++ b/libc/dns/getresolvconf.c @@ -19,7 +19,7 @@ #include "libc/dce.h" #include "libc/dns/resolvconf.h" #include "libc/fmt/fmt.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" diff --git a/libc/intrin/bits.h b/libc/intrin/bits.h index 586ebeb1c..d810a7355 100644 --- a/libc/intrin/bits.h +++ b/libc/intrin/bits.h @@ -6,10 +6,6 @@ COSMOPOLITAN_C_START_ #define CheckUnsigned(x) ((x) / !((typeof(x))(-1) < 0)) -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § bits ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - extern const uint8_t kReverseBits[256]; int _bitreverse8(int) libcesque pureconst; @@ -23,138 +19,96 @@ unsigned long _roundup2log(unsigned long) libcesque pureconst; unsigned long _rounddown2pow(unsigned long) libcesque pureconst; unsigned _bextra(const unsigned *, size_t, char); -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § bits » no assembly required ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ +#define READ16LE(P) \ + (__extension__({ \ + uint16_t __x; \ + __builtin_memcpy(&__x, P, 16 / 8); \ + __x; \ + })) -#ifdef __STRICT_ANSI__ -#define READ16LE(S) ((255 & (S)[1]) << 8 | (255 & (S)[0])) -#define READ16BE(S) ((255 & (S)[0]) << 8 | (255 & (S)[1])) -#define READ32LE(S) \ - ((uint32_t)(255 & (S)[3]) << 030 | (uint32_t)(255 & (S)[2]) << 020 | \ - (uint32_t)(255 & (S)[1]) << 010 | (uint32_t)(255 & (S)[0]) << 000) -#define READ32BE(S) \ - ((uint32_t)(255 & (S)[0]) << 030 | (uint32_t)(255 & (S)[1]) << 020 | \ - (uint32_t)(255 & (S)[2]) << 010 | (uint32_t)(255 & (S)[3]) << 000) -#define READ64LE(S) \ - ((uint64_t)(255 & (S)[7]) << 070 | (uint64_t)(255 & (S)[6]) << 060 | \ - (uint64_t)(255 & (S)[5]) << 050 | (uint64_t)(255 & (S)[4]) << 040 | \ - (uint64_t)(255 & (S)[3]) << 030 | (uint64_t)(255 & (S)[2]) << 020 | \ - (uint64_t)(255 & (S)[1]) << 010 | (uint64_t)(255 & (S)[0]) << 000) -#define READ64BE(S) \ - ((uint64_t)(255 & (S)[0]) << 070 | (uint64_t)(255 & (S)[1]) << 060 | \ - (uint64_t)(255 & (S)[2]) << 050 | (uint64_t)(255 & (S)[3]) << 040 | \ - (uint64_t)(255 & (S)[4]) << 030 | (uint64_t)(255 & (S)[5]) << 020 | \ - (uint64_t)(255 & (S)[6]) << 010 | (uint64_t)(255 & (S)[7]) << 000) -#else /* gcc needs help knowing above are mov if s isn't a variable */ -#define READ16LE(S) \ - ({ \ - const uint8_t *Ptr = (const uint8_t *)(S); \ - Ptr[1] << 8 | Ptr[0]; \ - }) -#define READ16BE(S) \ - ({ \ - const uint8_t *Ptr = (const uint8_t *)(S); \ - Ptr[0] << 8 | Ptr[1]; \ - }) -#define READ32LE(S) \ - ({ \ - const uint8_t *Ptr = (const uint8_t *)(S); \ - ((uint32_t)Ptr[3] << 030 | (uint32_t)Ptr[2] << 020 | \ - (uint32_t)Ptr[1] << 010 | (uint32_t)Ptr[0] << 000); \ - }) -#define READ32BE(S) \ - ({ \ - const uint8_t *Ptr = (const uint8_t *)(S); \ - ((uint32_t)Ptr[0] << 030 | (uint32_t)Ptr[1] << 020 | \ - (uint32_t)Ptr[2] << 010 | (uint32_t)Ptr[3] << 000); \ - }) -#define READ64LE(S) \ - ({ \ - const uint8_t *Ptr = (const uint8_t *)(S); \ - ((uint64_t)Ptr[7] << 070 | (uint64_t)Ptr[6] << 060 | \ - (uint64_t)Ptr[5] << 050 | (uint64_t)Ptr[4] << 040 | \ - (uint64_t)Ptr[3] << 030 | (uint64_t)Ptr[2] << 020 | \ - (uint64_t)Ptr[1] << 010 | (uint64_t)Ptr[0] << 000); \ - }) -#define READ64BE(S) \ - ({ \ - const uint8_t *Ptr = (const uint8_t *)(S); \ - ((uint64_t)Ptr[0] << 070 | (uint64_t)Ptr[1] << 060 | \ - (uint64_t)Ptr[2] << 050 | (uint64_t)Ptr[3] << 040 | \ - (uint64_t)Ptr[4] << 030 | (uint64_t)Ptr[5] << 020 | \ - (uint64_t)Ptr[6] << 010 | (uint64_t)Ptr[7] << 000); \ - }) -#endif +#define READ16BE(P) \ + (__extension__({ \ + uint16_t __x; \ + __builtin_memcpy(&__x, P, 16 / 8); \ + __builtin_bswap16(__x); \ + })) -#define WRITE16LE(P, V) \ - ((P)[0] = (0x00000000000000FF & (V)) >> 000, \ - (P)[1] = (0x000000000000FF00 & (V)) >> 010, (P) + 2) -#define WRITE16BE(P, V) \ - ((P)[0] = (0x000000000000FF00 & (V)) >> 010, \ - (P)[1] = (0x00000000000000FF & (V)) >> 000, (P) + 2) -#define WRITE32LE(P, V) \ - ((P)[0] = (0x00000000000000FF & (V)) >> 000, \ - (P)[1] = (0x000000000000FF00 & (V)) >> 010, \ - (P)[2] = (0x0000000000FF0000 & (V)) >> 020, \ - (P)[3] = (0x00000000FF000000 & (V)) >> 030, (P) + 4) -#define WRITE32BE(P, V) \ - ((P)[0] = (0x00000000FF000000 & (V)) >> 030, \ - (P)[1] = (0x0000000000FF0000 & (V)) >> 020, \ - (P)[2] = (0x000000000000FF00 & (V)) >> 010, \ - (P)[3] = (0x00000000000000FF & (V)) >> 000, (P) + 4) -#define WRITE64LE(P, V) \ - ((P)[0] = (0x00000000000000FF & (V)) >> 000, \ - (P)[1] = (0x000000000000FF00 & (V)) >> 010, \ - (P)[2] = (0x0000000000FF0000 & (V)) >> 020, \ - (P)[3] = (0x00000000FF000000 & (V)) >> 030, \ - (P)[4] = (0x000000FF00000000 & (V)) >> 040, \ - (P)[5] = (0x0000FF0000000000 & (V)) >> 050, \ - (P)[6] = (0x00FF000000000000 & (V)) >> 060, \ - (P)[7] = (0xFF00000000000000 & (V)) >> 070, (P) + 8) -#define WRITE64BE(P, V) \ - ((P)[0] = (0xFF00000000000000 & (V)) >> 070, \ - (P)[1] = (0x00FF000000000000 & (V)) >> 060, \ - (P)[2] = (0x0000FF0000000000 & (V)) >> 050, \ - (P)[3] = (0x000000FF00000000 & (V)) >> 040, \ - (P)[4] = (0x00000000FF000000 & (V)) >> 030, \ - (P)[5] = (0x0000000000FF0000 & (V)) >> 020, \ - (P)[6] = (0x000000000000FF00 & (V)) >> 010, \ - (P)[7] = (0x00000000000000FF & (V)) >> 000, (P) + 8) +#define READ32LE(P) \ + (__extension__({ \ + uint32_t __x; \ + __builtin_memcpy(&__x, P, 32 / 8); \ + __x; \ + })) -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § bits » some assembly required ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) +#define READ32BE(P) \ + (__extension__({ \ + uint32_t __x; \ + __builtin_memcpy(&__x, P, 32 / 8); \ + __builtin_bswap32(__x); \ + })) -#define lockinc(MEM) __ArithmeticOp1("lock inc", MEM) -#define lockdec(MEM) __ArithmeticOp1("lock dec", MEM) -#define locknot(MEM) __ArithmeticOp1("lock not", MEM) -#define lockneg(MEM) __ArithmeticOp1("lock neg", MEM) +#define READ64LE(P) \ + (__extension__({ \ + uint64_t __x; \ + __builtin_memcpy(&__x, P, 64 / 8); \ + __x; \ + })) -#define lockaddeq(MEM, VAL) __ArithmeticOp2("lock add", VAL, MEM) -#define locksubeq(MEM, VAL) __ArithmeticOp2("lock sub", VAL, MEM) -#define lockxoreq(MEM, VAL) __ArithmeticOp2("lock xor", VAL, MEM) -#define lockandeq(MEM, VAL) __ArithmeticOp2("lock and", VAL, MEM) -#define lockoreq(MEM, VAL) __ArithmeticOp2("lock or", VAL, MEM) +#define READ64BE(P) \ + (__extension__({ \ + uint64_t __x; \ + __builtin_memcpy(&__x, P, 64 / 8); \ + __builtin_bswap64(__x); \ + })) -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § bits » implementation details ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ +#define WRITE16LE(P, X) \ + (__extension__({ \ + __typeof__(&(P)[0]) __p = (P); \ + uint16_t __x = (X); \ + __builtin_memcpy(__p, &__x, 16 / 8); \ + __p + 16 / 8; \ + })) -#define __ArithmeticOp1(OP, MEM) \ - ({ \ - asm(OP "%z0\t%0" : "+m"(*(MEM)) : /* no inputs */ : "cc"); \ - MEM; \ - }) +#define WRITE16BE(P, X) \ + (__extension__({ \ + __typeof__(&(P)[0]) __p = (P); \ + uint16_t __x = __builtin_bswap16(X); \ + __builtin_memcpy(__p, &__x, 16 / 8); \ + __p + 16 / 8; \ + })) -#define __ArithmeticOp2(OP, VAL, MEM) \ - ({ \ - asm(OP "%z0\t%1,%0" : "+m,m"(*(MEM)) : "i,r"(VAL) : "cc"); \ - MEM; \ - }) +#define WRITE32LE(P, X) \ + (__extension__({ \ + __typeof__(&(P)[0]) __p = (P); \ + uint32_t __x = (X); \ + __builtin_memcpy(__p, &__x, 32 / 8); \ + __p + 32 / 8; \ + })) + +#define WRITE32BE(P, X) \ + (__extension__({ \ + __typeof__(&(P)[0]) __p = (P); \ + uint32_t __x = __builtin_bswap32(X); \ + __builtin_memcpy(__p, &__x, 32 / 8); \ + __p + 32 / 8; \ + })) + +#define WRITE64LE(P, X) \ + (__extension__({ \ + __typeof__(&(P)[0]) __p = (P); \ + uint64_t __x = (X); \ + __builtin_memcpy(__p, &__x, 64 / 8); \ + __p + 64 / 8; \ + })) + +#define WRITE64BE(P, X) \ + (__extension__({ \ + __typeof__(&(P)[0]) __p = (P); \ + uint64_t __x = __builtin_bswap64(X); \ + __builtin_memcpy(__p, &__x, 64 / 8); \ + __p + 64 / 8; \ + })) -#endif /* __GNUC__ && !__STRICT_ANSI__ */ #endif /* COSMO */ COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/ioctl_tiocswinsz.c b/libc/intrin/describewinsize.c similarity index 68% rename from libc/calls/ioctl_tiocswinsz.c rename to libc/intrin/describewinsize.c index d6bb7b341..29a711ba4 100644 --- a/libc/calls/ioctl_tiocswinsz.c +++ b/libc/intrin/describewinsize.c @@ -1,7 +1,7 @@ /*-*- 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,38 +16,37 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/internal.h" -#include "libc/calls/ioctl.h" #include "libc/calls/struct/winsize.h" -#include "libc/calls/syscall-sysv.internal.h" +#include "libc/calls/struct/winsize.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" -#include "libc/sysv/consts/termios.h" -#include "libc/sysv/errfuns.h" +#include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/kprintf.h" +#include "libc/limits.h" +#include "libc/macros.internal.h" -int ioctl_tiocswinsz_nt(int, const struct winsize *); +#define N 64 -/** - * Sets width and height of terminal. - * - * @see ioctl(fd, TIOCSWINSZ, ws) dispatches here - */ -int ioctl_tiocswinsz(int fd, ...) { - va_list va; - const struct winsize *ws; - va_start(va, fd); - ws = va_arg(va, const struct winsize *); - va_end(va); - if (IsAsan() && !__asan_is_valid(ws, sizeof(*ws))) return efault(); - if (fd >= 0) { - if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { - return enotty(); - } else if (!IsWindows()) { - return sys_ioctl(fd, TIOCSWINSZ, ws); - } else { - return ioctl_tiocswinsz_nt(fd, ws); - } - } else { - return einval(); +#define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__) + +const char *(DescribeWinsize)(char buf[N], int rc, struct winsize *ws) { + char b64[64]; + const char *d; + int i, j, o = 0; + + if (!ws) return "NULL"; + if (rc == -1) return "n/a"; + if ((!IsAsan() && kisdangerous(ws)) || + (IsAsan() && !__asan_is_valid(ws, sizeof(*ws)))) { + ksnprintf(buf, N, "%p", ws); + return buf; } + + append("{.ws_row=%d, .ws_col=%d", ws->ws_row, ws->ws_col); + if (ws->ws_xpixel | ws->ws_ypixel) { + append(", .ws_xpixel=%d, .ws_ypixel=%d", ws->ws_xpixel, ws->ws_ypixel); + } + append("}"); + + return buf; } diff --git a/libc/intrin/g_fds.c b/libc/intrin/g_fds.c index 9373ef5d1..7a9e4963e 100644 --- a/libc/intrin/g_fds.c +++ b/libc/intrin/g_fds.c @@ -20,7 +20,7 @@ #include "libc/calls/state.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/extend.internal.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/nt/runtime.h" diff --git a/libc/intrin/kopenflags.S b/libc/intrin/kopenflags.S index eb6ca038c..af09ed8ea 100644 --- a/libc/intrin/kopenflags.S +++ b/libc/intrin/kopenflags.S @@ -31,10 +31,6 @@ .balign 4 .underrun kOpenFlags: - .e O_RDWR,"RDWR" // order matters - .e O_RDONLY,"RDONLY" // - .e O_WRONLY,"WRONLY" // - .e O_ACCMODE,"ACCMODE" // mask of prev three .e O_CREAT,"CREAT" // .e O_EXCL,"EXCL" // .e O_TRUNC,"TRUNC" // diff --git a/libc/intrin/pushpop.h b/libc/intrin/pushpop.internal.h similarity index 96% rename from libc/intrin/pushpop.h rename to libc/intrin/pushpop.internal.h index 56bb847ee..20ace6e39 100644 --- a/libc/intrin/pushpop.h +++ b/libc/intrin/pushpop.internal.h @@ -4,7 +4,8 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) #ifdef COSMO -#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__) +#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__) || \ + !defined(__MNO_RED_ZONE__) #define pushpop(x) (x) #else /** @@ -32,7 +33,8 @@ }) #endif -#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__) +#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__) || \ + !defined(__MNO_RED_ZONE__) #define pushmov(d, x) (*(d) = (x)) #else #define pushmov(d, x) \ diff --git a/libc/intrin/ubsan.c b/libc/intrin/ubsan.c index a4e9a97d4..6057ab11f 100644 --- a/libc/intrin/ubsan.c +++ b/libc/intrin/ubsan.c @@ -19,7 +19,7 @@ #include "libc/calls/calls.h" #include "libc/fmt/fmt.h" #include "libc/intrin/kprintf.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/color.internal.h" diff --git a/libc/runtime/clone.c b/libc/runtime/clone.c index 3983d3790..4ebb109df 100644 --- a/libc/runtime/clone.c +++ b/libc/runtime/clone.c @@ -528,7 +528,7 @@ static int CloneLinux(int (*func)(void *arg, int rc), char *stk, size_t stksz, /** * Creates thread without malloc being linked. * - * If you use clone() you're on you're own, e.g. + * If you use clone() you're on your own. Example: * * int worker(void *arg) { return 0; } * struct CosmoTib tib = {.tib_self = &tib, .tib_tid = -1}; diff --git a/libc/runtime/finddebugbinary.c b/libc/runtime/finddebugbinary.c index 83bf1ba4f..364c7d7e7 100644 --- a/libc/runtime/finddebugbinary.c +++ b/libc/runtime/finddebugbinary.c @@ -41,7 +41,7 @@ static bool IsMyDebugBinaryImpl(const char *path) { // which is currently running in memory. if ((size = lseek(fd, 0, SEEK_END)) != -1 && (map = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0)) != MAP_FAILED) { - if (READ32LE(map) == READ32LE("\177ELF") && + if (READ32LE((char *)map) == READ32LE("\177ELF") && GetElfSymbolValue(map, "_etext", &value)) { res = !_etext || value == (uintptr_t)_etext; } diff --git a/libc/runtime/mprotect.c b/libc/runtime/mprotect.c index 93d84e866..10081a82b 100644 --- a/libc/runtime/mprotect.c +++ b/libc/runtime/mprotect.c @@ -24,6 +24,7 @@ #include "libc/intrin/strace.internal.h" #include "libc/runtime/internal.h" #include "libc/sysv/consts/prot.h" +#include "libc/sysv/errfuns.h" /** * Modifies restrictions on virtual memory address range. @@ -37,13 +38,11 @@ int mprotect(void *addr, size_t size, int prot) { int64_t rc; if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_GROWSDOWN | PROT_GROWSUP)) { - errno = EINVAL; // unix checks prot before checking size - rc = -1; + rc = einval(); // unix checks prot before checking size } else if (!size) { return 0; // make new technology consistent with unix } else if (UNLIKELY((intptr_t)addr & 4095)) { - errno = EINVAL; // unix checks prot before checking size - rc = -1; + rc = einval(); // unix checks prot before checking size } else if (!IsWindows()) { rc = sys_mprotect(addr, size, prot); } else { diff --git a/libc/runtime/openexecutable.S b/libc/runtime/openexecutable.S index 4a970ece7..ee1373c1b 100644 --- a/libc/runtime/openexecutable.S +++ b/libc/runtime/openexecutable.S @@ -19,6 +19,7 @@ #include "libc/dce.h" #include "libc/macros.internal.h" #include "libc/sysv/consts/auxv.h" +#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" .privileged @@ -36,12 +37,12 @@ _OpenExecutable: pushq __NR_open(%rip) // -0x08(%rbp) pushq __NR_mmap(%rip) // -0x10(%rbp) pushq __NR_munmap(%rip) // -0x18(%rbp) - pushq O_RDWR(%rip) // -0x20(%rbp) + pushq $O_RDWR // -0x20(%rbp) pushq MAP_ANONYMOUS(%rip) // -0x28(%rbp) pushq MAP_PRIVATE(%rip) // -0x30(%rbp) pushq MAP_FIXED(%rip) // -0x38(%rbp) pushq __NR_mprotect(%rip) // -0x40(%rbp) - pushq O_RDONLY(%rip) // -0x48(%rbp) + pushq $O_RDONLY // -0x48(%rbp) push %rbx // code buffer push %r12 // data buffer push %r14 // filename diff --git a/libc/runtime/opensymboltable.greg.c b/libc/runtime/opensymboltable.greg.c index 4bb858d6d..661d95df6 100644 --- a/libc/runtime/opensymboltable.greg.c +++ b/libc/runtime/opensymboltable.greg.c @@ -56,7 +56,7 @@ static struct SymbolTable *OpenSymbolTableImpl(const char *filename) { if (filesize < 64) goto RaiseEnoexec; elf = map = mmap(0, filesize, PROT_READ, MAP_PRIVATE, fd, 0); if (map == MAP_FAILED) goto SystemError; - if (READ32LE(map) != READ32LE("\177ELF")) goto RaiseEnoexec; + if (READ32LE((char *)map) != READ32LE("\177ELF")) goto RaiseEnoexec; if (!(name_base = GetStrtab(map, &m))) goto RaiseEnobufs; if (!(symtab = GetSymtab(map, &n))) goto RaiseEnobufs; tsz = 0; diff --git a/libc/runtime/printargs.c b/libc/runtime/printargs.c index cd12219ee..96b2cce8b 100644 --- a/libc/runtime/printargs.c +++ b/libc/runtime/printargs.c @@ -162,9 +162,9 @@ textstartup void __printargs(const char *prologue) { char **env; sigset_t ss; bool gotsome; - unsigned i, n; int e, x, flags; uintptr_t *auxp; + unsigned i, n, b; struct rlimit rlim; struct utsname uts; struct sigaction sa; @@ -391,7 +391,7 @@ textstartup void __printargs(const char *prologue) { PRINT("ARGUMENTS (%p)", __argv); if (*__argv) { for (i = 0; i < __argc; ++i) { - PRINT(" ☼ %p %s", __argv[i], __argv[i]); + PRINT(" ☼ %s", __argv[i]); } } else { PRINT(" none"); @@ -401,7 +401,7 @@ textstartup void __printargs(const char *prologue) { PRINT("ENVIRONMENT (%p)", __envp); if (*__envp) { for (env = __envp; *env; ++env) { - PRINT(" ☼ %p %s", *env, *env); + PRINT(" ☼ %s", *env); } } else { PRINT(" none"); @@ -414,9 +414,9 @@ textstartup void __printargs(const char *prologue) { for (auxp = __auxv; *auxp; auxp += 2) { if ((auxinfo = DescribeAuxv(auxp[0]))) { ksnprintf(u.path, sizeof(u.path), auxinfo->fmt, auxp[1]); - PRINT(" ☼ %p %16s[%4ld] = %s", auxp, auxinfo->name, auxp[0], u.path); + PRINT(" ☼ %16s[%4ld] = %s", auxinfo->name, auxp[0], u.path); } else { - PRINT(" ☼ %p %16s[%4ld] = %014p", auxp, "unknown", auxp[0], auxp[1]); + PRINT(" ☼ %16s[%4ld] = %014p", "unknown", auxp[0], auxp[1]); } } } @@ -558,63 +558,65 @@ textstartup void __printargs(const char *prologue) { } else if ((termios.c_cflag & CSIZE) == CS8) { kprintf(" CS8"); } - if ((termios.c_cflag & CBAUD) == B0) { + + b = cfgetospeed(&termios); + if (b == B0) { kprintf(" B0"); - } else if ((termios.c_cflag & CBAUD) == B50) { + } else if (b == B50) { kprintf(" B50"); - } else if ((termios.c_cflag & CBAUD) == B75) { + } else if (b == B75) { kprintf(" B75"); - } else if ((termios.c_cflag & CBAUD) == B110) { + } else if (b == B110) { kprintf(" B110"); - } else if ((termios.c_cflag & CBAUD) == B134) { + } else if (b == B134) { kprintf(" B134"); - } else if ((termios.c_cflag & CBAUD) == B150) { + } else if (b == B150) { kprintf(" B150"); - } else if ((termios.c_cflag & CBAUD) == B200) { + } else if (b == B200) { kprintf(" B200"); - } else if ((termios.c_cflag & CBAUD) == B300) { + } else if (b == B300) { kprintf(" B300"); - } else if ((termios.c_cflag & CBAUD) == B600) { + } else if (b == B600) { kprintf(" B600"); - } else if ((termios.c_cflag & CBAUD) == B1200) { + } else if (b == B1200) { kprintf(" B1200"); - } else if ((termios.c_cflag & CBAUD) == B1800) { + } else if (b == B1800) { kprintf(" B1800"); - } else if ((termios.c_cflag & CBAUD) == B2400) { + } else if (b == B2400) { kprintf(" B2400"); - } else if ((termios.c_cflag & CBAUD) == B4800) { + } else if (b == B4800) { kprintf(" B4800"); - } else if ((termios.c_cflag & CBAUD) == B9600) { + } else if (b == B9600) { kprintf(" B9600"); - } else if ((termios.c_cflag & CBAUD) == B19200) { + } else if (b == B19200) { kprintf(" B19200"); - } else if ((termios.c_cflag & CBAUD) == B38400) { + } else if (b == B38400) { kprintf(" B38400"); - } else if ((termios.c_cflag & CBAUD) == B57600) { + } else if (b == B57600) { kprintf(" B57600"); - } else if ((termios.c_cflag & CBAUD) == B115200) { + } else if (b == B115200) { kprintf(" B115200"); - } else if ((termios.c_cflag & CBAUD) == B230400) { + } else if (b == B230400) { kprintf(" B230400"); - } else if ((termios.c_cflag & CBAUD) == B500000) { + } else if (b == B500000) { kprintf(" B500000"); - } else if ((termios.c_cflag & CBAUD) == B576000) { + } else if (b == B576000) { kprintf(" B576000"); - } else if ((termios.c_cflag & CBAUD) == B1000000) { + } else if (b == B1000000) { kprintf(" B1000000"); - } else if ((termios.c_cflag & CBAUD) == B1152000) { + } else if (b == B1152000) { kprintf(" B1152000"); - } else if ((termios.c_cflag & CBAUD) == B1500000) { + } else if (b == B1500000) { kprintf(" B1500000"); - } else if ((termios.c_cflag & CBAUD) == B2000000) { + } else if (b == B2000000) { kprintf(" B2000000"); - } else if ((termios.c_cflag & CBAUD) == B2500000) { + } else if (b == B2500000) { kprintf(" B2500000"); - } else if ((termios.c_cflag & CBAUD) == B3000000) { + } else if (b == B3000000) { kprintf(" B3000000"); - } else if ((termios.c_cflag & CBAUD) == B3500000) { + } else if (b == B3500000) { kprintf(" B3500000"); - } else if ((termios.c_cflag & CBAUD) == B4000000) { + } else if (b == B4000000) { kprintf(" B4000000"); } kprintf("\n"); @@ -636,8 +638,8 @@ textstartup void __printargs(const char *prologue) { if (termios.c_lflag & PENDIN) kprintf(" PENDIN"); if (termios.c_lflag & XCASE) kprintf(" XCASE"); kprintf("\n"); - PRINT(" c_ispeed = %u", cfgetispeed(&termios)); - PRINT(" c_ospeed = %u", cfgetospeed(&termios)); + PRINT(" cfgetispeed() = %u", cfgetispeed(&termios)); + PRINT(" cfgetospeed() = %u", cfgetospeed(&termios)); PRINT(" c_cc[VMIN] = %d", termios.c_cc[VMIN]); PRINT(" c_cc[VTIME] = %d", termios.c_cc[VTIME]); PRINT(" c_cc[VINTR] = CTRL-%c", CTRL(termios.c_cc[VINTR])); diff --git a/libc/stdio/fflush_unlocked.c b/libc/stdio/fflush_unlocked.c index 1c71d90b6..c1f1207fd 100644 --- a/libc/stdio/fflush_unlocked.c +++ b/libc/stdio/fflush_unlocked.c @@ -19,7 +19,7 @@ #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/intrin/bits.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/macros.internal.h" #include "libc/mem/arraylist.internal.h" #include "libc/mem/mem.h" diff --git a/libc/str/lz4cpy.c b/libc/str/lz4cpy.c index 746581a41..c2859d47e 100644 --- a/libc/str/lz4cpy.c +++ b/libc/str/lz4cpy.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/intrin/repmovsb.h" #include "libc/nexgen32e/kompressor.h" #include "libc/str/str.h" diff --git a/libc/str/setlocale.c b/libc/str/setlocale.c index eadf87ce1..b7ebd61f0 100644 --- a/libc/str/setlocale.c +++ b/libc/str/setlocale.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/safemacros.internal.h" +#include "libc/intrin/strace.internal.h" #include "libc/str/locale.h" #include "libc/str/str.h" @@ -28,12 +29,17 @@ * "You can have any locale you want as long as it's C." -- Henry Ford */ char *setlocale(int category, const char *locale) { - if (!locale || (*locale == '\0')) return "C"; - if (!strcmp(locale, "C") || // - !strcmp(locale, "POSIX") || // - !strcmp(locale, "C.UTF-8")) { - return locale; + char *res; + if (!locale || (*locale == '\0')) { + res = "C"; + } else if (!strcmp(locale, "C") || // + !strcmp(locale, "POSIX") || // + !strcmp(locale, "C.UTF-8") || // + !strcmp(locale, "en_US.UTF-8")) { + res = locale; } else { - return NULL; + res = NULL; } + STRACE("setlocale(%d, %#s) → %s", category, locale, res); + return res; } diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 4fbaf2cd6..10b11f0a1 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -180,10 +180,7 @@ syscon compat SIGIOT 6 6 6 6 6 6 6 6 # PDP-11 feature; same # open() flags # # group name GNU/Systemd GNU/Systemd (Aarch64) XNU's Not UNIX! MacOS (Arm64) FreeBSD OpenBSD NetBSD Windoze Commentary -syscon open O_RDONLY 0 0 0 0 0 0 0 0 # consensus -syscon open O_WRONLY 1 1 1 1 1 1 1 1 # consensus syscon open O_RDWR 2 2 2 2 2 2 2 2 # consensus -syscon open O_ACCMODE 3 3 3 3 3 3 3 3 # O_RDONLY|O_WRONLY|O_RDWR syscon open O_APPEND 0x00000400 0x00000400 8 8 8 8 8 0x00000400 # bsd consensus & kNtFileAppendData; won't pose issues w/ mknod(S_IFIFO) [SYNC libc/calls/open-nt.c] syscon open O_CREAT 0x00000040 0x00000040 0x00000200 0x00000200 0x00000200 0x00000200 0x00000200 0x00000040 # bsd consensus & NT faked as Linux [SYNC libc/calls/open-nt.c] syscon open O_EXCL 0x00000080 0x00000080 0x00000800 0x00000800 0x00000800 0x00000800 0x00000800 0x00000080 # bsd consensus & NT faked as Linux [SYNC libc/calls/open-nt.c] @@ -1324,29 +1321,11 @@ syscon sched SCHED_RESET_ON_FORK 0x40000000 0x40000000 0 0 0 0 0 0 # = TIOCSETA → About 3,110 results (0.41 seconds) # # group name GNU/Systemd GNU/Systemd (Aarch64) XNU's Not UNIX! MacOS (Arm64) FreeBSD OpenBSD NetBSD The New Technology Commentary -syscon termios TCGETS 0x5401 0x5401 0x40487413 0x40487413 0x402c7413 0x402c7413 0x402c7413 0 # Gets console settings; tcgetattr(tty, argp) → ioctl(tty, TCGETS, struct termios *argp); polyfilled NT -syscon compat TIOCGETA 0x5401 0x5401 0x40487413 0x40487413 0x402c7413 0x402c7413 0x402c7413 0 # Gets console settings; = tcgetattr(tty, struct termios *argp) -#syscon compat TCGETA 0x5405 0x5405 0 0 0 0 0 0 # Gets console settings; ≈ ioctl(fd, TCGETA, struct termio *argp) -syscon termios TCSANOW 0 0 0 0 0 0 0 0 # Sets console settings; tcsetattr(fd, TCSANOW, argp); polyfilled NT -syscon termios TCSETS 0x5402 0x5402 0x80487414 0x80487414 0x802c7414 0x802c7414 0x802c7414 0x5402 # Sets console settings; = ioctl(tty, TCSETS, const struct termios *argp); polyfilled NT -syscon compat TIOCSETA 0x5402 0x5402 0x80487414 0x80487414 0x802c7414 0x802c7414 0x802c7414 0x5402 # Sets console settings; = ioctl(tty, TIOCSETA, const struct termios *argp); polyfilled NT -#syscon compat TCSETA 0x5402 0x5402 0x80487414 0x80487414 0x802c7414 0x802c7414 0x802c7414 0x5402 # Sets console settings; ≈ ioctl(tty, TCSETA, const struct termio *argp); polyfilled NT -syscon termios TCSADRAIN 1 1 1 1 1 1 1 1 # Drains output & sets console settings; tcsetawttr(fd, TCSADRAIN, argp); polyfilled NT -syscon termios TCSETSW 0x5403 0x5403 0x80487415 0x80487415 0x802c7415 0x802c7415 0x802c7415 0x5403 # Drains output & sets console settings; = ioctl(tty, TCSETSW, const struct termios *argp); polyfilled NT -syscon compat TIOCSETAW 0x5403 0x5403 0x80487415 0x80487415 0x802c7415 0x802c7415 0x802c7415 0x5403 # Drains output & sets console settings; = ioctl(tty, TIOCSETAW, const struct termios *argp); polyfilled NT -#syscon compat TCSETAW 0x5403 0x5403 0x80487415 0x80487415 0x802c7415 0x802c7415 0x802c7415 0x5403 # Drains output & sets console settings; ≈ ioctl(tty, TCSETAW, const struct termio *argp); polyfilled NT -syscon termios TCSAFLUSH 2 2 2 2 2 2 2 2 # Drops input & drains output & sets console settings; tcsetafttr(fd, TCSAFLUSH, argp); polyfilled NT -syscon termios TCSETSF 0x5404 0x5404 0x80487416 0x80487416 0x802c7416 0x802c7416 0x802c7416 0x5404 # Drops input & drains output & sets console settings; = ioctl(tty, TCSETSF, const struct termios *argp); polyfilled NT -syscon compat TIOCSETAF 0x5404 0x5404 0x80487416 0x80487416 0x802c7416 0x802c7416 0x802c7416 0x5402 # Drops input & drains output & sets console settings; = ioctl(tty, TIOCSETAF, const struct termios *argp); polyfilled NT -#syscon compat TCSETAF 0x5404 0x5404 0x80487416 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 0x5413 1074295912 1074295912 1074295912 1074295912 1074295912 0x5413 # ioctl(tty, TIOCGWINSZ, struct winsize *argp); polyfilled NT syscon termios TIOCSWINSZ 0x5414 0x5414 0x80087467 0x80087467 0x80087467 0x80087467 0x80087467 0x5414 # ioctl(tty, TIOCSWINSZ, const struct winsize *argp) (faked NT) syscon termios TIOCINQ 0x541b 0x541b 0x4004667f 0x4004667f 0x4004667f 0x4004667f 0x4004667f 0x4004667f # [Linuxism] same as FIONREAD syscon termios TIOCOUTQ 0x5411 0x5411 0x40047473 0x40047473 0x40047473 0x40047473 0x40047473 0 # get # bytes queued in TTY's output buffer ioctl(tty, TIOCSWINSZ, const struct winsize *argp) -syscon termios TIOCGPGRP 0x540f 0x540f 0x40047477 0x40047477 0x40047477 0x40047477 0x40047477 0 # tcgetpgrp(): get pgrp of tty syscon termios TIOCSPGRP 0x5410 0x5410 0x80047476 0x80047476 0x80047476 0x80047476 0x80047476 0 # tcsetpgrp(): set pgrp of tty -syscon termios TIOCSBRK 0x5427 0x5427 0x2000747b 0x2000747b 0x2000747b 0x2000747b 0x2000747b 0 # set break bit -syscon termios TIOCCBRK 0x5428 0x5428 0x2000747a 0x2000747a 0x2000747a 0x2000747a 0x2000747a 0 # boop syscon termios TIOCCONS 0x541d 0x541d 0x80047462 0x80047462 0x80047462 0x80047462 0x80047462 0 # boop syscon termios TIOCGETD 0x5424 0x5424 0x4004741a 0x4004741a 0x4004741a 0x4004741a 0x4004741a 0 # boop syscon termios TIOCNOTTY 0x5422 0x5422 0x20007471 0x20007471 0x20007471 0x20007471 0x20007471 0 # boop @@ -1354,44 +1333,7 @@ syscon termios TIOCNXCL 0x540d 0x540d 0x2000740e 0x2000740e 0x2000740e syscon termios TIOCSCTTY 0x540e 0x540e 0x20007461 0x20007461 0x20007461 0x20007461 0x20007461 0 # makes terminal controlling terminal of calling process (see login_tty) syscon termios TIOCSETD 0x5423 0x5423 0x8004741b 0x8004741b 0x8004741b 0x8004741b 0x8004741b 0 # boop syscon termios TIOCSIG 0x40045436 0x40045436 0x2000745f 0x2000745f 0x2004745f 0x8004745f 0x8004745f 0 # boop -syscon termios TIOCSTI 0x5412 0x5412 0x80017472 0x80017472 0x80017472 0 0 0 # boop -syscon termios TIOCGSID 0x5429 0x5429 0x40047463 0x40047463 0x40047463 0x40047463 0x40047463 0 # boop -syscon termios TABLDISC 0 0 0x3 0x3 0 0x3 0x3 0 # boop -syscon termios SLIPDISC 0 0 0x4 0x4 0x4 0x4 0x4 0 # boop -syscon termios PPPDISC 0 0 0x5 0x5 0x5 0x5 0x5 0 # boop -syscon termios TCSBRK 0x5409 0x5409 0x2000745e 0x2000745e 0x2000745e 0x2000745e 0x2000745e 0 # TIOCDRAIN on BSD; TIOCDRAIN on BSD -syscon termios TIOCSTAT 0 0 0x20007465 0x20007465 0x20007465 0x20007465 0x20007465 0 # boop -syscon termios TIOCSTART 0 0 0x2000746e 0x2000746e 0x2000746e 0x2000746e 0x2000746e 0 # boop -syscon termios TIOCCDTR 0 0 0x20007478 0x20007478 0x20007478 0x20007478 0x20007478 0 # clear data terminal ready -syscon termios TIOCSDTR 0 0 0x20007479 0x20007479 0x20007479 0x20007479 0x20007479 0 # boop -syscon termios TIOCEXT 0 0 0x80047460 0x80047460 0x80047460 0x80047460 0x80047460 0 # boop -syscon termios TIOCGDRAINWAIT 0 0 0x40047456 0x40047456 0x40047456 0 0 0 # boop -syscon termios TIOCTIMESTAMP 0 0 0x40107459 0x40107459 0x40107459 0 0 0 # boop -syscon termios TIOCSDRAINWAIT 0 0 0x80047457 0x80047457 0x80047457 0 0 0 # boop -syscon termios TIOCREMOTE 0 0 0x80047469 0x80047469 0 0x80047469 0x80047469 0 # boop -syscon termios TTYDISC 0 0 0 0 0 0 0 0 # boop -syscon termios TIOCFLAG_SOFTCAR 0 0 0 0 0 0x1 0x1 0 # boop -syscon termios TIOCFLAG_PPS 0 0 0 0 0 0x10 0x10 0 # boop -syscon termios TIOCFLAG_CLOCAL 0 0 0 0 0 0x2 0x2 0 # boop -syscon termios TIOCCHKVERAUTH 0 0 0 0 0 0x2000741e 0x2000741e 0 # boop -syscon termios TIOCGFLAGS 0 0 0 0 0 0x4004745d 0x4004745d 0 # boop -syscon termios TIOCGTSTAMP 0 0 0 0 0 0x4010745b 0x4010745b 0 # boop -syscon termios STRIPDISC 0 0 0 0 0 0x6 0x6 0 # boop -syscon termios NMEADISC 0 0 0 0 0 0x7 0x7 0 # boop -syscon termios TIOCUCNTL_CBRK 0 0 0 0 0 0x7a 0x7a 0 # boop -syscon termios TIOCFLAG_MDMBUF 0 0 0 0 0 0x8 0x8 0 # boop -syscon termios TIOCSETVERAUTH 0 0 0 0 0 0x8004741c 0x8004741c 0 # boop -syscon termios TIOCSFLAGS 0 0 0 0 0 0x8004745c 0x8004745c 0 # boop -syscon termios TIOCSTSTAMP 0 0 0 0 0 0x8008745a 0x8008745a 0 # boop -syscon termios ENDRUNDISC 0 0 0 0 0 0x9 0x9 0 # boop -syscon termios TIOCPTMASTER 0 0 0 0 0x2000741c 0 0 0 # boop -syscon termios TIOCPTYGRANT 0 0 0x20007454 0x20007454 0 0 0 0 # xnu grantpt() -syscon termios TIOCPTYUNLK 0 0 0x20007452 0x20007452 0 0 0 0 # xnu unlockpt() -syscon termios TIOCPTYGNAME 0 0 0x40807453 0x40807453 0 0 0 0 # xnu ptyname() -syscon termios TIOCPTSNAME 0 0 0 0 0 0 0x48087448 0 # netbsd ptyname() -syscon termios FIODGNAME 0 0 0 0 0x80106678 0 0 0 # freebsd ptsname_r() -syscon termios NETGRAPHDISC 0 0 0 0 0x6 0 0 0 # boop -syscon termios H4DISC 0 0 0 0 0x7 0 0 0 # boop +syscon termios TIOCSTI 0x5412 0x5412 0x80017472 0x80017472 0x80017472 0 0x80017472 0 # boop # Teletypewriter Control Modes # @@ -1406,7 +1348,9 @@ syscon termios CREAD 0b0000000010000000 0b0000000010000000 0b000000100000000 syscon termios PARENB 0b0000000100000000 0b0000000100000000 0b000001000000000000 0b000001000000000000 0b000001000000000000 0b0001000000000000 0b0001000000000000 0b0000000100000000 # termios.c_cflag syscon termios PARODD 0b0000001000000000 0b0000001000000000 0b000010000000000000 0b000010000000000000 0b000010000000000000 0b0010000000000000 0b0010000000000000 0b0000001000000000 # termios.c_cflag syscon termios HUPCL 0b0000010000000000 0b0000010000000000 0b000100000000000000 0b000100000000000000 0b000100000000000000 0b0100000000000000 0b0100000000000000 0b0000010000000000 # termios.c_cflag; bsd consensus -syscon termios CLOCAL 0b0000100000000000 0b0000100000000000 0b1000000000000000 0b1000000000000000 0b1000000000000000 0b1000000000000000 0b1000000000000000 0b0000100000000000 # termios.c_cflag; consensus +syscon termios CLOCAL 0b0000100000000000 0b0000100000000000 0b001000000000000000 0b001000000000000000 0b001000000000000000 0b1000000000000000 0b1000000000000000 0b0000100000000000 # termios.c_cflag; consensus +syscon termios CMSPAR 0x40000000 0x40000000 0 0 0 0 0 0 # termios.c_cflag; not in POSIX +syscon termios CRTSCTS 0x80000000 0x80000000 0x00030000 0x00030000 0x00030000 0x00010000 0x00010000 0x80000000 # termios.c_cflag # Teletypewriter Local Modes # @@ -1459,29 +1403,23 @@ syscon termios ONLRET 0b0000000000100000 0b0000000000100000 0b00000000000100 syscon termios OFILL 0b0000000001000000 0b0000000001000000 0b000000000010000000 0b000000000010000000 0 0 0 0b0000000001000000 # termios.c_oflag syscon termios OFDEL 0b0000000010000000 0b0000000010000000 0b100000000000000000 0b100000000000000000 0 0 0 0b0000000010000000 # termios.c_oflag syscon termios NLDLY 0b0000000100000000 0b0000000100000000 0b000000001100000000 0b000000001100000000 0b000000001100000000 0 0 0b0000000100000000 # (termios.c_oflag & NLDLY) ∈ {NL0,NL1,NL2,NL3} -syscon termios NL0 0b0000000000000000 0b0000000000000000 0b000000000000000000 0b000000000000000000 0b000000000000000000 0 0b000000000000000000 0b0000000000000000 # (termios.c_oflag & NLDLY) == NL0 syscon termios NL1 0b0000000100000000 0b0000000100000000 0b000000000100000000 0b000000000100000000 0b000000000100000000 0 0b000000000100000000 0b0000000100000000 # (termios.c_oflag & NLDLY) == NL1 syscon termios NL2 0 0 0b000000001000000000 0b000000001000000000 0b000000001000000000 0 0b000000001000000000 0 # (termios.c_oflag & NLDLY) == NL2 syscon termios NL3 0 0 0b000000001100000000 0b000000001100000000 0b000000001100000000 0 0b000000001100000000 0 # (termios.c_oflag & NLDLY) == NL3 syscon termios CRDLY 0b0000011000000000 0b0000011000000000 0b000011000000000000 0b000011000000000000 0b000011000000000000 0 0 0b0000011000000000 # (termios.c_oflag & CRDLY) ∈ {CR0,CR1,CR2,CR3} -syscon termios CR0 0b0000000000000000 0b0000000000000000 0b000000000000000000 0b000000000000000000 0b000000000000000000 0 0b000000000000000000 0b0000000000000000 # (termios.c_oflag & CRDLY) == CR0 syscon termios CR1 0b0000001000000000 0b0000001000000000 0b000001000000000000 0b000001000000000000 0b000001000000000000 0 0b000001000000000000 0b0000001000000000 # (termios.c_oflag & CRDLY) == CR1 syscon termios CR2 0b0000010000000000 0b0000010000000000 0b000010000000000000 0b000010000000000000 0b000010000000000000 0 0b000000010000000000 0b0000010000000000 # (termios.c_oflag & CRDLY) == CR2 syscon termios CR3 0b0000011000000000 0b0000011000000000 0b000011000000000000 0b000011000000000000 0b000011000000000000 0 0b000000011000000000 0b0000011000000000 # (termios.c_oflag & CRDLY) == CR3 syscon termios TABDLY 0b0001100000000000 0b0001100000000000 0b000000110000000100 0b000000110000000100 0b000000000000000100 0 0 0b0001100000000000 # (termios.c_oflag & TABDLY) ∈ {TAB0,TAB1,TAB2,TAB3,XTABS} -syscon termios TAB0 0b0000000000000000 0b0000000000000000 0b000000000000000000 0b000000000000000000 0b000000000000000000 0 0b000000000000000000 0b0000000000000000 # (termios.c_oflag & TABDLY) == TAB0 syscon termios TAB1 0b0000100000000000 0b0000100000000000 0b000000010000000000 0b000000010000000000 0b000000010000000000 0 0b000000010000000000 0b0000100000000000 # (termios.c_oflag & TABDLY) == TAB1 syscon termios TAB2 0b0001000000000000 0b0001000000000000 0b000000100000000000 0b000000100000000000 0b000000100000000000 0 0b000000100000000000 0b0001000000000000 # (termios.c_oflag & TABDLY) == TAB2 syscon termios TAB3 0b0001100000000000 0b0001100000000000 0b000000000000000100 0b000000000000000100 0b000000000000000100 0 0b000000000000000100 0b0001100000000000 # (termios.c_oflag & TABDLY) == TAB3 syscon termios XTABS 0b0001100000000000 0b0001100000000000 0b000000110000000000 0b000000110000000000 0b000000110000000000 0 0b000000110000000000 0b0001100000000000 # (termios.c_oflag & TABDLY) == XTABS syscon termios BSDLY 0b0010000000000000 0b0010000000000000 0b001000000000000000 0b001000000000000000 0b001000000000000000 0 0 0b0010000000000000 # termios.c_oflag -syscon termios BS0 0b0000000000000000 0b0000000000000000 0b000000000000000000 0b000000000000000000 0b000000000000000000 0 0 0b0000000000000000 # termios.c_oflag syscon termios BS1 0b0010000000000000 0b0010000000000000 0b001000000000000000 0b001000000000000000 0b001000000000000000 0 0 0b0010000000000000 # termios.c_oflag syscon termios VTDLY 0b0100000000000000 0b0100000000000000 0b010000000000000000 0b010000000000000000 0b010000000000000000 0 0 0b0100000000000000 # termios.c_oflag -syscon termios VT0 0b0000000000000000 0b0000000000000000 0b000000000000000000 0b000000000000000000 0b000000000000000000 0 0 0b0000000000000000 # termios.c_oflag syscon termios VT1 0b0100000000000000 0b0100000000000000 0b010000000000000000 0b010000000000000000 0b010000000000000000 0 0 0b0100000000000000 # termios.c_oflag syscon termios FFDLY 0b1000000000000000 0b1000000000000000 0b000100000000000000 0b000100000000000000 0b000100000000000000 0 0 0b1000000000000000 # termios.c_oflag -syscon termios FF0 0b0000000000000000 0b0000000000000000 0b000000000000000000 0b000000000000000000 0b000000000000000000 0 0 0b0000000000000000 # termios.c_oflag syscon termios FF1 0b1000000000000000 0b1000000000000000 0b000100000000000000 0b000100000000000000 0b000100000000000000 0 0 0b1000000000000000 # termios.c_oflag # Teletypewriter Special Control Character Assignments @@ -1489,7 +1427,6 @@ syscon termios FF1 0b1000000000000000 0b1000000000000000 0b000100000000000 # group name GNU/Systemd GNU/Systemd (Aarch64) XNU's Not UNIX! MacOS (Arm64) FreeBSD OpenBSD NetBSD The New Technology Commentary syscon termios VMIN 6+1 6+1 16 16 16 16 16 6 # termios.c_cc[VMIN]=𝑥 in non-canonical mode can be set to 0 for non-blocking reads, 1 for single character raw mode reads, or higher to buffer syscon termios VTIME 5+1 5+1 17 17 17 17 17 5 # termios.c_cc[VTIME]=𝑥 sets non-canonical read timeout to 𝑥×𝟷𝟶𝟶ms which is needed when entering escape sequences manually with the escape key -syscon termios NCCS 20 20 20 20 20 20 20 20 # ARRAYLEN(termios.c_cc); we schlep c_line into c_cc on linux syscon termios VINTR 0+1 0+1 8 8 8 8 8 0 # termios.c_cc[VINTR]=𝑥 syscon termios VQUIT 1+1 1+1 9 9 9 9 9 1 # termios.c_cc[VQUIT]=𝑥 syscon termios VERASE 2+1 2+1 3 3 3 3 3 2 # termios.c_cc[VERASE]=𝑥 @@ -1505,35 +1442,11 @@ syscon termios VDISCARD 13+1 13+1 15 15 15 15 15 13 # termios syscon termios VWERASE 14+1 14+1 4 4 4 4 4 14 # termios.c_cc[VWERASE]=𝑥 syscon termios VLNEXT 15+1 15+1 14 14 14 14 14 15 # termios.c_cc[VLNEXT]=𝑥 syscon termios VEOL2 16+1 16+1 2 2 2 2 2 16 # termios.c_cc[VEOL2]=𝑥 +syscon termios _POSIX_VDISABLE 0 0 255 255 255 255 255 0 # termios.c_cc tombstone value -syscon termios TIOCSERGETLSR 0x5459 0x5459 0 0 0 0 0 0 # -syscon termios TIOCSERGETMULTI 0x545a 0x545a 0 0 0 0 0 0 # -syscon termios TIOCSERSETMULTI 0x545b 0x545b 0 0 0 0 0 0 # -syscon termios TIOCSER_TEMT 1 1 0 0 0 0 0 0 # -syscon termios VERIFY 47 47 0 0 0 0 0 0 -syscon termios CIBAUD 0x100f0000 0x100f0000 0 0 0 0 0 0 -syscon termios CMSPAR 0x40000000 0x40000000 0 0 0 0 0 0 -syscon termios BUSY 4 4 0 0 0 0 0 0 -syscon termios CBAUD 0x100f 0x100f 0 0 0 0 0 0 -syscon termios CBAUDEX 0x1000 0x1000 0 0 0 0 0 0 -syscon termios EXTA 14 14 0x4b00 0x4b00 0x4b00 0x4b00 0x4b00 0 # bsd consensus -syscon termios EXTB 15 15 0x9600 0x9600 0x9600 0x9600 0x9600 0 # bsd consensus -syscon termios ERA 0x02002c 0x02002c 45 45 45 0 0 0 -syscon termios EMPTY 0 0 0 0 0 0 0 0 # consensus - -syscon termios TCFLSH 0x540b 0x540b 0x80047410 0x80047410 0x80047410 0x80047410 0x80047410 0 # see tcflush; TIOCFLUSH on BSD -syscon termios TIOCFLUSH 0x540b 0x540b 0x80047410 0x80047410 0x80047410 0x80047410 0x80047410 0 # see tcflush; TCFLSH on Linux -syscon termios TCIFLUSH 0 0 1 1 1 1 1 0 # see tcflush; bsd consensus; faked nt -syscon termios TCOFLUSH 1 1 2 2 2 2 2 1 # see tcflush; bsd consensus; faked nt -syscon termios TCIOFLUSH 2 2 3 3 3 3 3 2 # see tcflush; bsd consensus; faked nt - -syscon termios TCXONC 0x540A 0x540A 0 0 0 0 0 0 # see tcflow -syscon termios TIOCSTOP 0x540A 0x540A 0x2000746f 0x2000746f 0x2000746f 0x2000746f 0x2000746f 0 # see tcflow -syscon termios TIOCSTART 0x540A 0x540A 0x2000746e 0x2000746e 0x2000746e 0x2000746e 0x2000746e 0 # see tcflow -syscon termios TCOOFF 0 0 1 1 1 1 1 0 # see tcflow; bsd consensus -syscon termios TCOON 1 1 2 2 2 2 2 1 # see tcflow; bsd consensus -syscon termios TCIOFF 2 2 3 3 3 3 3 2 # see tcflow; bsd consensus -syscon termios TCION 3 3 4 4 4 4 4 3 # see tcflow; bsd consensus +syscon termios TCIFLUSH 0 0 1 1 1 1 1 0 # see tcflush; FREAD on BSD; faked nt +syscon termios TCOFLUSH 1 1 2 2 2 2 2 1 # see tcflush; FWRITE on BSD; faked nt +syscon termios TCIOFLUSH 2 2 3 3 3 3 3 2 # see tcflush; FREAD|FWRITE on BSD; faked nt syscon termios CSTART 17 17 17 17 17 17 17 0 # unix consensus syscon termios CSTOP 19 19 19 19 19 19 19 0 # unix consensus @@ -1552,7 +1465,6 @@ syscon pty TIOCPKT_START 8 8 8 8 8 8 8 8 # unix consensus syscon pty TIOCPKT_NOSTOP 16 16 16 16 16 16 16 16 # unix consensus syscon pty TIOCPKT_DOSTOP 32 32 32 32 32 32 32 32 # unix consensus syscon pty TIOCPKT_IOCTL 64 64 64 64 64 64 64 64 # unix consensus -syscon pty PTMGET 0 0 0 0 0 0x40287401 0x40287401 -1 # for /dev/ptm # Modem Control # diff --git a/libc/sysv/consts/BS0.S b/libc/sysv/consts/BS0.S deleted file mode 100644 index ace0605c8..000000000 --- a/libc/sysv/consts/BS0.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,BS0,0b0000000000000000,0b0000000000000000,0b000000000000000000,0b000000000000000000,0b000000000000000000,0,0,0b0000000000000000 diff --git a/libc/sysv/consts/BUSY.S b/libc/sysv/consts/BUSY.S deleted file mode 100644 index fd5dc9310..000000000 --- a/libc/sysv/consts/BUSY.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,BUSY,4,4,0,0,0,0,0,0 diff --git a/libc/sysv/consts/CBAUD.S b/libc/sysv/consts/CBAUD.S deleted file mode 100644 index 4cfe09de3..000000000 --- a/libc/sysv/consts/CBAUD.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,CBAUD,0x100f,0x100f,0,0,0,0,0,0 diff --git a/libc/sysv/consts/CBAUDEX.S b/libc/sysv/consts/CBAUDEX.S deleted file mode 100644 index f75c4289a..000000000 --- a/libc/sysv/consts/CBAUDEX.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,CBAUDEX,0x1000,0x1000,0,0,0,0,0,0 diff --git a/libc/sysv/consts/CIBAUD.S b/libc/sysv/consts/CIBAUD.S deleted file mode 100644 index ea62aca33..000000000 --- a/libc/sysv/consts/CIBAUD.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,CIBAUD,0x100f0000,0x100f0000,0,0,0,0,0,0 diff --git a/libc/sysv/consts/CLOCAL.S b/libc/sysv/consts/CLOCAL.S index 73a9a21b5..49b92ce7e 100644 --- a/libc/sysv/consts/CLOCAL.S +++ b/libc/sysv/consts/CLOCAL.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon termios,CLOCAL,0b0000100000000000,0b0000100000000000,0b1000000000000000,0b1000000000000000,0b1000000000000000,0b1000000000000000,0b1000000000000000,0b0000100000000000 +.syscon termios,CLOCAL,0b0000100000000000,0b0000100000000000,0b001000000000000000,0b001000000000000000,0b001000000000000000,0b1000000000000000,0b1000000000000000,0b0000100000000000 diff --git a/libc/sysv/consts/CR0.S b/libc/sysv/consts/CR0.S deleted file mode 100644 index 94f02f1b1..000000000 --- a/libc/sysv/consts/CR0.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,CR0,0b0000000000000000,0b0000000000000000,0b000000000000000000,0b000000000000000000,0b000000000000000000,0,0b000000000000000000,0b0000000000000000 diff --git a/libc/sysv/consts/CRTSCTS.S b/libc/sysv/consts/CRTSCTS.S new file mode 100644 index 000000000..aaa59c2a3 --- /dev/null +++ b/libc/sysv/consts/CRTSCTS.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon termios,CRTSCTS,0x80000000,0x80000000,0x00030000,0x00030000,0x00030000,0x00010000,0x00010000,0x80000000 diff --git a/libc/sysv/consts/EMPTY.S b/libc/sysv/consts/EMPTY.S deleted file mode 100644 index b0296b76c..000000000 --- a/libc/sysv/consts/EMPTY.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,EMPTY,0,0,0,0,0,0,0,0 diff --git a/libc/sysv/consts/ENDRUNDISC.S b/libc/sysv/consts/ENDRUNDISC.S deleted file mode 100644 index 941bb7a93..000000000 --- a/libc/sysv/consts/ENDRUNDISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,ENDRUNDISC,0,0,0,0,0,0x9,0x9,0 diff --git a/libc/sysv/consts/ERA.S b/libc/sysv/consts/ERA.S deleted file mode 100644 index 52358df42..000000000 --- a/libc/sysv/consts/ERA.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,ERA,0x02002c,0x02002c,45,45,45,0,0,0 diff --git a/libc/sysv/consts/EXTA.S b/libc/sysv/consts/EXTA.S deleted file mode 100644 index 14fa63d08..000000000 --- a/libc/sysv/consts/EXTA.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,EXTA,14,14,0x4b00,0x4b00,0x4b00,0x4b00,0x4b00,0 diff --git a/libc/sysv/consts/EXTB.S b/libc/sysv/consts/EXTB.S deleted file mode 100644 index 1e32535bf..000000000 --- a/libc/sysv/consts/EXTB.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,EXTB,15,15,0x9600,0x9600,0x9600,0x9600,0x9600,0 diff --git a/libc/sysv/consts/FF0.S b/libc/sysv/consts/FF0.S deleted file mode 100644 index db3571241..000000000 --- a/libc/sysv/consts/FF0.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,FF0,0b0000000000000000,0b0000000000000000,0b000000000000000000,0b000000000000000000,0b000000000000000000,0,0,0b0000000000000000 diff --git a/libc/sysv/consts/FIODGNAME.S b/libc/sysv/consts/FIODGNAME.S deleted file mode 100644 index 51887d338..000000000 --- a/libc/sysv/consts/FIODGNAME.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,FIODGNAME,0,0,0,0,0x80106678,0,0,0 diff --git a/libc/sysv/consts/H4DISC.S b/libc/sysv/consts/H4DISC.S deleted file mode 100644 index 5191c9573..000000000 --- a/libc/sysv/consts/H4DISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,H4DISC,0,0,0,0,0x7,0,0,0 diff --git a/libc/sysv/consts/NCCS.S b/libc/sysv/consts/NCCS.S deleted file mode 100644 index f4baf7a71..000000000 --- a/libc/sysv/consts/NCCS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,NCCS,20,20,20,20,20,20,20,20 diff --git a/libc/sysv/consts/NETGRAPHDISC.S b/libc/sysv/consts/NETGRAPHDISC.S deleted file mode 100644 index 00a5d6737..000000000 --- a/libc/sysv/consts/NETGRAPHDISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,NETGRAPHDISC,0,0,0,0,0x6,0,0,0 diff --git a/libc/sysv/consts/NL0.S b/libc/sysv/consts/NL0.S deleted file mode 100644 index 06495af96..000000000 --- a/libc/sysv/consts/NL0.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,NL0,0b0000000000000000,0b0000000000000000,0b000000000000000000,0b000000000000000000,0b000000000000000000,0,0b000000000000000000,0b0000000000000000 diff --git a/libc/sysv/consts/NMEADISC.S b/libc/sysv/consts/NMEADISC.S deleted file mode 100644 index b8bbc530a..000000000 --- a/libc/sysv/consts/NMEADISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,NMEADISC,0,0,0,0,0,0x7,0x7,0 diff --git a/libc/sysv/consts/O_ACCMODE.S b/libc/sysv/consts/O_ACCMODE.S deleted file mode 100644 index 00137d24f..000000000 --- a/libc/sysv/consts/O_ACCMODE.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon open,O_ACCMODE,3,3,3,3,3,3,3,3 diff --git a/libc/sysv/consts/O_RDONLY.S b/libc/sysv/consts/O_RDONLY.S deleted file mode 100644 index 82d744d93..000000000 --- a/libc/sysv/consts/O_RDONLY.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon open,O_RDONLY,0,0,0,0,0,0,0,0 diff --git a/libc/sysv/consts/O_WRONLY.S b/libc/sysv/consts/O_WRONLY.S deleted file mode 100644 index fa88ff5f8..000000000 --- a/libc/sysv/consts/O_WRONLY.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon open,O_WRONLY,1,1,1,1,1,1,1,1 diff --git a/libc/sysv/consts/PPPDISC.S b/libc/sysv/consts/PPPDISC.S deleted file mode 100644 index 9db0bbcc2..000000000 --- a/libc/sysv/consts/PPPDISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,PPPDISC,0,0,0x5,0x5,0x5,0x5,0x5,0 diff --git a/libc/sysv/consts/PTMGET.S b/libc/sysv/consts/PTMGET.S deleted file mode 100644 index 260ceec95..000000000 --- a/libc/sysv/consts/PTMGET.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon pty,PTMGET,0,0,0,0,0,0x40287401,0x40287401,-1 diff --git a/libc/sysv/consts/SLIPDISC.S b/libc/sysv/consts/SLIPDISC.S deleted file mode 100644 index 477f86d62..000000000 --- a/libc/sysv/consts/SLIPDISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,SLIPDISC,0,0,0x4,0x4,0x4,0x4,0x4,0 diff --git a/libc/sysv/consts/STRIPDISC.S b/libc/sysv/consts/STRIPDISC.S deleted file mode 100644 index 5e7d94b45..000000000 --- a/libc/sysv/consts/STRIPDISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,STRIPDISC,0,0,0,0,0,0x6,0x6,0 diff --git a/libc/sysv/consts/TAB0.S b/libc/sysv/consts/TAB0.S deleted file mode 100644 index 9b4007ad9..000000000 --- a/libc/sysv/consts/TAB0.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TAB0,0b0000000000000000,0b0000000000000000,0b000000000000000000,0b000000000000000000,0b000000000000000000,0,0b000000000000000000,0b0000000000000000 diff --git a/libc/sysv/consts/TABLDISC.S b/libc/sysv/consts/TABLDISC.S deleted file mode 100644 index 19867b86d..000000000 --- a/libc/sysv/consts/TABLDISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TABLDISC,0,0,0x3,0x3,0,0x3,0x3,0 diff --git a/libc/sysv/consts/TCFLSH.S b/libc/sysv/consts/TCFLSH.S deleted file mode 100644 index de1664201..000000000 --- a/libc/sysv/consts/TCFLSH.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCFLSH,0x540b,0x540b,0x80047410,0x80047410,0x80047410,0x80047410,0x80047410,0 diff --git a/libc/sysv/consts/TCGETS.S b/libc/sysv/consts/TCGETS.S deleted file mode 100644 index 8d4ca45e5..000000000 --- a/libc/sysv/consts/TCGETS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCGETS,0x5401,0x5401,0x40487413,0x40487413,0x402c7413,0x402c7413,0x402c7413,0 diff --git a/libc/sysv/consts/TCIOFF.S b/libc/sysv/consts/TCIOFF.S deleted file mode 100644 index c875b6674..000000000 --- a/libc/sysv/consts/TCIOFF.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCIOFF,2,2,3,3,3,3,3,2 diff --git a/libc/sysv/consts/TCION.S b/libc/sysv/consts/TCION.S deleted file mode 100644 index fbd71a5c2..000000000 --- a/libc/sysv/consts/TCION.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCION,3,3,4,4,4,4,4,3 diff --git a/libc/sysv/consts/TCOOFF.S b/libc/sysv/consts/TCOOFF.S deleted file mode 100644 index 8889bbd37..000000000 --- a/libc/sysv/consts/TCOOFF.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCOOFF,0,0,1,1,1,1,1,0 diff --git a/libc/sysv/consts/TCOON.S b/libc/sysv/consts/TCOON.S deleted file mode 100644 index 44d6456b9..000000000 --- a/libc/sysv/consts/TCOON.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCOON,1,1,2,2,2,2,2,1 diff --git a/libc/sysv/consts/TCSADRAIN.S b/libc/sysv/consts/TCSADRAIN.S deleted file mode 100644 index e0d479b8e..000000000 --- a/libc/sysv/consts/TCSADRAIN.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCSADRAIN,1,1,1,1,1,1,1,1 diff --git a/libc/sysv/consts/TCSAFLUSH.S b/libc/sysv/consts/TCSAFLUSH.S deleted file mode 100644 index 8970e531e..000000000 --- a/libc/sysv/consts/TCSAFLUSH.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCSAFLUSH,2,2,2,2,2,2,2,2 diff --git a/libc/sysv/consts/TCSANOW.S b/libc/sysv/consts/TCSANOW.S deleted file mode 100644 index 026b37e75..000000000 --- a/libc/sysv/consts/TCSANOW.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCSANOW,0,0,0,0,0,0,0,0 diff --git a/libc/sysv/consts/TCSBRK.S b/libc/sysv/consts/TCSBRK.S deleted file mode 100644 index bc9eba60d..000000000 --- a/libc/sysv/consts/TCSBRK.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCSBRK,0x5409,0x5409,0x2000745e,0x2000745e,0x2000745e,0x2000745e,0x2000745e,0 diff --git a/libc/sysv/consts/TCSETS.S b/libc/sysv/consts/TCSETS.S deleted file mode 100644 index 2bad14688..000000000 --- a/libc/sysv/consts/TCSETS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCSETS,0x5402,0x5402,0x80487414,0x80487414,0x802c7414,0x802c7414,0x802c7414,0x5402 diff --git a/libc/sysv/consts/TCSETSF.S b/libc/sysv/consts/TCSETSF.S deleted file mode 100644 index 6b542236b..000000000 --- a/libc/sysv/consts/TCSETSF.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCSETSF,0x5404,0x5404,0x80487416,0x80487416,0x802c7416,0x802c7416,0x802c7416,0x5404 diff --git a/libc/sysv/consts/TCSETSW.S b/libc/sysv/consts/TCSETSW.S deleted file mode 100644 index 992b8ee5e..000000000 --- a/libc/sysv/consts/TCSETSW.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCSETSW,0x5403,0x5403,0x80487415,0x80487415,0x802c7415,0x802c7415,0x802c7415,0x5403 diff --git a/libc/sysv/consts/TCXONC.S b/libc/sysv/consts/TCXONC.S deleted file mode 100644 index adc1b31b7..000000000 --- a/libc/sysv/consts/TCXONC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TCXONC,0x540A,0x540A,0,0,0,0,0,0 diff --git a/libc/sysv/consts/TIOCCBRK.S b/libc/sysv/consts/TIOCCBRK.S deleted file mode 100644 index 8278cd086..000000000 --- a/libc/sysv/consts/TIOCCBRK.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCCBRK,0x5428,0x5428,0x2000747a,0x2000747a,0x2000747a,0x2000747a,0x2000747a,0 diff --git a/libc/sysv/consts/TIOCCDTR.S b/libc/sysv/consts/TIOCCDTR.S deleted file mode 100644 index e099450d2..000000000 --- a/libc/sysv/consts/TIOCCDTR.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCCDTR,0,0,0x20007478,0x20007478,0x20007478,0x20007478,0x20007478,0 diff --git a/libc/sysv/consts/TIOCCHKVERAUTH.S b/libc/sysv/consts/TIOCCHKVERAUTH.S deleted file mode 100644 index eda2cce44..000000000 --- a/libc/sysv/consts/TIOCCHKVERAUTH.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCCHKVERAUTH,0,0,0,0,0,0x2000741e,0x2000741e,0 diff --git a/libc/sysv/consts/TIOCEXT.S b/libc/sysv/consts/TIOCEXT.S deleted file mode 100644 index c544bd5ca..000000000 --- a/libc/sysv/consts/TIOCEXT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCEXT,0,0,0x80047460,0x80047460,0x80047460,0x80047460,0x80047460,0 diff --git a/libc/sysv/consts/TIOCFLAG_CLOCAL.S b/libc/sysv/consts/TIOCFLAG_CLOCAL.S deleted file mode 100644 index 1a4d55d96..000000000 --- a/libc/sysv/consts/TIOCFLAG_CLOCAL.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCFLAG_CLOCAL,0,0,0,0,0,0x2,0x2,0 diff --git a/libc/sysv/consts/TIOCFLAG_MDMBUF.S b/libc/sysv/consts/TIOCFLAG_MDMBUF.S deleted file mode 100644 index e3e7e7bcb..000000000 --- a/libc/sysv/consts/TIOCFLAG_MDMBUF.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCFLAG_MDMBUF,0,0,0,0,0,0x8,0x8,0 diff --git a/libc/sysv/consts/TIOCFLAG_PPS.S b/libc/sysv/consts/TIOCFLAG_PPS.S deleted file mode 100644 index 571aed068..000000000 --- a/libc/sysv/consts/TIOCFLAG_PPS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCFLAG_PPS,0,0,0,0,0,0x10,0x10,0 diff --git a/libc/sysv/consts/TIOCFLAG_SOFTCAR.S b/libc/sysv/consts/TIOCFLAG_SOFTCAR.S deleted file mode 100644 index 3c5e6548a..000000000 --- a/libc/sysv/consts/TIOCFLAG_SOFTCAR.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCFLAG_SOFTCAR,0,0,0,0,0,0x1,0x1,0 diff --git a/libc/sysv/consts/TIOCFLUSH.S b/libc/sysv/consts/TIOCFLUSH.S deleted file mode 100644 index 285e4fe98..000000000 --- a/libc/sysv/consts/TIOCFLUSH.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCFLUSH,0x540b,0x540b,0x80047410,0x80047410,0x80047410,0x80047410,0x80047410,0 diff --git a/libc/sysv/consts/TIOCGDRAINWAIT.S b/libc/sysv/consts/TIOCGDRAINWAIT.S deleted file mode 100644 index a127b1d95..000000000 --- a/libc/sysv/consts/TIOCGDRAINWAIT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCGDRAINWAIT,0,0,0x40047456,0x40047456,0x40047456,0,0,0 diff --git a/libc/sysv/consts/TIOCGETA.S b/libc/sysv/consts/TIOCGETA.S deleted file mode 100644 index de04788af..000000000 --- a/libc/sysv/consts/TIOCGETA.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon compat,TIOCGETA,0x5401,0x5401,0x40487413,0x40487413,0x402c7413,0x402c7413,0x402c7413,0 diff --git a/libc/sysv/consts/TIOCGFLAGS.S b/libc/sysv/consts/TIOCGFLAGS.S deleted file mode 100644 index 9a89c0288..000000000 --- a/libc/sysv/consts/TIOCGFLAGS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCGFLAGS,0,0,0,0,0,0x4004745d,0x4004745d,0 diff --git a/libc/sysv/consts/TIOCGPGRP.S b/libc/sysv/consts/TIOCGPGRP.S deleted file mode 100644 index ce92e68e9..000000000 --- a/libc/sysv/consts/TIOCGPGRP.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCGPGRP,0x540f,0x540f,0x40047477,0x40047477,0x40047477,0x40047477,0x40047477,0 diff --git a/libc/sysv/consts/TIOCGSID.S b/libc/sysv/consts/TIOCGSID.S deleted file mode 100644 index 678d38e0f..000000000 --- a/libc/sysv/consts/TIOCGSID.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCGSID,0x5429,0x5429,0x40047463,0x40047463,0x40047463,0x40047463,0x40047463,0 diff --git a/libc/sysv/consts/TIOCGTSTAMP.S b/libc/sysv/consts/TIOCGTSTAMP.S deleted file mode 100644 index 6e5bc25f3..000000000 --- a/libc/sysv/consts/TIOCGTSTAMP.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCGTSTAMP,0,0,0,0,0,0x4010745b,0x4010745b,0 diff --git a/libc/sysv/consts/TIOCPTMASTER.S b/libc/sysv/consts/TIOCPTMASTER.S deleted file mode 100644 index 6beff1c04..000000000 --- a/libc/sysv/consts/TIOCPTMASTER.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCPTMASTER,0,0,0,0,0x2000741c,0,0,0 diff --git a/libc/sysv/consts/TIOCPTSNAME.S b/libc/sysv/consts/TIOCPTSNAME.S deleted file mode 100644 index 2b8f44165..000000000 --- a/libc/sysv/consts/TIOCPTSNAME.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCPTSNAME,0,0,0,0,0,0,0x48087448,0 diff --git a/libc/sysv/consts/TIOCPTYGNAME.S b/libc/sysv/consts/TIOCPTYGNAME.S deleted file mode 100644 index d4b767be9..000000000 --- a/libc/sysv/consts/TIOCPTYGNAME.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCPTYGNAME,0,0,0x40807453,0x40807453,0,0,0,0 diff --git a/libc/sysv/consts/TIOCPTYGRANT.S b/libc/sysv/consts/TIOCPTYGRANT.S deleted file mode 100644 index 1e0332e46..000000000 --- a/libc/sysv/consts/TIOCPTYGRANT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCPTYGRANT,0,0,0x20007454,0x20007454,0,0,0,0 diff --git a/libc/sysv/consts/TIOCPTYUNLK.S b/libc/sysv/consts/TIOCPTYUNLK.S deleted file mode 100644 index 3e5c0dc64..000000000 --- a/libc/sysv/consts/TIOCPTYUNLK.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCPTYUNLK,0,0,0x20007452,0x20007452,0,0,0,0 diff --git a/libc/sysv/consts/TIOCREMOTE.S b/libc/sysv/consts/TIOCREMOTE.S deleted file mode 100644 index aafe9bcd7..000000000 --- a/libc/sysv/consts/TIOCREMOTE.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCREMOTE,0,0,0x80047469,0x80047469,0,0x80047469,0x80047469,0 diff --git a/libc/sysv/consts/TIOCSBRK.S b/libc/sysv/consts/TIOCSBRK.S deleted file mode 100644 index 5ac2a5aaf..000000000 --- a/libc/sysv/consts/TIOCSBRK.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSBRK,0x5427,0x5427,0x2000747b,0x2000747b,0x2000747b,0x2000747b,0x2000747b,0 diff --git a/libc/sysv/consts/TIOCSDRAINWAIT.S b/libc/sysv/consts/TIOCSDRAINWAIT.S deleted file mode 100644 index 166f4cfaf..000000000 --- a/libc/sysv/consts/TIOCSDRAINWAIT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSDRAINWAIT,0,0,0x80047457,0x80047457,0x80047457,0,0,0 diff --git a/libc/sysv/consts/TIOCSDTR.S b/libc/sysv/consts/TIOCSDTR.S deleted file mode 100644 index 3d932e536..000000000 --- a/libc/sysv/consts/TIOCSDTR.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSDTR,0,0,0x20007479,0x20007479,0x20007479,0x20007479,0x20007479,0 diff --git a/libc/sysv/consts/TIOCSERGETLSR.S b/libc/sysv/consts/TIOCSERGETLSR.S deleted file mode 100644 index 6c5d6776b..000000000 --- a/libc/sysv/consts/TIOCSERGETLSR.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSERGETLSR,0x5459,0x5459,0,0,0,0,0,0 diff --git a/libc/sysv/consts/TIOCSERGETMULTI.S b/libc/sysv/consts/TIOCSERGETMULTI.S deleted file mode 100644 index ade8985be..000000000 --- a/libc/sysv/consts/TIOCSERGETMULTI.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSERGETMULTI,0x545a,0x545a,0,0,0,0,0,0 diff --git a/libc/sysv/consts/TIOCSERSETMULTI.S b/libc/sysv/consts/TIOCSERSETMULTI.S deleted file mode 100644 index efe48fd75..000000000 --- a/libc/sysv/consts/TIOCSERSETMULTI.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSERSETMULTI,0x545b,0x545b,0,0,0,0,0,0 diff --git a/libc/sysv/consts/TIOCSER_TEMT.S b/libc/sysv/consts/TIOCSER_TEMT.S deleted file mode 100644 index c9e5db5ae..000000000 --- a/libc/sysv/consts/TIOCSER_TEMT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSER_TEMT,1,1,0,0,0,0,0,0 diff --git a/libc/sysv/consts/TIOCSETA.S b/libc/sysv/consts/TIOCSETA.S deleted file mode 100644 index 6ed3b3f83..000000000 --- a/libc/sysv/consts/TIOCSETA.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon compat,TIOCSETA,0x5402,0x5402,0x80487414,0x80487414,0x802c7414,0x802c7414,0x802c7414,0x5402 diff --git a/libc/sysv/consts/TIOCSETAF.S b/libc/sysv/consts/TIOCSETAF.S deleted file mode 100644 index 7158b670f..000000000 --- a/libc/sysv/consts/TIOCSETAF.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon compat,TIOCSETAF,0x5404,0x5404,0x80487416,0x80487416,0x802c7416,0x802c7416,0x802c7416,0x5402 diff --git a/libc/sysv/consts/TIOCSETAW.S b/libc/sysv/consts/TIOCSETAW.S deleted file mode 100644 index 623c6e70d..000000000 --- a/libc/sysv/consts/TIOCSETAW.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon compat,TIOCSETAW,0x5403,0x5403,0x80487415,0x80487415,0x802c7415,0x802c7415,0x802c7415,0x5403 diff --git a/libc/sysv/consts/TIOCSETVERAUTH.S b/libc/sysv/consts/TIOCSETVERAUTH.S deleted file mode 100644 index fda0849ba..000000000 --- a/libc/sysv/consts/TIOCSETVERAUTH.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSETVERAUTH,0,0,0,0,0,0x8004741c,0x8004741c,0 diff --git a/libc/sysv/consts/TIOCSFLAGS.S b/libc/sysv/consts/TIOCSFLAGS.S deleted file mode 100644 index c4fe7be7e..000000000 --- a/libc/sysv/consts/TIOCSFLAGS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSFLAGS,0,0,0,0,0,0x8004745c,0x8004745c,0 diff --git a/libc/sysv/consts/TIOCSTART.S b/libc/sysv/consts/TIOCSTART.S deleted file mode 100644 index 251b180df..000000000 --- a/libc/sysv/consts/TIOCSTART.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSTART,0x540A,0x540A,0x2000746e,0x2000746e,0x2000746e,0x2000746e,0x2000746e,0 diff --git a/libc/sysv/consts/TIOCSTAT.S b/libc/sysv/consts/TIOCSTAT.S deleted file mode 100644 index dd1955d06..000000000 --- a/libc/sysv/consts/TIOCSTAT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSTAT,0,0,0x20007465,0x20007465,0x20007465,0x20007465,0x20007465,0 diff --git a/libc/sysv/consts/TIOCSTI.S b/libc/sysv/consts/TIOCSTI.S index 5a3f473af..cca5dfa8d 100644 --- a/libc/sysv/consts/TIOCSTI.S +++ b/libc/sysv/consts/TIOCSTI.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSTI,0x5412,0x5412,0x80017472,0x80017472,0x80017472,0,0,0 +.syscon termios,TIOCSTI,0x5412,0x5412,0x80017472,0x80017472,0x80017472,0,0x80017472,0 diff --git a/libc/sysv/consts/TIOCSTOP.S b/libc/sysv/consts/TIOCSTOP.S deleted file mode 100644 index dcc4b8726..000000000 --- a/libc/sysv/consts/TIOCSTOP.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSTOP,0x540A,0x540A,0x2000746f,0x2000746f,0x2000746f,0x2000746f,0x2000746f,0 diff --git a/libc/sysv/consts/TIOCSTSTAMP.S b/libc/sysv/consts/TIOCSTSTAMP.S deleted file mode 100644 index 743e5138d..000000000 --- a/libc/sysv/consts/TIOCSTSTAMP.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCSTSTAMP,0,0,0,0,0,0x8008745a,0x8008745a,0 diff --git a/libc/sysv/consts/TIOCTIMESTAMP.S b/libc/sysv/consts/TIOCTIMESTAMP.S deleted file mode 100644 index e44aeb978..000000000 --- a/libc/sysv/consts/TIOCTIMESTAMP.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCTIMESTAMP,0,0,0x40107459,0x40107459,0x40107459,0,0,0 diff --git a/libc/sysv/consts/TIOCUCNTL_CBRK.S b/libc/sysv/consts/TIOCUCNTL_CBRK.S deleted file mode 100644 index 44d3c0aaf..000000000 --- a/libc/sysv/consts/TIOCUCNTL_CBRK.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TIOCUCNTL_CBRK,0,0,0,0,0,0x7a,0x7a,0 diff --git a/libc/sysv/consts/TTYDISC.S b/libc/sysv/consts/TTYDISC.S deleted file mode 100644 index 929ba26ae..000000000 --- a/libc/sysv/consts/TTYDISC.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,TTYDISC,0,0,0,0,0,0,0,0 diff --git a/libc/sysv/consts/VERIFY.S b/libc/sysv/consts/VERIFY.S deleted file mode 100644 index aaee2dcac..000000000 --- a/libc/sysv/consts/VERIFY.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,VERIFY,47,47,0,0,0,0,0,0 diff --git a/libc/sysv/consts/VT0.S b/libc/sysv/consts/VT0.S deleted file mode 100644 index 4a25d65b4..000000000 --- a/libc/sysv/consts/VT0.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon termios,VT0,0b0000000000000000,0b0000000000000000,0b000000000000000000,0b000000000000000000,0b000000000000000000,0,0,0b0000000000000000 diff --git a/libc/sysv/consts/_POSIX_VDISABLE.S b/libc/sysv/consts/_POSIX_VDISABLE.S new file mode 100644 index 000000000..0430210e4 --- /dev/null +++ b/libc/sysv/consts/_POSIX_VDISABLE.S @@ -0,0 +1,2 @@ +#include "libc/sysv/consts/syscon.internal.h" +.syscon termios,_POSIX_VDISABLE,0,0,255,255,255,255,255,0 diff --git a/libc/sysv/consts/o.h b/libc/sysv/consts/o.h index 791e98871..d9994c12e 100644 --- a/libc/sysv/consts/o.h +++ b/libc/sysv/consts/o.h @@ -1,9 +1,14 @@ #ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_ #define COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_ + +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_RDWR 2 +#define O_ACCMODE 3 + #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -extern const unsigned O_ACCMODE; extern const unsigned O_APPEND; extern const unsigned O_ASYNC; extern const unsigned O_CLOEXEC; @@ -25,8 +30,6 @@ extern const unsigned O_NOFOLLOW_ANY; extern const unsigned O_NONBLOCK; extern const unsigned O_PATH; extern const unsigned O_RANDOM; -extern const unsigned O_RDONLY; -extern const unsigned O_RDWR; extern const unsigned O_RSYNC; extern const unsigned O_SEARCH; extern const unsigned O_SEQUENTIAL; @@ -37,15 +40,6 @@ extern const unsigned O_TMPFILE; extern const unsigned O_TRUNC; extern const unsigned O_TTY_INIT; extern const unsigned O_VERIFY; -extern const unsigned O_WRONLY; - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ - -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#define O_ACCMODE 3 #define O_APPEND O_APPEND #define O_ASYNC O_ASYNC @@ -89,4 +83,6 @@ COSMOPOLITAN_C_END_ #define __tmpcosmo_O_SYNC -282123817 #define __tmpcosmo_O_TRUNC 924355570 +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_ */ diff --git a/libc/sysv/consts/pty.h b/libc/sysv/consts/pty.h index 336fa3411..7084ea00c 100644 --- a/libc/sysv/consts/pty.h +++ b/libc/sysv/consts/pty.h @@ -13,7 +13,6 @@ extern const int TIOCPKT_NOSTOP; extern const int TIOCPKT_START; extern const int TIOCPKT_STOP; extern const int TIOCSPTLCK; -extern const int PTMGET; #define TIOCPKT_DATA 0x00 #define TIOCPKT_DOSTOP 0x01 @@ -26,11 +25,9 @@ extern const int PTMGET; #define TIOCPKT TIOCPKT #define TIOCSPTLCK TIOCSPTLCK -#define PTMGET PTMGET #define __tmpcosmo_TIOCPKT -1036987649 #define __tmpcosmo_TIOCSPTLCK 372918192 -#define __tmpcosmo_PTMGET -2064878958 COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/sysv/consts/termios.h b/libc/sysv/consts/termios.h index a768a4be8..cb441b73c 100644 --- a/libc/sysv/consts/termios.h +++ b/libc/sysv/consts/termios.h @@ -3,18 +3,16 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +#define EXTA B19200 +#define EXTB B38400 + +extern const int _POSIX_VDISABLE; extern const uint32_t BRKINT; -extern const uint32_t BS0; extern const uint32_t BS1; extern const uint32_t BS2; extern const uint32_t BSDLY; -extern const long BUSY; -extern const uint32_t CBAUD; -extern const uint32_t CBAUDEX; -extern const uint32_t CIBAUD; extern const uint32_t CLOCAL; extern const uint32_t CMSPAR; -extern const uint32_t CR0; extern const uint32_t CR1; extern const uint32_t CR2; extern const uint32_t CR3; @@ -26,23 +24,17 @@ extern const uint32_t CS7; extern const uint32_t CS8; extern const uint32_t CSIZE; extern const uint32_t CSTOPB; -extern const uint32_t ECHO; extern const uint32_t ECHOCTL; extern const uint32_t ECHOE; extern const uint32_t ECHOK; extern const uint32_t ECHOKE; extern const uint32_t ECHONL; extern const uint32_t ECHOPRT; -extern const long ENDRUNDISC; -extern const long EXTA; -extern const long EXTB; extern const long EXTPROC; -extern const uint32_t FF0; extern const uint32_t FF1; extern const uint32_t FF2; extern const uint32_t FFDLY; extern const uint32_t FLUSHO; -extern const long H4DISC; extern const uint32_t HUPCL; extern const uint32_t ICANON; extern const uint32_t ICRNL; @@ -60,13 +52,10 @@ extern const uint32_t IUTF8; extern const uint32_t IXANY; extern const uint32_t IXOFF; extern const uint32_t IXON; -extern const long NETGRAPHDISC; -extern const uint32_t NL0; extern const uint32_t NL1; extern const uint32_t NL2; extern const uint32_t NL3; extern const uint32_t NLDLY; -extern const long NMEADISC; extern const uint32_t NOFLSH; extern const uint32_t OCRNL; extern const uint32_t OFDEL; @@ -80,84 +69,35 @@ extern const uint32_t PARENB; extern const uint32_t PARMRK; extern const uint32_t PARODD; extern const uint32_t PENDIN; -extern const long PPPDISC; -extern const long SLIPDISC; -extern const long STRIPDISC; -extern const uint32_t TAB0; extern const uint32_t TAB1; extern const uint32_t TAB2; extern const uint32_t TAB3; extern const uint32_t TABDLY; -extern const long TABLDISC; -extern const uint64_t TCFLSH; -extern const uint64_t TCGETS; extern const int TCIFLUSH; -extern const int TCIOFF; extern const int TCIOFLUSH; -extern const int TCION; extern const int TCOFLUSH; -extern const int TCOOFF; -extern const int TCOON; extern const int TCSADRAIN; extern const int TCSAFLUSH; extern const int TCSANOW; -extern const uint64_t TCSBRK; -extern const uint64_t TCSETS; -extern const uint64_t TCSETSF; -extern const uint64_t TCSETSW; -extern const uint64_t TCXONC; -extern const uint64_t TIOCCBRK; -extern const uint64_t TIOCCDTR; -extern const uint64_t TIOCCHKVERAUTH; extern const uint64_t TIOCCONS; -extern const uint64_t TIOCEXT; -extern const uint64_t TIOCFLAG_CLOCAL; -extern const uint64_t TIOCFLAG_MDMBUF; -extern const uint64_t TIOCFLAG_PPS; -extern const uint64_t TIOCFLAG_SOFTCAR; -extern const uint64_t TIOCFLUSH; -extern const uint64_t TIOCGDRAINWAIT; extern const uint64_t TIOCGETD; -extern const uint64_t TIOCGFLAGS; -extern const uint64_t TIOCGPGRP; extern const uint64_t TIOCGPTN; -extern const uint64_t TIOCGSID; -extern const uint64_t TIOCGTSTAMP; extern const uint64_t TIOCGWINSZ; extern const uint64_t TIOCNOTTY; extern const uint64_t TIOCNXCL; extern const uint64_t TIOCOUTQ; -extern const uint64_t TIOCPTMASTER; -extern const uint64_t TIOCREMOTE; -extern const uint64_t TIOCSBRK; extern const uint64_t TIOCSCTTY; -extern const uint64_t TIOCSDRAINWAIT; -extern const uint64_t TIOCSDTR; -extern const uint64_t TIOCSERGETLSR; -extern const uint64_t TIOCSERGETMULTI; -extern const uint64_t TIOCSERSETMULTI; -extern const uint64_t TIOCSER_TEMT; extern const uint64_t TIOCSETD; -extern const uint64_t TIOCSETVERAUTH; -extern const uint64_t TIOCSFLAGS; extern const uint64_t TIOCSIG; extern const uint64_t TIOCSPGRP; -extern const uint64_t TIOCSTART; -extern const uint64_t TIOCSTAT; extern const uint64_t TIOCSTI; -extern const uint64_t TIOCSTOP; -extern const uint64_t TIOCSTSTAMP; extern const uint64_t TIOCSWINSZ; -extern const uint64_t TIOCTIMESTAMP; -extern const uint64_t TIOCUCNTL_CBRK; extern const long TOSTOP; -extern const long TTYDISC; extern const uint8_t VDISCARD; extern const uint8_t VEOF; extern const uint8_t VEOL2; extern const uint8_t VEOL; extern const uint8_t VERASE; -extern const long VERIFY; extern const uint8_t VINTR; extern const uint8_t VKILL; extern const uint8_t VLNEXT; @@ -168,7 +108,6 @@ extern const uint8_t VSTART; extern const uint8_t VSTOP; extern const uint8_t VSUSP; extern const uint8_t VSWTC; -extern const uint32_t VT0; extern const uint32_t VT1; extern const uint32_t VT2; extern const uint32_t VTDLY; @@ -176,339 +115,230 @@ extern const uint8_t VTIME; extern const uint8_t VWERASE; extern const uint32_t XCASE; extern const uint32_t XTABS; +extern const uint32_t CRTSCTS; + +#define TCOOFF 0 +#define TCOON 1 +#define TCIOFF 2 +#define TCION 3 + +#define BRKINT 0x02 +#define ICRNL 0x0100 +#define IGNBRK 0x01 +#define IGNCR 0x80 +#define IGNPAR 0x04 +#define IMAXBEL 0x2000 +#define INLCR 0x40 +#define INPCK 0x10 +#define ISTRIP 0x20 +#define IXANY 0x0800 +#define OPOST 0x01 +#define PARMRK 0x08 + +#define _POSIX_VDISABLE _POSIX_VDISABLE + +#define NLDLY NLDLY +#define NL0 0 +#define NL1 NL1 +#define NL2 NL2 +#define NL3 NL3 +#define CRDLY CRDLY +#define CR0 0 +#define CR1 CR1 +#define CR2 CR2 +#define CR3 CR3 +#define TABDLY TABDLY +#define TAB0 0 +#define TAB1 TAB1 +#define TAB2 TAB2 +#define TAB3 TAB3 +#define XTABS XTABS +#define CRTSCTS CRTSCTS +#define BSDLY BSDLY +#define BS0 0 +#define BS1 BS1 +#define BS2 BS2 +#define VTDLY VTDLY +#define VT0 0 +#define VT1 VT1 +#define VT2 VT2 +#define FFDLY FFDLY +#define FF0 0 +#define FF1 FF1 +#define FF2 FF2 + +#define CLOCAL CLOCAL +#define CREAD CREAD +#define CS5 CS5 +#define CS6 CS6 +#define CS7 CS7 +#define CS8 CS8 +#define CSIZE CSIZE +#define CSTOPB CSTOPB +#define ECHO 8 +#define ECHOCTL ECHOCTL +#define ECHOE ECHOE +#define ECHOK ECHOK +#define ECHOKE ECHOKE +#define ECHONL ECHONL +#define ECHOPRT ECHOPRT +#define EXTPROC EXTPROC +#define FLUSHO FLUSHO +#define HUPCL HUPCL +#define ICANON ICANON +#define IEXTEN IEXTEN +#define ISIG ISIG +#define IUCLC IUCLC +#define IUTF8 IUTF8 +#define IXOFF IXOFF +#define IXON IXON +#define NOFLSH NOFLSH +#define OCRNL OCRNL +#define OFDEL OFDEL +#define OFILL OFILL +#define OLCUC OLCUC +#define ONLCR ONLCR +#define ONLRET ONLRET +#define ONOCR ONOCR +#define PARENB PARENB +#define PARODD PARODD +#define PENDIN PENDIN +#define TCIFLUSH TCIFLUSH +#define TCIOFLUSH TCIOFLUSH +#define TCOFLUSH TCOFLUSH +#define TCSADRAIN 1 +#define TCSAFLUSH 2 +#define TCSANOW 0 +#define TIOCCONS TIOCCONS +#define TIOCGETD TIOCGETD +#define TIOCGPTN TIOCGPTN +#define TIOCGWINSZ TIOCGWINSZ +#define TIOCNOTTY TIOCNOTTY +#define TIOCNXCL TIOCNXCL +#define TIOCOUTQ TIOCOUTQ +#define TIOCSCTTY TIOCSCTTY +#define TIOCSETD TIOCSETD +#define TIOCSIG TIOCSIG +#define TIOCSPGRP TIOCSPGRP +#define TIOCSTI TIOCSTI +#define TIOCSWINSZ TIOCSWINSZ +#define TOSTOP TOSTOP +#define VDISCARD VDISCARD +#define VEOF VEOF +#define VEOL VEOL +#define VEOL2 VEOL2 +#define VERASE VERASE +#define VINTR VINTR +#define VKILL VKILL +#define VLNEXT VLNEXT +#define VMIN VMIN +#define VQUIT VQUIT +#define VREPRINT VREPRINT +#define VSTART VSTART +#define VSTOP VSTOP +#define VSUSP VSUSP +#define VSWTC VSWTC +#define VTIME VTIME +#define VWERASE VWERASE +#define XCASE XCASE + +#define __tmpcosmo__POSIX_VDISABLE 169854768 + +#define __tmpcosmo_NLDLY 1319994273 +#define __tmpcosmo_NL1 -70287396 +#define __tmpcosmo_NL2 652191906 +#define __tmpcosmo_NL3 1513394829 +#define __tmpcosmo_CRDLY 2044628767 +#define __tmpcosmo_CR1 1115673592 +#define __tmpcosmo_CR2 1871515224 +#define __tmpcosmo_CR3 -1010651809 +#define __tmpcosmo_TABDLY -886090656 +#define __tmpcosmo_TAB1 778986470 +#define __tmpcosmo_TAB2 -382588940 +#define __tmpcosmo_TAB3 -238740052 +#define __tmpcosmo_XTABS 3851498 +#define __tmpcosmo_CRTSCTS -1928718178 +#define __tmpcosmo_BSDLY 1798324922 +#define __tmpcosmo_BS1 -2123797836 +#define __tmpcosmo_BS2 -354341079 +#define __tmpcosmo_VTDLY -1916199946 +#define __tmpcosmo_VT1 159615710 +#define __tmpcosmo_VT2 -2135726260 +#define __tmpcosmo_FFDLY 1018442558 +#define __tmpcosmo_FF1 366192762 +#define __tmpcosmo_FF2 1064173224 + +#define __tmpcosmo_CLOCAL 819516838 +#define __tmpcosmo_CREAD -1620802775 +#define __tmpcosmo_CS5 -909937503 +#define __tmpcosmo_CS6 1486108550 +#define __tmpcosmo_CS7 2070161332 +#define __tmpcosmo_CS8 -894417336 +#define __tmpcosmo_CSIZE -2142503038 +#define __tmpcosmo_CSTOPB -1893740371 +#define __tmpcosmo_ECHOCTL 1839844219 +#define __tmpcosmo_ECHOE -462490559 +#define __tmpcosmo_ECHOK 2582183 +#define __tmpcosmo_ECHOKE 1807548346 +#define __tmpcosmo_ECHONL -1627629800 +#define __tmpcosmo_ECHOPRT 789779244 +#define __tmpcosmo_EXTPROC 1954282515 +#define __tmpcosmo_FLUSHO -1439777831 +#define __tmpcosmo_HUPCL -1762956935 +#define __tmpcosmo_ICANON 1391597225 +#define __tmpcosmo_IEXTEN -2017256995 +#define __tmpcosmo_ISIG 1460108174 +#define __tmpcosmo_IUCLC 1013808696 +#define __tmpcosmo_IUTF8 1988433768 +#define __tmpcosmo_IXOFF -206825490 +#define __tmpcosmo_IXON -1157774462 +#define __tmpcosmo_NOFLSH -1818319598 +#define __tmpcosmo_OCRNL -1553778506 +#define __tmpcosmo_OFDEL 424931285 +#define __tmpcosmo_OFILL -414167674 +#define __tmpcosmo_OLCUC 2114383293 +#define __tmpcosmo_ONLCR -1154324374 +#define __tmpcosmo_ONLRET -639724866 +#define __tmpcosmo_ONOCR -490882729 +#define __tmpcosmo_PARENB -1774689151 +#define __tmpcosmo_PARODD -404286749 +#define __tmpcosmo_PENDIN -619915085 +#define __tmpcosmo_TCIFLUSH 1056759293 +#define __tmpcosmo_TCIOFLUSH -342999896 +#define __tmpcosmo_TCOFLUSH 659539281 +#define __tmpcosmo_TIOCCONS 1455144588 +#define __tmpcosmo_TIOCGETD 470897144 +#define __tmpcosmo_TIOCGPTN 67701595 +#define __tmpcosmo_TIOCGWINSZ 965491756 +#define __tmpcosmo_TIOCNOTTY 1073131930 +#define __tmpcosmo_TIOCNXCL 1210582499 +#define __tmpcosmo_TIOCOUTQ 1063967309 +#define __tmpcosmo_TIOCSCTTY -1994241678 +#define __tmpcosmo_TIOCSETD -860412918 +#define __tmpcosmo_TIOCSIG 975589334 +#define __tmpcosmo_TIOCSPGRP -1362234385 +#define __tmpcosmo_TIOCSTI 1704247727 +#define __tmpcosmo_TIOCSWINSZ -273178782 +#define __tmpcosmo_TOSTOP 1907739786 +#define __tmpcosmo_VDISCARD 1773966586 +#define __tmpcosmo_VEOF 1992016613 +#define __tmpcosmo_VEOL 1926565027 +#define __tmpcosmo_VEOL2 -1297272191 +#define __tmpcosmo_VERASE 864859287 +#define __tmpcosmo_VINTR -973181253 +#define __tmpcosmo_VKILL 1764217477 +#define __tmpcosmo_VLNEXT -1045308606 +#define __tmpcosmo_VMIN 1479455781 +#define __tmpcosmo_VQUIT 853995221 +#define __tmpcosmo_VREPRINT 868062415 +#define __tmpcosmo_VSTART -245321985 +#define __tmpcosmo_VSTOP -1379951528 +#define __tmpcosmo_VSUSP -1054959499 +#define __tmpcosmo_VSWTC 1631975394 +#define __tmpcosmo_VTIME -942478376 +#define __tmpcosmo_VWERASE -908507167 +#define __tmpcosmo_XCASE -34176757 COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ - -#define BRKINT 0x02 -#define ICRNL 0x0100 -#define IGNBRK 0x01 -#define IGNCR 0x80 -#define IGNPAR 0x04 -#define IMAXBEL 0x2000 -#define INLCR 0x40 -#define INPCK 0x10 -#define ISTRIP 0x20 -#define IXANY 0x0800 -#define OPOST 0x01 -#define PARMRK 0x08 -#define TIOCSTOP TIOCSTOP - -#define NLDLY NLDLY -#define NL0 0 -#define NL1 NL1 -#define NL2 NL2 -#define NL3 NL3 -#define CRDLY CRDLY -#define CR0 0 -#define CR1 CR1 -#define CR2 CR2 -#define CR3 CR3 -#define TABDLY TABDLY -#define TAB0 0 -#define TAB1 TAB1 -#define TAB2 TAB2 -#define TAB3 TAB3 -#define XTABS XTABS -#define BSDLY BSDLY -#define BS0 0 -#define BS1 BS1 -#define BS2 BS2 -#define VTDLY VTDLY -#define VT0 0 -#define VT1 VT1 -#define VT2 VT2 -#define FFDLY FFDLY -#define FF0 0 -#define FF1 FF1 -#define FF2 FF2 - -#define BUSY BUSY -#define CBAUD CBAUD -#define CBAUDEX CBAUDEX -#define CIBAUD CIBAUD -#define CLOCAL CLOCAL -#define CMSPAR CMSPAR -#define CREAD CREAD -#define CS5 CS5 -#define CS6 CS6 -#define CS7 CS7 -#define CS8 CS8 -#define CSIZE CSIZE -#define CSTOPB CSTOPB -#define ECHO 8 -#define ECHOCTL ECHOCTL -#define ECHOE ECHOE -#define ECHOK ECHOK -#define ECHOKE ECHOKE -#define ECHONL ECHONL -#define ECHOPRT ECHOPRT -#define ENDRUNDISC ENDRUNDISC -#define EXTA EXTA -#define EXTB EXTB -#define EXTPROC EXTPROC -#define FLUSHO FLUSHO -#define H4DISC H4DISC -#define HUPCL HUPCL -#define ICANON ICANON -#define IEXTEN IEXTEN -#define ISIG ISIG -#define IUCLC IUCLC -#define IUTF8 IUTF8 -#define IXOFF IXOFF -#define IXON IXON -#define NCCS 20 -#define NETGRAPHDISC NETGRAPHDISC -#define NMEADISC NMEADISC -#define NOFLSH NOFLSH -#define OCRNL OCRNL -#define OFDEL OFDEL -#define OFILL OFILL -#define OLCUC OLCUC -#define ONLCR ONLCR -#define ONLRET ONLRET -#define ONOCR ONOCR -#define PARENB PARENB -#define PARODD PARODD -#define PENDIN PENDIN -#define PPPDISC PPPDISC -#define SLIPDISC SLIPDISC -#define STRIPDISC STRIPDISC -#define TABLDISC TABLDISC -#define TCFLSH TCFLSH -#define TCGETS TCGETS -#define TCIFLUSH TCIFLUSH -#define TCIOFF TCIOFF -#define TCIOFLUSH TCIOFLUSH -#define TCION TCION -#define TCOFLUSH TCOFLUSH -#define TCOOFF TCOOFF -#define TCOON TCOON -#define TCSADRAIN 1 -#define TCSAFLUSH 2 -#define TCSANOW 0 -#define TCSBRK TCSBRK -#define TCSETS TCSETS -#define TCSETSF TCSETSF -#define TCSETSW TCSETSW -#define TCXONC TCXONC -#define TIOCCBRK TIOCCBRK -#define TIOCCDTR TIOCCDTR -#define TIOCCHKVERAUTH TIOCCHKVERAUTH -#define TIOCCONS TIOCCONS -#define TIOCEXT TIOCEXT -#define TIOCFLAG_CLOCAL TIOCFLAG_CLOCAL -#define TIOCFLAG_MDMBUF TIOCFLAG_MDMBUF -#define TIOCFLAG_PPS TIOCFLAG_PPS -#define TIOCFLAG_SOFTCAR TIOCFLAG_SOFTCAR -#define TIOCFLUSH TIOCFLUSH -#define TIOCGDRAINWAIT TIOCGDRAINWAIT -#define TIOCGETD TIOCGETD -#define TIOCGFLAGS TIOCGFLAGS -#define TIOCGPGRP TIOCGPGRP -#define TIOCGPTN TIOCGPTN -#define TIOCGSID TIOCGSID -#define TIOCGTSTAMP TIOCGTSTAMP -#define TIOCGWINSZ TIOCGWINSZ -#define TIOCNOTTY TIOCNOTTY -#define TIOCNXCL TIOCNXCL -#define TIOCOUTQ TIOCOUTQ -#define TIOCPTMASTER TIOCPTMASTER -#define TIOCREMOTE TIOCREMOTE -#define TIOCSBRK TIOCSBRK -#define TIOCSCTTY TIOCSCTTY -#define TIOCSDRAINWAIT TIOCSDRAINWAIT -#define TIOCSDTR TIOCSDTR -#define TIOCSERGETLSR TIOCSERGETLSR -#define TIOCSERGETMULTI TIOCSERGETMULTI -#define TIOCSERSETMULTI TIOCSERSETMULTI -#define TIOCSER_TEMT TIOCSER_TEMT -#define TIOCSETD TIOCSETD -#define TIOCSETVERAUTH TIOCSETVERAUTH -#define TIOCSFLAGS TIOCSFLAGS -#define TIOCSIG TIOCSIG -#define TIOCSPGRP TIOCSPGRP -#define TIOCSTART TIOCSTART -#define TIOCSTAT TIOCSTAT -#define TIOCSTI TIOCSTI -#define TIOCSTSTAMP TIOCSTSTAMP -#define TIOCSWINSZ TIOCSWINSZ -#define TIOCTIMESTAMP TIOCTIMESTAMP -#define TIOCUCNTL_CBRK TIOCUCNTL_CBRK -#define TOSTOP TOSTOP -#define TTYDISC TTYDISC -#define VDISCARD VDISCARD -#define VEOF VEOF -#define VEOL VEOL -#define VEOL2 VEOL2 -#define VERASE VERASE -#define VERIFY VERIFY -#define VINTR VINTR -#define VKILL VKILL -#define VLNEXT VLNEXT -#define VMIN VMIN -#define VQUIT VQUIT -#define VREPRINT VREPRINT -#define VSTART VSTART -#define VSTOP VSTOP -#define VSUSP VSUSP -#define VSWTC VSWTC -#define VTIME VTIME -#define VWERASE VWERASE -#define XCASE XCASE - -#define __tmpcosmo_TIOCSTOP -1017191481 - -#define __tmpcosmo_NLDLY 1319994273 -#define __tmpcosmo_NL1 -70287396 -#define __tmpcosmo_NL2 652191906 -#define __tmpcosmo_NL3 1513394829 -#define __tmpcosmo_CRDLY 2044628767 -#define __tmpcosmo_CR1 1115673592 -#define __tmpcosmo_CR2 1871515224 -#define __tmpcosmo_CR3 -1010651809 -#define __tmpcosmo_TABDLY -886090656 -#define __tmpcosmo_TAB1 778986470 -#define __tmpcosmo_TAB2 -382588940 -#define __tmpcosmo_TAB3 -238740052 -#define __tmpcosmo_XTABS 3851498 -#define __tmpcosmo_BSDLY 1798324922 -#define __tmpcosmo_BS1 -2123797836 -#define __tmpcosmo_BS2 -354341079 -#define __tmpcosmo_VTDLY -1916199946 -#define __tmpcosmo_VT1 159615710 -#define __tmpcosmo_VT2 -2135726260 -#define __tmpcosmo_FFDLY 1018442558 -#define __tmpcosmo_FF1 366192762 -#define __tmpcosmo_FF2 1064173224 - -#define __tmpcosmo_BUSY 1091122196 -#define __tmpcosmo_CBAUD 621840898 -#define __tmpcosmo_CBAUDEX 1684865431 -#define __tmpcosmo_CIBAUD 232332978 -#define __tmpcosmo_CLOCAL 819516838 -#define __tmpcosmo_CMSPAR -1110572378 -#define __tmpcosmo_CREAD -1620802775 -#define __tmpcosmo_CS5 -909937503 -#define __tmpcosmo_CS6 1486108550 -#define __tmpcosmo_CS7 2070161332 -#define __tmpcosmo_CS8 -894417336 -#define __tmpcosmo_CSIZE -2142503038 -#define __tmpcosmo_CSTOPB -1893740371 -#define __tmpcosmo_ECHOCTL 1839844219 -#define __tmpcosmo_ECHOE -462490559 -#define __tmpcosmo_ECHOK 2582183 -#define __tmpcosmo_ECHOKE 1807548346 -#define __tmpcosmo_ECHONL -1627629800 -#define __tmpcosmo_ECHOPRT 789779244 -#define __tmpcosmo_ENDRUNDISC 890493373 -#define __tmpcosmo_EXTA -1952310979 -#define __tmpcosmo_EXTB -1924899818 -#define __tmpcosmo_EXTPROC 1954282515 -#define __tmpcosmo_FLUSHO -1439777831 -#define __tmpcosmo_H4DISC -383446731 -#define __tmpcosmo_HUPCL -1762956935 -#define __tmpcosmo_ICANON 1391597225 -#define __tmpcosmo_IEXTEN -2017256995 -#define __tmpcosmo_ISIG 1460108174 -#define __tmpcosmo_IUCLC 1013808696 -#define __tmpcosmo_IUTF8 1988433768 -#define __tmpcosmo_IXOFF -206825490 -#define __tmpcosmo_IXON -1157774462 -#define __tmpcosmo_NETGRAPHDISC -99256515 -#define __tmpcosmo_NMEADISC -74984305 -#define __tmpcosmo_NOFLSH -1818319598 -#define __tmpcosmo_OCRNL -1553778506 -#define __tmpcosmo_OFDEL 424931285 -#define __tmpcosmo_OFILL -414167674 -#define __tmpcosmo_OLCUC 2114383293 -#define __tmpcosmo_ONLCR -1154324374 -#define __tmpcosmo_ONLRET -639724866 -#define __tmpcosmo_ONOCR -490882729 -#define __tmpcosmo_PARENB -1774689151 -#define __tmpcosmo_PARODD -404286749 -#define __tmpcosmo_PENDIN -619915085 -#define __tmpcosmo_PPPDISC -1392399884 -#define __tmpcosmo_SLIPDISC -183947027 -#define __tmpcosmo_STRIPDISC 2025122243 -#define __tmpcosmo_TABLDISC -1858378918 -#define __tmpcosmo_TCFLSH -243453721 -#define __tmpcosmo_TCGETS -916893397 -#define __tmpcosmo_TCIFLUSH 1056759293 -#define __tmpcosmo_TCIOFF -737116690 -#define __tmpcosmo_TCIOFLUSH -342999896 -#define __tmpcosmo_TCION 520326151 -#define __tmpcosmo_TCOFLUSH 659539281 -#define __tmpcosmo_TCOOFF 478400994 -#define __tmpcosmo_TCOON 1521058272 -#define __tmpcosmo_TCSBRK 1276777613 -#define __tmpcosmo_TCSETS 535983615 -#define __tmpcosmo_TCSETSF 659034961 -#define __tmpcosmo_TCSETSW 1654950622 -#define __tmpcosmo_TCXONC -647714748 -#define __tmpcosmo_TIOCCBRK 1839061556 -#define __tmpcosmo_TIOCCDTR -752068369 -#define __tmpcosmo_TIOCCHKVERAUTH -1183922440 -#define __tmpcosmo_TIOCCONS 1455144588 -#define __tmpcosmo_TIOCEXT 186515040 -#define __tmpcosmo_TIOCFLAG_CLOCAL 698005770 -#define __tmpcosmo_TIOCFLAG_MDMBUF 1422045049 -#define __tmpcosmo_TIOCFLAG_PPS -620931778 -#define __tmpcosmo_TIOCFLAG_SOFTCAR -140438205 -#define __tmpcosmo_TIOCFLUSH 516222339 -#define __tmpcosmo_TIOCGDRAINWAIT -842950172 -#define __tmpcosmo_TIOCGETD 470897144 -#define __tmpcosmo_TIOCGFLAGS 713359628 -#define __tmpcosmo_TIOCGPGRP 1020495911 -#define __tmpcosmo_TIOCGPTN 67701595 -#define __tmpcosmo_TIOCGSID -1924582947 -#define __tmpcosmo_TIOCGTSTAMP 1116108087 -#define __tmpcosmo_TIOCGWINSZ 965491756 -#define __tmpcosmo_TIOCNOTTY 1073131930 -#define __tmpcosmo_TIOCNXCL 1210582499 -#define __tmpcosmo_TIOCOUTQ 1063967309 -#define __tmpcosmo_TIOCPTMASTER -1722245149 -#define __tmpcosmo_TIOCREMOTE -478898903 -#define __tmpcosmo_TIOCSBRK -1827728950 -#define __tmpcosmo_TIOCSCTTY -1994241678 -#define __tmpcosmo_TIOCSDRAINWAIT 2088849044 -#define __tmpcosmo_TIOCSDTR -1218831027 -#define __tmpcosmo_TIOCSERGETLSR -196763909 -#define __tmpcosmo_TIOCSERGETMULTI -1904826952 -#define __tmpcosmo_TIOCSERSETMULTI -2096909859 -#define __tmpcosmo_TIOCSER_TEMT 762771473 -#define __tmpcosmo_TIOCSETD -860412918 -#define __tmpcosmo_TIOCSETVERAUTH -1550886356 -#define __tmpcosmo_TIOCSFLAGS 1899558086 -#define __tmpcosmo_TIOCSIG 975589334 -#define __tmpcosmo_TIOCSPGRP -1362234385 -#define __tmpcosmo_TIOCSTART -1106632595 -#define __tmpcosmo_TIOCSTAT -1240783913 -#define __tmpcosmo_TIOCSTI 1704247727 -#define __tmpcosmo_TIOCSTSTAMP 290377566 -#define __tmpcosmo_TIOCSWINSZ -273178782 -#define __tmpcosmo_TIOCTIMESTAMP -167408548 -#define __tmpcosmo_TIOCUCNTL_CBRK -1260429107 -#define __tmpcosmo_TOSTOP 1907739786 -#define __tmpcosmo_TTYDISC -1450700552 -#define __tmpcosmo_VDISCARD 1773966586 -#define __tmpcosmo_VEOF 1992016613 -#define __tmpcosmo_VEOL 1926565027 -#define __tmpcosmo_VEOL2 -1297272191 -#define __tmpcosmo_VERASE 864859287 -#define __tmpcosmo_VERIFY 1512705907 -#define __tmpcosmo_VINTR -973181253 -#define __tmpcosmo_VKILL 1764217477 -#define __tmpcosmo_VLNEXT -1045308606 -#define __tmpcosmo_VMIN 1479455781 -#define __tmpcosmo_VQUIT 853995221 -#define __tmpcosmo_VREPRINT 868062415 -#define __tmpcosmo_VSTART -245321985 -#define __tmpcosmo_VSTOP -1379951528 -#define __tmpcosmo_VSUSP -1054959499 -#define __tmpcosmo_VSWTC 1631975394 -#define __tmpcosmo_VTIME -942478376 -#define __tmpcosmo_VWERASE -908507167 -#define __tmpcosmo_XCASE -34176757 - #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_TERMIOS_H_ */ diff --git a/libc/zip.internal.h b/libc/zip.internal.h index 3ebd2626a..9d2c3558c 100644 --- a/libc/zip.internal.h +++ b/libc/zip.internal.h @@ -9,6 +9,12 @@ * @fileoverview PKZIP Data Structures. */ +#ifdef __ASSEMBLER__ +#define ZM_(x) x +#else +#define ZM_(x) ~VEIL("r", ~x) /* prevent magic from appearing in binary */ +#endif + #define kZipOk 0 #define kZipErrorEocdNotFound -1 #define kZipErrorEocdOffsetOverflow -2 @@ -24,8 +30,6 @@ #define kZipErrorMapFailed -12 #define kZipErrorOpenFailed -13 -#define kZipAlign 2 - #define kZipCosmopolitanVersion kZipEra2001 #define kZipOsDos 0 @@ -59,10 +63,9 @@ #define kZipCompressionNone 0 #define kZipCompressionDeflate 8 -#define kZipCdirHdrMagic 0x06054b50 /* PK♣♠ "PK\5\6" */ -#define kZipCdirHdrMagicTodo 0x19184b50 /* PK♣♠ "PK\30\31" */ +#define kZipCdirHdrMagic ZM_(0x06054b50) /* PK♣♠ "PK\5\6" */ +#define kZipCdirHdrMagicTodo ZM_(0x19184b50) /* PK♣♠ "PK\30\31" */ #define kZipCdirHdrMinSize 22 -#define kZipCdirAlign kZipAlign #define kZipCdirHdrLinkableSize 294 #define kZipCdirDiskOffset 4 #define kZipCdirStartingDiskOffset 6 @@ -72,12 +75,12 @@ #define kZipCdirOffsetOffset 16 #define kZipCdirCommentSizeOffset 20 -#define kZipCdir64HdrMagic 0x06064b50 /* PK♣♠ "PK\6\6" */ +#define kZipCdir64HdrMagic ZM_(0x06064b50) /* PK♣♠ "PK\6\6" */ #define kZipCdir64HdrMinSize 56 -#define kZipCdir64LocatorMagic 0x07064b50 /* PK♠• "PK\6\7" */ +#define kZipCdir64LocatorMagic ZM_(0x07064b50) /* PK♠• "PK\6\7" */ #define kZipCdir64LocatorSize 20 -#define kZipCfileHdrMagic 0x02014b50 /* PK☺☻ "PK\1\2" */ +#define kZipCfileHdrMagic ZM_(0x02014b50) /* PK☺☻ "PK\1\2" */ #define kZipCfileHdrMinSize 46 #define kZipCfileOffsetGeneralflag 8 #define kZipCfileOffsetCompressionmethod 10 @@ -89,7 +92,7 @@ #define kZipCfileOffsetExternalattributes 38 #define kZipCfileOffsetOffset 42 -#define kZipLfileHdrMagic 0x04034b50 /* PK♥♦ "PK\3\4" */ +#define kZipLfileHdrMagic ZM_(0x04034b50) /* PK♥♦ "PK\3\4" */ #define kZipLfileHdrMinSize 30 #define kZipLfileOffsetGeneralflag 6 #define kZipLfileOffsetCompressionmethod 8 diff --git a/test/libc/fmt/palandprintf_test.c b/test/libc/fmt/palandprintf_test.c index 8adbab578..72cdb4be9 100644 --- a/test/libc/fmt/palandprintf_test.c +++ b/test/libc/fmt/palandprintf_test.c @@ -27,7 +27,7 @@ #include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" #include "libc/math.h" diff --git a/test/libc/runtime/grow_test.c b/test/libc/runtime/grow_test.c index 3fe8e52fe..e50565d58 100644 --- a/test/libc/runtime/grow_test.c +++ b/test/libc/runtime/grow_test.c @@ -17,7 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/kprintf.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/limits.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" diff --git a/test/net/https/argon2_test.c b/test/net/https/argon2_test.c index 5fabdcc91..a6b23f0bb 100644 --- a/test/net/https/argon2_test.c +++ b/test/net/https/argon2_test.c @@ -16,11 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/argon2/argon2.h" #include "libc/dce.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "net/https/https.h" -#include "third_party/argon2/argon2.h" TEST(argon2, testArgon2ReadmeExample) { uint8_t hash[24]; diff --git a/third_party/linenoise/linenoise.c b/third_party/linenoise/linenoise.c index 720092754..f96c8ecda 100644 --- a/third_party/linenoise/linenoise.c +++ b/third_party/linenoise/linenoise.c @@ -821,7 +821,7 @@ struct winsize linenoiseGetTerminalSize(struct winsize ws, int ifd, int ofd) { int x; ssize_t n; char *p, *s, b[16]; - ioctl(ofd, TIOCGWINSZ, &ws); + tcgetwinsize(ofd, &ws); if ((!ws.ws_row && (s = getenv("ROWS")) && (x = ParseUnsigned(s, 0)))) { ws.ws_row = x; } diff --git a/third_party/lua/lunix.c b/third_party/lua/lunix.c index ecd28016a..0bf99673d 100644 --- a/third_party/lua/lunix.c +++ b/third_party/lua/lunix.c @@ -3368,13 +3368,19 @@ int LuaUnix(lua_State *L) { lua_setglobal(L, "__signal_handlers"); LoadMagnums(L, kErrnoNames, ""); - LoadMagnums(L, kOpenFlags, "O_"); LoadMagnums(L, kSignalNames, ""); LoadMagnums(L, kIpOptnames, "IP_"); LoadMagnums(L, kTcpOptnames, "TCP_"); LoadMagnums(L, kSockOptnames, "SO_"); LoadMagnums(L, kClockNames, "CLOCK_"); + // open() + LuaSetIntField(L, "O_RDONLY", O_RDONLY); + LuaSetIntField(L, "O_WRONLY", O_WRONLY); + LuaSetIntField(L, "O_RDWR", O_RDWR); + LuaSetIntField(L, "O_ACCMODE", O_ACCMODE); + LoadMagnums(L, kOpenFlags, "O_"); + // seek() whence LuaSetIntField(L, "SEEK_SET", SEEK_SET); LuaSetIntField(L, "SEEK_CUR", SEEK_CUR); diff --git a/third_party/python/Lib/test/test_ioctl.py b/third_party/python/Lib/test/test_ioctl.py deleted file mode 100644 index c8e580dfd..000000000 --- a/third_party/python/Lib/test/test_ioctl.py +++ /dev/null @@ -1,98 +0,0 @@ -import array -import unittest -from test.support import import_module, get_attribute -import os, struct - -fcntl = import_module('fcntl') -termios = import_module('termios') -get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature - -if __name__ == 'PYOBJ.COM': - import fcntl - import termios - -try: - tty = open("/dev/tty", "rb") -except OSError: - # todo: gh-runners fail on skiptest cosmo issue #431 - import sys - sys.exit() - raise unittest.SkipTest("Unable to open /dev/tty") -else: - # Skip if another process is in foreground - r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") - tty.close() - rpgrp = struct.unpack("i", r)[0] - if rpgrp not in (os.getpgrp(), os.getsid(0)): - raise unittest.SkipTest("Neither the process group nor the session " - "are attached to /dev/tty") - del tty, r, rpgrp - -try: - import pty -except ImportError: - pty = None - -class IoctlTests(unittest.TestCase): - def test_ioctl(self): - # If this process has been put into the background, TIOCGPGRP returns - # the session ID instead of the process group id. - ids = (os.getpgrp(), os.getsid(0)) - with open("/dev/tty", "rb") as tty: - r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") - rpgrp = struct.unpack("i", r)[0] - self.assertIn(rpgrp, ids) - - def _check_ioctl_mutate_len(self, nbytes=None): - buf = array.array('i') - intsize = buf.itemsize - ids = (os.getpgrp(), os.getsid(0)) - # A fill value unlikely to be in `ids` - fill = -12345 - if nbytes is not None: - # Extend the buffer so that it is exactly `nbytes` bytes long - buf.extend([fill] * (nbytes // intsize)) - self.assertEqual(len(buf) * intsize, nbytes) # sanity check - else: - buf.append(fill) - with open("/dev/tty", "rb") as tty: - r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) - rpgrp = buf[0] - self.assertEqual(r, 0) - self.assertIn(rpgrp, ids) - - def test_ioctl_mutate(self): - self._check_ioctl_mutate_len() - - def test_ioctl_mutate_1024(self): - # Issue #9758: a mutable buffer of exactly 1024 bytes wouldn't be - # copied back after the system call. - self._check_ioctl_mutate_len(1024) - - def test_ioctl_mutate_2048(self): - # Test with a larger buffer, just for the record. - self._check_ioctl_mutate_len(2048) - - def test_ioctl_signed_unsigned_code_param(self): - if not pty or not hasattr(os, 'openpty'): - raise unittest.SkipTest('pty module required') - mfd, sfd = pty.openpty() - try: - if termios.TIOCSWINSZ < 0: - set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ - set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffff - else: - set_winsz_opcode_pos = termios.TIOCSWINSZ - set_winsz_opcode_maybe_neg, = struct.unpack("i", - struct.pack("I", termios.TIOCSWINSZ)) - our_winsz = struct.pack("HHHH",80,25,0,0) - # test both with a positive and potentially negative ioctl code - new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz) - new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz) - finally: - os.close(mfd) - os.close(sfd) - - -if __name__ == "__main__": - unittest.main() diff --git a/third_party/python/Modules/posixmodule.c b/third_party/python/Modules/posixmodule.c index 73eed567a..27259da36 100644 --- a/third_party/python/Modules/posixmodule.c +++ b/third_party/python/Modules/posixmodule.c @@ -10479,7 +10479,7 @@ get_terminal_size(PyObject *self, PyObject *args) */ if (!PyArg_ParseTuple(args, "|i", &fd)) return NULL; - if (ioctl(fd, TIOCGWINSZ, &w)) + if (tcgetwinsize(fd, &w)) return PyErr_SetFromErrno(PyExc_OSError); columns = w.ws_col; lines = w.ws_row; diff --git a/third_party/python/Modules/termios.c b/third_party/python/Modules/termios.c index 9d2292de7..06492ab62 100644 --- a/third_party/python/Modules/termios.c +++ b/third_party/python/Modules/termios.c @@ -59,15 +59,12 @@ PYTHON_PROVIDE("termios.BRKINT"); PYTHON_PROVIDE("termios.BS0"); PYTHON_PROVIDE("termios.BS1"); PYTHON_PROVIDE("termios.BSDLY"); -PYTHON_PROVIDE("termios.CBAUD"); -PYTHON_PROVIDE("termios.CBAUDEX"); PYTHON_PROVIDE("termios.CDSUSP"); PYTHON_PROVIDE("termios.CEOF"); PYTHON_PROVIDE("termios.CEOL"); PYTHON_PROVIDE("termios.CEOT"); PYTHON_PROVIDE("termios.CERASE"); PYTHON_PROVIDE("termios.CFLUSH"); -PYTHON_PROVIDE("termios.CIBAUD"); PYTHON_PROVIDE("termios.CINTR"); PYTHON_PROVIDE("termios.CKILL"); PYTHON_PROVIDE("termios.CLNEXT"); @@ -146,8 +143,6 @@ PYTHON_PROVIDE("termios.TAB1"); PYTHON_PROVIDE("termios.TAB2"); PYTHON_PROVIDE("termios.TAB3"); PYTHON_PROVIDE("termios.TABDLY"); -PYTHON_PROVIDE("termios.TCFLSH"); -PYTHON_PROVIDE("termios.TCGETS"); PYTHON_PROVIDE("termios.TCIFLUSH"); PYTHON_PROVIDE("termios.TCIOFF"); PYTHON_PROVIDE("termios.TCIOFLUSH"); @@ -158,15 +153,9 @@ PYTHON_PROVIDE("termios.TCOON"); PYTHON_PROVIDE("termios.TCSADRAIN"); PYTHON_PROVIDE("termios.TCSAFLUSH"); PYTHON_PROVIDE("termios.TCSANOW"); -PYTHON_PROVIDE("termios.TCSBRK"); -PYTHON_PROVIDE("termios.TCSETS"); -PYTHON_PROVIDE("termios.TCSETSF"); -PYTHON_PROVIDE("termios.TCSETSW"); PYTHON_PROVIDE("termios.TCXONC"); PYTHON_PROVIDE("termios.TIOCCONS"); PYTHON_PROVIDE("termios.TIOCGETD"); -PYTHON_PROVIDE("termios.TIOCGPGRP"); -PYTHON_PROVIDE("termios.TIOCGWINSZ"); PYTHON_PROVIDE("termios.TIOCMBIC"); PYTHON_PROVIDE("termios.TIOCMBIS"); PYTHON_PROVIDE("termios.TIOCMGET"); @@ -187,10 +176,6 @@ PYTHON_PROVIDE("termios.TIOCNXCL"); PYTHON_PROVIDE("termios.TIOCOUTQ"); PYTHON_PROVIDE("termios.TIOCPKT"); PYTHON_PROVIDE("termios.TIOCSCTTY"); -PYTHON_PROVIDE("termios.TIOCSERGETLSR"); -PYTHON_PROVIDE("termios.TIOCSERGETMULTI"); -PYTHON_PROVIDE("termios.TIOCSERSETMULTI"); -PYTHON_PROVIDE("termios.TIOCSER_TEMT"); PYTHON_PROVIDE("termios.TIOCSETD"); PYTHON_PROVIDE("termios.TIOCSPGRP"); PYTHON_PROVIDE("termios.TIOCSTI"); @@ -573,7 +558,6 @@ PyInit_termios(void) if (B3000000) PyModule_AddIntConstant(m, "B3000000", B3000000); if (B3500000) PyModule_AddIntConstant(m, "B3500000", B3500000); if (B4000000) PyModule_AddIntConstant(m, "B4000000", B4000000); - if (CBAUDEX) PyModule_AddIntConstant(m, "CBAUDEX", CBAUDEX); /* TODO(jart): B460800 */ /* TODO(jart): B921600 */ /* TODO(jart): B460800 */ @@ -641,7 +625,6 @@ PyInit_termios(void) if (PARODD) PyModule_AddIntConstant(m, "PARODD", PARODD); if (HUPCL) PyModule_AddIntConstant(m, "HUPCL", HUPCL); if (CLOCAL) PyModule_AddIntConstant(m, "CLOCAL", CLOCAL); - if (CIBAUD) PyModule_AddIntConstant(m, "CIBAUD", CIBAUD); PyModule_AddIntConstant(m, "CS5", CS5); if (CS6) PyModule_AddIntConstant(m, "CS6", CS6); if (CS7) PyModule_AddIntConstant(m, "CS7", CS7); @@ -682,7 +665,6 @@ PyInit_termios(void) PyModule_AddIntConstant(m, "VWERASE", VWERASE); PyModule_AddIntConstant(m, "VLNEXT", VLNEXT); PyModule_AddIntConstant(m, "VEOL2", VEOL2); - if (CBAUD) PyModule_AddIntConstant(m, "CBAUD", CBAUD); /* */ PyModule_AddIntConstant(m, "CEOF", CEOF); @@ -721,28 +703,18 @@ PyInit_termios(void) /* TODO(jart): SLIP */ /* TODO(jart): STRIP */ /* TODO(jart): TTY */ - if (TCFLSH) PyModule_AddIntConstant(m, "TCFLSH", TCFLSH); /* TODO(jart): TCGETA */ - if (TCGETS) PyModule_AddIntConstant(m, "TCGETS", TCGETS); - if (TCSBRK) PyModule_AddIntConstant(m, "TCSBRK", TCSBRK); /* TODO(jart): TCSBRKP */ /* TODO(jart): TCSETA */ /* TODO(jart): TCSETAF */ /* TODO(jart): TCSETAW */ - if (TCSETS) PyModule_AddIntConstant(m, "TCSETS", TCSETS); - if (TCSETSF) PyModule_AddIntConstant(m, "TCSETSF", TCSETSF); - if (TCSETSW) PyModule_AddIntConstant(m, "TCSETSW", TCSETSW); - if (TCXONC) PyModule_AddIntConstant(m, "TCXONC", TCXONC); if (TIOCCONS) PyModule_AddIntConstant(m, "TIOCCONS", TIOCCONS); /* TODO(jart): TIOCEXCL */ if (TIOCGETD) PyModule_AddIntConstant(m, "TIOCGETD", TIOCGETD); /* TODO(jart): TIOCGICOUNT */ /* TODO(jart): TIOCGLCKTRMIOS */ - if (TIOCGPGRP) PyModule_AddIntConstant(m, "TIOCGPGRP", TIOCGPGRP); /* TODO(jart): TIOCGSERIAL */ /* TODO(jart): TIOCGSOFTCAR */ - PyModule_AddIntConstant(m, "TIOCGWINSZ", TIOCGWINSZ); - PyModule_AddIntConstant(m, "TIOCSWINSZ", TIOCSWINSZ); /* TODO(jart): TIOCINQ */ /* TODO(jart): TIOCLINUX */ if (TIOCMBIC) PyModule_AddIntConstant(m, "TIOCMBIC", TIOCMBIC); @@ -774,13 +746,9 @@ PyInit_termios(void) /* TODO(jart): STOP */ if (TIOCSCTTY) PyModule_AddIntConstant(m, "TIOCSCTTY", TIOCSCTTY); /* TODO(jart): TIOCSERCONFIG */ - if (TIOCSERGETLSR) PyModule_AddIntConstant(m, "TIOCSERGETLSR", TIOCSERGETLSR); - if (TIOCSERGETMULTI) PyModule_AddIntConstant(m, "TIOCSERGETMULTI", TIOCSERGETMULTI); /* TODO(jart): TIOCSERGSTRUCT */ /* TODO(jart): TIOCSERGWILD */ - if (TIOCSERSETMULTI) PyModule_AddIntConstant(m, "TIOCSERSETMULTI", TIOCSERSETMULTI); /* TODO(jart): TIOCSERSWILD */ - if (TIOCSER_TEMT) PyModule_AddIntConstant(m, "TIOCSER_TEMT", TIOCSER_TEMT); if (TIOCSETD) PyModule_AddIntConstant(m, "TIOCSETD", TIOCSETD); /* TODO(jart): TIOCSLCKTRMIOS */ if (TIOCSPGRP) PyModule_AddIntConstant(m, "TIOCSPGRP", TIOCSPGRP); diff --git a/third_party/python/Python/pystate.c b/third_party/python/Python/pystate.c index 8bc592d2d..a14dcee22 100644 --- a/third_party/python/Python/pystate.c +++ b/third_party/python/Python/pystate.c @@ -5,7 +5,7 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" -#include "libc/intrin/pushpop.h" +#include "libc/intrin/pushpop.internal.h" #include "libc/runtime/dlfcn.h" #include "third_party/python/Include/ceval.h" #include "third_party/python/Include/dictobject.h" diff --git a/third_party/python/python.mk b/third_party/python/python.mk index 852521369..1b1472dc2 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -1885,7 +1885,6 @@ THIRD_PARTY_PYTHON_PYTEST_PYMAINS = \ third_party/python/Lib/test/test_index.py \ third_party/python/Lib/test/test_int.py \ third_party/python/Lib/test/test_int_literal.py \ - third_party/python/Lib/test/test_ioctl.py \ third_party/python/Lib/test/test_ipaddress.py \ third_party/python/Lib/test/test_isinstance.py \ third_party/python/Lib/test/test_iter.py \ @@ -2154,8 +2153,6 @@ o/$(MODE)/third_party/python/Lib/test/test_signal.py.runs: \ private .PLEDGE = stdio rpath wpath cpath fattr proc flock inet o/$(MODE)/third_party/python/Lib/test/test_timeout.py.runs: \ private .PLEDGE = stdio rpath wpath cpath fattr proc inet -o/$(MODE)/third_party/python/Lib/test/test_ioctl.py.runs: \ - private .PLEDGE = stdio rpath wpath cpath fattr proc tty PYTHONTESTER = $(VM) o/$(MODE)/third_party/python/pythontester.com diff --git a/third_party/quickjs/quickjs-libc.c b/third_party/quickjs/quickjs-libc.c index 07fb0622f..708fe4857 100644 --- a/third_party/quickjs/quickjs-libc.c +++ b/third_party/quickjs/quickjs-libc.c @@ -22,6 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "third_party/quickjs/quickjs-libc.h" #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" @@ -51,7 +52,6 @@ #include "libc/time/time.h" #include "third_party/quickjs/cutils.h" #include "third_party/quickjs/list.h" -#include "third_party/quickjs/quickjs-libc.h" asm(".ident\t\"\\n\\n\ QuickJS (MIT License)\\n\ @@ -1696,7 +1696,7 @@ static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val, if (JS_ToInt32(ctx, &fd, argv[0])) return JS_EXCEPTION; - if (ioctl(fd, TIOCGWINSZ, &ws) == 0 && + if (tcgetwinsize(fd, &ws) == 0 && ws.ws_col >= 4 && ws.ws_row >= 4) { obj = JS_NewArray(ctx); if (JS_IsException(obj)) diff --git a/third_party/unzip/ttyio.c b/third_party/unzip/ttyio.c index 566221be7..3ed030c0f 100644 --- a/third_party/unzip/ttyio.c +++ b/third_party/unzip/ttyio.c @@ -34,6 +34,8 @@ #include "third_party/unzip/crypt.h" #include "libc/sysv/consts/termios.h" #include "libc/calls/ioctl.h" +#include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "third_party/unzip/globals.h" #if (CRYPT || (defined(UNZIP) && !defined(FUNZIP))) diff --git a/tool/build/compile.c b/tool/build/compile.c index 503078629..30c65917d 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -27,6 +27,7 @@ #include "libc/calls/struct/stat.h" #include "libc/calls/struct/timeval.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/conv.h" @@ -334,7 +335,7 @@ int GetTerminalWidth(void) { return atoi(s); } else { ws.ws_col = 0; - ioctl(2, TIOCGWINSZ, &ws); + tcgetwinsize(2, &ws); return ws.ws_col; } } @@ -348,7 +349,7 @@ int GetLineWidth(bool *isineditor) { } if (s) { return atoi(s); - } else if (ioctl(2, TIOCGWINSZ, &ws) != -1) { + } else if (tcgetwinsize(2, &ws) != -1) { if (ws.ws_col && ws.ws_row) { return ws.ws_col * ws.ws_row / 3; } else { diff --git a/tool/build/lib/bits.h b/tool/build/lib/bits.h deleted file mode 100755 index c8332ccfc..000000000 --- a/tool/build/lib/bits.h +++ /dev/null @@ -1,166 +0,0 @@ -#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_BITS_H_ -#define COSMOPOLITAN_TOOL_BUILD_LIB_BITS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct iovec_bits { - uint8_t iov_base[8]; - uint8_t iov_len[8]; -}; - -struct pollfd_bits { - uint8_t fd[4]; - uint8_t events[2]; - uint8_t revents[2]; -}; - -struct timeval_bits { - uint8_t tv_sec[8]; - uint8_t tv_usec[8]; -}; - -struct timespec_bits { - uint8_t tv_sec[8]; - uint8_t tv_nsec[8]; -}; - -struct timezone_bits { - uint8_t tz_minuteswest[4]; - uint8_t tz_dsttime[4]; -}; - -struct sigaction_bits { - uint8_t handler[8]; - uint8_t flags[8]; - uint8_t restorer[8]; - uint8_t mask[8]; -}; - -struct winsize_bits { - uint8_t ws_row[2]; - uint8_t ws_col[2]; - uint8_t ws_xpixel[2]; - uint8_t ws_ypixel[2]; -}; - -struct termios_bits { - uint8_t c_iflag[4]; - uint8_t c_oflag[4]; - uint8_t c_cflag[4]; - uint8_t c_lflag[4]; - uint8_t c_cc[32]; - uint8_t c_ispeed[4]; - uint8_t c_ospeed[4]; -}; - -struct sockaddr_in_bits { - uint8_t sin_family[2]; - uint16_t sin_port; - uint32_t sin_addr; - uint8_t sin_zero[8]; -}; - -struct stat_bits { - uint8_t st_dev[8]; - uint8_t st_ino[8]; - uint8_t st_nlink[8]; - uint8_t st_mode[4]; - uint8_t st_uid[4]; - uint8_t st_gid[4]; - uint8_t __pad[4]; - uint8_t st_rdev[8]; - uint8_t st_size[8]; - uint8_t st_blksize[8]; - uint8_t st_blocks[8]; - struct timespec_bits st_atim; - struct timespec_bits st_mtim; - struct timespec_bits st_ctim; -}; - -struct itimerval_bits { - struct timeval_bits it_interval; - struct timeval_bits it_value; -}; - -struct rusage_bits { - struct timeval_bits ru_utime; - struct timeval_bits ru_stime; - uint8_t ru_maxrss[8]; - uint8_t ru_ixrss[8]; - uint8_t ru_idrss[8]; - uint8_t ru_isrss[8]; - uint8_t ru_minflt[8]; - uint8_t ru_majflt[8]; - uint8_t ru_nswap[8]; - uint8_t ru_inblock[8]; - uint8_t ru_oublock[8]; - uint8_t ru_msgsnd[8]; - uint8_t ru_msgrcv[8]; - uint8_t ru_nsignals[8]; - uint8_t ru_nvcsw[8]; - uint8_t ru_nivcsw[8]; -}; - -struct siginfo_bits { - uint8_t si_signo[4]; - uint8_t si_errno[4]; - uint8_t si_code[4]; - uint8_t __pad[4]; - uint8_t payload[112]; -}; - -struct fpstate_bits { - uint8_t cwd[2]; - uint8_t swd[2]; - uint8_t ftw[2]; - uint8_t fop[2]; - uint8_t rip[8]; - uint8_t rdp[8]; - uint8_t mxcsr[4]; - uint8_t mxcr_mask[4]; - uint8_t st[8][16]; - uint8_t xmm[16][16]; - uint8_t __padding[96]; -}; - -struct ucontext_bits { - uint8_t uc_flags[8]; - uint8_t uc_link[8]; - uint8_t ss_sp[8]; - uint8_t ss_flags[4]; - uint8_t __pad0[4]; - uint8_t ss_size[8]; - uint8_t r8[8]; - uint8_t r9[8]; - uint8_t r10[8]; - uint8_t r11[8]; - uint8_t r12[8]; - uint8_t r13[8]; - uint8_t r14[8]; - uint8_t r15[8]; - uint8_t rdi[8]; - uint8_t rsi[8]; - uint8_t rbp[8]; - uint8_t rbx[8]; - uint8_t rdx[8]; - uint8_t rax[8]; - uint8_t rcx[8]; - uint8_t rsp[8]; - uint8_t rip[8]; - uint8_t eflags[8]; - uint8_t cs[2]; - uint8_t gs[2]; - uint8_t fs[2]; - uint8_t ss[2]; - uint8_t err[8]; - uint8_t trapno[8]; - uint8_t oldmask[8]; - uint8_t cr2[8]; - uint8_t fpstate[8]; - uint8_t __pad1[64]; - uint8_t uc_sigmask[8]; -}; - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_TOOL_BUILD_LIB_BITS_H_ */ diff --git a/tool/build/mv.c b/tool/build/mv.c index b3caedd60..c5362ca63 100644 --- a/tool/build/mv.c +++ b/tool/build/mv.c @@ -27,8 +27,6 @@ #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" -#include "libc/sysv/consts/ex.h" -#include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/ok.h" #include "libc/sysv/consts/s.h" #include "libc/x/x.h" @@ -63,6 +61,30 @@ char linkbuf[PATH_MAX]; void Mv(char *, char *); +nullterminated() void Print(int fd, const char *s, ...) { + va_list va; + char buf[2048]; + va_start(va, s); + buf[0] = 0; + do { + strlcat(buf, s, sizeof(buf)); + } while ((s = va_arg(va, const char *))); + write(fd, buf, strlen(buf)); + va_end(va); +} + +wontreturn void Die(const char *path, const char *reason) { + Print(2, path, ": ", reason, "\n", NULL); + exit(1); +} + +wontreturn void SysExit(const char *path, const char *func) { + const char *errstr; + if (!(errstr = _strerdoc(errno))) errstr = "EUNKNOWN"; + Print(2, path, ": ", func, "() failed with ", errstr, "\n", NULL); + exit(1); +} + bool IsDirectory(const char *path) { int e; bool res; @@ -84,10 +106,8 @@ bool IsSymlink(const char *path) { return res; } -wontreturn void PrintUsage(int rc, FILE *f) { - fputs("usage: ", f); - fputs(prog, f); - fputs(USAGE, f); +wontreturn void PrintUsage(int rc, int fd) { + Print(fd, "usage: ", prog, USAGE, NULL); exit(rc); } @@ -104,9 +124,9 @@ void GetOpts(int argc, char *argv[]) { break; case 'h': case '?': - PrintUsage(EXIT_SUCCESS, stdout); + PrintUsage(0, 1); default: - PrintUsage(EX_USAGE, stderr); + PrintUsage(1, 2); } } } @@ -131,9 +151,7 @@ int Visit(const char *fpath, const struct stat *sb, int tflag, Mv(srcfile, dstfile); return 0; default: - fputs(fpath, stderr); - fputs(": can't handle file type\n", stderr); - exit(1); + Die(fpath, "can't handle file type"); } } @@ -142,7 +160,7 @@ char *Join(const char *a, const char *b) { n = strlen(a); m = strlen(b); if (n + 1 + m + 1 > sizeof(dstfile)) { - fputs("error: mv: path too long\n", stderr); + Print(2, "error: mv: path too long\n", NULL); exit(1); } stpcpy(stpcpy(stpcpy(dstfile, a), "/"), b); @@ -151,16 +169,14 @@ char *Join(const char *a, const char *b) { void Mv(char *src, char *dst) { ssize_t rc; - const char *s; + const char *s, *d; if (strlen(src) + 1 > PATH_MAX) _Exit(2); if (strlen(dst) + 1 > PATH_MAX) _Exit(2); basename(src); basename(dst); if (IsDirectory(src)) { if (!recursive) { - fputs(prog, stderr); - fputs(": won't move directory without -r flag.\n", stderr); - exit(1); + Die(prog, "won't move directory without -r flag."); } strcpy(dstdir, dst); if (IsDirectory(dst)) { @@ -175,46 +191,40 @@ void Mv(char *src, char *dst) { strcpy(srcdir, ""); } if (nftw(src, Visit, 20, 0) == -1) { - fputs(prog, stderr); - fputs(": nftw failed: ", stderr); - fputs(_strerdoc(errno), stderr); - fputs("\n", stderr); - exit(1); + SysExit(src, "nftw"); } return; } if (IsDirectory(dst)) { dst = Join(dst, basename(src)); } - if (!force && access(dst, W_OK) == -1 && errno != ENOENT) goto OnFail; - strcpy(mkbuf, dst); - if (makedirs(dirname(mkbuf), 0755) == -1) goto OnFail; - if (IsSymlink(src)) { - if ((rc = readlink(src, linkbuf, sizeof(linkbuf) - 1)) == -1) goto OnFail; - linkbuf[rc] = 0; - if (symlink(linkbuf, dst) == -1) goto OnFail; - } else { - if (rename(src, dst) == -1) goto OnFail; + if (!force && access(dst, W_OK) == -1 && errno != ENOENT) { + SysExit(dst, "access"); + } + strcpy(mkbuf, dst); + if (makedirs((d = dirname(mkbuf)), 0755) == -1) { + SysExit(d, "makedirs"); + } + if (IsSymlink(src)) { + if ((rc = readlink(src, linkbuf, sizeof(linkbuf) - 1)) == -1) { + SysExit(src, "readlink"); + } + linkbuf[rc] = 0; + if (symlink(linkbuf, dst)) { + SysExit(dst, "symlink"); + } + } else { + if (rename(src, dst)) { + SysExit(src, "rename"); + } } - return; -OnFail: - s = _strerdoc(errno); - fputs(prog, stderr); - fputs(": ", stderr); - fputs(src, stderr); - fputs(" ", stderr); - fputs(dst, stderr); - fputs(": ", stderr); - fputs(s, stderr); - fputs("\n", stderr); - exit(1); } int main(int argc, char *argv[]) { int i; prog = argc > 0 ? argv[0] : "mv.com"; GetOpts(argc, argv); - if (argc - optind < 2) PrintUsage(EX_USAGE, stderr); + if (argc - optind < 2) PrintUsage(1, 2); for (i = optind; i < argc - 1; ++i) { Mv(argv[i], argv[argc - 1]); } diff --git a/tool/build/zipcopy.c b/tool/build/zipcopy.c index 784be57d7..0d416e883 100644 --- a/tool/build/zipcopy.c +++ b/tool/build/zipcopy.c @@ -188,14 +188,11 @@ static void CopyZip(void) { ldest += length; // write directory entry length = ZIP_CFILE_HDRSIZE(cfile); - if (READ32LE(cfile) != kZipCfileHdrMagic) notpossible; if (pwrite(outfd, cfile, length, cdest) != length) { SysExit(outpath, "lfile pwrite"); } cdest += length; } - if (ldest != outsize + ltotal) __builtin_trap(); - if (cdest != outsize + ltotal + ctotal) __builtin_trap(); WRITE32LE(eocd + kZipCdirOffsetOffset, outsize + ltotal); length = ZIP_CDIR_HDRSIZE(eocd); if (pwrite(outfd, eocd, length, cdest) != length) { diff --git a/tool/emacs/cosmo-stuff.el b/tool/emacs/cosmo-stuff.el index ebdea150d..42648c5c7 100644 --- a/tool/emacs/cosmo-stuff.el +++ b/tool/emacs/cosmo-stuff.el @@ -26,6 +26,7 @@ (require 'make-mode) (setq cosmo-dbg-mode "dbg") +(setq cosmo-default-mode "") (setq c-doc-comment-style 'javadown) (add-to-list 'auto-mode-alist '("\\.x$" . c-mode)) ;; -aux-info @@ -170,7 +171,7 @@ ((eq arg 8) "aarch64-tiny") (default default) ((cosmo-intest) cosmo-dbg-mode) - (t "fastbuild"))) + (t cosmo-default-mode))) (defun cosmo--make-suffix (arg) (cond ((eq arg 9) ".chibicc") @@ -637,7 +638,7 @@ (let ((default-directory root)) (save-buffer) (cond ((memq major-mode '(c-mode c++-mode asm-mode fortran-mode)) - (let* ((mode (cosmo--make-mode arg "fastbuild")) + (let* ((mode (cosmo--make-mode arg cosmo-default-mode)) (compile-command (cosmo--compile-command this root 'test mode "" "" ".ok"))) (compile compile-command))) ('t @@ -653,7 +654,7 @@ (let ((default-directory root)) (save-buffer) (cond ((memq major-mode '(c-mode c++-mode asm-mode fortran-mode)) - (let* ((mode (cosmo--make-mode arg "fastbuild")) + (let* ((mode (cosmo--make-mode arg cosmo-default-mode)) (compile-command (cosmo--compile-command this root 'run-win10 mode "" "" ""))) (compile compile-command))) ('t diff --git a/tool/net/help.txt b/tool/net/help.txt index b577410fd..cd88bab9e 100644 --- a/tool/net/help.txt +++ b/tool/net/help.txt @@ -4359,7 +4359,7 @@ UNIX MODULE tty - Allows isatty, tiocgwinsz, tcgets, tcsets, tcsetsw, tcsetsf. + Allows isatty, tcgetwinsize, tcgets, tcsets, tcsetsw, tcsetsf. inet @@ -4683,7 +4683,7 @@ UNIX MODULE No other error numbers are possible. - unix.tiocgwinsz(fd:int) + unix.tcgetwinsize(fd:int) ├─→ rows:int, cols:int └─→ nil, unix.Errno diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 6202fc611..0893ef426 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -31,6 +31,7 @@ #include "libc/calls/struct/stat.h" #include "libc/calls/struct/termios.h" #include "libc/calls/struct/timespec.h" +#include "libc/calls/termios.h" #include "libc/dce.h" #include "libc/dns/dns.h" #include "libc/dns/hoststxt.h" @@ -6606,7 +6607,7 @@ static int MemoryMonitor(void *arg, int tid) { pthread_spin_lock(&shared->montermlock); if (!id) { if ((tty = open(monitortty, O_RDWR | O_NOCTTY)) != -1) { - ioctl(tty, TCGETS, &oldterm); + tcgetattr(tty, &oldterm); term = oldterm; term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); term.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); @@ -6615,7 +6616,7 @@ static int MemoryMonitor(void *arg, int tid) { term.c_cflag |= CS8; term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; - ioctl(tty, TCSETS, &term); + tcsetattr(tty, TCSANOW, &term); WRITE(tty, "\e[?25l", 6); } } @@ -6658,7 +6659,7 @@ static int MemoryMonitor(void *arg, int tid) { ws.ws_col = 80; ws.ws_row = 40; - _getttysize(tty, &ws); + tcgetwinsize(tty, &ws); appendr(&b, 0); appends(&b, "\e[H\e[1m"); @@ -6718,7 +6719,7 @@ static int MemoryMonitor(void *arg, int tid) { appendr(&b, 0); appends(&b, "\e[H\e[J\e[?25h"); WRITE(tty, b, appendz(b).i); - ioctl(tty, TCSETS, &oldterm); + tcsetattr(tty, TCSANOW, &oldterm); } DEBUGF("(memv) exiting..."); diff --git a/tool/scripts/cosmoc++ b/tool/scripts/cosmoc++ index b21cb26ca..49cf71fca 100755 --- a/tool/scripts/cosmoc++ +++ b/tool/scripts/cosmoc++ @@ -34,12 +34,18 @@ # __builtin_trap(); # } # -# building programs in tiny mode +# building in tiny mode # # export MODE=tiny # (cd /opt/cosmo; make -j8 toolchain) # cosmoc++ -Os -o foo.com foo.cc # +# building in tiniest mode (linux only) +# +# export MODE=tinylinux +# (cd /opt/cosmo; make -j8 toolchain) +# cosmoc++ -Os -o foo.com foo.c +# # hardening programs with memory safety # # export MODE=asan @@ -65,7 +71,7 @@ PLATFORM="-D__COSMOPOLITAN__" PREDEF="-include libc/integral/normalize.inc" CCFLAGS="-fdata-sections -ffunction-sections -fno-pie -mno-tls-direct-seg-refs -mno-red-zone -fportcosmo" CXXFLAGS="-fno-exceptions -fuse-cxa-atexit -fno-threadsafe-statics" -CPPFLAGS="-DNDEBUG -nostdinc -iquote $COSMO -isystem $COSMOS/include -isystem $COSMO/libc/isystem" +CPPFLAGS="-nostdinc -iquote $COSMO -isystem $COSMOS/include -isystem $COSMO/libc/isystem" LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -L$COSMOS/lib -Wl,-T,$COSMO/o/$MODE/ape/public/ape.lds $COSMO/o/$MODE/ape/ape-no-modify-self.o $COSMO/o/$MODE/libc/crt/crt.o" LDLIBS="$COSMO/o/$MODE/third_party/libcxx/libcxx.a $COSMO/o/$MODE/cosmopolitan.a" @@ -148,7 +154,7 @@ for x; do set -- "$@" "$x" done -if [ x"$OPT" != x"-Os" ] && [ x"$MODE" != x"tiny" ]; then +if [ x"$OPT" != x"-Os" ] && [ x"${MODE#tiny}" != x"${MODE}" ]; then # support --ftrace unless optimizing for size CXXFLAGS="$CXXFLAGS -fpatchable-function-entry=18,16" fi @@ -158,7 +164,7 @@ if [ $INTENT = cpp ]; then elif [ $INTENT = cc ]; then set -- $PLATFORM $PREDEF $CCFLAGS $CXXFLAGS $CPPFLAGS "$@" $FRAME else - set -- $PLATFORM $PREDEF $LDFLAGS $CXXFLAGS $CPPFLAGS "$@" $LDLIBS -Wl,-z,common-page-size=65536 -Wl,-z,max-page-size=65536 $FRAME + set -- $PLATFORM $PREDEF $LDFLAGS $CXXFLAGS $CPPFLAGS "$@" $LDLIBS -Wl,-z,common-page-size=4096 -Wl,-z,max-page-size=4096 $FRAME fi set -- "$CXX" "$@" diff --git a/tool/scripts/cosmocc b/tool/scripts/cosmocc index 08918224b..fb5271b20 100755 --- a/tool/scripts/cosmocc +++ b/tool/scripts/cosmocc @@ -34,12 +34,18 @@ # __builtin_trap(); # } # -# building programs in tiny mode +# building in tiny mode # # export MODE=tiny # (cd /opt/cosmo; make -j8 toolchain) # cosmocc -Os -o foo.com foo.c # +# building in tiniest mode (linux only) +# +# export MODE=tinylinux +# (cd /opt/cosmo; make -j8 toolchain) +# cosmocc -Os -o foo.com foo.c +# # hardening programs with memory safety # # export MODE=asan @@ -65,7 +71,7 @@ PLATFORM="-D__COSMOPOLITAN__" PREDEF="-include libc/integral/normalize.inc" CCFLAGS="-fdata-sections -ffunction-sections -fno-pie -mno-tls-direct-seg-refs -mno-red-zone -fportcosmo" CFLAGS= -CPPFLAGS="-DNDEBUG -nostdinc -iquote $COSMO -isystem $COSMOS/include -isystem $COSMO/libc/isystem" +CPPFLAGS="-nostdinc -iquote $COSMO -isystem $COSMOS/include -isystem $COSMO/libc/isystem" LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -L$COSMOS/lib -Wl,-T,$COSMO/o/$MODE/ape/public/ape.lds $COSMO/o/$MODE/ape/ape-no-modify-self.o $COSMO/o/$MODE/libc/crt/crt.o" LDLIBS="$COSMO/o/$MODE/cosmopolitan.a" @@ -148,7 +154,7 @@ for x; do set -- "$@" "$x" done -if [ x"$OPT" != x"-Os" ] && [ x"$MODE" != x"tiny" ]; then +if [ x"$OPT" != x"-Os" ] && [ x"${MODE#tiny}" != x"${MODE}" ]; then # support --ftrace unless optimizing for size CFLAGS="$CFLAGS -fpatchable-function-entry=18,16" fi @@ -158,7 +164,7 @@ if [ $INTENT = cpp ]; then elif [ $INTENT = cc ]; then set -- $PLATFORM $PREDEF $CCFLAGS $CFLAGS $CPPFLAGS "$@" $FRAME else - set -- $PLATFORM $PREDEF $LDFLAGS $CFLAGS $CPPFLAGS "$@" $LDLIBS -Wl,-z,common-page-size=65536 -Wl,-z,max-page-size=65536 $FRAME + set -- $PLATFORM $PREDEF $LDFLAGS $CFLAGS $CPPFLAGS "$@" $LDLIBS -Wl,-z,common-page-size=4096 -Wl,-z,max-page-size=4096 $FRAME fi set -- "$CC" "$@" diff --git a/tool/viz/basicidea.c b/tool/viz/basicidea.c index 83eb26c45..b85c127f6 100644 --- a/tool/viz/basicidea.c +++ b/tool/viz/basicidea.c @@ -21,6 +21,7 @@ #include "libc/calls/ioctl.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/fmt/fmt.h" #include "libc/log/log.h" #include "libc/macros.internal.h" @@ -97,8 +98,8 @@ void GetTermSize(int *out_rows, int *out_cols) { struct winsize ws; ws.ws_row = 20; ws.ws_col = 80; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws); - ioctl(STDIN_FILENO, TIOCGWINSZ, &ws); + tcgetwinsize(STDOUT_FILENO, &ws); + tcgetwinsize(STDIN_FILENO, &ws); *out_rows = ws.ws_row; *out_cols = ws.ws_col; } diff --git a/tool/viz/derasterize.c b/tool/viz/derasterize.c index 5f1e0391a..a0aaf2a29 100644 --- a/tool/viz/derasterize.c +++ b/tool/viz/derasterize.c @@ -453,8 +453,8 @@ static void GetTermSize(unsigned out_rows[1], unsigned out_cols[1]) { struct winsize ws; ws.ws_row = 24; ws.ws_col = 80; - if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) { - ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws); + if (tcgetwinsize(STDIN_FILENO, &ws) == -1) { + tcgetwinsize(STDOUT_FILENO, &ws); } out_rows[0] = ws.ws_row; out_cols[0] = ws.ws_col; diff --git a/tool/viz/fontspace.c b/tool/viz/fontspace.c index 07c6682a4..9439703ca 100644 --- a/tool/viz/fontspace.c +++ b/tool/viz/fontspace.c @@ -19,6 +19,7 @@ #include "dsp/scale/cdecimate2xuint8x8.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/fmt/conv.h" #include "libc/intrin/bsr.h" #include "libc/log/libfatal.internal.h" @@ -69,7 +70,7 @@ int main(int argc, char *argv[]) { unsigned char *intotal; int w, h, i, j, c, arg, opt, errs, line, count, maxcode, s = 40 * 4, rc = 0; ShowCrashReports(); - ioctl(0, TIOCGWINSZ, &ws); + tcgetwinsize(0, &ws); while ((opt = getopt(argc, argv, "vs:e:")) != -1) { switch (opt) { case 'v': diff --git a/tool/viz/life.c b/tool/viz/life.c index d5e7fa240..19e0d901c 100644 --- a/tool/viz/life.c +++ b/tool/viz/life.c @@ -22,6 +22,7 @@ #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/termios.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" @@ -712,7 +713,7 @@ static void GetTtySize(void) { struct winsize wsize; wsize.ws_row = tyn + 1; wsize.ws_col = txn; - _getttysize(out, &wsize); + tcgetwinsize(out, &wsize); tyn = wsize.ws_row - 1; txn = wsize.ws_col; right = left + txn; @@ -729,14 +730,14 @@ static void EnableRaw(void) { term.c_cflag &= ~(CSIZE | PARENB); term.c_cflag |= CS8; term.c_iflag |= IUTF8; - ioctl(out, TCSETS, &term); + tcsetattr(out, TCSANOW, &term); } static void OnExit(void) { LeaveScreen(); ShowTtyCursor(); DisableMouse(); - ioctl(out, TCSETS, &oldterm); + tcsetattr(out, TCSANOW, &oldterm); } static void OnSigInt(int sig) { @@ -1101,7 +1102,7 @@ static bool ShouldDraw(void) { static void Tui(void) { GetTtySize(); Dimension(); - ioctl(out, TCGETS, &oldterm); + tcgetattr(out, &oldterm); HideTtyCursor(); EnableRaw(); EnableMouse(); diff --git a/tool/viz/memzoom.c b/tool/viz/memzoom.c index 18e34c3b8..00e8d3455 100644 --- a/tool/viz/memzoom.c +++ b/tool/viz/memzoom.c @@ -24,6 +24,7 @@ #include "libc/calls/struct/stat.h" #include "libc/calls/struct/termios.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/calls/ucontext.h" #include "libc/errno.h" #include "libc/fmt/conv.h" @@ -192,7 +193,7 @@ static void GetTtySize(void) { struct winsize wsize; wsize.ws_row = tyn + 1; wsize.ws_col = txn; - _getttysize(out, &wsize); + tcgetwinsize(out, &wsize); tyn = MAX(2, wsize.ws_row) - 1; txn = MAX(17, wsize.ws_col) - 16; tyn = _rounddown2pow(tyn); @@ -210,14 +211,14 @@ static void EnableRaw(void) { term.c_cflag &= ~(CSIZE | PARENB); term.c_cflag |= CS8; term.c_iflag |= IUTF8; - ioctl(out, TCSETS, &term); + tcsetattr(out, TCSANOW, &term); } static void OnExit(void) { LeaveScreen(); ShowCursor(); DisableMouse(); - ioctl(out, TCSETS, &oldterm); + tcsetattr(out, TCSANOW, &oldterm); } static void OnSigInt(int sig, struct siginfo *sa, void *uc) { @@ -232,7 +233,7 @@ static void Setup(void) { tyn = 80; txn = 24; action = RESIZED; - ioctl(out, TCGETS, &oldterm); + tcgetattr(out, &oldterm); HideCursor(); EnableRaw(); EnableMouse(); diff --git a/tool/viz/printansi.c b/tool/viz/printansi.c index 397f4320a..8b771d4cf 100644 --- a/tool/viz/printansi.c +++ b/tool/viz/printansi.c @@ -26,6 +26,7 @@ #include "libc/calls/ioctl.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/dce.h" #include "libc/fmt/conv.h" #include "libc/intrin/bits.h" @@ -174,8 +175,8 @@ static void GetOpts(int *argc, char *argv[]) { if (!g_flags.full && (!g_flags.width || !g_flags.width)) { ws.ws_col = 80; ws.ws_row = 24; - if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1 || - ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1) { + if (tcgetwinsize(STDIN_FILENO, &ws) != -1 || + tcgetwinsize(STDOUT_FILENO, &ws) != -1) { g_flags.width = ws.ws_col * (1 + !g_flags.half); g_flags.height = ws.ws_row * 2; } diff --git a/tool/viz/printimage.c b/tool/viz/printimage.c index b95533243..862abe5f6 100644 --- a/tool/viz/printimage.c +++ b/tool/viz/printimage.c @@ -25,6 +25,7 @@ #include "libc/calls/ioctl.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/winsize.h" +#include "libc/calls/termios.h" #include "libc/dce.h" #include "libc/fmt/conv.h" #include "libc/log/check.h" @@ -177,8 +178,8 @@ static void GetOpts(int *argc, char *argv[]) { g_winsize.ws_col = 80; g_winsize.ws_row = 24; if (!g_flags.full && (!g_flags.width || !g_flags.height)) { - ioctl(STDIN_FILENO, TIOCGWINSZ, &g_winsize) != -1 || - ioctl(STDOUT_FILENO, TIOCGWINSZ, &g_winsize); + tcgetwinsize(STDIN_FILENO, &g_winsize) != -1 || + tcgetwinsize(STDOUT_FILENO, &g_winsize); } ttyquantsetup(g_flags.quant, kTtyQuantRgb, g_flags.blocks); } diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index 83b078e10..f306b9f3c 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -428,7 +428,9 @@ static void DimensionDisplay(void) { wsize_.ws_row = 25; wsize_.ws_col = 80; wsize_ = (struct winsize){.ws_row = 40, .ws_col = 80}; - if (_getttysize(outfd_, &wsize_) == -1) _getttysize(0, &wsize_); + if (tcgetwinsize(outfd_, &wsize_) == -1) { + tcgetwinsize(0, &wsize_); + } dh_ = wsize_.ws_row * 2; dw_ = wsize_.ws_col * 2; }