diff --git a/Makefile b/Makefile index 624be011..fb4832a8 100644 --- a/Makefile +++ b/Makefile @@ -187,6 +187,7 @@ include test/libc/rand/test.mk include test/libc/time/test.mk include test/libc/stdio/test.mk include test/libc/conv/test.mk +include test/libc/release/test.mk include test/libc/test.mk include test/ape/lib/test.mk include test/ape/test.mk @@ -253,8 +254,9 @@ COSMOPOLITAN_OBJECTS = \ LIBC_CONV \ LIBC_CRYPTO \ LIBC_DNS \ - LIBC_FMT \ LIBC_ELF \ + LIBC_FMT \ + LIBC_INTRIN \ LIBC_LOG \ LIBC_MEM \ LIBC_NEXGEN32E \ @@ -270,7 +272,9 @@ COSMOPOLITAN_OBJECTS = \ LIBC_TIME \ LIBC_TINYMATH \ LIBC_UNICODE \ + LIBC_X \ LIBC_ZIPOS \ + THIRD_PARTY_COMPILER_RT \ THIRD_PARTY_DLMALLOC \ THIRD_PARTY_DTOA \ THIRD_PARTY_GETOPT \ @@ -279,22 +283,31 @@ COSMOPOLITAN_OBJECTS = \ COSMOPOLITAN_HEADERS = \ LIBC \ + LIBC_ALG \ + LIBC_BITS \ LIBC_CALLS \ LIBC_CONV \ LIBC_CRYPTO \ LIBC_DNS \ + LIBC_ELF \ LIBC_FMT \ + LIBC_INTRIN \ + LIBC_LOG \ LIBC_MEM \ + LIBC_NEXGEN32E \ + LIBC_NT \ + LIBC_OHMYPLUS \ LIBC_RAND \ LIBC_RUNTIME \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_TIME \ - LIBC_UNICODE \ - LIBC_ZIPOS \ LIBC_SYSV \ - LIBC_NT \ + LIBC_TIME \ + LIBC_TINYMATH \ + LIBC_UNICODE \ + LIBC_X \ + LIBC_ZIPOS \ THIRD_PARTY_DLMALLOC \ THIRD_PARTY_DTOA \ THIRD_PARTY_GETOPT \ @@ -302,11 +315,11 @@ COSMOPOLITAN_HEADERS = \ THIRD_PARTY_REGEX o/$(MODE)/cosmopolitan.a: $(filter-out o/libc/stubs/exit11.o,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_OBJS))) -o/$(MODE)/.cosmopolitan.h: $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS)) - build/rollup $^ >$@ -o/$(MODE)/cosmopolitan.h: o/$(MODE)/.cosmopolitan.h - build/compile $(PREPROCESS) -P $(OUTPUT_OPTION) $< - clang-format-10 -i $@ +o/cosmopolitan.h: \ + o/$(MODE)/tool/build/rollup.com.dbg \ + libc/integral/normalize.inc \ + $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS)) + @ACTION=ROLLUP TARGET=$@ build/do $^ >$@ # UNSPECIFIED PREREQUISITES TUTORIAL # diff --git a/ape/ape.S b/ape/ape.S index d1df16d5..38968aef 100644 --- a/ape/ape.S +++ b/ape/ape.S @@ -40,11 +40,10 @@ #include "ape/notice.inc" #include "ape/relocations.h" #include "libc/elf/def.h" -#include "libc/macho.h" -#include "libc/nexgen32e/uart.h" -#include "libc/nexgen32e/vidya.h" -#include "libc/nt/pedef.h" -#include "libc/nexgen32e/vidya.h" +#include "libc/macho.internal.h" +#include "libc/nexgen32e/uart.internal.h" +#include "libc/nexgen32e/vidya.internal.h" +#include "libc/nt/pedef.internal.h" #include "libc/dce.h" #include "libc/sysv/consts/prot.h" @@ -440,33 +439,6 @@ apmoff: mov $0x5300,%ax # apm installation check 1: call panic .endfn apmoff,globl -/ Video put char. -/ -/ @param al is the char -/ @mode real -rvputc: push %bx # don't clobber bp,bx,di,si,cx - push %bp # original ibm pc scroll up bug - mov $7,%bx # normal mda/cga style page zero - mov $0x0e,%ah # teletype output al cp437 - int $0x10 # vidya service - pop %bp # preserves al - pop %bx - ret - .endfn rvputc - -/ Video put string. -/ -/ @param di is the string -/ @mode real -rvputs: mov %di,%si -0: lodsb - test %al,%al - je 1f - call rvputc - jmp 0b -1: ret - .endfn rvputs,globl,hidden - /*───────────────────────────────────────────────────────────────────────────│─╗ │ αcτµαlly pδrταblε εxεcµταblε § partition table ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ @@ -1267,6 +1239,33 @@ sputs: push %bx ret .endfn sputs,globl +/ Video put string. +/ +/ @param di is the string +/ @mode real +rvputs: mov %di,%si +0: lodsb + test %al,%al + je 1f + rlcall rvputc + jmp 0b +1: ret + .endfn rvputs,globl,hidden + +/ Video put char. +/ +/ @param al is the char +/ @mode real +rvputc: push %bx # don't clobber bp,bx,di,si,cx + push %bp # original ibm pc scroll up bug + mov $7,%bx # normal mda/cga style page zero + mov $0x0e,%ah # teletype output al cp437 + int $0x10 # vidya service + pop %bp # preserves al + pop %bx + ret + .endfn rvputc + /* █ █▒ █ █ █▓▄ █ █ @@ -1613,8 +1612,8 @@ metal: mov $.Lape.bss.vaddr,%edi mov $.Lape.bss.memsz,%ecx rep stosb - .weak hostos - ezlea hostos,ax + .weak __hostos + ezlea __hostos,ax test %rax,%rax jz 1f movb $METAL,(%rax) diff --git a/ape/ape.lds b/ape/ape.lds index 046e1707..4feef395 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -177,7 +177,7 @@ #ifdef __LINKER__ #include "ape/macros.h" #include "ape/config.h" -#include "libc/nt/pedef.h" +#include "libc/nt/pedef.internal.h" #include "libc/zip.h" ENTRY(_start) diff --git a/ape/ape.mk b/ape/ape.mk index fdf6e144..529c0d1e 100644 --- a/ape/ape.mk +++ b/ape/ape.mk @@ -39,7 +39,7 @@ APE_DEPS = $(APE_LIB) APE_CHECKS = $(APE_HDRS:%=o/%.ok) o/ape/idata.inc: \ - ape/idata.h \ + ape/idata.internal.h \ ape/relocations.h $(APE_OBJS): $(BUILD_FILES) \ diff --git a/ape/config.h b/ape/config.h index 2451203a..b988bdec 100644 --- a/ape/config.h +++ b/ape/config.h @@ -38,7 +38,7 @@ /** * PC Display Configuration (MDA/CGA) * @see www.lammertbies.nl/comm/info/serial-uart.html - * @see ape/lib/vidya.h + * @see ape/lib/vidya.internal.h */ #ifndef VIDYA_MODE #define VIDYA_MODE VIDYA_MODE_CGA diff --git a/ape/idata.h b/ape/idata.internal.h similarity index 57% rename from ape/idata.h rename to ape/idata.internal.h index 89ba3192..7aac4b31 100644 --- a/ape/idata.h +++ b/ape/idata.internal.h @@ -1,22 +1,3 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef APE_IDATA_H_ #define APE_IDATA_H_ #ifdef __ASSEMBLER__ diff --git a/ape/lib/flattenhighmemory.c b/ape/lib/flattenhighmemory.c index 8c0d8416..54b0045e 100644 --- a/ape/lib/flattenhighmemory.c +++ b/ape/lib/flattenhighmemory.c @@ -20,7 +20,7 @@ #include "ape/config.h" #include "ape/lib/pc.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" /** * Virtualizes physical memory. diff --git a/ape/macros.h b/ape/macros.h index bb393b58..924c161a 100644 --- a/ape/macros.h +++ b/ape/macros.h @@ -1,38 +1,3 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╠──────────────────────────────────────────────────────────────────────────────╣ -│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀█░█▀█░▀█▀░█░█░█▀█░█░░░█░░░█░█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀█░█░▄░░█░░█░█░█▀█░█░░░█░░░▀█▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░▀░▀░▀▀▀░░▀░░▀▀▀░▀░▀░▀▀▀░▀▀▀░░▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀█░█▀█░█▀█░▀█▀░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀▀░█ █░██▀░░█░░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░▀░░░▀▀▀░▀░▀░░▀░░▀░▀░▀▀▀░▀▀▀░▀▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀▀░█░█░█▀▀░█▀█░█░█░▀█▀░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░▄▄░░░▐█░░│ -│░░░░░░░█▀▀░▄▀▄░█▀▀░█░▄░█░█░░█░░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░▄▄▄░░░▄██▄░░█▀░░░█░▄░│ -│░░░░░░░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░░▀░░▀░▀░▀▀▀░▀▀░▀▀▀░░░░░░░░░░▄██▀█▌░██▄▄░░▐█▀▄░▐█▀░░│ -│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▐█▀▀▌░░░▄▀▌░▌░█░▌░░▌░▌░░│ -╠──────────────────────────────────────────────────────▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄─│ -│ αcτµαlly pδrταblε εxεcµταblε § macros │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef APE_MACROS_H_ #define APE_MACROS_H_ #include "libc/macros.h" diff --git a/ape/mtime.h b/ape/mtime.h deleted file mode 100644 index 181a2e0c..00000000 --- a/ape/mtime.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef COSMOPOLITAN_APE_MTIME_H_ -#define COSMOPOLITAN_APE_MTIME_H_ -#include "libc/dos.h" - -/** - * @fileoverview Deterministic last modified timestamp embedding. - */ - -#ifndef MTIME_YEAR -#define MTIME_YEAR 2019 -#endif - -#ifndef MTIME_MONTH -#define MTIME_MONTH 1 -#endif - -#ifndef MTIME_DAY -#define MTIME_DAY 1 -#endif - -#ifndef MTIME_HOUR -#define MTIME_HOUR 0 -#endif - -#ifndef MTIME_MINUTES -#define MTIME_MINUTES 0 -#endif - -#ifndef MTIME_SECONDS -#define MTIME_SECONDS 0 -#endif - -#ifndef ZIP_MTIME_DATE -#define ZIP_MTIME_DATE DOS_DATE(MTIME_YEAR, MTIME_MONTH, MTIME_DAY) -#endif - -#ifndef ZIP_MTIME_TIME -#define ZIP_MTIME_TIME DOS_TIME(MTIME_HOUR, MTIME_MINUTES, MTIME_SECONDS) -#endif - -#endif /* COSMOPOLITAN_APE_MTIME_H_ */ diff --git a/build/definitions.mk b/build/definitions.mk index 139f213e..feafcd24 100644 --- a/build/definitions.mk +++ b/build/definitions.mk @@ -383,5 +383,5 @@ TAGSFLAGS = \ --if0=no \ --langmap=c:.c.h.i \ --line-directives=yes \ - --exclude=libc/nt/struct/imagefileheader.h \ + --exclude=libc/nt/struct/imagefileheader.internal.h \ --exclude=libc/nt/struct/filesegmentelement.h diff --git a/build/htags b/build/htags index 6ce02de7..401097cd 100755 --- a/build/htags +++ b/build/htags @@ -59,13 +59,13 @@ set -- --regex-c='/^extern [^(]*(\*const \([^)]*\))(/\1/b' "$@" # struct WorstSoftwareEver; set -- --regex-c='/^struct.*;$/uehocruehcroue/b' "$@" -exec ${TAGS:-ctags} \ - -e \ - --langmap=c:.c.h \ - --exclude=libc/nt/struct/imagefileheader.h \ - --exclude=libc/nt/struct/imageseparatedebugheader.h \ - --exclude=libc/nt/struct/importobjectheader.h \ - --exclude=libc/nt/struct/nonpageddebuginfo.h \ - --exclude=libc/nt/struct/ansistring.h \ - --exclude=libc/nt/struct/filesegmentelement.h \ +exec ${TAGS:-ctags} \ + -e \ + --langmap=c:.c.h \ + --exclude=libc/nt/struct/imagefileheader.internal.h \ + --exclude=libc/nt/struct/imageseparatedebugheader.internal.h \ + --exclude=libc/nt/struct/importobjectheader.h \ + --exclude=libc/nt/struct/nonpageddebuginfo.h \ + --exclude=libc/nt/struct/ansistring.h \ + --exclude=libc/nt/struct/filesegmentelement.h \ "$@" diff --git a/dsp/core/gamma.c b/dsp/core/gamma.c index a220d931..b01bdd91 100644 --- a/dsp/core/gamma.c +++ b/dsp/core/gamma.c @@ -24,6 +24,7 @@ double rgb2stdpc(double x, double g) { return COMPANDLUMA_SRGB(x, g); } + double rgb2linpc(double x, double g) { return UNCOMPANDLUMA_SRGB(x, g); } @@ -31,6 +32,7 @@ double rgb2linpc(double x, double g) { double rgb2stdtv(double x) { return COMPANDLUMA_BT1886(x); } + double rgb2lintv(double x) { return UNCOMPANDLUMA_BT1886(x); } diff --git a/dsp/core/scalevolume.c b/dsp/core/scalevolume.c index 8dceb97c..c7f9e656 100644 --- a/dsp/core/scalevolume.c +++ b/dsp/core/scalevolume.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/limits.h" /** @@ -43,7 +43,7 @@ void scalevolume(size_t n, int16_t pcm[n][8], int p) { if (p > 15) p = 15; for (i = 0; i < n; ++i) { for (j = 0; j < 8; ++j) { - pcm[i][j] = SAR(pcm[i][j], p); + pcm[i][j] = pcm[i][j] >> p; } } } diff --git a/dsp/mpeg/mpeg1.c b/dsp/mpeg/mpeg1.c index 968ccb38..5b8a5e2f 100644 --- a/dsp/mpeg/mpeg1.c +++ b/dsp/mpeg/mpeg1.c @@ -32,7 +32,7 @@ #include "dsp/mpeg/idct.h" #include "dsp/mpeg/mpeg.h" #include "dsp/mpeg/video.h" -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/conv/conv.h" #include "libc/log/log.h" #include "libc/macros.h" diff --git a/dsp/scale/magikarp.c b/dsp/scale/magikarp.c index 6989ccdc..48289d2b 100644 --- a/dsp/scale/magikarp.c +++ b/dsp/scale/magikarp.c @@ -40,8 +40,8 @@ signed char g_magikarp[8]; const signed char kMagikarp[8][8] = { {-1, -3, 3, 17, 17, 3, -3, -1}, /* 1331+161 derived w/ one off cas */ - {-1, -3, 6, 28, 6, -3, -1, 0}, /* due to the convolution theorem? */ - {0, 0, -11, 53, -11, 0, 0, 0}, /* plus, some random experimenting */ + {-1, -3, 6, 28, 6, -3, -1, 0}, /* no due to the convolution theorem? */ + {0, 0, -11, 53, -11, 0, 0, 0}, /* no plus, some random experimenting */ {-2, -6, 2, 22, 22, 2, -6, -2}, /* one a line please clang-format? */ {-3, -9, 1, 27, 27, 1, -9, -3}, }; diff --git a/dsp/tty/ident.c b/dsp/tty/ident.c index ae986a69..988c83ff 100644 --- a/dsp/tty/ident.c +++ b/dsp/tty/ident.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/tty.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/calls/termios.h" diff --git a/dsp/tty/internal.h b/dsp/tty/internal.h index 02ea1d1d..a4d5390c 100644 --- a/dsp/tty/internal.h +++ b/dsp/tty/internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_DSP_TTY_INTERNAL_H_ #define COSMOPOLITAN_DSP_TTY_INTERNAL_H_ #include "dsp/tty/ttyrgb.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/dsp/tty/itoa8.c b/dsp/tty/itoa8.c index 6eb84f4b..82aabcc8 100644 --- a/dsp/tty/itoa8.c +++ b/dsp/tty/itoa8.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/itoa8.h" #include "libc/bits/bits.h" -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/str/str.h" struct Itoa8 kItoa8; diff --git a/dsp/tty/quant.h b/dsp/tty/quant.h index ea6ccf4c..d60e5f36 100644 --- a/dsp/tty/quant.h +++ b/dsp/tty/quant.h @@ -3,7 +3,7 @@ #include "dsp/tty/ttyrgb.h" #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/limits.h" #include "libc/str/str.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) diff --git a/dsp/tty/rgb2ansi.c b/dsp/tty/rgb2ansi.c index e0b3de01..0b124a0d 100644 --- a/dsp/tty/rgb2ansi.c +++ b/dsp/tty/rgb2ansi.c @@ -20,7 +20,7 @@ #include "dsp/core/core.h" #include "dsp/tty/quant.h" #include "libc/assert.h" -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/limits.h" #include "libc/log/log.h" #include "libc/macros.h" diff --git a/dsp/tty/rgb2ttyf2i.c b/dsp/tty/rgb2ttyf2i.c index de6cbf20..dffb724d 100644 --- a/dsp/tty/rgb2ttyf2i.c +++ b/dsp/tty/rgb2ttyf2i.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/quant.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" struct TtyRgb rgb2ttyf2i_(__m128 rgb) { __v4si i4; diff --git a/dsp/tty/sendtitle.c b/dsp/tty/sendtitle.c index 8cc51eda..559e43f6 100644 --- a/dsp/tty/sendtitle.c +++ b/dsp/tty/sendtitle.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/tty.h" -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/runtime/gc.h" #include "libc/x/x.h" diff --git a/dsp/tty/ttymove.c b/dsp/tty/ttymove.c index d685624b..549d0735 100644 --- a/dsp/tty/ttymove.c +++ b/dsp/tty/ttymove.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/itoa8.h" #include "dsp/tty/tty.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/limits.h" #include "libc/log/check.h" diff --git a/dsp/tty/ttyquant.c b/dsp/tty/ttyquant.c index f1b02ae4..dd8a264f 100644 --- a/dsp/tty/ttyquant.c +++ b/dsp/tty/ttyquant.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/internal.h" #include "dsp/tty/quant.h" -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/dce.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/dsp/tty/ttyraster.c b/dsp/tty/ttyraster.c index 6d64657c..93fe971c 100644 --- a/dsp/tty/ttyraster.c +++ b/dsp/tty/ttyraster.c @@ -24,7 +24,7 @@ #include "dsp/tty/windex.h" #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" diff --git a/examples/auto-launch-gdb-on-crash.c b/examples/auto-launch-gdb-on-crash.c index 7e665243..e91cda4c 100644 --- a/examples/auto-launch-gdb-on-crash.c +++ b/examples/auto-launch-gdb-on-crash.c @@ -32,13 +32,13 @@ * @see examples and reference material on using the asm() keyword * - libc/nexgen32e/bsf.h * - libc/nexgen32e/tzcnt.h - * - libc/nexgen32e/cpuid4.h - * - libc/nexgen32e/tinystrcmp.h + * - libc/nexgen32e/cpuid4.internal.h + * - libc/nexgen32e/tinystrcmp.internal.h * - https://gist.github.com/jart/fe8d104ef93149b5ba9b72912820282c */ int main(int argc, char *argv[]) { showcrashreports(); - asm("int3"); /* cf. die(), perror("msg"), abort(), exit(1), _Exit(1) */ + asm("int3"); /* cf. __die(), perror("msg"), abort(), exit(1), _Exit(1) */ return 0; } diff --git a/examples/backtrace.c b/examples/backtrace.c deleted file mode 100644 index 270c0259..00000000 --- a/examples/backtrace.c +++ /dev/null @@ -1,63 +0,0 @@ -#if 0 -/*─────────────────────────────────────────────────────────────────╗ -│ To the extent possible under law, Justine Tunney has waived │ -│ all copyright and related or neighboring rights to this file, │ -│ as it is written in the following disclaimers: │ -│ • http://unlicense.org/ │ -│ • http://creativecommons.org/publicdomain/zero/1.0/ │ -╚─────────────────────────────────────────────────────────────────*/ -#endif -#include "libc/calls/calls.h" -#include "libc/log/backtrace.h" -#include "libc/log/log.h" -#include "libc/mem/mem.h" -#include "libc/runtime/gc.h" -#include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" -#include "libc/stdio/stdio.h" -#include "libc/sysv/consts/fileno.h" - -/* - - Your executables will try to find the addr2line tool, which is needed - to decrypt gcc debug information, enabling backtraces like this: - - 0x0000000000403a7a: Hello at examples/backtrace.c:31 - 0x0000000000403ac3: World at examples/backtrace.c:38 - 0x0000000000401608: main at examples/backtrace.c:42 - 0x0000000000401379: _start at libc/crt/crt.S:61 - - If that doesn't work, then your αcτµαlly pδrταblε εxεcµταblε will use - its own builtin fallback solution: - - 0000ac2fa7e0 000000403a9b Hello+0x49 - 0000ac2fa7f0 000000403ac4 World+0x22 - 0000ac2fa800 000000401609 main+0x7 - 0000ac2fa810 00000040137a _start+0x63 - - This is guaranteed to work if the .com.dbg file can be found. - Otherwise it'll print numbers: - - 0000268a8390 000000403a90 (null)+0x403a8f - 0000268a83a0 000000403aef (null)+0x403aee - 0000268a83b0 0000004015fe (null)+0x4015fd - 0000268a83c0 00000040137a (null)+0x401379 - -*/ - -void hello(void) { - gc(malloc(1)); - ShowBacktrace(STDOUT_FILENO, NULL); - setenv("ADDR2LINE", "", true); - ShowBacktrace(STDOUT_FILENO, NULL); -} - -void world(void) { - gc(malloc(1)); - hello(); -} - -int main(int argc, char *argv[]) { - world(); - return 0; -} diff --git a/examples/cplusplus.cc b/examples/cplusplus.cc index a0885b14..c523eb10 100644 --- a/examples/cplusplus.cc +++ b/examples/cplusplus.cc @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -31,9 +31,15 @@ class Log { int *x_; }; -Log::Log() { x_ = new int[64]; } -Log::~Log() { delete x_; } -int *Log::x() { return x_; } +Log::Log() { + x_ = new int[64]; +} +Log::~Log() { + delete x_; +} +int *Log::x() { + return x_; +} class Log g_log; diff --git a/examples/ctrlc.c b/examples/ctrlc.c index 1fa699e6..fa3e79cb 100644 --- a/examples/ctrlc.c +++ b/examples/ctrlc.c @@ -9,7 +9,7 @@ #endif #include "libc/calls/calls.h" #include "libc/log/check.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/log.h" #include "libc/mem/mem.h" #include "libc/runtime/gc.h" diff --git a/examples/dinlerp.c b/examples/dinlerp.c index 067f9383..17f8141a 100644 --- a/examples/dinlerp.c +++ b/examples/dinlerp.c @@ -12,7 +12,7 @@ #include "dsp/scale/scale.h" #include "dsp/tty/itoa8.h" #include "dsp/tty/quant.h" -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/stat.h" diff --git a/examples/findprime.c b/examples/findprime.c index c2e7b323..b231f312 100644 --- a/examples/findprime.c +++ b/examples/findprime.c @@ -13,7 +13,7 @@ #include "libc/conv/conv.h" #include "libc/limits.h" #include "libc/log/check.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/log.h" #include "libc/math.h" #include "libc/runtime/runtime.h" diff --git a/examples/gui.c b/examples/gui.c index 291f38fb..5e373dec 100644 --- a/examples/gui.c +++ b/examples/gui.c @@ -7,7 +7,7 @@ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ #endif -#include "libc/nt/enum/messageboxtype.h" +#include "libc/nt/enum/mb.h" #include "libc/nt/messagebox.h" int main(int argc, char *argv[]) { diff --git a/examples/ispell.c b/examples/ispell.c index ed7ab73f..95d8e9be 100644 --- a/examples/ispell.c +++ b/examples/ispell.c @@ -8,7 +8,8 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "libc/alg/alg.h" -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" +#include "libc/alg/critbit0.h" #include "libc/bits/bits.h" #include "libc/calls/calls.h" #include "libc/conv/conv.h" @@ -18,7 +19,7 @@ #include "libc/mem/mem.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" #include "libc/sysv/consts/fileno.h" #include "libc/x/x.h" diff --git a/examples/kilo.c b/examples/kilo.c index e8cfd0f3..0c475b7a 100644 --- a/examples/kilo.c +++ b/examples/kilo.c @@ -59,7 +59,7 @@ Contact: antirez@gmail.com\"\n\ #define _GNU_SOURCE #include "libc/alg/alg.h" -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/calls/calls.h" #include "libc/calls/termios.h" #include "libc/calls/weirdtypes.h" diff --git a/examples/lstime.c b/examples/lstime.c index 9d4ac753..ffeebfd3 100644 --- a/examples/lstime.c +++ b/examples/lstime.c @@ -8,8 +8,8 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "libc/alg/alg.h" -#include "libc/alg/arraylist2.h" -#include "libc/bits/safemacros.h" +#include "libc/alg/arraylist2.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/stat.h" diff --git a/examples/nesemu1.cc b/examples/nesemu1.cc index 20403b74..5de68076 100644 --- a/examples/nesemu1.cc +++ b/examples/nesemu1.cc @@ -10,10 +10,10 @@ #include "dsp/tty/itoa8.h" #include "dsp/tty/quant.h" #include "dsp/tty/tty.h" -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" #include "libc/calls/struct/itimerval.h" diff --git a/examples/now.c b/examples/now.c index eeaa0022..424708c9 100644 --- a/examples/now.c +++ b/examples/now.c @@ -8,7 +8,7 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/dce.h" #include "libc/stdio/stdio.h" diff --git a/examples/printargs.c b/examples/printargs.c index eae6b7d3..1028bc36 100644 --- a/examples/printargs.c +++ b/examples/printargs.c @@ -7,7 +7,7 @@ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ #endif -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/log/log.h" #include "libc/macros.h" #include "libc/runtime/runtime.h" diff --git a/examples/printmysymbols.c b/examples/printmysymbols.c deleted file mode 100644 index 16869424..00000000 --- a/examples/printmysymbols.c +++ /dev/null @@ -1,36 +0,0 @@ -#if 0 -/*─────────────────────────────────────────────────────────────────╗ -│ To the extent possible under law, Justine Tunney has waived │ -│ all copyright and related or neighboring rights to this file, │ -│ as it is written in the following disclaimers: │ -│ • http://unlicense.org/ │ -│ • http://creativecommons.org/publicdomain/zero/1.0/ │ -╚─────────────────────────────────────────────────────────────────*/ -#endif -#include "libc/calls/calls.h" -#include "libc/elf/elf.h" -#include "libc/log/backtrace.h" -#include "libc/log/log.h" -#include "libc/runtime/symbols.h" -#include "libc/stdio/stdio.h" -#include "libc/sysv/consts/fileno.h" - -int main(int argc, char *argv[]) { - int rc = 0; - char *filename; - struct SymbolTable *tab = NULL; - if ((filename = FindDebugBinary()) != NULL && - (tab = OpenSymbolTable(filename))) { - for (unsigned i = 0; i < tab->count; ++i) { - printf("%p %s\n", tab->addr_base + tab->symbols[i].addr_rva, - GetElfString(tab->elf, tab->elfsize, tab->name_base, - tab->symbols[i].name_rva)); - } - } else { - perror("printmysymbols"); - ShowBacktrace(STDERR_FILENO, NULL); - rc = 1; - } - CloseSymbolTable(&tab); - return rc; -} diff --git a/libc/alg/alg.h b/libc/alg/alg.h index 207ce403..e8f9d7fc 100644 --- a/libc/alg/alg.h +++ b/libc/alg/alg.h @@ -12,7 +12,7 @@ void *bsearch(const void *, const void *, size_t, size_t, void *bsearch_r(const void *, const void *, size_t, size_t, int cmp(const void *, const void *, void *), void *) paramsnonnull((1, 2, 5)) nothrow nosideeffect; -void djbsort(size_t n, int32_t[n]); +void djbsort(int32_t *, size_t); void qsort(void *, size_t, size_t, int (*)(const void *, const void *)) paramsnonnull(); void qsort_r(void *, size_t, size_t, @@ -43,72 +43,14 @@ char16_t *concatstr16(const char16_t *, ...) nullterminated() wchar_t *concatwcs(const wchar_t *, ...) nullterminated() paramsnonnull() __algalloc; -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § algorithms » containers ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -struct critbit0 { - void *root; - size_t count; -}; - -bool critbit0_contains(struct critbit0 *, const char *) nothrow nosideeffect - paramsnonnull(); -bool critbit0_insert(struct critbit0 *, const char *) paramsnonnull(); -bool critbit0_delete(struct critbit0 *, const char *) nothrow paramsnonnull(); -void critbit0_clear(struct critbit0 *) nothrow paramsnonnull(); -char *critbit0_get(struct critbit0 *, const char *); -intptr_t critbit0_allprefixed(struct critbit0 *, const char *, - intptr_t (*)(const char *, void *), void *) - paramsnonnull((1, 2, 3)) nothrow; -bool critbit0_emplace(struct critbit0 *, char *, size_t) paramsnonnull(); - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § algorithms » comparators ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -int cmpsb(/*const signed char[1]*/ const void *, const void *) - paramsnonnull() nothrow nocallback nosideeffect; -int cmpub(/*const unsigned char[1]*/ const void *, const void *) - paramsnonnull() nothrow nocallback nosideeffect; -int cmpsw(/*const signed short[1]*/ const void *, const void *) - paramsnonnull() nothrow nocallback nosideeffect; -int cmpuw(/*const unsigned short[1]*/ const void *, const void *) - paramsnonnull() nothrow nocallback nosideeffect; -int cmpsl(/*const signed int[1]*/ const void *, const void *) - paramsnonnull() nothrow nocallback nosideeffect; -int cmpul(/*const unsigned int[1]*/ const void *, const void *) - paramsnonnull() nothrow nocallback nosideeffect; -int cmpsq(/*const signed long[1]*/ const void *, const void *) - paramsnonnull() nothrow nocallback nosideeffect; -int cmpuq(/*const unsigned long[1]*/ const void *, const void *) - paramsnonnull() nothrow nocallback nosideeffect; - -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § algorithms » generics ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -#if __STDC_VERSION__ + 0 >= 201112 - -#define memmem(haystack, haystacklen, needle, needlelen) \ - _Generic(*(haystack), wchar_t \ - : wmemmem, char16_t \ - : memmem16, default \ - : memmem)(haystack, haystacklen, needle, needlelen) - -#define replacestr(s, needle, replacement) \ - _Generic(*(s), wchar_t \ - : replacewcs, char16_t \ - : replacestr16, default \ - : replacestr)(s, needle, replacement) - -#define concatstr(s, ...) \ - _Generic(*(s), wchar_t \ - : concatwcs, char16_t \ - : concatstr16, default \ - : concatstr)(s, __VA_ARGS__) - -#endif /* C11 */ +int cmpsb(const void *, const void *); +int cmpub(const void *, const void *); +int cmpsw(const void *, const void *); +int cmpuw(const void *, const void *); +int cmpsl(const void *, const void *); +int cmpul(const void *, const void *); +int cmpsq(const void *, const void *); +int cmpuq(const void *, const void *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/alg/arraylist.h b/libc/alg/arraylist.internal.h similarity index 88% rename from libc/alg/arraylist.h rename to libc/alg/arraylist.internal.h index 765e257a..6012fe50 100644 --- a/libc/alg/arraylist.h +++ b/libc/alg/arraylist.internal.h @@ -28,20 +28,20 @@ #define append(ARRAYLIST, ITEM) concat((ARRAYLIST), (ITEM), 1) -#define concat(ARRAYLIST, ITEM, COUNT) \ - ({ \ - autotype(ARRAYLIST) List = (ARRAYLIST); \ - autotype(&List->p[0]) Item = (ITEM); \ - size_t SizE = sizeof(*Item); \ - size_t Count = (COUNT); \ - size_t Idx = List->i; \ - if (Idx + Count < List->n || grow(&List->p, &List->n, SizE, Count)) { \ - memcpy(&List->p[Idx], Item, SizE *Count); \ - atomic_store(&List->i, Idx + Count); \ - } else { \ - Idx = -1UL; \ - } \ - (ssize_t)(Idx); \ +#define concat(ARRAYLIST, ITEM, COUNT) \ + ({ \ + autotype(ARRAYLIST) List = (ARRAYLIST); \ + autotype(&List->p[0]) Item = (ITEM); \ + size_t SizE = sizeof(*Item); \ + size_t Count = (COUNT); \ + size_t Idx = List->i; \ + if (Idx + Count < List->n || __grow(&List->p, &List->n, SizE, Count)) { \ + memcpy(&List->p[Idx], Item, SizE *Count); \ + atomic_store(&List->i, Idx + Count); \ + } else { \ + Idx = -1UL; \ + } \ + (ssize_t)(Idx); \ }) #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/alg/arraylist2.h b/libc/alg/arraylist2.internal.h similarity index 86% rename from libc/alg/arraylist2.h rename to libc/alg/arraylist2.internal.h index 9ad045bc..b78008ec 100644 --- a/libc/alg/arraylist2.h +++ b/libc/alg/arraylist2.internal.h @@ -10,26 +10,26 @@ COSMOPOLITAN_C_START_ #define APPEND(LIST_P, LIST_I, LIST_N, ITEM) \ CONCAT(LIST_P, LIST_I, LIST_N, ITEM, 1) -#define CONCAT(LIST_P, LIST_I, LIST_N, ITEM, COUNT) \ - ({ \ - autotype(LIST_P) ListP = (LIST_P); \ - autotype(LIST_I) ListI = (LIST_I); \ - autotype(LIST_N) ListN = (LIST_N); \ - typeof(&(*ListP)[0]) Item = (ITEM); \ - size_t SizE = sizeof(*Item); \ - size_t Count = (COUNT); \ - ssize_t Entry = -1; \ - /* NOTE: We use `<` to guarantee one additional slot */ \ - /* grow() will memset(0) extended memory, thus */ \ - /* you get a nul-terminator for free sometimes */ \ - /* the exception is if you list.i=0 and re-use */ \ - /* so you need concat(...); list.p[list.i++]=0 */ \ - if (*ListI + Count < *ListN || grow(ListP, ListN, SizE, Count)) { \ - memcpy(&(*ListP)[*ListI], Item, (SizE) * (Count)); \ - Entry = *ListI; \ - *ListI += Count; /* happens after copy in case signal */ \ - } \ - Entry; \ +#define CONCAT(LIST_P, LIST_I, LIST_N, ITEM, COUNT) \ + ({ \ + autotype(LIST_P) ListP = (LIST_P); \ + autotype(LIST_I) ListI = (LIST_I); \ + autotype(LIST_N) ListN = (LIST_N); \ + typeof(&(*ListP)[0]) Item = (ITEM); \ + size_t SizE = sizeof(*Item); \ + size_t Count = (COUNT); \ + ssize_t Entry = -1; \ + /* NOTE: We use `<` to guarantee one additional slot */ \ + /* grow() will memset(0) extended memory, thus */ \ + /* you get a nul-terminator for free sometimes */ \ + /* the exception is if you list.i=0 and re-use */ \ + /* so you need concat(...); list.p[list.i++]=0 */ \ + if (*ListI + Count < *ListN || __grow(ListP, ListN, SizE, Count)) { \ + memcpy(&(*ListP)[*ListI], Item, (SizE) * (Count)); \ + Entry = *ListI; \ + *ListI += Count; /* happens after copy in case signal */ \ + } \ + Entry; \ }) COSMOPOLITAN_C_END_ diff --git a/libc/alg/bisect.h b/libc/alg/bisect.internal.h similarity index 100% rename from libc/alg/bisect.h rename to libc/alg/bisect.internal.h diff --git a/libc/alg/bisectcarleft.h b/libc/alg/bisectcarleft.internal.h similarity index 72% rename from libc/alg/bisectcarleft.h rename to libc/alg/bisectcarleft.internal.h index 9c7627fc..7c4c9b3c 100644 --- a/libc/alg/bisectcarleft.h +++ b/libc/alg/bisectcarleft.internal.h @@ -3,13 +3,8 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -/** - * Floor binary search of low 32-bits of 64-bit array items. - * - * This is well-suited to NexGen-32e, requiring less than 32 bytes of - * code. It's particularly useful for frozen maps, requiring less effort - * and memory than a perfect hash table. - */ +/* TODO: DELETE */ + forceinline int32_t bisectcarleft(const int32_t (*cons)[2], size_t count, const int32_t key) { size_t left = 0; diff --git a/libc/alg/bisectleft.h b/libc/alg/bisectleft.h deleted file mode 100644 index d59b289f..00000000 --- a/libc/alg/bisectleft.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_ -#define COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -forceinline size_t bisectleft(const void *key, const void *base, size_t count, - size_t sz, int cmp(const void *, const void *)) { - size_t m, l, r; - l = 0; - r = count; - while (l < r) { - m = (l + r) >> 1; - if (cmp((char *)base + m * sz, key) < 0) { - l = m + 1; - } else { - r = m; - } - } - if (l && (l == count || cmp((char *)base + l * sz, key) > 0)) { - l--; - } - return l; -} - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_ */ diff --git a/libc/alg/bisectright.h b/libc/alg/bisectright.h deleted file mode 100644 index 1f1df38c..00000000 --- a/libc/alg/bisectright.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_ -#define COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -forceinline size_t bisectright(const void *key, const void *base, size_t count, - size_t sz, int cmp(const void *, const void *)) { - size_t left = 0; - size_t right = count; - while (left < right) { - size_t m = (right + right) >> 1; - if (cmp((char *)base + m * sz, key) > 0) { - right = m + 1; - } else { - right = m; - } - } - if (right && (right == count || cmp((char *)base + right * sz, key) > 0)) { - right--; - } - return right; -} - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_ */ diff --git a/libc/alg/bsearch.c b/libc/alg/bsearch.c index b048d485..4b607d7f 100644 --- a/libc/alg/bsearch.c +++ b/libc/alg/bsearch.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/bisect.h" +#include "libc/alg/bisect.internal.h" /** * Searches sorted array for exact item in logarithmic time. diff --git a/libc/alg/bsearch_r.c b/libc/alg/bsearch_r.c index d08be198..7083f89f 100644 --- a/libc/alg/bsearch_r.c +++ b/libc/alg/bsearch_r.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/bisect.h" +#include "libc/alg/bisect.internal.h" /** * Searches sorted array for exact item in logarithmic time. diff --git a/libc/alg/critbit0.h b/libc/alg/critbit0.h new file mode 100644 index 00000000..ddacc991 --- /dev/null +++ b/libc/alg/critbit0.h @@ -0,0 +1,27 @@ +#ifndef COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_ +#define COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § data structures » critical bit tree (for c strings) ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + +struct critbit0 { + void *root; + size_t count; +}; + +bool critbit0_contains(struct critbit0 *, const char *) nothrow nosideeffect + paramsnonnull(); +bool critbit0_insert(struct critbit0 *, const char *) paramsnonnull(); +bool critbit0_delete(struct critbit0 *, const char *) nothrow paramsnonnull(); +void critbit0_clear(struct critbit0 *) nothrow paramsnonnull(); +char *critbit0_get(struct critbit0 *, const char *); +intptr_t critbit0_allprefixed(struct critbit0 *, const char *, + intptr_t (*)(const char *, void *), void *) + paramsnonnull((1, 2, 3)) nothrow; +bool critbit0_emplace(struct critbit0 *, char *, size_t) paramsnonnull(); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_ */ diff --git a/libc/alg/critbit0_allprefixed.c b/libc/alg/critbit0_allprefixed.c index 97bbc154..11b78d3b 100644 --- a/libc/alg/critbit0_allprefixed.c +++ b/libc/alg/critbit0_allprefixed.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/alg.h" +#include "libc/alg/critbit0.h" #include "libc/alg/internal.h" #include "libc/str/str.h" diff --git a/libc/alg/critbit0_clear.c b/libc/alg/critbit0_clear.c index ca83f78f..e8c54f12 100644 --- a/libc/alg/critbit0_clear.c +++ b/libc/alg/critbit0_clear.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/alg.h" +#include "libc/alg/critbit0.h" #include "libc/alg/internal.h" #include "libc/mem/mem.h" diff --git a/libc/alg/critbit0_contains.c b/libc/alg/critbit0_contains.c index c43b7225..5a2846a7 100644 --- a/libc/alg/critbit0_contains.c +++ b/libc/alg/critbit0_contains.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/alg.h" +#include "libc/alg/critbit0.h" #include "libc/alg/internal.h" #include "libc/str/str.h" diff --git a/libc/alg/critbit0_delete.c b/libc/alg/critbit0_delete.c index d321b167..6308fff0 100644 --- a/libc/alg/critbit0_delete.c +++ b/libc/alg/critbit0_delete.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/alg.h" +#include "libc/alg/critbit0.h" #include "libc/alg/internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/libc/alg/critbit0_emplace.c b/libc/alg/critbit0_emplace.c index 6d5f3f99..cb8b072f 100644 --- a/libc/alg/critbit0_emplace.c +++ b/libc/alg/critbit0_emplace.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/alg.h" +#include "libc/alg/critbit0.h" #include "libc/alg/internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/libc/alg/critbit0_get.c b/libc/alg/critbit0_get.c index 3db2b388..2d646ebe 100644 --- a/libc/alg/critbit0_get.c +++ b/libc/alg/critbit0_get.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/alg.h" +#include "libc/alg/critbit0.h" #include "libc/alg/internal.h" #include "libc/str/str.h" diff --git a/libc/alg/critbit0_insert.c b/libc/alg/critbit0_insert.c index 70fed8e1..2e0bc4f7 100644 --- a/libc/alg/critbit0_insert.c +++ b/libc/alg/critbit0_insert.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/alg.h" +#include "libc/alg/critbit0.h" #include "libc/alg/internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/libc/alg/insertionsort.h b/libc/alg/insertionsort.h deleted file mode 100644 index 97c37bd7..00000000 --- a/libc/alg/insertionsort.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_ALG_INSERTIONSORT_H_ -#define COSMOPOLITAN_LIBC_ALG_INSERTIONSORT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) - -#define siftbackwards(C, X, V, i) \ - do { \ - autotype(V) V_ = (V); \ - for (autotype(i) j = (i); j && C(&V_[j - 1], &V_[j]) > 0; --j) { \ - X(&V_[j - 1], &V_[j]); \ - } \ - } while (0) - -#if 0 -/** - * Tiny in-place quadratic sorting algorithm. - * - * The only advantage to insertion sort is saving on code size when - * there's a strong level of certainty the array won't have more than - * sixteen items. Sometimes Insertion Sort is favored for sorting data - * that's almost sorted. SmoothSort should be a better choice (see - * qsort()) since it has that advantage and a linearithmic worst-case. - */ -#endif -#define INSERTIONSORT(C, X, A, n) \ - do { \ - autotype(A) A_ = (A); \ - autotype(n) n_ = (n); \ - for (autotype(n) i = 1; i < n_; ++i) { \ - siftbackwards(C, X, A_, i); \ - } \ - } while (0) - -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_ALG_INSERTIONSORT_H_ */ diff --git a/libc/alg/replacestr.c b/libc/alg/replacestr.c index cfea0654..fd9ec2fc 100644 --- a/libc/alg/replacestr.c +++ b/libc/alg/replacestr.c @@ -18,8 +18,8 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist2.h" -#include "libc/bits/safemacros.h" +#include "libc/alg/arraylist2.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" diff --git a/libc/alg/replacestr16.c b/libc/alg/replacestr16.c index 751b36f2..dc875764 100644 --- a/libc/alg/replacestr16.c +++ b/libc/alg/replacestr16.c @@ -18,14 +18,15 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist2.h" -#include "libc/bits/safemacros.h" +#include "libc/alg/arraylist2.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" #undef strlen #undef replacestr #define replacestr replacestr16 +#define memmem memmem16 #define char char16_t #define strlen strlen16 #include "libc/alg/replacestr.c" diff --git a/libc/alg/reverse.h b/libc/alg/reverse.h index 84277731..a782ec7f 100644 --- a/libc/alg/reverse.h +++ b/libc/alg/reverse.h @@ -3,16 +3,14 @@ #include "libc/bits/xchg.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) -#if 0 /** * Reverses array. * - * @param ARRAY is a typed array or a pointer to one + * @param ARRAY is a typed array or a pointer to one * @param COUNT is the number of items * @return pointer to start of array * @see ARRAYLEN() */ -#endif #define reverse(ARRAY, COUNT) \ ({ \ autotype(&(ARRAY)[0]) Array = (ARRAY); \ diff --git a/libc/alg/shuffle.h b/libc/alg/shuffle.h index 0f68f710..43e55862 100644 --- a/libc/alg/shuffle.h +++ b/libc/alg/shuffle.h @@ -3,7 +3,6 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) #include "libc/bits/xchg.h" -#if 0 /** * Fisher-Yates shuffle. * @@ -12,7 +11,6 @@ * @param n is the number of items in A * @see ARRAYLEN() */ -#endif #define shuffle(R, A, n) \ do { \ autotype(A) Array = (A); \ diff --git a/libc/bits/avx2intrin.h b/libc/bits/avx2intrin.internal.h similarity index 99% rename from libc/bits/avx2intrin.h rename to libc/bits/avx2intrin.internal.h index 4af23783..2f3a45b6 100644 --- a/libc/bits/avx2intrin.h +++ b/libc/bits/avx2intrin.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_BITS_AVX2INTRIN_H_ #define COSMOPOLITAN_LIBC_BITS_AVX2INTRIN_H_ -#include "libc/bits/avxintrin.h" +#include "libc/bits/avxintrin.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/bits/avxintrin.h b/libc/bits/avxintrin.internal.h similarity index 100% rename from libc/bits/avxintrin.h rename to libc/bits/avxintrin.internal.h diff --git a/libc/bits/bigword.h b/libc/bits/bigword.h deleted file mode 100644 index 5db6a9a7..00000000 --- a/libc/bits/bigword.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_BITS_BIGWORD_H_ -#define COSMOPOLITAN_LIBC_BITS_BIGWORD_H_ - -#if 0 -/** - * Let BIGWORD be the the number of bytes in the largest cpu register - * available within the instruction set architecture requirements chosen - * at compile-time. - * - * In plainer terms, if you tune with flags like -mavx, you're not just - * giving the compiler permission to generate code that's incompatible - * with older computers; you're also asking Cosmopolitan to systemically - * change alignment, vectoring, buffering, ABIs, memory allocation, etc. - */ -#endif -#ifndef BIGWORD -#if __AVX512F__ + 0 -#define BIGWORD 64 -#elif __AVX2__ + 0 -#define BIGWORD 32 -#elif __SSE2__ + 0 -#define BIGWORD 16 -#else -#define BIGWORD __BIGGEST_ALIGNMENT__ -#endif -#endif /*BIGWORD*/ - -#endif /* COSMOPOLITAN_LIBC_BITS_BIGWORD_H_ */ diff --git a/libc/bits/bigword.internal.h b/libc/bits/bigword.internal.h new file mode 100644 index 00000000..4bf33dce --- /dev/null +++ b/libc/bits/bigword.internal.h @@ -0,0 +1,16 @@ +#ifndef COSMOPOLITAN_LIBC_BITS_BIGWORD_H_ +#define COSMOPOLITAN_LIBC_BITS_BIGWORD_H_ + +#ifndef BIGWORD +#if __AVX512F__ + 0 +#define BIGWORD 64 +#elif __AVX2__ + 0 +#define BIGWORD 32 +#elif __SSE2__ + 0 +#define BIGWORD 16 +#else +#define BIGWORD __BIGGEST_ALIGNMENT__ +#endif +#endif /*BIGWORD*/ + +#endif /* COSMOPOLITAN_LIBC_BITS_BIGWORD_H_ */ diff --git a/libc/bits/bitreverse16.S b/libc/bits/bitreverse16.c similarity index 85% rename from libc/bits/bitreverse16.S rename to libc/bits/bitreverse16.c index f39bd955..b6b44167 100644 --- a/libc/bits/bitreverse16.S +++ b/libc/bits/bitreverse16.c @@ -1,5 +1,5 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ @@ -17,15 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.h" +#include "libc/bits/bits.h" -bitreverse16: - push %rbx - mov %edi,%eax - mov $kReverseBits,%ebx - xlat - xchg %al,%ah - xlat - pop %rbx - ret - .endfn bitreverse16,globl +uint16_t(bitreverse16)(uint16_t x) { + return kReverseBits[x & 0x00FF] << 8 | kReverseBits[(x & 0xFF00) >> 8]; +} diff --git a/libc/bits/bitreverse8.S b/libc/bits/bitreverse8.c similarity index 84% rename from libc/bits/bitreverse8.S rename to libc/bits/bitreverse8.c index a59169d8..fdf3d9ca 100644 --- a/libc/bits/bitreverse8.S +++ b/libc/bits/bitreverse8.c @@ -1,5 +1,5 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ @@ -17,15 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.h" +#include "libc/bits/bits.h" -bitreverse8: - .leafprologue - .profilable - push %rbx - mov %edi,%eax - mov $kReverseBits,%ebx - xlat - pop %rbx - .leafepilogue - .endfn bitreverse8,globl +uint8_t(bitreverse8)(uint8_t x) { + return kReverseBits[x]; +} diff --git a/libc/bits/bits.h b/libc/bits/bits.h index a43606ab..6f631bfe 100644 --- a/libc/bits/bits.h +++ b/libc/bits/bits.h @@ -9,42 +9,26 @@ COSMOPOLITAN_C_START_ │ cosmopolitan § bits ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -extern const bool kTrue; -extern const bool kFalse; extern const uint8_t kReverseBits[256]; uint32_t gray(uint32_t) pureconst; uint32_t ungray(uint32_t) pureconst; -unsigned bcdadd(unsigned, unsigned) pureconst; -unsigned long bcd2i(unsigned long) pureconst; -unsigned long i2bcd(unsigned long) pureconst; -void bcxcpy(unsigned char (*)[16], unsigned long); -int ffs(int) pureconst; -int ffsl(long int) pureconst; -int ffsll(long long int) pureconst; -int fls(int) pureconst; -int flsl(long int) pureconst; -int flsll(long long int) pureconst; + uint8_t bitreverse8(uint8_t) libcesque pureconst; uint16_t bitreverse16(uint16_t) libcesque pureconst; uint32_t bitreverse32(uint32_t) libcesque pureconst; uint64_t bitreverse64(uint64_t) libcesque pureconst; + unsigned long roundup2pow(unsigned long) libcesque pureconst; unsigned long roundup2log(unsigned long) libcesque pureconst; unsigned long rounddown2pow(unsigned long) libcesque pureconst; + unsigned long hamming(unsigned long, unsigned long) pureconst; /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § bits » no assembly required ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -/** - * Undocumented incantations for ROR, ROL, and SAR. - */ -#define ROR(w, k) (CheckUnsigned(w) >> (k) | (w) << (sizeof(w) * 8 - (k))) -#define ROL(w, k) ((w) << (k) | CheckUnsigned(w) >> (sizeof(w) * 8 - (k))) -#define SAR(w, k) (((w) & ~(~0u >> (k))) | ((w) >> ((k) & (sizeof(w) * 8 - 1)))) - #define bitreverse8(X) (kReverseBits[(uint8_t)(X)]) #define bitreverse16(X) \ ((uint16_t)kReverseBits[(uint8_t)(X)] << 010 | \ @@ -253,49 +237,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; Val; \ }) -/** - * Returns true if bit is set in memory. - * - * This is a generically-typed Bitset ∀ RAM. This macro is intended - * to be container-like with optimal machine instruction encoding, cf. - * machine-agnostic container abstractions. Memory accesses are words. - * Register allocation can be avoided if BIT is known. Be careful when - * casting character arrays since that should cause a page fault. - * - * @param MEM is uint𝑘_t[] where 𝑘 ∈ {16,32,64} base address - * @param BIT ∈ [-(2**(𝑘-1)),2**(𝑘-1)) is zero-based index - * @return true if bit is set, otherwise false - * @see Intel's Six Thousand Page Manual V.2A 3-113 - * @see bts(), btr(), btc() - */ -#define bt(MEM, BIT) \ - ({ \ - bool OldBit; \ - if (isconstant(BIT)) { \ - asm(CFLAG_ASM("bt%z1\t%2,%1") \ - : CFLAG_CONSTRAINT(OldBit) \ - : "m"((MEM)[(BIT) / (sizeof((MEM)[0]) * CHAR_BIT)]), \ - "J"((BIT) % (sizeof((MEM)[0]) * CHAR_BIT)) \ - : "cc"); \ - } else if (sizeof((MEM)[0]) == 2) { \ - asm(CFLAG_ASM("bt\t%w2,%1") \ - : CFLAG_CONSTRAINT(OldBit) \ - : "m"((MEM)[0]), "r"(BIT) \ - : "cc"); \ - } else if (sizeof((MEM)[0]) == 4) { \ - asm(CFLAG_ASM("bt\t%k2,%1") \ - : CFLAG_CONSTRAINT(OldBit) \ - : "m"((MEM)[0]), "r"(BIT) \ - : "cc"); \ - } else if (sizeof((MEM)[0]) == 8) { \ - asm(CFLAG_ASM("bt\t%q2,%1") \ - : CFLAG_CONSTRAINT(OldBit) \ - : "m"((MEM)[0]), "r"(BIT) \ - : "cc"); \ - } \ - OldBit; \ - }) - #define bts(MEM, BIT) __BitOp("bts", BIT, MEM) /** bit test and set */ #define btr(MEM, BIT) __BitOp("btr", BIT, MEM) /** bit test and reset */ #define btc(MEM, BIT) __BitOp("btc", BIT, MEM) /** bit test and complement */ diff --git a/libc/bits/emmintrin.h b/libc/bits/emmintrin.internal.h similarity index 99% rename from libc/bits/emmintrin.h rename to libc/bits/emmintrin.internal.h index 0dd27258..b1a9bde7 100644 --- a/libc/bits/emmintrin.h +++ b/libc/bits/emmintrin.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_BITS_EMMINTRIN_H_ #define COSMOPOLITAN_LIBC_BITS_EMMINTRIN_H_ -#include "libc/bits/progn.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/progn.internal.h" +#include "libc/bits/xmmintrin.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) /*───────────────────────────────────────────────────────────────────────────│─╗ diff --git a/libc/bits/gray.c b/libc/bits/gray.c index cabfb123..f941c23b 100644 --- a/libc/bits/gray.c +++ b/libc/bits/gray.c @@ -17,14 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/bits.h" -uint32_t gray(uint32_t x) { return x ^ (x >> 1); } - -uint32_t ungray(uint32_t x) { - x ^= x >> 16; - x ^= x >> 8; - x ^= x >> 4; - x ^= x >> 2; - x ^= x >> 1; - return x; +uint32_t gray(uint32_t x) { + return x ^ (x >> 1); } diff --git a/libc/bits/i2bcd.S b/libc/bits/i2bcd.S deleted file mode 100644 index a33e56a0..00000000 --- a/libc/bits/i2bcd.S +++ /dev/null @@ -1,48 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.h" - -/ Converts integer to binary-coded decimal. -i2bcd: .leafprologue - .profilable - test %rdi,%rdi - je 2f - mov %rdi,%rsi - xor %r9d,%r9d - mov $0xcccccccccccccccd,%r8 - xor %ecx,%ecx -1: mov %rsi,%rax - mul %r8 - shr $3,%rdx - lea (%rdx,%rdx),%rax - lea (%rax,%rax,4),%rax - mov %rsi,%rdi - sub %rax,%rdi - shl %cl,%rdi - add %rdi,%r9 - add $4,%rcx - cmp $9,%rsi - mov %rdx,%rsi - ja 1b - jmp 3f -2: xor %r9d,%r9d -3: mov %r9,%rax - .leafepilogue - .endfn i2bcd,globl diff --git a/libc/bits/initializer.h b/libc/bits/initializer.internal.h similarity index 97% rename from libc/bits/initializer.h rename to libc/bits/initializer.internal.h index 901f7148..de6dd661 100644 --- a/libc/bits/initializer.h +++ b/libc/bits/initializer.internal.h @@ -2,6 +2,8 @@ #define COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) +/* TODO: DELETE */ + /** * Teleports code fragment inside _init(). */ diff --git a/libc/bits/mmintrin.h b/libc/bits/mmintrin.internal.h similarity index 100% rename from libc/bits/mmintrin.h rename to libc/bits/mmintrin.internal.h diff --git a/libc/bits/pmmintrin.h b/libc/bits/pmmintrin.internal.h similarity index 100% rename from libc/bits/pmmintrin.h rename to libc/bits/pmmintrin.internal.h diff --git a/libc/bits/progn.h b/libc/bits/progn.internal.h similarity index 100% rename from libc/bits/progn.h rename to libc/bits/progn.internal.h diff --git a/libc/bits/safemacros.h b/libc/bits/safemacros.internal.h similarity index 100% rename from libc/bits/safemacros.h rename to libc/bits/safemacros.internal.h diff --git a/libc/bits/shaintrin.h b/libc/bits/shaintrin.internal.h similarity index 95% rename from libc/bits/shaintrin.h rename to libc/bits/shaintrin.internal.h index 785f58d2..6d1ad0ce 100644 --- a/libc/bits/shaintrin.h +++ b/libc/bits/shaintrin.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_BITS_SHAINTRIN_H_ #define COSMOPOLITAN_LIBC_BITS_SHAINTRIN_H_ -#include "libc/bits/emmintrin.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/emmintrin.internal.h" +#include "libc/bits/xmmintrin.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) #define _mm_sha1rnds4_epu32(M128I_0, M128I_1, MEM) \ diff --git a/libc/bits/smmintrin.h b/libc/bits/smmintrin.internal.h similarity index 100% rename from libc/bits/smmintrin.h rename to libc/bits/smmintrin.internal.h diff --git a/libc/bits/tmmintrin.h b/libc/bits/tmmintrin.internal.h similarity index 96% rename from libc/bits/tmmintrin.h rename to libc/bits/tmmintrin.internal.h index 2b81e411..95d237cf 100644 --- a/libc/bits/tmmintrin.h +++ b/libc/bits/tmmintrin.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_BITS_TMMINTRIN_H_ #define COSMOPOLITAN_LIBC_BITS_TMMINTRIN_H_ -#include "libc/bits/emmintrin.h" +#include "libc/bits/emmintrin.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) /*───────────────────────────────────────────────────────────────────────────│─╗ diff --git a/libc/bits/typecheck.h b/libc/bits/typecheck.h deleted file mode 100644 index d6a240a7..00000000 --- a/libc/bits/typecheck.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_BITS_TYPECHECK_H_ -#define COSMOPOLITAN_LIBC_BITS_TYPECHECK_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) - -#define TYPECHECK(T, X) \ - ({ \ - T Lol1; \ - typeof(X) Lol2; \ - (void)(&Lol1 == &Lol2); \ - X; \ - }) - -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_BITS_TYPECHECK_H_ */ diff --git a/test/libc/conv/dosdatetimetounix_test.c b/libc/bits/ungray.c similarity index 84% rename from test/libc/conv/dosdatetimetounix_test.c rename to libc/bits/ungray.c index d01c7dc5..d37dc86f 100644 --- a/test/libc/conv/dosdatetimetounix_test.c +++ b/libc/bits/ungray.c @@ -17,16 +17,13 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/conv/conv.h" -#include "libc/dos.h" -#include "libc/testlib/testlib.h" +#include "libc/bits/bits.h" -TEST(DosDateTimeToUnix, test) { - EXPECT_EQ(1601929396, - DosDateTimeToUnix(DOS_DATE(2020, 10, 5), DOS_TIME(20, 23, 16))); -} - -TEST(DosDateTimeToUnix, testNotLeapYear) { - EXPECT_EQ(4107529396, - DosDateTimeToUnix(DOS_DATE(2100, 2, 28), DOS_TIME(20, 23, 16))); +uint32_t ungray(uint32_t x) { + x ^= x >> 16; + x ^= x >> 8; + x ^= x >> 4; + x ^= x >> 2; + x ^= x >> 1; + return x; } diff --git a/libc/bits/unsignedsubtract.c b/libc/bits/unsignedsubtract.c index e8ae3712..75788501 100644 --- a/libc/bits/unsignedsubtract.c +++ b/libc/bits/unsignedsubtract.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" /** * Subtracts unsigned integers w/ wraparound. diff --git a/libc/bits/wmmintrin.h b/libc/bits/wmmintrin.internal.h similarity index 96% rename from libc/bits/wmmintrin.h rename to libc/bits/wmmintrin.internal.h index f7520618..8bc5637a 100644 --- a/libc/bits/wmmintrin.h +++ b/libc/bits/wmmintrin.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_BITS_WMMINTRIN_H_ #define COSMOPOLITAN_LIBC_BITS_WMMINTRIN_H_ -#include "libc/bits/emmintrin.h" +#include "libc/bits/emmintrin.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) #define _mm_clmulepi64_si128(X, Y, IMM) \ diff --git a/libc/bits/xmmintrin.h b/libc/bits/xmmintrin.internal.h similarity index 98% rename from libc/bits/xmmintrin.h rename to libc/bits/xmmintrin.internal.h index 4c0d9d3c..ef48c169 100644 --- a/libc/bits/xmmintrin.h +++ b/libc/bits/xmmintrin.internal.h @@ -1,8 +1,8 @@ #ifndef COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_ #define COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_ -#include "libc/bits/emmintrin.h" -#include "libc/bits/mmintrin.h" -#include "libc/bits/progn.h" +#include "libc/bits/emmintrin.internal.h" +#include "libc/bits/mmintrin.internal.h" +#include "libc/bits/progn.internal.h" #include "libc/dce.h" #define _MM_EXCEPT_MASK 0x003f diff --git a/libc/calls/calls.h b/libc/calls/calls.h index ff0aa62e..0f4e3fca 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -226,7 +226,6 @@ uint32_t getsid(int) nosideeffect; uint32_t gettid(void) nosideeffect; uint32_t getuid(void) nosideeffect; uint32_t umask(int32_t); -void *getprocaddressmodule(const char *, const char *); #define getcwd(BUF, SIZE) \ (isconstant(BUF) && (&(BUF)[0] == NULL) ? get_current_dir_name() \ diff --git a/libc/calls/clock_gettime.c b/libc/calls/clock_gettime.c index 367c8a2e..659827fa 100644 --- a/libc/calls/clock_gettime.c +++ b/libc/calls/clock_gettime.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/struct/timespec.h" diff --git a/libc/calls/commandv.c b/libc/calls/commandv.c index 4b6cfab4..2bf22f78 100644 --- a/libc/calls/commandv.c +++ b/libc/calls/commandv.c @@ -17,14 +17,13 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/progn.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/conv/conv.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/nt/ntdll.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/ok.h" diff --git a/libc/calls/copyfd.c b/libc/calls/copyfd.c index c13ecaa2..0540263f 100644 --- a/libc/calls/copyfd.c +++ b/libc/calls/copyfd.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/errno.h" diff --git a/libc/calls/fprot2nt.c b/libc/calls/fprot2nt.c index 4eb0fe37..65d89d69 100644 --- a/libc/calls/fprot2nt.c +++ b/libc/calls/fprot2nt.c @@ -19,6 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/nt/enum/filemapflags.h" +#include "libc/nt/enum/pageflags.h" #include "libc/nt/memory.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" diff --git a/libc/calls/fstat-nt.c b/libc/calls/fstat-nt.c index b3d4c63c..2363cc7f 100644 --- a/libc/calls/fstat-nt.c +++ b/libc/calls/fstat-nt.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/internal.h" #include "libc/calls/struct/stat.h" #include "libc/conv/conv.h" @@ -32,8 +32,8 @@ #include "libc/sysv/consts/s.h" textwindows int fstat$nt(int64_t handle, struct stat *st) { + int filetype; uint64_t actualsize; - enum NtFileType filetype; struct NtByHandleFileInformation wst; struct NtFileCompressionInfo fci; if (GetFileInformationByHandle(handle, &wst)) { diff --git a/libc/calls/g_fds.c b/libc/calls/g_fds.c index 896004fe..b7685d69 100644 --- a/libc/calls/g_fds.c +++ b/libc/calls/g_fds.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/bits/pushpop.h" #include "libc/calls/internal.h" #include "libc/nt/runtime.h" diff --git a/libc/calls/getenv.c b/libc/calls/getenv.c index 1347c239..47795703 100644 --- a/libc/calls/getenv.c +++ b/libc/calls/getenv.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" diff --git a/libc/calls/getpid.c b/libc/calls/getpid.c index b4cd4958..ffc0bb43 100644 --- a/libc/calls/getpid.c +++ b/libc/calls/getpid.c @@ -22,21 +22,20 @@ #include "libc/calls/internal.h" #include "libc/dce.h" #include "libc/nt/process.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" static int g_pid; -static void __updatepid(void) { - g_pid = __getpid(); +static int __get_pid(void) { + if (!IsWindows()) { + return getpid$sysv(); + } else { + return GetCurrentProcessId(); + } } -int __getpid(void) { - if (!IsWindows()) { - return GETPID(); - } else { - return NtGetPid(); - } +static void __update_pid(void) { + g_pid = __get_pid(); } /** @@ -46,8 +45,8 @@ int __getpid(void) { int getpid(void) { static bool once; if (!once) { - __updatepid(); - atfork(__updatepid, NULL); + __update_pid(); + atfork(__update_pid, NULL); once = true; } return g_pid; diff --git a/libc/calls/getpriority-nt.c b/libc/calls/getpriority-nt.c index 15763f80..d383e52d 100644 --- a/libc/calls/getpriority-nt.c +++ b/libc/calls/getpriority-nt.c @@ -20,8 +20,9 @@ #include "libc/bits/bits.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/kntprioritycombos.h" +#include "libc/calls/kntprioritycombos.internal.h" #include "libc/conv/conv.h" +#include "libc/nexgen32e/ffs.h" #include "libc/nt/enum/processcreationflags.h" #include "libc/nt/enum/threadpriority.h" #include "libc/nt/process.h" diff --git a/libc/calls/getprocaddressmodule.c b/libc/calls/getprocaddressmodule.c index 1edf4b29..86615c09 100644 --- a/libc/calls/getprocaddressmodule.c +++ b/libc/calls/getprocaddressmodule.c @@ -17,12 +17,12 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/internal.h" #include "libc/nt/dll.h" -#include "libc/calls/calls.h" /** * Returns address of function in a DLL that's already loaded. */ -textwindows void *getprocaddressmodule(const char *module, const char *symbol) { +textwindows void *GetProcAddressModule(const char *module, const char *symbol) { return GetProcAddress(GetModuleHandle(module), symbol); } diff --git a/libc/calls/hefty/copyfile.c b/libc/calls/hefty/copyfile.c index 061cf21c..0619748e 100644 --- a/libc/calls/hefty/copyfile.c +++ b/libc/calls/hefty/copyfile.c @@ -24,6 +24,8 @@ #include "libc/nt/createfile.h" #include "libc/nt/enum/accessmask.h" #include "libc/nt/enum/creationdisposition.h" +#include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/nt/files.h" #include "libc/nt/runtime.h" #include "libc/sysv/consts/at.h" diff --git a/libc/calls/hefty/dirstream.c b/libc/calls/hefty/dirstream.c index 845993b5..28b26fbb 100644 --- a/libc/calls/hefty/dirstream.c +++ b/libc/calls/hefty/dirstream.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/calls/internal.h" #include "libc/calls/struct/dirent.h" #include "libc/dce.h" diff --git a/libc/calls/hefty/filecmp.c b/libc/calls/hefty/filecmp.c index a9282d99..8fa29399 100644 --- a/libc/calls/hefty/filecmp.c +++ b/libc/calls/hefty/filecmp.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/str/str.h" diff --git a/libc/calls/hefty/fork-nt.c b/libc/calls/hefty/fork-nt.c index 21da3c3a..4c7e87fd 100644 --- a/libc/calls/hefty/fork-nt.c +++ b/libc/calls/hefty/fork-nt.c @@ -28,7 +28,6 @@ #include "libc/nt/process.h" #include "libc/nt/runtime.h" #include "libc/runtime/memtrack.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" diff --git a/libc/calls/hefty/get_current_dir_name.c b/libc/calls/hefty/get_current_dir_name.c index b1eb3d67..f9d6ebeb 100644 --- a/libc/calls/hefty/get_current_dir_name.c +++ b/libc/calls/hefty/get_current_dir_name.c @@ -17,10 +17,10 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" +#include "libc/calls/calls.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" -#include "libc/calls/calls.h" #include "libc/sysv/errfuns.h" /** diff --git a/libc/calls/hefty/mkntcmdline.c b/libc/calls/hefty/mkntcmdline.c index 6675056a..b5eb3a22 100644 --- a/libc/calls/hefty/mkntcmdline.c +++ b/libc/calls/hefty/mkntcmdline.c @@ -17,16 +17,17 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/ntspawn.h" #include "libc/conv/conv.h" #include "libc/macros.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/runtime/runtime.h" +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" #include "libc/sysv/consts/fileno.h" #include "libc/sysv/errfuns.h" diff --git a/libc/calls/hefty/mkntenvblock.c b/libc/calls/hefty/mkntenvblock.c index 493f42c8..ce8e7207 100644 --- a/libc/calls/hefty/mkntenvblock.c +++ b/libc/calls/hefty/mkntenvblock.c @@ -17,13 +17,14 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/calls/hefty/ntspawn.h" #include "libc/conv/conv.h" #include "libc/macros.h" #include "libc/mem/mem.h" +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" #include "libc/sysv/errfuns.h" /** diff --git a/libc/calls/hefty/mkvarargv.h b/libc/calls/hefty/mkvarargv.h index ede3484d..9a45b48f 100644 --- a/libc/calls/hefty/mkvarargv.h +++ b/libc/calls/hefty/mkvarargv.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_HEFTY_MKVARARGV_H_ #define COSMOPOLITAN_LIBC_CALLS_HEFTY_MKVARARGV_H_ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/calls/hefty/ntspawn.c b/libc/calls/hefty/ntspawn.c index ae315c0c..4ddf1703 100644 --- a/libc/calls/hefty/ntspawn.c +++ b/libc/calls/hefty/ntspawn.c @@ -18,9 +18,9 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/ntspawn.h" #include "libc/calls/internal.h" @@ -28,7 +28,6 @@ #include "libc/nt/enum/processcreationflags.h" #include "libc/nt/process.h" #include "libc/nt/runtime.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/fileno.h" diff --git a/libc/calls/hefty/replaceuser.c b/libc/calls/hefty/replaceuser.c index 97fef978..34d479fe 100644 --- a/libc/calls/hefty/replaceuser.c +++ b/libc/calls/hefty/replaceuser.c @@ -17,11 +17,11 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" +#include "libc/calls/calls.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" -#include "libc/calls/calls.h" /** * Replaces tilde in path w/ user home folder. diff --git a/libc/calls/hefty/sortenvp.c b/libc/calls/hefty/sortenvp.c index 267fc3fc..59b44e3c 100644 --- a/libc/calls/hefty/sortenvp.c +++ b/libc/calls/hefty/sortenvp.c @@ -18,10 +18,10 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/calls/hefty/ntspawn.h" #include "libc/dce.h" -#include "libc/nexgen32e/tinystrcmp.h" +#include "libc/nexgen32e/tinystrcmp.internal.h" #include "libc/str/str.h" static int CompareStrings(const char *l, const char *r) { diff --git a/libc/calls/hefty/spawnlp.c b/libc/calls/hefty/spawnlp.c index 04502e1a..c7112cef 100644 --- a/libc/calls/hefty/spawnlp.c +++ b/libc/calls/hefty/spawnlp.c @@ -21,7 +21,6 @@ #include "libc/calls/hefty/mkvarargv.h" #include "libc/calls/hefty/spawn.h" #include "libc/mem/mem.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" /** diff --git a/libc/calls/hefty/spawnve-nt.c b/libc/calls/hefty/spawnve-nt.c index 5cedbbce..357b6e7e 100644 --- a/libc/calls/hefty/spawnve-nt.c +++ b/libc/calls/hefty/spawnve-nt.c @@ -23,6 +23,7 @@ #include "libc/calls/hefty/ntspawn.h" #include "libc/calls/hefty/spawn.h" #include "libc/calls/internal.h" +#include "libc/nt/enum/processcreationflags.h" #include "libc/nt/enum/startf.h" #include "libc/nt/files.h" #include "libc/nt/ipc.h" diff --git a/libc/calls/hefty/ttyname_r.c b/libc/calls/hefty/ttyname_r.c index bb601153..ba4c4838 100644 --- a/libc/calls/hefty/ttyname_r.c +++ b/libc/calls/hefty/ttyname_r.c @@ -24,6 +24,7 @@ #include "libc/fmt/fmt.h" #include "libc/log/log.h" #include "libc/nt/console.h" +#include "libc/nt/enum/consolemodeflags.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" diff --git a/libc/calls/internal.h b/libc/calls/internal.h index 39c308d6..0326ceb2 100644 --- a/libc/calls/internal.h +++ b/libc/calls/internal.h @@ -196,7 +196,6 @@ void *mremap$sysv(void *, u64, u64, i32, void *) hidden; │ cosmopolitan § syscalls » system five » support ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -int __getpid(void) hidden; void __onfork(void) hidden; bool32 __sigenter(i32, struct siginfo *, struct ucontext *) hidden; i32 fixupnewfd$sysv(i32, i32) hidden; @@ -246,7 +245,6 @@ int symlink$nt(const char *, const char *) hidden; int sysinfo$nt(struct sysinfo *) hidden; int truncate$nt(const char *, u64) hidden; int unlink$nt(const char *) hidden; -int wait4$nt(int, int *, int, struct rusage *) hidden; i64 lseek$nt(int, i64, int) hidden; ssize_t read$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden; ssize_t write$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden; @@ -260,6 +258,7 @@ int nanosleep$nt(const struct timespec *, struct timespec *) hidden; ╚────────────────────────────────────────────────────────────────────────────│*/ void WinMainForked(void) hidden; +void *GetProcAddressModule(const char *, const char *) hidden; int getsetpriority$nt(int, unsigned, int, int (*)(int)); void ntcontext2linux(struct ucontext *, const struct NtContext *) hidden; struct NtOverlapped *offset2overlap(int64_t, struct NtOverlapped *) hidden; diff --git a/libc/calls/ioctl-tcgets.c b/libc/calls/ioctl-tcgets.c index 4d793a59..998ec6cf 100644 --- a/libc/calls/ioctl-tcgets.c +++ b/libc/calls/ioctl-tcgets.c @@ -18,8 +18,8 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/struct/metatermios.h" -#include "libc/calls/termios-internal.h" +#include "libc/calls/struct/metatermios.internal.h" +#include "libc/calls/termios.internal.h" #include "libc/sysv/consts/termios.h" int ioctl$tcgets$nt(int, struct termios *); diff --git a/libc/calls/ioctl-tcsets-nt.c b/libc/calls/ioctl-tcsets-nt.c index 5bcd9e08..1d54fdd9 100644 --- a/libc/calls/ioctl-tcsets-nt.c +++ b/libc/calls/ioctl-tcsets-nt.c @@ -18,9 +18,10 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/struct/metatermios.h" -#include "libc/calls/termios-internal.h" +#include "libc/calls/struct/metatermios.internal.h" +#include "libc/calls/termios.internal.h" #include "libc/nt/console.h" +#include "libc/nt/enum/consolemodeflags.h" #include "libc/nt/enum/version.h" #include "libc/nt/struct/teb.h" #include "libc/sysv/consts/o.h" diff --git a/libc/calls/ioctl-tcsets.c b/libc/calls/ioctl-tcsets.c index 1d1d3e74..72729e4a 100644 --- a/libc/calls/ioctl-tcsets.c +++ b/libc/calls/ioctl-tcsets.c @@ -18,8 +18,8 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/struct/metatermios.h" -#include "libc/calls/termios-internal.h" +#include "libc/calls/struct/metatermios.internal.h" +#include "libc/calls/termios.internal.h" #include "libc/dce.h" #include "libc/sysv/consts/termios.h" diff --git a/libc/calls/ioctl.h b/libc/calls/ioctl.h index 4c1bf47a..fb6a7f93 100644 --- a/libc/calls/ioctl.h +++ b/libc/calls/ioctl.h @@ -1,20 +1,20 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_IOCTL_H_ #define COSMOPOLITAN_LIBC_CALLS_IOCTL_H_ +#include "libc/macros.h" +#include "libc/sysv/consts/termios.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ /*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § system calls » input output control ─╬─│┼ +│ cosmopolitan § system calls » ioctl ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ int ioctl(int, uint64_t, void *); /*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § system calls » input output control » undiamonding ─╬─│┼ +│ cosmopolitan § system calls » ioctl » undiamonding (size optimization) ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ #if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#include "libc/macros.h" -#include "libc/sysv/consts/termios.h" #define ioctl(FD, REQUEST, MEMORY) ioctl$dispatch(FD, REQUEST, MEMORY) diff --git a/libc/calls/isdebuggerpresent.c b/libc/calls/isdebuggerpresent.c index 4522428f..0f025bea 100644 --- a/libc/calls/isdebuggerpresent.c +++ b/libc/calls/isdebuggerpresent.c @@ -18,13 +18,13 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/conv/conv.h" #include "libc/dce.h" #include "libc/log/log.h" -#include "libc/nexgen32e/vendor.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/nt/struct/teb.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" diff --git a/libc/calls/kill.c b/libc/calls/kill.c index 3b90f0c3..99f00011 100644 --- a/libc/calls/kill.c +++ b/libc/calls/kill.c @@ -40,10 +40,15 @@ * @asyncsignalsafe */ int kill(int pid, int sig) { - if (pid == getpid()) return raise(sig); + int me; if (!IsWindows()) { return kill$sysv(pid, sig, 1); } else { - return enosys(); + me = getpid(); + if (!pid || pid == me || pid == -me) { + return raise(sig); + } else { + return enosys(); + } } } diff --git a/libc/calls/kntprioritycombos.c b/libc/calls/kntprioritycombos.c index 91cf4767..ce88bcd9 100644 --- a/libc/calls/kntprioritycombos.c +++ b/libc/calls/kntprioritycombos.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/calls/kntprioritycombos.h" +#include "libc/calls/kntprioritycombos.internal.h" #include "libc/limits.h" #include "libc/macros.h" #include "libc/nt/enum/processcreationflags.h" diff --git a/libc/calls/kntprioritycombos.h b/libc/calls/kntprioritycombos.internal.h similarity index 100% rename from libc/calls/kntprioritycombos.h rename to libc/calls/kntprioritycombos.internal.h diff --git a/libc/calls/madvise-nt.c b/libc/calls/madvise-nt.c index 9c2b5b38..ed0a16e7 100644 --- a/libc/calls/madvise-nt.c +++ b/libc/calls/madvise-nt.c @@ -19,6 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" #include "libc/macros.h" +#include "libc/nt/enum/offerpriority.h" #include "libc/nt/memory.h" #include "libc/nt/runtime.h" #include "libc/nt/struct/memoryrangeentry.h" @@ -31,7 +32,7 @@ forceinline typeof(PrefetchVirtualMemory) *GetPrefetchVirtualMemory(void) { if (!once) { once = true; PrefetchVirtualMemory_ = /* win8.1+ */ - getprocaddressmodule("KernelBase.dll", "PrefetchVirtualMemory"); + GetProcAddressModule("KernelBase.dll", "PrefetchVirtualMemory"); } return PrefetchVirtualMemory_; } @@ -42,7 +43,7 @@ forceinline typeof(OfferVirtualMemory) *GetOfferVirtualMemory(void) { if (!once) { once = true; OfferVirtualMemory_ = /* win8.1+ */ - getprocaddressmodule("KernelBase.dll", "OfferVirtualMemory"); + GetProcAddressModule("KernelBase.dll", "OfferVirtualMemory"); } return OfferVirtualMemory_; } diff --git a/libc/calls/mkntpath.ncabi.c b/libc/calls/mkntpath.ncabi.c index bedd01b5..43659840 100644 --- a/libc/calls/mkntpath.ncabi.c +++ b/libc/calls/mkntpath.ncabi.c @@ -17,10 +17,11 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/ntmagicpaths.h" -#include "libc/nexgen32e/tinystrcmp.h" +#include "libc/calls/ntmagicpaths.internal.h" +#include "libc/nexgen32e/tinystrcmp.internal.h" +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/errfuns.h" diff --git a/libc/calls/nanosleep-xnu.c b/libc/calls/nanosleep-xnu.c index 587d4eb0..de6c5695 100644 --- a/libc/calls/nanosleep-xnu.c +++ b/libc/calls/nanosleep-xnu.c @@ -22,6 +22,7 @@ #include "libc/macros.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/sock/internal.h" +#include "libc/sock/select.internal.h" int nanosleep$xnu(const struct timespec *req, struct timespec *rem) { long millis; diff --git a/libc/calls/nice.c b/libc/calls/nice.c index 247aa311..e60b3968 100644 --- a/libc/calls/nice.c +++ b/libc/calls/nice.c @@ -17,12 +17,14 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/conv/conv.h" #include "libc/sysv/consts/prio.h" -static int clamp(int p) { return max(-NZERO, min(NZERO - 1, p)); } +static int clamp(int p) { + return max(-NZERO, min(NZERO - 1, p)); +} /** * Changes process priority. diff --git a/libc/calls/now.c b/libc/calls/now.c index 623bf7fa..d410bb9d 100644 --- a/libc/calls/now.c +++ b/libc/calls/now.c @@ -18,8 +18,8 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/initializer.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/initializer.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/dce.h" #include "libc/nexgen32e/rdtsc.h" diff --git a/libc/calls/ntaccesscheck.c b/libc/calls/ntaccesscheck.c index 4e56072d..49d31286 100644 --- a/libc/calls/ntaccesscheck.c +++ b/libc/calls/ntaccesscheck.c @@ -20,6 +20,7 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/nt/enum/accessmask.h" +#include "libc/nt/enum/securityimpersonationlevel.h" #include "libc/nt/enum/securityinformation.h" #include "libc/nt/errors.h" #include "libc/nt/files.h" diff --git a/libc/calls/ntmagicpaths.c b/libc/calls/ntmagicpaths.c index 666409f1..5792ef65 100644 --- a/libc/calls/ntmagicpaths.c +++ b/libc/calls/ntmagicpaths.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/ntmagicpaths.h" +#include "libc/calls/ntmagicpaths.internal.h" const struct NtMagicPaths kNtMagicPaths = { #define TAB(NAME, STRING) STRING, diff --git a/libc/calls/ntmagicpaths.h b/libc/calls/ntmagicpaths.internal.h similarity index 100% rename from libc/calls/ntmagicpaths.h rename to libc/calls/ntmagicpaths.internal.h diff --git a/libc/calls/open-nt.c b/libc/calls/open-nt.c index bd7ab713..6ef2b0d4 100644 --- a/libc/calls/open-nt.c +++ b/libc/calls/open-nt.c @@ -19,9 +19,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/calls/internal.h" -#include "libc/calls/ntmagicpaths.h" -#include "libc/nexgen32e/tinystrcmp.h" +#include "libc/calls/ntmagicpaths.internal.h" +#include "libc/nexgen32e/tinystrcmp.internal.h" #include "libc/nt/createfile.h" +#include "libc/nt/enum/accessmask.h" +#include "libc/nt/enum/creationdisposition.h" +#include "libc/nt/enum/fileflagandattributes.h" #include "libc/nt/enum/filesharemode.h" #include "libc/nt/enum/filetype.h" #include "libc/nt/enum/fsctl.h" diff --git a/libc/calls/openanon.c b/libc/calls/openanon.c index 77ee127e..64017619 100644 --- a/libc/calls/openanon.c +++ b/libc/calls/openanon.c @@ -21,12 +21,14 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/conv/conv.h" -#include "libc/conv/isslash.h" +#include "libc/conv/isslash.internal.h" #include "libc/conv/itoa.h" #include "libc/dce.h" #include "libc/nt/createfile.h" +#include "libc/nt/enum/accessmask.h" #include "libc/nt/enum/creationdisposition.h" #include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/o.h" diff --git a/libc/calls/openbsd.h b/libc/calls/openbsd.h deleted file mode 100644 index bb8a43aa..00000000 --- a/libc/calls/openbsd.h +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#ifndef COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ -#define COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § system calls » openbsd ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -typedef unsigned char u_char; - -int pledge(const char *promises, const char *execpromises); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ */ diff --git a/libc/calls/openbsd.internal.h b/libc/calls/openbsd.internal.h new file mode 100644 index 00000000..8a8b62bc --- /dev/null +++ b/libc/calls/openbsd.internal.h @@ -0,0 +1,15 @@ +#ifndef COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ +#define COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § system calls » openbsd ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + +typedef unsigned char u_char; + +int pledge(const char *promises, const char *execpromises); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ */ diff --git a/libc/calls/preadv.c b/libc/calls/preadv.c index eb0f1b7d..0f0e3a0f 100644 --- a/libc/calls/preadv.c +++ b/libc/calls/preadv.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/struct/iovec.h" diff --git a/libc/calls/pwritev.c b/libc/calls/pwritev.c index 93efb84a..2d98fc21 100644 --- a/libc/calls/pwritev.c +++ b/libc/calls/pwritev.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/struct/iovec.h" diff --git a/libc/calls/raise.c b/libc/calls/raise.c index 82606810..8d5849b0 100644 --- a/libc/calls/raise.c +++ b/libc/calls/raise.c @@ -19,7 +19,23 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/runtime/missioncritical.h" +#include "libc/nt/console.h" +#include "libc/nt/enum/ctrlevent.h" +#include "libc/nt/runtime.h" +#include "libc/sysv/consts/sig.h" + +static uint32_t GetCtrlEvent(int sig) { + switch (sig) { + case SIGINT: + return kNtCtrlCEvent; + case SIGHUP: + return kNtCtrlCloseEvent; + case SIGQUIT: + return kNtCtrlBreakEvent; + default: + ExitProcess(128 + sig); + } +} /** * Sends signal to this process. @@ -28,4 +44,23 @@ * @return 0 on success or -1 w/ errno * @asyncsignalsafe */ -int raise(int sig) { return RAISE(sig); } +int raise(int sig) { + if (sig == SIGTRAP) { + DebugBreak(); + return 0; + } + if (sig == SIGFPE) { + volatile int x = 0; + x = 1 / x; + return 0; + } + if (!IsWindows()) { + return kill$sysv(getpid(), sig, 1); + } else { + if (GenerateConsoleCtrlEvent(GetCtrlEvent(sig), 0)) { + return 0; + } else { + return winerr(); + } + } +} diff --git a/libc/calls/rename-nt.c b/libc/calls/rename-nt.c index 12c97f7e..91fa3864 100644 --- a/libc/calls/rename-nt.c +++ b/libc/calls/rename-nt.c @@ -18,6 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" +#include "libc/nt/enum/movefileexflags.h" #include "libc/nt/files.h" #include "libc/nt/runtime.h" #include "libc/str/str.h" diff --git a/libc/calls/sched_setaffinity.c b/libc/calls/sched_setaffinity.c index ee0ebf88..c09e4079 100644 --- a/libc/calls/sched_setaffinity.c +++ b/libc/calls/sched_setaffinity.c @@ -17,11 +17,13 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/dce.h" #include "libc/limits.h" +#include "libc/nt/enum/processaccess.h" +#include "libc/nt/enum/threadaccess.h" #include "libc/nt/process.h" #include "libc/nt/runtime.h" #include "libc/nt/thread.h" @@ -64,7 +66,6 @@ static textwindows noinline int sched_setaffinity$nt(int pid, * * @param pid is the process or thread id (or 0 for caller) * @param bitsetsize is byte length of bitset - * @param bitset can be manipulated using bt(), bts(), etc. * @return 0 on success, or -1 w/ errno */ int sched_setaffinity(int pid, uint64_t bitsetsize, const void *bitset) { diff --git a/libc/calls/setpriority-nt.c b/libc/calls/setpriority-nt.c index 2779f7e0..79980d55 100644 --- a/libc/calls/setpriority-nt.c +++ b/libc/calls/setpriority-nt.c @@ -17,9 +17,9 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/internal.h" -#include "libc/calls/kntprioritycombos.h" +#include "libc/calls/kntprioritycombos.internal.h" #include "libc/nt/process.h" #include "libc/nt/runtime.h" #include "libc/nt/thread.h" diff --git a/libc/calls/sigaction.c b/libc/calls/sigaction.c index d389922a..fbdca6d7 100644 --- a/libc/calls/sigaction.c +++ b/libc/calls/sigaction.c @@ -20,10 +20,10 @@ #include "libc/bits/bits.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" -#include "libc/calls/struct/sigaction-freebsd.h" -#include "libc/calls/struct/sigaction-linux.h" -#include "libc/calls/struct/sigaction-openbsd.h" -#include "libc/calls/struct/sigaction-xnu.h" +#include "libc/calls/struct/sigaction-freebsd.internal.h" +#include "libc/calls/struct/sigaction-linux.internal.h" +#include "libc/calls/struct/sigaction-openbsd.internal.h" +#include "libc/calls/struct/sigaction-xnu.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/typedef/sigaction_f.h" #include "libc/calls/ucontext.h" @@ -63,7 +63,7 @@ union metasigaction { static void sigaction$cosmo2native(union metasigaction *sa) { if (!sa) return; - switch (hostos) { + switch (__hostos) { case LINUX: SWITCHEROO(sa->cosmo, sa->linux, sa_handler, sa_flags, sa_restorer, sa_mask); @@ -87,7 +87,7 @@ static void sigaction$cosmo2native(union metasigaction *sa) { static void sigaction$native2cosmo(union metasigaction *sa) { if (!sa) return; - switch (hostos) { + switch (__hostos) { case LINUX: SWITCHEROO(sa->linux, sa->cosmo, sa_handler, sa_flags, sa_restorer, sa_mask); diff --git a/libc/calls/sigaddset.c b/libc/calls/sigaddset.c index c8183dcf..2acf6ba6 100644 --- a/libc/calls/sigaddset.c +++ b/libc/calls/sigaddset.c @@ -18,13 +18,20 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sigbits.h" -#include "libc/calls/calls.h" +#include "libc/sysv/errfuns.h" /** - * Adds sig to set. + * Adds signal to set. * * @return true, false, or -1 w/ errno - * @error EINVAL * @asyncsignalsafe */ -int(sigaddset)(sigset_t *set, int sig) { return sigaddset(set, sig); } +int sigaddset(sigset_t *set, int sig) { + unsigned i = sig - 1; + if (i < sizeof(set->__bits) * 8) { + set->__bits[i >> 6] |= 1ull << (i & 63); + return 0; + } else { + return einval(); + } +} diff --git a/libc/calls/sigbits.h b/libc/calls/sigbits.h index a3942400..da837a23 100644 --- a/libc/calls/sigbits.h +++ b/libc/calls/sigbits.h @@ -1,52 +1,14 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_SIGBITS_H_ #define COSMOPOLITAN_LIBC_CALLS_SIGBITS_H_ -#include "libc/bits/bits.h" -#include "libc/bits/progn.h" -#include "libc/str/str.h" #include "libc/calls/struct/sigset.h" -#include "libc/sysv/errfuns.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct sigset; - -int sigaddset(struct sigset *, int) paramsnonnull(); -int sigdelset(struct sigset *, int) paramsnonnull(); -int sigemptyset(struct sigset *) paramsnonnull(); -int sigfillset(struct sigset *) paramsnonnull(); -int sigismember(const struct sigset *, int) paramsnonnull() nosideeffect; - -#define sigemptyset(SET) \ - ({ \ - memset((SET), 0, sizeof(struct sigset)); \ - 0; \ - }) - -#define sigfillset(SET) \ - ({ \ - memset((SET), -1, sizeof(struct sigset)); \ - 0; \ - }) - -#define sigaddset(SET, SIG) \ - ({ \ - int Sig = (SIG); \ - __IsValidSignal(Sig) ? PROGN(bts((SET)->sig, Sig - 1), 0) : einval(); \ - }) - -#define sigdelset(SET, SIG) \ - ({ \ - int Sig = (SIG); \ - __IsValidSignal(Sig) ? PROGN(btr((SET)->sig, Sig - 1), 0) : einval(); \ - }) - -#define sigismember(SET, SIG) \ - ({ \ - int Sig = (SIG); \ - __IsValidSignal(Sig) ? bt((SET)->sig, Sig - 1) : einval(); \ - }) - -#define __IsValidSignal(SIG) (1 <= (SIG) && (SIG) <= NSIG) +int sigaddset(sigset_t *, int) paramsnonnull(); +int sigdelset(sigset_t *, int) paramsnonnull(); +int sigemptyset(sigset_t *) paramsnonnull(); +int sigfillset(sigset_t *) paramsnonnull(); +int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/sigdelset.c b/libc/calls/sigdelset.c index c364ce98..806d19dd 100644 --- a/libc/calls/sigdelset.c +++ b/libc/calls/sigdelset.c @@ -18,13 +18,20 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sigbits.h" -#include "libc/calls/calls.h" +#include "libc/sysv/errfuns.h" /** - * Removes sig from set. + * Removes signal from set. * * @return 0 on success, or -1 w/ errno - * @error EINVAL * @asyncsignalsafe */ -int(sigdelset)(sigset_t *set, int sig) { return sigdelset(set, sig); } +int sigdelset(sigset_t *set, int sig) { + unsigned i = sig - 1; + if (i < sizeof(set->__bits) * 8) { + set->__bits[i >> 6] &= ~(1ull << (i & 63)); + return 0; + } else { + return einval(); + } +} diff --git a/libc/calls/sigemptyset.c b/libc/calls/sigemptyset.c index 12d2b75b..446ce064 100644 --- a/libc/calls/sigemptyset.c +++ b/libc/calls/sigemptyset.c @@ -18,13 +18,15 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sigbits.h" -#include "libc/calls/calls.h" +#include "libc/str/str.h" /** * Removes all signals from set. * * @return 0 on success, or -1 w/ errno - * @error EINVAL * @asyncsignalsafe */ -int(sigemptyset)(sigset_t *set) { return sigemptyset(set); } +int sigemptyset(sigset_t *set) { + memset(set->__bits, 0, sizeof(set->__bits)); + return 0; +} diff --git a/libc/calls/sigfillset.c b/libc/calls/sigfillset.c index f8849d23..09230290 100644 --- a/libc/calls/sigfillset.c +++ b/libc/calls/sigfillset.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sigbits.h" -#include "libc/calls/calls.h" +#include "libc/str/str.h" /** * Adds all signals to set. @@ -26,4 +26,7 @@ * @return 0 on success, or -1 w/ errno * @asyncsignalsafe */ -int(sigfillset)(sigset_t *set) { return sigfillset(set); } +int sigfillset(sigset_t *set) { + memset(set->__bits, -1, sizeof(set->__bits)); + return 0; +} diff --git a/libc/calls/sigignore.c b/libc/calls/sigignore.c index 083a81c8..66d192fb 100644 --- a/libc/calls/sigignore.c +++ b/libc/calls/sigignore.c @@ -21,6 +21,9 @@ #include "libc/calls/struct/sigaction.h" #include "libc/str/str.h" +/** + * Configures process to ignore signal. + */ int sigignore(int sig) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); diff --git a/libc/calls/sigismember.c b/libc/calls/sigismember.c index 0029db27..3cca7ff5 100644 --- a/libc/calls/sigismember.c +++ b/libc/calls/sigismember.c @@ -18,13 +18,19 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sigbits.h" -#include "libc/calls/calls.h" +#include "libc/sysv/errfuns.h" /** - * Returns true if sig ∈ set. + * Returns true if signal is member of set. * * @return true, false, or -1 w/ errno - * @error EINVAL * @asyncsignalsafe */ -int(sigismember)(const sigset_t *set, int sig) { return sigismember(set, sig); } +int sigismember(const sigset_t *set, int sig) { + unsigned i = sig - 1; + if (i < sizeof(set->__bits) * 8) { + return (set->__bits[i >> 6] >> (i & 63)) & 1; + } else { + return einval(); + } +} diff --git a/libc/calls/stat-nt.c b/libc/calls/stat-nt.c index b64d582d..3f085404 100644 --- a/libc/calls/stat-nt.c +++ b/libc/calls/stat-nt.c @@ -20,6 +20,9 @@ #include "libc/calls/internal.h" #include "libc/nt/createfile.h" #include "libc/nt/enum/accessmask.h" +#include "libc/nt/enum/creationdisposition.h" +#include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/nt/files.h" #include "libc/nt/runtime.h" #include "libc/runtime/runtime.h" diff --git a/libc/calls/stat2linux.c b/libc/calls/stat2linux.c index d1a31c7a..c65f15c4 100644 --- a/libc/calls/stat2linux.c +++ b/libc/calls/stat2linux.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/struct/metastat.h" +#include "libc/calls/struct/metastat.internal.h" #include "libc/dce.h" #define SWITCHEROO(S1, S2, A, B, C, D, E, F, G, H, I, J, K, L, M) \ diff --git a/libc/calls/struct/metastat.h b/libc/calls/struct/metastat.internal.h similarity index 100% rename from libc/calls/struct/metastat.h rename to libc/calls/struct/metastat.internal.h diff --git a/libc/calls/struct/metatermios.h b/libc/calls/struct/metatermios.internal.h similarity index 100% rename from libc/calls/struct/metatermios.h rename to libc/calls/struct/metatermios.internal.h diff --git a/libc/calls/struct/sigaction-freebsd.h b/libc/calls/struct/sigaction-freebsd.internal.h similarity index 100% rename from libc/calls/struct/sigaction-freebsd.h rename to libc/calls/struct/sigaction-freebsd.internal.h diff --git a/libc/calls/struct/sigaction-linux.h b/libc/calls/struct/sigaction-linux.internal.h similarity index 100% rename from libc/calls/struct/sigaction-linux.h rename to libc/calls/struct/sigaction-linux.internal.h diff --git a/libc/calls/struct/sigaction-openbsd.h b/libc/calls/struct/sigaction-openbsd.internal.h similarity index 100% rename from libc/calls/struct/sigaction-openbsd.h rename to libc/calls/struct/sigaction-openbsd.internal.h diff --git a/libc/calls/struct/sigaction-xnu.h b/libc/calls/struct/sigaction-xnu.internal.h similarity index 95% rename from libc/calls/struct/sigaction-xnu.h rename to libc/calls/struct/sigaction-xnu.internal.h index e83bac80..e6932959 100644 --- a/libc/calls/struct/sigaction-xnu.h +++ b/libc/calls/struct/sigaction-xnu.internal.h @@ -1,6 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_XNU_H_ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_XNU_H_ -#include "libc/calls/internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct __darwin_ucontext; diff --git a/libc/calls/struct/sigset.h b/libc/calls/struct/sigset.h index b46b6015..7f1fb1f9 100644 --- a/libc/calls/struct/sigset.h +++ b/libc/calls/struct/sigset.h @@ -2,11 +2,9 @@ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) -struct sigset { /* cosmo abi (linux is uint64_t) */ - uint32_t sig[4]; /* ignore sig[2] and sig[3] (for freebsd) */ -} aligned(8); - -typedef struct sigset sigset_t; +typedef struct sigset { + uint64_t __bits[2]; +} sigset_t; #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ */ diff --git a/libc/calls/sync-nt.c b/libc/calls/sync-nt.c index 6df5e383..0cf29c91 100644 --- a/libc/calls/sync-nt.c +++ b/libc/calls/sync-nt.c @@ -20,6 +20,9 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/nt/createfile.h" +#include "libc/nt/enum/accessmask.h" +#include "libc/nt/enum/creationdisposition.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/nt/files.h" #include "libc/nt/runtime.h" #include "libc/sysv/consts/ok.h" diff --git a/libc/calls/sysinfo.c b/libc/calls/sysinfo.c index 74cad971..0154d9b4 100644 --- a/libc/calls/sysinfo.c +++ b/libc/calls/sysinfo.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/struct/sysinfo.h" diff --git a/libc/calls/termios-internal.h b/libc/calls/termios.internal.h similarity index 92% rename from libc/calls/termios-internal.h rename to libc/calls/termios.internal.h index 9d62bbc4..eb567cec 100644 --- a/libc/calls/termios-internal.h +++ b/libc/calls/termios.internal.h @@ -1,8 +1,8 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_ #define COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_ #ifndef __STRICT_ANSI__ -#include "libc/bits/safemacros.h" -#include "libc/calls/struct/metatermios.h" +#include "libc/bits/safemacros.internal.h" +#include "libc/calls/struct/metatermios.internal.h" #include "libc/calls/struct/termios.h" #include "libc/str/str.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) diff --git a/libc/calls/termios2host.c b/libc/calls/termios2host.c index e73ab716..816e7400 100644 --- a/libc/calls/termios2host.c +++ b/libc/calls/termios2host.c @@ -18,9 +18,9 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/ioctl.h" -#include "libc/calls/struct/metatermios.h" -#include "libc/calls/termios-internal.h" +#include "libc/calls/struct/metatermios.internal.h" #include "libc/calls/termios.h" +#include "libc/calls/termios.internal.h" #include "libc/dce.h" void *termios2host(union metatermios *t, const struct termios *lt) { diff --git a/libc/calls/termios2linux.c b/libc/calls/termios2linux.c index a95d5157..4fcda566 100644 --- a/libc/calls/termios2linux.c +++ b/libc/calls/termios2linux.c @@ -18,9 +18,9 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/ioctl.h" -#include "libc/calls/struct/metatermios.h" -#include "libc/calls/termios-internal.h" +#include "libc/calls/struct/metatermios.internal.h" #include "libc/calls/termios.h" +#include "libc/calls/termios.internal.h" #include "libc/dce.h" void termios2linux(struct termios *lt, const union metatermios *t) { diff --git a/libc/calls/utimensat-nt.c b/libc/calls/utimensat-nt.c index 847bb985..6df29994 100644 --- a/libc/calls/utimensat-nt.c +++ b/libc/calls/utimensat-nt.c @@ -20,7 +20,10 @@ #include "libc/calls/internal.h" #include "libc/conv/conv.h" #include "libc/nt/createfile.h" +#include "libc/nt/enum/accessmask.h" #include "libc/nt/enum/creationdisposition.h" +#include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/nt/files.h" #include "libc/nt/runtime.h" #include "libc/nt/synchronization.h" diff --git a/libc/calls/wait4-nt.c b/libc/calls/wait4-nt.c index e7fbaace..6fff38e4 100644 --- a/libc/calls/wait4-nt.c +++ b/libc/calls/wait4-nt.c @@ -28,7 +28,6 @@ #include "libc/nt/runtime.h" #include "libc/nt/struct/filetime.h" #include "libc/nt/synchronization.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/w.h" diff --git a/libc/calls/wait4.c b/libc/calls/wait4.c index 3837b864..42d99e09 100644 --- a/libc/calls/wait4.c +++ b/libc/calls/wait4.c @@ -19,6 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" +#include "libc/calls/wait4.h" #include "libc/dce.h" /** diff --git a/libc/calls/wait4.h b/libc/calls/wait4.h new file mode 100644 index 00000000..03ea3ba2 --- /dev/null +++ b/libc/calls/wait4.h @@ -0,0 +1,11 @@ +#ifndef COSMOPOLITAN_LIBC_CALLS_WAIT4_H_ +#define COSMOPOLITAN_LIBC_CALLS_WAIT4_H_ +#include "libc/calls/struct/rusage.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int wait4$nt(int, int *, int, struct rusage *) hidden; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_CALLS_WAIT4_H_ */ diff --git a/libc/calls/waitpid.c b/libc/calls/waitpid.c index 3320309c..b6ddaa8c 100644 --- a/libc/calls/waitpid.c +++ b/libc/calls/waitpid.c @@ -19,6 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" +#include "libc/calls/wait4.h" #include "libc/dce.h" /** diff --git a/libc/calls/wincrash.c b/libc/calls/wincrash.c index fddb6186..5a1745c1 100644 --- a/libc/calls/wincrash.c +++ b/libc/calls/wincrash.c @@ -18,14 +18,11 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" -#include "libc/calls/struct/siginfo.h" #include "libc/calls/ucontext.h" #include "libc/nt/enum/exceptionhandleractions.h" -#include "libc/nt/signals.h" +#include "libc/nt/enum/signal.h" #include "libc/nt/struct/ntexceptionpointers.h" -#include "libc/nt/struct/ntexceptionrecord.h" #include "libc/str/str.h" -#include "libc/sysv/consts/sig.h" textwindows unsigned __wincrash(struct NtExceptionPointers *ep) { int sig; diff --git a/libc/calls/xattr.h b/libc/calls/xattr.h index 0b14d2c6..3e134c7e 100644 --- a/libc/calls/xattr.h +++ b/libc/calls/xattr.h @@ -3,23 +3,18 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -ssize_t flistxattr(int filedes, char *list, size_t size); -ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size); -int fsetxattr(int filedes, const char *name, const void *value, size_t size, - int flags); -int fremovexattr(int filedes, const char *name); - -ssize_t listxattr(const char *path, char *list, size_t size); -ssize_t getxattr(const char *path, const char *name, void *value, size_t size); -int setxattr(const char *path, const char *name, const void *value, size_t size, - int flags); -int removexattr(const char *path, const char *name); - -ssize_t llistxattr(const char *path, char *list, size_t size); -ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); -int lsetxattr(const char *path, const char *name, const void *value, - size_t size, int flags); -int lremovexattr(const char *path, const char *name); +ssize_t flistxattr(int, char *, size_t); +ssize_t fgetxattr(int, const char *, void *, size_t); +int fsetxattr(int, const char *, const void *, size_t, int); +int fremovexattr(int, const char *); +ssize_t listxattr(const char *, char *, size_t); +ssize_t getxattr(const char *, const char *, void *, size_t); +int setxattr(const char *, const char *, const void *, size_t, int); +int removexattr(const char *, const char *); +ssize_t llistxattr(const char *, char *, size_t); +ssize_t lgetxattr(const char *, const char *, void *, size_t); +int lsetxattr(const char *, const char *, const void *, size_t, int); +int lremovexattr(const char *, const char *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/conv/atoi.c b/libc/conv/atoi.c index cb650b96..153ab7ae 100644 --- a/libc/conv/atoi.c +++ b/libc/conv/atoi.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/strlol.h" +#include "libc/conv/strlol.internal.h" #include "libc/limits.h" /** @@ -29,4 +29,6 @@ * @note calling strtoimax() directly with base 0 permits greater * flexibility in terms of inputs */ -int atoi(const char *s) { return STRLOL(s, NULL, 10, INT_MIN, INT_MAX); } +int atoi(const char *s) { + return STRLOL(s, NULL, 10, INT_MIN, INT_MAX); +} diff --git a/libc/conv/atol.c b/libc/conv/atol.c index 1f720edc..578c5350 100644 --- a/libc/conv/atol.c +++ b/libc/conv/atol.c @@ -18,7 +18,9 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/strlol.h" +#include "libc/conv/strlol.internal.h" #include "libc/limits.h" -long atol(const char *s) { return STRLOL(s, NULL, 10, LONG_MIN, LONG_MAX); } +long atol(const char *s) { + return STRLOL(s, NULL, 10, LONG_MIN, LONG_MAX); +} diff --git a/libc/conv/atoll.c b/libc/conv/atoll.c index 77ce43c0..3349fe61 100644 --- a/libc/conv/atoll.c +++ b/libc/conv/atoll.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/strlol.h" +#include "libc/conv/strlol.internal.h" #include "libc/limits.h" long long atoll(const char *s) { diff --git a/libc/conv/basename.c b/libc/conv/basename.c index df16bb81..0e3b3f51 100644 --- a/libc/conv/basename.c +++ b/libc/conv/basename.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/isslash.h" +#include "libc/conv/isslash.internal.h" #include "libc/str/str.h" /** diff --git a/libc/conv/basename_n.c b/libc/conv/basename_n.c index 544507d3..9be71c0d 100644 --- a/libc/conv/basename_n.c +++ b/libc/conv/basename_n.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/isslash.h" +#include "libc/conv/isslash.internal.h" /** * Returns pointer to last filename component in path. diff --git a/libc/conv/conv.h b/libc/conv/conv.h index 4e9306d8..a099c313 100644 --- a/libc/conv/conv.h +++ b/libc/conv/conv.h @@ -8,13 +8,6 @@ │ cosmopolitan § conversion ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -/** - * COBOL timestamp (1601) for UNIX epoch (1970). - * - * It's a well-known fact in the social sciences that the introduction - * of the UNIX operation system signalled the end of modernity. Windows - * timestamps are living proof. - */ #define MODERNITYSECONDS 11644473600ull #define HECTONANOSECONDS 10000000ull diff --git a/libc/conv/isabspath.c b/libc/conv/isabspath.c index 18f7b934..b5521d4e 100644 --- a/libc/conv/isabspath.c +++ b/libc/conv/isabspath.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/isslash.h" +#include "libc/conv/isslash.internal.h" /** * Returns true if pathname could be absolute on any known platform. diff --git a/libc/conv/isslash.h b/libc/conv/isslash.internal.h similarity index 100% rename from libc/conv/isslash.h rename to libc/conv/isslash.internal.h diff --git a/libc/conv/itoa.h b/libc/conv/itoa.h index d5f79bd1..d5c31264 100644 --- a/libc/conv/itoa.h +++ b/libc/conv/itoa.h @@ -2,9 +2,9 @@ #define COSMOPOLITAN_LIBC_CONV_ITOA_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ - -/* - +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § integer conversion ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│─╝ FASTEST + TINY - uint64toarray_radix10(0x31337, a) l: 68 (20ns) m: 112 (33ns) @@ -14,9 +14,7 @@ COSMOPOLITAN_C_START_ - snprintf(a, sizeof(a), "%d", 0x31337) l: 199 (58ns) m: 421 (123ns) - uint128toarray_radix10(0x31337, a) l: 93 (27ns) m: 141 (41ns) - - int128toarray_radix10(0x31337, a) l: 96 (28ns) m: 173 (51ns) - -*/ + - int128toarray_radix10(0x31337, a) l: 96 (28ns) m: 173 (51ns) */ size_t int64toarray_radix10(int64_t, char[hasatleast 21]); size_t uint64toarray_radix10(uint64_t, char[hasatleast 21]); diff --git a/libc/conv/strlol.h b/libc/conv/strlol.internal.h similarity index 100% rename from libc/conv/strlol.h rename to libc/conv/strlol.internal.h diff --git a/libc/conv/strtol.c b/libc/conv/strtol.c index f209891c..23280b02 100644 --- a/libc/conv/strtol.c +++ b/libc/conv/strtol.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/strlol.h" +#include "libc/conv/strlol.internal.h" #include "libc/limits.h" /** diff --git a/libc/conv/strtoll.c b/libc/conv/strtoll.c index aae22434..f97c5333 100644 --- a/libc/conv/strtoll.c +++ b/libc/conv/strtoll.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/strlol.h" +#include "libc/conv/strlol.internal.h" #include "libc/limits.h" long long strtoll(const char *s, char **endptr, int optional_base) { diff --git a/libc/conv/strtoul.c b/libc/conv/strtoul.c index 16505022..e0787e3f 100644 --- a/libc/conv/strtoul.c +++ b/libc/conv/strtoul.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/strlol.h" +#include "libc/conv/strlol.internal.h" #include "libc/limits.h" unsigned long strtoul(const char *s, char **endptr, int optional_base) { diff --git a/libc/conv/strtoull.c b/libc/conv/strtoull.c index b87e55ca..3910f6aa 100644 --- a/libc/conv/strtoull.c +++ b/libc/conv/strtoull.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/strlol.h" +#include "libc/conv/strlol.internal.h" #include "libc/limits.h" unsigned long long strtoull(const char *s, char **endptr, int optional_base) { diff --git a/libc/conv/wcslol.h b/libc/conv/wcslol.internal.h similarity index 100% rename from libc/conv/wcslol.h rename to libc/conv/wcslol.internal.h diff --git a/libc/conv/wcstol.c b/libc/conv/wcstol.c index e2cbc2c5..8bb2acd0 100644 --- a/libc/conv/wcstol.c +++ b/libc/conv/wcstol.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" -#include "libc/conv/wcslol.h" +#include "libc/conv/wcslol.internal.h" #include "libc/limits.h" #include "libc/str/str.h" diff --git a/libc/crt/crt.S b/libc/crt/crt.S index 1f796f8c..1100b1dc 100644 --- a/libc/crt/crt.S +++ b/libc/crt/crt.S @@ -34,7 +34,7 @@ _start: test %rdi,%rdi cmovnz %rdi,%rsp jz 0f - movb $FREEBSD,hostos(%rip) + movb $FREEBSD,__hostos(%rip) 0: mov (%rsp),%ebx # argc lea 8(%rsp),%rsi # argv lea 24(%rsp,%rbx,8),%rdx # envp @@ -64,6 +64,6 @@ _start: test %rdi,%rdi / @note FreeBSD is special (see freebsd/lib/csu/amd64/...) / @noreturn _start_xnu: - movb $XNU,hostos(%rip) + movb $XNU,__hostos(%rip) jmp 0b .endfn _start_xnu,weak,hidden diff --git a/libc/crypto/rijndael.c b/libc/crypto/rijndael.c index 696ba727..92d6816c 100644 --- a/libc/crypto/rijndael.c +++ b/libc/crypto/rijndael.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/emmintrin.h" +#include "libc/bits/emmintrin.internal.h" #include "libc/crypto/rijndael.h" #include "libc/nexgen32e/x86feature.h" diff --git a/libc/crypto/rijndaelinit.c b/libc/crypto/rijndaelinit.c index cd68b2ef..023af8f2 100644 --- a/libc/crypto/rijndaelinit.c +++ b/libc/crypto/rijndaelinit.c @@ -19,11 +19,13 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/crypto/rijndael.h" #include "libc/dce.h" #include "libc/str/internal.h" +#define ROR(w, k) (CheckUnsigned(w) >> (k) | (w) << (sizeof(w) * 8 - (k))) + static const uint8_t Rcon[11] = {0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36}; @@ -45,7 +47,7 @@ forceinline uint32_t SubRot(uint32_t t) { */ void rijndaelinit(struct Rijndael *ctx, uint32_t n, aes_block_t k1, aes_block_t k2) { -#define Nk (n - 6) +#define Nk (n - 6) #define W(i) (ctx->rk[(i) / 4].u32[(i) % 4]) #define K(i) ((i) < 4 ? k1[i] : k2[(i)-4]) uint32_t i, t; diff --git a/libc/crypto/unrijndael.c b/libc/crypto/unrijndael.c index aadba9d0..7f962871 100644 --- a/libc/crypto/unrijndael.c +++ b/libc/crypto/unrijndael.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/emmintrin.h" +#include "libc/bits/emmintrin.internal.h" #include "libc/crypto/rijndael.h" #include "libc/nexgen32e/x86feature.h" diff --git a/libc/crypto/unrijndaelinit.c b/libc/crypto/unrijndaelinit.c index c55f5545..44e5fbfe 100644 --- a/libc/crypto/unrijndaelinit.c +++ b/libc/crypto/unrijndaelinit.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/crypto/rijndael.h" #include "libc/nexgen32e/x86feature.h" diff --git a/libc/dce.h b/libc/dce.h index 606d5c11..0179c04e 100644 --- a/libc/dce.h +++ b/libc/dce.h @@ -17,7 +17,6 @@ * offer marginal improvements in terms of code size and performance, at * the cost of portability. */ -#define HOSTOS (hostos & SUPPORT_VECTOR) #ifndef SUPPORT_VECTOR #define SUPPORT_VECTOR 0b11111111 #endif @@ -94,29 +93,30 @@ ((SUPPORT_VECTOR & (LINUX | METAL | XNU | OPENBSD | FREEBSD)) != 0) #ifndef __ASSEMBLER__ -#define IsLinux() ((HOSTOS & LINUX) == LINUX) -#define IsMetal() ((HOSTOS & METAL) == METAL) -#define IsWindows() ((HOSTOS & WINDOWS) == WINDOWS) -#define IsBsd() ((HOSTOS & (XNU | FREEBSD | OPENBSD)) != 0) -#define IsXnu() ((HOSTOS & XNU) == XNU) -#define IsFreebsd() ((HOSTOS & FREEBSD) == FREEBSD) -#define IsOpenbsd() ((HOSTOS & OPENBSD) == OPENBSD) +#define __HOSTOS (__hostos & SUPPORT_VECTOR) +#define IsLinux() ((__HOSTOS & LINUX) == LINUX) +#define IsMetal() ((__HOSTOS & METAL) == METAL) +#define IsWindows() ((__HOSTOS & WINDOWS) == WINDOWS) +#define IsBsd() ((__HOSTOS & (XNU | FREEBSD | OPENBSD)) != 0) +#define IsXnu() ((__HOSTOS & XNU) == XNU) +#define IsFreebsd() ((__HOSTOS & FREEBSD) == FREEBSD) +#define IsOpenbsd() ((__HOSTOS & OPENBSD) == OPENBSD) #else /* clang-format off */ -#define IsLinux() $LINUX,hostos(%rip) -#define IsMetal() $METAL,hostos(%rip) -#define IsWindows() $WINDOWS,hostos(%rip) -#define IsBsd() $XNU|FREEBSD|OPENBSD,hostos(%rip) -#define IsXnu() $XNU,hostos(%rip) -#define IsFreebsd() $FREEBSD,hostos(%rip) -#define IsOpenbsd() $OPENBSD,hostos(%rip) +#define IsLinux() $LINUX,__hostos(%rip) +#define IsMetal() $METAL,__hostos(%rip) +#define IsWindows() $WINDOWS,__hostos(%rip) +#define IsBsd() $XNU|FREEBSD|OPENBSD,__hostos(%rip) +#define IsXnu() $XNU,__hostos(%rip) +#define IsFreebsd() $FREEBSD,__hostos(%rip) +#define IsOpenbsd() $OPENBSD,__hostos(%rip) /* clang-format on */ #endif #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -extern const int hostos; +extern const int __hostos; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/dns/dnsnamecmp.c b/libc/dns/dnsnamecmp.c index b044c543..22638fb4 100644 --- a/libc/dns/dnsnamecmp.c +++ b/libc/dns/dnsnamecmp.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/dns/dns.h" #include "libc/str/str.h" diff --git a/libc/dns/dnsquestion.h b/libc/dns/dnsquestion.h index bb916139..8463fd6c 100644 --- a/libc/dns/dnsquestion.h +++ b/libc/dns/dnsquestion.h @@ -1,8 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_DNS_DNSQUESTION_H_ #define COSMOPOLITAN_LIBC_DNS_DNSQUESTION_H_ -#ifndef __STRICT_ANSI__ -#include "libc/dns/dns.h" -#include "libc/sysv/errfuns.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -12,23 +9,8 @@ struct DnsQuestion { uint16_t qclass; }; -/** - * Serializes DNS question record to wire. - * - * @return number of bytes written - * @see pascalifydnsname() - */ -forceinline int serializednsquestion(uint8_t *buf, size_t size, - struct DnsQuestion dq) { - int wrote; - if ((wrote = pascalifydnsname(buf, size, dq.qname)) == -1) return -1; - if (wrote + 1 + 4 > size) return enospc(); - buf[wrote + 1] = dq.qtype >> 010, buf[wrote + 2] = dq.qtype >> 000; - buf[wrote + 3] = dq.qclass >> 010, buf[wrote + 4] = dq.qclass >> 000; - return wrote + 5; -} +int serializednsquestion(uint8_t *, size_t, struct DnsQuestion); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* !ANSI */ #endif /* COSMOPOLITAN_LIBC_DNS_DNSQUESTION_H_ */ diff --git a/libc/dns/getaddrinfo.c b/libc/dns/getaddrinfo.c index 6f523a74..dfeb175b 100644 --- a/libc/dns/getaddrinfo.c +++ b/libc/dns/getaddrinfo.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/conv/conv.h" #include "libc/dns/dns.h" diff --git a/libc/dns/gethoststxt.c b/libc/dns/gethoststxt.c index c4e2911c..129ef1f5 100644 --- a/libc/dns/gethoststxt.c +++ b/libc/dns/gethoststxt.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" #include "libc/bits/pushpop.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/dce.h" #include "libc/dns/hoststxt.h" #include "libc/fmt/fmt.h" diff --git a/libc/dns/getntnameservers.c b/libc/dns/getntnameservers.c index 8c1f4116..631e6908 100644 --- a/libc/dns/getntnameservers.c +++ b/libc/dns/getntnameservers.c @@ -17,11 +17,13 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/dns/dns.h" #include "libc/dns/resolvconf.h" +#include "libc/nt/enum/keyaccess.h" +#include "libc/nt/enum/reggetvalueflags.h" #include "libc/nt/registry.h" #include "libc/nt/runtime.h" #include "libc/runtime/runtime.h" diff --git a/libc/dns/parsehoststxt.c b/libc/dns/parsehoststxt.c index e5e68a3d..89c410e1 100644 --- a/libc/dns/parsehoststxt.c +++ b/libc/dns/parsehoststxt.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/dns/dns.h" #include "libc/dns/hoststxt.h" #include "libc/runtime/runtime.h" diff --git a/libc/dns/parseresolvconf.c b/libc/dns/parseresolvconf.c index c9fb116a..4085fcbf 100644 --- a/libc/dns/parseresolvconf.c +++ b/libc/dns/parseresolvconf.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/dns/dns.h" #include "libc/dns/resolvconf.h" #include "libc/mem/mem.h" diff --git a/libc/bits/bcxcpy.S b/libc/dns/serializednsquestion.c similarity index 71% rename from libc/bits/bcxcpy.S rename to libc/dns/serializednsquestion.c index b0ebaf25..1d70f421 100644 --- a/libc/bits/bcxcpy.S +++ b/libc/dns/serializednsquestion.c @@ -1,5 +1,5 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ @@ -17,38 +17,21 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.h" +#include "libc/dns/dns.h" +#include "libc/dns/dnsquestion.h" +#include "libc/sysv/errfuns.h" -bcxcpy: push %rbp - mov %rsp,%rbp - .profilable - push %rbx - xor %ebx,%ebx - lea -64(%rbp),%rdx - sub $24,%rsp -3: lea (,%rbx,4),%ecx - mov %rsi,%rax - shr %cl,%rax - and $15,%eax - cmp $9,%eax - lea 7(%rax),%ecx - cmova %ecx,%eax - add $48,%eax - mov %al,(%rdx,%rbx) - add $1,%rbx - cmp $16,%rbx - jne 3b - mov %rdx,%rax - lea -48(%rbp),%rcx - lea 15(%rdi),%rdx -4: movzbl (%rax),%ebx - add $1,%rax - sub $1,%rdx - mov %bl,1(%rdx) - cmp %rcx,%rax - jne 4b - add $24,%rsp - pop %rbx - pop %rbp - ret - .endfn bcxcpy,globl +/** + * Serializes DNS question record to wire. + * + * @return number of bytes written + * @see pascalifydnsname() + */ +int serializednsquestion(uint8_t *buf, size_t size, struct DnsQuestion dq) { + int wrote; + if ((wrote = pascalifydnsname(buf, size, dq.qname)) == -1) return -1; + if (wrote + 1 + 4 > size) return enospc(); + buf[wrote + 1] = dq.qtype >> 010, buf[wrote + 2] = dq.qtype >> 000; + buf[wrote + 3] = dq.qclass >> 010, buf[wrote + 4] = dq.qclass >> 000; + return wrote + 5; +} diff --git a/libc/dos.h b/libc/dos.h deleted file mode 100644 index d9a1a826..00000000 --- a/libc/dos.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_DOS_H_ -#define COSMOPOLITAN_LIBC_DOS_H_ -#include "libc/macros.h" - -/** - * @fileoverview MS-DOS Data Structures. - */ - -#define DOS_DATE(YEAR, MONTH_IDX1, DAY_IDX1) \ - (((YEAR)-1980) << 9 | (MONTH_IDX1) << 5 | (DAY_IDX1)) - -#define DOS_TIME(HOUR, MINUTE, SECOND) \ - ((HOUR) << 11 | (MINUTE) << 5 | (SECOND) >> 1) - -#endif /* COSMOPOLITAN_LIBC_DOS_H_ */ diff --git a/libc/bits/bcdadd.S b/libc/elf/checkelfaddress.c similarity index 78% rename from libc/bits/bcdadd.S rename to libc/elf/checkelfaddress.c index 11c99df3..1f3914f5 100644 --- a/libc/bits/bcdadd.S +++ b/libc/elf/checkelfaddress.c @@ -1,5 +1,5 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ @@ -17,22 +17,14 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.h" +#include "libc/elf/elf.h" +#include "libc/runtime/runtime.h" -/ Performs addition on binary-coded decimals. -bcdadd: .leafprologue - .profilable - lea 0x6666666(%rdi),%ecx - xor %esi,%ecx - lea (%rdi,%rsi),%eax - add $0x6666666,%eax - xor %eax,%ecx - not %ecx - and $0x11111110,%ecx - mov %ecx,%edx - shr $2,%edx - shr $3,%ecx - orl %edx,%ecx - sub %ecx,%eax - .leafepilogue - .endfn bcdadd,globl +void CheckElfAddress(const Elf64_Ehdr *elf, size_t mapsize, intptr_t addr, + size_t addrsize) { +#if !(TRUSTWORTHY + ELF_TRUSTWORTHY + 0) || ELF_UNTRUSTWORTHY + 0 + if (addr < (intptr_t)elf || addr + addrsize > (intptr_t)elf + mapsize) { + abort(); + } +#endif +} diff --git a/libc/elf/def.h b/libc/elf/def.h index 53cfeebd..e5362ca2 100644 --- a/libc/elf/def.h +++ b/libc/elf/def.h @@ -1,11 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_ELF_STRUCT_DEF_H_ #define COSMOPOLITAN_LIBC_ELF_STRUCT_DEF_H_ -#if 0 /** * @fileoverview Executable and Linkable Format Definitions. */ -#endif #define EI_MAG0 0 #define EI_MAG1 1 diff --git a/libc/elf/elf.h b/libc/elf/elf.h index 155dfa03..88fa7fd7 100644 --- a/libc/elf/elf.h +++ b/libc/elf/elf.h @@ -1,15 +1,10 @@ #ifndef COSMOPOLITAN_LIBC_ELF_H_ #define COSMOPOLITAN_LIBC_ELF_H_ -#ifndef __STRICT_ANSI__ -#include "libc/bits/safemacros.h" -#include "libc/elf/def.h" #include "libc/elf/struct/ehdr.h" #include "libc/elf/struct/phdr.h" #include "libc/elf/struct/shdr.h" #include "libc/elf/struct/sym.h" -#include "libc/limits.h" -#include "libc/runtime/runtime.h" -#include "libc/str/str.h" +#include "libc/runtime/ezmap.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -17,101 +12,20 @@ COSMOPOLITAN_C_START_ │ cosmopolitan § executable & linkable format ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -struct MappedFile; - -Elf64_Ehdr *mapelfread(const char *, struct MappedFile *); char *GetElfStringTable(const Elf64_Ehdr *, size_t); Elf64_Sym *GetElfSymbolTable(const Elf64_Ehdr *, size_t, Elf64_Xword *); bool IsElf64Binary(const Elf64_Ehdr *, size_t); - -forceinline void checkelfaddress(const Elf64_Ehdr *elf, size_t mapsize, - intptr_t addr, size_t addrsize) { -#if !(TRUSTWORTHY + ELF_TRUSTWORTHY + 0) || ELF_UNTRUSTWORTHY + 0 - if (addr < (intptr_t)elf || addr + addrsize > (intptr_t)elf + mapsize) { - abort(); - } -#endif -} - -static inline bool iselfsymbolcontent(const Elf64_Sym *sym) { - return sym->st_size > 0 && (ELF64_ST_TYPE(sym->st_info) == STT_FUNC || - ELF64_ST_TYPE(sym->st_info) == STT_OBJECT); -} - -static inline Elf64_Phdr *getelfsegmentheaderaddress(const Elf64_Ehdr *elf, - size_t mapsize, - unsigned i) { - intptr_t addr = - ((intptr_t)elf + (intptr_t)elf->e_phoff + (intptr_t)elf->e_phentsize * i); - checkelfaddress(elf, mapsize, addr, elf->e_phentsize); - return (Elf64_Phdr *)addr; -} - -static inline Elf64_Shdr *getelfsectionheaderaddress(const Elf64_Ehdr *elf, - size_t mapsize, - Elf64_Half i) { - intptr_t addr = - ((intptr_t)elf + (intptr_t)elf->e_shoff + (intptr_t)elf->e_shentsize * i); - checkelfaddress(elf, mapsize, addr, elf->e_shentsize); - return (Elf64_Shdr *)addr; -} - -static inline void *getelfsectionaddress(const Elf64_Ehdr *elf, size_t mapsize, - const Elf64_Shdr *shdr) { - intptr_t addr, size; - addr = (intptr_t)elf + (intptr_t)shdr->sh_offset; - size = (intptr_t)shdr->sh_size; - checkelfaddress(elf, mapsize, addr, size); - return (void *)addr; -} - -static inline char *getelfsectionnamestringtable(const Elf64_Ehdr *elf, - size_t mapsize) { - if (!elf->e_shoff || !elf->e_shentsize) return NULL; - return getelfsectionaddress( - elf, mapsize, getelfsectionheaderaddress(elf, mapsize, elf->e_shstrndx)); -} - -static inline void getelfvirtualaddressrange(const Elf64_Ehdr *elf, - size_t elfsize, - intptr_t *out_start, - intptr_t *out_end) { - unsigned i; - Elf64_Phdr *phdr; - intptr_t start, end, pstart, pend; - start = INTPTR_MAX; - end = 0; - for (i = 0; i < elf->e_phnum; ++i) { - phdr = getelfsegmentheaderaddress(elf, elfsize, i); - if (phdr->p_type != PT_LOAD) continue; - pstart = phdr->p_vaddr; - pend = phdr->p_vaddr + phdr->p_memsz; - if (pstart < start) start = pstart; - if (pend > end) end = pend; - } - if (out_start) *out_start = start; - if (out_end) *out_end = end; -} - -static inline char *GetElfString(const Elf64_Ehdr *elf, size_t mapsize, - const char *strtab, Elf64_Word rva) { - intptr_t addr = (intptr_t)strtab + rva; -#if !(TRUSTWORTHY + ELF_TRUSTWORTHY + 0) - checkelfaddress(elf, mapsize, addr, 0); - checkelfaddress(elf, mapsize, addr, - strnlen((char *)addr, (intptr_t)elf + mapsize - addr) + 1); -#endif - return (char *)addr; -} - -static inline const char *GetElfSectionName(const Elf64_Ehdr *elf, - size_t mapsize, Elf64_Shdr *shdr) { - if (!elf || !shdr) return NULL; - return GetElfString(elf, mapsize, getelfsectionnamestringtable(elf, mapsize), - shdr->sh_name); -} +void CheckElfAddress(const Elf64_Ehdr *, size_t, intptr_t, size_t); +bool IsElfSymbolContent(const Elf64_Sym *); +Elf64_Phdr *GetElfSegmentHeaderAddress(const Elf64_Ehdr *, size_t, unsigned); +Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half); +void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *); +char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t); +void GetElfVirtualAddressRange(const Elf64_Ehdr *, size_t, intptr_t *, + intptr_t *); +char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word); +const char *GetElfSectionName(const Elf64_Ehdr *, size_t, Elf64_Shdr *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* !ANSI */ #endif /* COSMOPOLITAN_LIBC_ELF_H_ */ diff --git a/libc/elf/getelfsectionaddress.c b/libc/elf/getelfsectionaddress.c new file mode 100644 index 00000000..4da614d9 --- /dev/null +++ b/libc/elf/getelfsectionaddress.c @@ -0,0 +1,29 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ │ +│ This program is free software; you can redistribute it and/or modify │ +│ it under the terms of the GNU General Public License as published by │ +│ the Free Software Foundation; version 2 of the License. │ +│ │ +│ This program is distributed in the hope that it will be useful, but │ +│ WITHOUT ANY WARRANTY; without even the implied warranty of │ +│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ +│ General Public License for more details. │ +│ │ +│ You should have received a copy of the GNU General Public License │ +│ along with this program; if not, write to the Free Software │ +│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ +│ 02110-1301 USA │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/elf/elf.h" + +void *GetElfSectionAddress(const Elf64_Ehdr *elf, size_t mapsize, + const Elf64_Shdr *shdr) { + intptr_t addr, size; + addr = (intptr_t)elf + (intptr_t)shdr->sh_offset; + size = (intptr_t)shdr->sh_size; + CheckElfAddress(elf, mapsize, addr, size); + return (void *)addr; +} diff --git a/libc/elf/getelfsectionheaderaddress.c b/libc/elf/getelfsectionheaderaddress.c new file mode 100644 index 00000000..43b4dfd7 --- /dev/null +++ b/libc/elf/getelfsectionheaderaddress.c @@ -0,0 +1,28 @@ +/*-*- 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 │ +│ │ +│ This program is free software; you can redistribute it and/or modify │ +│ it under the terms of the GNU General Public License as published by │ +│ the Free Software Foundation; version 2 of the License. │ +│ │ +│ This program is distributed in the hope that it will be useful, but │ +│ WITHOUT ANY WARRANTY; without even the implied warranty of │ +│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ +│ General Public License for more details. │ +│ │ +│ You should have received a copy of the GNU General Public License │ +│ along with this program; if not, write to the Free Software │ +│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ +│ 02110-1301 USA │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/elf/elf.h" + +Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *elf, size_t mapsize, + Elf64_Half i) { + intptr_t addr = + ((intptr_t)elf + (intptr_t)elf->e_shoff + (intptr_t)elf->e_shentsize * i); + CheckElfAddress(elf, mapsize, addr, elf->e_shentsize); + return (Elf64_Shdr *)addr; +} diff --git a/libc/elf/getelfsectionname.c b/libc/elf/getelfsectionname.c new file mode 100644 index 00000000..1adc7fad --- /dev/null +++ b/libc/elf/getelfsectionname.c @@ -0,0 +1,27 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ │ +│ This program is free software; you can redistribute it and/or modify │ +│ it under the terms of the GNU General Public License as published by │ +│ the Free Software Foundation; version 2 of the License. │ +│ │ +│ This program is distributed in the hope that it will be useful, but │ +│ WITHOUT ANY WARRANTY; without even the implied warranty of │ +│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ +│ General Public License for more details. │ +│ │ +│ You should have received a copy of the GNU General Public License │ +│ along with this program; if not, write to the Free Software │ +│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ +│ 02110-1301 USA │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/elf/elf.h" + +const char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize, + Elf64_Shdr *shdr) { + if (!elf || !shdr) return NULL; + return GetElfString(elf, mapsize, GetElfSectionNameStringTable(elf, mapsize), + shdr->sh_name); +} diff --git a/libc/elf/getelfsectionnamestringtable.c b/libc/elf/getelfsectionnamestringtable.c new file mode 100644 index 00000000..7d0e536a --- /dev/null +++ b/libc/elf/getelfsectionnamestringtable.c @@ -0,0 +1,26 @@ +/*-*- 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 │ +│ │ +│ This program is free software; you can redistribute it and/or modify │ +│ it under the terms of the GNU General Public License as published by │ +│ the Free Software Foundation; version 2 of the License. │ +│ │ +│ This program is distributed in the hope that it will be useful, but │ +│ WITHOUT ANY WARRANTY; without even the implied warranty of │ +│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ +│ General Public License for more details. │ +│ │ +│ You should have received a copy of the GNU General Public License │ +│ along with this program; if not, write to the Free Software │ +│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ +│ 02110-1301 USA │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/elf/elf.h" + +char *GetElfSectionNameStringTable(const Elf64_Ehdr *elf, size_t mapsize) { + if (!elf->e_shoff || !elf->e_shentsize) return NULL; + return GetElfSectionAddress( + elf, mapsize, GetElfSectionHeaderAddress(elf, mapsize, elf->e_shstrndx)); +} diff --git a/libc/elf/getelfsegmentheaderaddress.c b/libc/elf/getelfsegmentheaderaddress.c new file mode 100644 index 00000000..c5cb0077 --- /dev/null +++ b/libc/elf/getelfsegmentheaderaddress.c @@ -0,0 +1,28 @@ +/*-*- 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 │ +│ │ +│ This program is free software; you can redistribute it and/or modify │ +│ it under the terms of the GNU General Public License as published by │ +│ the Free Software Foundation; version 2 of the License. │ +│ │ +│ This program is distributed in the hope that it will be useful, but │ +│ WITHOUT ANY WARRANTY; without even the implied warranty of │ +│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ +│ General Public License for more details. │ +│ │ +│ You should have received a copy of the GNU General Public License │ +│ along with this program; if not, write to the Free Software │ +│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ +│ 02110-1301 USA │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/elf/elf.h" + +Elf64_Phdr *GetElfSegmentHeaderAddress(const Elf64_Ehdr *elf, size_t mapsize, + unsigned i) { + intptr_t addr = + ((intptr_t)elf + (intptr_t)elf->e_phoff + (intptr_t)elf->e_phentsize * i); + CheckElfAddress(elf, mapsize, addr, elf->e_phentsize); + return (Elf64_Phdr *)addr; +} diff --git a/libc/bits/bcd2i.S b/libc/elf/getelfstring.c similarity index 75% rename from libc/bits/bcd2i.S rename to libc/elf/getelfstring.c index 90b5f8b6..10486796 100644 --- a/libc/bits/bcd2i.S +++ b/libc/elf/getelfstring.c @@ -1,5 +1,5 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ @@ -17,26 +17,16 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.h" +#include "libc/elf/elf.h" +#include "libc/str/str.h" -/ Converts binary-coded-decimal to integer. -/ -/ @param rdi is the string copied into a word -bcd2i: .leafprologue - .profilable - test %rdi,%rdi - je 2f - mov $1,%ecx - xor %eax,%eax -1: mov %edi,%edx - and $15,%edx - imul %rcx,%rdx - add %rdx,%rax - add %rcx,%rcx - lea (%rcx,%rcx,4),%rcx - shr $4,%rdi - jne 1b - ret -2: xor %eax,%eax - .leafepilogue - .endfn bcd2i,globl +char *GetElfString(const Elf64_Ehdr *elf, size_t mapsize, const char *strtab, + Elf64_Word rva) { + intptr_t addr = (intptr_t)strtab + rva; +#if !(TRUSTWORTHY + ELF_TRUSTWORTHY + 0) + CheckElfAddress(elf, mapsize, addr, 0); + CheckElfAddress(elf, mapsize, addr, + strnlen((char *)addr, (intptr_t)elf + mapsize - addr) + 1); +#endif + return (char *)addr; +} diff --git a/libc/elf/getelfstringtable.c b/libc/elf/getelfstringtable.c index 365e895d..da28576c 100644 --- a/libc/elf/getelfstringtable.c +++ b/libc/elf/getelfstringtable.c @@ -25,9 +25,9 @@ char *GetElfStringTable(const Elf64_Ehdr *elf, size_t mapsize) { Elf64_Shdr *shdr; for (i = elf->e_shnum; i > 0; --i) { if (i - 1 == elf->e_shstrndx) continue; - shdr = getelfsectionheaderaddress(elf, mapsize, i - 1); + shdr = GetElfSectionHeaderAddress(elf, mapsize, i - 1); if (shdr->sh_type == SHT_STRTAB) { - return getelfsectionaddress(elf, mapsize, shdr); + return GetElfSectionAddress(elf, mapsize, shdr); } } return NULL; diff --git a/libc/elf/getelfsymboltable.c b/libc/elf/getelfsymboltable.c index f0e60765..0089bffd 100644 --- a/libc/elf/getelfsymboltable.c +++ b/libc/elf/getelfsymboltable.c @@ -25,11 +25,11 @@ Elf64_Sym *GetElfSymbolTable(const Elf64_Ehdr *elf, size_t mapsize, Elf64_Half i; Elf64_Shdr *shdr; for (i = elf->e_shnum; i > 0; --i) { - shdr = getelfsectionheaderaddress(elf, mapsize, i - 1); + shdr = GetElfSectionHeaderAddress(elf, mapsize, i - 1); if (shdr->sh_type == SHT_SYMTAB) { if (shdr->sh_entsize != sizeof(Elf64_Sym)) continue; if (out_count) *out_count = shdr->sh_size / shdr->sh_entsize; - return getelfsectionaddress(elf, mapsize, shdr); + return GetElfSectionAddress(elf, mapsize, shdr); } } return NULL; diff --git a/libc/elf/getelfvirtualaddressrange.c b/libc/elf/getelfvirtualaddressrange.c new file mode 100644 index 00000000..43d2fb71 --- /dev/null +++ b/libc/elf/getelfvirtualaddressrange.c @@ -0,0 +1,40 @@ +/*-*- 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 │ +│ │ +│ This program is free software; you can redistribute it and/or modify │ +│ it under the terms of the GNU General Public License as published by │ +│ the Free Software Foundation; version 2 of the License. │ +│ │ +│ This program is distributed in the hope that it will be useful, but │ +│ WITHOUT ANY WARRANTY; without even the implied warranty of │ +│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ +│ General Public License for more details. │ +│ │ +│ You should have received a copy of the GNU General Public License │ +│ along with this program; if not, write to the Free Software │ +│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ +│ 02110-1301 USA │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/elf/elf.h" +#include "libc/limits.h" + +void GetElfVirtualAddressRange(const Elf64_Ehdr *elf, size_t elfsize, + intptr_t *out_start, intptr_t *out_end) { + unsigned i; + Elf64_Phdr *phdr; + intptr_t start, end, pstart, pend; + start = INTPTR_MAX; + end = 0; + for (i = 0; i < elf->e_phnum; ++i) { + phdr = GetElfSegmentHeaderAddress(elf, elfsize, i); + if (phdr->p_type != PT_LOAD) continue; + pstart = phdr->p_vaddr; + pend = phdr->p_vaddr + phdr->p_memsz; + if (pstart < start) start = pstart; + if (pend > end) end = pend; + } + if (out_start) *out_start = start; + if (out_end) *out_end = end; +} diff --git a/libc/elf/iself64binary.c b/libc/elf/iself64binary.c index c45717f3..856444c4 100644 --- a/libc/elf/iself64binary.c +++ b/libc/elf/iself64binary.c @@ -18,6 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/elf/elf.h" +#include "libc/str/str.h" bool IsElf64Binary(const Elf64_Ehdr *elf, size_t mapsize) { if (mapsize < sizeof(Elf64_Ehdr)) return false; diff --git a/libc/elf/iselfsymbolcontent.c b/libc/elf/iselfsymbolcontent.c new file mode 100644 index 00000000..33114421 --- /dev/null +++ b/libc/elf/iselfsymbolcontent.c @@ -0,0 +1,25 @@ +/*-*- 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 │ +│ │ +│ This program is free software; you can redistribute it and/or modify │ +│ it under the terms of the GNU General Public License as published by │ +│ the Free Software Foundation; version 2 of the License. │ +│ │ +│ This program is distributed in the hope that it will be useful, but │ +│ WITHOUT ANY WARRANTY; without even the implied warranty of │ +│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ +│ General Public License for more details. │ +│ │ +│ You should have received a copy of the GNU General Public License │ +│ along with this program; if not, write to the Free Software │ +│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ +│ 02110-1301 USA │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/elf/elf.h" + +bool IsElfSymbolContent(const Elf64_Sym *sym) { + return sym->st_size > 0 && (ELF64_ST_TYPE(sym->st_info) == STT_FUNC || + ELF64_ST_TYPE(sym->st_info) == STT_OBJECT); +} diff --git a/libc/fmt/bing.c b/libc/fmt/bing.c index d2ad4db8..aab1a120 100644 --- a/libc/fmt/bing.c +++ b/libc/fmt/bing.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/str/str.h" /** diff --git a/libc/fmt/bing.h b/libc/fmt/bing.internal.h similarity index 100% rename from libc/fmt/bing.h rename to libc/fmt/bing.internal.h diff --git a/libc/fmt/palandftoa.c b/libc/fmt/palandftoa.c index fa3bbff9..7d109f98 100644 --- a/libc/fmt/palandftoa.c +++ b/libc/fmt/palandftoa.c @@ -31,7 +31,7 @@ │ be thread safe). │ └─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/paland.inc" -#include "libc/fmt/palandprintf.h" +#include "libc/fmt/palandprintf.internal.h" #include "libc/math.h" /** diff --git a/libc/fmt/palandntoa.c b/libc/fmt/palandntoa.c index 2b06158d..29cd80a5 100644 --- a/libc/fmt/palandntoa.c +++ b/libc/fmt/palandntoa.c @@ -27,7 +27,7 @@ #include "libc/assert.h" #include "libc/conv/conv.h" #include "libc/fmt/paland.inc" -#include "libc/fmt/palandprintf.h" +#include "libc/fmt/palandprintf.internal.h" uintmax_t __udivmodti4(uintmax_t, uintmax_t, uintmax_t *); diff --git a/libc/fmt/palandprintf.c b/libc/fmt/palandprintf.c index bf73e7fc..9ffbd1ba 100644 --- a/libc/fmt/palandprintf.c +++ b/libc/fmt/palandprintf.c @@ -41,7 +41,7 @@ #include "libc/conv/conv.h" #include "libc/fmt/fmt.h" #include "libc/fmt/paland.inc" -#include "libc/fmt/palandprintf.h" +#include "libc/fmt/palandprintf.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/internal.h" #include "libc/str/str.h" diff --git a/libc/fmt/palandprintf.h b/libc/fmt/palandprintf.internal.h similarity index 100% rename from libc/fmt/palandprintf.h rename to libc/fmt/palandprintf.internal.h diff --git a/libc/fmt/pflink.h b/libc/fmt/pflink.h index 0fcfd8a6..278a63a3 100644 --- a/libc/fmt/pflink.h +++ b/libc/fmt/pflink.h @@ -1,8 +1,8 @@ #ifndef COSMOPOLITAN_LIBC_FMT_PFLINK_H_ #define COSMOPOLITAN_LIBC_FMT_PFLINK_H_ +#include "libc/dce.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) #ifndef __STRICT_ANSI__ -#include "libc/dce.h" /** * @fileoverview builtin+preprocessor+linker tricks for printf/scanf. @@ -37,7 +37,7 @@ STATIC_YOINK("malloc"); \ STATIC_YOINK("calloc"); \ STATIC_YOINK("free_s"); \ - STATIC_YOINK("grow"); \ + STATIC_YOINK("__grow"); \ } \ FMT; \ }) diff --git a/libc/fmt/spacepad.c b/libc/fmt/spacepad.c index 9121e382..b9644650 100644 --- a/libc/fmt/spacepad.c +++ b/libc/fmt/spacepad.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/fmt/palandprintf.h" +#include "libc/fmt/palandprintf.internal.h" int spacepad(int out(long, void *), void *arg, unsigned long n) { int i, rc; diff --git a/libc/fmt/stoa.c b/libc/fmt/stoa.c index 4f93c837..f4e209e7 100644 --- a/libc/fmt/stoa.c +++ b/libc/fmt/stoa.c @@ -19,8 +19,8 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/weaken.h" #include "libc/fmt/paland.inc" -#include "libc/fmt/palandprintf.h" -#include "libc/nexgen32e/tinystrlen.h" +#include "libc/fmt/palandprintf.internal.h" +#include "libc/nexgen32e/tinystrlen.internal.h" #include "libc/str/str.h" #include "libc/str/thompike.h" #include "libc/str/tpenc.h" diff --git a/libc/fmt/strerror_r.c b/libc/fmt/strerror_r.c index 739871b4..3ccd3973 100644 --- a/libc/fmt/strerror_r.c +++ b/libc/fmt/strerror_r.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" diff --git a/libc/fmt/typefmt.h b/libc/fmt/typefmt.h deleted file mode 100644 index 3c0e0f5e..00000000 --- a/libc/fmt/typefmt.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_FMT_TYPEFMT_H_ -#define COSMOPOLITAN_LIBC_FMT_TYPEFMT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -/** - * Returns printf directive to format scalar type of expression. - * - * @see TYPE_NAME() - */ -#define TYPE_FMT(X, DXOB, UXOB) \ - _Generic((X), long double \ - : "Lf", double \ - : "f", float \ - : "f", char \ - : "c", signed char \ - : "hh" DXOB, unsigned char \ - : "hh" UXOB, short \ - : "h" DXOB, unsigned short \ - : "h" UXOB, int \ - : DXOB, unsigned \ - : UXOB, long \ - : "l" DXOB, unsigned long \ - : "l" UXOB) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_FMT_TYPEFMT_H_ */ diff --git a/libc/fmt/unbing.c b/libc/fmt/unbing.c index 5c54df91..39c649e6 100644 --- a/libc/fmt/unbing.c +++ b/libc/fmt/unbing.c @@ -76,7 +76,7 @@ static textstartup void g_cp437i_init() { unsigned i; for (i = 0; i < 256; ++i) g_cp437i[i] = kCp437[i] << 8 | i; memcpy(g_cp437i + 256, kCp437iMultimappings, sizeof(kCp437iMultimappings)); - djbsort(ARRAYLEN(g_cp437i), g_cp437i); + djbsort(g_cp437i, ARRAYLEN(g_cp437i)); } const void *const g_cp437i_ctor[] initarray = {g_cp437i_init}; diff --git a/libc/fmt/unhexbuf.c b/libc/fmt/unhexbuf.c index 75e61617..a3529621 100644 --- a/libc/fmt/unhexbuf.c +++ b/libc/fmt/unhexbuf.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/str/str.h" void *unhexbuf(void *buf, size_t size, const char *hexdigs) { diff --git a/libc/fmt/vcscanf.c b/libc/fmt/vcscanf.c index 52760ad7..2ca4ebcf 100644 --- a/libc/fmt/vcscanf.c +++ b/libc/fmt/vcscanf.c @@ -22,8 +22,9 @@ #include "libc/fmt/fmt.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" -#include "libc/str/tpdecodecb.h" +#include "libc/str/tpdecodecb.internal.h" #include "libc/sysv/errfuns.h" /** @@ -232,7 +233,7 @@ int vcscanf(int callback(void *), void *arg, const char *fmt, va_list va) { size_t j = 0; for (;;) { if (ismalloc && !width && j + 2 + 1 >= bufsize && - !weaken(grow)(&buf, &bufsize, charbytes, 0)) { + !weaken(__grow)(&buf, &bufsize, charbytes, 0)) { width = bufsize - 1; } if (c != -1 && j + !rawmode < bufsize && (rawmode || !isspace(c))) { diff --git a/libc/fmt/vsnprintf.c b/libc/fmt/vsnprintf.c index 8f29f083..4d8d844a 100644 --- a/libc/fmt/vsnprintf.c +++ b/libc/fmt/vsnprintf.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/dce.h" #include "libc/fmt/fmt.h" #include "libc/limits.h" diff --git a/libc/integral/c.inc b/libc/integral/c.inc index 34da759e..d1cd9a46 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -804,16 +804,6 @@ typedef uint64_t uintmax_t; do { \ } while (0) -/** - * Makes one-line for-statements possible w/o formatter/linter drama. - * @note Python uses this keyword - */ -#define /* TODO(jart): delete */ pass FUIX MOE BROKEN a int a c int - -#ifndef assume -#define /* TODO(jart): delete */ assume(x) __builtin_assume(x) -#endif - #ifndef likely #define likely(expr) __builtin_expect(!!(expr), 1) #endif diff --git a/libc/internal/outofsight.h b/libc/internal/outofsight.h deleted file mode 100644 index ff84431e..00000000 --- a/libc/internal/outofsight.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTERNAL_OUTOFSIGHT_H_ -#define COSMOPOLITAN_LIBC_INTERNAL_OUTOFSIGHT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -#if 0 -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § standard library » little concerns ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ -#endif - -#if 0 -/** - * Hardware-Accellerated 32-Bit Castagnoli Cyclic Redundancy Check. - * Introduced w/ Intel Nehalem c. 2008 & AMD Bulldozer c. 2011 - * @see crc32c() - */ -#endif -#define __crc32c(out_Gdqp, in_Eb_Evqp) \ - asm("crc32\t%1,%0" : "+r"(*(r)) : "rm"(p)) - -#if 0 -/** - * Works around GCC's poorly implemented -Waddress feature. - * Used for the well-known divide-by-zero static assertion. - */ -#endif -#define __NOTNOT(ADDR) ((uintptr_t)(ADDR) != (uintptr_t)NULL ? 1 : 0) -#define __LITERALLY_STRING(S) (typeof(&S[0]))((uintptr_t)(S) / __NOTNOT(S)) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTERNAL_OUTOFSIGHT_H_ */ diff --git a/libc/isystem/unistd.h b/libc/isystem/unistd.h index c1776edb..6562dea9 100644 --- a/libc/isystem/unistd.h +++ b/libc/isystem/unistd.h @@ -1,6 +1,5 @@ #ifndef LIBC_ISYSTEM_UNISTD_H_ #define LIBC_ISYSTEM_UNISTD_H_ -#include "libc/calls/openbsd.h" #include "libc/calls/calls.h" #include "libc/calls/weirdtypes.h" #include "libc/sysv/consts/fileno.h" diff --git a/libc/isystem/windows.h b/libc/isystem/windows.h index 8d14c7ba..399a9c9b 100644 --- a/libc/isystem/windows.h +++ b/libc/isystem/windows.h @@ -446,22 +446,22 @@ #define PFILE_END_OF_FILE_INFORMATION struct FileEndOfFileInformation* #define _GET_FILEEX_INFO_LEVELS NtGetFileexInfoLevels -#define GET_FILEEX_INFO_LEVELS struct NtGetFileexInfoLevels -#define LPGET_FILEEX_INFO_LEVELS struct NtGetFileexInfoLevels* +#define GET_FILEEX_INFO_LEVELS int +#define LPGET_FILEEX_INFO_LEVELS int* #define _WIN32_FIND_DATA NtWin32FindData #define WIN32_FIND_DATA struct NtWin32FindData #define LPWIN32_FIND_DATA struct NtWin32FindData* #define _FINDEX_INFO_LEVELS NtFindexInfoLevels -#define FINDEX_INFO_LEVELS enum NtFindexInfoLevels +#define FINDEX_INFO_LEVELS int #define FindExInfoStandard kNtFindExInfoStandard #define FindExInfoBasic kNtFindExInfoBasic #define FindExInfoMaxInfoLevel kNtFindExInfoMaxInfoLevel #define FIND_FIRST_EX_CASE_SENSITIVE kNtFindFirstExCaseSensitive #define FIND_FIRST_EX_LARGE_FETCH kNtFindFirstExLargeFetch #define _FINDEX_SEARCH_OPS NtFindexSearchOps -#define FINDEX_SEARCH_OPS enum NtFindexSearchOps +#define FINDEX_SEARCH_OPS int #define FindExSearchNameMatch kNtFindExSearchNameMatch #define FindExSearchLimitToDirectories kNtFindExSearchLimitToDirectories #define FindExSearchLimitToDevices kNtFindExSearchLimitToDevices @@ -477,7 +477,7 @@ #define MOVEFILE_FAIL_IF_NOT_TRACKABLE kNtMovefileFailIfNotTrackable #define MOVEFILE_WRITE_THROUGH kNtMovefileWriteThrough -#define OFFER_PRIORITY enum NtOfferPriority +#define OFFER_PRIORITY int #define VmOfferPriorityVeryLow kNtVmOfferPriorityVeryLow #define VmOfferPriorityLow kNtVmOfferPriorityLow #define VmOfferPriorityBelowNormal kNtVmOfferPriorityBelowNormal @@ -486,20 +486,20 @@ #define _KWAIT_REASON uint32_t #define KWAIT_REASON uint32_t #define _OBJECT_INFORMATION_CLASS NtObjectInformationClass -#define OBJECT_INFORMATION_CLASS enum NtObjectInformationClass +#define OBJECT_INFORMATION_CLASS int #define _PROCESSINFOCLASS NtProcessinfoclass -#define PROCESSINFOCLASS enum NtProcessinfoclass +#define PROCESSINFOCLASS int #define _THREAD_STATE NtThreadState -#define THREAD_STATE enum NtThreadState +#define THREAD_STATE int #define _TOKEN_TYPE NtTokenType -#define TOKEN_TYPE enum NtTokenType +#define TOKEN_TYPE int #define _THREADINFOCLASS Nthreadinfoclass -#define THREADINFOCLASS enum Nthreadinfoclass +#define THREADINFOCLASS int #define _THREAD_INFORMATION_CLASS NtThreadInformationClass -#define THREAD_INFORMATION_CLASS enum NtThreadInformationClass -#define PTHREAD_INFORMATION_CLASS enum NtThreadInformationClass* +#define THREAD_INFORMATION_CLASS int +#define PTHREAD_INFORMATION_CLASS int* #define OWNER_SECURITY_INFORMATION kNtOwnerSecurityInformation #define GROUP_SECURITY_INFORMATION kNtGroupSecurityInformation @@ -1219,9 +1219,9 @@ #define PAFPROTOCOLS struct NtAfProtocols* #define LPAFPROTOCOLS struct NtAfProtocols* -#define WSAECOMPARATOR enum NtWsaEComparator -#define PWSAECOMPARATOR enum NtWsaEComparator* -#define LPWSAECOMPARATOR enum NtWsaEComparator* +#define WSAECOMPARATOR int +#define PWSAECOMPARATOR int* +#define LPWSAECOMPARATOR int* #define WSANETWORKEVENTS struct NtWsaNetworkEvents #define PWSANETWORKEVENTS struct NtWsaNetworkEvents* @@ -1299,9 +1299,9 @@ #define LPCONDITIONPROC NtConditionProc #define LPWSAOVERLAPPED_COMPLETION_ROUTINE NtWsaOverlappedCompletionRoutine -#define WSACOMPLETIONTYPE enum NtWsaCompletionType -#define PWSACOMPLETIONTYPE enum NtWsaCompletionType* -#define LPWSACOMPLETIONTYPE enum NtWsaCompletionType* +#define WSACOMPLETIONTYPE int +#define PWSACOMPLETIONTYPE int* +#define LPWSACOMPLETIONTYPE int* #define NSP_NOTIFY_IMMEDIATELY kNtNspNotifyImmediately #define NSP_NOTIFY_HWND kNtNspNotifyHwnd #define NSP_NOTIFY_EVENT kNtNspNotifyEvent diff --git a/libc/log/asan.c b/libc/log/asan.c index cf70367e..580eca4b 100644 --- a/libc/log/asan.c +++ b/libc/log/asan.c @@ -17,20 +17,22 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/safemacros.internal.h" #include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/conv/itoa.h" -#include "libc/log/asan.h" -#include "libc/log/backtrace.h" +#include "libc/log/asan.internal.h" +#include "libc/log/backtrace.internal.h" #include "libc/log/log.h" #include "libc/mem/hook/hook.h" #include "libc/runtime/directmap.h" #include "libc/runtime/memtrack.h" #include "libc/runtime/runtime.h" +#include "libc/str/str.h" #include "libc/sysv/consts/fileno.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" STATIC_YOINK("_init_asan"); @@ -147,7 +149,7 @@ static const char *__asan_describe_access_poison(int c) { static noreturn void __asan_die(const char *msg, size_t size) { write(STDERR_FILENO, msg, size); - die(); + __die(); } static char *__asan_report_start(char *p) { diff --git a/libc/log/asan.h b/libc/log/asan.internal.h similarity index 100% rename from libc/log/asan.h rename to libc/log/asan.internal.h diff --git a/libc/log/attachdebugger.c b/libc/log/attachdebugger.c index 6c17ed00..8ab048c3 100644 --- a/libc/log/attachdebugger.c +++ b/libc/log/attachdebugger.c @@ -17,17 +17,17 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" #include "libc/fmt/fmt.h" #include "libc/log/gdb.h" #include "libc/log/log.h" #include "libc/nexgen32e/stackframe.h" -#include "libc/nexgen32e/vendor.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/paths.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/fileno.h" diff --git a/libc/log/backtrace.h b/libc/log/backtrace.internal.h similarity index 91% rename from libc/log/backtrace.h rename to libc/log/backtrace.internal.h index eb16ea3b..bcd42356 100644 --- a/libc/log/backtrace.h +++ b/libc/log/backtrace.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_LOG_BACKTRACE_H_ #define COSMOPOLITAN_LIBC_LOG_BACKTRACE_H_ #include "libc/nexgen32e/stackframe.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/log/backtrace2.c b/libc/log/backtrace2.c index 5eaf1081..23ce7d79 100644 --- a/libc/log/backtrace2.c +++ b/libc/log/backtrace2.c @@ -18,19 +18,19 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/bisectcarleft.h" -#include "libc/bits/safemacros.h" +#include "libc/alg/bisectcarleft.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" #include "libc/conv/conv.h" #include "libc/dce.h" #include "libc/fmt/fmt.h" -#include "libc/log/backtrace.h" +#include "libc/log/backtrace.internal.h" #include "libc/log/log.h" -#include "libc/nexgen32e/gc.h" +#include "libc/nexgen32e/gc.internal.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" #include "libc/str/str.h" #include "libc/sysv/consts/fileno.h" @@ -55,14 +55,14 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) { argv[i++] = "-a"; /* filter out w/ shell script wrapper for old versions */ argv[i++] = "-pCife"; argv[i++] = debugbin; - garbage = weaken(g_garbage); + garbage = weaken(__garbage); gi = garbage ? garbage->i : 0; for (frame = bp; frame && i < kBacktraceMaxFrames - 1; frame = frame->next) { addr = frame->addr; - if (addr == weakaddr("CollectGarbage")) { + if (addr == weakaddr("__gc")) { do { --gi; - } while ((addr = garbage->p[gi].ret) == weakaddr("CollectGarbage")); + } while ((addr = garbage->p[gi].ret) == weakaddr("__gc")); } argv[i++] = &buf[j]; j += snprintf(&buf[j], 17, "%#x", addr - 1) + 1; diff --git a/libc/log/backtrace3.c b/libc/log/backtrace3.c index c123085c..9daf559a 100644 --- a/libc/log/backtrace3.c +++ b/libc/log/backtrace3.c @@ -17,18 +17,18 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/bisectcarleft.h" +#include "libc/alg/bisectcarleft.internal.h" #include "libc/assert.h" #include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/conv/itoa.h" #include "libc/fmt/fmt.h" -#include "libc/log/backtrace.h" +#include "libc/log/backtrace.internal.h" #include "libc/macros.h" -#include "libc/nexgen32e/gc.h" +#include "libc/nexgen32e/gc.internal.h" #include "libc/nexgen32e/stackframe.h" -#include "libc/runtime/missioncritical.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/runtime.h" +#include "libc/runtime/symbols.internal.h" #include "libc/str/str.h" /** @@ -53,14 +53,14 @@ int PrintBacktraceUsingSymbols(int fd, const struct StackFrame *bp, const struct StackFrame *frame; if (!st) return -1; if (!bp) bp = __builtin_frame_address(0); - garbage = weaken(g_garbage); + garbage = weaken(__garbage); gi = garbage ? garbage->i : 0; for (frame = bp; frame; frame = frame->next) { addr = frame->addr; - if (addr == weakaddr("CollectGarbage")) { + if (addr == weakaddr("__gc")) { do { --gi; - } while ((addr = garbage->p[gi].ret) == weakaddr("CollectGarbage")); + } while ((addr = garbage->p[gi].ret) == weakaddr("__gc")); } p = buf; p = mempcpy(p, ibuf, uint64toarray_fixed16((intptr_t)frame, ibuf, 48)); diff --git a/libc/log/cancolor.c b/libc/log/cancolor.c index 25618fc8..bc697dcf 100644 --- a/libc/log/cancolor.c +++ b/libc/log/cancolor.c @@ -26,7 +26,7 @@ #include "libc/nt/enum/filetype.h" #include "libc/nt/enum/version.h" #include "libc/nt/files.h" -#include "libc/nt/pedef.h" +#include "libc/nt/pedef.internal.h" #include "libc/nt/runtime.h" #include "libc/nt/struct/teb.h" #include "libc/runtime/runtime.h" diff --git a/libc/log/checkaligned.c b/libc/log/checkaligned.c index bf73f438..9697f669 100644 --- a/libc/log/checkaligned.c +++ b/libc/log/checkaligned.c @@ -31,5 +31,5 @@ void __check_fail_aligned(unsigned bytes, uint64_t ptr) { if (!IsTiny()) memsummary(fileno(stderr)); (dprintf)(fileno(stderr), "%s%d%s%#p\r\n", "error: pointer not ", bytes, "-byte aligned: ", ptr); - die(); + __die(); } diff --git a/libc/log/checkfail.c b/libc/log/checkfail.c index 0f8eba1d..9e812ff6 100644 --- a/libc/log/checkfail.c +++ b/libc/log/checkfail.c @@ -18,13 +18,13 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/log/check.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/log/log.h" #include "libc/runtime/memtrack.h" @@ -81,6 +81,6 @@ relegated void __check_fail(const char *suffix, const char *opstr, PrintMemoryIntervals(STDERR_FILENO, &_mmi); } - die(); + __die(); unreachable; } diff --git a/libc/log/checkfail_ndebug.c b/libc/log/checkfail_ndebug.c index f2cd56ff..27d9d860 100644 --- a/libc/log/checkfail_ndebug.c +++ b/libc/log/checkfail_ndebug.c @@ -21,7 +21,7 @@ #include "libc/errno.h" #include "libc/log/internal.h" #include "libc/log/log.h" -#include "libc/runtime/missioncritical.h" +#include "libc/runtime/runtime.h" /** * Handles failure of CHECK_xx() macros in -DNDEBUG mode. diff --git a/libc/log/color.h b/libc/log/color.internal.h similarity index 100% rename from libc/log/color.h rename to libc/log/color.internal.h diff --git a/libc/log/commandvenv.c b/libc/log/commandvenv.c index 538c91f7..a5fd8f6e 100644 --- a/libc/log/commandvenv.c +++ b/libc/log/commandvenv.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/log/log.h" #include "libc/mem/mem.h" diff --git a/libc/log/die.c b/libc/log/die.c index bbd5082d..36055221 100644 --- a/libc/log/die.c +++ b/libc/log/die.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/log/backtrace.h" +#include "libc/log/backtrace.internal.h" #include "libc/log/log.h" #include "libc/runtime/internal.h" #include "libc/stdio/stdio.h" @@ -28,7 +28,7 @@ /** * Aborts process after printing details on its current state. */ -relegated noreturn void die(void) { +relegated noreturn void __die(void) { static bool once; if (!once) { once = true; diff --git a/libc/log/gdb.h b/libc/log/gdb.h index d8323191..15d65b3e 100644 --- a/libc/log/gdb.h +++ b/libc/log/gdb.h @@ -1,12 +1,20 @@ #ifndef COSMOPOLITAN_LIBC_LOG_GDB_H_ #define COSMOPOLITAN_LIBC_LOG_GDB_H_ #include "libc/calls/calls.h" -#include "libc/runtime/missioncritical.h" +#include "libc/calls/wait4.h" #include "libc/sysv/consts/nr.h" #include "libc/sysv/consts/w.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +/** + * @fileoverview GDB Attach Support Code. + * + * The goal of these macros is to make the backtrace into the failing + * code as short as possible. It also helps avoid GDB getting confused + * about how we don't use its readability destroying unwind directives. + */ + extern volatile int g_gdbsync; int gdbexec(const char *); @@ -15,21 +23,37 @@ int attachdebugger(intptr_t); #define attachdebugger(CONTINUE_TO_ADDR) /* shorten backtraces */ \ SYNCHRONIZE_DEBUGGER((attachdebugger)(CONTINUE_TO_ADDR)) -#define SYNCHRONIZE_DEBUGGER(PID) \ - ({ \ - int Rc, Pid = (PID); \ - if (Pid != -1) { \ - while ((Rc = WAIT4(Pid, NULL, WNOHANG, NULL)) == 0) { \ - if (g_gdbsync) { \ - g_gdbsync = 0; \ - if (Rc > 0) Pid = 0; \ - break; \ - } else { \ - SCHED_YIELD(); \ - } \ - } \ - } \ - Pid; \ +#define SYNCHRONIZE_DEBUGGER(PID) \ + ({ \ + int Rc, Pid = (PID); \ + if (Pid != -1) { \ + while ((Rc = __inline_wait4(Pid, NULL, WNOHANG, NULL)) == 0) { \ + if (g_gdbsync) { \ + g_gdbsync = 0; \ + if (Rc > 0) Pid = 0; \ + break; \ + } else { \ + sched_yield(); \ + } \ + } \ + } \ + Pid; \ + }) + +#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE) \ + ({ \ + int64_t WaAx; \ + if (!IsWindows()) { \ + register void *Reg10 asm("r10") = (OPT_OUT_RUSAGE); \ + asm volatile("syscall" \ + : "=a"(WaAx) \ + : "0"(__NR_wait4), "D"(PID), "S"(OPT_OUT_WSTATUS), \ + "d"(OPTIONS), "r"(Reg10) \ + : "rcx", "r11", "cc", "memory"); \ + } else { \ + WaAx = wait4$nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \ + } \ + WaAx; \ }) COSMOPOLITAN_C_END_ diff --git a/libc/log/gdbexec.c b/libc/log/gdbexec.c index 9eba4558..dcf49f99 100644 --- a/libc/log/gdbexec.c +++ b/libc/log/gdbexec.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" #include "libc/fmt/fmt.h" @@ -25,7 +25,7 @@ #include "libc/log/log.h" #include "libc/nexgen32e/stackframe.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" /** * Attachs GDB temporarilly, to do something like print a variable. diff --git a/libc/log/getsymboltable.c b/libc/log/getsymboltable.c index 654971cd..56d9d53f 100644 --- a/libc/log/getsymboltable.c +++ b/libc/log/getsymboltable.c @@ -18,7 +18,8 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/runtime.h" +#include "libc/runtime/symbols.internal.h" /** * Returns debug binary symbol table, as global singleton. diff --git a/libc/log/getttysize.c b/libc/log/getttysize.c index 6cf953a0..ae216e7e 100644 --- a/libc/log/getttysize.c +++ b/libc/log/getttysize.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/termios.h" #include "libc/conv/conv.h" diff --git a/libc/log/isterminalinarticulate.c b/libc/log/isterminalinarticulate.c index 5f68cdf7..5bc869cb 100644 --- a/libc/log/isterminalinarticulate.c +++ b/libc/log/isterminalinarticulate.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/log/log.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" diff --git a/libc/log/log.h b/libc/log/log.h index cde968f9..b2b407b7 100644 --- a/libc/log/log.h +++ b/libc/log/log.h @@ -34,7 +34,7 @@ typedef struct FILE FILE; extern FILE *g_logfile; void perror(const char *) relegated; /* print the last system error */ -void die(void) relegated noreturn; /* print backtrace and abort() */ +void __die(void) relegated noreturn; /* print backtrace and abort() */ void meminfo(int); /* shows malloc statistics &c. */ void memsummary(int); /* light version of same thing */ uint16_t getttycols(uint16_t); diff --git a/libc/log/logfile.initabi.c b/libc/log/logfile.initabi.c index 0107b73d..6f013714 100644 --- a/libc/log/logfile.initabi.c +++ b/libc/log/logfile.initabi.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/stdio/stdio.h" FILE *g_logfile; diff --git a/libc/log/malloc_stats.c b/libc/log/malloc_stats.c index a8029901..bfe1367e 100644 --- a/libc/log/malloc_stats.c +++ b/libc/log/malloc_stats.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "libc/stdio/stdio.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" STATIC_YOINK("ntoa"); diff --git a/libc/log/oncrash.c b/libc/log/oncrash.c index c5a608f8..94f32d89 100644 --- a/libc/log/oncrash.c +++ b/libc/log/oncrash.c @@ -22,9 +22,10 @@ #include "libc/calls/struct/utsname.h" #include "libc/calls/ucontext.h" #include "libc/dce.h" +#include "libc/errno.h" #include "libc/fmt/fmt.h" -#include "libc/log/backtrace.h" -#include "libc/log/color.h" +#include "libc/log/backtrace.internal.h" +#include "libc/log/color.internal.h" #include "libc/log/gdb.h" #include "libc/log/internal.h" #include "libc/log/log.h" @@ -126,7 +127,7 @@ relegated static void ShowGeneralRegisters(int fd, ucontext_t *ctx) { relegated static void ShowSseRegisters(int fd, ucontext_t *ctx) { size_t i; - write(fd, "\r\n", 2); + write(fd, "\r\n\r\n", 4); for (i = 0; i < 8; ++i) { (dprintf)(fd, VEIL("r", "%s%-2zu %016lx%016lx %s%-2d %016lx%016lx\r\n"), "XMM", i + 0, ctx->fpustate.xmm[i + 0].u64[0], diff --git a/libc/log/perror.c b/libc/log/perror.c index ed5a6a5d..6adf2e3d 100644 --- a/libc/log/perror.c +++ b/libc/log/perror.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/fmt/fmt.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/log/log.h" #include "libc/runtime/runtime.h" diff --git a/libc/log/shadowargs.greg.c b/libc/log/shadowargs.greg.c deleted file mode 100644 index 0cc01162..00000000 --- a/libc/log/shadowargs.greg.c +++ /dev/null @@ -1,58 +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 │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/log/log.h" -#include "libc/log/shadowargs.h" -#include "libc/runtime/internal.h" -#include "libc/runtime/symbols.h" - -alignas(1) const - char __shadowargs_slotnames[SHADOWARGS_SLOTS][SHADOWARGS_MAXNAME] = { - "func", "%rsp", "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9", -}; -alignas(64) struct ShadowArgs __shadowargs[SHADOWARGS_COUNT]; -unsigned __shadowargs_index; - -nocallersavedregisters void __fentry__(uint64_t rdi, uint64_t rsi, uint64_t rdx, - uint64_t rcx, uint64_t r8, uint64_t r9) { - void *addr = __builtin_return_address(0); - intptr_t frame = (intptr_t)__builtin_frame_address(0); - unsigned i = __shadowargs_index; - intptr_t lastframe = (intptr_t)__shadowargs[i].frame; - if (frame < lastframe) { - i--; - i &= SHADOWARGS_COUNT - 1; - } else if (frame > lastframe) { - unsigned j = i; - do { - j++; - j &= SHADOWARGS_COUNT - 1; - } while (frame > (intptr_t)__shadowargs[j].frame && j != i); - i = j; - } - __shadowargs[i].addr = addr; - __shadowargs[i].frame = (void *)frame; - __shadowargs[i].arg1 = rdi; - __shadowargs[i].arg2 = rsi; - __shadowargs[i].arg3 = rdx; - __shadowargs[i].arg4 = rcx; - __shadowargs[i].arg5 = r8; - __shadowargs[i].arg6 = r9; - __shadowargs_index = i; -} diff --git a/libc/log/showcrashreports.c b/libc/log/showcrashreports.c index 08b4e051..f8ff2d5c 100644 --- a/libc/log/showcrashreports.c +++ b/libc/log/showcrashreports.c @@ -24,14 +24,14 @@ #include "libc/dce.h" #include "libc/log/internal.h" #include "libc/log/log.h" -#include "libc/log/ubsan.h" +#include "libc/log/ubsan.internal.h" #include "libc/macros.h" #include "libc/nt/signals.h" #include "libc/str/str.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sig.h" -STATIC_YOINK("die"); +STATIC_YOINK("__die"); STATIC_YOINK("__ubsan_abort"); extern const unsigned char __oncrash_thunks[7][11]; diff --git a/libc/log/startfatal.c b/libc/log/startfatal.c index d4a1254b..5c2e2994 100644 --- a/libc/log/startfatal.c +++ b/libc/log/startfatal.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/fileno.h" diff --git a/libc/log/startfatal_ndebug.c b/libc/log/startfatal_ndebug.c index 68917a1b..026fd424 100644 --- a/libc/log/startfatal_ndebug.c +++ b/libc/log/startfatal_ndebug.c @@ -17,8 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/log/color.h" -#include "libc/runtime/missioncritical.h" +#include "libc/log/color.internal.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" /** diff --git a/libc/log/thunks/__check_fail_ndebug.S b/libc/log/thunks/__check_fail_ndebug.S index e82e6081..bf176e58 100644 --- a/libc/log/thunks/__check_fail_ndebug.S +++ b/libc/log/thunks/__check_fail_ndebug.S @@ -25,5 +25,5 @@ __check_fail_ndebug: mov %rsp,%rbp call ___check_fail_ndebug pop %rbp - jmp die # fewer elements in backtrace + jmp __die # fewer elements in backtrace .endfn __check_fail_ndebug,globl diff --git a/libc/log/ubsan.c b/libc/log/ubsan.c index f56de0d3..dbd7c7aa 100644 --- a/libc/log/ubsan.c +++ b/libc/log/ubsan.c @@ -22,9 +22,8 @@ #include "libc/fmt/fmt.h" #include "libc/log/internal.h" #include "libc/log/log.h" -#include "libc/log/ubsan.h" +#include "libc/log/ubsan.internal.h" #include "libc/runtime/internal.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -56,7 +55,7 @@ void __ubsan_abort(const struct UbsanSourceLocation *loc, if (IsDebuggerPresent(false)) DebugBreak(); __start_fatal(loc->file, loc->line); fprintf(stderr, "%s\r\n", description); - die(); + __die(); unreachable; } diff --git a/libc/log/ubsan.h b/libc/log/ubsan.internal.h similarity index 100% rename from libc/log/ubsan.h rename to libc/log/ubsan.internal.h diff --git a/libc/log/verr.c b/libc/log/verr.c index 896dfeef..81da2125 100644 --- a/libc/log/verr.c +++ b/libc/log/verr.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/bsd.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/libc/log/verrx.c b/libc/log/verrx.c index 36db02f7..ce86db5b 100644 --- a/libc/log/verrx.c +++ b/libc/log/verrx.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/bsd.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/libc/log/vflogf.c b/libc/log/vflogf.c index 46d1bcbd..550df441 100644 --- a/libc/log/vflogf.c +++ b/libc/log/vflogf.c @@ -116,7 +116,7 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f, if (level == kLogFatal) { __start_fatal(file, line); (dprintf)(STDERR_FILENO, "fatal error see logfile\r\n"); - die(); + __die(); unreachable; } } diff --git a/libc/log/vwarn.c b/libc/log/vwarn.c index f6ccc0f5..bc9d1600 100644 --- a/libc/log/vwarn.c +++ b/libc/log/vwarn.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/bsd.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/libc/log/vwarnx.c b/libc/log/vwarnx.c index 117f0115..d93355ab 100644 --- a/libc/log/vwarnx.c +++ b/libc/log/vwarnx.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/bsd.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/libc/macho.h b/libc/macho.internal.h similarity index 100% rename from libc/macho.h rename to libc/macho.internal.h diff --git a/libc/macros-cpp.inc b/libc/macros-cpp.inc index 5ca2a1fb..8eb5e602 100644 --- a/libc/macros-cpp.inc +++ b/libc/macros-cpp.inc @@ -1,22 +1,3 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ /* clang-format off */ #include "ape/relocations.h" diff --git a/libc/macros.h b/libc/macros.h index be651c7a..bb3fb8d5 100644 --- a/libc/macros.h +++ b/libc/macros.h @@ -8,8 +8,6 @@ /** * @fileoverview Common C preprocessor, assembler, and linker macros. - * - * @see libc/bits/safemacros.h which it's really complicated */ #define TRUE 1 diff --git a/libc/macros.inc b/libc/macros.inc index 9aaccaed..d0bf11d2 100644 --- a/libc/macros.inc +++ b/libc/macros.inc @@ -1,23 +1,3 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ - / Shorthand notation for widely-acknowledged sections. .macro .rodata .section .rodata,"a",@progbits diff --git a/libc/mem/malloc_trim.c b/libc/mem/malloc_trim.c index 2c789f03..2274c65c 100644 --- a/libc/mem/malloc_trim.c +++ b/libc/mem/malloc_trim.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Releases freed memory back to system. diff --git a/libc/mem/mem.h b/libc/mem/mem.h index 312fc2cd..5f14d0c6 100644 --- a/libc/mem/mem.h +++ b/libc/mem/mem.h @@ -19,7 +19,6 @@ void *memalign(size_t, size_t) attributeallocalign((1)) attributeallocsize((2)) mallocesque; void *realloc(void *, size_t) reallocesque; void *realloc_in_place(void *, size_t); -bool grow(void *, size_t *, size_t, size_t) paramsnonnull((1, 2)) libcesque; void *reallocarray(void *, size_t, size_t) nodiscard; void *valloc(size_t) attributeallocsize((1)) vallocesque; void *pvalloc(size_t) attributeallocsize((1)) mallocesque; @@ -27,6 +26,7 @@ char *strdup(const char *) paramsnonnull() mallocesque; char *strndup(const char *, size_t) paramsnonnull() attributeallocsize((2)) mallocesque; int posix_memalign(void **, size_t, size_t); /* wut */ +bool __grow(void *, size_t *, size_t, size_t) paramsnonnull((1, 2)) libcesque; int malloc_trim(size_t); size_t bulk_free(void **, size_t); diff --git a/libc/mem/unhexstr.c b/libc/mem/unhexstr.c index f699ca5f..ea80fc6b 100644 --- a/libc/mem/unhexstr.c +++ b/libc/mem/unhexstr.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/libc/nexgen32e/cachesize.h b/libc/nexgen32e/cachesize.h index 6caba9c4..10764c23 100644 --- a/libc/nexgen32e/cachesize.h +++ b/libc/nexgen32e/cachesize.h @@ -3,13 +3,11 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -enum CpuCacheType { - kCpuCacheTypeData = 1, - kCpuCacheTypeInstruction, - kCpuCacheTypeUnified, -}; +#define kCpuCacheTypeData 1 +#define kCpuCacheTypeInstruction 2 +#define kCpuCacheTypeUnified 3 -unsigned getcachesize(enum CpuCacheType, int); +unsigned getcachesize(int, int); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/nexgen32e/cpuid4.h b/libc/nexgen32e/cpuid4.internal.h similarity index 100% rename from libc/nexgen32e/cpuid4.h rename to libc/nexgen32e/cpuid4.internal.h diff --git a/libc/nexgen32e/crc32z.c b/libc/nexgen32e/crc32z.c index d6e62b63..c0ed7dd6 100644 --- a/libc/nexgen32e/crc32z.c +++ b/libc/nexgen32e/crc32z.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/x86feature.h" diff --git a/libc/nexgen32e/djbsort.c b/libc/nexgen32e/djbsort.c index c5f3e75b..499eb3d1 100644 --- a/libc/nexgen32e/djbsort.c +++ b/libc/nexgen32e/djbsort.c @@ -26,10 +26,10 @@ void djbsort$avx2(int32_t *, long); /** * D.J. Bernstein's outrageously fast integer sorting algorithm. */ -void djbsort(size_t n, int32_t a[n]) { +void djbsort(int32_t *a, size_t n) { if (X86_HAVE(AVX2)) { djbsort$avx2(a, n); } else { - insertionsort(n, a); + insertionsort(a, n); } } diff --git a/libc/nexgen32e/ffs.h b/libc/nexgen32e/ffs.h new file mode 100644 index 00000000..6a161763 --- /dev/null +++ b/libc/nexgen32e/ffs.h @@ -0,0 +1,12 @@ +#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_ +#define COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int ffs(int) pureconst; +int ffsl(long int) pureconst; +int ffsll(long long int) pureconst; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_ */ diff --git a/libc/nexgen32e/fpu.h b/libc/nexgen32e/fpu.h deleted file mode 100644 index f17b22e7..00000000 --- a/libc/nexgen32e/fpu.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_ -#define COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) - -/** - * Saves FPU state. - * @see X86_HAVE(FXSR) - */ -#define FXSAVE(STATE) \ - asm volatile("fxsave\t%0" \ - : "=m"(STATE) \ - : /* x87/sse */ \ - : "memory") - -/** - * Restores FPU state. - * @see X86_HAVE(FXSR) - */ -#define FXRSTOR(STATE) \ - asm volatile("fxrstor\t%0" \ - : /* x87/sse */ \ - : "m"(STATE) \ - : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", \ - "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", \ - "xmm14", "xmm15", "st", "st(1)", "st(2)", "st(3)", "st(4)", \ - "st(5)", "st(6)", "st(7)", "memory", "fpsr", "fpcr") - -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_ */ diff --git a/libc/nexgen32e/gc.S b/libc/nexgen32e/gc.S index c884406f..afa83167 100644 --- a/libc/nexgen32e/gc.S +++ b/libc/nexgen32e/gc.S @@ -33,10 +33,9 @@ / @param rax,rdx,xmm0,xmm1,st0,st1 is return value / @see test/libc/runtime/gc_test.c / -CollectGarbage: - decq g_garbage(%rip) - mov g_garbage(%rip),%r8 - mov g_garbage+16(%rip),%r9 +__gc: decq __garbage(%rip) + mov __garbage(%rip),%r8 + mov __garbage+16(%rip),%r9 js 9f shl $5,%r8 lea (%r9,%r8),%r8 @@ -59,12 +58,12 @@ CollectGarbage: leave ret 9: call abort - .endfn CollectGarbage,globl,hidden + .endfn __gc,globl,hidden .source __FILE__ .bss .align 8 -g_garbage: +__garbage: .quad 0 # garbage.i .quad 0 # garbage.n .quad 0 # garbage.p @@ -74,10 +73,10 @@ g_garbage: .quad 0 # garbage.p[𝑖].arg .quad 0 # garbage.p[𝑖].ret .endr - .endobj g_garbage,globl,hidden + .endobj __garbage,globl,hidden .previous .init.start 100,_init_garbage - movb $INITIAL_CAPACITY,g_garbage+8(%rip) - movl $g_garbage+24,g_garbage+16(%rip) + movb $INITIAL_CAPACITY,__garbage+8(%rip) + movl $__garbage+24,__garbage+16(%rip) .init.end 100,_init_garbage diff --git a/libc/nexgen32e/gc.h b/libc/nexgen32e/gc.internal.h similarity index 85% rename from libc/nexgen32e/gc.h rename to libc/nexgen32e/gc.internal.h index 69559f31..48cbe044 100644 --- a/libc/nexgen32e/gc.h +++ b/libc/nexgen32e/gc.internal.h @@ -14,9 +14,9 @@ struct Garbages { } * p; }; -hidden extern struct Garbages g_garbage; +hidden extern struct Garbages __garbage; -int64_t CollectGarbage(void) hidden; +int64_t __gc(void) hidden; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/nexgen32e/gclongjmp.S b/libc/nexgen32e/gclongjmp.S index eb96fe14..65977768 100644 --- a/libc/nexgen32e/gclongjmp.S +++ b/libc/nexgen32e/gclongjmp.S @@ -33,8 +33,8 @@ gclongjmp: .leafprologue .profilable - .weak g_garbage - lea g_garbage(%rip),%r12 + .weak __garbage + lea __garbage(%rip),%r12 test %r12,%r12 jnz .L.unwind.destructors 0: jmp longjmp diff --git a/libc/nexgen32e/hascharacter.h b/libc/nexgen32e/hascharacter.internal.h similarity index 100% rename from libc/nexgen32e/hascharacter.h rename to libc/nexgen32e/hascharacter.internal.h diff --git a/libc/nexgen32e/insertionsort.greg.c b/libc/nexgen32e/insertionsort.greg.c index 63b581ad..36675876 100644 --- a/libc/nexgen32e/insertionsort.greg.c +++ b/libc/nexgen32e/insertionsort.greg.c @@ -24,7 +24,7 @@ * Sorts array of signed 32-bit integers. * @see djbsort() */ -textreal void insertionsort(size_t n, int32_t a[n]) { +textreal void insertionsort(int32_t *a, size_t n) { int t; unsigned i, j; for (i = 1; i < n; ++i) { diff --git a/libc/nexgen32e/lz4.h b/libc/nexgen32e/lz4.h index a911661b..ef2f1c0b 100644 --- a/libc/nexgen32e/lz4.h +++ b/libc/nexgen32e/lz4.h @@ -1,7 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_LZ4_H_ #define COSMOPOLITAN_LIBC_LZ4_H_ #include "libc/bits/bits.h" -#if 0 /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § lz4 ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│─╝ @@ -10,39 +9,36 @@ @see https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md @see https://github.com/lz4/lz4/blob/master/doc/lz4_Block_format.md @see http://ticki.github.io/blog/how-lz4-works/ */ -#endif -#define LZ4_EOF 0 -#define LZ4_VERSION 1 -#define LZ4_MAGICNUMBER 0x184D2204 -#define LZ4_SKIPPABLE0 0x184D2A50 -#define LZ4_SKIPPABLEMASK 0xFFFFFFF0 -#define LZ4_MAXHEADERSIZE (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1) -#define LZ4_BLOCKMAXSIZE_64KB 4 +#define LZ4_EOF 0 +#define LZ4_VERSION 1 +#define LZ4_MAGICNUMBER 0x184D2204 +#define LZ4_SKIPPABLE0 0x184D2A50 +#define LZ4_SKIPPABLEMASK 0xFFFFFFF0 +#define LZ4_MAXHEADERSIZE (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1) +#define LZ4_BLOCKMAXSIZE_64KB 4 #define LZ4_BLOCKMAXSIZE_256KB 5 -#define LZ4_BLOCKMAXSIZE_1MB 6 -#define LZ4_BLOCKMAXSIZE_4MB 7 +#define LZ4_BLOCKMAXSIZE_1MB 6 +#define LZ4_BLOCKMAXSIZE_4MB 7 #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § lz4 » frames ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif -#define LZ4_MAGIC(FRAME) read32le(FRAME) -#define LZ4_FRAME_VERSION(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 6) & 0b11) -#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1) -#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1) +#define LZ4_MAGIC(FRAME) read32le(FRAME) +#define LZ4_FRAME_VERSION(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 6) & 0b11) +#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1) +#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1) #define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1) #define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \ ((_LZ4_FRAME_FLG(FRAME) >> 2) & 1) #define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1) -#define LZ4_FRAME_BLOCKMAXSIZE(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 4) & 0b111) -#define LZ4_FRAME_RESERVED1(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1) -#define LZ4_FRAME_RESERVED2(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 7) & 1) -#define LZ4_FRAME_RESERVED3(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 0) & 0b1111) +#define LZ4_FRAME_BLOCKMAXSIZE(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 4) & 0b111) +#define LZ4_FRAME_RESERVED1(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1) +#define LZ4_FRAME_RESERVED2(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 7) & 1) +#define LZ4_FRAME_RESERVED3(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 0) & 0b1111) #define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \ (LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? read64le((FRAME) + 4 + 1 + 1) : 0) #define LZ4_FRAME_DICTIONARYID(FRAME) \ @@ -57,17 +53,15 @@ COSMOPOLITAN_C_START_ (4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \ 4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME) + 1) #define _LZ4_FRAME_FLG(FRAME) (*((FRAME) + 4)) -#define _LZ4_FRAME_BD(FRAME) (*((FRAME) + 5)) +#define _LZ4_FRAME_BD(FRAME) (*((FRAME) + 5)) -#if 0 /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § lz4 » blocks ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif -#define LZ4_BLOCK_DATA(block) (block + sizeof(uint32_t)) -#define LZ4_BLOCK_DATASIZE(block) (read32le(block) & 0x7fffffff) -#define LZ4_BLOCK_ISEOF(block) (read32le(block) == LZ4_EOF) +#define LZ4_BLOCK_DATA(block) (block + sizeof(uint32_t)) +#define LZ4_BLOCK_DATASIZE(block) (read32le(block) & 0x7fffffff) +#define LZ4_BLOCK_ISEOF(block) (read32le(block) == LZ4_EOF) #define LZ4_BLOCK_ISCOMPRESSED(block) ((read32le(block) & 0x80000000) == 0) #define LZ4_BLOCK_SIZE(frame, block) \ (sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \ diff --git a/libc/nexgen32e/macros.inc b/libc/nexgen32e/macros.inc index 53db1a83..7112762d 100644 --- a/libc/nexgen32e/macros.inc +++ b/libc/nexgen32e/macros.inc @@ -1,22 +1,3 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/nexgen32e/x86feature.h" #include "libc/macros.h" diff --git a/libc/nexgen32e/memcpy.S b/libc/nexgen32e/memcpy.S index b8db542f..a2ac30d8 100644 --- a/libc/nexgen32e/memcpy.S +++ b/libc/nexgen32e/memcpy.S @@ -112,7 +112,7 @@ MemCpy: .leafprologue .L1: mov (%rsi),%cl mov %cl,(%rdi) jmp .L0 -.Lerms: cmp $4*1024*1024,%rdx +.Lerms: cmp $4*1024*1024,%rdx # TODO: getcachesize() ja .Lnts push %rdi push %rsi diff --git a/libc/nexgen32e/nexgen32e.h b/libc/nexgen32e/nexgen32e.h index 10619500..7ac2ea8e 100644 --- a/libc/nexgen32e/nexgen32e.h +++ b/libc/nexgen32e/nexgen32e.h @@ -4,8 +4,7 @@ COSMOPOLITAN_C_START_ void imapxlatab(void *); -void insertionsort(size_t n, int32_t[n]); -void *doublebytes(size_t, void *); +void insertionsort(int32_t *, size_t); int64_t div10int64(int64_t) libcesque pureconst; int64_t div100int64(int64_t) libcesque pureconst; diff --git a/libc/nexgen32e/nt2sysv.S b/libc/nexgen32e/nt2sysv.S index e5ea81bc..71494538 100644 --- a/libc/nexgen32e/nt2sysv.S +++ b/libc/nexgen32e/nt2sysv.S @@ -28,7 +28,8 @@ / @param %rax is function address / @param %rcx,%rdx,%r8,%r9 / @return %rax,%xmm0 -/ @note this is so much slower than sysv2nt() +/ @note slower than __sysv2nt +/ @see NT2SYSV() macro __nt2sysv: push %rbp mov %rsp,%rbp diff --git a/libc/nexgen32e/nt2sysv.h b/libc/nexgen32e/nt2sysv.h new file mode 100644 index 00000000..1ba5dc21 --- /dev/null +++ b/libc/nexgen32e/nt2sysv.h @@ -0,0 +1,14 @@ +#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_ +#define COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_ +#include "libc/nexgen32e/trampoline.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +/** + * Creates function to thunk FUNCTION from MSX64 to System V ABI. + * + * This macro should be used when specifying callbacks in the WIN32 API. + */ +#define NT2SYSV(FUNCTION) TRAMPOLINE(FUNCTION, __nt2sysv) + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_ */ diff --git a/libc/nexgen32e/sgetc.S b/libc/nexgen32e/sgetc.S index ef2ce948..39176fe9 100644 --- a/libc/nexgen32e/sgetc.S +++ b/libc/nexgen32e/sgetc.S @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "ape/macros.h" -#include "libc/nexgen32e/uart.h" +#include "libc/nexgen32e/uart.internal.h" #include "libc/notice.inc" .real .code16 # ∩ .code32 ∩ .code64 diff --git a/libc/nexgen32e/tinystrcmp.h b/libc/nexgen32e/tinystrcmp.internal.h similarity index 100% rename from libc/nexgen32e/tinystrcmp.h rename to libc/nexgen32e/tinystrcmp.internal.h diff --git a/libc/nexgen32e/tinystrlen.h b/libc/nexgen32e/tinystrlen.internal.h similarity index 100% rename from libc/nexgen32e/tinystrlen.h rename to libc/nexgen32e/tinystrlen.internal.h diff --git a/libc/nexgen32e/trampoline.h b/libc/nexgen32e/trampoline.h new file mode 100644 index 00000000..55e4da21 --- /dev/null +++ b/libc/nexgen32e/trampoline.h @@ -0,0 +1,20 @@ +#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_ +#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +#define TRAMPOLINE(FUNCTION, THUNK) \ + ({ \ + typeof(FUNCTION) *Tramp; \ + asm(".pushsection .text.trampoline\n" \ + "183:\n\t" \ + "mov\t%1,%%eax\n\t" \ + "jmp\t" #THUNK "\n\t" \ + ".popsection\n\t" \ + "mov\t$183b,%k0" \ + : "=r"(Tramp) \ + : "i"(FUNCTION)); \ + Tramp; \ + }) + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_ */ diff --git a/libc/nexgen32e/uart.h b/libc/nexgen32e/uart.internal.h similarity index 100% rename from libc/nexgen32e/uart.h rename to libc/nexgen32e/uart.internal.h diff --git a/libc/nexgen32e/vcls.S b/libc/nexgen32e/vcls.S index abcd1a8a..0d58849b 100644 --- a/libc/nexgen32e/vcls.S +++ b/libc/nexgen32e/vcls.S @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "ape/macros.h" -#include "libc/nexgen32e/vidya.h" +#include "libc/nexgen32e/vidya.internal.h" #include "libc/notice.inc" .real .code16 # ∩ .code32 ∩ .code64 diff --git a/libc/nexgen32e/vendor.h b/libc/nexgen32e/vendor.internal.h similarity index 100% rename from libc/nexgen32e/vendor.h rename to libc/nexgen32e/vendor.internal.h diff --git a/libc/nexgen32e/vidya.h b/libc/nexgen32e/vidya.h deleted file mode 100644 index 5de5b583..00000000 --- a/libc/nexgen32e/vidya.h +++ /dev/null @@ -1,130 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╠──────────────────────────────────────────────────────────────────────────────╣ -│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀█░█▀█░▀█▀░█░█░█▀█░█░░░█░░░█░█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀█░█░▄░░█░░█░█░█▀█░█░░░█░░░▀█▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░▀░▀░▀▀▀░░▀░░▀▀▀░▀░▀░▀▀▀░▀▀▀░░▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀█░█▀█░█▀█░▀█▀░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀▀░█ █░██▀░░█░░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░▀░░░▀▀▀░▀░▀░░▀░░▀░▀░▀▀▀░▀▀▀░▀▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ -│░░░░░░░█▀▀░█░█░█▀▀░█▀█░█░█░▀█▀░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░▄▄░░░▐█░░│ -│░░░░░░░█▀▀░▄▀▄░█▀▀░█░▄░█░█░░█░░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░▄▄▄░░░▄██▄░░█▀░░░█░▄░│ -│░░░░░░░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░░▀░░▀░▀░▀▀▀░▀▀░▀▀▀░░░░░░░░░░▄██▀█▌░██▄▄░░▐█▀▄░▐█▀░░│ -│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▐█▀▀▌░░░▄▀▌░▌░█░▌░░▌░▌░░│ -╠──────────────────────────────────────────────────────▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄─│ -│ αcτµαlly pδrταblε εxεcµταblε § pc display helpers │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_ -#define COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_ - -/** - * @fileoverview PC Display Helpers. - * - * These functions provide the baseline of PC graphics & teletype - * emulation support that doesn't require switching context or cpu mode. - * - * @see https://youtu.be/yHXx3orN35Y - * @see https://youtu.be/H1p1im_2uf4 - * @see Google's SGABIOS which logs MDA/CGA displays to UART as ASCII - * @mode long,legacy,real - */ - -#define VIDYA_ROWS 25 -#define VIDYA_COLUMNS 80 -#define VIDYA_SIZE (VIDYA_ROWS * VIDYA_COLUMNS * 2) -#define VIDYA_MODE_MDA 7 -#define VIDYA_MODE_CGA 3 -#define VIDYA_ADDR_MDA 0xb0000 -#define VIDYA_ADDR_CGA 0xb8000 -#define VIDYA_ATTR_NORMAL 0x07 /* cozy default for both mda and cga */ -#define VIDYA_REWIND ~0x7fff /* derived from mode addr min. lzcnt */ -#define VIDYA_SERVICE 0x10 -#define VIDYA_SET_MODE 0x0003 -#define VIDYA_SET_CURSOR 0x0100 -#define VIDYA_SET_CURSOR_NONE 0x2000 -#define VIDYA_SET_BLINKING 0x1003 -#define VIDYA_SET_BLINKING_NONE 0x0000 - -#if !(__ASSEMBLER__ + __LINKER__ + 0) - -enum VidyaMode { - kVidyaModeMda = VIDYA_MODE_MDA, - kVidyaModeCga = VIDYA_MODE_CGA -}; - -enum VidyaColor { - kVidyaColorBlack = 0x0, - kVidyaColorBlue = 0x1, - kVidyaColorGreen = 0x2, - kVidyaColorCyan = 0x3, - kVidyaColorRed = 0x4, - kVidyaColorMagenta = 0x5, - kVidyaColorBrown = 0x6, - kVidyaColorLightGray = 0x7, - kVidyaColorDarkGray = 0x8, - kVidyaColorLightBlue = 0x9, - kVidyaColorLightGreen = 0xa, - kVidyaColorLightCyan = 0xb, - kVidyaColorLightRed = 0xc, - kVidyaColorLightMagenta = 0xd, - kVidyaColorYellow = 0xe, - kVidyaColorWhite = 0xf -}; - -struct thatispacked VidyaCell { - unsigned glyph : 8; /* IBM Code Page 437 */ - union VidyaAttr { - enum { - kVidyaAttrBlank = 0x00, - kVidyaAttrNormal = VIDYA_ATTR_NORMAL, - kVidyaAttrMdaFlipped = 0x70, - kVidyaAttrMdaFlippedFaded = 0x78, - kVidyaAttrMdaFlippedIntense = 0xf0, - kVidyaAttrMdaFlippedFadedIntense = 0xf8 - } preset : 8; - struct VidyaTextDecoration { /* MDA Only */ - unsigned underline : 1; - unsigned __ignore1 : 1; - unsigned bold : 1; - unsigned __ignore2 : 3; - unsigned intense : 1; - } decoration; - struct { /* CGA Only */ - enum VidyaColor fg : 4; - enum VidyaColor bg : 4; - } color; - } attr; -}; - -typedef union VidyaAttr VidyaAttr; -typedef struct VidyaCell VidyaCell; -typedef struct VidyaCell VidyaPage[VIDYA_ROWS][VIDYA_COLUMNS]; - -__far VidyaPage *vinit(enum VidyaMode mode); -__far VidyaPage *vcls(__far VidyaCell *pos); -__far VidyaCell *vputc(__far VidyaCell *pos, int c); -__far VidyaCell *vputs(__far VidyaCell *pos, const char *str); -__far VidyaCell *vtput(__far VidyaCell *pos, const void *data, size_t size); -__far VidyaCell *vscroll(__far VidyaCell *pos, size_t bytes); - -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_ */ diff --git a/libc/nexgen32e/vidya.internal.h b/libc/nexgen32e/vidya.internal.h new file mode 100644 index 00000000..6891192a --- /dev/null +++ b/libc/nexgen32e/vidya.internal.h @@ -0,0 +1,83 @@ +#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_ +#define COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_ + +#define VIDYA_ROWS 25 +#define VIDYA_COLUMNS 80 +#define VIDYA_SIZE (VIDYA_ROWS * VIDYA_COLUMNS * 2) +#define VIDYA_MODE_MDA 7 +#define VIDYA_MODE_CGA 3 +#define VIDYA_ADDR_MDA 0xb0000 +#define VIDYA_ADDR_CGA 0xb8000 +#define VIDYA_ATTR_NORMAL 0x07 /* cozy default for both mda and cga */ +#define VIDYA_REWIND ~0x7fff /* derived from mode addr min. lzcnt */ +#define VIDYA_SERVICE 0x10 +#define VIDYA_SET_MODE 0x0003 +#define VIDYA_SET_CURSOR 0x0100 +#define VIDYA_SET_CURSOR_NONE 0x2000 +#define VIDYA_SET_BLINKING 0x1003 +#define VIDYA_SET_BLINKING_NONE 0x0000 + +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +enum VidyaMode { + kVidyaModeMda = VIDYA_MODE_MDA, + kVidyaModeCga = VIDYA_MODE_CGA +}; + +enum VidyaColor { + kVidyaColorBlack = 0x0, + kVidyaColorBlue = 0x1, + kVidyaColorGreen = 0x2, + kVidyaColorCyan = 0x3, + kVidyaColorRed = 0x4, + kVidyaColorMagenta = 0x5, + kVidyaColorBrown = 0x6, + kVidyaColorLightGray = 0x7, + kVidyaColorDarkGray = 0x8, + kVidyaColorLightBlue = 0x9, + kVidyaColorLightGreen = 0xa, + kVidyaColorLightCyan = 0xb, + kVidyaColorLightRed = 0xc, + kVidyaColorLightMagenta = 0xd, + kVidyaColorYellow = 0xe, + kVidyaColorWhite = 0xf +}; + +struct thatispacked VidyaCell { + unsigned glyph : 8; /* IBM Code Page 437 */ + union VidyaAttr { + enum { + kVidyaAttrBlank = 0x00, + kVidyaAttrNormal = VIDYA_ATTR_NORMAL, + kVidyaAttrMdaFlipped = 0x70, + kVidyaAttrMdaFlippedFaded = 0x78, + kVidyaAttrMdaFlippedIntense = 0xf0, + kVidyaAttrMdaFlippedFadedIntense = 0xf8 + } preset : 8; + struct VidyaTextDecoration { /* MDA Only */ + unsigned underline : 1; + unsigned __ignore1 : 1; + unsigned bold : 1; + unsigned __ignore2 : 3; + unsigned intense : 1; + } decoration; + struct { /* CGA Only */ + enum VidyaColor fg : 4; + enum VidyaColor bg : 4; + } color; + } attr; +}; + +typedef union VidyaAttr VidyaAttr; +typedef struct VidyaCell VidyaCell; +typedef struct VidyaCell VidyaPage[VIDYA_ROWS][VIDYA_COLUMNS]; + +__far VidyaPage *vinit(enum VidyaMode mode); +__far VidyaPage *vcls(__far VidyaCell *pos); +__far VidyaCell *vputc(__far VidyaCell *pos, int c); +__far VidyaCell *vputs(__far VidyaCell *pos, const char *str); +__far VidyaCell *vtput(__far VidyaCell *pos, const void *data, size_t size); +__far VidyaCell *vscroll(__far VidyaCell *pos, size_t bytes); + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_ */ diff --git a/libc/nt/accounting.h b/libc/nt/accounting.h index fba01621..696b0c7c 100644 --- a/libc/nt/accounting.h +++ b/libc/nt/accounting.h @@ -1,9 +1,11 @@ #ifndef COSMOPOLITAN_LIBC_NT_ACCOUNTING_H_ #define COSMOPOLITAN_LIBC_NT_ACCOUNTING_H_ +#include "libc/nt/struct/filetime.h" +#include "libc/nt/struct/iocounters.h" +#include "libc/nt/struct/memorystatusex.h" #include "libc/nt/thunk/msabi.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -28,11 +30,6 @@ COSMOPOLITAN_C_START_ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » accounting ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif - -struct NtFileTime; -struct NtIoCounters; -struct NtMemoryStatusEx; int GetUserName(char16_t (*buf)[257], uint32_t *in_out_size); bool32 GlobalMemoryStatusEx(struct NtMemoryStatusEx *lpBuffer); diff --git a/libc/nt/automation.h b/libc/nt/automation.h index 591f00c2..7d2bd918 100644 --- a/libc/nt/automation.h +++ b/libc/nt/automation.h @@ -2,7 +2,6 @@ #define COSMOPOLITAN_LIBC_NT_AUTOMATION_H_ #include "libc/nt/typedef/hookproc.h" #include "libc/nt/typedef/wndenumproc.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -27,7 +26,6 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » aol hacking ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/nt/codegen.h b/libc/nt/codegen.h index 0b4a0ced..7af39195 100644 --- a/libc/nt/codegen.h +++ b/libc/nt/codegen.h @@ -1,5 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_NT_CODEGEN_H_ #define COSMOPOLITAN_LIBC_NT_CODEGEN_H_ -#include "ape/idata.h" +#include "ape/idata.internal.h" #include "ape/macros.h" #endif /* COSMOPOLITAN_LIBC_NT_CODEGEN_H_ */ diff --git a/libc/nt/comdlg.h b/libc/nt/comdlg.h new file mode 100644 index 00000000..66cd8ebd --- /dev/null +++ b/libc/nt/comdlg.h @@ -0,0 +1,37 @@ +#ifndef COSMOPOLITAN_LIBC_NT_COMDLG_H_ +#define COSMOPOLITAN_LIBC_NT_COMDLG_H_ +#include "libc/nt/struct/openfilename.h" +/* ░░░░ + ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ + ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ + ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▒▓░ + ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▒ ▒▒▒▓▓█ + ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓ + ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓ █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█ + ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓ + ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒ + ▒▒▒▒▓▓ ▓▒▒▓▓▓▓ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█ + ▒▓ ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓ + ░░░░░░░░░░░▒▒▒▒ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█ + ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓ ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓ + ░▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓░ ░▓███▓ + ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░ ▒▓▓▓▒▒▒ ░▒▒▒▓ ████████████ + ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░ ░███ + ▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓ ███ + ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓ ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒ ▓██ + ▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓ ▓██ + ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒ ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒ ███ + ░▒▓ ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓ ▓██ +╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ +│ cosmopolitan § new technology » common dialogs ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +bool32 GetOpenFileName(struct NtOpenFilename *arg); +bool32 GetSaveFileName(struct NtOpenFilename *arg); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NT_COMDLG_H_ */ diff --git a/libc/nt/comdlg32/ChooseColorA.s b/libc/nt/comdlg32/ChooseColorA.s index 4002c535..0e02c353 100644 --- a/libc/nt/comdlg32/ChooseColorA.s +++ b/libc/nt/comdlg32/ChooseColorA.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_ChooseColorA,ChooseColorA,102 + + .text.windows +ChooseColorA: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_ChooseColorA(%rip) + leave + ret + .endfn ChooseColorA,globl + .previous diff --git a/libc/nt/comdlg32/ChooseColorW.s b/libc/nt/comdlg32/ChooseColorW.s index d8a8165a..7dfd2a46 100644 --- a/libc/nt/comdlg32/ChooseColorW.s +++ b/libc/nt/comdlg32/ChooseColorW.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_ChooseColorW,ChooseColorW,103 + + .text.windows +ChooseColor: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_ChooseColorW(%rip) + leave + ret + .endfn ChooseColor,globl + .previous diff --git a/libc/nt/comdlg32/ChooseFontA.s b/libc/nt/comdlg32/ChooseFontA.s index 01eeb876..91a441c2 100644 --- a/libc/nt/comdlg32/ChooseFontA.s +++ b/libc/nt/comdlg32/ChooseFontA.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_ChooseFontA,ChooseFontA,104 + + .text.windows +ChooseFontA: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_ChooseFontA(%rip) + leave + ret + .endfn ChooseFontA,globl + .previous diff --git a/libc/nt/comdlg32/ChooseFontW.s b/libc/nt/comdlg32/ChooseFontW.s index 4a84259f..e1b761df 100644 --- a/libc/nt/comdlg32/ChooseFontW.s +++ b/libc/nt/comdlg32/ChooseFontW.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_ChooseFontW,ChooseFontW,105 + + .text.windows +ChooseFont: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_ChooseFontW(%rip) + leave + ret + .endfn ChooseFont,globl + .previous diff --git a/libc/nt/comdlg32/GetFileTitleA.s b/libc/nt/comdlg32/GetFileTitleA.s index 60cf7a34..88a1fcc0 100644 --- a/libc/nt/comdlg32/GetFileTitleA.s +++ b/libc/nt/comdlg32/GetFileTitleA.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_GetFileTitleA,GetFileTitleA,111 + + .text.windows +GetFileTitleA: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_GetFileTitleA(%rip),%rax + jmp __sysv2nt + .endfn GetFileTitleA,globl + .previous diff --git a/libc/nt/comdlg32/GetFileTitleW.s b/libc/nt/comdlg32/GetFileTitleW.s index 75132c23..718e43bd 100644 --- a/libc/nt/comdlg32/GetFileTitleW.s +++ b/libc/nt/comdlg32/GetFileTitleW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_GetFileTitleW,GetFileTitleW,112 + + .text.windows +GetFileTitle: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_GetFileTitleW(%rip),%rax + jmp __sysv2nt + .endfn GetFileTitle,globl + .previous diff --git a/libc/nt/comdlg32/GetOpenFileNameA.s b/libc/nt/comdlg32/GetOpenFileNameA.s index 189576e0..5b628459 100644 --- a/libc/nt/comdlg32/GetOpenFileNameA.s +++ b/libc/nt/comdlg32/GetOpenFileNameA.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_GetOpenFileNameA,GetOpenFileNameA,113 + + .text.windows +GetOpenFileNameA: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_GetOpenFileNameA(%rip) + leave + ret + .endfn GetOpenFileNameA,globl + .previous diff --git a/libc/nt/comdlg32/GetOpenFileNameW.s b/libc/nt/comdlg32/GetOpenFileNameW.s index 8a1050ac..13d2d6fe 100644 --- a/libc/nt/comdlg32/GetOpenFileNameW.s +++ b/libc/nt/comdlg32/GetOpenFileNameW.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_GetOpenFileNameW,GetOpenFileNameW,114 + + .text.windows +GetOpenFileName: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_GetOpenFileNameW(%rip) + leave + ret + .endfn GetOpenFileName,globl + .previous diff --git a/libc/nt/comdlg32/GetSaveFileNameA.s b/libc/nt/comdlg32/GetSaveFileNameA.s index bcc3e522..b390319d 100644 --- a/libc/nt/comdlg32/GetSaveFileNameA.s +++ b/libc/nt/comdlg32/GetSaveFileNameA.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_GetSaveFileNameA,GetSaveFileNameA,115 + + .text.windows +GetSaveFileNameA: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_GetSaveFileNameA(%rip) + leave + ret + .endfn GetSaveFileNameA,globl + .previous diff --git a/libc/nt/comdlg32/GetSaveFileNameW.s b/libc/nt/comdlg32/GetSaveFileNameW.s index 600a6b17..f7fe50f6 100644 --- a/libc/nt/comdlg32/GetSaveFileNameW.s +++ b/libc/nt/comdlg32/GetSaveFileNameW.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_GetSaveFileNameW,GetSaveFileNameW,116 + + .text.windows +GetSaveFileName: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_GetSaveFileNameW(%rip) + leave + ret + .endfn GetSaveFileName,globl + .previous diff --git a/libc/nt/comdlg32/PrintDlgA.s b/libc/nt/comdlg32/PrintDlgA.s index 1e943cc0..b7008252 100644 --- a/libc/nt/comdlg32/PrintDlgA.s +++ b/libc/nt/comdlg32/PrintDlgA.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_PrintDlgA,PrintDlgA,120 + + .text.windows +PrintDlgA: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_PrintDlgA(%rip) + leave + ret + .endfn PrintDlgA,globl + .previous diff --git a/libc/nt/comdlg32/PrintDlgW.s b/libc/nt/comdlg32/PrintDlgW.s index a34648d9..8474e6aa 100644 --- a/libc/nt/comdlg32/PrintDlgW.s +++ b/libc/nt/comdlg32/PrintDlgW.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_PrintDlgW,PrintDlgW,123 + + .text.windows +PrintDlg: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_PrintDlgW(%rip) + leave + ret + .endfn PrintDlg,globl + .previous diff --git a/libc/nt/comdlg32/ReplaceTextA.s b/libc/nt/comdlg32/ReplaceTextA.s index aac7f178..1451440c 100644 --- a/libc/nt/comdlg32/ReplaceTextA.s +++ b/libc/nt/comdlg32/ReplaceTextA.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_ReplaceTextA,ReplaceTextA,124 + + .text.windows +ReplaceTextA: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_ReplaceTextA(%rip) + leave + ret + .endfn ReplaceTextA,globl + .previous diff --git a/libc/nt/comdlg32/ReplaceTextW.s b/libc/nt/comdlg32/ReplaceTextW.s index 32aa00a9..c91fe2f7 100644 --- a/libc/nt/comdlg32/ReplaceTextW.s +++ b/libc/nt/comdlg32/ReplaceTextW.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp comdlg32,__imp_ReplaceTextW,ReplaceTextW,125 + + .text.windows +ReplaceText: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_ReplaceTextW(%rip) + leave + ret + .endfn ReplaceText,globl + .previous diff --git a/libc/nt/console.h b/libc/nt/console.h index c5197303..c1100018 100644 --- a/libc/nt/console.h +++ b/libc/nt/console.h @@ -1,10 +1,15 @@ #ifndef COSMOPOLITAN_LIBC_NT_CONSOLE_H_ #define COSMOPOLITAN_LIBC_NT_CONSOLE_H_ -#include "libc/nt/enum/consolemodeflags.h" +#include "libc/nt/struct/charinfo.h" +#include "libc/nt/struct/consolecursorinfo.h" +#include "libc/nt/struct/consolescreenbufferinfo.h" +#include "libc/nt/struct/consolescreenbufferinfoex.h" +#include "libc/nt/struct/consoleselectioninfo.h" #include "libc/nt/struct/coord.h" +#include "libc/nt/struct/inputrecord.h" +#include "libc/nt/struct/smallrect.h" #include "libc/nt/thunk/msabi.h" #include "libc/nt/typedef/handlerroutine.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -29,21 +34,12 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » console ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif #define kNtAttachParentProcess -1u #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtCharInfo; -struct NtConsoleCursorInfo; -struct NtConsoleScreenBufferInfo; -struct NtConsoleScreenBufferInfoEx; -struct NtConsoleSelectionInfo; -struct NtInputRecord; -struct NtSmallRect; - bool32 WriteConsoleOutput(int64_t hConsoleOutput, const struct NtCharInfo *lpBuffer, struct NtCoord dwBufferSize, diff --git a/libc/nt/createfile.h b/libc/nt/createfile.h index 853eb465..98b7d11e 100644 --- a/libc/nt/createfile.h +++ b/libc/nt/createfile.h @@ -1,14 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_CREATEFILE_H_ #define COSMOPOLITAN_LIBC_NT_CREATEFILE_H_ -#include "libc/nt/enum/accessmask.h" -#include "libc/nt/enum/creationdisposition.h" -#include "libc/nt/enum/fileflagandattributes.h" -#include "libc/nt/enum/filesharemode.h" +#include "libc/nt/struct/securityattributes.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtSecurityAttributes; - int64_t CreateFile( const char16_t *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode, struct NtSecurityAttributes *opt_lpSecurityAttributes, diff --git a/libc/nt/debug.h b/libc/nt/debug.h index 7cfeae4c..1c3cc3ac 100644 --- a/libc/nt/debug.h +++ b/libc/nt/debug.h @@ -2,7 +2,6 @@ #define COSMOPOLITAN_LIBC_NT_DEBUG_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -27,7 +26,6 @@ COSMOPOLITAN_C_START_ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » debugging ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif /* Some of these APIs were moved to system.h and libc.h */ int32_t DebugBreakProcess(void *Process); diff --git a/libc/nt/dll.h b/libc/nt/dll.h index b0e19425..22b45ed9 100644 --- a/libc/nt/dll.h +++ b/libc/nt/dll.h @@ -2,7 +2,6 @@ #define COSMOPOLITAN_LIBC_NT_DLL_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -27,7 +26,6 @@ COSMOPOLITAN_C_START_ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » dynamic link libraries ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif int64_t LoadLibrary(const char16_t *lpLibFileName); int64_t LoadLibraryEx(const char16_t *lpLibFileName, int64_t hFile, diff --git a/libc/nt/enum/bitblt.h b/libc/nt/enum/bitblt.h new file mode 100644 index 00000000..46403d25 --- /dev/null +++ b/libc/nt/enum/bitblt.h @@ -0,0 +1,20 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_BITBLT_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_BITBLT_H_ + +#define kNtSrccopy 0x00CC0020u /* src */ +#define kNtSrcpaint 0x00EE0086u /* src | dst */ +#define kNtSrcand 0x008800C6u /* src & dst */ +#define kNtSrcinvert 0x00660046u /* src ^ dst */ +#define kNtSrcerase 0x00440328u /* src & ~dst */ +#define kNtNotsrccopy 0x00330008u /* ~src */ +#define kNtNotsrcerase 0x001100A6u /* ~src & ~dst */ +#define kNtMergecopy 0x00C000CAu /* (src & pattern) */ +#define kNtMergepaint 0x00BB0226u /* ~src | dst */ +#define kNtPatcopy 0x00F00021u /* pat */ +#define kNtPatpaint 0x00FB0A09u /* wut */ +#define kNtPatinvert 0x005A0049u /* pat ^ dst */ +#define kNtDstinvert 0x00550009u /* ~dst */ +#define kNtBlackness 0x00000042u /* black */ +#define kNtWhiteness 0x00FF0062u /* white */ + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_BITBLT_H_ */ diff --git a/libc/nt/enum/callback.h b/libc/nt/enum/callback.h new file mode 100644 index 00000000..172fab1a --- /dev/null +++ b/libc/nt/enum/callback.h @@ -0,0 +1,7 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_CALLBACK_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_CALLBACK_H_ + +#define kNtCallbackChunkFinished 0 +#define kNtCallbackStreamSwitch 1 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_CALLBACK_H_ */ diff --git a/libc/nt/enum/copyfile.h b/libc/nt/enum/copyfile.h new file mode 100644 index 00000000..9b8b8d5a --- /dev/null +++ b/libc/nt/enum/copyfile.h @@ -0,0 +1,17 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_COPYFILE_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_COPYFILE_H_ + +#define kNtCopyFileFailIfExists 0x00000001 +#define kNtCopyFileRestartable 0x00000002 +#define kNtCopyFileOpenSourceForWrite 0x00000004 +#define kNtCopyFileAllowDecryptedDestination 0x00000008 +#define kNtCopyFileCopySymlink 0x00000800 +#define kNtCopyFileNoBuffering 0x00001000 +#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */ +#define kNtCopyFileResumeFromPause 0x00004000 /* Win8+ */ +#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */ +#define kNtCopyFileNoOffload 0x00040000 /* Win8+ */ +#define kNtCopyFileIgnoreEdpBlock 0x00400000 /* Win10+ */ +#define kNtCopyFileIgnoreSourceEncryption 0x00800000 /* Win10+ */ + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_COPYFILE_H_ */ diff --git a/libc/nt/enum/cs.h b/libc/nt/enum/cs.h new file mode 100644 index 00000000..c9749db2 --- /dev/null +++ b/libc/nt/enum/cs.h @@ -0,0 +1,18 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_CS_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_CS_H_ + +#define kNtCsVredraw 0x00000001 +#define kNtCsHredraw 0x00000002 +#define kNtCsDblclks 0x00000008 +#define kNtCsOwndc 0x00000020 +#define kNtCsClassdc 0x00000040 +#define kNtCsParentdc 0x00000080 +#define kNtCsNoclose 0x00000200 +#define kNtCsSavebits 0x00000800 +#define kNtCsBytealignclient 0x00001000 +#define kNtCsBytealignwindow 0x00002000 +#define kNtCsGlobalclass 0x00004000 +#define kNtCsIme 0x00010000 +#define kNtCsDropshadow 0x00020000 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_CS_H_ */ diff --git a/libc/nt/enum/dialogresult.h b/libc/nt/enum/dialogresult.h index f04508c5..2ae62a8a 100644 --- a/libc/nt/enum/dialogresult.h +++ b/libc/nt/enum/dialogresult.h @@ -1,20 +1,16 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_DIALOGRESULT_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_DIALOGRESULT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum DialogResult { - kNtIdok = 1, - kNtIdcancel = 2, - kNtIdabort = 3, - kNtIdretry = 4, - kNtIdignore = 5, - kNtIdyes = 6, - kNtIdno = 7, - kNtIdclose = 8, - kNtIdhelp = 9, - kNtIdtryagain = 10, - kNtIdcontinue = 11 -}; +#define kNtIdok 1 +#define kNtIdcancel 2 +#define kNtIdabort 3 +#define kNtIdretry 4 +#define kNtIdignore 5 +#define kNtIdyes 6 +#define kNtIdno 7 +#define kNtIdclose 8 +#define kNtIdhelp 9 +#define kNtIdtryagain 10 +#define kNtIdcontinue 11 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_DIALOGRESULT_H_ */ diff --git a/libc/nt/enum/errormodeflags.h b/libc/nt/enum/errormodeflags.h index bf18aba9..92ea1d71 100644 --- a/libc/nt/enum/errormodeflags.h +++ b/libc/nt/enum/errormodeflags.h @@ -1,15 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_ERRORMODEFLAGS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_ERRORMODEFLAGS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ -enum NtErrorModeFlags { - kNtErrorModeDefault = 0x0, - kNtSemFailcriticalerrors = 0x1, - kNtSemNogpfaulterrorbox = 0x2, - kNtSemNoopenfileerrorbox = 0x8000 -}; +#define kNtErrorModeDefault 0x0 +#define kNtSemFailcriticalerrors 0x1 +#define kNtSemNogpfaulterrorbox 0x2 +#define kNtSemNoopenfileerrorbox 0x8000 -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_ERRORMODEFLAGS_H_ */ diff --git a/libc/nt/enum/event.h b/libc/nt/enum/event.h new file mode 100644 index 00000000..d1227b70 --- /dev/null +++ b/libc/nt/enum/event.h @@ -0,0 +1,56 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_EVENT_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_EVENT_H_ + +#define kNtEventSystemSound 0x0001 +#define kNtEventSystemAlert 0x0002 +#define kNtEventSystemForeground 0x0003 +#define kNtEventSystemMenustart 0x0004 +#define kNtEventSystemMenuend 0x0005 +#define kNtEventSystemMenupopupstart 0x0006 +#define kNtEventSystemMenupopupend 0x0007 +#define kNtEventSystemCapturestart 0x0008 +#define kNtEventSystemCaptureend 0x0009 +#define kNtEventSystemMovesizestart 0x000A +#define kNtEventSystemMovesizeend 0x000B +#define kNtEventSystemContexthelpstart 0x000C +#define kNtEventSystemContexthelpend 0x000D +#define kNtEventSystemDragdropstart 0x000E +#define kNtEventSystemDragdropend 0x000F +#define kNtEventSystemDialogstart 0x0010 +#define kNtEventSystemDialogend 0x0011 +#define kNtEventSystemScrollingstart 0x0012 +#define kNtEventSystemScrollingend 0x0013 +#define kNtEventSystemSwitchstart 0x0014 +#define kNtEventSystemSwitchend 0x0015 +#define kNtEventSystemMinimizestart 0x0016 +#define kNtEventSystemMinimizeend 0x0017 + +#define kNtEventConsoleCaret 0x4001 +#define kNtEventConsoleUpdateRegion 0x4002 +#define kNtEventConsoleUpdateSimple 0x4003 +#define kNtEventConsoleUpdateScroll 0x4004 +#define kNtEventConsoleLayout 0x4005 +#define kNtEventConsoleStartApplication 0x4006 +#define kNtEventConsoleEndApplication 0x4007 + +#define kNtEventObjectCreate 0x8000 +#define kNtEventObjectDestroy 0x8001 +#define kNtEventObjectShow 0x8002 +#define kNtEventObjectHide 0x8003 +#define kNtEventObjectReorder 0x8004 +#define kNtEventObjectFocus 0x8005 +#define kNtEventObjectSelection 0x8006 +#define kNtEventObjectSelectionadd 0x8007 +#define kNtEventObjectSelectionremove 0x8008 +#define kNtEventObjectSelectionwithin 0x8009 +#define kNtEventObjectStatechange 0x800A +#define kNtEventObjectLocationchange 0x800B +#define kNtEventObjectNamechange 0x800C +#define kNtEventObjectDescriptionchange 0x800D +#define kNtEventObjectValuechange 0x800E +#define kNtEventObjectParentchange 0x800F +#define kNtEventObjectHelpchange 0x8010 +#define kNtEventObjectDefactionchange 0x8011 +#define kNtEventObjectAcceleratorchange 0x8012 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_EVENT_H_ */ diff --git a/libc/nt/enum/eventtype.h b/libc/nt/enum/eventtype.h index 07924f1c..edb6dbb8 100644 --- a/libc/nt/enum/eventtype.h +++ b/libc/nt/enum/eventtype.h @@ -1,8 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_EVENTTYPE_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_EVENTTYPE_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtEventType { kNtNotificationEvent, kNtSynchronizationEvent }; +#define kNtNotificationEvent 0 +#define kNtSynchronizationEvent 1 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_EVENTTYPE_H_ */ diff --git a/libc/nt/enum/filelockflags.h b/libc/nt/enum/filelockflags.h index 3c1457e4..9f153b19 100644 --- a/libc/nt/enum/filelockflags.h +++ b/libc/nt/enum/filelockflags.h @@ -1,11 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_FILELOCKFLAGS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_FILELOCKFLAGS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtFileLockFlags { - kNtLockfileFailImmediately = 1, - kNtLockfileExclusiveLock = 2, -}; +#define kNtLockfileFailImmediately 1 +#define kNtLockfileExclusiveLock 2 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_FILELOCKFLAGS_H_ */ diff --git a/libc/nt/enum/filemovemethod.h b/libc/nt/enum/filemovemethod.h index bb93c3cc..33637b56 100644 --- a/libc/nt/enum/filemovemethod.h +++ b/libc/nt/enum/filemovemethod.h @@ -1,8 +1,8 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_FILEMOVEMETHOD_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_FILEMOVEMETHOD_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtFileMoveMethod { kNtFileBegin, kNtFileCurrent, kNtFileEnd }; +#define kNtFileBegin 0 +#define kNtFileCurrent 1 +#define kNtFileEnd 2 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_FILEMOVEMETHOD_H_ */ diff --git a/libc/nt/enum/filetype.h b/libc/nt/enum/filetype.h index 7ddfe4ed..98e79d2d 100644 --- a/libc/nt/enum/filetype.h +++ b/libc/nt/enum/filetype.h @@ -1,20 +1,10 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_FILETYPE_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_FILETYPE_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -/** - * NT Device File Types. - * - * @see GetFileType() - * @see libc/sysv/consts.sh - */ -enum NtFileType { - kNtFileTypeUnknown = 0x0000, - kNtFileTypeDisk = 0x0001, /* @see S_ISBLK() */ - kNtFileTypeChar = 0x0002, /* @see S_ISCHR() */ - kNtFileTypePipe = 0x0003, /* @see S_ISFIFO() */ - kNtFileTypeRemote = 0x8000 /* unused -MSDN */ -}; +#define kNtFileTypeUnknown 0x0000 +#define kNtFileTypeDisk 0x0001 /* @see S_ISBLK() */ +#define kNtFileTypeChar 0x0002 /* @see S_ISCHR() */ +#define kNtFileTypePipe 0x0003 /* @see S_ISFIFO() */ +#define kNtFileTypeRemote 0x8000 /* unused -MSDN */ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_FILETYPE_H_ */ diff --git a/libc/nt/enum/findexinfolevels.h b/libc/nt/enum/findexinfolevels.h index ea4fa1c5..49fa077f 100644 --- a/libc/nt/enum/findexinfolevels.h +++ b/libc/nt/enum/findexinfolevels.h @@ -1,12 +1,8 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_FINDEXINFOLEVELS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXINFOLEVELS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtFindexInfoLevels { - kNtFindExInfoStandard, - kNtFindExInfoBasic, - kNtFindExInfoMaxInfoLevel -}; +#define kNtFindExInfoStandard 0 +#define kNtFindExInfoBasic 1 +#define kNtFindExInfoMaxInfoLevel 2 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_FINDEXINFOLEVELS_H_ */ diff --git a/libc/nt/enum/findexsearchops.h b/libc/nt/enum/findexsearchops.h index 566536e2..8a1dee4e 100644 --- a/libc/nt/enum/findexsearchops.h +++ b/libc/nt/enum/findexsearchops.h @@ -1,13 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_FINDEXSEARCHOPS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXSEARCHOPS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtFindexSearchOps { - kNtFindExSearchNameMatch, - kNtFindExSearchLimitToDirectories, - kNtFindExSearchLimitToDevices, - kNtFindExSearchMaxSearchOp -}; +#define kNtFindExSearchNameMatch 0 +#define kNtFindExSearchLimitToDirectories 1 +#define kNtFindExSearchLimitToDevices 2 +#define kNtFindExSearchMaxSearchOp 3 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_FINDEXSEARCHOPS_H_ */ diff --git a/libc/nt/enum/formatmessageflags.h b/libc/nt/enum/formatmessageflags.h index d35ce30e..c12991c3 100644 --- a/libc/nt/enum/formatmessageflags.h +++ b/libc/nt/enum/formatmessageflags.h @@ -1,16 +1,12 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_FORMATMESSAGEFLAGS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_FORMATMESSAGEFLAGS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtFormatMessageFlags { - kNtFormatMessageAllocateBuffer = 0x100, - kNtFormatMessageIgnoreInserts = 0x200, - kNtFormatMessageFromString = 0x400, - kNtFormatMessageFromHmodule = 0x800, - kNtFormatMessageFromSystem = 0x1000, - kNtFormatMessageArgumentArray = 0x2000, - kNtFormatMessageMaxWidthMask = 0xff -}; +#define kNtFormatMessageAllocateBuffer 0x100 +#define kNtFormatMessageIgnoreInserts 0x200 +#define kNtFormatMessageFromString 0x400 +#define kNtFormatMessageFromHmodule 0x800 +#define kNtFormatMessageFromSystem 0x1000 +#define kNtFormatMessageArgumentArray 0x2000 +#define kNtFormatMessageMaxWidthMask 0xff -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_FORMATMESSAGEFLAGS_H_ */ diff --git a/libc/nt/enum/getfileexinfolevels.h b/libc/nt/enum/getfileexinfolevels.h index 520d4dbd..207e57cd 100644 --- a/libc/nt/enum/getfileexinfolevels.h +++ b/libc/nt/enum/getfileexinfolevels.h @@ -1,8 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_GETFILEEXINFOLEVELS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_GETFILEEXINFOLEVELS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtGetFileexInfoLevels { kNtGetFileExInfoStandard, kNtGetFile_MAX }; +#define kNtGetFileExInfoStandard 0 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_GETFILEEXINFOLEVELS_H_ */ diff --git a/libc/nt/enum/ht.h b/libc/nt/enum/ht.h new file mode 100644 index 00000000..7372e487 --- /dev/null +++ b/libc/nt/enum/ht.h @@ -0,0 +1,34 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_HT_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_HT_H_ + +#define kNtHterror -2 +#define kNtHttransparent -1 +#define kNtHtnowhere 0 +#define kNtHtclient 1 +#define kNtHtcaption 2 +#define kNtHtsysmenu 3 +#define kNtHtgrowbox 4 +#define kNtHtsize kNtHtgrowbox +#define kNtHtmenu 5 +#define kNtHthscroll 6 +#define kNtHtvscroll 7 +#define kNtHtminbutton 8 +#define kNtHtmaxbutton 9 +#define kNtHtleft 10 +#define kNtHtright 11 +#define kNtHttop 12 +#define kNtHttopleft 13 +#define kNtHttopright 14 +#define kNtHtbottom 15 +#define kNtHtbottomleft 16 +#define kNtHtbottomright 17 +#define kNtHtborder 18 +#define kNtHtreduce kNtHtminbutton +#define kNtHtzoom kNtHtmaxbutton +#define kNtHtsizefirst kNtHtleft +#define kNtHtsizelast kNtHtbottomright +#define kNtHtobject 19 +#define kNtHtclose 20 +#define kNtHthelp 21 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_HT_H_ */ diff --git a/libc/nt/enum/imageauxsymboltype.h b/libc/nt/enum/imageauxsymboltype.h index d2211006..22b69fa8 100644 --- a/libc/nt/enum/imageauxsymboltype.h +++ b/libc/nt/enum/imageauxsymboltype.h @@ -1,8 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_IMAGEAUXSYMBOLTYPE_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_IMAGEAUXSYMBOLTYPE_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtImageAuxSymbolType { IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1 }; +#define kNtImageAuxSymbolTypeTokenDef 1 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_IMAGEAUXSYMBOLTYPE_H_ */ diff --git a/libc/nt/enum/jobobjectinfoclass.h b/libc/nt/enum/jobobjectinfoclass.h index 3da98d2a..1f04880e 100644 --- a/libc/nt/enum/jobobjectinfoclass.h +++ b/libc/nt/enum/jobobjectinfoclass.h @@ -1,20 +1,15 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_JOBOBJECTINFOCLASS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_JOBOBJECTINFOCLASS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtJobObjectInfoClass { - kNtJobObjectBasicAccountingInformation = 1, - kNtJobObjectBasicLimitInformation, - kNtJobObjectBasicProcessIdList, - kNtJobObjectBasicUIRestrictions, - kNtJobObjectSecurityLimitInformation, - kNtJobObjectEndOfJobTimeInformation, - kNtJobObjectAssociateCompletionPortInformation, - kNtJobObjectBasicAndIoAccountingInformation, - kNtJobObjectExtendedLimitInformation, - kNtJobObjectJobSetInformation, - kNtJobObjectInfoClass_MAX -}; +#define kNtJobObjectBasicAccountingInformation 1 +#define kNtJobObjectBasicLimitInformation 2 +#define kNtJobObjectBasicProcessIdList 3 +#define kNtJobObjectBasicUIRestrictions 4 +#define kNtJobObjectSecurityLimitInformation 5 +#define kNtJobObjectEndOfJobTimeInformation 6 +#define kNtJobObjectAssociateCompletionPortInformation 7 +#define kNtJobObjectBasicAndIoAccountingInformation 8 +#define kNtJobObjectExtendedLimitInformation 9 +#define kNtJobObjectJobSetInformation 10 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_JOBOBJECTINFOCLASS_H_ */ diff --git a/libc/nt/enum/keyaccess.h b/libc/nt/enum/keyaccess.h index 125a5774..06709ad4 100644 --- a/libc/nt/enum/keyaccess.h +++ b/libc/nt/enum/keyaccess.h @@ -1,13 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtKeyAccess { - kNtKeyRead = 0x00020019, - kNtKeyWrite = 0x00020006, - kNtKeyExecute = 0x00020019, - kNtKeyAllAccess = 0x000f003f -}; +#define kNtKeyRead 0x00020019 +#define kNtKeyWrite 0x00020006 +#define kNtKeyExecute 0x00020019 +#define kNtKeyAllAccess 0x000f003f -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_ */ diff --git a/libc/nt/enum/keyinformationclass.h b/libc/nt/enum/keyinformationclass.h index 9640784e..98f15c21 100644 --- a/libc/nt/enum/keyinformationclass.h +++ b/libc/nt/enum/keyinformationclass.h @@ -1,13 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_KEYINFORMATIONCLASS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_KEYINFORMATIONCLASS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtKeyInformationClass { - kNtKeyBasicInformation, - kNtKeyNodeInformation, - kNtKeyFullInformation, - kNtKeyNameInformation -}; +#define kNtKeyBasicInformation 0 +#define kNtKeyNodeInformation 1 +#define kNtKeyFullInformation 2 +#define kNtKeyNameInformation 3 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_KEYINFORMATIONCLASS_H_ */ diff --git a/libc/nt/enum/mb.h b/libc/nt/enum/mb.h new file mode 100644 index 00000000..edae1522 --- /dev/null +++ b/libc/nt/enum/mb.h @@ -0,0 +1,44 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_MB_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_MB_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +#define kNtMbOk 0x00000000 +#define kNtMbOkcancel 0x00000001 +#define kNtMbAbortretryignore 0x00000002 +#define kNtMbYesnocancel 0x00000003 +#define kNtMbYesno 0x00000004 +#define kNtMbRetrycancel 0x00000005 +#define kNtMbCanceltrycontinue 0x00000006 +#define kNtMbIconhand 0x00000010 +#define kNtMbIconquestion 0x00000020 +#define kNtMbIconexclamation 0x00000030 +#define kNtMbIconasterisk 0x00000040 +#define kNtMbUsericon 0x00000080 +#define kNtMbIconwarning kNtMbIconexclamation +#define kNtMbIconerror kNtMbIconhand +#define kNtMbIconinformation kNtMbIconasterisk +#define kNtMbIconstop kNtMbIconhand +#define kNtMbDefbutton1 0x00000000 +#define kNtMbDefbutton2 0x00000100 +#define kNtMbDefbutton3 0x00000200 +#define kNtMbDefbutton4 0x00000300 +#define kNtMbApplmodal 0x00000000 +#define kNtMbSystemmodal 0x00001000 +#define kNtMbTaskmodal 0x00002000 +#define kNtMbHelp 0x00004000 +#define kNtMbNofocus 0x00008000 +#define kNtMbSetforeground 0x00010000 +#define kNtMbDefaultDesktopOnly 0x00020000 +#define kNtMbTopmost 0x00040000 +#define kNtMbRight 0x00080000 +#define kNtMbRtlreading 0x00100000 +#define kNtMbServiceNotification 0x00200000 +#define kNtMbServiceNotificationNt3x 0x00040000 +#define kNtMbTypemask 0x0000000F +#define kNtMbIconmask 0x000000F0 +#define kNtMbDefmask 0x00000F00 +#define kNtMbModemask 0x00003000 +#define kNtMbMiscmask 0x0000C000 + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_MB_H_ */ diff --git a/libc/nt/enum/memoryinformationclass.h b/libc/nt/enum/memoryinformationclass.h index ba0705a8..00bab926 100644 --- a/libc/nt/enum/memoryinformationclass.h +++ b/libc/nt/enum/memoryinformationclass.h @@ -1,13 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_MEMORYINFORMATIONCLASS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_MEMORYINFORMATIONCLASS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtMemoryInformationClass { - kNtMemoryBasicInformation, - kNtMemoryWorkingSetList, - kNtMemorySectionName, - kNtMemoryBasicVlmInformation -}; +#define kNtMemoryBasicInformation 0 +#define kNtMemoryWorkingSetList 1 +#define kNtMemorySectionName 2 +#define kNtMemoryBasicVlmInformation 3 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_MEMORYINFORMATIONCLASS_H_ */ diff --git a/libc/nt/enum/messageboxtype.h b/libc/nt/enum/messageboxtype.h deleted file mode 100644 index 35c9d510..00000000 --- a/libc/nt/enum/messageboxtype.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_NT_ENUM_MESSAGEBOXTYPE_H_ -#define COSMOPOLITAN_LIBC_NT_ENUM_MESSAGEBOXTYPE_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) - -enum MessageBoxType { - kNtMbOk = 0x00000000, - kNtMbOkcancel = 0x00000001, - kNtMbAbortretryignore = 0x00000002, - kNtMbYesnocancel = 0x00000003, - kNtMbYesno = 0x00000004, - kNtMbRetrycancel = 0x00000005, - kNtMbCanceltrycontinue = 0x00000006, - kNtMbIconhand = 0x00000010, - kNtMbIconquestion = 0x00000020, - kNtMbIconexclamation = 0x00000030, - kNtMbIconasterisk = 0x00000040, - kNtMbUsericon = 0x00000080, - kNtMbIconwarning = kNtMbIconexclamation, - kNtMbIconerror = kNtMbIconhand, - kNtMbIconinformation = kNtMbIconasterisk, - kNtMbIconstop = kNtMbIconhand, - kNtMbDefbutton1 = 0x00000000, - kNtMbDefbutton2 = 0x00000100, - kNtMbDefbutton3 = 0x00000200, - kNtMbDefbutton4 = 0x00000300, - kNtMbApplmodal = 0x00000000, - kNtMbSystemmodal = 0x00001000, - kNtMbTaskmodal = 0x00002000, - kNtMbHelp = 0x00004000, - kNtMbNofocus = 0x00008000, - kNtMbSetforeground = 0x00010000, - kNtMbDefaultDesktopOnly = 0x00020000, - kNtMbTopmost = 0x00040000, - kNtMbRight = 0x00080000, - kNtMbRtlreading = 0x00100000, - kNtMbServiceNotification = 0x00200000, - kNtMbServiceNotificationNt3x = 0x00040000, - kNtMbTypemask = 0x0000000F, - kNtMbIconmask = 0x000000F0, - kNtMbDefmask = 0x00000F00, - kNtMbModemask = 0x00003000, - kNtMbMiscmask = 0x0000C000 -}; - -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_NT_ENUM_MESSAGEBOXTYPE_H_ */ diff --git a/libc/nt/enum/mf.h b/libc/nt/enum/mf.h new file mode 100644 index 00000000..2abc970f --- /dev/null +++ b/libc/nt/enum/mf.h @@ -0,0 +1,32 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_MF_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_MF_H_ + +#define kNtMfInsert 0x00000000 +#define kNtMfChange 0x00000080 +#define kNtMfAppend 0x00000100 +#define kNtMfDelete 0x00000200 +#define kNtMfRemove 0x00001000 +#define kNtMfBycommand 0x00000000 +#define kNtMfByposition 0x00000400 +#define kNtMfSeparator 0x00000800 +#define kNtMfEnabled 0x00000000 +#define kNtMfGrayed 0x00000001 +#define kNtMfDisabled 0x00000002 +#define kNtMfUnchecked 0x00000000 +#define kNtMfChecked 0x00000008 +#define kNtMfUsecheckbitmaps 0x00000200 +#define kNtMfString 0x00000000 +#define kNtMfBitmap 0x00000004 +#define kNtMfOwnerdraw 0x00000100 +#define kNtMfPopup 0x00000010 +#define kNtMfMenubarbreak 0x00000020 +#define kNtMfMenubreak 0x00000040 +#define kNtMfUnhilite 0x00000000 +#define kNtMfHilite 0x00000080 +#define kNtMfDefault 0x00001000 +#define kNtMfSysmenu 0x00002000 +#define kNtMfHelp 0x00004000 +#define kNtMfRightjustify 0x00004000 +#define kNtMfMouseselect 0x00008000 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_MF_H_ */ diff --git a/libc/nt/enum/mk.h b/libc/nt/enum/mk.h new file mode 100644 index 00000000..d310fba1 --- /dev/null +++ b/libc/nt/enum/mk.h @@ -0,0 +1,12 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_MK_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_MK_H_ + +#define kNtMkLbutton 0x0001 +#define kNtMkRbutton 0x0002 +#define kNtMkShift 0x0004 +#define kNtMkControl 0x0008 +#define kNtMkMbutton 0x0010 +#define kNtMkXbutton1 0x0020 +#define kNtMkXbutton2 0x0040 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_MK_H_ */ diff --git a/libc/nt/enum/movefileexflags.h b/libc/nt/enum/movefileexflags.h index a45b124b..19020716 100644 --- a/libc/nt/enum/movefileexflags.h +++ b/libc/nt/enum/movefileexflags.h @@ -1,15 +1,11 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_MOVEFILEEXFLAGS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_MOVEFILEEXFLAGS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtMoveFileExFlags { - kNtMovefileReplaceExisting = 1, - kNtMovefileCopyAllowed = 2, - kNtMovefileDelayUntilReboot = 4, - kNtMovefileCreateHardlink = 16, - kNtMovefileFailIfNotTrackable = 32, - kNtMovefileWriteThrough = 8 -}; +#define kNtMovefileReplaceExisting 1 +#define kNtMovefileCopyAllowed 2 +#define kNtMovefileDelayUntilReboot 4 +#define kNtMovefileCreateHardlink 16 +#define kNtMovefileFailIfNotTrackable 32 +#define kNtMovefileWriteThrough 8 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_MOVEFILEEXFLAGS_H_ */ diff --git a/libc/nt/enum/objectinformationclass.h b/libc/nt/enum/objectinformationclass.h index 743d6a32..c61afcf2 100644 --- a/libc/nt/enum/objectinformationclass.h +++ b/libc/nt/enum/objectinformationclass.h @@ -1,14 +1,10 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_OBJECTINFORMATIONCLASS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_OBJECTINFORMATIONCLASS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtObjectInformationClass { - kNtObjectBasicInformation, /*→ struct NtObjectBasicInformation */ - kNtObjectNameInformation, /*→ etc. */ - kNtObjectTypeInformation, - kNtObjectAllInformation, - kNtObjectDataInformation -}; +#define kNtObjectBasicInformation 0 /*→ struct NtObjectBasicInformation */ +#define kNtObjectNameInformation 1 /*→ etc. */ +#define kNtObjectTypeInformation 2 +#define kNtObjectAllInformation 3 +#define kNtObjectDataInformation 4 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_OBJECTINFORMATIONCLASS_H_ */ diff --git a/libc/nt/enum/offerpriority.h b/libc/nt/enum/offerpriority.h index 10c23359..230c5e18 100644 --- a/libc/nt/enum/offerpriority.h +++ b/libc/nt/enum/offerpriority.h @@ -1,14 +1,10 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_OFFERPRIORITY_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_OFFERPRIORITY_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtOfferPriority { - /* TODO(jart): Are these values correct? */ - kNtVmOfferPriorityVeryLow = 1, /* 0x00001000? */ - kNtVmOfferPriorityLow, /* 0x00002000? */ - kNtVmOfferPriorityBelowNormal, /* 0x00002000? */ - kNtVmOfferPriorityNormal /* 0x00002000? */ -}; +/* TODO(jart): Are these values correct? */ +#define kNtVmOfferPriorityVeryLow 1 /* 0x00001000? */ +#define kNtVmOfferPriorityLow 2 /* 0x00002000? */ +#define kNtVmOfferPriorityBelowNormal 3 /* 0x00002000? */ +#define kNtVmOfferPriorityNormal 4 /* 0x00002000? */ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_OFFERPRIORITY_H_ */ diff --git a/libc/nt/enum/ofn.h b/libc/nt/enum/ofn.h new file mode 100644 index 00000000..68463a15 --- /dev/null +++ b/libc/nt/enum/ofn.h @@ -0,0 +1,31 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_OFN_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_OFN_H_ + +#define kNtOfnReadonly 0x00000001 +#define kNtOfnOverwriteprompt 0x00000002 +#define kNtOfnHidereadonly 0x00000004 +#define kNtOfnNochangedir 0x00000008 +#define kNtOfnShowhelp 0x00000010 +#define kNtOfnEnablehook 0x00000020 +#define kNtOfnEnabletemplate 0x00000040 +#define kNtOfnEnabletemplatehandle 0x00000080 +#define kNtOfnNovalidate 0x00000100 +#define kNtOfnAllowmultiselect 0x00000200 +#define kNtOfnExtensiondifferent 0x00000400 +#define kNtOfnPathmustexist 0x00000800 +#define kNtOfnFilemustexist 0x00001000 +#define kNtOfnCreateprompt 0x00002000 +#define kNtOfnShareaware 0x00004000 +#define kNtOfnNoreadonlyreturn 0x00008000 +#define kNtOfnNotestfilecreate 0x00010000 +#define kNtOfnNonetworkbutton 0x00020000 +#define kNtOfnNolongnames 0x00040000 +#define kNtOfnExplorer 0x00080000 +#define kNtOfnNodereferencelinks 0x00100000 +#define kNtOfnLongnames 0x00200000 +#define kNtOfnEnableincludenotify 0x00400000 +#define kNtOfnEnablesizing 0x00800000 +#define kNtOfnDontaddtorecent 0x02000000 +#define kNtOfnForceshowhidden 0x10000000 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_OFN_H_ */ diff --git a/libc/nt/enum/processinfoclass.h b/libc/nt/enum/processinfoclass.h index 7be961a0..a5c6d4c7 100644 --- a/libc/nt/enum/processinfoclass.h +++ b/libc/nt/enum/processinfoclass.h @@ -1,21 +1,17 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_PROCESSINFOCLASS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSINFOCLASS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtProcessInfoClass { - kNtProcessBasicInformation = 0, - kNtProcessQuotaLimits = 1, - kNtProcessIoCounters = 2, - kNtProcessVmCounters = 3, - kNtProcessTimes = 4, - kNtProcessBasePriority = 5, - kNtProcessRaisePriority = 6, - kNtProcessDebugPort = 7, - kNtProcessExceptionPort = 8, - kNtProcessAccessToken = 9, - kNtProcessWow64Information = 26, - kNtProcessImageFileName = 27 -}; +#define kNtProcessBasicInformation 0 +#define kNtProcessQuotaLimits 1 +#define kNtProcessIoCounters 2 +#define kNtProcessVmCounters 3 +#define kNtProcessTimes 4 +#define kNtProcessBasePriority 5 +#define kNtProcessRaisePriority 6 +#define kNtProcessDebugPort 7 +#define kNtProcessExceptionPort 8 +#define kNtProcessAccessToken 9 +#define kNtProcessWow64Information 26 +#define kNtProcessImageFileName 27 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_PROCESSINFOCLASS_H_ */ diff --git a/libc/nt/enum/progress.h b/libc/nt/enum/progress.h new file mode 100644 index 00000000..c3237563 --- /dev/null +++ b/libc/nt/enum/progress.h @@ -0,0 +1,9 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_PROGRESS_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_PROGRESS_H_ + +#define kNtProgressContinue 0 +#define kNtProgressCancel 1 +#define kNtProgressStop 2 +#define kNtProgressQuiet 3 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_PROGRESS_H_ */ diff --git a/libc/nt/enum/rdw.h b/libc/nt/enum/rdw.h new file mode 100644 index 00000000..d2afcdb2 --- /dev/null +++ b/libc/nt/enum/rdw.h @@ -0,0 +1,17 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_RDW_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_RDW_H_ + +#define kNtRdwInvalidate 0x0001 +#define kNtRdwInternalpaint 0x0002 +#define kNtRdwErase 0x0004 +#define kNtRdwValidate 0x0008 +#define kNtRdwNointernalpaint 0x0010 +#define kNtRdwNoerase 0x0020 +#define kNtRdwNochildren 0x0040 +#define kNtRdwAllchildren 0x0080 +#define kNtRdwUpdatenow 0x0100 +#define kNtRdwErasenow 0x0200 +#define kNtRdwFrame 0x0400 +#define kNtRdwNoframe 0x0800 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_RDW_H_ */ diff --git a/libc/nt/enum/reggetvalueflags.h b/libc/nt/enum/reggetvalueflags.h index 8def968f..2fb1c6f1 100644 --- a/libc/nt/enum/reggetvalueflags.h +++ b/libc/nt/enum/reggetvalueflags.h @@ -1,24 +1,20 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_REGGETVALUEFLAGS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_REGGETVALUEFLAGS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtRegGetValueFlags { - kNtRrfRtRegNone = 0x00000001, - kNtRrfRtRegSz = 0x00000002, - kNtRrfRtRegExpandSz = 0x00000004, - kNtRrfRtRegBinary = 0x00000008, - kNtRrfRtRegDword = 0x00000010, - kNtRrfRtRegMultiSz = 0x00000020, - kNtRrfRtRegQword = 0x00000040, - kNtRrfRtDword = kNtRrfRtRegBinary | kNtRrfRtRegDword, - kNtRrfRtQword = kNtRrfRtRegBinary | kNtRrfRtRegQword, - kNtRrfRtAny = 0x0000ffff, - kNtRrfSubkeyWow6464key = 0x00010000, - kNtRrfSubkeyWow6432key = 0x00020000, - kNtRrfWow64Mask = 0x00030000, - kNtRrfNoexpand = 0x10000000, - kNtRrfZeroonfailure = 0x20000000 -}; +#define kNtRrfRtRegNone 0x00000001 +#define kNtRrfRtRegSz 0x00000002 +#define kNtRrfRtRegExpandSz 0x00000004 +#define kNtRrfRtRegBinary 0x00000008 +#define kNtRrfRtRegDword 0x00000010 +#define kNtRrfRtRegMultiSz 0x00000020 +#define kNtRrfRtRegQword 0x00000040 +#define kNtRrfRtDword (kNtRrfRtRegBinary | kNtRrfRtRegDword) +#define kNtRrfRtQword (kNtRrfRtRegBinary | kNtRrfRtRegQword) +#define kNtRrfRtAny 0x0000ffff +#define kNtRrfSubkeyWow6464key 0x00010000 +#define kNtRrfSubkeyWow6432key 0x00020000 +#define kNtRrfWow64Mask 0x00030000 +#define kNtRrfNoexpand 0x10000000 +#define kNtRrfZeroonfailure 0x20000000 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_REGGETVALUEFLAGS_H_ */ diff --git a/libc/nt/enum/regtype.h b/libc/nt/enum/regtype.h index 41bab0c6..63c16460 100644 --- a/libc/nt/enum/regtype.h +++ b/libc/nt/enum/regtype.h @@ -1,21 +1,17 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_REGTYPE_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_REGTYPE_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtRegType { - kNtRegNone = 0, - kNtRegSz = 1, /* UTF-16 NUL-terminated string */ - kNtRegExpandSz = 2, /* UTF-16 NUL-terminated string w/ env vars refs */ - kNtRegBinary = 3, - kNtRegDword = 4, - kNtRegDwordBigEndian = 5, - kNtRegLink = 6, - kNtRegMultiSz = 7, /* UTF-16 double-NUL-terminated string list */ - kNtRegResourceList = 8, - kNtRegFullResourceDescriptor = 9, - kNtRegResourceRequirementsList = 10, - kNtRegQword = 11, -}; +#define kNtRegNone 0 +#define kNtRegSz 1 /* UTF-16 string */ +#define kNtRegExpandSz 2 /* UTF-16 string w/ env vars refs */ +#define kNtRegBinary 3 +#define kNtRegDword 4 +#define kNtRegDwordBigEndian 5 +#define kNtRegLink 6 +#define kNtRegMultiSz 7 /* UTF-16 double-nul-terminated */ +#define kNtRegResourceList 8 +#define kNtRegFullResourceDescriptor 9 +#define kNtRegResourceRequirementsList 10 +#define kNtRegQword 11 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_REGTYPE_H_ */ diff --git a/libc/nt/enum/replacefile.h b/libc/nt/enum/replacefile.h new file mode 100644 index 00000000..67b70d90 --- /dev/null +++ b/libc/nt/enum/replacefile.h @@ -0,0 +1,8 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_REPLACEFILE_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_REPLACEFILE_H_ + +#define kNtReplacefileWriteThrough 1 +#define kNtReplacefileIgnoreMergeErrors 2 +#define kNtReplacefileIgnoreAclErrors 4 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_REPLACEFILE_H_ */ diff --git a/libc/nt/enum/sc.h b/libc/nt/enum/sc.h new file mode 100644 index 00000000..5aec1fd1 --- /dev/null +++ b/libc/nt/enum/sc.h @@ -0,0 +1,25 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_SC_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_SC_H_ + +#define kNtScSize 0xF000 +#define kNtScMove 0xF010 +#define kNtScMinimize 0xF020 +#define kNtScMaximize 0xF030 +#define kNtScNextwindow 0xF040 +#define kNtScPrevwindow 0xF050 +#define kNtScClose 0xF060 +#define kNtScVscroll 0xF070 +#define kNtScHscroll 0xF080 +#define kNtScMousemenu 0xF090 +#define kNtScKeymenu 0xF100 +#define kNtScArrange 0xF110 +#define kNtScRestore 0xF120 +#define kNtScTasklist 0xF130 +#define kNtScScreensave 0xF140 +#define kNtScHotkey 0xF150 +#define kNtScDefault 0xF160 +#define kNtScMonitorpower 0xF170 +#define kNtScContexthelp 0xF180 +#define kNtScSeparator 0xF00F + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_SC_H_ */ diff --git a/libc/nt/enum/sectioninformationclass.h b/libc/nt/enum/sectioninformationclass.h index 1075730d..6973206c 100644 --- a/libc/nt/enum/sectioninformationclass.h +++ b/libc/nt/enum/sectioninformationclass.h @@ -1,11 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINFORMATIONCLASS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINFORMATIONCLASS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtSectionInformationClass { - kNtSectionBasicInformation, - kNtSectionImageInformation -}; +#define kNtSectionBasicInformation 0 +#define kNtSectionImageInformation 1 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINFORMATIONCLASS_H_ */ diff --git a/libc/nt/enum/sectionmapflags.h b/libc/nt/enum/sectionmapflags.h index 8daef5b0..d3fb61e9 100644 --- a/libc/nt/enum/sectionmapflags.h +++ b/libc/nt/enum/sectionmapflags.h @@ -1,15 +1,11 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_SECTIONMAPFLAGS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONMAPFLAGS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtSectionMapFlags { - kNtSectionQuery = 0x0001, - kNtSectionMapWrite = 0x0002, - kNtSectionMapRead = 0x0004, - kNtSectionMapExecute = 0x0008, - kNtSectionExtendSize = 0x0010, - kNtSectionMapExecuteExplicit = 0x0020 -}; +#define kNtSectionQuery 0x0001 +#define kNtSectionMapWrite 0x0002 +#define kNtSectionMapRead 0x0004 +#define kNtSectionMapExecute 0x0008 +#define kNtSectionExtendSize 0x0010 +#define kNtSectionMapExecuteExplicit 0x0020 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_SECTIONMAPFLAGS_H_ */ diff --git a/libc/nt/enum/securityimpersonationlevel.h b/libc/nt/enum/securityimpersonationlevel.h index 9aefc6a3..1913201d 100644 --- a/libc/nt/enum/securityimpersonationlevel.h +++ b/libc/nt/enum/securityimpersonationlevel.h @@ -1,13 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_SECURITYIMPERSONATIONLEVEL_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYIMPERSONATIONLEVEL_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtSecurityImpersonationLevel { - kNtSecurityAnonymous, - kNtSecurityIdentification, - kNtSecurityImpersonation, - kNtSecurityDelegation -}; +#define kNtSecurityAnonymous 0 +#define kNtSecurityIdentification 1 +#define kNtSecurityImpersonation 2 +#define kNtSecurityDelegation 3 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_SECURITYIMPERSONATIONLEVEL_H_ */ diff --git a/libc/nt/enum/signal.h b/libc/nt/enum/signal.h new file mode 100644 index 00000000..812a7614 --- /dev/null +++ b/libc/nt/enum/signal.h @@ -0,0 +1,29 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_SIGNAL_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_SIGNAL_H_ + +#define kNtSignalBreakpoint 0x80000003u +#define kNtSignalIllegalInstruction 0xC000001Du +#define kNtSignalPrivInstruction 0xC0000096u +#define kNtSignalGuardPage 0x80000001u +#define kNtSignalAccessViolation 0xC0000005u +#define kNtSignalInPageError 0xC0000006u +#define kNtSignalInvalidHandle 0xC0000008u +#define kNtSignalInvalidParameter 0xC000000du +#define kNtSignalFltDenormalOperand 0xC000008Du +#define kNtSignalFltDivideByZero 0xC000008Eu +#define kNtSignalFltInexactResult 0xC000008Fu +#define kNtSignalFltInvalidOperation 0xC0000090u +#define kNtSignalFltOverflow 0xC0000091u +#define kNtSignalFltStackCheck 0xC0000092u +#define kNtSignalFltUnderflow 0xC0000093u +#define kNtSignalIntegerDivideByZero 0xC0000094u +#define kNtSignalDllNotFound 0xC0000135u +#define kNtSignalOrdinalNotFound 0xC0000138u +#define kNtSignalEntrypointNotFound 0xC0000139u +#define kNtSignalControlCExit 0xC000013Au +#define kNtSignalDllInitFailed 0xC0000142u +#define kNtSignalFloatMultipleFaults 0xC00002B4u +#define kNtSignalFloatMultipleTraps 0xC00002B5u +#define kNtSignalAssertionFailure 0xC0000420u + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_SIGNAL_H_ */ diff --git a/libc/nt/enum/size.h b/libc/nt/enum/size.h new file mode 100644 index 00000000..9fb1baaf --- /dev/null +++ b/libc/nt/enum/size.h @@ -0,0 +1,10 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_SIZE_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_SIZE_H_ + +#define kNtSizeRestored 0 +#define kNtSizeMinimized 1 +#define kNtSizeMaximized 2 +#define kNtSizeMaxshow 3 +#define kNtSizeMaxhide 4 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_SIZE_H_ */ diff --git a/libc/nt/enum/threadstate.h b/libc/nt/enum/threadstate.h index f257c91e..d1386593 100644 --- a/libc/nt/enum/threadstate.h +++ b/libc/nt/enum/threadstate.h @@ -1,19 +1,13 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_THREADSTATE_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_THREADSTATE_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ -enum NtThreadState { - kNtStateInitialized = 0, - kNtStateReady, - kNtStateRunning, - kNtStateStandby, - kNtStateTerminated, - kNtStateWait, - kNtStateTransition, - kNtStateUnknown -}; +#define kNtStateInitialized 0 +#define kNtStateReady 1 +#define kNtStateRunning 2 +#define kNtStateStandby 3 +#define kNtStateTerminated 4 +#define kNtStateWait 5 +#define kNtStateTransition 6 +#define kNtStateUnknown 7 -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_THREADSTATE_H_ */ diff --git a/libc/nt/enum/tokentype.h b/libc/nt/enum/tokentype.h index b202cb7c..54a070a8 100644 --- a/libc/nt/enum/tokentype.h +++ b/libc/nt/enum/tokentype.h @@ -1,8 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_TOKENTYPE_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_TOKENTYPE_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtTokenType { kNtTokenPrimary = 1, kNtTokenImpersonation }; +#define kNtTokenPrimary 1 +#define kNtTokenImpersonation 2 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_TOKENTYPE_H_ */ diff --git a/libc/nt/enum/tpm.h b/libc/nt/enum/tpm.h new file mode 100644 index 00000000..07f2151f --- /dev/null +++ b/libc/nt/enum/tpm.h @@ -0,0 +1,25 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_TPM_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_TPM_H_ + +#define kNtTpmLeftbutton 0x00000 +#define kNtTpmRightbutton 0x00002 +#define kNtTpmLeftalign 0x00000 +#define kNtTpmCenteralign 0x00004 +#define kNtTpmRightalign 0x00008 +#define kNtTpmTopalign 0x00000 +#define kNtTpmVcenteralign 0x00010 +#define kNtTpmBottomalign 0x00020 +#define kNtTpmHorizontal 0x00000 +#define kNtTpmVertical 0x00040 +#define kNtTpmNonotify 0x00080 +#define kNtTpmReturncmd 0x00100 +#define kNtTpmRecurse 0x00001 +#define kNtTpmHorposanimation 0x00400 +#define kNtTpmHorneganimation 0x00800 +#define kNtTpmVerposanimation 0x01000 +#define kNtTpmVerneganimation 0x02000 +#define kNtTpmNoanimation 0x04000 +#define kNtTpmLayoutrtl 0x08000 +#define kNtTpmWorkarea 0x10000 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_TPM_H_ */ diff --git a/libc/nt/enum/valueinformationclass.h b/libc/nt/enum/valueinformationclass.h index 7223c786..35dc10ab 100644 --- a/libc/nt/enum/valueinformationclass.h +++ b/libc/nt/enum/valueinformationclass.h @@ -1,14 +1,10 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_VALUEINFORMATIONCLASS_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_VALUEINFORMATIONCLASS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -enum NtKeyValueInformationClass { - kNtKeyValueBasicInformation, - kNtKeyValueFullInformation, - kNtKeyValuePartialInformation, - kNtKeyValueFullInformationAlign64, - kNtKeyValuePartialInformationAlign64 -}; +#define kNtKeyValueBasicInformation 0 +#define kNtKeyValueFullInformation 1 +#define kNtKeyValuePartialInformation 2 +#define kNtKeyValueFullInformationAlign64 3 +#define kNtKeyValuePartialInformationAlign64 4 -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_VALUEINFORMATIONCLASS_H_ */ diff --git a/libc/nt/enum/vk.h b/libc/nt/enum/vk.h new file mode 100644 index 00000000..b5235578 --- /dev/null +++ b/libc/nt/enum/vk.h @@ -0,0 +1,182 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_VK_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_VK_H_ + +#define kNtVkLbutton 0x01 +#define kNtVkRbutton 0x02 +#define kNtVkCancel 0x03 +#define kNtVkMbutton 0x04 +#define kNtVkXbutton1 0x05 +#define kNtVkXbutton2 0x06 +#define kNtVkBack 0x08 +#define kNtVkTab 0x09 +#define kNtVkClear 0x0C +#define kNtVkReturn 0x0D +#define kNtVkShift 0x10 +#define kNtVkControl 0x11 +#define kNtVkMenu 0x12 /* alt? */ +#define kNtVkPause 0x13 +#define kNtVkCapital 0x14 +#define kNtVkKana 0x15 +#define kNtVkHangul 0x15 +#define kNtVkJunja 0x17 +#define kNtVkFinal 0x18 +#define kNtVkHanja 0x19 +#define kNtVkKanji 0x19 +#define kNtVkEscape 0x1B +#define kNtVkConvert 0x1C +#define kNtVkNonconvert 0x1D +#define kNtVkAccept 0x1E +#define kNtVkModechange 0x1F +#define kNtVkSpace 0x20 +#define kNtVkPrior 0x21 +#define kNtVkNext 0x22 +#define kNtVkEnd 0x23 +#define kNtVkHome 0x24 +#define kNtVkLeft 0x25 +#define kNtVkUp 0x26 +#define kNtVkRight 0x27 +#define kNtVkDown 0x28 +#define kNtVkSelect 0x29 +#define kNtVkPrint 0x2A +#define kNtVkExecute 0x2B +#define kNtVkSnapshot 0x2C +#define kNtVkInsert 0x2D +#define kNtVkDelete 0x2E +#define kNtVkHelp 0x2F +#define kNtVkLwin 0x5B +#define kNtVkRwin 0x5C +#define kNtVkApps 0x5D +#define kNtVkSleep 0x5F +#define kNtVkNumpad0 0x60 +#define kNtVkNumpad1 0x61 +#define kNtVkNumpad2 0x62 +#define kNtVkNumpad3 0x63 +#define kNtVkNumpad4 0x64 +#define kNtVkNumpad5 0x65 +#define kNtVkNumpad6 0x66 +#define kNtVkNumpad7 0x67 +#define kNtVkNumpad8 0x68 +#define kNtVkNumpad9 0x69 +#define kNtVkMultiply 0x6A +#define kNtVkAdd 0x6B +#define kNtVkSeparator 0x6C +#define kNtVkSubtract 0x6D +#define kNtVkDecimal 0x6E +#define kNtVkDivide 0x6F +#define kNtVkF1 0x70 +#define kNtVkF2 0x71 +#define kNtVkF3 0x72 +#define kNtVkF4 0x73 +#define kNtVkF5 0x74 +#define kNtVkF6 0x75 +#define kNtVkF7 0x76 +#define kNtVkF8 0x77 +#define kNtVkF9 0x78 +#define kNtVkF10 0x79 +#define kNtVkF11 0x7A +#define kNtVkF12 0x7B +#define kNtVkF13 0x7C +#define kNtVkF14 0x7D +#define kNtVkF15 0x7E +#define kNtVkF16 0x7F +#define kNtVkF17 0x80 +#define kNtVkF18 0x81 +#define kNtVkF19 0x82 +#define kNtVkF20 0x83 +#define kNtVkF21 0x84 +#define kNtVkF22 0x85 +#define kNtVkF23 0x86 +#define kNtVkF24 0x87 +#define kNtVkNumlock 0x90 +#define kNtVkScroll 0x91 +#define kNtVkLshift 0xA0 +#define kNtVkRshift 0xA1 +#define kNtVkLcontrol 0xA2 +#define kNtVkRcontrol 0xA3 +#define kNtVkLmenu 0xA4 +#define kNtVkRmenu 0xA5 +#define kNtVkBrowserBack 0xA6 +#define kNtVkBrowserForward 0xA7 +#define kNtVkBrowserRefresh 0xA8 +#define kNtVkBrowserStop 0xA9 +#define kNtVkBrowserSearch 0xAA +#define kNtVkBrowserFavorites 0xAB +#define kNtVkBrowserHome 0xAC +#define kNtVkVolumeMute 0xAD +#define kNtVkVolumeDown 0xAE +#define kNtVkVolumeUp 0xAF +#define kNtVkMediaNextTrack 0xB0 +#define kNtVkMediaPrevTrack 0xB1 +#define kNtVkMediaStop 0xB2 +#define kNtVkMediaPlayPause 0xB3 +#define kNtVkLaunchMail 0xB4 +#define kNtVkLaunchMediaSelect 0xB5 +#define kNtVkLaunchApp1 0xB6 +#define kNtVkLaunchApp2 0xB7 +#define kNtVkOem_1 0xBA +#define kNtVkOemPlus 0xBB +#define kNtVkOemComma 0xBC +#define kNtVkOemMinus 0xBD +#define kNtVkOemPeriod 0xBE +#define kNtVkOem_2 0xBF +#define kNtVkOem_3 0xC0 +#define kNtVkGamepadA 0xC3 +#define kNtVkGamepadB 0xC4 +#define kNtVkGamepadX 0xC5 +#define kNtVkGamepadY 0xC6 +#define kNtVkGamepadRightShoulder 0xC7 +#define kNtVkGamepadLeftShoulder 0xC8 +#define kNtVkGamepadLeftTrigger 0xC9 +#define kNtVkGamepadRightTrigger 0xCA +#define kNtVkGamepadDpadUp 0xCB +#define kNtVkGamepadDpadDown 0xCC +#define kNtVkGamepadDpadLeft 0xCD +#define kNtVkGamepadDpadRight 0xCE +#define kNtVkGamepadMenu 0xCF +#define kNtVkGamepadView 0xD0 +#define kNtVkGamepadLeftThumbstickButton 0xD1 +#define kNtVkGamepadRightThumbstickButton 0xD2 +#define kNtVkGamepadLeftThumbstickUp 0xD3 +#define kNtVkGamepadLeftThumbstickDown 0xD4 +#define kNtVkGamepadLeftThumbstickRight 0xD5 +#define kNtVkGamepadLeftThumbstickLeft 0xD6 +#define kNtVkGamepadRightThumbstickUp 0xD7 +#define kNtVkGamepadRightThumbstickDown 0xD8 +#define kNtVkGamepadRightThumbstickRight 0xD9 +#define kNtVkGamepadRightThumbstickLeft 0xDA +#define kNtVkOem_4 0xDB +#define kNtVkOem_5 0xDC +#define kNtVkOem_6 0xDD +#define kNtVkOem_7 0xDE +#define kNtVkOem_8 0xDF +#define kNtVkOemAx 0xE1 +#define kNtVkOem_102 0xE2 +#define kNtVkIcoHelp 0xE3 +#define kNtVkIco_00 0xE4 +#define kNtVkProcesskey 0xE5 +#define kNtVkIcoClear 0xE6 +#define kNtVkPacket 0xE7 +#define kNtVkOemReset 0xE9 +#define kNtVkOemJump 0xEA +#define kNtVkOemPa1 0xEB +#define kNtVkOemPa2 0xEC +#define kNtVkOemPa3 0xED +#define kNtVkOemWsctrl 0xEE +#define kNtVkOemCusel 0xEF +#define kNtVkOemAttn 0xF0 +#define kNtVkOemFinish 0xF1 +#define kNtVkOemCopy 0xF2 +#define kNtVkOemAuto 0xF3 +#define kNtVkOemEnlw 0xF4 +#define kNtVkOemBacktab 0xF5 +#define kNtVkAttn 0xF6 +#define kNtVkCrsel 0xF7 +#define kNtVkExsel 0xF8 +#define kNtVkEreof 0xF9 +#define kNtVkPlay 0xFA +#define kNtVkZoom 0xFB +#define kNtVkNoname 0xFC +#define kNtVkPa1 0xFD +#define kNtVkOemClear 0xFE + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_VK_H_ */ diff --git a/libc/nt/events.h b/libc/nt/events.h index 28f086a6..f6a2eee0 100644 --- a/libc/nt/events.h +++ b/libc/nt/events.h @@ -2,7 +2,6 @@ #define COSMOPOLITAN_LIBC_NT_EVENTS_H_ #include "libc/nt/struct/msg.h" #include "libc/nt/struct/point.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -27,59 +26,6 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » events ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif - -#define NT_EVENT_SYSTEM_SOUND 0x0001 -#define NT_EVENT_SYSTEM_ALERT 0x0002 -#define NT_EVENT_SYSTEM_FOREGROUND 0x0003 -#define NT_EVENT_SYSTEM_MENUSTART 0x0004 -#define NT_EVENT_SYSTEM_MENUEND 0x0005 -#define NT_EVENT_SYSTEM_MENUPOPUPSTART 0x0006 -#define NT_EVENT_SYSTEM_MENUPOPUPEND 0x0007 -#define NT_EVENT_SYSTEM_CAPTURESTART 0x0008 -#define NT_EVENT_SYSTEM_CAPTUREEND 0x0009 -#define NT_EVENT_SYSTEM_MOVESIZESTART 0x000A -#define NT_EVENT_SYSTEM_MOVESIZEEND 0x000B -#define NT_EVENT_SYSTEM_CONTEXTHELPSTART 0x000C -#define NT_EVENT_SYSTEM_CONTEXTHELPEND 0x000D -#define NT_EVENT_SYSTEM_DRAGDROPSTART 0x000E -#define NT_EVENT_SYSTEM_DRAGDROPEND 0x000F -#define NT_EVENT_SYSTEM_DIALOGSTART 0x0010 -#define NT_EVENT_SYSTEM_DIALOGEND 0x0011 -#define NT_EVENT_SYSTEM_SCROLLINGSTART 0x0012 -#define NT_EVENT_SYSTEM_SCROLLINGEND 0x0013 -#define NT_EVENT_SYSTEM_SWITCHSTART 0x0014 -#define NT_EVENT_SYSTEM_SWITCHEND 0x0015 -#define NT_EVENT_SYSTEM_MINIMIZESTART 0x0016 -#define NT_EVENT_SYSTEM_MINIMIZEEND 0x0017 - -#define NT_EVENT_CONSOLE_CARET 0x4001 -#define NT_EVENT_CONSOLE_UPDATE_REGION 0x4002 -#define NT_EVENT_CONSOLE_UPDATE_SIMPLE 0x4003 -#define NT_EVENT_CONSOLE_UPDATE_SCROLL 0x4004 -#define NT_EVENT_CONSOLE_LAYOUT 0x4005 -#define NT_EVENT_CONSOLE_START_APPLICATION 0x4006 -#define NT_EVENT_CONSOLE_END_APPLICATION 0x4007 - -#define NT_EVENT_OBJECT_CREATE 0x8000 -#define NT_EVENT_OBJECT_DESTROY 0x8001 -#define NT_EVENT_OBJECT_SHOW 0x8002 -#define NT_EVENT_OBJECT_HIDE 0x8003 -#define NT_EVENT_OBJECT_REORDER 0x8004 -#define NT_EVENT_OBJECT_FOCUS 0x8005 -#define NT_EVENT_OBJECT_SELECTION 0x8006 -#define NT_EVENT_OBJECT_SELECTIONADD 0x8007 -#define NT_EVENT_OBJECT_SELECTIONREMOVE 0x8008 -#define NT_EVENT_OBJECT_SELECTIONWITHIN 0x8009 -#define NT_EVENT_OBJECT_STATECHANGE 0x800A -#define NT_EVENT_OBJECT_LOCATIONCHANGE 0x800B -#define NT_EVENT_OBJECT_NAMECHANGE 0x800C -#define NT_EVENT_OBJECT_DESCRIPTIONCHANGE 0x800D -#define NT_EVENT_OBJECT_VALUECHANGE 0x800E -#define NT_EVENT_OBJECT_PARENTCHANGE 0x800F -#define NT_EVENT_OBJECT_HELPCHANGE 0x8010 -#define NT_EVENT_OBJECT_DEFACTIONCHANGE 0x8011 -#define NT_EVENT_OBJECT_ACCELERATORCHANGE 0x8012 #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -90,6 +36,8 @@ int32_t TranslateMessage(const struct NtMsg *lpMsg); intptr_t DispatchMessage(const struct NtMsg *lpMsg); void PostQuitMessage(int nExitCode); bool32 GetCursorPos(struct NtPoint *lpPoint); +int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam, + int64_t lParam); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/nt/files.h b/libc/nt/files.h index b096ec9a..865f0924 100644 --- a/libc/nt/files.h +++ b/libc/nt/files.h @@ -1,20 +1,15 @@ #ifndef COSMOPOLITAN_LIBC_NT_FILES_H_ #define COSMOPOLITAN_LIBC_NT_FILES_H_ -#include "libc/nt/enum/accessmask.h" -#include "libc/nt/enum/fileinfobyhandleclass.h" -#include "libc/nt/enum/filemovemethod.h" -#include "libc/nt/enum/filesharemode.h" -#include "libc/nt/enum/findexinfolevels.h" -#include "libc/nt/enum/findexsearchops.h" -#include "libc/nt/enum/getfileexinfolevels.h" -#include "libc/nt/enum/movefileexflags.h" -#include "libc/nt/enum/securityimpersonationlevel.h" -#include "libc/nt/enum/securityinformation.h" -#include "libc/nt/enum/tokentype.h" +#include "libc/nt/struct/byhandlefileinformation.h" #include "libc/nt/struct/filesegmentelement.h" #include "libc/nt/struct/filetime.h" +#include "libc/nt/struct/genericmapping.h" +#include "libc/nt/struct/objectattributes.h" +#include "libc/nt/struct/overlapped.h" +#include "libc/nt/struct/privilegeset.h" +#include "libc/nt/struct/securityattributes.h" +#include "libc/nt/struct/win32finddata.h" #include "libc/nt/thunk/msabi.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -39,61 +34,21 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » files ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif -/* CopyFileEx */ -#define NT_PROGRESS_CONTINUE 0 -#define NT_PROGRESS_CANCEL 1 -#define NT_PROGRESS_STOP 2 -#define NT_PROGRESS_QUIET 3 -#define NT_CALLBACK_CHUNK_FINISHED 0x00000000 -#define NT_CALLBACK_STREAM_SWITCH 0x00000001 -#define NT_COPY_FILE_FAIL_IF_EXISTS 0x00000001 -#define NT_COPY_FILE_RESTARTABLE 0x00000002 -#define NT_COPY_FILE_OPEN_SOURCE_FOR_WRITE 0x00000004 -#define NT_COPY_FILE_ALLOW_DECRYPTED_DESTINATION 0x00000008 -#define NT_COPY_FILE_COPY_SYMLINK 0x00000800 -#define NT_COPY_FILE_NO_BUFFERING 0x00001000 -#define NT_COPY_FILE_REQUEST_SECURITY_PRIVILEGES 0x00002000 /* Win8+ */ -#define NT_COPY_FILE_RESUME_FROM_PAUSE 0x00004000 /* Win8+ */ -#define NT_COPY_FILE_REQUEST_SECURITY_PRIVILEGES 0x00002000 /* Win8+ */ -#define NT_COPY_FILE_NO_OFFLOAD 0x00040000 /* Win8+ */ -#define NT_COPY_FILE_IGNORE_EDP_BLOCK 0x00400000 /* Win10+ */ -#define NT_COPY_FILE_IGNORE_SOURCE_ENCRYPTION 0x00800000 /* Win10+ */ +#define kNtHandleFlagInherit 1 /* SetHandleInformation */ +#define kNtHandleFlagProtectFromClose 2 -/* ReplaceFile */ -#define NT_REPLACEFILE_WRITE_THROUGH 0x00000001 -#define NT_REPLACEFILE_IGNORE_MERGE_ERRORS 0x00000002 -#define NT_REPLACEFILE_IGNORE_ACL_ERRORS 0x00000004 -#define NT_REPLACEFILE_WRITE_THROUGH 0x00000001 -#define NT_REPLACEFILE_IGNORE_MERGE_ERRORS 0x00000002 -#define NT_REPLACEFILE_IGNORE_ACL_ERRORS 0x00000004 +#define kNtFindFirstExCaseSensitive 1 +#define kNtFindFirstExLargeFetch 2 -/* SetHandleInformation */ -#define kNtHandleFlagInherit 0x00000001 -#define kNtHandleFlagProtectFromClose 0x00000002 - -#define kNtFindFirstExCaseSensitive 0x00000001 -#define kNtFindFirstExLargeFetch 0x00000002 - -#define kNtDuplicateCloseSource 0x00000001 -#define kNtDuplicateSameAccess 0x00000002 +#define kNtDuplicateCloseSource 1 +#define kNtDuplicateSameAccess 2 #define kNtSymbolicLinkFlagDirectory 1 #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtByHandleFileInformation; -struct NtFileTime; -struct NtGenericMapping; -struct NtOverlapped; -struct NtPrivilegeSet; -struct NtSecurityAttributes; -struct NtSecurityDescriptor; -struct NtWin32FindData; -struct NtWin32FindData; - intptr_t LoadResource(int64_t hModule, int64_t hResInfo); uint32_t SetHandleCount(uint32_t uNumber); uint32_t GetLogicalDrives(void); @@ -111,8 +66,7 @@ bool32 CopyFile(const char16_t *lpExistingFileName, bool32 MoveFile(const char16_t *lpExistingFileName, const char16_t *lpNewFileName) paramsnonnull(); bool32 MoveFileEx(const char16_t *lpExistingFileName, - const char16_t *lpNewFileName, enum NtMoveFileExFlags dwFlags) - paramsnonnull(); + const char16_t *lpNewFileName, int dwFlags) paramsnonnull(); bool32 SetCurrentDirectory(const char16_t *lpPathName); uint32_t GetCurrentDirectory(uint32_t nBufferLength, char16_t *out_lpBuffer); @@ -128,7 +82,7 @@ bool32 DuplicateHandle(int64_t hSourceProcessHandle, int64_t hSourceHandle, bool32 GetHandleInformation(int64_t hObject, uint32_t *out_lpdwFlags); bool32 SetHandleInformation(int64_t hObject, uint32_t dwMask, uint32_t dwFlags); -enum NtFileType GetFileType(int64_t hFile); +int GetFileType(int64_t hFile); bool32 GetFileInformationByHandleEx(int64_t hFile, uint32_t FileInformationClass, @@ -140,8 +94,7 @@ bool32 GetFileInformationByHandle( uint32_t GetFileAttributes(const char16_t *lpFileName); bool32 GetFileAttributesEx( - const char16_t *lpFileName, - enum NtGetFileexInfoLevels fInfoLevelId /* kNtGetFileExInfoStandard */, + const char16_t *lpFileName, int fInfoLevelId /* kNtGetFileExInfoStandard */, void *out_lpFileInformation /* → struct NtWin32FileAttributeData * */) paramsnonnull(); @@ -187,10 +140,9 @@ bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName, uint32_t SetFilePointer(int64_t hFile, int32_t lDistanceToMove, int32_t *optional_lpDistanceToMoveHigh, - enum NtFileMoveMethod dwMoveMethod); + int dwMoveMethod); bool32 SetFilePointerEx(int64_t hFile, int64_t liDistanceToMove, - int64_t *optional_lpNewFilePointer, - enum NtFileMoveMethod dwMoveMethod); + int64_t *optional_lpNewFilePointer, int dwMoveMethod); bool32 SetEndOfFile(int64_t hFile); bool32 SetFileValidData(int64_t hFile, int64_t ValidDataLength); @@ -202,13 +154,12 @@ bool32 GetFileSecurity(const char16_t *lpFileName, bool32 OpenProcessToken(int64_t hProcessHandle, uint32_t dwDesiredAccess, int64_t *out_hTokenHandle); -bool32 DuplicateToken(int64_t hExistingTokenHandle, - enum NtSecurityImpersonationLevel dwImpersonationLevel, +bool32 DuplicateToken(int64_t hExistingTokenHandle, int dwImpersonationLevel, int64_t *out_hDuplicateTokenHandle); bool32 DuplicateTokenEx(int64_t hExistingToken, unsigned int dwDesiredAccess, struct NtSecurityAttributes *lpTokenAttributes, - enum NtSecurityImpersonationLevel ImpersonationLevel, - enum NtTokenType TokenType, int64_t *out_phNewToken); + int ImpersonationLevel, int TokenType, + int64_t *out_phNewToken); bool32 AccessCheck(struct NtSecurityDescriptor *pSecurityDescriptor, int64_t ClientToken, unsigned int DesiredAccess, @@ -222,10 +173,8 @@ void MapGenericMask(uint32_t *AccessMask, int64_t FindFirstFile(const char16_t *lpFileName, struct NtWin32FindData *out_lpFindFileData); -int64_t FindFirstFileEx(const char16_t *lpFileName, - enum NtFindexInfoLevels fInfoLevelId, - void *out_lpFindFileData, - enum NtFindexSearchOps fSearchOp, +int64_t FindFirstFileEx(const char16_t *lpFileName, int fInfoLevelId, + void *out_lpFindFileData, int fSearchOp, void *reserved_lpSearchFilter, uint32_t dwAdditionalFlags); bool32 FindNextFile(int64_t hFindFile, diff --git a/libc/nt/gdi32/CreateCompatibleBitmap.s b/libc/nt/gdi32/CreateCompatibleBitmap.s index 20978908..9295531f 100644 --- a/libc/nt/gdi32/CreateCompatibleBitmap.s +++ b/libc/nt/gdi32/CreateCompatibleBitmap.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_CreateCompatibleBitmap,CreateCompatibleBitmap,1063 + + .text.windows +CreateCompatibleBitmap: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_CreateCompatibleBitmap(%rip),%rax + jmp __sysv2nt + .endfn CreateCompatibleBitmap,globl + .previous diff --git a/libc/nt/gdi32/CreateCompatibleDC.s b/libc/nt/gdi32/CreateCompatibleDC.s index b2d915c1..b601d483 100644 --- a/libc/nt/gdi32/CreateCompatibleDC.s +++ b/libc/nt/gdi32/CreateCompatibleDC.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_CreateCompatibleDC,CreateCompatibleDC,1064 + + .text.windows +CreateCompatibleDC: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_CreateCompatibleDC(%rip) + leave + ret + .endfn CreateCompatibleDC,globl + .previous diff --git a/libc/nt/gdi32/DeleteDC.s b/libc/nt/gdi32/DeleteDC.s index 9d245ff8..671f2f9f 100644 --- a/libc/nt/gdi32/DeleteDC.s +++ b/libc/nt/gdi32/DeleteDC.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_DeleteDC,DeleteDC,1384 + + .text.windows +DeleteDC: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_DeleteDC(%rip) + leave + ret + .endfn DeleteDC,globl + .previous diff --git a/libc/nt/gdi32/DeleteObject.s b/libc/nt/gdi32/DeleteObject.s index c1dabf3e..63f67f98 100644 --- a/libc/nt/gdi32/DeleteObject.s +++ b/libc/nt/gdi32/DeleteObject.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_DeleteObject,DeleteObject,1387 + + .text.windows +DeleteObject: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_DeleteObject(%rip) + leave + ret + .endfn DeleteObject,globl + .previous diff --git a/libc/nt/gdi32/GetPixel.s b/libc/nt/gdi32/GetPixel.s index d3f31eb2..63f2bdf2 100644 --- a/libc/nt/gdi32/GetPixel.s +++ b/libc/nt/gdi32/GetPixel.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_GetPixel,GetPixel,1691 + + .text.windows +GetPixel: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_GetPixel(%rip),%rax + jmp __sysv2nt + .endfn GetPixel,globl + .previous diff --git a/libc/nt/gdi32/RestoreDC.s b/libc/nt/gdi32/RestoreDC.s index eccf2195..9767543e 100644 --- a/libc/nt/gdi32/RestoreDC.s +++ b/libc/nt/gdi32/RestoreDC.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_RestoreDC,RestoreDC,1808 + + .text.windows +RestoreDC: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_RestoreDC(%rip),%rax + jmp __sysv2nt + .endfn RestoreDC,globl + .previous diff --git a/libc/nt/gdi32/SaveDC.s b/libc/nt/gdi32/SaveDC.s index 469efbab..afb892d8 100644 --- a/libc/nt/gdi32/SaveDC.s +++ b/libc/nt/gdi32/SaveDC.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_SaveDC,SaveDC,1815 + + .text.windows +SaveDC: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_SaveDC(%rip) + leave + ret + .endfn SaveDC,globl + .previous diff --git a/libc/nt/gdi32/SelectObject.s b/libc/nt/gdi32/SelectObject.s index a1db2074..874bcc7b 100644 --- a/libc/nt/gdi32/SelectObject.s +++ b/libc/nt/gdi32/SelectObject.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_SelectObject,SelectObject,1864 + + .text.windows +SelectObject: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_SelectObject(%rip),%rax + jmp __sysv2nt + .endfn SelectObject,globl + .previous diff --git a/libc/nt/gdi32/SetPixel.s b/libc/nt/gdi32/SetPixel.s index 42b62146..5f15af16 100644 --- a/libc/nt/gdi32/SetPixel.s +++ b/libc/nt/gdi32/SetPixel.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp gdi32,__imp_SetPixel,SetPixel,1901 + + .text.windows +SetPixel: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_SetPixel(%rip),%rax + jmp __sysv2nt + .endfn SetPixel,globl + .previous diff --git a/libc/nt/iocp.h b/libc/nt/iocp.h index b44693cd..3781bccb 100644 --- a/libc/nt/iocp.h +++ b/libc/nt/iocp.h @@ -2,7 +2,6 @@ #define COSMOPOLITAN_LIBC_NT_IOCP_H_ #include "libc/nt/struct/overlapped.h" #include "libc/nt/struct/overlappedentry.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -27,7 +26,6 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » i/o completion ports ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif #define kNtFileSkipCompletionPortOnSuccess 1 #define kNtFileSkipSetEventOnHandle 2 diff --git a/libc/nt/ipc.h b/libc/nt/ipc.h index ad015e1f..da6a7a7a 100644 --- a/libc/nt/ipc.h +++ b/libc/nt/ipc.h @@ -1,6 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_IPC_H_ #define COSMOPOLITAN_LIBC_NT_IPC_H_ -#if 0 +#include "libc/nt/struct/overlapped.h" +#include "libc/nt/struct/securityattributes.h" /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -25,7 +26,6 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » ipc ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif /* CreateNamedPipe:dwOpenMode */ #define kNtPipeAccessInbound 0x00000001 @@ -52,9 +52,6 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtOverlapped; -struct NtSecurityAttributes; - bool32 CreatePipe(int64_t *out_hReadPipe, int64_t *out_hWritePipe, const struct NtSecurityAttributes *opt_lpPipeAttributes, uint32_t nSize) paramsnonnull((1, 2)); diff --git a/libc/nt/master.sh b/libc/nt/master.sh index 55f3b0f8..7204b82f 100755 --- a/libc/nt/master.sh +++ b/libc/nt/master.sh @@ -151,8 +151,8 @@ imp 'AppXPostSuccessExtension' AppXPostSuccessExtension KernelBase 65 imp 'AppXPreCreationExtension' AppXPreCreationExtension KernelBase 66 imp 'AppXReleaseAppXContext' AppXReleaseAppXContext KernelBase 67 imp 'AppXUpdatePackageCapabilities' AppXUpdatePackageCapabilities KernelBase 68 -imp 'AppendMenuA' AppendMenuA user32 1515 -imp 'AppendMenu' AppendMenuW user32 1516 +imp 'AppendMenuA' AppendMenuA user32 1515 4 +imp 'AppendMenu' AppendMenuW user32 1516 4 imp 'ApplicationRecoveryFinished' ApplicationRecoveryFinished kernel32 34 imp 'ApplicationRecoveryInProgress' ApplicationRecoveryInProgress kernel32 35 imp 'ApplicationUserModelIdFromProductId' ApplicationUserModelIdFromProductId KernelBase 69 @@ -409,10 +409,10 @@ imp 'CheckTokenMembershipEx' CheckTokenMembershipEx KernelBase 128 imp 'CheckWindowThreadDesktop' CheckWindowThreadDesktop user32 1580 imp 'ChildWindowFromPoint' ChildWindowFromPoint user32 1581 imp 'ChildWindowFromPointEx' ChildWindowFromPointEx user32 1582 -imp 'ChooseColorA' ChooseColorA comdlg32 102 -imp 'ChooseColor' ChooseColorW comdlg32 103 -imp 'ChooseFontA' ChooseFontA comdlg32 104 -imp 'ChooseFont' ChooseFontW comdlg32 105 +imp 'ChooseColorA' ChooseColorA comdlg32 102 1 +imp 'ChooseColor' ChooseColorW comdlg32 103 1 +imp 'ChooseFontA' ChooseFontA comdlg32 104 1 +imp 'ChooseFont' ChooseFontW comdlg32 105 1 imp 'ChoosePixelFormat' ChoosePixelFormat gdi32 1040 imp 'Chord' Chord gdi32 1041 imp 'ChrCmpIA' ChrCmpIA KernelBase 129 @@ -557,8 +557,8 @@ imp 'CreateCaret' CreateCaret user32 1603 imp 'CreateCodeAuthzLevel' CreateCodeAuthzLevel advapi32 1136 imp 'CreateColorSpaceA' CreateColorSpaceA gdi32 1061 imp 'CreateColorSpace' CreateColorSpaceW gdi32 1062 -imp 'CreateCompatibleBitmap' CreateCompatibleBitmap gdi32 1063 -imp 'CreateCompatibleDC' CreateCompatibleDC gdi32 1064 +imp 'CreateCompatibleBitmap' CreateCompatibleBitmap gdi32 1063 3 +imp 'CreateCompatibleDC' CreateCompatibleDC gdi32 1064 1 imp 'CreateConsoleScreenBuffer' CreateConsoleScreenBuffer KernelBase 176 imp 'CreateCursor' CreateCursor user32 1604 imp 'CreateDCA' CreateDCA gdi32 1065 @@ -634,7 +634,7 @@ imp 'CreateMDIWindow' CreateMDIWindowW user32 1620 imp 'CreateMailslotA' CreateMailslotA kernel32 212 imp 'CreateMailslot' CreateMailslotW kernel32 213 imp 'CreateMemoryResourceNotification' CreateMemoryResourceNotification KernelBase 196 -imp 'CreateMenu' CreateMenu user32 1621 +imp 'CreateMenu' CreateMenu user32 1621 0 imp 'CreateMetaFileA' CreateMetaFileA gdi32 1087 imp 'CreateMetaFile' CreateMetaFileW gdi32 1088 imp 'CreateMutex' CreateMutexW KernelBase 200 @@ -653,7 +653,7 @@ imp 'CreatePenIndirect' CreatePenIndirect gdi32 1094 imp 'CreatePipe' CreatePipe KernelBase 202 4 imp 'CreatePolyPolygonRgn' CreatePolyPolygonRgn gdi32 1095 imp 'CreatePolygonRgn' CreatePolygonRgn gdi32 1096 -imp 'CreatePopupMenu' CreatePopupMenu user32 1622 +imp 'CreatePopupMenu' CreatePopupMenu user32 1622 0 imp 'CreatePrivateNamespaceA' CreatePrivateNamespaceA kernel32 222 imp 'CreatePrivateNamespace' CreatePrivateNamespaceW KernelBase 203 imp 'CreatePrivateObjectSecurity' CreatePrivateObjectSecurity KernelBase 204 @@ -1193,7 +1193,7 @@ imp 'DeleteAce' DeleteAce KernelBase 248 imp 'DeleteAtom' DeleteAtom kernel32 270 imp 'DeleteBoundaryDescriptor' DeleteBoundaryDescriptor KernelBase 249 imp 'DeleteColorSpace' DeleteColorSpace gdi32 1383 -imp 'DeleteDC' DeleteDC gdi32 1384 +imp 'DeleteDC' DeleteDC gdi32 1384 1 imp 'DeleteEnclave' DeleteEnclave KernelBase 251 imp 'DeleteEnhMetaFile' DeleteEnhMetaFile gdi32 1385 imp 'DeleteFiber' DeleteFiber KernelBase 252 @@ -1201,9 +1201,9 @@ imp 'DeleteFile' DeleteFileW KernelBase 254 1 imp 'DeleteFileA' DeleteFileA KernelBase 253 1 imp 'DeleteFileTransactedA' DeleteFileTransactedA kernel32 275 imp 'DeleteFileTransacted' DeleteFileTransactedW kernel32 276 -imp 'DeleteMenu' DeleteMenu user32 1681 +imp 'DeleteMenu' DeleteMenu user32 1681 3 imp 'DeleteMetaFile' DeleteMetaFile gdi32 1386 -imp 'DeleteObject' DeleteObject gdi32 1387 +imp 'DeleteObject' DeleteObject gdi32 1387 1 imp 'DeleteProcThreadAttributeList' DeleteProcThreadAttributeList KernelBase 255 1 imp 'DeleteService' DeleteService advapi32 1238 imp 'DeleteStateAtomValue' DeleteStateAtomValue KernelBase 256 @@ -1227,7 +1227,7 @@ imp 'DestroyCaret' DestroyCaret user32 1684 imp 'DestroyCursor' DestroyCursor user32 1685 imp 'DestroyDCompositionHwndTarget' DestroyDCompositionHwndTarget user32 1686 imp 'DestroyIcon' DestroyIcon user32 1687 -imp 'DestroyMenu' DestroyMenu user32 1688 +imp 'DestroyMenu' DestroyMenu user32 1688 1 imp 'DestroyOPMProtectedOutput' DestroyOPMProtectedOutput gdi32 1389 imp 'DestroyPalmRejectionDelayZone' DestroyPalmRejectionDelayZone user32 1504 imp 'DestroyPhysicalMonitorInternal' DestroyPhysicalMonitorInternal gdi32 1390 @@ -2055,7 +2055,7 @@ imp 'GetCurrentThread' GetCurrentThread KernelBase 505 0 imp 'GetCurrentThreadId' GetCurrentThreadId KernelBase 506 0 imp 'GetCurrentThreadStackLimits' GetCurrentThreadStackLimits KernelBase 507 imp 'GetCurrentUmsThread' GetCurrentUmsThread kernel32 547 -imp 'GetCursor' GetCursor user32 1826 +imp 'GetCursor' GetCursor user32 1826 0 imp 'GetCursorFrameInfo' GetCursorFrameInfo user32 1827 imp 'GetCursorInfo' GetCursorInfo user32 1828 imp 'GetCursorPos' GetCursorPos user32 1829 1 @@ -2165,8 +2165,8 @@ imp 'GetFileSecurityA' GetFileSecurityA advapi32 1326 5 imp 'GetFileSize' GetFileSize KernelBase 552 m imp 'GetFileSizeEx' GetFileSizeEx KernelBase 553 m imp 'GetFileTime' GetFileTime KernelBase 554 4 -imp 'GetFileTitleA' GetFileTitleA comdlg32 111 -imp 'GetFileTitle' GetFileTitleW comdlg32 112 +imp 'GetFileTitleA' GetFileTitleA comdlg32 111 3 +imp 'GetFileTitle' GetFileTitleW comdlg32 112 3 imp 'GetFileType' GetFileType KernelBase 555 1 imp 'GetFileVersionInfoA' GetFileVersionInfoA KernelBase 556 imp 'GetFileVersionInfoByHandle' GetFileVersionInfoByHandle KernelBase 557 @@ -2240,7 +2240,7 @@ imp 'GetKerningPairsA' GetKerningPairsA gdi32 1666 imp 'GetKerningPairs' GetKerningPairsW gdi32 1667 imp 'GetKeyNameTextA' GetKeyNameTextA user32 1864 imp 'GetKeyNameText' GetKeyNameTextW user32 1865 -imp 'GetKeyState' GetKeyState user32 1866 +imp 'GetKeyState' GetKeyState user32 1866 1 imp 'GetKeyboardLayout' GetKeyboardLayout user32 1867 imp 'GetKeyboardLayoutList' GetKeyboardLayoutList user32 1868 imp 'GetKeyboardLayoutNameA' GetKeyboardLayoutNameA user32 1869 @@ -2287,7 +2287,7 @@ imp 'GetMappedFileName' GetMappedFileNameW KernelBase 595 imp 'GetMaximumProcessorCount' GetMaximumProcessorCount kernel32 627 imp 'GetMaximumProcessorGroupCount' GetMaximumProcessorGroupCount kernel32 628 imp 'GetMemoryErrorHandlingCapabilities' GetMemoryErrorHandlingCapabilities KernelBase 596 -imp 'GetMenu' GetMenu user32 1881 +imp 'GetMenu' GetMenu user32 1881 1 imp 'GetMenuBarInfo' GetMenuBarInfo user32 1882 imp 'GetMenuCheckMarkDimensions' GetMenuCheckMarkDimensions user32 1883 imp 'GetMenuContextHelpId' GetMenuContextHelpId user32 1884 @@ -2381,8 +2381,8 @@ imp 'GetObjectType' GetObjectType gdi32 1683 imp 'GetObject' GetObjectW gdi32 1684 imp 'GetOldestEventLogRecord' GetOldestEventLogRecord advapi32 1347 imp 'GetOpenClipboardWindow' GetOpenClipboardWindow user32 1905 -imp 'GetOpenFileNameA' GetOpenFileNameA comdlg32 113 -imp 'GetOpenFileName' GetOpenFileNameW comdlg32 114 +imp 'GetOpenFileNameA' GetOpenFileNameA comdlg32 113 1 +imp 'GetOpenFileName' GetOpenFileNameW comdlg32 114 1 imp 'GetOsManufacturingMode' GetOsManufacturingMode KernelBase 625 imp 'GetOsSafeBootMode' GetOsSafeBootMode KernelBase 626 imp 'GetOutlineTextMetricsA' GetOutlineTextMetricsA gdi32 1685 @@ -2431,7 +2431,7 @@ imp 'GetPhysicalCursorPos' GetPhysicalCursorPos user32 1907 imp 'GetPhysicalMonitorDescription' GetPhysicalMonitorDescription gdi32 1689 imp 'GetPhysicalMonitors' GetPhysicalMonitors gdi32 1690 imp 'GetPhysicallyInstalledSystemMemory' GetPhysicallyInstalledSystemMemory KernelBase 663 -imp 'GetPixel' GetPixel gdi32 1691 +imp 'GetPixel' GetPixel gdi32 1691 3 imp 'GetPixelFormat' GetPixelFormat gdi32 1692 imp 'GetPointerCursorId' GetPointerCursorId user32 1908 imp 'GetPointerDevice' GetPointerDevice user32 1909 @@ -2535,8 +2535,8 @@ imp 'GetRegistryValueWithFallback' GetRegistryValueWithFallbackW KernelBas imp 'GetRelAbs' GetRelAbs gdi32 1699 imp 'GetRgnBox' GetRgnBox gdi32 1700 imp 'GetRoamingLastObservedChangeTime' GetRoamingLastObservedChangeTime KernelBase 699 -imp 'GetSaveFileNameA' GetSaveFileNameA comdlg32 115 -imp 'GetSaveFileName' GetSaveFileNameW comdlg32 116 +imp 'GetSaveFileNameA' GetSaveFileNameA comdlg32 115 1 +imp 'GetSaveFileName' GetSaveFileNameW comdlg32 116 1 imp 'GetScrollBarInfo' GetScrollBarInfo user32 1945 imp 'GetScrollInfo' GetScrollInfo user32 1946 imp 'GetScrollPos' GetScrollPos user32 1947 @@ -2606,7 +2606,7 @@ imp 'GetSystemDpiForProcess' GetSystemDpiForProcess user32 1954 imp 'GetSystemFileCacheSize' GetSystemFileCacheSize KernelBase 739 imp 'GetSystemFirmwareTable' GetSystemFirmwareTable KernelBase 740 imp 'GetSystemInfo' GetSystemInfo KernelBase 741 1 -imp 'GetSystemMenu' GetSystemMenu user32 1955 +imp 'GetSystemMenu' GetSystemMenu user32 1955 2 imp 'GetSystemMetadataPath' GetSystemMetadataPath KernelBase 742 imp 'GetSystemMetadataPathForPackage' GetSystemMetadataPathForPackage KernelBase 743 imp 'GetSystemMetadataPathForPackageFamily' GetSystemMetadataPathForPackageFamily KernelBase 744 @@ -2764,7 +2764,7 @@ imp 'GetWindowMinimizeRect' GetWindowMinimizeRect user32 1991 imp 'GetWindowModuleFileNameA' GetWindowModuleFileNameA user32 1993 imp 'GetWindowModuleFileName' GetWindowModuleFileNameW user32 1994 imp 'GetWindowOrgEx' GetWindowOrgEx gdi32 1732 -imp 'GetWindowPlacement' GetWindowPlacement user32 1995 +imp 'GetWindowPlacement' GetWindowPlacement user32 1995 2 imp 'GetWindowProcessHandle' GetWindowProcessHandle user32 1996 imp 'GetWindowRect' GetWindowRect user32 1997 2 imp 'GetWindowRgn' GetWindowRgn user32 1998 @@ -2913,10 +2913,10 @@ imp 'InjectKeyboardInput' InjectKeyboardInput user32 2037 imp 'InjectMouseInput' InjectMouseInput user32 2038 imp 'InjectPointerInput' InjectPointerInput user32 2039 imp 'InjectTouchInput' InjectTouchInput user32 2040 -imp 'InsertMenuA' InsertMenuA user32 2041 +imp 'InsertMenuA' InsertMenuA user32 2041 5 imp 'InsertMenuItemA' InsertMenuItemA user32 2042 imp 'InsertMenuItem' InsertMenuItemW user32 2043 -imp 'InsertMenu' InsertMenuW user32 2044 +imp 'InsertMenu' InsertMenuW user32 2044 5 imp 'InstallApplication' InstallApplication advapi32 1408 imp 'InstallELAMCertificateInfo' InstallELAMCertificateInfo KernelBase 866 imp 'InternalDeleteDC' InternalDeleteDC gdi32 1736 @@ -2985,7 +2985,7 @@ imp 'IsEnclaveTypeSupported' IsEnclaveTypeSupported KernelBase 906 imp 'IsGUIThread' IsGUIThread user32 2065 imp 'IsGlobalizationUserSettingsKeyRedirected' IsGlobalizationUserSettingsKeyRedirected KernelBase 907 imp 'IsHungAppWindow' IsHungAppWindow user32 2066 -imp 'IsIconic' IsIconic user32 2067 +imp 'IsIconic' IsIconic user32 2067 1 imp 'IsImmersiveProcess' IsImmersiveProcess user32 2068 imp 'IsInDesktopWindowBand' IsInDesktopWindowBand user32 2069 imp 'IsInternetESCEnabled' IsInternetESCEnabled KernelBase 908 @@ -4332,10 +4332,10 @@ imp 'PowerSetRequest' PowerSetRequest kernel32 1059 imp 'PrefetchVirtualMemory' PrefetchVirtualMemory KernelBase 1222 4 imp 'PrepareDiscForBurnRunDll' PrepareDiscForBurnRunDllW shell32 135 imp 'PrepareTape' PrepareTape kernel32 1061 -imp 'PrintDlgA' PrintDlgA comdlg32 120 +imp 'PrintDlgA' PrintDlgA comdlg32 120 1 imp 'PrintDlgExA' PrintDlgExA comdlg32 121 imp 'PrintDlgEx' PrintDlgExW comdlg32 122 -imp 'PrintDlg' PrintDlgW comdlg32 123 +imp 'PrintDlg' PrintDlgW comdlg32 123 1 imp 'PrintWindow' PrintWindow user32 2209 imp 'PrintersGetCommand_RunDLL' PrintersGetCommand_RunDLL shell32 138 imp 'PrintersGetCommand_RunDLLA' PrintersGetCommand_RunDLLA shell32 139 @@ -4541,7 +4541,7 @@ imp 'RecordShutdownReason' RecordShutdownReason user32 2245 imp 'RectInRegion' RectInRegion gdi32 1796 imp 'RectVisible' RectVisible gdi32 1797 imp 'Rectangle' Rectangle gdi32 1798 -imp 'RedrawWindow' RedrawWindow user32 2246 +imp 'RedrawWindow' RedrawWindow user32 2246 4 imp 'RefreshPackageInfo' RefreshPackageInfo KernelBase 1318 imp 'RefreshPolicyExInternal' RefreshPolicyExInternal KernelBase 1319 imp 'RefreshPolicyInternal' RefreshPolicyInternal KernelBase 1320 @@ -4699,7 +4699,7 @@ imp 'RegisterWowBaseHandlers' RegisterWowBaseHandlers kernel32 1194 imp 'RegisterWowExec' RegisterWowExec kernel32 1195 imp 'ReleaseActCtx' ReleaseActCtx KernelBase 1390 imp 'ReleaseActCtxWorker' ReleaseActCtxWorker kernel32 1197 -imp 'ReleaseCapture' ReleaseCapture user32 2279 +imp 'ReleaseCapture' ReleaseCapture user32 2279 0 imp 'ReleaseDC' ReleaseDC user32 2280 imp 'ReleaseDwmHitTestWaiters' ReleaseDwmHitTestWaiters user32 2281 imp 'ReleaseMutex' ReleaseMutex KernelBase 1391 1 @@ -4741,8 +4741,8 @@ imp 'ReplaceFileA' ReplaceFileA kernel32 1215 imp 'ReplaceFileExInternal' ReplaceFileExInternal KernelBase 1408 imp 'ReplaceFile' ReplaceFileW KernelBase 1409 imp 'ReplacePartitionUnit' ReplacePartitionUnit kernel32 1217 -imp 'ReplaceTextA' ReplaceTextA comdlg32 124 -imp 'ReplaceText' ReplaceTextW comdlg32 125 +imp 'ReplaceTextA' ReplaceTextA comdlg32 124 1 +imp 'ReplaceText' ReplaceTextW comdlg32 125 1 imp 'ReplyMessage' ReplyMessage user32 2288 imp 'ReportEventA' ReportEventA advapi32 1704 imp 'ReportEvent' ReportEventW advapi32 1705 @@ -4761,7 +4761,7 @@ imp 'ResolveDesktopForWOW' ResolveDesktopForWOW user32 2289 imp 'ResolveLocaleName' ResolveLocaleName KernelBase 1415 imp 'RestartDialog' RestartDialog shell32 59 imp 'RestartDialogEx' RestartDialogEx shell32 730 -imp 'RestoreDC' RestoreDC gdi32 1808 +imp 'RestoreDC' RestoreDC gdi32 1808 2 imp 'ResumeThread' ResumeThread KernelBase 1417 imp 'ReuseDDElParam' ReuseDDElParam user32 2290 imp 'RevertToSelf' RevertToSelf KernelBase 1418 @@ -6061,7 +6061,7 @@ imp 'SaferiPopulateDefaultsInRegistry' SaferiPopulateDefaultsInRegistry adva imp 'SaferiRecordEventLogEntry' SaferiRecordEventLogEntry advapi32 1722 imp 'SaferiSearchMatchingHashRules' SaferiSearchMatchingHashRules advapi32 1723 imp 'SaveAlternatePackageRootPath' SaveAlternatePackageRootPath KernelBase 1451 -imp 'SaveDC' SaveDC gdi32 1815 +imp 'SaveDC' SaveDC gdi32 1815 1 imp 'SaveStateRootFolderPath' SaveStateRootFolderPath KernelBase 1452 imp 'SbExecuteProcedure' SbExecuteProcedure ntdll 1610 imp 'SbSelectProcedure' SbSelectProcedure ntdll 1611 @@ -6082,7 +6082,7 @@ imp 'SelectBrushLocal' SelectBrushLocal gdi32 1860 imp 'SelectClipPath' SelectClipPath gdi32 1861 imp 'SelectClipRgn' SelectClipRgn gdi32 1862 imp 'SelectFontLocal' SelectFontLocal gdi32 1863 -imp 'SelectObject' SelectObject gdi32 1864 +imp 'SelectObject' SelectObject gdi32 1864 2 imp 'SelectPalette' SelectPalette gdi32 1865 imp 'SendDlgItemMessageA' SendDlgItemMessageA user32 2296 imp 'SendDlgItemMessage' SendDlgItemMessageW user32 2297 @@ -6094,7 +6094,7 @@ imp 'SendMessageCallbackA' SendMessageCallbackA user32 2302 imp 'SendMessageCallback' SendMessageCallbackW user32 2303 imp 'SendMessageTimeoutA' SendMessageTimeoutA user32 2304 imp 'SendMessageTimeout' SendMessageTimeoutW user32 2305 -imp 'SendMessage' SendMessageW user32 2306 +imp 'SendMessage' SendMessageW user32 2306 4 imp 'SendNotifyMessageA' SendNotifyMessageA user32 2307 imp 'SendNotifyMessage' SendNotifyMessageW user32 2308 imp 'SetAbortProc' SetAbortProc gdi32 1866 @@ -6114,13 +6114,13 @@ imp 'SetBrushOrgEx' SetBrushOrgEx gdi32 1875 imp 'SetCachedSigningLevel' SetCachedSigningLevel KernelBase 1458 imp 'SetCalendarInfoA' SetCalendarInfoA kernel32 1249 imp 'SetCalendarInfo' SetCalendarInfoW KernelBase 1459 -imp 'SetCapture' SetCapture user32 2310 +imp 'SetCapture' SetCapture user32 2310 1 imp 'SetCaretBlinkTime' SetCaretBlinkTime user32 2311 imp 'SetCaretPos' SetCaretPos user32 2312 -imp 'SetClassLongA' SetClassLongA user32 2313 +imp 'SetClassLongA' SetClassLongA user32 2313 3 imp 'SetClassLongPtrA' SetClassLongPtrA user32 2314 imp 'SetClassLongPtr' SetClassLongPtrW user32 2315 -imp 'SetClassLong' SetClassLongW user32 2316 +imp 'SetClassLong' SetClassLongW user32 2316 3 imp 'SetClassWord' SetClassWord user32 2317 imp 'SetClientDynamicTimeZoneInformation' SetClientDynamicTimeZoneInformation KernelBase 1460 imp 'SetClientTimeZoneInformation' SetClientTimeZoneInformation KernelBase 1461 @@ -6176,7 +6176,7 @@ imp 'SetCurrentConsoleFontEx' SetCurrentConsoleFontEx KernelBase 1492 imp 'SetCurrentDirectory' SetCurrentDirectoryW KernelBase 1494 1 imp 'SetCurrentDirectoryA' SetCurrentDirectoryA KernelBase 1493 1 imp 'SetCurrentProcessExplicitAppUserModelID' SetCurrentProcessExplicitAppUserModelID shell32 569 -imp 'SetCursor' SetCursor user32 2321 +imp 'SetCursor' SetCursor user32 2321 1 imp 'SetCursorContents' SetCursorContents user32 2322 imp 'SetCursorPos' SetCursorPos user32 2323 imp 'SetDCBrushColor' SetDCBrushColor gdi32 1878 @@ -6304,7 +6304,7 @@ imp 'SetOPMSigningKeyAndSequenceNumbers' SetOPMSigningKeyAndSequenceNumbers imp 'SetPaletteEntries' SetPaletteEntries gdi32 1900 imp 'SetParent' SetParent user32 2357 2 imp 'SetPhysicalCursorPos' SetPhysicalCursorPos user32 2358 -imp 'SetPixel' SetPixel gdi32 1901 +imp 'SetPixel' SetPixel gdi32 1901 4 imp 'SetPixelFormat' SetPixelFormat gdi32 1902 imp 'SetPixelV' SetPixelV gdi32 1903 imp 'SetPolyFillMode' SetPolyFillMode gdi32 1904 @@ -6443,7 +6443,7 @@ imp 'SetWindowLongPtrA' SetWindowLongPtrA user32 2396 imp 'SetWindowLongPtr' SetWindowLongPtrW user32 2397 imp 'SetWindowLong' SetWindowLongW user32 2398 imp 'SetWindowOrgEx' SetWindowOrgEx gdi32 1919 -imp 'SetWindowPlacement' SetWindowPlacement user32 2399 +imp 'SetWindowPlacement' SetWindowPlacement user32 2399 2 imp 'SetWindowPos' SetWindowPos user32 2400 7 imp 'SetWindowRgn' SetWindowRgn user32 2401 imp 'SetWindowRgnEx' SetWindowRgnEx user32 2402 @@ -6723,7 +6723,7 @@ imp 'TpWaitForWait' TpWaitForWait ntdll 1676 imp 'TpWaitForWork' TpWaitForWork ntdll 1677 imp 'TraceSetInformation' TraceSetInformation advapi32 1812 imp 'TrackMouseEvent' TrackMouseEvent user32 2442 -imp 'TrackPopupMenu' TrackPopupMenu user32 2443 +imp 'TrackPopupMenu' TrackPopupMenu user32 2443 7 imp 'TrackPopupMenuEx' TrackPopupMenuEx user32 2444 imp 'TransactNamedPipe' TransactNamedPipe KernelBase 1684 7 imp 'TranslateAcceleratorA' TranslateAcceleratorA user32 2446 diff --git a/libc/nt/memory.h b/libc/nt/memory.h index ba7c1689..b8dfe3e9 100644 --- a/libc/nt/memory.h +++ b/libc/nt/memory.h @@ -1,11 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_MEMORY_H_ #define COSMOPOLITAN_LIBC_NT_MEMORY_H_ -#include "libc/nt/enum/filemapflags.h" -#include "libc/nt/enum/memflags.h" -#include "libc/nt/enum/offerpriority.h" -#include "libc/nt/enum/pageflags.h" +#include "libc/nt/struct/memorybasicinformation.h" +#include "libc/nt/struct/memoryrangeentry.h" +#include "libc/nt/struct/securityattributes.h" #include "libc/nt/thunk/msabi.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -30,17 +28,12 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » memory ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif #define kNtNumaNoPreferredNode 0xffffffff #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtMemoryBasicInformation; -struct NtMemoryRangeEntry; -struct NtSecurityAttributes; - int64_t CreateFileMappingNuma( int64_t opt_hFile /* -1ul is MAP_ANONYMOUS */, const struct NtSecurityAttributes *opt_lpFileMappingAttributes, @@ -73,7 +66,7 @@ bool32 PrefetchVirtualMemory(int64_t hProcess, const uint32_t *NumberOfEntries, struct NtMemoryRangeEntry *VirtualAddresses, uint32_t reserved_Flags); bool32 OfferVirtualMemory(void *inout_VirtualAddress, size_t Size, - enum NtOfferPriority Priority); + int Priority); #if ShouldUseMsabiAttribute() #include "libc/nt/thunk/memory.inc" diff --git a/libc/nt/messagebox.h b/libc/nt/messagebox.h index bd84f788..309a5c13 100644 --- a/libc/nt/messagebox.h +++ b/libc/nt/messagebox.h @@ -1,16 +1,14 @@ #ifndef COSMOPOLITAN_LIBC_NT_MESSAGEBOX_H_ #define COSMOPOLITAN_LIBC_NT_MESSAGEBOX_H_ #include "libc/nt/enum/dialogresult.h" -#include "libc/nt/enum/messageboxtype.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -enum DialogResult MessageBox(int64_t hWnd, const char16_t *lpText, - const char16_t *lpCaption, - enum MessageBoxType uType); -enum DialogResult MessageBoxEx(int64_t hWnd, const char16_t *lpText, - const char16_t *lpCaption, - enum MessageBoxType uType, uint16_t wLanguageId); +int MessageBox(int64_t hWnd, const char16_t *lpText, const char16_t *lpCaption, + uint32_t mbType); +int MessageBoxEx(int64_t hWnd, const char16_t *lpText, + const char16_t *lpCaption, uint32_t mbType, + uint16_t wLanguageId); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/nt/nt/debug.h b/libc/nt/nt/debug.h index 2145af1a..35a880c0 100644 --- a/libc/nt/nt/debug.h +++ b/libc/nt/nt/debug.h @@ -3,7 +3,6 @@ #include "libc/nt/enum/status.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -32,7 +31,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif struct NtContext; diff --git a/libc/nt/nt/file.h b/libc/nt/nt/file.h index 313ac511..3b171510 100644 --- a/libc/nt/nt/file.h +++ b/libc/nt/nt/file.h @@ -6,7 +6,6 @@ #include "libc/nt/typedef/ioapcroutine.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -35,7 +34,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif struct NtIoStatusBlock; struct NtObjectAttributes; diff --git a/libc/nt/nt/ipc.h b/libc/nt/nt/ipc.h index f60657b8..3cf8357d 100644 --- a/libc/nt/nt/ipc.h +++ b/libc/nt/nt/ipc.h @@ -3,7 +3,6 @@ #include "libc/nt/enum/status.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -32,7 +31,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif struct NtIoStatusBlock; struct NtObjectAttributes; diff --git a/libc/nt/nt/loader.h b/libc/nt/nt/loader.h index 523d160f..7d77a1e2 100644 --- a/libc/nt/nt/loader.h +++ b/libc/nt/nt/loader.h @@ -4,7 +4,6 @@ #include "libc/nt/typedef/wambda.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -33,7 +32,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif struct NtAnsiString; struct NtLdrDataTableEntry; diff --git a/libc/nt/nt/memory.h b/libc/nt/nt/memory.h index 3934d7a9..afa9ac3f 100644 --- a/libc/nt/nt/memory.h +++ b/libc/nt/nt/memory.h @@ -4,7 +4,6 @@ #include "libc/nt/enum/status.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -33,7 +32,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif NtStatus NtAllocateVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress, uint32_t dwZeroBits, @@ -42,11 +40,11 @@ NtStatus NtAllocateVirtualMemory(int64_t ProcessHandle, uint32_t dwPageProtect); NtStatus NtFreeVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress, size_t *inout_FreeSize, uint32_t FreeType); -NtStatus NtQueryVirtualMemory( - int64_t ProcessHandle, const void *BaseAddress, - enum NtMemoryInformationClass MemoryInformationClass, - void *out_MemoryInformation, size_t MemoryInformationLength, - size_t *opt_out_ReturnLength); +NtStatus NtQueryVirtualMemory(int64_t ProcessHandle, const void *BaseAddress, + int MemoryInformationClass, + void *out_MemoryInformation, + size_t MemoryInformationLength, + size_t *opt_out_ReturnLength); NtStatus NtProtectVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress, uint32_t *inout_ProtectSize, uint32_t NewProtect, uint32_t *out_OldProtect); diff --git a/libc/nt/nt/process.h b/libc/nt/nt/process.h index a4457f41..09878a76 100644 --- a/libc/nt/nt/process.h +++ b/libc/nt/nt/process.h @@ -4,7 +4,6 @@ #include "libc/nt/thunk/msabi.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -33,7 +32,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif struct NtClientId; struct NtObjectAttributes; diff --git a/libc/nt/nt/sections.h b/libc/nt/nt/sections.h index 697658f7..ef09cef7 100644 --- a/libc/nt/nt/sections.h +++ b/libc/nt/nt/sections.h @@ -1,13 +1,10 @@ #ifndef COSMOPOLITAN_LIBC_NT_NT_SECTIONS_H_ #define COSMOPOLITAN_LIBC_NT_NT_SECTIONS_H_ -#include "libc/nt/enum/sectioninformationclass.h" -#include "libc/nt/enum/sectioninherit.h" #include "libc/nt/enum/status.h" +#include "libc/nt/struct/objectattributes.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtObjectAttributes; - NtStatus NtCreateSection(int64_t *out_SectionHandle, uint32_t DesiredAccess, struct NtObjectAttributes *ObjectAttributes, int64_t *opt_SectionSize, uint32_t Protect, @@ -17,12 +14,10 @@ NtStatus NtOpenSection(int64_t *out_SectionHandle, uint32_t DesiredAccess, NtStatus NtMapViewOfSection(int64_t SectionHandle, int64_t ProcessHandle, void **inout_BaseAddress, uint32_t *ZeroBits, size_t CommitSize, int64_t *opt_inout_SectionOffset, - size_t *inout_ViewSize, - enum NtSectionInherit InheritDisposition, + size_t *inout_ViewSize, int InheritDisposition, uint32_t AllocationType, uint32_t Protect); NtStatus NtUnmapViewOfSection(int64_t ProcessHandle, void *BaseAddress); -NtStatus NtQuerySection(int64_t SectionHandle, - enum NtSectionInformationClass SectionInformationClass, +NtStatus NtQuerySection(int64_t SectionHandle, int SectionInformationClass, void *out_SectionInformation, uint32_t SectionInformationLength, uint32_t *opt_out_ResultLength); diff --git a/libc/nt/nt/signing.h b/libc/nt/nt/signing.h index dccb6a15..59e6f22f 100644 --- a/libc/nt/nt/signing.h +++ b/libc/nt/nt/signing.h @@ -3,7 +3,6 @@ #include "libc/nt/enum/status.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -32,7 +31,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif NtStatus CsrClientCallServer(void *inout_Message, void *unknown, uint32_t Opcode, uint32_t Size); diff --git a/libc/nt/nt/thread.h b/libc/nt/nt/thread.h index d4ecb09e..a309003b 100644 --- a/libc/nt/nt/thread.h +++ b/libc/nt/nt/thread.h @@ -4,7 +4,6 @@ #include "libc/nt/enum/threadinfoclass.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -33,7 +32,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif struct NtClientId; struct NtContext; diff --git a/libc/nt/nt/time.h b/libc/nt/nt/time.h index 6274d5c3..4694c5ed 100644 --- a/libc/nt/nt/time.h +++ b/libc/nt/nt/time.h @@ -4,7 +4,6 @@ #include "libc/nt/thunk/msabi.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -33,7 +32,6 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif NtStatus NtDelayExecution(bool32 alertable, int64_t *AbsCobolOrNegRelHectoNano); diff --git a/libc/nt/ntdll.h b/libc/nt/ntdll.h index 6a3bc6c2..c550c0a7 100644 --- a/libc/nt/ntdll.h +++ b/libc/nt/ntdll.h @@ -1,21 +1,17 @@ #ifndef COSMOPOLITAN_LIBC_NT_NTDLL_H_ #define COSMOPOLITAN_LIBC_NT_NTDLL_H_ -#include "libc/nt/enum/eventtype.h" -#include "libc/nt/enum/fileinformationclass.h" -#include "libc/nt/enum/fsinformationclass.h" -#include "libc/nt/enum/jobobjectinfoclass.h" -#include "libc/nt/enum/keyinformationclass.h" -#include "libc/nt/enum/objectinformationclass.h" -#include "libc/nt/enum/status.h" -#include "libc/nt/enum/systeminformationclass.h" -#include "libc/nt/enum/tokeninformationclass.h" -#include "libc/nt/enum/valueinformationclass.h" +#include "libc/nt/struct/context.h" +#include "libc/nt/struct/criticalsection.h" +#include "libc/nt/struct/filebasicinformation.h" +#include "libc/nt/struct/filenetworkopeninformation.h" +#include "libc/nt/struct/iostatusblock.h" +#include "libc/nt/struct/ntexceptionrecord.h" +#include "libc/nt/struct/objectattributes.h" #include "libc/nt/thunk/msabi.h" #include "libc/nt/typedef/ioapcroutine.h" #include "libc/nt/typedef/pknormalroutine.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -44,27 +40,14 @@ COSMOPOLITAN_C_START_ the operating system and subject to change from one release of Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#endif #define g_nt_system_call_dispatcher (wambda *)0x7ffe0308 extern const struct NtUnicodeString *const RtlNtdllName; -#if 0 /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § new technology » beyond the pale » eponymous runtime ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif - -struct NtContext; -struct NtCriticalSection; -struct NtExceptionRecord; -struct NtFileBasicInformation; -struct NtFileNetworkOpenInformation; -struct NtIoStatusBlock; -struct NtObjectAttributes; -struct NtSecurityDescriptor; -struct NtUnicodeString; #define NT_PROCESS_FLAGS_CREATE_SUSPENDED 0x00000001 #define NT_PROCESS_FLAGS_INHERIT_HANDLES 0x00000002 @@ -99,8 +82,7 @@ NtStatus NtCreateTimer(void **out_TimerHandle, uint32_t DesiredAccess, NtStatus NtSetTimer(void *TimerHandle, int64_t *DueTime, void *TimerApcRoutine, void *TimerContext, int32_t Resume, int32_t Period, int32_t *out_PreviousState); -NtStatus NtQueryObject(void *ObjectHandle, - enum NtObjectInformationClass ObjectInformationClass, +NtStatus NtQueryObject(void *ObjectHandle, int ObjectInformationClass, void *out_ObjectInformation, uint32_t ObjectInformationLength, uint32_t *opt_out_ReturnLength); @@ -117,17 +99,15 @@ NtStatus NtSetValueKey(void *KeyHandle, struct NtUnicodeString *ValueName, uint32_t opt_TitleIndex, uint32_t Type, void *Data, uint32_t DataSize); NtStatus NtDeleteKey(void *KeyHandle); -NtStatus NtQueryValueKey( - void *KeyHandle, struct NtUnicodeString *ValueName, - enum NtKeyValueInformationClass KeyValueInformationClass, - void *out_KeyValueInformation, uint32_t Length, uint32_t *out_ResultLength); +NtStatus NtQueryValueKey(void *KeyHandle, struct NtUnicodeString *ValueName, + int KeyValueInformationClass, + void *out_KeyValueInformation, uint32_t Length, + uint32_t *out_ResultLength); NtStatus NtFlushKey(void *KeyHandle); -NtStatus NtEnumerateKey(int64_t hkey, uint32_t index, - enum NtKeyInformationClass info_class, +NtStatus NtEnumerateKey(int64_t hkey, uint32_t index, int info_class, void *out_key_info, uint32_t key_info_size, uint32_t *out_bytes_received); -NtStatus NtEnumerateValueKey(int64_t hKey, uint32_t index, - enum NtKeyValueInformationClass info_class, +NtStatus NtEnumerateValueKey(int64_t hKey, uint32_t index, int info_class, void *out_key_info, uint32_t key_info_size, uint32_t *out_bytes_received); NtStatus NtQuerySystemTime(int64_t *SystemTime); @@ -146,7 +126,7 @@ NtStatus NtRaiseException(struct NtExceptionRecord *ExceptionRecord, struct NtContext *Context, int32_t SearchFrames); NtStatus NtCreateEvent(void **out_EventHandle, uint32_t DesiredAccess, struct NtObjectAttributes *ObjectAttributes, - enum NtEventType EventType, int32_t InitialState); + int EventType, int32_t InitialState); NtStatus NtWaitForSingleObject(void *ObjectHandle, int32_t Alertable, int64_t *TimeOut); NtStatus NtSetEvent(void *EventHandle, int32_t *opt_out_PreviousState); @@ -214,16 +194,14 @@ NtStatus NtQueryDirectoryFile( NtStatus NtFlushVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress, uint32_t **inout_FlushSize, struct NtIoStatusBlock *out_IoStatusBlock); -NtStatus NtQueryInformationJobObject( - void *JobHandle, enum NtJobObjectInfoClass JobInformationClass, - void *out_JobInformation, uint32_t JobInformationLength, - uint32_t *opt_out_ReturnLength); +NtStatus NtQueryInformationJobObject(void *JobHandle, int JobInformationClass, + void *out_JobInformation, + uint32_t JobInformationLength, + uint32_t *opt_out_ReturnLength); -#if 0 /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § new technology » beyond the pale » runtime library ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif NtStatus RtlInitializeCriticalSection(struct NtCriticalSection *out_crit); NtStatus RtlDeleteCriticalSection(struct NtCriticalSection *crit); diff --git a/libc/nt/ntdllimport.h b/libc/nt/ntdllimport.h index 31a88c18..d4248788 100644 --- a/libc/nt/ntdllimport.h +++ b/libc/nt/ntdllimport.h @@ -1,22 +1,3 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_ #define COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_ #include "ape/relocations.h" diff --git a/libc/nt/paint.h b/libc/nt/paint.h index 725e80c5..3d727ec6 100644 --- a/libc/nt/paint.h +++ b/libc/nt/paint.h @@ -3,13 +3,12 @@ #include "libc/nt/struct/drawtextparams.h" #include "libc/nt/struct/paintstruct.h" #include "libc/nt/struct/rect.h" +#include "libc/nt/thunk/msabi.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § new technology » cpu graphics ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif int64_t BeginPaint(int64_t hWnd, struct NtPaintStruct *lpPaint); int32_t EndPaint(int64_t hWnd, const struct NtPaintStruct *lpPaint); @@ -27,7 +26,21 @@ int32_t DrawTextEx(int64_t hdc, char16_t *lpchText, int cchText, struct NtRect *lprc, uint32_t format, struct NtDrawTextParams *lpdtp); int32_t FillRect(int64_t hDC, const struct NtRect *lpRC, int64_t hBrush); +uint32_t GetPixel(int64_t hdc, int x, int y); +uint32_t SetPixel(int64_t hdc, int x, int y, uint32_t color); +bool32 RedrawWindow(int64_t hWnd, const struct NtRect *opt_lprcUpdate, + int64_t opt_hrgnUpdate, uint32_t rdwFlags); +int64_t CreateCompatibleDC(int64_t hdc); +int64_t CreateCompatibleBitmap(int64_t hdc, int cx, int cy); +int64_t SelectObject(int64_t hdc, int64_t h); +bool32 DeleteObject(int64_t ho); +bool32 DeleteDC(int64_t hdc); +int SaveDC(int64_t hdc); +bool32 RestoreDC(int64_t hdc, int nSavedDC); +#if ShouldUseMsabiAttribute() +#include "libc/nt/thunk/paint.inc" +#endif /* ShouldUseMsabiAttribute() */ COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_PAINT_H_ */ diff --git a/libc/nt/pedef.h b/libc/nt/pedef.internal.h similarity index 100% rename from libc/nt/pedef.h rename to libc/nt/pedef.internal.h diff --git a/libc/nt/privilege.h b/libc/nt/privilege.h index 36f6763b..043c2e3d 100644 --- a/libc/nt/privilege.h +++ b/libc/nt/privilege.h @@ -1,7 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_PRIVILEGE_H_ #define COSMOPOLITAN_LIBC_NT_PRIVILEGE_H_ #include "libc/nt/struct/luid.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -26,12 +25,11 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » check your privilege ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif #define kNtSePrivilegeEnabledByDefault 0x00000001u -#define kNtSePrivilegeEnabled 0x00000002u -#define kNtSePrivilegeRemoved 0x00000004u -#define kNtSePrivilegeUsedForAccess 0x80000000u +#define kNtSePrivilegeEnabled 0x00000002u +#define kNtSePrivilegeRemoved 0x00000004u +#define kNtSePrivilegeUsedForAccess 0x80000000u #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/nt/process.h b/libc/nt/process.h index ad275989..6fe89c15 100644 --- a/libc/nt/process.h +++ b/libc/nt/process.h @@ -1,11 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_PROCESS_H_ #define COSMOPOLITAN_LIBC_NT_PROCESS_H_ -#include "libc/nt/enum/accessmask.h" -#include "libc/nt/enum/processaccess.h" -#include "libc/nt/enum/processcreationflags.h" #include "libc/nt/startupinfo.h" +#include "libc/nt/struct/processinformation.h" +#include "libc/nt/struct/securityattributes.h" #include "libc/nt/thunk/msabi.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -30,15 +28,10 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » processes ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtProcessInformation; -struct NtSecurityAttributes; -struct NtStartupInfo; - bool32 CreateProcess(const char16_t *opt_lpApplicationName, char16_t *lpCommandLine, struct NtSecurityAttributes *opt_lpProcessAttributes, diff --git a/libc/nt/registry.h b/libc/nt/registry.h index 6ee1a6b4..b3dec34b 100644 --- a/libc/nt/registry.h +++ b/libc/nt/registry.h @@ -1,10 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_REGISTRY_H_ #define COSMOPOLITAN_LIBC_NT_REGISTRY_H_ -#include "libc/nt/enum/keyaccess.h" -#include "libc/nt/enum/reggetvalueflags.h" -#include "libc/nt/enum/regtype.h" #include "libc/nt/enum/securityinformation.h" -#if 0 +#include "libc/nt/struct/filetime.h" +#include "libc/nt/struct/securityattributes.h" +#include "libc/nt/struct/valent.h" /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -29,46 +28,39 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » registry ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif -#define kNtMaxKeyNameChars 255 +#define kNtMaxKeyNameChars 255 #define kNtMaxValueNameChars 16383 -#define kNtMaxValueBytes 0x100000 +#define kNtMaxValueBytes 0x100000 -#define kNtHkeyClassesRoot 0x80000000l -#define kNtHkeyCurrentUser 0x80000001l -#define kNtHkeyLocalMachine 0x80000002l -#define kNtHkeyUsers 0x80000003l -#define kNtHkeyPerformanceData 0x80000004l -#define kNtHkeyPerformanceText 0x80000050l -#define kNtHkeyPerformanceNlstext 0x80000060l -#define kNtHkeyCurrentConfig 0x80000005l -#define kNtHkeyDynData 0x80000006l +#define kNtHkeyClassesRoot 0x80000000l +#define kNtHkeyCurrentUser 0x80000001l +#define kNtHkeyLocalMachine 0x80000002l +#define kNtHkeyUsers 0x80000003l +#define kNtHkeyPerformanceData 0x80000004l +#define kNtHkeyPerformanceText 0x80000050l +#define kNtHkeyPerformanceNlstext 0x80000060l +#define kNtHkeyCurrentConfig 0x80000005l +#define kNtHkeyDynData 0x80000006l #define kNtHkeyCurrentUserLocalSettings 0x80000007l #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtFileTime; -struct NtSecurityAttributes; -struct NtValent; - int RegOpenKey(int64_t hKey, const char16_t *opt_lpSubKey, int64_t *out_phkResult) paramsnonnull((3)); int RegOpenKeyEx(int64_t hKey, const char16_t *opt_lpSubKey, - uint32_t opt_ulOptions, enum NtKeyAccess samDesired, - int64_t *out_phkResult) paramsnonnull((5)); + uint32_t opt_ulOptions, int samDesired, int64_t *out_phkResult) + paramsnonnull((5)); int RegCloseKey(int64_t hKey); int RegGetValue(int64_t hkey, const char16_t *opt_lpSubKey, - const char16_t *opt_lpValue, enum NtRegGetValueFlags dwFlags, - enum NtRegType *opt_pdwType, void *opt_out_pvData, - uint32_t *opt_inout_pcbDataBytes); -int RegSetValue(int64_t hKey, const char16_t *lpSubKey, enum NtRegType dwType, + const char16_t *opt_lpValue, unsigned dwFlags, int *opt_pdwType, + void *opt_out_pvData, uint32_t *opt_inout_pcbDataBytes); +int RegSetValue(int64_t hKey, const char16_t *lpSubKey, int dwType, const char16_t *lpData, uint32_t cbData); int RegSetValueEx(int64_t hKey, const char16_t *lpValueName, uint32_t Reserved, - enum NtRegType dwType, const unsigned char *lpData, - uint32_t cbData); + int dwType, const unsigned char *lpData, uint32_t cbData); int RegQueryInfoKey(int64_t hKey, char16_t *opt_out_lpClass, uint32_t *opt_inout_lpClassLen, uint32_t *lpReserved, @@ -89,19 +81,19 @@ int RegEnumKeyEx(int64_t hKey, uint32_t dwIndex, char16_t *out_lpName, int RegEnumValue(int64_t hKey, uint32_t dwIndex, char16_t *lpValueName, uint32_t *lpValueNameLen, uint32_t *lpReserved, - enum NtRegType *opt_out_lpType, unsigned char *opt_out_lpData, + int *opt_out_lpType, unsigned char *opt_out_lpData, uint32_t *opt_inout_lpcbDataBytes); int RegQueryValue(int64_t hKey, const char16_t *opt_lpSubKey, char16_t *opt_out_lpData, int32_t *opt_inout_lpcbDataBytes); int RegQueryValueEx(int64_t hKey, const char16_t *opt_lpValueName, - uint32_t *lpReserved, enum NtRegType *opt_out_lpType, + uint32_t *lpReserved, int *opt_out_lpType, unsigned char *opt_out_lpData, uint32_t *opt_inout_lpcbDataBytes); int RegOverridePredefKey(int64_t hKey, int64_t hNewHKey); -int RegOpenUserClassesRoot(void *hToken, uint32_t dwOptions, - enum NtKeyAccess samDesired, int64_t *phkResult); -int RegOpenCurrentUser(enum NtKeyAccess samDesired, int64_t *phkResult); +int RegOpenUserClassesRoot(void *hToken, uint32_t dwOptions, int samDesired, + int64_t *phkResult); +int RegOpenCurrentUser(int samDesired, int64_t *phkResult); int RegDisablePredefinedCache(); int RegConnectRegistry(const char16_t *lpMachineName, int64_t hKey, int64_t *phkResult); @@ -109,13 +101,12 @@ int RegConnectRegistryEx(const char16_t *lpMachineName, int64_t hKey, uint32_t Flags, int64_t *phkResult); int RegCreateKey(int64_t hKey, const char16_t *lpSubKey, int64_t *phkResult); int RegCreateKeyEx(int64_t hKey, const char16_t *lpSubKey, uint32_t Reserved, - int16_t *lpClass, uint32_t dwOptions, - enum NtKeyAccess samDesired, + int16_t *lpClass, uint32_t dwOptions, int samDesired, struct NtSecurityAttributes *lpSecurityAttributes, int64_t *phkResult, uint32_t *lpdwDisposition); int RegDeleteKey(int64_t hKey, const char16_t *lpSubKey); -int RegDeleteKeyEx(int64_t hKey, const char16_t *lpSubKey, - enum NtKeyAccess samDesired, uint32_t Reserved); +int RegDeleteKeyEx(int64_t hKey, const char16_t *lpSubKey, int samDesired, + uint32_t Reserved); int RegDeleteTree(int64_t hKey, const char16_t *opt_lpSubKey); int RegDisableReflectionKey(int64_t hBase); int RegEnableReflectionKey(int64_t hBase); diff --git a/libc/nt/runtime.h b/libc/nt/runtime.h index 5caba845..cb5a858c 100644 --- a/libc/nt/runtime.h +++ b/libc/nt/runtime.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_RUNTIME_H_ #define COSMOPOLITAN_LIBC_NT_RUNTIME_H_ -#include "libc/nt/enum/ctrlevent.h" +#include "libc/nt/struct/overlapped.h" #include "libc/nt/thunk/msabi.h" #include "libc/nt/typedef/handlerroutine.h" @@ -21,8 +21,6 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtOverlapped; - char16_t *GetCommandLine(void) nosideeffect; char16_t *GetEnvironmentStrings(void) nodiscard; bool32 FreeEnvironmentStrings(char16_t *) paramsnonnull(); @@ -35,7 +33,7 @@ bool32 WriteFile(int64_t hFile, const void *lpBuffer, struct NtOverlapped *opt_lpOverlapped); bool32 TerminateProcess(int64_t hProcess, uint32_t uExitCode); int64_t GetCurrentProcess(void) pureconst; -void ExitProcess(uint32_t uExitCode); +void ExitProcess(uint32_t uExitCode) noreturn; uint32_t GetLastError(void) nosideeffect; bool32 CloseHandle(int64_t hObject) nothrow nocallback; intptr_t GetStdHandle(int64_t nStdHandle) nosideeffect; diff --git a/libc/nt/signals.h b/libc/nt/signals.h index 2d047072..7ca3c71c 100644 --- a/libc/nt/signals.h +++ b/libc/nt/signals.h @@ -1,9 +1,8 @@ #ifndef COSMOPOLITAN_LIBC_NT_EXCEPTIONS_H_ #define COSMOPOLITAN_LIBC_NT_EXCEPTIONS_H_ -#include "libc/nt/enum/errormodeflags.h" #include "libc/nt/struct/context.h" +#include "libc/nt/struct/ntexceptionpointers.h" #include "libc/nt/thunk/msabi.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -28,42 +27,14 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » signals ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif - -#define kNtSignalBreakpoint 0x80000003u -#define kNtSignalIllegalInstruction 0xC000001Du -#define kNtSignalPrivInstruction 0xC0000096u -#define kNtSignalGuardPage 0x80000001u -#define kNtSignalAccessViolation 0xC0000005u -#define kNtSignalInPageError 0xC0000006u -#define kNtSignalInvalidHandle 0xC0000008u -#define kNtSignalInvalidParameter 0xC000000du -#define kNtSignalFltDenormalOperand 0xC000008Du -#define kNtSignalFltDivideByZero 0xC000008Eu -#define kNtSignalFltInexactResult 0xC000008Fu -#define kNtSignalFltInvalidOperation 0xC0000090u -#define kNtSignalFltOverflow 0xC0000091u -#define kNtSignalFltStackCheck 0xC0000092u -#define kNtSignalFltUnderflow 0xC0000093u -#define kNtSignalIntegerDivideByZero 0xC0000094u -#define kNtSignalDllNotFound 0xC0000135u -#define kNtSignalOrdinalNotFound 0xC0000138u -#define kNtSignalEntrypointNotFound 0xC0000139u -#define kNtSignalControlCExit 0xC000013Au -#define kNtSignalDllInitFailed 0xC0000142u -#define kNtSignalFloatMultipleFaults 0xC00002B4u -#define kNtSignalFloatMultipleTraps 0xC00002B5u -#define kNtSignalAssertionFailure 0xC0000420u #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtExceptionPointers; - typedef int (*NtTopLevelExceptionFilter)(const struct NtExceptionPointers *); typedef int32_t (*NtVectoredExceptionHandler)(struct NtExceptionPointers *); -enum NtErrorModeFlags SetErrorMode(enum NtErrorModeFlags uMode); +int SetErrorMode(int uMode); int64_t AddVectoredExceptionHandler(uint32_t First, NtVectoredExceptionHandler pHandler); diff --git a/libc/nt/startupinfo.h b/libc/nt/startupinfo.h index 45b0cc60..bafe9dc5 100644 --- a/libc/nt/startupinfo.h +++ b/libc/nt/startupinfo.h @@ -1,12 +1,11 @@ #ifndef COSMOPOLITAN_LIBC_NT_NTSTARTUPINFO_H_ #define COSMOPOLITAN_LIBC_NT_NTSTARTUPINFO_H_ +#include "libc/nt/struct/procthreadattributelist.h" +#include "libc/nt/struct/startupinfo.h" #include "libc/nt/thunk/msabi.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtStartupInfo; -struct NtProcThreadAttributeList; /* opaque */ - void GetStartupInfo(struct NtStartupInfo *lpStartupInfo); bool32 InitializeProcThreadAttributeList( diff --git a/libc/nt/struct/editmenu.h b/libc/nt/struct/editmenu.h new file mode 100644 index 00000000..73209684 --- /dev/null +++ b/libc/nt/struct/editmenu.h @@ -0,0 +1,16 @@ +#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_EDITMENU_H_ +#define COSMOPOLITAN_LIBC_NT_STRUCT_EDITMENU_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +struct NtEditMenu { + int64_t hmenu; + uint16_t idEdit; + uint16_t idCut; + uint16_t idCopy; + uint16_t idPaste; + uint16_t idClear; + uint16_t idUndo; +}; + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_EDITMENU_H_ */ diff --git a/libc/nt/struct/imagearchivememberheader.h b/libc/nt/struct/imagearchivememberheader.internal.h similarity index 100% rename from libc/nt/struct/imagearchivememberheader.h rename to libc/nt/struct/imagearchivememberheader.internal.h diff --git a/libc/nt/struct/imageauxsymbol.h b/libc/nt/struct/imageauxsymbol.internal.h similarity index 91% rename from libc/nt/struct/imageauxsymbol.h rename to libc/nt/struct/imageauxsymbol.internal.h index 846af297..615223e9 100644 --- a/libc/nt/struct/imageauxsymbol.h +++ b/libc/nt/struct/imageauxsymbol.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEAUXSYMBOL_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEAUXSYMBOL_H_ -#include "libc/nt/pedef.h" -#include "libc/nt/struct/imageauxsymboltokendef.h" +#include "libc/nt/pedef.internal.h" +#include "libc/nt/struct/imageauxsymboltokendef.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) union NtImageAuxSymbol { diff --git a/libc/nt/struct/imageauxsymbolex.h b/libc/nt/struct/imageauxsymbolex.internal.h similarity index 88% rename from libc/nt/struct/imageauxsymbolex.h rename to libc/nt/struct/imageauxsymbolex.internal.h index 13876890..66945853 100644 --- a/libc/nt/struct/imageauxsymbolex.h +++ b/libc/nt/struct/imageauxsymbolex.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEAUXSYMBOLEX_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEAUXSYMBOLEX_H_ -#include "libc/nt/struct/imageauxsymboltokendef.h" -#include "libc/nt/struct/imagesymbolex.h" +#include "libc/nt/struct/imageauxsymboltokendef.internal.h" +#include "libc/nt/struct/imagesymbolex.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) union NtImageAuxSymbolEx { diff --git a/libc/nt/struct/imageauxsymboltokendef.h b/libc/nt/struct/imageauxsymboltokendef.internal.h similarity index 100% rename from libc/nt/struct/imageauxsymboltokendef.h rename to libc/nt/struct/imageauxsymboltokendef.internal.h diff --git a/libc/nt/struct/imagebaserelocation.h b/libc/nt/struct/imagebaserelocation.internal.h similarity index 100% rename from libc/nt/struct/imagebaserelocation.h rename to libc/nt/struct/imagebaserelocation.internal.h diff --git a/libc/nt/struct/imageboundforwarderref.h b/libc/nt/struct/imageboundforwarderref.internal.h similarity index 100% rename from libc/nt/struct/imageboundforwarderref.h rename to libc/nt/struct/imageboundforwarderref.internal.h diff --git a/libc/nt/struct/imageboundimportdescriptor.h b/libc/nt/struct/imageboundimportdescriptor.internal.h similarity index 100% rename from libc/nt/struct/imageboundimportdescriptor.h rename to libc/nt/struct/imageboundimportdescriptor.internal.h diff --git a/libc/nt/struct/imageceruntimefunctionentry.h b/libc/nt/struct/imageceruntimefunctionentry.internal.h similarity index 100% rename from libc/nt/struct/imageceruntimefunctionentry.h rename to libc/nt/struct/imageceruntimefunctionentry.internal.h diff --git a/libc/nt/struct/imagecoffsymbolsheader.h b/libc/nt/struct/imagecoffsymbolsheader.internal.h similarity index 100% rename from libc/nt/struct/imagecoffsymbolsheader.h rename to libc/nt/struct/imagecoffsymbolsheader.internal.h diff --git a/libc/nt/struct/imagedatadirectory.h b/libc/nt/struct/imagedatadirectory.internal.h similarity index 100% rename from libc/nt/struct/imagedatadirectory.h rename to libc/nt/struct/imagedatadirectory.internal.h diff --git a/libc/nt/struct/imagedebugdirectory.h b/libc/nt/struct/imagedebugdirectory.internal.h similarity index 100% rename from libc/nt/struct/imagedebugdirectory.h rename to libc/nt/struct/imagedebugdirectory.internal.h diff --git a/libc/nt/struct/imagedebugmisc.h b/libc/nt/struct/imagedebugmisc.internal.h similarity index 100% rename from libc/nt/struct/imagedebugmisc.h rename to libc/nt/struct/imagedebugmisc.internal.h diff --git a/libc/nt/struct/imagedelayloaddescriptor.h b/libc/nt/struct/imagedelayloaddescriptor.internal.h similarity index 100% rename from libc/nt/struct/imagedelayloaddescriptor.h rename to libc/nt/struct/imagedelayloaddescriptor.internal.h diff --git a/libc/nt/struct/imagedosheader.h b/libc/nt/struct/imagedosheader.internal.h similarity index 100% rename from libc/nt/struct/imagedosheader.h rename to libc/nt/struct/imagedosheader.internal.h diff --git a/libc/nt/struct/imagedynamicrelocation.h b/libc/nt/struct/imagedynamicrelocation.internal.h similarity index 87% rename from libc/nt/struct/imagedynamicrelocation.h rename to libc/nt/struct/imagedynamicrelocation.internal.h index 4092e2b6..df2102d9 100644 --- a/libc/nt/struct/imagedynamicrelocation.h +++ b/libc/nt/struct/imagedynamicrelocation.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEDYNAMICRELOCATION_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEDYNAMICRELOCATION_H_ -#include "libc/nt/struct/imagebaserelocation.h" +#include "libc/nt/struct/imagebaserelocation.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct NtImageDynamicRelocation { diff --git a/libc/nt/struct/imagedynamicrelocationtable.h b/libc/nt/struct/imagedynamicrelocationtable.internal.h similarity index 87% rename from libc/nt/struct/imagedynamicrelocationtable.h rename to libc/nt/struct/imagedynamicrelocationtable.internal.h index b3d0e843..41f3fae4 100644 --- a/libc/nt/struct/imagedynamicrelocationtable.h +++ b/libc/nt/struct/imagedynamicrelocationtable.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEDYNAMICRELOCATIONTABLE_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEDYNAMICRELOCATIONTABLE_H_ -#include "libc/nt/struct/imagedynamicrelocation.h" +#include "libc/nt/struct/imagedynamicrelocation.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct NtImageDynamicRelocationTable { diff --git a/libc/nt/struct/imagedynamicrelocationv2.h b/libc/nt/struct/imagedynamicrelocationv2.internal.h similarity index 100% rename from libc/nt/struct/imagedynamicrelocationv2.h rename to libc/nt/struct/imagedynamicrelocationv2.internal.h diff --git a/libc/nt/struct/imageenclaveconfig.h b/libc/nt/struct/imageenclaveconfig.internal.h similarity index 95% rename from libc/nt/struct/imageenclaveconfig.h rename to libc/nt/struct/imageenclaveconfig.internal.h index e970f2a1..1617b6e4 100644 --- a/libc/nt/struct/imageenclaveconfig.h +++ b/libc/nt/struct/imageenclaveconfig.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEENCLAVECONFIG_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEENCLAVECONFIG_H_ -#include "libc/nt/pedef.h" +#include "libc/nt/pedef.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct NtImageEnclaveConfig { diff --git a/libc/nt/struct/imageenclaveimport.h b/libc/nt/struct/imageenclaveimport.internal.h similarity index 93% rename from libc/nt/struct/imageenclaveimport.h rename to libc/nt/struct/imageenclaveimport.internal.h index 2c4e5250..8ac8165a 100644 --- a/libc/nt/struct/imageenclaveimport.h +++ b/libc/nt/struct/imageenclaveimport.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEENCLAVEIMPORT_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEENCLAVEIMPORT_H_ -#include "libc/nt/pedef.h" +#include "libc/nt/pedef.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct NtImageEnclaveImport { diff --git a/libc/nt/struct/imageepiloguedynamicrelocationheader.h b/libc/nt/struct/imageepiloguedynamicrelocationheader.internal.h similarity index 100% rename from libc/nt/struct/imageepiloguedynamicrelocationheader.h rename to libc/nt/struct/imageepiloguedynamicrelocationheader.internal.h diff --git a/libc/nt/struct/imageexportdirectory.h b/libc/nt/struct/imageexportdirectory.internal.h similarity index 100% rename from libc/nt/struct/imageexportdirectory.h rename to libc/nt/struct/imageexportdirectory.internal.h diff --git a/libc/nt/struct/imagefileheader.h b/libc/nt/struct/imagefileheader.internal.h similarity index 100% rename from libc/nt/struct/imagefileheader.h rename to libc/nt/struct/imagefileheader.internal.h diff --git a/libc/nt/struct/imagehotpatchbase.h b/libc/nt/struct/imagehotpatchbase.internal.h similarity index 100% rename from libc/nt/struct/imagehotpatchbase.h rename to libc/nt/struct/imagehotpatchbase.internal.h diff --git a/libc/nt/struct/imagehotpatchhashes.h b/libc/nt/struct/imagehotpatchhashes.internal.h similarity index 100% rename from libc/nt/struct/imagehotpatchhashes.h rename to libc/nt/struct/imagehotpatchhashes.internal.h diff --git a/libc/nt/struct/imagehotpatchinfo.h b/libc/nt/struct/imagehotpatchinfo.internal.h similarity index 100% rename from libc/nt/struct/imagehotpatchinfo.h rename to libc/nt/struct/imagehotpatchinfo.internal.h diff --git a/libc/nt/struct/imageimportbyname.h b/libc/nt/struct/imageimportbyname.internal.h similarity index 100% rename from libc/nt/struct/imageimportbyname.h rename to libc/nt/struct/imageimportbyname.internal.h diff --git a/libc/nt/struct/imageimportdescriptor.h b/libc/nt/struct/imageimportdescriptor.internal.h similarity index 100% rename from libc/nt/struct/imageimportdescriptor.h rename to libc/nt/struct/imageimportdescriptor.internal.h diff --git a/libc/nt/struct/imagelinenumber.h b/libc/nt/struct/imagelinenumber.internal.h similarity index 100% rename from libc/nt/struct/imagelinenumber.h rename to libc/nt/struct/imagelinenumber.internal.h diff --git a/libc/nt/struct/imageloadconfigcodeintegrity.h b/libc/nt/struct/imageloadconfigcodeintegrity.internal.h similarity index 100% rename from libc/nt/struct/imageloadconfigcodeintegrity.h rename to libc/nt/struct/imageloadconfigcodeintegrity.internal.h diff --git a/libc/nt/struct/imageloadconfigdirectory.h b/libc/nt/struct/imageloadconfigdirectory.internal.h similarity index 96% rename from libc/nt/struct/imageloadconfigdirectory.h rename to libc/nt/struct/imageloadconfigdirectory.internal.h index cef2ee2c..6a81801a 100644 --- a/libc/nt/struct/imageloadconfigdirectory.h +++ b/libc/nt/struct/imageloadconfigdirectory.internal.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGELOADCONFIGDIRECTORY_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGELOADCONFIGDIRECTORY_H_ -#include "libc/nt/struct/imageloadconfigcodeintegrity.h" +#include "libc/nt/struct/imageloadconfigcodeintegrity.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct NtImageLoadConfigDirectory { diff --git a/libc/nt/struct/imagentheaders.h b/libc/nt/struct/imagentheaders.internal.h similarity index 78% rename from libc/nt/struct/imagentheaders.h rename to libc/nt/struct/imagentheaders.internal.h index ea643b85..0b0ad503 100644 --- a/libc/nt/struct/imagentheaders.h +++ b/libc/nt/struct/imagentheaders.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGENTHEADERS_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGENTHEADERS_H_ -#include "libc/nt/struct/imagefileheader.h" -#include "libc/nt/struct/imageoptionalheader.h" +#include "libc/nt/struct/imagefileheader.internal.h" +#include "libc/nt/struct/imageoptionalheader.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct NtImageNtHeaders { diff --git a/libc/nt/struct/imageoptionalheader.h b/libc/nt/struct/imageoptionalheader.internal.h similarity index 93% rename from libc/nt/struct/imageoptionalheader.h rename to libc/nt/struct/imageoptionalheader.internal.h index 552efe5d..4fb6d006 100644 --- a/libc/nt/struct/imageoptionalheader.h +++ b/libc/nt/struct/imageoptionalheader.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEOPTIONALHEADER_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGEOPTIONALHEADER_H_ -#include "libc/nt/pedef.h" -#include "libc/nt/struct/imagedatadirectory.h" +#include "libc/nt/pedef.internal.h" +#include "libc/nt/struct/imagedatadirectory.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct NtImageOptionalHeader { diff --git a/libc/nt/struct/imageprologuedynamicrelocationheader.h b/libc/nt/struct/imageprologuedynamicrelocationheader.internal.h similarity index 100% rename from libc/nt/struct/imageprologuedynamicrelocationheader.h rename to libc/nt/struct/imageprologuedynamicrelocationheader.internal.h diff --git a/libc/nt/struct/imagerelocation.h b/libc/nt/struct/imagerelocation.internal.h similarity index 100% rename from libc/nt/struct/imagerelocation.h rename to libc/nt/struct/imagerelocation.internal.h diff --git a/libc/nt/struct/imageresourcedataentry.h b/libc/nt/struct/imageresourcedataentry.internal.h similarity index 100% rename from libc/nt/struct/imageresourcedataentry.h rename to libc/nt/struct/imageresourcedataentry.internal.h diff --git a/libc/nt/struct/imageresourcedirectory.h b/libc/nt/struct/imageresourcedirectory.internal.h similarity index 100% rename from libc/nt/struct/imageresourcedirectory.h rename to libc/nt/struct/imageresourcedirectory.internal.h diff --git a/libc/nt/struct/imageresourcedirectoryentry.h b/libc/nt/struct/imageresourcedirectoryentry.internal.h similarity index 100% rename from libc/nt/struct/imageresourcedirectoryentry.h rename to libc/nt/struct/imageresourcedirectoryentry.internal.h diff --git a/libc/nt/struct/imageresourcedirstring.h b/libc/nt/struct/imageresourcedirstring.internal.h similarity index 100% rename from libc/nt/struct/imageresourcedirstring.h rename to libc/nt/struct/imageresourcedirstring.internal.h diff --git a/libc/nt/struct/imageromoptionalheader.h b/libc/nt/struct/imageromoptionalheader.internal.h similarity index 100% rename from libc/nt/struct/imageromoptionalheader.h rename to libc/nt/struct/imageromoptionalheader.internal.h diff --git a/libc/nt/struct/imageruntimefunctionentry.h b/libc/nt/struct/imageruntimefunctionentry.internal.h similarity index 100% rename from libc/nt/struct/imageruntimefunctionentry.h rename to libc/nt/struct/imageruntimefunctionentry.internal.h diff --git a/libc/nt/struct/imagesectionheader.h b/libc/nt/struct/imagesectionheader.internal.h similarity index 94% rename from libc/nt/struct/imagesectionheader.h rename to libc/nt/struct/imagesectionheader.internal.h index 8f857c69..278f9642 100644 --- a/libc/nt/struct/imagesectionheader.h +++ b/libc/nt/struct/imagesectionheader.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IMAGESECTIONHEADER_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_IMAGESECTIONHEADER_H_ +#include "libc/nt/pedef.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) -#include "libc/nt/pedef.h" struct NtImageSectionHeader { uint8_t Name[kNtImageSizeofShortName]; diff --git a/libc/nt/struct/imageseparatedebugheader.h b/libc/nt/struct/imageseparatedebugheader.internal.h similarity index 100% rename from libc/nt/struct/imageseparatedebugheader.h rename to libc/nt/struct/imageseparatedebugheader.internal.h diff --git a/libc/nt/struct/imagesymbol.h b/libc/nt/struct/imagesymbol.internal.h similarity index 100% rename from libc/nt/struct/imagesymbol.h rename to libc/nt/struct/imagesymbol.internal.h diff --git a/libc/nt/struct/imagesymbolex.h b/libc/nt/struct/imagesymbolex.internal.h similarity index 100% rename from libc/nt/struct/imagesymbolex.h rename to libc/nt/struct/imagesymbolex.internal.h diff --git a/libc/nt/struct/imagethunkdata.h b/libc/nt/struct/imagethunkdata.internal.h similarity index 100% rename from libc/nt/struct/imagethunkdata.h rename to libc/nt/struct/imagethunkdata.internal.h diff --git a/libc/nt/struct/imagetlsdirectory.h b/libc/nt/struct/imagetlsdirectory.internal.h similarity index 100% rename from libc/nt/struct/imagetlsdirectory.h rename to libc/nt/struct/imagetlsdirectory.internal.h diff --git a/libc/nt/struct/importobjectheader.h b/libc/nt/struct/importobjectheader.internal.h similarity index 100% rename from libc/nt/struct/importobjectheader.h rename to libc/nt/struct/importobjectheader.internal.h diff --git a/libc/nt/struct/ntexceptionpointers.h b/libc/nt/struct/ntexceptionpointers.h index 5d6c6e7d..ddcb2ce1 100644 --- a/libc/nt/struct/ntexceptionpointers.h +++ b/libc/nt/struct/ntexceptionpointers.h @@ -1,10 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONPOINTERS_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONPOINTERS_H_ +#include "libc/nt/struct/context.h" +#include "libc/nt/struct/ntexceptionrecord.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) -struct NtContext; -struct NtExceptionRecord; - struct NtExceptionPointers { struct NtExceptionRecord *ExceptionRecord; struct NtContext *ContextRecord; diff --git a/libc/nt/struct/openfilename.h b/libc/nt/struct/openfilename.h new file mode 100644 index 00000000..8c0e1835 --- /dev/null +++ b/libc/nt/struct/openfilename.h @@ -0,0 +1,33 @@ +#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_OPENFILENAME_H_ +#define COSMOPOLITAN_LIBC_NT_STRUCT_OPENFILENAME_H_ +#include "libc/nt/struct/editmenu.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +struct NtOpenFilename { + uint32_t lStructSize; + int64_t hwndOwner; + int64_t hInstance; + const char16_t *lpstrFilter; + char16_t *lpstrCustomFilter; + uint32_t nMaxCustFilter; + uint32_t nFilterIndex; + char16_t *lpstrFile; + uint32_t nMaxFile; + char16_t *lpstrFileTitle; + uint32_t nMaxFileTitle; + const char16_t *lpstrInitialDir; + const char16_t *lpstrTitle; + uint32_t Flags; + uint16_t nFileOffset; + uint16_t nFileExtension; + const char16_t *lpstrDefExt; + intptr_t lCustData; + uint64_t (*lpfnHook)(int64_t, uint32_t, uint64_t, int64_t); + const char16_t *lpTemplateName; + void *pvReserved; + uint32_t dwReserved; + uint32_t FlagsEx; +}; + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_OPENFILENAME_H_ */ diff --git a/libc/nt/struct/paintstruct.h b/libc/nt/struct/paintstruct.h index 688f72f8..c10e987e 100644 --- a/libc/nt/struct/paintstruct.h +++ b/libc/nt/struct/paintstruct.h @@ -2,7 +2,6 @@ #define COSMOPOLITAN_LIBC_NT_STRUCT_PAINTSTRUCT_H_ #include "libc/nt/struct/rect.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ struct NtPaintStruct { int64_t hdc; @@ -13,6 +12,5 @@ struct NtPaintStruct { uint8_t rgbReserved[32]; }; -COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_STRUCT_PAINTSTRUCT_H_ */ diff --git a/libc/nt/struct/procthreadattributelist.h b/libc/nt/struct/procthreadattributelist.h new file mode 100644 index 00000000..5b664dcb --- /dev/null +++ b/libc/nt/struct/procthreadattributelist.h @@ -0,0 +1,6 @@ +#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_PROCTHREADATTRIBUTELIST_H_ +#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCTHREADATTRIBUTELIST_H_ + +struct NtProcThreadAttributeList; + +#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_PROCTHREADATTRIBUTELIST_H_ */ diff --git a/libc/nt/struct/rect.h b/libc/nt/struct/rect.h index b3d21579..6e6aca3e 100644 --- a/libc/nt/struct/rect.h +++ b/libc/nt/struct/rect.h @@ -1,7 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_RECT_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_RECT_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ struct NtRect { int32_t left; @@ -10,6 +9,5 @@ struct NtRect { int32_t bottom; }; -COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_STRUCT_RECT_H_ */ diff --git a/libc/nt/struct/startupinfoex.h b/libc/nt/struct/startupinfoex.h index 0b513ebf..0a9beb72 100644 --- a/libc/nt/struct/startupinfoex.h +++ b/libc/nt/struct/startupinfoex.h @@ -1,16 +1,13 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFOEX_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFOEX_H_ +#include "libc/nt/struct/procthreadattributelist.h" #include "libc/nt/struct/startupinfo.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct NtProcThreadAttributeList; struct NtStartupInfoEx { struct NtStartupInfo StartupInfo; struct NtProcThreadAttributeList *lpAttributeList; }; -COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFOEX_H_ */ diff --git a/libc/nt/struct/systemprocessorperformanceinformation.h b/libc/nt/struct/systemprocessorperformanceinformation.h index e8122e3d..b2ce8368 100644 --- a/libc/nt/struct/systemprocessorperformanceinformation.h +++ b/libc/nt/struct/systemprocessorperformanceinformation.h @@ -11,5 +11,4 @@ struct NtSystemProcessorPerformanceInformation { }; #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORPERFORMANCEINFORMATION_H_ \ - */ +#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORPERFORMANCEINFORMATION_H_*/ diff --git a/libc/nt/struct/systemthreads.h b/libc/nt/struct/systemthreads.h index 657de8f1..18d496d9 100644 --- a/libc/nt/struct/systemthreads.h +++ b/libc/nt/struct/systemthreads.h @@ -1,7 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTHREADS_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTHREADS_H_ #include "libc/nt/enum/kwaitreason.h" -#include "libc/nt/enum/threadstate.h" #include "libc/nt/struct/clientid.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) @@ -15,7 +14,7 @@ struct NtSystemThreads { int32_t Priority; int32_t BasePriority; uint32_t ContextSwitchCount; - enum NtThreadState State; + int State; uint32_t WaitReason; }; diff --git a/libc/nt/struct/teb.h b/libc/nt/struct/teb.h index 558a2fa2..972b9c5e 100644 --- a/libc/nt/struct/teb.h +++ b/libc/nt/struct/teb.h @@ -4,9 +4,7 @@ #include "libc/nt/struct/peb.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) -#if 0 /* These macros address directly into NT's TEB a.k.a. TIB */ -#endif #define NtGetPeb() gs((struct NtPeb **)(0x60ULL)) #define NtGetTeb() gs((void **)(0x30)) /* %gs:0 linear address */ #define NtGetPid() gs((uint32_t *)(0x40)) /* GetCurrentProcessId() */ diff --git a/libc/nt/struct/windowplacement.h b/libc/nt/struct/windowplacement.h new file mode 100644 index 00000000..a249f6b6 --- /dev/null +++ b/libc/nt/struct/windowplacement.h @@ -0,0 +1,18 @@ +#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_WINDOWPLACEMENT_H_ +#define COSMOPOLITAN_LIBC_NT_STRUCT_WINDOWPLACEMENT_H_ +#include "libc/nt/struct/point.h" +#include "libc/nt/struct/rect.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +struct NtWindowPlacement { + uint32_t length; + uint32_t flags; + uint32_t showCmd; + struct NtPoint ptMinPosition; + struct NtPoint ptMaxPosition; + struct NtRect rcNormalPosition; + struct NtRect rcDevice; +}; + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_WINDOWPLACEMENT_H_ */ diff --git a/libc/nt/synchronization.h b/libc/nt/synchronization.h index 7f841791..05d3ef28 100644 --- a/libc/nt/synchronization.h +++ b/libc/nt/synchronization.h @@ -7,7 +7,6 @@ #include "libc/nt/struct/systemtime.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -32,7 +31,6 @@ COSMOPOLITAN_C_START_ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » synchronization ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif typedef void (*NtTimerapcroutine)(void *lpArgToCompletionRoutine, uint32_t dwTimerLowValue, diff --git a/libc/nt/systeminfo.h b/libc/nt/systeminfo.h index f53219d4..daaf6f0d 100644 --- a/libc/nt/systeminfo.h +++ b/libc/nt/systeminfo.h @@ -5,8 +5,6 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct NtSystemInfo; - void GetSystemInfo(struct NtSystemInfo *lpSystemInfo); uint32_t GetSystemDirectory(char16_t *lpBuffer, uint32_t uSize); uint32_t GetSystemDirectoryA(char *lpBuffer, uint32_t uSize); diff --git a/libc/nt/thread.h b/libc/nt/thread.h index fb4378ed..f8901295 100644 --- a/libc/nt/thread.h +++ b/libc/nt/thread.h @@ -1,12 +1,10 @@ #ifndef COSMOPOLITAN_LIBC_NT_THREADS_H_ #define COSMOPOLITAN_LIBC_NT_THREADS_H_ -#include "libc/nt/enum/threadaccess.h" #include "libc/nt/struct/overlapped.h" #include "libc/nt/struct/securityattributes.h" #include "libc/nt/thunk/msabi.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -31,7 +29,6 @@ COSMOPOLITAN_C_START_ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » threads ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif typedef uint32_t (*NtThreadStartRoutine)(void *lpParameter); diff --git a/libc/nt/thunk/paint.inc b/libc/nt/thunk/paint.inc new file mode 100644 index 00000000..5f9705a9 --- /dev/null +++ b/libc/nt/thunk/paint.inc @@ -0,0 +1,5 @@ +#define SetPixel(...) __imp_SetPixel(__VA_ARGS__) +#define GetPixel(...) __imp_GetPixel(__VA_ARGS__) + +extern typeof(SetPixel) *const __imp_SetPixel __msabi; +extern typeof(GetPixel) *const __imp_GetPixel __msabi; diff --git a/libc/nt/thunk/runtime.inc b/libc/nt/thunk/runtime.inc index 4d220489..89a61ace 100644 --- a/libc/nt/thunk/runtime.inc +++ b/libc/nt/thunk/runtime.inc @@ -1,6 +1,3 @@ -#define ExitProcess(...) __imp_ExitProcess(__VA_ARGS__) -extern typeof(ExitProcess) *const __imp_ExitProcess __msabi; - #define FreeEnvironmentStrings(...) __imp_FreeEnvironmentStringsW(__VA_ARGS__) extern typeof(FreeEnvironmentStrings) *const __imp_FreeEnvironmentStringsW __msabi; diff --git a/libc/nt/user32/AppendMenuA.s b/libc/nt/user32/AppendMenuA.s index d54061ef..f0817a6c 100644 --- a/libc/nt/user32/AppendMenuA.s +++ b/libc/nt/user32/AppendMenuA.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_AppendMenuA,AppendMenuA,1515 + + .text.windows +AppendMenuA: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_AppendMenuA(%rip),%rax + jmp __sysv2nt + .endfn AppendMenuA,globl + .previous diff --git a/libc/nt/user32/AppendMenuW.s b/libc/nt/user32/AppendMenuW.s index eb358da9..4cbc08f5 100644 --- a/libc/nt/user32/AppendMenuW.s +++ b/libc/nt/user32/AppendMenuW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_AppendMenuW,AppendMenuW,1516 + + .text.windows +AppendMenu: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_AppendMenuW(%rip),%rax + jmp __sysv2nt + .endfn AppendMenu,globl + .previous diff --git a/libc/nt/user32/CreateMenu.s b/libc/nt/user32/CreateMenu.s index a1729e19..a900dd18 100644 --- a/libc/nt/user32/CreateMenu.s +++ b/libc/nt/user32/CreateMenu.s @@ -1,2 +1,14 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_CreateMenu,CreateMenu,1621 + + .text.windows +CreateMenu: + push %rbp + mov %rsp,%rbp + .profilable + sub $32,%rsp + call *__imp_CreateMenu(%rip) + leave + ret + .endfn CreateMenu,globl + .previous diff --git a/libc/nt/user32/CreatePopupMenu.s b/libc/nt/user32/CreatePopupMenu.s index c3512f59..92e4b3bd 100644 --- a/libc/nt/user32/CreatePopupMenu.s +++ b/libc/nt/user32/CreatePopupMenu.s @@ -1,2 +1,14 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_CreatePopupMenu,CreatePopupMenu,1622 + + .text.windows +CreatePopupMenu: + push %rbp + mov %rsp,%rbp + .profilable + sub $32,%rsp + call *__imp_CreatePopupMenu(%rip) + leave + ret + .endfn CreatePopupMenu,globl + .previous diff --git a/libc/nt/user32/DeleteMenu.s b/libc/nt/user32/DeleteMenu.s index 0a225fb6..a1647195 100644 --- a/libc/nt/user32/DeleteMenu.s +++ b/libc/nt/user32/DeleteMenu.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_DeleteMenu,DeleteMenu,1681 + + .text.windows +DeleteMenu: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_DeleteMenu(%rip),%rax + jmp __sysv2nt + .endfn DeleteMenu,globl + .previous diff --git a/libc/nt/user32/DestroyMenu.s b/libc/nt/user32/DestroyMenu.s index fb47cc65..6749e935 100644 --- a/libc/nt/user32/DestroyMenu.s +++ b/libc/nt/user32/DestroyMenu.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_DestroyMenu,DestroyMenu,1688 + + .text.windows +DestroyMenu: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_DestroyMenu(%rip) + leave + ret + .endfn DestroyMenu,globl + .previous diff --git a/libc/nt/user32/GetCursor.s b/libc/nt/user32/GetCursor.s index d6cd5972..028c5ec7 100644 --- a/libc/nt/user32/GetCursor.s +++ b/libc/nt/user32/GetCursor.s @@ -1,2 +1,14 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_GetCursor,GetCursor,1826 + + .text.windows +GetCursor: + push %rbp + mov %rsp,%rbp + .profilable + sub $32,%rsp + call *__imp_GetCursor(%rip) + leave + ret + .endfn GetCursor,globl + .previous diff --git a/libc/nt/user32/GetKeyState.s b/libc/nt/user32/GetKeyState.s index e230a818..7642595f 100644 --- a/libc/nt/user32/GetKeyState.s +++ b/libc/nt/user32/GetKeyState.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_GetKeyState,GetKeyState,1866 + + .text.windows +GetKeyState: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_GetKeyState(%rip) + leave + ret + .endfn GetKeyState,globl + .previous diff --git a/libc/nt/user32/GetMenu.s b/libc/nt/user32/GetMenu.s index 051db423..28e3acf2 100644 --- a/libc/nt/user32/GetMenu.s +++ b/libc/nt/user32/GetMenu.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_GetMenu,GetMenu,1881 + + .text.windows +GetMenu: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_GetMenu(%rip) + leave + ret + .endfn GetMenu,globl + .previous diff --git a/libc/nt/user32/GetSystemMenu.s b/libc/nt/user32/GetSystemMenu.s index 20e42ed3..c0442d6f 100644 --- a/libc/nt/user32/GetSystemMenu.s +++ b/libc/nt/user32/GetSystemMenu.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_GetSystemMenu,GetSystemMenu,1955 + + .text.windows +GetSystemMenu: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_GetSystemMenu(%rip),%rax + jmp __sysv2nt + .endfn GetSystemMenu,globl + .previous diff --git a/libc/nt/user32/GetWindowPlacement.s b/libc/nt/user32/GetWindowPlacement.s index 5ddb46a3..7bcb6952 100644 --- a/libc/nt/user32/GetWindowPlacement.s +++ b/libc/nt/user32/GetWindowPlacement.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_GetWindowPlacement,GetWindowPlacement,1995 + + .text.windows +GetWindowPlacement: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_GetWindowPlacement(%rip),%rax + jmp __sysv2nt + .endfn GetWindowPlacement,globl + .previous diff --git a/libc/nt/user32/InsertMenuA.s b/libc/nt/user32/InsertMenuA.s index 84fe4953..755310c9 100644 --- a/libc/nt/user32/InsertMenuA.s +++ b/libc/nt/user32/InsertMenuA.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_InsertMenuA,InsertMenuA,2041 + + .text.windows +InsertMenuA: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_InsertMenuA(%rip),%rax + jmp __sysv2nt6 + .endfn InsertMenuA,globl + .previous diff --git a/libc/nt/user32/InsertMenuW.s b/libc/nt/user32/InsertMenuW.s index 9ffd81f7..6429bab9 100644 --- a/libc/nt/user32/InsertMenuW.s +++ b/libc/nt/user32/InsertMenuW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_InsertMenuW,InsertMenuW,2044 + + .text.windows +InsertMenu: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_InsertMenuW(%rip),%rax + jmp __sysv2nt6 + .endfn InsertMenu,globl + .previous diff --git a/libc/nt/user32/IsIconic.s b/libc/nt/user32/IsIconic.s index 4d15f8ef..18221b65 100644 --- a/libc/nt/user32/IsIconic.s +++ b/libc/nt/user32/IsIconic.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_IsIconic,IsIconic,2067 + + .text.windows +IsIconic: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_IsIconic(%rip) + leave + ret + .endfn IsIconic,globl + .previous diff --git a/libc/nt/user32/RedrawWindow.s b/libc/nt/user32/RedrawWindow.s index 092c4843..e0a1211b 100644 --- a/libc/nt/user32/RedrawWindow.s +++ b/libc/nt/user32/RedrawWindow.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_RedrawWindow,RedrawWindow,2246 + + .text.windows +RedrawWindow: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_RedrawWindow(%rip),%rax + jmp __sysv2nt + .endfn RedrawWindow,globl + .previous diff --git a/libc/nt/user32/ReleaseCapture.s b/libc/nt/user32/ReleaseCapture.s index afb1b4be..7bdd2767 100644 --- a/libc/nt/user32/ReleaseCapture.s +++ b/libc/nt/user32/ReleaseCapture.s @@ -1,2 +1,14 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_ReleaseCapture,ReleaseCapture,2279 + + .text.windows +ReleaseCapture: + push %rbp + mov %rsp,%rbp + .profilable + sub $32,%rsp + call *__imp_ReleaseCapture(%rip) + leave + ret + .endfn ReleaseCapture,globl + .previous diff --git a/libc/nt/user32/SendMessageW.s b/libc/nt/user32/SendMessageW.s index 68eccca1..5e803f28 100644 --- a/libc/nt/user32/SendMessageW.s +++ b/libc/nt/user32/SendMessageW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_SendMessageW,SendMessageW,2306 + + .text.windows +SendMessage: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_SendMessageW(%rip),%rax + jmp __sysv2nt + .endfn SendMessage,globl + .previous diff --git a/libc/nt/user32/SetCapture.s b/libc/nt/user32/SetCapture.s index c92c51f3..c71259f7 100644 --- a/libc/nt/user32/SetCapture.s +++ b/libc/nt/user32/SetCapture.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_SetCapture,SetCapture,2310 + + .text.windows +SetCapture: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_SetCapture(%rip) + leave + ret + .endfn SetCapture,globl + .previous diff --git a/libc/nt/user32/SetClassLongA.s b/libc/nt/user32/SetClassLongA.s index 306142f6..6df2f777 100644 --- a/libc/nt/user32/SetClassLongA.s +++ b/libc/nt/user32/SetClassLongA.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_SetClassLongA,SetClassLongA,2313 + + .text.windows +SetClassLongA: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_SetClassLongA(%rip),%rax + jmp __sysv2nt + .endfn SetClassLongA,globl + .previous diff --git a/libc/nt/user32/SetClassLongW.s b/libc/nt/user32/SetClassLongW.s index 0c6e0dde..03b598dd 100644 --- a/libc/nt/user32/SetClassLongW.s +++ b/libc/nt/user32/SetClassLongW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_SetClassLongW,SetClassLongW,2316 + + .text.windows +SetClassLong: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_SetClassLongW(%rip),%rax + jmp __sysv2nt + .endfn SetClassLong,globl + .previous diff --git a/libc/nt/user32/SetCursor.s b/libc/nt/user32/SetCursor.s index 2b9a20f3..0567766d 100644 --- a/libc/nt/user32/SetCursor.s +++ b/libc/nt/user32/SetCursor.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_SetCursor,SetCursor,2321 + + .text.windows +SetCursor: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_SetCursor(%rip) + leave + ret + .endfn SetCursor,globl + .previous diff --git a/libc/nt/user32/SetWindowPlacement.s b/libc/nt/user32/SetWindowPlacement.s index 648f9b5d..275ee2e7 100644 --- a/libc/nt/user32/SetWindowPlacement.s +++ b/libc/nt/user32/SetWindowPlacement.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_SetWindowPlacement,SetWindowPlacement,2399 + + .text.windows +SetWindowPlacement: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_SetWindowPlacement(%rip),%rax + jmp __sysv2nt + .endfn SetWindowPlacement,globl + .previous diff --git a/libc/nt/user32/TrackPopupMenu.s b/libc/nt/user32/TrackPopupMenu.s index f5e233a6..2f4b8827 100644 --- a/libc/nt/user32/TrackPopupMenu.s +++ b/libc/nt/user32/TrackPopupMenu.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp user32,__imp_TrackPopupMenu,TrackPopupMenu,2443 + + .text.windows +TrackPopupMenu: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_TrackPopupMenu(%rip),%rax + jmp __sysv2nt8 + .endfn TrackPopupMenu,globl + .previous diff --git a/libc/nt/windows.h b/libc/nt/windows.h index 2291e81a..64926aeb 100644 --- a/libc/nt/windows.h +++ b/libc/nt/windows.h @@ -1,9 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_NT_WINDOWS_H_ #define COSMOPOLITAN_LIBC_NT_WINDOWS_H_ #include "libc/nt/struct/rect.h" +#include "libc/nt/struct/windowplacement.h" #include "libc/nt/struct/wndclass.h" #include "libc/nt/typedef/timerproc.h" -#if 0 /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -28,7 +28,6 @@ ╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ │ cosmopolitan § new technology » windows ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -45,28 +44,53 @@ int64_t DefWindowProc(int64_t hWnd, uint32_t Msg, uint64_t wParam, int32_t CloseWindow(int64_t hWnd); int32_t DestroyWindow(int64_t hWnd); int32_t ShowWindow(int64_t hWnd, int sw); -int32_t ShowCursor(bool32 bShow); -int64_t LoadCursor(int64_t opt_hInstance, const char16_t *lpCursorNameOrIdc); int32_t ShowCaret(bool32 bShow); int32_t AnimateWindow(int64_t hWnd, uint32_t dwTime, uint32_t dwFlags); int64_t LoadIcon(int64_t hInstance, const char16_t *lpIconName); -int32_t IsWindow(int64_t hWnd); -int32_t IsMenu(int64_t hMenu); -int32_t IsChild(int64_t hWndParent, int64_t hWnd); int32_t MoveWindow(int64_t hWnd, int X, int Y, int nWidth, int nHeight, bool32 bRepaint); int32_t BringWindowToTop(int64_t hWnd); int32_t IsWindowVisible(int64_t hWnd); -int32_t IsZoomed(int64_t hWnd); int32_t SetWindowText(int64_t hWnd, const char16_t *lpString); int32_t GetWindowText(int64_t hWnd, char16_t *lpString, int nMaxCount); int32_t SetWindowPos(int64_t hWnd, int64_t hWndInsertAfter, int X, int Y, int cx, int cy, uint32_t uFlags); +bool32 GetWindowPlacement(int64_t hWnd, struct NtWindowPlacement *lpwndpl); +bool32 SetWindowPlacement(int64_t hWnd, + const struct NtWindowPlacement *lpwndpl); + +int64_t GetCursor(void); +int64_t SetCursor(int64_t hCursor); +int32_t ShowCursor(bool32 bShow); +int64_t LoadCursor(int64_t opt_hInstance, const char16_t *lpCursorNameOrIdc); + +bool32 IsWindow(int64_t hWnd); +bool32 IsMenu(int64_t hMenu); +bool32 IsChild(int64_t hWndParent, int64_t hWnd); +bool32 IsZoomed(int64_t hWnd); +bool32 IsIconic(int64_t hWnd); uintptr_t SetTimer(int64_t opt_hWnd, uintptr_t nIDEvent, uint32_t uElapseMs, NtTimerProc lpTimerFunc); int32_t KillTimer(int64_t hWnd, uintptr_t uIDEvent); +int64_t SetCapture(int64_t hWnd); +bool32 ReleaseCapture(void); +int16_t GetKeyState(int32_t nVirtKey); + +int64_t CreateMenu(void); +int64_t CreatePopupMenu(void); +int64_t GetMenu(int64_t hWnd); +bool32 DestroyMenu(int64_t hMenu); +int64_t GetSystemMenu(int64_t hWnd, bool32 bRevert); +bool32 AppendMenu(int64_t hMenu, uint32_t mfFlags, uintptr_t uIDNewItem, + const char16_t *lpNewItem); +bool32 InsertMenu(int64_t hMenu, uint32_t uPosition, uint32_t uFlags, + uintptr_t uIDNewItem, const char16_t *lpNewItem); +bool32 TrackPopupMenu(int64_t hMenu, uint32_t uFlags, int32_t x, int32_t y, + int32_t nReserved, int64_t hWnd, + const struct NtRect *prcRect); + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_WINDOWS_H_ */ diff --git a/libc/nt/winsock.h b/libc/nt/winsock.h index 1c749ff4..5a01ec07 100644 --- a/libc/nt/winsock.h +++ b/libc/nt/winsock.h @@ -4,7 +4,6 @@ #include "libc/nt/struct/overlapped.h" #include "libc/nt/struct/pollfd.h" #include "libc/sock/sock.h" -#if 0 /* ░▓█████████████████████████████████████████████▓▒ ░█▓░░░░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒░ ░█▓░ ░▒▒▒▒ ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒ @@ -43,7 +42,6 @@ ╔────────────────────────────────────────────────────────────────▀▀▀▀───▀▀▀▀─│─╗ │ cosmopolitan § new technology » winsock ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#endif #define kNtWsaFlagOverlapped 0x01 #define kNtWsaFlagNoHandleInherit 0x80 diff --git a/libc/ohmyplus/vector.h b/libc/ohmyplus/vector.h index dd791a83..f4255e93 100644 --- a/libc/ohmyplus/vector.h +++ b/libc/ohmyplus/vector.h @@ -1,24 +1,6 @@ -/*-*-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 │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef COSMOPOLITAN_LIBC_OHMYPLUS_VECTOR_H_ #define COSMOPOLITAN_LIBC_OHMYPLUS_VECTOR_H_ +#ifdef __cplusplus extern "C" { void __vector_reserve(size_t, size_t, intptr_t **, size_t *); } /* extern c */ @@ -27,17 +9,38 @@ namespace std { template class vector { public: - vector() : data_(NULL), size_(0), toto_(0) {} - vector(size_t n) : data_(NULL), size_(n), toto_(0) { VectorReserve(n); } - size_t size() const { return size_; } - size_t capacity() const { return toto_; } - T &front() { return data_[0]; } - T &back() { return data_[size_ - 1]; } - void clear() { size_ = 0; } - void reserve(size_t n) { VectorReserve(n); } - void resize(size_t n) { reserve((size_ = n)); } - bool empty() const { return !size_; } - T &operator[](size_t i) { return data_[i]; } + vector() : data_(NULL), size_(0), toto_(0) { + } + vector(size_t n) : data_(NULL), size_(n), toto_(0) { + VectorReserve(n); + } + size_t size() const { + return size_; + } + size_t capacity() const { + return toto_; + } + T &front() { + return data_[0]; + } + T &back() { + return data_[size_ - 1]; + } + void clear() { + size_ = 0; + } + void reserve(size_t n) { + VectorReserve(n); + } + void resize(size_t n) { + reserve((size_ = n)); + } + bool empty() const { + return !size_; + } + T &operator[](size_t i) { + return data_[i]; + } private: T *data_; @@ -49,4 +52,5 @@ class vector { }; }; /* namespace std */ +#endif /* __cplusplus */ #endif /* COSMOPOLITAN_LIBC_OHMYPLUS_VECTOR_H_ */ diff --git a/libc/pe.h b/libc/pe.h deleted file mode 100644 index 32c1f0f6..00000000 --- a/libc/pe.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_PE_H_ -#define COSMOPOLITAN_LIBC_PE_H_ -#ifndef __STRICT_ANSI__ -#include "libc/dce.h" -#include "libc/nt/pedef.h" -#include "libc/nt/struct/imagedosheader.h" -#include "libc/runtime/runtime.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -forceinline void *pecheckaddress(struct NtImageDosHeader *mz, size_t mzsize, - void *addr, uint32_t addrsize) { -#if !(TRUSTWORTHY + PE_TRUSTWORTHY + 0) - if ((intptr_t)addr < (intptr_t)mz || - (intptr_t)addr + addrsize > (intptr_t)mz + mzsize) { - abort(); - } -#endif - return addr; -} - -forceinline void *pecomputerva(struct NtImageDosHeader *mz, size_t mzsize, - uint32_t reladdr, uint32_t addrsize) { - return pecheckaddress(mz, mzsize, (void *)((intptr_t)mz + reladdr), addrsize); -} - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* !ANSI */ -#endif /* COSMOPOLITAN_LIBC_PE_H_ */ diff --git a/libc/rand/getrandom.c b/libc/rand/getrandom.c index 57ab998e..873b3820 100644 --- a/libc/rand/getrandom.c +++ b/libc/rand/getrandom.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/internal.h" #include "libc/errno.h" #include "libc/rand/rand.h" diff --git a/libc/rand/rand.h b/libc/rand/rand.h index ae1a8c3c..96293cd3 100644 --- a/libc/rand/rand.h +++ b/libc/rand/rand.h @@ -23,6 +23,7 @@ ssize_t getrandom(void *, size_t, unsigned); int devrand(void *, size_t); int64_t winrandish(void); uint64_t rdrand(void); +uint64_t rdseed(void); float randf(void); COSMOPOLITAN_C_END_ diff --git a/libc/rand/rdrand.c b/libc/rand/rdrand.c index f6ae4dda..5e259e3f 100644 --- a/libc/rand/rdrand.c +++ b/libc/rand/rdrand.c @@ -26,7 +26,7 @@ /** * Intel Secure Key Digital Random Number Generator * Introduced w/ Ivy Bridge c. 2013 and Excavator c. 2015 - * @see rand32(), rand64(), and randcpy() + * @see rdseed(), rand32(), rand64(), and randcpy() */ uint64_t rdrand(void) { char cf; diff --git a/libc/log/shadowargs.h b/libc/rand/rdseed.c similarity index 66% rename from libc/log/shadowargs.h rename to libc/rand/rdseed.c index 8bfbf28f..b72de7c0 100644 --- a/libc/log/shadowargs.h +++ b/libc/rand/rdseed.c @@ -1,5 +1,5 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ @@ -17,37 +17,31 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#ifndef COSMOPOLITAN_LIBC_SHADOWARGS_H_ -#define COSMOPOLITAN_LIBC_SHADOWARGS_H_ +#include "libc/assert.h" +#include "libc/bits/bits.h" +#include "libc/calls/calls.h" +#include "libc/nexgen32e/x86feature.h" +#include "libc/rand/rand.h" -#define SHADOWARGS_COUNT 32 -#define SHADOWARGS_SLOTS 8 -#define SHADOWARGS_MAXNAME 5 - -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct ShadowArgs { - union { - unsigned long slots[SHADOWARGS_SLOTS]; - struct { - void *addr; - void *frame; - unsigned long arg1; - unsigned long arg2; - unsigned long arg3; - unsigned long arg4; - unsigned long arg5; - unsigned long arg6; - }; - }; -}; - -hidden extern unsigned __shadowargs_index; -hidden extern struct ShadowArgs __shadowargs[SHADOWARGS_COUNT]; -hidden extern const char __shadowargs_slotnames[SHADOWARGS_SLOTS] - [SHADOWARGS_MAXNAME]; - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_SHADOWARGS_H_ */ +/** + * Intel Securer Key Digital Random Number Generator + * Introduced w/ Ivy Bridge c. 2013 and Excavator c. 2015 + * @see rdrand(), rand32(), rand64(), and randcpy() + */ +uint64_t rdseed(void) { + char cf; + size_t i; + uint64_t res; + assert(X86_HAVE(RDSEED)); + for (;;) { + for (i = 0; i < 10; ++i) { + /* CF=1: Destination register valid. Quoth Intel DRNG-SIG 4.1.3 */ + asm volatile(CFLAG_ASM("rdseed\t%1") + : CFLAG_CONSTRAINT(cf), "=r"(res) + : /* no inputs */ + : "cc"); + if (cf) return res; + } + asm volatile("rep nop"); /* unlikely 140 cycle spin */ + } +} diff --git a/libc/runtime/arch_prctl.c b/libc/runtime/arch_prctl.c index c7711bb6..60bcfc81 100644 --- a/libc/runtime/arch_prctl.c +++ b/libc/runtime/arch_prctl.c @@ -165,7 +165,7 @@ int arch_prctl(int code, int64_t addr) { if (g_fsgs_once == 2) { return arch_prctl$fsgsbase(code, addr); } - switch (hostos) { + switch (__hostos) { case METAL: return arch_prctl$msr(code, addr); case FREEBSD: diff --git a/libc/runtime/assertfail.c b/libc/runtime/assertfail.c index f31463f3..9d80931b 100644 --- a/libc/runtime/assertfail.c +++ b/libc/runtime/assertfail.c @@ -48,7 +48,7 @@ relegated void __assert_fail(const char *expr, const char *file, int line) { p = mempcpy(p, expr, exprlen); p = stpcpy(p, "\r\n"); write(STDERR_FILENO, msg, p - msg); - if (weaken(die)) weaken(die)(); + if (weaken(__die)) weaken(__die)(); } abort(); unreachable; diff --git a/libc/runtime/closesymboltable.c b/libc/runtime/closesymboltable.c index 56552edc..a3be5623 100644 --- a/libc/runtime/closesymboltable.c +++ b/libc/runtime/closesymboltable.c @@ -19,7 +19,8 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/runtime/ezmap.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/runtime.h" +#include "libc/runtime/symbols.internal.h" /** * Frees symbol table. @@ -32,7 +33,7 @@ int CloseSymbolTable(struct SymbolTable **table) { if (*table && *table != MAP_FAILED) { t = *table; *table = NULL; - rc |= unmapfile(&t->mf); + rc |= UnmapFile(&t->mf); rc |= munmap(t, t->scratch); } return rc; diff --git a/libc/runtime/defer.greg.c b/libc/runtime/defer.greg.c index 69a2b334..77f3bcac 100644 --- a/libc/runtime/defer.greg.c +++ b/libc/runtime/defer.greg.c @@ -17,12 +17,12 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/assert.h" #include "libc/bits/bits.h" #include "libc/calls/calls.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/gc.h" +#include "libc/nexgen32e/gc.internal.h" #include "libc/runtime/gc.h" #include "libc/runtime/runtime.h" @@ -53,10 +53,10 @@ void __defer(struct StackFrame *frame, void *fn, void *arg) { frame2 = __builtin_frame_address(0); assert(frame2->next == frame); assert(PointerNotOwnedByParentStackFrame(frame2, frame, arg)); - if (append(&g_garbage, + if (append(&__garbage, (&(const struct Garbage){frame->next, (intptr_t)fn, (intptr_t)arg, frame->addr})) != -1) { - atomic_store(&frame->addr, (intptr_t)&CollectGarbage); + atomic_store(&frame->addr, (intptr_t)&__gc); } else { abort(); } diff --git a/libc/runtime/ezmap.c b/libc/runtime/ezmap.c index d45d1d3a..e31aad86 100644 --- a/libc/runtime/ezmap.c +++ b/libc/runtime/ezmap.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/limits.h" #include "libc/runtime/ezmap.h" @@ -30,7 +30,7 @@ * Memory-maps file for reading. * An internal veneer for a common mmap() use-case. */ -int mapfileread(const char *filename, struct MappedFile *mf) { +int MapFileRead(const char *filename, struct MappedFile *mf) { mf->addr = MAP_FAILED; if ((mf->fd = open(filename, O_RDONLY)) != -1 && (mf->size = getfiledescriptorsize(mf->fd)) < INT_MAX && @@ -39,15 +39,15 @@ int mapfileread(const char *filename, struct MappedFile *mf) { : NULL) != MAP_FAILED) { return 0; } else { - unmapfile(mf); + UnmapFile(mf); return -1; } } /** - * Releases resource returned by mapfileread(). + * Releases resource returned by MapFileRead(). */ -int unmapfile(struct MappedFile *mf) { +int UnmapFile(struct MappedFile *mf) { int rc; rc = 0; if (mf->addr && mf->addr != MAP_FAILED) { diff --git a/libc/runtime/ezmap.h b/libc/runtime/ezmap.h index f39cfc7c..77a9757a 100644 --- a/libc/runtime/ezmap.h +++ b/libc/runtime/ezmap.h @@ -1,22 +1,3 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef COSMOPOLITAN_LIBC_EZMAP_H_ #define COSMOPOLITAN_LIBC_EZMAP_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) @@ -28,8 +9,8 @@ struct MappedFile { size_t size; }; -int mapfileread(const char *, struct MappedFile *) hidden; -int unmapfile(struct MappedFile *) hidden; +int MapFileRead(const char *, struct MappedFile *) hidden; +int UnmapFile(struct MappedFile *) hidden; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/runtime/finddebugbinary.c b/libc/runtime/finddebugbinary.c index d672c0f6..01677099 100644 --- a/libc/runtime/finddebugbinary.c +++ b/libc/runtime/finddebugbinary.c @@ -22,7 +22,7 @@ #include "libc/errno.h" #include "libc/macros.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" #include "libc/str/str.h" #include "libc/sysv/consts/auxv.h" diff --git a/libc/runtime/ftrace.greg.c b/libc/runtime/ftrace.greg.c index 769baef4..b0d7c853 100644 --- a/libc/runtime/ftrace.greg.c +++ b/libc/runtime/ftrace.greg.c @@ -17,9 +17,9 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/bisectcarleft.h" +#include "libc/alg/bisectcarleft.internal.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/struct/sigset.h" @@ -31,9 +31,9 @@ #include "libc/nt/runtime.h" #include "libc/nt/thunk/msabi.h" #include "libc/runtime/internal.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" +#include "libc/str/str.h" #include "libc/sysv/consts/fileno.h" #include "libc/sysv/consts/nr.h" #include "libc/sysv/consts/prot.h" @@ -71,7 +71,6 @@ privileged interruptfn void ftrace_hook(void) { size_t i, j, nesting; const char *symbol; struct StackFrame *frame; - LOAD_DEFAULT_RBX(); if (g_symbols) { frame = __builtin_frame_address(0); symbol = @@ -98,7 +97,6 @@ privileged interruptfn void ftrace_hook(void) { } g_lastsymbol = symbol; } - RESTORE_RBX(); } /** diff --git a/libc/runtime/getdosargv.c b/libc/runtime/getdosargv.c index f468dfba..9916b981 100644 --- a/libc/runtime/getdosargv.c +++ b/libc/runtime/getdosargv.c @@ -20,7 +20,7 @@ #include "libc/assert.h" #include "libc/bits/bits.h" #include "libc/bits/pushpop.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/runtime/internal.h" #include "libc/str/appendchar.h" #include "libc/str/str.h" diff --git a/libc/runtime/getdosenviron.h b/libc/runtime/getdosenviron.h deleted file mode 100644 index be84af80..00000000 --- a/libc/runtime/getdosenviron.h +++ /dev/null @@ -1,73 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#ifndef COSMOPOLITAN_LIBC_DOSENVIRON_H_ -#define COSMOPOLITAN_LIBC_DOSENVIRON_H_ -#ifndef __STRICT_ANSI__ -#include "libc/bits/safemacros.h" -#include "libc/str/appendchar.h" -#include "libc/str/str.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) - -/** - * Transcodes NT environment variable block from UTF-16 to UTF-8. - * - * @param env is a double NUL-terminated block of key=values - * @param buf is the new environment - * @param size is the byte capacity of buf - * @param envp stores NULL-terminated string pointer list - * @param max is the pointer count capacity of envp - * @return number of variables decoded, excluding NULL-terminator - */ -static inline int GetDosEnviron(const char16_t *env, char *buf, size_t size, - char **envp, size_t max) { - wint_t wc; - size_t envc; - char *p, *pe; - bool endstring; - const char16_t *s; - s = env; - envc = 0; - if (size) { - p = buf; - pe = buf + size - 1; - if (p < pe) { - wc = DecodeNtsUtf16(&s); - while (wc) { - if (++envc < max) { - envp[envc - 1] = p < pe ? p : NULL; - } - do { - AppendChar(&p, pe, wc); - endstring = !wc; - wc = DecodeNtsUtf16(&s); - } while (!endstring); - buf[min(p - buf, size - 2)] = u'\0'; - } - } - AppendChar(&p, pe, '\0'); - buf[min(p - buf, size - 1)] = u'\0'; - } - if (max) envp[min(envc, max - 1)] = NULL; - return envc; -} - -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* !ANSI */ -#endif /* COSMOPOLITAN_LIBC_DOSENVIRON_H_ */ diff --git a/libc/runtime/getdosenviron.internal.h b/libc/runtime/getdosenviron.internal.h new file mode 100644 index 00000000..c805efac --- /dev/null +++ b/libc/runtime/getdosenviron.internal.h @@ -0,0 +1,55 @@ +#ifndef COSMOPOLITAN_LIBC_DOSENVIRON_H_ +#define COSMOPOLITAN_LIBC_DOSENVIRON_H_ +#ifndef __STRICT_ANSI__ +#include "libc/bits/safemacros.internal.h" +#include "libc/str/appendchar.h" +#include "libc/str/str.h" +#include "libc/str/utf16.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +/** + * Transcodes NT environment variable block from UTF-16 to UTF-8. + * + * @param env is a double NUL-terminated block of key=values + * @param buf is the new environment + * @param size is the byte capacity of buf + * @param envp stores NULL-terminated string pointer list + * @param max is the pointer count capacity of envp + * @return number of variables decoded, excluding NULL-terminator + */ +static inline int GetDosEnviron(const char16_t *env, char *buf, size_t size, + char **envp, size_t max) { + wint_t wc; + size_t envc; + char *p, *pe; + bool endstring; + const char16_t *s; + s = env; + envc = 0; + if (size) { + p = buf; + pe = buf + size - 1; + if (p < pe) { + wc = DecodeNtsUtf16(&s); + while (wc) { + if (++envc < max) { + envp[envc - 1] = p < pe ? p : NULL; + } + do { + AppendChar(&p, pe, wc); + endstring = !wc; + wc = DecodeNtsUtf16(&s); + } while (!endstring); + buf[min(p - buf, size - 2)] = u'\0'; + } + } + AppendChar(&p, pe, '\0'); + buf[min(p - buf, size - 1)] = u'\0'; + } + if (max) envp[min(envc, max - 1)] = NULL; + return envc; +} + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* !ANSI */ +#endif /* COSMOPOLITAN_LIBC_DOSENVIRON_H_ */ diff --git a/libc/runtime/gothere.greg.c b/libc/runtime/gothere.greg.c index 30e1cbff..2a39f394 100644 --- a/libc/runtime/gothere.greg.c +++ b/libc/runtime/gothere.greg.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/itoa.h" -#include "libc/runtime/missioncritical.h" +#include "libc/runtime/runtime.h" /** * Debugs super low-level stuff, e.g. diff --git a/libc/runtime/grow.c b/libc/runtime/grow.c index 6f77227f..b0e7f921 100644 --- a/libc/runtime/grow.c +++ b/libc/runtime/grow.c @@ -56,7 +56,7 @@ * @note tiny programs might need to explicitly YOINK(realloc) * @see test/libc/runtime/grow_test.c */ -bool grow(void *pp, size_t *capacity, size_t itemsize, size_t extra) { +bool __grow(void *pp, size_t *capacity, size_t itemsize, size_t extra) { void **p, *p1, *p2; size_t n1, n2; /* item counts */ size_t t1, t2; /* byte counts */ diff --git a/libc/runtime/hook.greg.c b/libc/runtime/hook.greg.c index 03ce50c1..a2aeb995 100644 --- a/libc/runtime/hook.greg.c +++ b/libc/runtime/hook.greg.c @@ -22,7 +22,7 @@ #include "libc/calls/internal.h" #include "libc/calls/struct/sigset.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" #include "libc/sysv/consts/prot.h" /** diff --git a/libc/runtime/internal.h b/libc/runtime/internal.h index 24c7a81c..41a5b2c7 100644 --- a/libc/runtime/internal.h +++ b/libc/runtime/internal.h @@ -2,6 +2,8 @@ #define COSMOPOLITAN_LIBC_RUNTIME_INTERNAL_H_ #ifndef __STRICT_ANSI__ #include "libc/dce.h" +#include "libc/elf/struct/ehdr.h" +#include "libc/runtime/ezmap.h" #include "libc/runtime/runtime.h" #define STACK_CEIL 0x700000000000ul @@ -23,6 +25,7 @@ void __stack_chk_fail_local(void) noreturn relegated hidden; void _jmpstack(void *, void *, ...) hidden noreturn; long _setstack(void *, void *, ...) hidden; int GetDosArgv(const char16_t *, char *, size_t, char **, size_t) hidden; +Elf64_Ehdr *MapElfRead(const char *, struct MappedFile *) hidden; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/runtime/interruptiblecall.c b/libc/runtime/interruptiblecall.c index 76a09028..6a605b81 100644 --- a/libc/runtime/interruptiblecall.c +++ b/libc/runtime/interruptiblecall.c @@ -17,8 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/progn.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/interruptiblecall.h" #include "libc/runtime/runtime.h" diff --git a/libc/runtime/mapelfread.c b/libc/runtime/mapelfread.c index 0d40fb0e..27dff9e1 100644 --- a/libc/runtime/mapelfread.c +++ b/libc/runtime/mapelfread.c @@ -20,12 +20,13 @@ #include "libc/elf/def.h" #include "libc/elf/elf.h" #include "libc/runtime/ezmap.h" +#include "libc/runtime/internal.h" -Elf64_Ehdr *mapelfread(const char *filename, struct MappedFile *mf) { - if (mapfileread(filename, mf) != -1 && IsElf64Binary(mf->addr, mf->size)) { +Elf64_Ehdr *MapElfRead(const char *filename, struct MappedFile *mf) { + if (MapFileRead(filename, mf) != -1 && IsElf64Binary(mf->addr, mf->size)) { return mf->addr; } else { - unmapfile(mf); + UnmapFile(mf); return NULL; } } diff --git a/libc/runtime/missioncritical.h b/libc/runtime/missioncritical.h deleted file mode 100644 index 18ae3ae0..00000000 --- a/libc/runtime/missioncritical.h +++ /dev/null @@ -1,147 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTERNAL_MISSIONCRITICAL_H_ -#define COSMOPOLITAN_LIBC_INTERNAL_MISSIONCRITICAL_H_ -#ifndef __STRICT_ANSI__ -#include "libc/bits/bits.h" -#include "libc/calls/internal.h" -#include "libc/dce.h" -#include "libc/nexgen32e/nexgen32e.h" -#include "libc/nexgen32e/tinystrlen.h" -#include "libc/nt/console.h" -#include "libc/nt/enum/version.h" -#include "libc/nt/ntdll.h" -#include "libc/nt/runtime.h" -#include "libc/nt/struct/teb.h" -#include "libc/runtime/runtime.h" -#include "libc/sysv/consts/nr.h" -#include "libc/sysv/consts/sig.h" -#include "libc/sysv/errfuns.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) - -/** - * @fileoverview Mission critical system calls. - */ - -#define PRINT(STR) __print(STR, tinystrlen(STR)) - -#define NT_HAVE_IMPORT(SLOT) \ - ((void *)*SLOT && *SLOT != (void *)&missingno /* see libc/crt/crt.S */) - -#define _EXIT(rc) \ - ({ \ - int ExitAx; \ - asm volatile("syscall" \ - : "=a"(ExitAx) \ - : "0"(__NR_exit), "D"(rc) \ - : "rcx", "r11", "cc", "memory"); \ - ExitAx; \ - }) - -#define GETPID() \ - ({ \ - int Res; \ - asm("syscall" : "=a"(Res) : "0"(__NR_getpid) : "rcx", "r11", "cc"); \ - Res; \ - }) - -#define KILL(pid, sig) \ - ({ \ - int KillAx; \ - unsigned char Cf; \ - asm volatile(CFLAG_ASM("clc\n\t" \ - "syscall") \ - : CFLAG_CONSTRAINT(Cf), "=a"(KillAx) \ - : "1"(__NR_kill), "D"(pid), "S"(sig) \ - : "rcx", "r11", "cc", "memory"); \ - Cf ? -KillAx : KillAx; \ - }) - -#define RAISE(SIG) \ - ({ \ - int RaiseAx = -1; \ - int Sig = (SIG); \ - if (Sig == SIGTRAP) { \ - DebugBreak(); \ - } else if (!IsWindows()) { \ - RaiseAx = KILL(GETPID(), Sig); \ - } else { \ - switch (Sig) { \ - case SIGINT: \ - GenerateConsoleCtrlEvent(kNtCtrlCEvent, 0); \ - break; \ - case SIGHUP: \ - GenerateConsoleCtrlEvent(kNtCtrlCloseEvent, 0); \ - break; \ - case SIGQUIT: \ - GenerateConsoleCtrlEvent(kNtCtrlBreakEvent, 0); \ - break; \ - default: \ - for (;;) TerminateProcess(GetCurrentProcess(), 128 + Sig); \ - } \ - } \ - RaiseAx; \ - }) - -#define SCHED_YIELD() \ - ({ \ - int64_t SyAx; \ - if (!IsWindows()) { \ - asm volatile("syscall" \ - : "=a"(SyAx) \ - : "0"(__NR_sched_yield) \ - : "rcx", "r11", "cc", "memory"); \ - } else { \ - NtYieldExecution(); \ - } \ - 0; \ - }) - -#define WAIT4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE) \ - ({ \ - int64_t WaAx; \ - if (!IsWindows()) { \ - register void *Reg10 asm("r10") = (OPT_OUT_RUSAGE); \ - asm volatile("syscall" \ - : "=a"(WaAx) \ - : "0"(__NR_wait4), "D"(PID), "S"(OPT_OUT_WSTATUS), \ - "d"(OPTIONS), "r"(Reg10) \ - : "rcx", "r11", "cc", "memory"); \ - } else { \ - WaAx = wait4$nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \ - } \ - WaAx; \ - }) - -#if 0 -/** - * Exits on Windows the hard way. - */ -#endif -#define NT_TERMINATE_PROCESS() \ - do \ - if (NtGetVersion() < kNtVersionFuture) { \ - int64_t ax, cx; \ - do \ - asm volatile( \ - "syscall" /* hook THIS system call */ \ - : "=a"(ax), "=c"(cx) \ - : "0"(NtGetVersion() < kNtVersionWindows8 \ - ? 0x0029 \ - : NtGetVersion() < kNtVersionWindows81 \ - ? 0x002a \ - : NtGetVersion() < kNtVersionWindows10 ? 0x002b \ - : 0x002c), \ - "1"(-1L /* GetCurrentProcess() */), "d"(42) \ - : "r11", "cc", "memory"); \ - while (!ax); \ - } \ - while (0) - -void __print(const void *, size_t); -void __print_string(const char *); - -#define LOAD_DEFAULT_RBX() /* disabled for now b/c clang */ -#define RESTORE_RBX() /* disabled for now b/c clang */ - -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* !ANSI */ -#endif /* COSMOPOLITAN_LIBC_INTERNAL_MISSIONCRITICAL_H_ */ diff --git a/libc/runtime/mmap.c b/libc/runtime/mmap.c index e16c4c76..800d4f09 100644 --- a/libc/runtime/mmap.c +++ b/libc/runtime/mmap.c @@ -22,7 +22,7 @@ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/dce.h" -#include "libc/log/asan.h" +#include "libc/log/asan.internal.h" #include "libc/macros.h" #include "libc/rand/rand.h" #include "libc/runtime/directmap.h" diff --git a/libc/runtime/opensymboltable.c b/libc/runtime/opensymboltable.c index 9e2d3c81..9b7e1f96 100644 --- a/libc/runtime/opensymboltable.c +++ b/libc/runtime/opensymboltable.c @@ -22,8 +22,9 @@ #include "libc/elf/def.h" #include "libc/elf/elf.h" #include "libc/runtime/carsort.h" +#include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" @@ -38,15 +39,15 @@ struct SymbolTable *OpenSymbolTable(const char *filename) { const Elf64_Sym *symtab, *sym; t = MAP_FAILED; if (filename && (t = mapanon(BIGPAGESIZE)) != MAP_FAILED && - mapelfread(filename, &t->mf) && + MapElfRead(filename, &t->mf) && (t->name_base = GetElfStringTable(t->elf, t->elfsize)) != NULL && (symtab = GetElfSymbolTable(t->elf, t->elfsize, &t->count)) && sizeof(struct SymbolTable) + sizeof(struct Symbol) * t->count < (t->scratch = BIGPAGESIZE)) { - getelfvirtualaddressrange(t->elf, t->elfsize, &t->addr_base, &t->addr_end); + GetElfVirtualAddressRange(t->elf, t->elfsize, &t->addr_base, &t->addr_end); for (j = i = 0; i < t->count; ++i) { sym = &symtab[i]; - if (iselfsymbolcontent(sym) && + if (IsElfSymbolContent(sym) && (sym->st_value >= t->addr_base && sym->st_value <= t->addr_end)) { t->symbols[j].addr_rva = (unsigned)(sym->st_value - t->addr_base); t->symbols[j].name_rva = sym->st_name; diff --git a/libc/runtime/piro.c b/libc/runtime/piro.c index 1e3248af..475fca1b 100644 --- a/libc/runtime/piro.c +++ b/libc/runtime/piro.c @@ -33,7 +33,7 @@ ╠──────────────────────────────────────────────────────▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄─│ │ αcτµαlly pδrταblε εxεcµταblε § post-initialization read-only │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/runtime/internal.h" diff --git a/libc/runtime/print.greg.c b/libc/runtime/print.greg.c index fb29738e..8d5e51b9 100644 --- a/libc/runtime/print.greg.c +++ b/libc/runtime/print.greg.c @@ -21,12 +21,14 @@ #include "libc/dce.h" #include "libc/nt/files.h" #include "libc/nt/runtime.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/fileno.h" #include "libc/sysv/consts/nr.h" +#define WasImported(SLOT) \ + ((void *)*SLOT && *SLOT != (void *)&missingno /* see libc/crt/crt.S */) + static privileged void __print$nt(const void *data, size_t len) { int64_t hand; uint32_t wrote; @@ -47,11 +49,10 @@ static privileged void __print$nt(const void *data, size_t len) { * * @param len can be computed w/ tinystrlen() * @clob nothing except flags - * @see PRINT() */ privileged void __print(const void *data, size_t len) { int64_t ax, ordinal; - if (NT_HAVE_IMPORT(__imp_WriteFile)) { + if (WasImported(__imp_WriteFile)) { __print$nt(data, len); } else { ordinal = __NR_write > 0 ? __NR_write : IsXnu() ? 0x2000004 : 4; @@ -59,14 +60,13 @@ privileged void __print(const void *data, size_t len) { : "=a"(ax) : "0"(ordinal), "D"(STDERR_FILENO), "S"(data), "d"(len) : "rcx", "r11", "memory", "cc"); - if (ax == -1 && !hostos && !__NR_write) { + if (ax == -1 && !__hostos && !__NR_write) { asm volatile("syscall" : "=a"(ax) : "0"(ordinal), "D"(STDERR_FILENO), "S"(data), "d"(len) : "rcx", "r11", "memory", "cc"); } } - RESTORE_RBX(); } privileged void __print_string(const char *s) { diff --git a/libc/runtime/runtime.h b/libc/runtime/runtime.h index 5ccae782..d464b0ab 100644 --- a/libc/runtime/runtime.h +++ b/libc/runtime/runtime.h @@ -55,7 +55,6 @@ int putenv(char *) paramsnonnull(); int setenv(const char *, const char *, int) paramsnonnull(); int unsetenv(const char *); int clearenv(void); -void __fast_math(void); void fpreset(void); void savexmm(void *); void loadxmm(void *); @@ -68,6 +67,9 @@ void *mremap(void *, uint64_t, uint64_t, int32_t, void *); int munmap(void *, uint64_t); int mprotect(void *, uint64_t, int) privileged; int msync(void *, size_t, int); +void __print(const void *, size_t); +void __print_string(const char *); +void __fast_math(void); /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § runtime » optimizations ─╬─│┼ diff --git a/libc/runtime/stackchkfail.c b/libc/runtime/stackchkfail.c index 94a7b3eb..7971b486 100644 --- a/libc/runtime/stackchkfail.c +++ b/libc/runtime/stackchkfail.c @@ -17,12 +17,11 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "ape/config.h" -#include "libc/bits/bits.h" #include "libc/bits/pushpop.h" -#include "libc/nt/process.h" +#include "libc/nt/enum/version.h" +#include "libc/nt/runtime.h" +#include "libc/nt/struct/teb.h" #include "libc/runtime/internal.h" -#include "libc/runtime/missioncritical.h" #include "libc/sysv/consts/fileno.h" #include "libc/sysv/consts/nr.h" @@ -32,11 +31,13 @@ * Aborts program under enemy fire to avoid being taken alive. */ void __stack_chk_fail(void) { + size_t len; + const char *msg; + int64_t ax, cx, si; if (!IsWindows()) { - const char *const msg = STACK_SMASH_MESSAGE; - const size_t len = pushpop(sizeof(STACK_SMASH_MESSAGE) - 1); + msg = STACK_SMASH_MESSAGE; + len = pushpop(sizeof(STACK_SMASH_MESSAGE) - 1); if (!IsMetal()) { - unsigned ax; asm volatile("syscall" : "=a"(ax) : "0"(__NR_write), "D"(pushpop(STDERR_FILENO)), "S"(msg), @@ -44,18 +45,31 @@ void __stack_chk_fail(void) { : "rcx", "r11", "cc", "memory"); asm volatile("syscall" : "=a"(ax) - : "0"(__NR_exit), "D"(pushpop(88)) + : "0"(__NR_exit), "D"(pushpop(23)) : "rcx", "r11", "cc", "memory"); } - short(*ttys)[4] = (short(*)[4])XLM(BIOS_DATA_AREA); - unsigned long si; - unsigned cx; asm volatile("rep outsb" : "=S"(si), "=c"(cx) - : "0"(msg), "1"(len), "d"((*ttys)[1 /*COM2*/]) + : "0"(msg), "1"(len), "d"(0x3F8 /* COM1 */) : "memory"); triplf(); } - NT_TERMINATE_PROCESS(); - for (;;) TerminateProcess(GetCurrentProcess(), 42); + if (NtGetVersion() < kNtVersionFuture) { + do { + asm volatile( + "syscall" + : "=a"(ax), "=c"(cx) + : "0"(NtGetVersion() < kNtVersionWindows8 + ? 0x0029 + : NtGetVersion() < kNtVersionWindows81 + ? 0x002a + : NtGetVersion() < kNtVersionWindows10 ? 0x002b + : 0x002c), + "1"(pushpop(-1L)), "d"(42) + : "r11", "cc", "memory"); + } while (!ax); + } + for (;;) { + TerminateProcess(GetCurrentProcess(), 42); + } } diff --git a/libc/runtime/symbols.h b/libc/runtime/symbols.internal.h similarity index 100% rename from libc/runtime/symbols.h rename to libc/runtime/symbols.internal.h diff --git a/libc/runtime/unsetenv.c b/libc/runtime/unsetenv.c index 455e1c04..66e89d88 100644 --- a/libc/runtime/unsetenv.c +++ b/libc/runtime/unsetenv.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index 012837ac..fb722582 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -26,21 +26,21 @@ #include "libc/macros.h" #include "libc/nt/console.h" #include "libc/nt/enum/consolemodeflags.h" +#include "libc/nt/enum/filemapflags.h" #include "libc/nt/enum/filetype.h" #include "libc/nt/enum/loadlibrarysearch.h" #include "libc/nt/enum/pageflags.h" +#include "libc/nt/enum/version.h" #include "libc/nt/files.h" #include "libc/nt/memory.h" -#include "libc/nt/pedef.h" +#include "libc/nt/pedef.internal.h" #include "libc/nt/process.h" #include "libc/nt/runtime.h" #include "libc/nt/struct/teb.h" -#include "libc/runtime/getdosenviron.h" +#include "libc/runtime/getdosenviron.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/memtrack.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/winmain.h" #include "libc/sock/internal.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" @@ -62,8 +62,6 @@ static struct CmdExe { } oldin, oldout; } g_cmdexe; -struct WinMain g_winmain; - static textwindows void RestoreCmdExe(void) { if (g_cmdexe.oldin.handle) { SetConsoleCP(g_cmdexe.oldin.codepage); @@ -122,21 +120,15 @@ static textwindows char *AllocateMemory(void *addr, size_t size, int64_t *h) { kNtNumaNoPreferredNode); } -static textwindows noreturn void WinMainNew(int64_t hInstance, - int64_t hPrevInstance, - const char *lpCmdLine, - int nCmdShow) { +static textwindows noreturn void WinMainNew(void) { int64_t h; size_t size; int i, count; uint64_t data; struct WinArgs *wa; const char16_t *env16; - g_winmain.nCmdShow = nCmdShow; - g_winmain.hInstance = hInstance; - g_winmain.hPrevInstance = hPrevInstance; NormalizeCmdExe(); - *(/*unconst*/ int *)&hostos = WINDOWS; + *(/*unconst*/ int *)&__hostos = WINDOWS; size = ROUNDUP(STACKSIZE + sizeof(struct WinArgs), FRAMESIZE); data = 0x777000000000; data = (intptr_t)AllocateMemory((char *)data, size, &_mmi.p[0].h); @@ -191,11 +183,12 @@ static textwindows noreturn void WinMainNew(int64_t hInstance, * from having fork() so we pass pipe handles in an environment * variable literally copy all the memory. * + * @param hInstance call GetModuleHandle(NULL) from main if you need it */ textwindows int64_t WinMain(int64_t hInstance, int64_t hPrevInstance, const char *lpCmdLine, int nCmdShow) { SetDefaultDllDirectories(kNtLoadLibrarySearchSearchSystem32); if (weaken(winsockinit)) weaken(winsockinit)(); if (weaken(WinMainForked)) weaken(WinMainForked)(); - WinMainNew(hInstance, hPrevInstance, lpCmdLine, nCmdShow); + WinMainNew(); } diff --git a/libc/runtime/winmain.h b/libc/runtime/winmain.h deleted file mode 100644 index 7a65c779..00000000 --- a/libc/runtime/winmain.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_RUNTIME_WINMAIN_H_ -#define COSMOPOLITAN_LIBC_RUNTIME_WINMAIN_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct WinMain { - int nCmdShow; - int64_t hInstance; - int64_t hPrevInstance; -}; - -extern struct WinMain g_winmain; - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_RUNTIME_WINMAIN_H_ */ diff --git a/libc/sock/closesocket-nt.c b/libc/sock/closesocket-nt.c index 1d7297b3..eee70c8b 100644 --- a/libc/sock/closesocket-nt.c +++ b/libc/sock/closesocket-nt.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/internal.h" #include "libc/nt/winsock.h" #include "libc/sock/internal.h" diff --git a/libc/sock/internal.h b/libc/sock/internal.h index 7e767ec8..7d1f8682 100644 --- a/libc/sock/internal.h +++ b/libc/sock/internal.h @@ -1,22 +1,3 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_ #define COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_ #ifndef __STRICT_ANSI__ @@ -74,7 +55,6 @@ int32_t __socket$sysv(int32_t, int32_t, int32_t) hidden; int32_t __getsockname$sysv(int32_t, void *, uint32_t *) hidden; int32_t __getpeername$sysv(int32_t, void *, uint32_t *) hidden; -int32_t select$sysv(int32_t, fd_set *, fd_set *, fd_set *, struct timeval *); int32_t setsockopt$sysv(int32_t, int32_t, int32_t, const void *, uint32_t) hidden; int32_t accept4$sysv(int32_t, void *, uint32_t *, int) nodiscard hidden; diff --git a/libc/sock/ipclassify.h b/libc/sock/ipclassify.internal.h similarity index 100% rename from libc/sock/ipclassify.h rename to libc/sock/ipclassify.internal.h diff --git a/libc/sock/select.c b/libc/sock/select.c index 22e3c1c6..356cef9d 100644 --- a/libc/sock/select.c +++ b/libc/sock/select.c @@ -18,9 +18,12 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/timeval.h" -#include "libc/sock/internal.h" +#include "libc/sock/select.internal.h" #include "libc/sock/sock.h" +/** + * Does what poll() does except with a complicated bitset API. + */ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { /* TODO(jart): Windows */ diff --git a/libc/sock/select.h b/libc/sock/select.h new file mode 100644 index 00000000..b8a8eb38 --- /dev/null +++ b/libc/sock/select.h @@ -0,0 +1,24 @@ +#ifndef COSMOPOLITAN_LIBC_SOCK_SELECT_H_ +#define COSMOPOLITAN_LIBC_SOCK_SELECT_H_ +#include "libc/calls/struct/timeval.h" +#include "libc/str/str.h" + +#define FD_SETSIZE 1024 /* it's 64 on windows */ + +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +typedef struct fd_set { + uint64_t fds_bits[FD_SETSIZE / 64]; +} fd_set; + +#define FD_ISSET(FD, SET) (((SET)->fds_bits[(FD) >> 6] >> ((FD)&63)) & 1) +#define FD_SET(FD, SET) ((SET)->fds_bits[(FD) >> 6] |= 1ull << ((FD)&63)) +#define FD_CLR(FD, SET) ((SET)->fds_bits[(FD) >> 6] &= ~(1ull << ((FD)&63))) +#define FD_ZERO(SET) memset((SET)->fds_bits, 0, sizeof((SET)->fds_bits)) + +int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_SOCK_SELECT_H_ */ diff --git a/libc/sock/select.internal.h b/libc/sock/select.internal.h new file mode 100644 index 00000000..cdb61cae --- /dev/null +++ b/libc/sock/select.internal.h @@ -0,0 +1,11 @@ +#ifndef COSMOPOLITAN_LIBC_SOCK_SELECT_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_SOCK_SELECT_INTERNAL_H_ +#include "libc/sock/select.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int32_t select$sysv(int32_t, fd_set *, fd_set *, fd_set *, struct timeval *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_SOCK_SELECT_INTERNAL_H_ */ diff --git a/libc/sock/sendfile.c b/libc/sock/sendfile.c index a065bafd..0c3ca23c 100644 --- a/libc/sock/sendfile.c +++ b/libc/sock/sendfile.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/dce.h" diff --git a/libc/sock/sock.h b/libc/sock/sock.h index eaa62538..35decbd8 100644 --- a/libc/sock/sock.h +++ b/libc/sock/sock.h @@ -87,13 +87,6 @@ int ppoll(struct pollfd *, uint64_t, const struct timespec *, ssize_t sendto(int, const void *, size_t, uint32_t, const void *, uint32_t) paramsnonnull((2)); -typedef int64_t fd_set; -#define FD_CLR(FD, SET) btr(SET, FD) -#define FD_ISSET(FD, SET) bt(SET, FD) -#define FD_SET(FD, SET) bts(SET, FD) -#define FD_ZERO(SET) *(SET) = 0 -int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); - COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_SOCK_SOCK_H_ */ diff --git a/libc/sock/xinet_ntop.c b/libc/sock/xinet_ntop.c index 31f2a006..5a4b7cc7 100644 --- a/libc/sock/xinet_ntop.c +++ b/libc/sock/xinet_ntop.c @@ -35,7 +35,7 @@ char *xinet_ntop(int af, const void *src) { if (inet_ntop(af, src, ip, sizeof(ip)) && (res = strdup(ip))) { return res; } else { - if (weaken(die)) weaken(die)(); + if (weaken(__die)) weaken(__die)(); abort(); unreachable; } diff --git a/libc/stdio/fflush.c b/libc/stdio/fflush.c index 76d8a1c4..d8813906 100644 --- a/libc/stdio/fflush.c +++ b/libc/stdio/fflush.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/bits/bits.h" #include "libc/bits/pushpop.h" #include "libc/calls/calls.h" diff --git a/libc/stdio/fgetwc.c b/libc/stdio/fgetwc.c index 83652c5e..c9558859 100644 --- a/libc/stdio/fgetwc.c +++ b/libc/stdio/fgetwc.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/stdio/stdio.h" -#include "libc/str/tpdecodecb.h" +#include "libc/str/tpdecodecb.internal.h" /** * Reads UTF-8 character from stream. diff --git a/libc/stdio/fputwc.c b/libc/stdio/fputwc.c index 6d945b9d..5e6184c1 100644 --- a/libc/stdio/fputwc.c +++ b/libc/stdio/fputwc.c @@ -21,7 +21,7 @@ #include "libc/stdio/internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpencode.internal.h" /** * Writes wide character to stream. diff --git a/libc/stdio/freopen.c b/libc/stdio/freopen.c index 91be142c..0a598793 100644 --- a/libc/stdio/freopen.c +++ b/libc/stdio/freopen.c @@ -21,7 +21,9 @@ #include "libc/calls/internal.h" #include "libc/dce.h" #include "libc/errno.h" +#include "libc/nt/enum/accessmask.h" #include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/nt/files.h" #include "libc/nt/runtime.h" #include "libc/stdio/stdio.h" diff --git a/libc/stdio/getdelim.c b/libc/stdio/getdelim.c index 3479cbf9..63868e32 100644 --- a/libc/stdio/getdelim.c +++ b/libc/stdio/getdelim.c @@ -50,7 +50,7 @@ ssize_t getdelim(char **line, size_t *n, int delim, FILE *f) { if (feof(f) && i) rc = i; break; } - if (i + 2 >= *n && !grow(line, n, 1, 0)) { + if (i + 2 >= *n && !__grow(line, n, 1, 0)) { fseterrno(f); break; } diff --git a/libc/stdio/serialstdio.c b/libc/stdio/serialstdio.c index a2da9f84..a1bb536d 100644 --- a/libc/stdio/serialstdio.c +++ b/libc/stdio/serialstdio.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "ape/lib/pc.h" -#include "libc/nexgen32e/uart.h" +#include "libc/nexgen32e/uart.internal.h" #include "libc/stdio/internal.h" #include "libc/stdio/stdio.h" diff --git a/libc/stdio/stdio.h b/libc/stdio/stdio.h index 38cf1776..32e8058c 100644 --- a/libc/stdio/stdio.h +++ b/libc/stdio/stdio.h @@ -118,10 +118,6 @@ int __getc_moar(FILE *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § standard i/o » definitions for assembler fans ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - #define stdin SYMBOLIC(stdin) #define stdout SYMBOLIC(stdout) #define stderr SYMBOLIC(stderr) diff --git a/libc/stdio/system.c b/libc/stdio/system.c index 34bd4b3e..203267ab 100644 --- a/libc/stdio/system.c +++ b/libc/stdio/system.c @@ -22,7 +22,6 @@ #include "libc/calls/hefty/spawn.h" #include "libc/dce.h" #include "libc/paths.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/libc/str/appendchar.h b/libc/str/appendchar.h index 643fa7be..ce241815 100644 --- a/libc/str/appendchar.h +++ b/libc/str/appendchar.h @@ -3,7 +3,7 @@ #ifndef __STRICT_ANSI__ #include "libc/str/str.h" #include "libc/str/tpenc.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpencode.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) static inline void AppendChar(char **p, char *pe, wint_t wc) { diff --git a/libc/str/getcachesize.c b/libc/str/getcachesize.c index fd59aa30..0a3dc541 100644 --- a/libc/str/getcachesize.c +++ b/libc/str/getcachesize.c @@ -21,7 +21,7 @@ #include "libc/bits/bits.h" #include "libc/dce.h" #include "libc/nexgen32e/cachesize.h" -#include "libc/nexgen32e/cpuid4.h" +#include "libc/nexgen32e/cpuid4.internal.h" static unsigned getcachesize$cpuid4(int type, int level) { unsigned i, k; @@ -51,7 +51,7 @@ static unsigned getcachesize$cpuid4(int type, int level) { * @param level starts at 1 * @return size in bytes, or 0 if unknown */ -unsigned getcachesize(enum CpuCacheType type, int level) { +unsigned getcachesize(int type, int level) { assert(1 <= type && type <= 3); assert(level >= 1); return getcachesize$cpuid4(type, level); diff --git a/libc/str/getutf16.ncabi.c b/libc/str/getutf16.ncabi.c index 69b84753..7d8a0648 100644 --- a/libc/str/getutf16.ncabi.c +++ b/libc/str/getutf16.ncabi.c @@ -28,6 +28,7 @@ * @return number of bytes (NUL counts as 1) or -1 w/ errno * @note synchronization is performed to skip leading continuations; * canonicalization and validation are performed to some extent + * @todo delete */ forcealignargpointer unsigned(getutf16)(const char16_t *p, wint_t *wc) { unsigned skip = 0; diff --git a/libc/str/getx86processormodel.c b/libc/str/getx86processormodel.c index 5745e291..443de90d 100644 --- a/libc/str/getx86processormodel.c +++ b/libc/str/getx86processormodel.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/bisect.h" +#include "libc/alg/bisect.internal.h" #include "libc/nexgen32e/x86info.h" static int CmpX86ProcModelKey(const struct X86ProcessorModel *a, diff --git a/libc/str/internal.h b/libc/str/internal.h index df678062..e5bb2f4e 100644 --- a/libc/str/internal.h +++ b/libc/str/internal.h @@ -1,22 +1,3 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef COSMOPOLITAN_LIBC_STR_INTERNAL_H_ #define COSMOPOLITAN_LIBC_STR_INTERNAL_H_ #ifndef __STRICT_ANSI__ diff --git a/libc/str/mbtowc.c b/libc/str/mbtowc.c index 658c6005..c530b85e 100644 --- a/libc/str/mbtowc.c +++ b/libc/str/mbtowc.c @@ -20,7 +20,7 @@ #include "libc/limits.h" #include "libc/macros.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" compatfn int mbtowc(wchar_t *wc, const char *s, size_t n) { if (!s) return 0; diff --git a/libc/str/memset16.c b/libc/str/memset16.c index 9a86f4d4..8f806654 100644 --- a/libc/str/memset16.c +++ b/libc/str/memset16.c @@ -17,11 +17,11 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/bigword.h" +#include "libc/bits/bigword.internal.h" #include "libc/str/str.h" #define wmemset memset16 -#define T unsigned short -#define N (BIGWORD / sizeof(T)) +#define T unsigned short +#define N (BIGWORD / sizeof(T)) #include "libc/nexgen32e/wmemset.inc" #undef wmemset #undef T diff --git a/libc/str/oldutf16.internal.h b/libc/str/oldutf16.internal.h new file mode 100644 index 00000000..8f0224fc --- /dev/null +++ b/libc/str/oldutf16.internal.h @@ -0,0 +1,47 @@ +#ifndef COSMOPOLITAN_LIBC_STR_OLDUTF16_H_ +#define COSMOPOLITAN_LIBC_STR_OLDUTF16_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +unsigned getutf16(const char16_t *, wint_t *); +int pututf16(char16_t *, size_t, wint_t, bool); + +#define pututf16(BUF, SIZE, CH, AWESOME) __pututf16(BUF, SIZE, CH, AWESOME) +#define getutf16(BUF, CHPTR) __getutf16(BUF, CHPTR) + +forceinline int __pututf16(char16_t *s, size_t size, wint_t wc, + bool32 awesome) { + if (size >= 1 && (0x00 <= wc && wc <= 0xD7FF)) { + if (wc >= 32 || !awesome) { + s[0] = (char16_t)wc; + return 1; + } else if (size >= 2) { + s[0] = 0xd800; + s[1] = 0xdc00 | (char16_t)wc; + return 2; + } + } + int ax; + asm("call\tpututf16" + : "=a"(ax), "=m"(*(char(*)[size])s) + : "D"(s), "S"(size), "d"(wc) + : "cc"); + return ax; +} + +forceinline unsigned __getutf16(const char16_t *s, wint_t *wc) { + if ((0x00 <= s[0] && s[0] <= 0xD7FF)) { + *wc = s[0]; + return 1; + } + unsigned ax; + asm("call\tgetutf16" + : "=a"(ax), "=m"(*wc) + : "D"(s), "S"(wc), "m"(*s), "m"(*(char(*)[4])s) + : "cc"); + return ax; +} + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_STR_OLDUTF16_H_ */ diff --git a/libc/str/pututf16.ncabi.c b/libc/str/pututf16.ncabi.c index 9bcbe1e7..fe3bee7c 100644 --- a/libc/str/pututf16.ncabi.c +++ b/libc/str/pututf16.ncabi.c @@ -17,6 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" /** @@ -30,6 +31,7 @@ * @param size is the number of shorts available in s * @param awesome enables numbers the IETF unilaterally banned * @return number of shorts written or -1 w/ errno + * @todo delete */ int(pututf16)(char16_t *s, size_t size, wint_t wc, bool awesome) { wint_t wc2; diff --git a/libc/str/sha256.c b/libc/str/sha256.c index 37cdf1c6..d903b451 100644 --- a/libc/str/sha256.c +++ b/libc/str/sha256.c @@ -11,11 +11,11 @@ * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf This implementation uses little endian byte order. *********************************************************************/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/dce.h" #include "libc/nexgen32e/x86feature.h" #include "libc/str/internal.h" -#include "libc/str/str.h" +#include "libc/str/sha256.h" #define ROTLEFT(a, b) (((a) << (b)) | ((a) >> (32 - (b)))) #define ROTRIGHT(a, b) (((a) >> (b)) | ((a) << (32 - (b)))) diff --git a/libc/str/sha256.h b/libc/str/sha256.h new file mode 100644 index 00000000..3c473338 --- /dev/null +++ b/libc/str/sha256.h @@ -0,0 +1,22 @@ +#ifndef COSMOPOLITAN_LIBC_STR_SHA256_H_ +#define COSMOPOLITAN_LIBC_STR_SHA256_H_ + +#define SHA256_BLOCK_SIZE 32 + +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +struct Sha256Ctx { + uint8_t data[64]; + uint32_t datalen; + uint64_t bitlen; + uint32_t state[8]; +}; + +void sha256_init(struct Sha256Ctx *); +void sha256_update(struct Sha256Ctx *, const uint8_t *, size_t); +void sha256_final(struct Sha256Ctx *, uint8_t *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_STR_SHA256_H_ */ diff --git a/libc/str/str.h b/libc/str/str.h index 5d87cb0c..f3ea0770 100644 --- a/libc/str/str.h +++ b/libc/str/str.h @@ -62,9 +62,6 @@ int cescapec(int); #define INVALID_CODEPOINT 0xfffd -wint_t DecodeNtsUtf16(const char16_t **); -unsigned getutf16(const char16_t *, wint_t *); -int pututf16(char16_t *, size_t, wint_t, bool); int iswalnum(wint_t); int iswalpha(wint_t); int iswblank(wint_t); @@ -183,6 +180,7 @@ compatfn wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque; char *tinystrstr(const char *, const char *) strlenesque; char16_t *tinystrstr16(const char16_t *, const char16_t *) strlenesque; void *tinymemmem(const void *, size_t, const void *, size_t) strlenesque; +void *tinymemccpy(void *, const void *, int, size_t) memcpyesque; void *memtolower(void *, size_t); char *strntolower(char *, size_t); @@ -231,25 +229,6 @@ typedef unsigned wctype_t; wctype_t wctype(const char *) strlenesque; int iswctype(wint_t, wctype_t) pureconst; -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § strings » hashing ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -#define SHA256_BLOCK_SIZE 32 - -struct Sha256Ctx { - uint8_t data[64]; - uint32_t datalen; - uint64_t bitlen; - uint32_t state[8]; -}; - -void sha256_init(struct Sha256Ctx *); -void sha256_update(struct Sha256Ctx *, const uint8_t *, size_t); -void sha256_final(struct Sha256Ctx *, uint8_t *); - -bool luhn(const char *); - /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § strings » system ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ @@ -264,9 +243,8 @@ char *strsignal(int) returnsnonnull libcesque; extern int (*const __memcmp)(const void *, const void *, size_t); #define memcmp(a, b, n) __memcmp(a, b, n) -/* gcc -Werror=stringop-truncation misunderstands strncpy() api */ char *_strncpy(char *, const char *, size_t) asm("strncpy") memcpyesque; -#define strncpy(DEST, SRC, N) _strncpy(DEST, SRC, N) +#define strncpy(DEST, SRC, N) _strncpy(DEST, SRC, N) /* pacify bad warning */ #define explicit_bzero(STR, BYTES) \ do { \ @@ -378,44 +356,9 @@ char *_strncpy(char *, const char *, size_t) asm("strncpy") memcpyesque; #endif /* hosted/sse2/unbloat */ -#define pututf16(BUF, SIZE, CH, AWESOME) __pututf16(BUF, SIZE, CH, AWESOME) -#define getutf16(BUF, CHPTR) __getutf16(BUF, CHPTR) size_t _strlen(const char *s) asm("strlen") strlenesque; void *_memchr(const void *, int, size_t) asm("memchr") strlenesque; -forceinline int __pututf16(char16_t *s, size_t size, wint_t wc, - bool32 awesome) { - if (size >= 1 && (0x00 <= wc && wc <= 0xD7FF)) { - if (wc >= 32 || !awesome) { - s[0] = (char16_t)wc; - return 1; - } else if (size >= 2) { - s[0] = 0xd800; - s[1] = 0xdc00 | (char16_t)wc; - return 2; - } - } - int ax; - asm("call\tpututf16" - : "=a"(ax), "=m"(*(char(*)[size])s) - : "D"(s), "S"(size), "d"(wc) - : "cc"); - return ax; -} - -forceinline unsigned __getutf16(const char16_t *s, wint_t *wc) { - if ((0x00 <= s[0] && s[0] <= 0xD7FF)) { - *wc = s[0]; - return 1; - } - unsigned ax; - asm("call\tgetutf16" - : "=a"(ax), "=m"(*wc) - : "D"(s), "S"(wc), "m"(*s), "m"(*(char(*)[4])s) - : "cc"); - return ax; -} - #endif /* __GNUC__ && !__STRICT_ANSI__ */ COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/str/strcasecmp8to16.c b/libc/str/strcasecmp8to16.c index da18b109..40ec12e3 100644 --- a/libc/str/strcasecmp8to16.c +++ b/libc/str/strcasecmp8to16.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/internal.h" -#include "libc/str/strcmp8to16i.h" +#include "libc/str/strcmp8to16i.internal.h" /** * Compares UTF-8 and UTF-16 strings, ignoring case. diff --git a/libc/str/strcmp8to16.c b/libc/str/strcmp8to16.c index 566798f3..ef7646e4 100644 --- a/libc/str/strcmp8to16.c +++ b/libc/str/strcmp8to16.c @@ -18,9 +18,11 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/internal.h" -#include "libc/str/strcmp8to16i.h" +#include "libc/str/strcmp8to16i.internal.h" -forceinline unsigned identity32u(unsigned x) { return x; } +forceinline unsigned identity32u(unsigned x) { + return x; +} /** * Compares UTF-8 and UTF-16 strings. diff --git a/libc/str/strcmp8to16i.h b/libc/str/strcmp8to16i.internal.h similarity index 89% rename from libc/str/strcmp8to16i.h rename to libc/str/strcmp8to16i.internal.h index 3f158fc8..c202c58a 100644 --- a/libc/str/strcmp8to16i.h +++ b/libc/str/strcmp8to16i.internal.h @@ -1,8 +1,9 @@ #ifndef COSMOPOLITAN_LIBC_STR_STRCMP8TO16I_H_ #define COSMOPOLITAN_LIBC_STR_STRCMP8TO16I_H_ #include "libc/conv/conv.h" +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/libc/str/strcspn.c b/libc/str/strcspn.c index 322f700f..de664a88 100644 --- a/libc/str/strcspn.c +++ b/libc/str/strcspn.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" /** diff --git a/libc/str/strcspn16.c b/libc/str/strcspn16.c index 56b25e9e..9d28ee32 100644 --- a/libc/str/strcspn16.c +++ b/libc/str/strcspn16.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" /** diff --git a/libc/str/strlcat.c b/libc/str/strlcat.c index 4e8fd972..6eef2671 100644 --- a/libc/str/strlcat.c +++ b/libc/str/strlcat.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/str/str.h" /** diff --git a/libc/str/strlcpy.c b/libc/str/strlcpy.c index fd006389..fcbef23e 100644 --- a/libc/str/strlcpy.c +++ b/libc/str/strlcpy.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/str/str.h" /** diff --git a/libc/str/strncasecmp8to16.c b/libc/str/strncasecmp8to16.c index ed390902..848be057 100644 --- a/libc/str/strncasecmp8to16.c +++ b/libc/str/strncasecmp8to16.c @@ -17,14 +17,15 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/assert.h" #include "libc/str/internal.h" -#include "libc/str/strcmp8to16i.h" +#include "libc/str/strcmp8to16i.internal.h" /** * Compares UTF-8 and UTF-16 strings, ignoring case, with limit. */ int strncasecmp8to16(const char *s1, const char16_t *s2, size_t n) { - assume(n != -1ul); + assert(n != -1ul); return strcmp8to16i(s1, s2, n, towlower); } diff --git a/libc/str/strncmp8to16.c b/libc/str/strncmp8to16.c index 879d74c2..11a365e2 100644 --- a/libc/str/strncmp8to16.c +++ b/libc/str/strncmp8to16.c @@ -17,16 +17,19 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/assert.h" #include "libc/str/internal.h" -#include "libc/str/strcmp8to16i.h" +#include "libc/str/strcmp8to16i.internal.h" -forceinline unsigned identity32u(unsigned x) { return x; } +forceinline unsigned identity32u(unsigned x) { + return x; +} /** * Compares UTF-8 and UTF-16 strings, with limit. */ int strncmp8to16(const char *s1, const char16_t *s2, size_t n) { - assume(n != -1ul); + assert(n != -1ul); return strcmp8to16i(s1, s2, n, identity32u); } diff --git a/libc/str/strpbrk.c b/libc/str/strpbrk.c index fbb78dc3..690abf92 100644 --- a/libc/str/strpbrk.c +++ b/libc/str/strpbrk.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" /** diff --git a/libc/str/strpbrk16.c b/libc/str/strpbrk16.c index 19bf75ef..8e56fee9 100644 --- a/libc/str/strpbrk16.c +++ b/libc/str/strpbrk16.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" #undef strpbrk diff --git a/libc/str/strspn.c b/libc/str/strspn.c index 0889a50d..7a13deaf 100644 --- a/libc/str/strspn.c +++ b/libc/str/strspn.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" /** diff --git a/libc/str/strspn16.c b/libc/str/strspn16.c index 538ef2ee..b3649efa 100644 --- a/libc/str/strspn16.c +++ b/libc/str/strspn16.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" #undef strspn diff --git a/libc/str/tinymemccpy.c b/libc/str/tinymemccpy.c index 1992bfa4..2f73ada9 100644 --- a/libc/str/tinymemccpy.c +++ b/libc/str/tinymemccpy.c @@ -18,7 +18,6 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" -#include "libc/str/tinymemccpy.h" void *tinymemccpy(void *dst, const void *src, int termchar, size_t limit) { size_t i; diff --git a/libc/str/tinymemccpy.h b/libc/str/tinymemccpy.h deleted file mode 100644 index 97144837..00000000 --- a/libc/str/tinymemccpy.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_STR_TINYMEMCCPY_H_ -#define COSMOPOLITAN_LIBC_STR_TINYMEMCCPY_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void *tinymemccpy(void *, const void *, int, size_t); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_STR_TINYMEMCCPY_H_ */ diff --git a/libc/str/tinymemmem.c b/libc/str/tinymemmem.c index 4fb74ecd..a4b7303b 100644 --- a/libc/str/tinymemmem.c +++ b/libc/str/tinymemmem.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" -#include "libc/str/tinymemmem.h" +#include "libc/str/tinymemmem.internal.h" /** * Naïve substring search implementation. diff --git a/libc/str/tinymemmem.h b/libc/str/tinymemmem.internal.h similarity index 100% rename from libc/str/tinymemmem.h rename to libc/str/tinymemmem.internal.h diff --git a/libc/str/tinystrstr.c b/libc/str/tinystrstr.c index ea36afe3..6947242b 100644 --- a/libc/str/tinystrstr.c +++ b/libc/str/tinystrstr.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/internal.h" -#include "libc/str/tinystrstr.h" +#include "libc/str/tinystrstr.internal.h" /** * Naïve substring search implementation. diff --git a/libc/str/tinystrstr.h b/libc/str/tinystrstr.internal.h similarity index 100% rename from libc/str/tinystrstr.h rename to libc/str/tinystrstr.internal.h diff --git a/libc/str/tinystrstr16.c b/libc/str/tinystrstr16.c index ba34770d..40997f1f 100644 --- a/libc/str/tinystrstr16.c +++ b/libc/str/tinystrstr16.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/internal.h" -#include "libc/str/tinystrstr.h" +#include "libc/str/tinystrstr.internal.h" /** * Naïve substring search implementation. diff --git a/libc/str/tpdecode.h b/libc/str/tpdecode.internal.h similarity index 100% rename from libc/str/tpdecode.h rename to libc/str/tpdecode.internal.h diff --git a/libc/str/tpdecode.ncabi.c b/libc/str/tpdecode.ncabi.c index ea8fd7df..b3133a23 100644 --- a/libc/str/tpdecode.ncabi.c +++ b/libc/str/tpdecode.ncabi.c @@ -19,8 +19,8 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" -#include "libc/str/tpdecodecb.h" +#include "libc/str/tpdecode.internal.h" +#include "libc/str/tpdecodecb.internal.h" forceinline int getbyte(void *arg, uint32_t i) { return ((const unsigned char *)arg)[i]; @@ -32,7 +32,7 @@ forceinline int getbyte(void *arg, uint32_t i) { * @param s is a NUL-terminated string * @return number of bytes successfully consumed or -1 w/ errno * @note synchronization is performed - * @see libc/str/tpdecodecb.h (for implementation) + * @see libc/str/tpdecodecb.internal.h (for implementation) */ int(tpdecode)(const char *s, wint_t *out) { return tpdecodecb(out, (unsigned char)s[0], getbyte, (void *)s); diff --git a/libc/str/tpdecodecb.h b/libc/str/tpdecodecb.h deleted file mode 100644 index c7098d17..00000000 --- a/libc/str/tpdecodecb.h +++ /dev/null @@ -1,56 +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 │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#ifndef COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ -#define COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ -#include "libc/nexgen32e/bsr.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) - -/** - * Generic Thompson-Pike Varint Decoder. - * @return number of bytes successfully consumed or -1 w/ errno - * @note synchronization is performed - */ -forceinline int tpdecodecb(wint_t *out, int first, - int get(void *arg, uint32_t i), void *arg) { - uint32_t wc, cb, need, msb, j, i = 1; - if (unlikely((wc = first) == -1)) return -1; - while (unlikely((wc & 0b11000000) == 0b10000000)) { - if ((wc = get(arg, i++)) == -1) return -1; - } - if (unlikely(!(0 <= wc && wc <= 0x7F))) { - msb = wc < 252 ? bsr(~wc & 0xff) : 1; - need = 7 - msb; - wc &= ((1u << msb) - 1) | 0b00000011; - for (j = 1; j < need; ++j) { - if ((cb = get(arg, i++)) == -1) return -1; - if ((cb & 0b11000000) == 0b10000000) { - wc = wc << 6 | (cb & 0b00111111); - } else { - if (out) *out = u'�'; - return -1; - } - } - } - if (likely(out)) *out = (wint_t)wc; - return i; -} - -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ */ diff --git a/libc/str/tpdecodecb.internal.h b/libc/str/tpdecodecb.internal.h new file mode 100644 index 00000000..97208ee9 --- /dev/null +++ b/libc/str/tpdecodecb.internal.h @@ -0,0 +1,38 @@ +#ifndef COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ +#define COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ +#include "libc/nexgen32e/bsr.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +/** + * Generic Thompson-Pike Varint Decoder. + * @return number of bytes successfully consumed or -1 w/ errno + * @note synchronization is performed + * @todo delete + */ +forceinline int tpdecodecb(wint_t *out, int first, + int get(void *arg, uint32_t i), void *arg) { + uint32_t wc, cb, need, msb, j, i = 1; + if (unlikely((wc = first) == -1)) return -1; + while (unlikely((wc & 0b11000000) == 0b10000000)) { + if ((wc = get(arg, i++)) == -1) return -1; + } + if (unlikely(!(0 <= wc && wc <= 0x7F))) { + msb = wc < 252 ? bsr(~wc & 0xff) : 1; + need = 7 - msb; + wc &= ((1u << msb) - 1) | 0b00000011; + for (j = 1; j < need; ++j) { + if ((cb = get(arg, i++)) == -1) return -1; + if ((cb & 0b11000000) == 0b10000000) { + wc = wc << 6 | (cb & 0b00111111); + } else { + if (out) *out = u'�'; + return -1; + } + } + } + if (likely(out)) *out = (wint_t)wc; + return i; +} + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_STR_TPDECODECB_H_ */ diff --git a/libc/str/tpencode.h b/libc/str/tpencode.internal.h similarity index 100% rename from libc/str/tpencode.h rename to libc/str/tpencode.internal.h diff --git a/libc/str/tpencode.ncabi.c b/libc/str/tpencode.ncabi.c index 30a7772a..53acadb7 100644 --- a/libc/str/tpencode.ncabi.c +++ b/libc/str/tpencode.ncabi.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/internal.h" #include "libc/str/tpenc.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpencode.internal.h" /** * Thompson-Pike Varint Encoder. diff --git a/libc/str/utf16.h b/libc/str/utf16.h index ab7beba5..d6516a9c 100644 --- a/libc/str/utf16.h +++ b/libc/str/utf16.h @@ -5,6 +5,9 @@ #define UTF16_MOAR 0xd800 /* 0xD800..0xDBFF */ #define UTF16_CONT 0xdc00 /* 0xDC00..0xDBFF */ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + #define IsUcs2(wc) (((wc)&UTF16_MASK) != UTF16_MOAR) #define IsUtf16Cont(wc) (((wc)&UTF16_MASK) == UTF16_CONT) #define MergeUtf16(lo, hi) ((((lo)-0xD800) << 10) + ((hi)-0xDC00) + 0x10000) @@ -17,4 +20,8 @@ ((((wc)-0x10000) & 1023) + 0xDC00) << 16) \ : 0xFFFD) +wint_t DecodeNtsUtf16(const char16_t **); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_STR_UTF16_H_ */ diff --git a/libc/str/wcrtomb.c b/libc/str/wcrtomb.c index 733bb503..8b6238d6 100644 --- a/libc/str/wcrtomb.c +++ b/libc/str/wcrtomb.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/limits.h" #include "libc/str/str.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpencode.internal.h" size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) { if (!s) return 1; diff --git a/libc/str/wcscspn.c b/libc/str/wcscspn.c index 351e414c..dd62a0f4 100644 --- a/libc/str/wcscspn.c +++ b/libc/str/wcscspn.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" /** diff --git a/libc/str/wcspbrk.c b/libc/str/wcspbrk.c index 1a1a7676..540b435c 100644 --- a/libc/str/wcspbrk.c +++ b/libc/str/wcspbrk.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" #undef strpbrk diff --git a/libc/str/wcsrtombs.c b/libc/str/wcsrtombs.c index fc17c9f0..251ad054 100644 --- a/libc/str/wcsrtombs.c +++ b/libc/str/wcsrtombs.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/conv.h" #include "libc/str/str.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpencode.internal.h" size_t wcsrtombs(char *dest, const wchar_t **src, size_t len, mbstate_t *ps) { /* TODO(jart): broken */ diff --git a/libc/str/wcsspn.c b/libc/str/wcsspn.c index 9381a9ae..967b66bb 100644 --- a/libc/str/wcsspn.c +++ b/libc/str/wcsspn.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/hascharacter.h" +#include "libc/nexgen32e/hascharacter.internal.h" #include "libc/str/str.h" #undef strspn diff --git a/libc/str/wctomb.c b/libc/str/wctomb.c index d46d6a43..56884814 100644 --- a/libc/str/wctomb.c +++ b/libc/str/wctomb.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/limits.h" #include "libc/str/str.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpencode.internal.h" int wctomb(char *s, wchar_t wc) { if (!s) return 0; diff --git a/libc/str/wmemset.c b/libc/str/wmemset.c index 8c8c822b..bef9a03a 100644 --- a/libc/str/wmemset.c +++ b/libc/str/wmemset.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/bigword.h" +#include "libc/bits/bigword.internal.h" #include "libc/str/str.h" #define T wchar_t #define N (BIGWORD / sizeof(T)) diff --git a/libc/sysv/g_syscount.S b/libc/sysv/g_syscount.S index b4d1b331..38aab9ed 100644 --- a/libc/sysv/g_syscount.S +++ b/libc/sysv/g_syscount.S @@ -46,8 +46,8 @@ syscount: .previous .init.start 701,_init_g_syscount - mov systemfive(%rip),%rax + mov __systemfive(%rip),%rax stosq ezlea syscount,ax - mov %rax,systemfive(%rip) + mov %rax,__systemfive(%rip) .init.end 701,_init_g_syscount diff --git a/libc/sysv/macros.h b/libc/sysv/macros.h index c9792b43..789ff0f4 100644 --- a/libc/sysv/macros.h +++ b/libc/sysv/macros.h @@ -1,22 +1,3 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef COSMOPOLITAN_LIBC_SYSV_MACROS_H_ #define COSMOPOLITAN_LIBC_SYSV_MACROS_H_ #ifdef __ASSEMBLER__ @@ -38,13 +19,13 @@ .ifnb \kw2 .align 16 \name: movabs $\num,%rax - jmp *systemfive(%rip) + jmp *__systemfive(%rip) .else \name: push %rbp mov %rsp,%rbp movabs $\num,%rax .hookable - call *systemfive(%rip) + call *__systemfive(%rip) pop %rbp ret .endif diff --git a/libc/sysv/syscall.S b/libc/sysv/syscall.S index 0a60b846..c80245ea 100644 --- a/libc/sysv/syscall.S +++ b/libc/sysv/syscall.S @@ -40,5 +40,5 @@ syscall:mov %rdi,%rax mov %r8,%rcx # ← intended mov %r9,%r8 mov 8(%rsp),%r9 - jmp *systemfive(%rip) + jmp *__systemfive(%rip) .endfn syscall,globl diff --git a/libc/sysv/systemfive.S b/libc/sysv/systemfive.S index e7a28a8f..27aeae14 100644 --- a/libc/sysv/systemfive.S +++ b/libc/sysv/systemfive.S @@ -84,11 +84,12 @@ / @clob %rcx,%r10,%r11 / @see syscalls.sh .initbss 300,_init_systemfive -hostos: .quad 0 - .endobj hostos,globl,hidden -systemfive: +__hostos: .quad 0 - .endobj systemfive,globl,hidden + .endobj __hostos,globl,hidden +__systemfive: + .quad 0 + .endobj __systemfive,globl,hidden .previous .Lanchorpoint: systemfive.linux: @@ -211,10 +212,10 @@ systemfive.init.xnu: systemfive.init.os: ezlea .Lanchorpoint,cx pop %rax - stosq #→ hostos + stosq #→ __hostos pop %rax add %rcx,%rax - stosq #→ systemfive + stosq #→ __systemfive push %rdi ezlea syscon.start,di ezlea syscon.end,bx diff --git a/libc/testlib/benchrunner.c b/libc/testlib/benchrunner.c index 201b945a..6604b0c6 100644 --- a/libc/testlib/benchrunner.c +++ b/libc/testlib/benchrunner.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/kntprioritycombos.h" +#include "libc/calls/kntprioritycombos.internal.h" #include "libc/log/log.h" #include "libc/nexgen32e/x86feature.h" #include "libc/runtime/runtime.h" diff --git a/libc/testlib/comborunner.c b/libc/testlib/comborunner.c index 59f919e4..4cbae97e 100644 --- a/libc/testlib/comborunner.c +++ b/libc/testlib/comborunner.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/fmt/fmt.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/libc/testlib/formatstr.c b/libc/testlib/formatstr.c index a766699f..9327f37e 100644 --- a/libc/testlib/formatstr.c +++ b/libc/testlib/formatstr.c @@ -17,8 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/progn.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" diff --git a/libc/testlib/runner.c b/libc/testlib/runner.c index ed0081be..64b60db3 100644 --- a/libc/testlib/runner.c +++ b/libc/testlib/runner.c @@ -20,7 +20,6 @@ #include "libc/calls/calls.h" #include "libc/log/log.h" #include "libc/nexgen32e/nexgen32e.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/testlib/testlib.h" diff --git a/libc/testlib/showerror.c b/libc/testlib/showerror.c index f8c50d10..519f89c2 100644 --- a/libc/testlib/showerror.c +++ b/libc/testlib/showerror.c @@ -20,7 +20,7 @@ #include "libc/calls/internal.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/log/log.h" #include "libc/math.h" diff --git a/libc/testlib/showerror_.c b/libc/testlib/showerror_.c index b0392a72..a6a05530 100644 --- a/libc/testlib/showerror_.c +++ b/libc/testlib/showerror_.c @@ -17,11 +17,11 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/internal.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/internal.h" #include "libc/log/log.h" #include "libc/math.h" diff --git a/libc/testlib/testmain.c b/libc/testlib/testmain.c index 5dda0cc9..7c0a6bc6 100644 --- a/libc/testlib/testmain.c +++ b/libc/testlib/testmain.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/internal.h" #include "libc/log/log.h" #include "libc/nexgen32e/x86feature.h" @@ -38,7 +38,7 @@ Flags:\n\ -h show this information\n\ \n" -STATIC_YOINK("die"); +STATIC_YOINK("__die"); static bool runbenchmarks_; diff --git a/libc/testlib/testmem.c b/libc/testlib/testmem.c index d7d7de0b..a24729a4 100644 --- a/libc/testlib/testmem.c +++ b/libc/testlib/testmem.c @@ -18,10 +18,10 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/dce.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" @@ -44,7 +44,9 @@ static bool g_atstartofpage; static struct TestAllocation testmem_push(struct TestMemoryStack *stack, struct TestAllocation entry) { if (stack->i == stack->n) { - if (!grow(&stack->p, &stack->n, sizeof(struct TestAllocation), 0)) abort(); + if (!__grow(&stack->p, &stack->n, sizeof(struct TestAllocation), 0)) { + abort(); + } } return (stack->p[stack->i++] = entry); } @@ -56,7 +58,7 @@ static struct TestAllocation testmem_pop(struct TestMemoryStack *stack) { } static void testmem_destroy(struct TestAllocation alloc) { - if (munmap(alloc.mapaddr, alloc.mapsize) == -1) perror("munmap"), die(); + if (munmap(alloc.mapaddr, alloc.mapsize) == -1) perror("munmap"), __die(); } static struct TestAllocation talloc(size_t n) { diff --git a/libc/time/localtime.c b/libc/time/localtime.c index a19afd2c..1e02adec 100644 --- a/libc/time/localtime.c +++ b/libc/time/localtime.c @@ -1,7 +1,7 @@ /*-*- mode:c; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ │vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/calls/calls.h" #include "libc/macros.h" #include "libc/math.h" @@ -12,7 +12,7 @@ #include "libc/sysv/consts/o.h" #include "libc/time/struct/tm.h" #include "libc/time/time.h" -#include "libc/tzfile.h" +#include "libc/time/tzfile.internal.h" #define ALL_STATE diff --git a/libc/time/strftime.c b/libc/time/strftime.c index 5c056070..b52083dc 100644 --- a/libc/time/strftime.c +++ b/libc/time/strftime.c @@ -23,7 +23,7 @@ #include "libc/nexgen32e/nexgen32e.h" #include "libc/time/struct/tm.h" #include "libc/time/time.h" -#include "libc/tzfile.h" +#include "libc/time/tzfile.internal.h" STATIC_YOINK("ntoa"); diff --git a/libc/tzfile.h b/libc/time/tzfile.internal.h similarity index 100% rename from libc/tzfile.h rename to libc/time/tzfile.internal.h diff --git a/libc/tinymath/rint.S b/libc/tinymath/rint.S index 599c447e..5c73fee4 100644 --- a/libc/tinymath/rint.S +++ b/libc/tinymath/rint.S @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/nexgen32e/x86feature.h" -#include "libc/bits/smmintrin.h" +#include "libc/bits/smmintrin.internal.h" #include "libc/macros.h" .source __FILE__ diff --git a/libc/tinymath/round.S b/libc/tinymath/round.S index 4abfe836..21efbe44 100644 --- a/libc/tinymath/round.S +++ b/libc/tinymath/round.S @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.h" -#include "libc/bits/smmintrin.h" +#include "libc/bits/smmintrin.internal.h" #include "libc/nexgen32e/x86feature.h" .source __FILE__ diff --git a/libc/tinymath/roundf.S b/libc/tinymath/roundf.S index 22d2cab0..c619001f 100644 --- a/libc/tinymath/roundf.S +++ b/libc/tinymath/roundf.S @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.h" -#include "libc/bits/smmintrin.h" +#include "libc/bits/smmintrin.internal.h" #include "libc/nexgen32e/x86feature.h" .source __FILE__ diff --git a/libc/typename.h b/libc/typename.h deleted file mode 100644 index e6d7358d..00000000 --- a/libc/typename.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_TYPENAME_H_ -#define COSMOPOLITAN_LIBC_TYPENAME_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -/** - * Returns string identifier for scalar type of expression. - * - * @see TYPE_FMT() - */ -#define TYPE_NAME(X) \ - _Generic((X), long double \ - : "long double", double \ - : "double", float \ - : "float", char \ - : "char", signed char \ - : "signed char", unsigned char \ - : "unsigned char", short \ - : "short", unsigned short \ - : "unsigned short", int \ - : "int", unsigned \ - : "unsigned", long \ - : "long", unsigned long \ - : "unsigned long long", long long \ - : "long long", unsigned long long \ - : "unsigned long long") - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_TYPENAME_H_ */ diff --git a/libc/unicode/strnwidth16.c b/libc/unicode/strnwidth16.c index 1b0c9f26..d0c6ed04 100644 --- a/libc/unicode/strnwidth16.c +++ b/libc/unicode/strnwidth16.c @@ -17,7 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" #include "libc/unicode/unicode.h" diff --git a/libc/unicode/strwidth16.c b/libc/unicode/strwidth16.c index 479321ac..2fd95a88 100644 --- a/libc/unicode/strwidth16.c +++ b/libc/unicode/strwidth16.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/limits.h" #include "libc/unicode/unicode.h" diff --git a/libc/wave.h b/libc/wave.h deleted file mode 100644 index 2f2a1855..00000000 --- a/libc/wave.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_WAVE_H_ -#define COSMOPOLITAN_LIBC_WAVE_H_ - -#define kWaveAlign 4 - -#define kWaveMagnumRiff 0x46464952u /* "RIFF" */ -#define kWaveMagnumWave 0x46464952u /* "WAVE" */ - -#define WAVE_AUDIOFORMAT_PCM 1 - -#define WAVE_OFFSET_CHUNK_ID 0 -#define WAVE_OFFSET_CHUNK_SIZE 4 -#define WAVE_OFFSET_FORMAT 8 -#define WAVE_OFFSET_SUBCHUNK_1_ID 12 -#define WAVE_OFFSET_SUBCHUNK_1_SIZE 16 -#define WAVE_OFFSET_AUDIOFORMAT 20 -#define WAVE_OFFSET_CHANNELS 22 -#define WAVE_OFFSET_SAMPLERATE 24 -#define WAVE_OFFSET_BYTERATE 28 -#define WAVE_OFFSET_BLOCKALIGN 32 -#define WAVE_OFFSET_BITSPERSAMPLE 34 -#define WAVE_OFFSET_SUBCHUNK_2_ID 36 -/* #define WAVE_OFFSET_SUBCHUNK_2_ID 40 */ - -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -/** - * @fileoverview RIFF WAVE data structures. - */ - -#define WAVE_MAGIC(P) read64le(P) -#define WAVE_MAGIC_WRITE(P) read64le(P) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_WAVE_H_ */ diff --git a/libc/x/bingblit.c b/libc/x/bingblit.c index 31c15fbe..bd9e2dc3 100644 --- a/libc/x/bingblit.c +++ b/libc/x/bingblit.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/x/x.h" short *bingblit(int ys, int xs, unsigned char M[ys][xs], int yn, int xn) { diff --git a/libc/x/unbingbuf.c b/libc/x/unbingbuf.c index d6661d4f..05bb49c5 100644 --- a/libc/x/unbingbuf.c +++ b/libc/x/unbingbuf.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/log/check.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/libc/x/unbingstr.c b/libc/x/unbingstr.c index 8c12aa0a..1ff46cfa 100644 --- a/libc/x/unbingstr.c +++ b/libc/x/unbingstr.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/libc/x/x.h b/libc/x/x.h index 66aa5e3a..476feb48 100644 --- a/libc/x/x.h +++ b/libc/x/x.h @@ -1,27 +1,10 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ #ifndef COSMOPOLITAN_LIBC_X_H_ #define COSMOPOLITAN_LIBC_X_H_ +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timeval.h" #include "libc/fmt/pflink.h" +#include "libc/stdio/stdio.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ /*───────────────────────────────────────────────────────────────────────────│─╗ @@ -34,10 +17,6 @@ COSMOPOLITAN_C_START_ #define _XMAL returnspointerwithnoaliases _XRET #define _XMALPG returnsaligned((PAGESIZE)) _XMAL -struct FILE; -struct sigaction; -struct timeval; - /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § eXtended apis » system calls ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ diff --git a/libc/x/xdie.c b/libc/x/xdie.c index 6b56be03..899bde8f 100644 --- a/libc/x/xdie.c +++ b/libc/x/xdie.c @@ -23,6 +23,6 @@ #include "libc/x/x.h" void xdie(void) { - if (weaken(die)) die(); + if (weaken(__die)) __die(); abort(); } diff --git a/libc/x/xjoinpaths.c b/libc/x/xjoinpaths.c index 7c6ed87a..be1d8c50 100644 --- a/libc/x/xjoinpaths.c +++ b/libc/x/xjoinpaths.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/str/str.h" #include "libc/x/x.h" diff --git a/libc/x/xstrcat.c b/libc/x/xstrcat.c index 028b526a..6d4ee5ab 100644 --- a/libc/x/xstrcat.c +++ b/libc/x/xstrcat.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "libc/x/x.h" diff --git a/libc/zipos/read.c b/libc/zipos/read.c index a01bca37..1051ef67 100644 --- a/libc/zipos/read.c +++ b/libc/zipos/read.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/internal.h" #include "libc/calls/struct/iovec.h" #include "libc/str/str.h" diff --git a/libc/zipos/stat-impl.c b/libc/zipos/stat-impl.c index db621cb8..3cd7888d 100644 --- a/libc/zipos/stat-impl.c +++ b/libc/zipos/stat-impl.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/runtime/rbx.h" diff --git a/net/http/parsehttprequest.c b/net/http/parsehttprequest.c index 1f01f7d9..be5d1910 100644 --- a/net/http/parsehttprequest.c +++ b/net/http/parsehttprequest.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/limits.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/dsp/scale/magikarp_test.c b/test/dsp/scale/magikarp_test.c index 29f3c7ef..1769892b 100644 --- a/test/dsp/scale/magikarp_test.c +++ b/test/dsp/scale/magikarp_test.c @@ -21,7 +21,7 @@ #include "dsp/scale/cdecimate2xuint8x8.h" #include "dsp/scale/scale.h" #include "libc/assert.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/log/check.h" #include "libc/math.h" #include "libc/mem/mem.h" diff --git a/test/dsp/scale/scale_test.c b/test/dsp/scale/scale_test.c index ff6eb952..4e06098d 100644 --- a/test/dsp/scale/scale_test.c +++ b/test/dsp/scale/scale_test.c @@ -22,7 +22,7 @@ #include "dsp/core/core.h" #include "dsp/core/half.h" #include "dsp/scale/scale.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/macros.h" #include "libc/mem/mem.h" #include "libc/stdio/stdio.h" diff --git a/test/dsp/tty/ttyraster_test.c b/test/dsp/tty/ttyraster_test.c index 4e19df17..ea3eb699 100644 --- a/test/dsp/tty/ttyraster_test.c +++ b/test/dsp/tty/ttyraster_test.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/quant.h" -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "net/http/csscolor.h" diff --git a/test/libc/alg/arraylist_test.c b/test/libc/alg/arraylist_test.c index a9989554..276bc10f 100644 --- a/test/libc/alg/arraylist_test.c +++ b/test/libc/alg/arraylist_test.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" @@ -61,37 +61,33 @@ TEST(append, isGenericallyTyped) { } TEST(concat, worksGreatForStrings) { - const char *ks = - "Und wird die Welt auch in Flammen stehen\n" - "Wir werden wieder auferstehen\n"; + const char *ks = "Und wird die Welt auch in Flammen stehen\n" + "Wir werden wieder auferstehen\n"; struct string s; memset(&s, 0, sizeof(s)); ASSERT_EQ(0, concat(&s, ks, strlen(ks))); ASSERT_EQ(strlen(ks), concat(&s, ks, strlen(ks) + 1)); - ASSERT_STREQ( - "Und wird die Welt auch in Flammen stehen\n" - "Wir werden wieder auferstehen\n" - "Und wird die Welt auch in Flammen stehen\n" - "Wir werden wieder auferstehen\n", - s.p); + ASSERT_STREQ("Und wird die Welt auch in Flammen stehen\n" + "Wir werden wieder auferstehen\n" + "Und wird die Welt auch in Flammen stehen\n" + "Wir werden wieder auferstehen\n", + s.p); ASSERT_EQ(strlen(ks) * 2 + 1, s.i); free_s(&s.p); } TEST(concat, isGenericallyTyped) { - const char16_t *ks = - u"Drum hoch die Fäuste, hoch zum Licht.\n" - u"Unsere schwarzen Seelen bekommt ihr nicht.\n"; + const char16_t *ks = u"Drum hoch die Fäuste, hoch zum Licht.\n" + u"Unsere schwarzen Seelen bekommt ihr nicht.\n"; struct string16 s; memset(&s, 0, sizeof(s)); ASSERT_EQ(0, concat(&s, ks, strlen16(ks))); ASSERT_EQ(strlen16(ks), concat(&s, ks, strlen16(ks) + 1)); - ASSERT_STREQ( - u"Drum hoch die Fäuste, hoch zum Licht.\n" - u"Unsere schwarzen Seelen bekommt ihr nicht.\n" - u"Drum hoch die Fäuste, hoch zum Licht.\n" - u"Unsere schwarzen Seelen bekommt ihr nicht.\n", - s.p); + ASSERT_STREQ(u"Drum hoch die Fäuste, hoch zum Licht.\n" + u"Unsere schwarzen Seelen bekommt ihr nicht.\n" + u"Drum hoch die Fäuste, hoch zum Licht.\n" + u"Unsere schwarzen Seelen bekommt ihr nicht.\n", + s.p); ASSERT_EQ(strlen16(ks) * 2 + 1, s.i); free_s(&s.p); } diff --git a/test/libc/alg/bisectcarleft_test.c b/test/libc/alg/bisectcarleft_test.c index fa2b9bb2..9fa185df 100644 --- a/test/libc/alg/bisectcarleft_test.c +++ b/test/libc/alg/bisectcarleft_test.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/bisectcarleft.h" +#include "libc/alg/bisectcarleft.internal.h" #include "libc/bits/bits.h" #include "libc/macros.h" #include "libc/runtime/runtime.h" diff --git a/test/libc/alg/critbit0_test.c b/test/libc/alg/critbit0_test.c index 3941f437..abd6705a 100644 --- a/test/libc/alg/critbit0_test.c +++ b/test/libc/alg/critbit0_test.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/alg.h" +#include "libc/alg/critbit0.h" #include "libc/bits/bits.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" @@ -36,8 +36,14 @@ static testonly nodiscard struct Bog *NewBog(unsigned n) { res->n = n; return res; } -static testonly void ClearBog(struct Bog *bog) { bog->i = 0; } -static testonly void FreeBog(struct Bog **bog) { free(*bog), *bog = NULL; } + +static testonly void ClearBog(struct Bog *bog) { + bog->i = 0; +} + +static testonly void FreeBog(struct Bog **bog) { + free(*bog), *bog = NULL; +} static const char *const elems[] = {"a", "aa", "aaz", "abz", "bba", "bbc", "bbd", NULL}; diff --git a/test/libc/alg/djbsort_test.c b/test/libc/alg/djbsort_test.c index 35bb550b..fd34e224 100644 --- a/test/libc/alg/djbsort_test.c +++ b/test/libc/alg/djbsort_test.c @@ -42,9 +42,9 @@ TEST(djbsort, test4) { a = memcpy(tgc(tmalloc(n * 4)), kA, n * 4); b = memcpy(tgc(tmalloc(n * 4)), kA, n * 4); c = memcpy(tgc(tmalloc(n * 4)), kA, n * 4); - insertionsort(n, a); + insertionsort(a, n); djbsort$avx2(b, n); - djbsort(n, c); + djbsort(c, n); ASSERT_EQ(0, memcmp(a, b, n * 4)); ASSERT_EQ(0, memcmp(a, c, n * 4)); } @@ -69,8 +69,8 @@ TEST(djbsort, test64) { a = memcpy(tgc(tmalloc(n * 4)), kA, n * 4); b = memcpy(tgc(tmalloc(n * 4)), kA, n * 4); c = memcpy(tgc(tmalloc(n * 4)), kA, n * 4); - insertionsort(n, a); - djbsort(n, c); + insertionsort(a, n); + djbsort(c, n); ASSERT_EQ(0, memcmp(a, c, n * 4)); if (X86_HAVE(AVX2)) { djbsort$avx2(b, n); @@ -82,6 +82,6 @@ BENCH(djbsort, bench) { n = 256; a = gc(memalign(32, n * 4)); EZBENCH2("insertionsort[255]", rngset(a, n * 4, rand64, -1), - insertionsort(n, a)); - EZBENCH2("djbsort[255]", rngset(a, n * 4, rand64, -1), djbsort(n, a)); + insertionsort(a, n)); + EZBENCH2("djbsort[255]", rngset(a, n * 4, rand64, -1), djbsort(a, n)); } diff --git a/test/libc/alg/replacestr_test.inc b/test/libc/alg/replacestr_test.inc index e300f677..c218fa05 100644 --- a/test/libc/alg/replacestr_test.inc +++ b/test/libc/alg/replacestr_test.inc @@ -20,19 +20,19 @@ TEST(REPLACESTR, demo) { EXPECT_STREQ(S("hello friends"), - replacestr(S("hello world"), S("world"), S("friends"))); - EXPECT_STREQ(S("bbbbbbbb"), replacestr(S("aaaa"), S("a"), S("bb"))); + REPLACESTR(S("hello world"), S("world"), S("friends"))); + EXPECT_STREQ(S("bbbbbbbb"), REPLACESTR(S("aaaa"), S("a"), S("bb"))); } TEST(REPLACESTR, emptyString) { - EXPECT_STREQ(S(""), replacestr(S(""), S("x"), S("y"))); + EXPECT_STREQ(S(""), REPLACESTR(S(""), S("x"), S("y"))); } TEST(REPLACESTR, emptyNeedle) { - EXPECT_EQ(NULL, replacestr(S("a"), S(""), S("a"))); + EXPECT_EQ(NULL, REPLACESTR(S("a"), S(""), S("a"))); EXPECT_EQ(EINVAL, errno); } TEST(REPLACESTR, needleInReplacement_doesntExplode) { - EXPECT_STREQ(S("xxxxxxx"), replacestr(S("x"), S("x"), S("xxxxxxx"))); + EXPECT_STREQ(S("xxxxxxx"), REPLACESTR(S("x"), S("x"), S("xxxxxxx"))); } diff --git a/test/libc/bits/bitreverse_test.c b/test/libc/bits/bitreverse_test.c index 5f3751b5..e993e9b8 100644 --- a/test/libc/bits/bitreverse_test.c +++ b/test/libc/bits/bitreverse_test.c @@ -28,6 +28,10 @@ TEST(bitreverse, test) { EXPECT_EQ(0xde00, (bitreverse16)(123)); EXPECT_EQ(0xde000000u, bitreverse32(123)); EXPECT_EQ(0xde000000u, (bitreverse32)(123)); + EXPECT_EQ(0xde00000000000000ul, bitreverse64(123)); + EXPECT_EQ(0xde00000000000000ul, (bitreverse64)(123)); + EXPECT_EQ(0x482d96c305f7c697ul, bitreverse64(0xe963efa0c369b412)); + EXPECT_EQ(0x482d96c305f7c697ul, (bitreverse64)(0xe963efa0c369b412)); } BENCH(bitreverse, bench) { diff --git a/test/libc/bits/bt_test.c b/test/libc/bits/bt_test.c deleted file mode 100644 index d89d530f..00000000 --- a/test/libc/bits/bt_test.c +++ /dev/null @@ -1,66 +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 │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/bits.h" -#include "libc/testlib/testlib.h" - -TEST(bt_uint16x4, test) { - uint16_t v[4] = {0}; - EXPECT_FALSE(bt(v, 0)); - EXPECT_FALSE(bt(v, 63)); - EXPECT_FALSE(bts(v, 63)); - EXPECT_TRUE(bt(v, 63)); - EXPECT_TRUE(bts(v, 63)); -} - -TEST(bt_uint32x2, test) { - uint32_t v[2] = {0}; - EXPECT_FALSE(bt(v, 0)); - EXPECT_FALSE(bt(v, 63)); - EXPECT_FALSE(bts(v, 63)); - EXPECT_TRUE(bt(v, 63)); - EXPECT_TRUE(bts(v, 63)); -} - -TEST(bt_uint64x1, test) { - uint64_t v = 0; - EXPECT_FALSE(bt(&v, 0)); - EXPECT_FALSE(bt(&v, 63)); - EXPECT_FALSE(bts(&v, 63)); - EXPECT_TRUE(bt(&v, 63)); - EXPECT_TRUE(bts(&v, 63)); -} - -TEST(bt_uint64, testPresent) { - uint64_t v = 1; - EXPECT_TRUE(bt(&v, 0)); - EXPECT_FALSE(bt(&v, 63)); - v = 0x8000000000000001; - EXPECT_TRUE(bt(&v, 0)); - EXPECT_TRUE(bt(&v, 63)); -} - -TEST(bt_uint64, testPresent_avoidingDeadCodeElimination) { - volatile uint64_t v = 1; - EXPECT_TRUE(bt(&v, 0)); - EXPECT_FALSE(bt(&v, 63)); - v = 0x8000000000000001; - EXPECT_TRUE(bt(&v, 0)); - EXPECT_TRUE(bt(&v, 63)); -} diff --git a/test/libc/bits/division_test.c b/test/libc/bits/division_test.c index af94f691..be755ce5 100644 --- a/test/libc/bits/division_test.c +++ b/test/libc/bits/division_test.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/bits/integralarithmetic_test.c b/test/libc/bits/integralarithmetic_test.c index 5a4eecd1..55535f96 100644 --- a/test/libc/bits/integralarithmetic_test.c +++ b/test/libc/bits/integralarithmetic_test.c @@ -22,6 +22,9 @@ #include "libc/macros.h" #include "libc/testlib/testlib.h" +#define ROR(w, k) (CheckUnsigned(w) >> (k) | (w) << (sizeof(w) * 8 - (k))) +#define ROL(w, k) ((w) << (k) | CheckUnsigned(w) >> (sizeof(w) * 8 - (k))) + TEST(TwosComplementBane, LiteralsThatAreLiterallyTheSameNumber) { EXPECT_EQ(4, sizeof(INT_MIN)); EXPECT_EQ(8, sizeof(-2147483648)); @@ -30,12 +33,6 @@ TEST(TwosComplementBane, LiteralsThatAreLiterallyTheSameNumber) { EXPECT_FALSE(TYPE_SIGNED(-0x80000000)); } -TEST(ShiftArithmeticRight, DeclassifiedByGuySteele) { - EXPECT_EQ(-1u, SAR(-2u, 1u)); - EXPECT_EQ(-1u, SAR(-1u, 1u)); - EXPECT_EQ(0xc0000000u, SAR(0x80000000u, 1u)); -} - TEST(RotateRight, Test) { EXPECT_EQ(0x41122334u, ROR(0x11223344u, 4)); EXPECT_EQ(0x44112233u, ROR(0x11223344u, 8)); diff --git a/test/libc/bits/unsignedsubtract_test.c b/test/libc/bits/unsignedsubtract_test.c index a44e2c7a..4c425661 100644 --- a/test/libc/bits/unsignedsubtract_test.c +++ b/test/libc/bits/unsignedsubtract_test.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/testlib/testlib.h" TEST(unsignedsubtract, testMacro) { diff --git a/test/libc/calls/fallocate_test.c b/test/libc/calls/fallocate_test.c index 05cd71ea..06c875f8 100644 --- a/test/libc/calls/fallocate_test.c +++ b/test/libc/calls/fallocate_test.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/dce.h" diff --git a/test/libc/calls/signal_test.c b/test/libc/calls/signal_test.c index fa2bbfc0..ea45bf35 100644 --- a/test/libc/calls/signal_test.c +++ b/test/libc/calls/signal_test.c @@ -24,11 +24,13 @@ #include "libc/sysv/consts/sig.h" #include "libc/testlib/testlib.h" -testonly void OnCtrlC(int sig) { _exit(0); } +testonly void OnCtrlC(int sig) { + _exit(0); +} TEST(signal, test) { if (IsWindows()) return; /* omg */ ASSERT_NE(SIG_ERR, signal(SIGINT, OnCtrlC)); ASSERT_NE(-1, raise(SIGINT)); - die(); + __die(); } diff --git a/test/libc/crypto/rijndael_test.c b/test/libc/crypto/rijndael_test.c index 71730c89..c860114c 100644 --- a/test/libc/crypto/rijndael_test.c +++ b/test/libc/crypto/rijndael_test.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/crypto/rijndael.h" #include "libc/dce.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/runtime/internal.h" #include "libc/str/str.h" #include "libc/sysv/consts/prot.h" diff --git a/test/libc/fmt/palandprintf_test.c b/test/libc/fmt/palandprintf_test.c index 781cc369..f937b5f0 100644 --- a/test/libc/fmt/palandprintf_test.c +++ b/test/libc/fmt/palandprintf_test.c @@ -24,9 +24,9 @@ │ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN │ │ THE SOFTWARE. │ └─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/bits/pushpop.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/itoa.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" diff --git a/test/libc/fmt/sprintf_s_test.c b/test/libc/fmt/sprintf_s_test.c index 9e95c054..1bac4d84 100644 --- a/test/libc/fmt/sprintf_s_test.c +++ b/test/libc/fmt/sprintf_s_test.c @@ -18,8 +18,8 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/progn.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/progn.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/fmt/fmt.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/intrin/intrin_test.c b/test/libc/intrin/intrin_test.c index 61437fbf..d7add1c8 100644 --- a/test/libc/intrin/intrin_test.c +++ b/test/libc/intrin/intrin_test.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/intrin/mpsadbw.h" #include "libc/intrin/pabsb.h" #include "libc/intrin/pabsd.h" diff --git a/test/libc/intrin/palignr_test.c b/test/libc/intrin/palignr_test.c index 7374a76b..d75e323b 100644 --- a/test/libc/intrin/palignr_test.c +++ b/test/libc/intrin/palignr_test.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/intrin/palignr.h" #include "libc/rand/rand.h" #include "libc/testlib/ezbench.h" diff --git a/test/libc/mem/malloc_test.c b/test/libc/mem/malloc_test.c index 05a5a06f..77833f8a 100644 --- a/test/libc/mem/malloc_test.c +++ b/test/libc/mem/malloc_test.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/macros.h" diff --git a/test/libc/nexgen32e/lz4decode_test.c b/test/libc/nexgen32e/lz4decode_test.c index aa42d21a..a8f81acf 100644 --- a/test/libc/nexgen32e/lz4decode_test.c +++ b/test/libc/nexgen32e/lz4decode_test.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/log/check.h" #include "libc/nexgen32e/kompressor.h" @@ -73,8 +73,8 @@ TEST(lz4, decompress_runLengthDecode) { TEST(lz4, zoneFileGmt) { if (!fileexists("usr/share/zoneinfo.dict.lz4")) return; struct MappedFile dict, gmt; - CHECK_NE(-1, mapfileread("usr/share/zoneinfo.dict.lz4", &dict)); - CHECK_NE(-1, mapfileread("usr/share/zoneinfo/GMT.lz4", &gmt)); + CHECK_NE(-1, MapFileRead("usr/share/zoneinfo.dict.lz4", &dict)); + CHECK_NE(-1, MapFileRead("usr/share/zoneinfo/GMT.lz4", &gmt)); size_t mapsize, gmtsize; char *mapping, *gmtdata; lz4decode((gmtdata = lz4decode( @@ -91,6 +91,6 @@ TEST(lz4, zoneFileGmt) { u"               ☺   ☺       ☺   ☺   ♦°              GMT   ◙GMT0◙", gmtdata); munmap(mapping, mapsize); - unmapfile(&dict); - unmapfile(&gmt); + UnmapFile(&dict); + UnmapFile(&gmt); } diff --git a/test/libc/nexgen32e/memmove_test.c b/test/libc/nexgen32e/memmove_test.c index 33ebbeed..dfbabe7c 100644 --- a/test/libc/nexgen32e/memmove_test.c +++ b/test/libc/nexgen32e/memmove_test.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/release/smoke.c b/test/libc/release/smoke.c new file mode 100644 index 00000000..ba622f85 --- /dev/null +++ b/test/libc/release/smoke.c @@ -0,0 +1,7 @@ +int main() { + FILE *f; + f = fopen("/dev/null", "w"); + fprintf(f, "hello world\n"); + fclose(f); + return 0; +} diff --git a/test/libc/release/test.mk b/test/libc/release/test.mk new file mode 100644 index 00000000..87aec6ae --- /dev/null +++ b/test/libc/release/test.mk @@ -0,0 +1,38 @@ +#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐ +#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘ + +o/$(MODE)/test/libc/release/cosmopolitan.zip: \ + o/cosmopolitan.h \ + o/$(MODE)/ape/ape.lds \ + o/$(MODE)/libc/crt/crt.o \ + o/$(MODE)/ape/ape.o \ + o/$(MODE)/cosmopolitan.a + zip -j $@ $^ + +o/$(MODE)/test/libc/release/smoke.com: \ + test/libc/release/smoke.c \ + o/cosmopolitan.h \ + o/$(MODE)/ape/ape.lds \ + o/$(MODE)/libc/crt/crt.o \ + o/$(MODE)/ape/ape.o \ + o/$(MODE)/cosmopolitan.a + @ACTION=CC build/compile $(CC) \ + -o $@ \ + -Os \ + -static \ + -fno-pie \ + -no-pie \ + -nostdlib \ + -nostdinc \ + -Wl,--oformat=binary \ + -Wl,-T,o/$(MODE)/ape/ape.lds \ + -include o/cosmopolitan.h \ + test/libc/release/smoke.c \ + o/$(MODE)/libc/crt/crt.o \ + o/$(MODE)/ape/ape.o \ + o/$(MODE)/cosmopolitan.a + +.PHONY: o/$(MODE)/test/libc/release +o/$(MODE)/test/libc/release: \ + o/$(MODE)/test/libc/release/smoke.com \ + o/$(MODE)/test/libc/release/smoke.com.runs diff --git a/test/libc/runtime/getdosenviron_test.c b/test/libc/runtime/getdosenviron_test.c index 7b2425d2..37d960a5 100644 --- a/test/libc/runtime/getdosenviron_test.c +++ b/test/libc/runtime/getdosenviron_test.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/getdosenviron.h" +#include "libc/runtime/getdosenviron.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/runtime/grow_test.c b/test/libc/runtime/grow_test.c index f738c029..bf2757e9 100644 --- a/test/libc/runtime/grow_test.c +++ b/test/libc/runtime/grow_test.c @@ -28,7 +28,7 @@ TEST(grow, testNull_hasAllocatingBehavior) { void *p = NULL; size_t capacity = 0; - EXPECT_TRUE(grow(&p, &capacity, 1, 0)); + EXPECT_TRUE(__grow(&p, &capacity, 1, 0)); EXPECT_NE(NULL, p); EXPECT_EQ(32, capacity); free_s(&p); @@ -37,7 +37,7 @@ TEST(grow, testNull_hasAllocatingBehavior) { TEST(grow, testCapacity_isInUnits_withTerminatorGuarantee) { void *p = NULL; size_t capacity = 0; - EXPECT_TRUE(grow(&p, &capacity, 8, 0)); + EXPECT_TRUE(__grow(&p, &capacity, 8, 0)); EXPECT_NE(NULL, p); EXPECT_EQ(32 / 8 + 1, capacity); free_s(&p); @@ -48,7 +48,7 @@ TEST(grow, testStackMemory_convertsToDynamic) { int *p = A; size_t capacity = ARRAYLEN(A); if (!isheap(p)) { - EXPECT_TRUE(grow(&p, &capacity, sizeof(int), 0)); + EXPECT_TRUE(__grow(&p, &capacity, sizeof(int), 0)); EXPECT_TRUE(isheap(p)); EXPECT_GT(capacity, ARRAYLEN(A)); EXPECT_EQ(1, p[0]); @@ -64,7 +64,7 @@ TEST(grow, testGrowth_clearsNewMemory) { size_t i, capacity = 123; char *p = malloc(capacity); memset(p, 'a', capacity); - EXPECT_TRUE(grow(&p, &capacity, 1, 0)); + EXPECT_TRUE(__grow(&p, &capacity, 1, 0)); EXPECT_GT(capacity, 123); for (i = 0; i < 123; ++i) ASSERT_EQ('a', p[i]); for (i = 123; i < capacity; ++i) ASSERT_EQ(0, p[i]); @@ -74,11 +74,11 @@ TEST(grow, testGrowth_clearsNewMemory) { TEST(grow, testBonusParam_willGoAboveAndBeyond) { size_t capacity = 32; char *p = malloc(capacity); - EXPECT_TRUE(grow(&p, &capacity, 1, 0)); + EXPECT_TRUE(__grow(&p, &capacity, 1, 0)); EXPECT_LT(capacity, 1024); free_s(&p); p = malloc((capacity = 32)); - EXPECT_TRUE(grow(&p, &capacity, 1, 1024)); + EXPECT_TRUE(__grow(&p, &capacity, 1, 1024)); EXPECT_GT(capacity, 1024); free_s(&p); } @@ -88,7 +88,7 @@ TEST(grow, testOverflow_returnsFalseAndDoesNotFree) { int *p = A; size_t capacity = ARRAYLEN(A); if (!isheap(p)) { - EXPECT_FALSE(grow(&p, &capacity, pushpop(SIZE_MAX), 0)); + EXPECT_FALSE(__grow(&p, &capacity, pushpop(SIZE_MAX), 0)); EXPECT_FALSE(isheap(p)); EXPECT_EQ(capacity, ARRAYLEN(A)); EXPECT_EQ(1, p[0]); diff --git a/test/libc/runtime/mmap_test.c b/test/libc/runtime/mmap_test.c index 1128f86e..96e1e57b 100644 --- a/test/libc/runtime/mmap_test.c +++ b/test/libc/runtime/mmap_test.c @@ -25,7 +25,6 @@ #include "libc/mem/mem.h" #include "libc/runtime/gc.h" #include "libc/runtime/memtrack.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/sock/inet_pton_test.c b/test/libc/sock/inet_pton_test.c index 0189e71f..3c442240 100644 --- a/test/libc/sock/inet_pton_test.c +++ b/test/libc/sock/inet_pton_test.c @@ -17,8 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/progn.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/sock/sock.h" #include "libc/sysv/consts/af.h" #include "libc/sysv/consts/inaddr.h" diff --git a/test/libc/str/getutf16_test.c b/test/libc/str/getutf16_test.c index db5792be..00b06478 100644 --- a/test/libc/str/getutf16_test.c +++ b/test/libc/str/getutf16_test.c @@ -18,8 +18,9 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" #include "libc/testlib/testlib.h" TEST(getutf16, testNul) { diff --git a/test/libc/str/memccpy_test.c b/test/libc/str/memccpy_test.c index 34d7453f..a1dc5daf 100644 --- a/test/libc/str/memccpy_test.c +++ b/test/libc/str/memccpy_test.c @@ -19,7 +19,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/str/tinymemccpy.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/str/pututf16_test.c b/test/libc/str/pututf16_test.c index 67f3b754..a2d3a211 100644 --- a/test/libc/str/pututf16_test.c +++ b/test/libc/str/pututf16_test.c @@ -18,6 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" +#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" #include "libc/unicode/unicode.h" diff --git a/test/libc/str/sha256_test.c b/test/libc/str/sha256_test.c index b950401d..8668c162 100644 --- a/test/libc/str/sha256_test.c +++ b/test/libc/str/sha256_test.c @@ -17,6 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/str/sha256.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" diff --git a/test/libc/str/sigset_test.c b/test/libc/str/sigset_test.c index 6deb4321..ea4dc8bb 100644 --- a/test/libc/str/sigset_test.c +++ b/test/libc/str/sigset_test.c @@ -18,10 +18,10 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" -#include "libc/str/str.h" -#include "libc/calls/sigbits.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" +#include "libc/calls/sigbits.h" +#include "libc/str/str.h" #include "libc/testlib/testlib.h" sigset_t ss; diff --git a/test/libc/str/strcmp_test.c b/test/libc/str/strcmp_test.c index 7ef413e5..98fab4a6 100644 --- a/test/libc/str/strcmp_test.c +++ b/test/libc/str/strcmp_test.c @@ -21,7 +21,7 @@ #include "libc/dce.h" #include "libc/macros.h" #include "libc/nexgen32e/cachesize.h" -#include "libc/nexgen32e/tinystrcmp.h" +#include "libc/nexgen32e/tinystrcmp.internal.h" #include "libc/nexgen32e/x86feature.h" #include "libc/rand/rand.h" #include "libc/stdio/stdio.h" diff --git a/test/libc/str/strlen_test.c b/test/libc/str/strlen_test.c index 2a75d5ac..773aeae2 100644 --- a/test/libc/str/strlen_test.c +++ b/test/libc/str/strlen_test.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" #include "libc/macros.h" -#include "libc/nexgen32e/tinystrlen.h" +#include "libc/nexgen32e/tinystrlen.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/str/tpdecode_test.c b/test/libc/str/tpdecode_test.c index deb82cb6..11abbc46 100644 --- a/test/libc/str/tpdecode_test.c +++ b/test/libc/str/tpdecode_test.c @@ -18,14 +18,14 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/progn.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/progn.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/errno.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/limits.h" #include "libc/runtime/gc.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" #include "libc/testlib/testlib.h" wint_t wc; diff --git a/test/libc/str/tpencode_test.c b/test/libc/str/tpencode_test.c index 8c0e7ab4..41f6ff74 100644 --- a/test/libc/str/tpencode_test.c +++ b/test/libc/str/tpencode_test.c @@ -18,10 +18,10 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/progn.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/progn.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/str/str.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpencode.internal.h" #include "libc/testlib/testlib.h" char buf[8]; diff --git a/test/libc/str/undeflate_test.c b/test/libc/str/undeflate_test.c index 2e0ccd7d..89a64e93 100644 --- a/test/libc/str/undeflate_test.c +++ b/test/libc/str/undeflate_test.c @@ -27,7 +27,7 @@ #include "libc/runtime/gc.h" #include "libc/runtime/rbx.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/undeflate.h" diff --git a/test/libc/test.mk b/test/libc/test.mk index 1361bae6..b3f35b00 100644 --- a/test/libc/test.mk +++ b/test/libc/test.mk @@ -15,6 +15,7 @@ o/$(MODE)/test/libc: \ o/$(MODE)/test/libc/mem \ o/$(MODE)/test/libc/nexgen32e \ o/$(MODE)/test/libc/rand \ + o/$(MODE)/test/libc/release \ o/$(MODE)/test/libc/runtime \ o/$(MODE)/test/libc/sock \ o/$(MODE)/test/libc/stdio \ diff --git a/test/libc/xed/x86ild_lib.c b/test/libc/xed/x86ild_lib.c index f015b3e7..eb21b142 100644 --- a/test/libc/xed/x86ild_lib.c +++ b/test/libc/xed/x86ild_lib.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/macros.h" #include "libc/runtime/gc.h" #include "libc/str/str.h" diff --git a/test/net/http/uriparse_test.c b/test/net/http/uriparse_test.c index 8650f5ea..2daffc75 100644 --- a/test/net/http/uriparse_test.c +++ b/test/net/http/uriparse_test.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/errno.h" #include "libc/log/log.h" #include "libc/macros.h" diff --git a/test/tool/build/lib/alu_test.c b/test/tool/build/lib/alu_test.c index 8b86eae6..96e33623 100644 --- a/test/tool/build/lib/alu_test.c +++ b/test/tool/build/lib/alu_test.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/limits.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/test/tool/build/lib/divmul_test.c b/test/tool/build/lib/divmul_test.c index a2a34f13..9011f6c2 100644 --- a/test/tool/build/lib/divmul_test.c +++ b/test/tool/build/lib/divmul_test.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" +#include "libc/bits/progn.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/log/check.h" #include "libc/runtime/gc.h" diff --git a/test/tool/build/lib/machine_test.c b/test/tool/build/lib/machine_test.c index 568ea803..39f71f2f 100644 --- a/test/tool/build/lib/machine_test.c +++ b/test/tool/build/lib/machine_test.c @@ -17,8 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/progn.h" -#include "libc/fmt/bing.h" +#include "libc/bits/progn.internal.h" +#include "libc/fmt/bing.internal.h" #include "libc/math.h" #include "libc/mem/mem.h" #include "libc/runtime/gc.h" diff --git a/third_party/avir/avir.h b/third_party/avir/avir.h index 5396da35..e4fb3bdc 100644 --- a/third_party/avir/avir.h +++ b/third_party/avir/avir.h @@ -58,7 +58,7 @@ #define AVIR_CIMAGERESIZER_INCLUDED #include "third_party/avir/notice.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/str/str.h" #include "libc/mem/mem.h" #include "libc/bits/bits.h" diff --git a/third_party/avir/avir_float4_sse.h b/third_party/avir/avir_float4_sse.h index 6d3cb1ff..143d8f89 100644 --- a/third_party/avir/avir_float4_sse.h +++ b/third_party/avir/avir_float4_sse.h @@ -17,11 +17,11 @@ #define AVIR_FLOAT4_SSE_INCLUDED #include "third_party/avir/avir.h" -#include "libc/bits/mmintrin.h" -#include "libc/bits/xmmintrin.h" -#include "libc/bits/xmmintrin.h" -#include "libc/bits/xmmintrin.h" -#include "libc/bits/emmintrin.h" +#include "libc/bits/mmintrin.internal.h" +#include "libc/bits/xmmintrin.internal.h" +#include "libc/bits/xmmintrin.internal.h" +#include "libc/bits/xmmintrin.internal.h" +#include "libc/bits/emmintrin.internal.h" namespace avir { diff --git a/third_party/avir/avir_float8_avx.h b/third_party/avir/avir_float8_avx.h index ce00cd06..72834bfd 100644 --- a/third_party/avir/avir_float8_avx.h +++ b/third_party/avir/avir_float8_avx.h @@ -16,12 +16,12 @@ #ifndef AVIR_FLOAT8_AVX_INCLUDED #define AVIR_FLOAT8_AVX_INCLUDED -#include "libc/bits/mmintrin.h" -#include "libc/bits/avxintrin.h" -#include "libc/bits/smmintrin.h" -#include "libc/bits/pmmintrin.h" -#include "libc/bits/avx2intrin.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/mmintrin.internal.h" +#include "libc/bits/avxintrin.internal.h" +#include "libc/bits/smmintrin.internal.h" +#include "libc/bits/pmmintrin.internal.h" +#include "libc/bits/avx2intrin.internal.h" +#include "libc/bits/xmmintrin.internal.h" #include "third_party/avir/avir_dil.h" namespace avir { diff --git a/third_party/avir/lanczos1.cc b/third_party/avir/lanczos1.cc index c35751d6..af2c31d2 100644 --- a/third_party/avir/lanczos1.cc +++ b/third_party/avir/lanczos1.cc @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/limits.h" #include "libc/log/log.h" #include "libc/runtime/runtime.h" diff --git a/third_party/avir/lanczos1f.cc b/third_party/avir/lanczos1f.cc index 5e0036e9..9cead815 100644 --- a/third_party/avir/lanczos1f.cc +++ b/third_party/avir/lanczos1f.cc @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/runtime/runtime.h" #include "third_party/avir/lanczos1f.h" namespace { diff --git a/third_party/dlmalloc/bulk_free.c b/third_party/dlmalloc/bulk_free.c index 60e0d57b..e8701782 100644 --- a/third_party/dlmalloc/bulk_free.c +++ b/third_party/dlmalloc/bulk_free.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Frees and clears (sets to NULL) each non-null pointer in the given diff --git a/third_party/dlmalloc/dlcalloc.c b/third_party/dlmalloc/dlcalloc.c index 1d61b9d4..43343a8d 100644 --- a/third_party/dlmalloc/dlcalloc.c +++ b/third_party/dlmalloc/dlcalloc.c @@ -1,5 +1,5 @@ #include "libc/str/str.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" void *dlcalloc(size_t n_elements, size_t elem_size) { void *mem; diff --git a/third_party/dlmalloc/dlindependent_calloc.c b/third_party/dlmalloc/dlindependent_calloc.c index 85fe045a..cab3b1df 100644 --- a/third_party/dlmalloc/dlindependent_calloc.c +++ b/third_party/dlmalloc/dlindependent_calloc.c @@ -1,6 +1,6 @@ #include "libc/mem/mem.h" #include "libc/str/str.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /* Common support for independent_X routines, handling @@ -152,7 +152,7 @@ static void **ialloc(mstate m, size_t n_elements, size_t *sizes, int opts, * int n = read_number_of_nodes_needed(); * if (n <= 0) return 0; * pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0); - * if (pool == 0) die(); + * if (pool == 0) __die(); * // organize into a linked list... * struct Node* first = pool[0]; * for (i = 0; i < n-1; ++i) @@ -206,8 +206,7 @@ void **dlindependent_calloc(size_t n_elements, size_t elem_size, * int msglen = strlen(msg); * size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) }; * void* chunks[3]; - * if (independent_comalloc(3, sizes, chunks) == 0) - * die(); + * if (independent_comalloc(3, sizes, chunks) == 0) __die(); * struct Head* head = (struct Head*)(chunks[0]); * char* body = (char*)(chunks[1]); * struct Foot* foot = (struct Foot*)(chunks[2]); diff --git a/third_party/dlmalloc/dlmalloc-debug.c b/third_party/dlmalloc/dlmalloc-debug.c index 6111165f..bd420950 100644 --- a/third_party/dlmalloc/dlmalloc-debug.c +++ b/third_party/dlmalloc/dlmalloc-debug.c @@ -1,4 +1,4 @@ -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /* Check properties of any chunk, whether free, inuse, mmapped etc */ forceinline void do_check_any_chunk(mstate m, mchunkptr p) { diff --git a/third_party/dlmalloc/dlmalloc-usable.c b/third_party/dlmalloc/dlmalloc-usable.c index 5443694c..8ee9b31f 100644 --- a/third_party/dlmalloc/dlmalloc-usable.c +++ b/third_party/dlmalloc/dlmalloc-usable.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" size_t dlmalloc_usable_size(const void* mem) { if (mem != 0) { diff --git a/third_party/dlmalloc/dlmalloc.c b/third_party/dlmalloc/dlmalloc.c index 8699b5cd..db428e4a 100644 --- a/third_party/dlmalloc/dlmalloc.c +++ b/third_party/dlmalloc/dlmalloc.c @@ -1,5 +1,5 @@ -#include "libc/bits/initializer.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/initializer.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/internal.h" #include "libc/calls/struct/sysinfo.h" #include "libc/conv/conv.h" @@ -14,7 +14,7 @@ #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" #include "libc/sysv/errfuns.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" STATIC_YOINK("_init_dlmalloc"); diff --git a/third_party/dlmalloc/dlmalloc.h b/third_party/dlmalloc/dlmalloc.internal.h similarity index 100% rename from third_party/dlmalloc/dlmalloc.h rename to third_party/dlmalloc/dlmalloc.internal.h diff --git a/third_party/dlmalloc/dlmalloc_stats.c b/third_party/dlmalloc/dlmalloc_stats.c index e3592ab4..adabaada 100644 --- a/third_party/dlmalloc/dlmalloc_stats.c +++ b/third_party/dlmalloc/dlmalloc_stats.c @@ -1,6 +1,6 @@ -#include "third_party/dlmalloc/dlmalloc.h" #include "libc/mem/mem.h" #include "libc/str/str.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Prints on stderr the amount of space obtained from the system (both diff --git a/third_party/dlmalloc/dlmalloc_try_realloc_chunk.c b/third_party/dlmalloc/dlmalloc_try_realloc_chunk.c index cfac7f46..b3a6c937 100644 --- a/third_party/dlmalloc/dlmalloc_try_realloc_chunk.c +++ b/third_party/dlmalloc/dlmalloc_try_realloc_chunk.c @@ -1,4 +1,4 @@ -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /* Realloc using mmap */ static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb, int flags) { diff --git a/third_party/dlmalloc/dlmemalign-impl.c b/third_party/dlmalloc/dlmemalign-impl.c index a29b85cd..a1725bf3 100644 --- a/third_party/dlmalloc/dlmemalign-impl.c +++ b/third_party/dlmalloc/dlmemalign-impl.c @@ -1,7 +1,7 @@ #include "libc/bits/bits.h" #include "libc/mem/mem.h" #include "libc/sysv/errfuns.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" void* dlmemalign$impl(mstate m, size_t alignment, size_t bytes) { void* mem = 0; diff --git a/third_party/dlmalloc/dlmemalign.c b/third_party/dlmalloc/dlmemalign.c index dcc6812a..26b679c5 100644 --- a/third_party/dlmalloc/dlmemalign.c +++ b/third_party/dlmalloc/dlmemalign.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" void *dlmemalign(size_t alignment, size_t bytes) { if (alignment <= MALLOC_ALIGNMENT) return dlmalloc(bytes); diff --git a/third_party/dlmalloc/dlposix_memalign.c b/third_party/dlmalloc/dlposix_memalign.c index d46d2ad8..2f50d2de 100644 --- a/third_party/dlmalloc/dlposix_memalign.c +++ b/third_party/dlmalloc/dlposix_memalign.c @@ -1,7 +1,7 @@ #include "libc/errno.h" #include "libc/mem/mem.h" #include "libc/sysv/errfuns.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" int dlposix_memalign(void** pp, size_t alignment, size_t bytes) { void* mem; diff --git a/third_party/dlmalloc/dlpvalloc.c b/third_party/dlmalloc/dlpvalloc.c index 882ba7ab..ac81aa18 100644 --- a/third_party/dlmalloc/dlpvalloc.c +++ b/third_party/dlmalloc/dlpvalloc.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" void *dlpvalloc(size_t bytes) { size_t pagesz; diff --git a/third_party/dlmalloc/dlrealloc.c b/third_party/dlmalloc/dlrealloc.c index 0bdb8c3f..32229258 100644 --- a/third_party/dlmalloc/dlrealloc.c +++ b/third_party/dlmalloc/dlrealloc.c @@ -1,6 +1,6 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" void *dlrealloc(void *oldmem, size_t bytes) { void *mem = 0; diff --git a/third_party/dlmalloc/dlrealloc_in_place.c b/third_party/dlmalloc/dlrealloc_in_place.c index 9ed4020d..ab9bbc9b 100644 --- a/third_party/dlmalloc/dlrealloc_in_place.c +++ b/third_party/dlmalloc/dlrealloc_in_place.c @@ -1,6 +1,6 @@ #include "libc/mem/mem.h" #include "libc/sysv/errfuns.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" void *dlrealloc_in_place(void *oldmem, size_t bytes) { void *mem = 0; diff --git a/third_party/dlmalloc/dlvalloc.c b/third_party/dlmalloc/dlvalloc.c index a9cbef80..ee75da4c 100644 --- a/third_party/dlmalloc/dlvalloc.c +++ b/third_party/dlmalloc/dlvalloc.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" void *dlvalloc(size_t bytes) { size_t pagesz; diff --git a/third_party/dlmalloc/mallinfo.c b/third_party/dlmalloc/mallinfo.c index 56a0afd7..4d8b0e88 100644 --- a/third_party/dlmalloc/mallinfo.c +++ b/third_party/dlmalloc/mallinfo.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Returns (by copy) a struct containing various summary statistics: diff --git a/third_party/dlmalloc/malloc_footprint.c b/third_party/dlmalloc/malloc_footprint.c index b340e0d9..818f8cc7 100644 --- a/third_party/dlmalloc/malloc_footprint.c +++ b/third_party/dlmalloc/malloc_footprint.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Returns the number of bytes obtained from the system. The total diff --git a/third_party/dlmalloc/malloc_footprint_limit.c b/third_party/dlmalloc/malloc_footprint_limit.c index 295e02b9..84cd9bc4 100644 --- a/third_party/dlmalloc/malloc_footprint_limit.c +++ b/third_party/dlmalloc/malloc_footprint_limit.c @@ -1,6 +1,6 @@ #include "libc/limits.h" #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Returns the number of bytes that the heap is allowed to obtain from diff --git a/third_party/dlmalloc/malloc_inspect_all.c b/third_party/dlmalloc/malloc_inspect_all.c index 96d336b2..9fc415ca 100644 --- a/third_party/dlmalloc/malloc_inspect_all.c +++ b/third_party/dlmalloc/malloc_inspect_all.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" static void internal_inspect_all(mstate m, void (*handler)(void* start, void* end, diff --git a/third_party/dlmalloc/malloc_max_footprint.c b/third_party/dlmalloc/malloc_max_footprint.c index 68fdaca2..301b2b98 100644 --- a/third_party/dlmalloc/malloc_max_footprint.c +++ b/third_party/dlmalloc/malloc_max_footprint.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Returns the maximum number of bytes obtained from the system. This diff --git a/third_party/dlmalloc/malloc_set_footprint_limit.c b/third_party/dlmalloc/malloc_set_footprint_limit.c index 47c842f8..68d84042 100644 --- a/third_party/dlmalloc/malloc_set_footprint_limit.c +++ b/third_party/dlmalloc/malloc_set_footprint_limit.c @@ -1,6 +1,6 @@ #include "libc/limits.h" #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Sets the maximum number of bytes to obtain from the system, causing diff --git a/third_party/dlmalloc/malloc_trim.c b/third_party/dlmalloc/malloc_trim.c index ef361c08..a2657b18 100644 --- a/third_party/dlmalloc/malloc_trim.c +++ b/third_party/dlmalloc/malloc_trim.c @@ -1,5 +1,5 @@ #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * If possible, gives memory back to the system (via negative arguments diff --git a/third_party/dlmalloc/mallopt.c b/third_party/dlmalloc/mallopt.c index e8a300da..67fe25ff 100644 --- a/third_party/dlmalloc/mallopt.c +++ b/third_party/dlmalloc/mallopt.c @@ -1,6 +1,6 @@ #include "libc/limits.h" #include "libc/mem/mem.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" /** * Sets memory allocation parameter. diff --git a/third_party/dlmalloc/mtrace.c b/third_party/dlmalloc/mtrace.c index 038eea47..f1ed4543 100644 --- a/third_party/dlmalloc/mtrace.c +++ b/third_party/dlmalloc/mtrace.c @@ -18,9 +18,9 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/conv/itoa.h" -#include "libc/runtime/missioncritical.h" +#include "libc/runtime/runtime.h" #include "libc/str/str.h" -#include "third_party/dlmalloc/dlmalloc.h" +#include "third_party/dlmalloc/dlmalloc.internal.h" static uintptr_t lastfree_; diff --git a/third_party/lex/flexdef.h b/third_party/lex/flexdef.h index e069fd97..33ca638e 100644 --- a/third_party/lex/flexdef.h +++ b/third_party/lex/flexdef.h @@ -2,7 +2,7 @@ #include "libc/stdio/stdio.h" #include "libc/runtime/runtime.h" #include "libc/macros.h" -#include "libc/calls/openbsd.h" +#include "libc/calls/openbsd.internal.h" /* $OpenBSD: flexdef.h,v 1.15 2015/11/19 23:48:06 tedu Exp $ */ diff --git a/third_party/lex/main.c b/third_party/lex/main.c index 4dc934ee..5b19a657 100644 --- a/third_party/lex/main.c +++ b/third_party/lex/main.c @@ -56,8 +56,8 @@ asm(".include \"third_party/lex/COPYING\""); #include "libc/x/x.h" #include "libc/runtime/runtime.h" #include "libc/x/x.h" -#include "libc/bits/safemacros.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" +#include "libc/bits/safemacros.internal.h" #include "tables.h" static char flex_version[] = FLEX_VERSION; diff --git a/third_party/lz4cli/bench.c b/third_party/lz4cli/bench.c index 9fcb3384..9906cbb3 100644 --- a/third_party/lz4cli/bench.c +++ b/third_party/lz4cli/bench.c @@ -43,8 +43,7 @@ #include "libc/stdio/stdio.h" /* fprintf, fopen, ftello */ #include "libc/time/time.h" /* clock_t, clock, CLOCKS_PER_SEC */ #include "libc/assert.h" -#include "libc/bits/initializer.h" -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/runtime/runtime.h" /* assert */ #include "datagen.h" /* RDG_genBuffer */ diff --git a/third_party/lz4cli/lz4io.c b/third_party/lz4cli/lz4io.c index 313696a9..3ade722f 100644 --- a/third_party/lz4cli/lz4io.c +++ b/third_party/lz4cli/lz4io.c @@ -54,7 +54,7 @@ #include "third_party/lz4cli/lz4hc.h" /* still required for legacy format */ #define LZ4F_STATIC_LINKING_ONLY #include "libc/runtime/runtime.h" -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "third_party/lz4cli/lz4frame.h" diff --git a/third_party/m4/eval.c b/third_party/m4/eval.c index c24e4db5..595f6dc6 100644 --- a/third_party/m4/eval.c +++ b/third_party/m4/eval.c @@ -40,7 +40,7 @@ * by: oz */ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/conv.h" #include "libc/errno.h" #include "libc/limits.h" diff --git a/third_party/m4/main.c b/third_party/m4/main.c index d096b3ca..4ad050b3 100644 --- a/third_party/m4/main.c +++ b/third_party/m4/main.c @@ -44,7 +44,7 @@ asm(".include \"third_party/m4/COPYING\""); #include "libc/assert.h" #include "libc/log/bsd.h" -#include "libc/calls/openbsd.h" +#include "libc/calls/openbsd.internal.h" #include "libc/calls/calls.h" #include "libc/sysv/consts/sig.h" #include "third_party/getopt/getopt.h" diff --git a/third_party/regex/regerror.c b/third_party/regex/regerror.c index 385ed947..c0c40630 100644 --- a/third_party/regex/regerror.c +++ b/third_party/regex/regerror.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/fmt/fmt.h" #include "libc/str/str.h" #include "third_party/regex/regex.h" diff --git a/third_party/stb/stb_image.c b/third_party/stb/stb_image.c index 52435e60..7a5418a0 100644 --- a/third_party/stb/stb_image.c +++ b/third_party/stb/stb_image.c @@ -35,6 +35,8 @@ #include "third_party/stb/internal.h" #include "third_party/stb/stb_image.h" +#define ROL(w, k) ((w) << (k) | CheckUnsigned(w) >> (sizeof(w) * 8 - (k))) + asm(".ident\t\"\\n\\n\ stb_image (Public Domain)\\n\ Credit: Sean Barrett, et al.\\n\ diff --git a/third_party/zlib/adler32simd.c b/third_party/zlib/adler32simd.c index 1e1f5a28..91ff6e67 100644 --- a/third_party/zlib/adler32simd.c +++ b/third_party/zlib/adler32simd.c @@ -5,8 +5,8 @@ │ Use of this source code is governed by the BSD-style licenses that can │ │ be found in the third_party/zlib/LICENSE file. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/emmintrin.h" -#include "libc/bits/tmmintrin.h" +#include "libc/bits/emmintrin.internal.h" +#include "libc/bits/tmmintrin.internal.h" #include "third_party/zlib/internal.h" asm(".ident\t\"\\n\\n\ diff --git a/third_party/zlib/chunkcopy.h b/third_party/zlib/chunkcopy.h index 47a32608..cc12ba0f 100644 --- a/third_party/zlib/chunkcopy.h +++ b/third_party/zlib/chunkcopy.h @@ -1,6 +1,6 @@ #ifndef THIRD_PARTY_ZLIB_CHUNKCOPY_H #define THIRD_PARTY_ZLIB_CHUNKCOPY_H -#include "libc/bits/emmintrin.h" +#include "libc/bits/emmintrin.internal.h" #include "third_party/zlib/zutil.h" asm(".ident\t\"\\n\\n\ diff --git a/third_party/zlib/crcfold.c b/third_party/zlib/crcfold.c index 45d08a4d..e414840a 100644 --- a/third_party/zlib/crcfold.c +++ b/third_party/zlib/crcfold.c @@ -5,10 +5,10 @@ │ Use of this source code is governed by the BSD-style licenses that can │ │ be found in the third_party/zlib/LICENSE file. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/emmintrin.h" -#include "libc/bits/smmintrin.h" -#include "libc/bits/tmmintrin.h" -#include "libc/bits/wmmintrin.h" +#include "libc/bits/emmintrin.internal.h" +#include "libc/bits/smmintrin.internal.h" +#include "libc/bits/tmmintrin.internal.h" +#include "libc/bits/wmmintrin.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "third_party/zlib/deflate.h" diff --git a/third_party/zlib/deflatesse.c b/third_party/zlib/deflatesse.c index 88a4ae8f..72d6e41f 100644 --- a/third_party/zlib/deflatesse.c +++ b/third_party/zlib/deflatesse.c @@ -5,7 +5,7 @@ │ Use of this source code is governed by the BSD-style licenses that can │ │ be found in the third_party/zlib/LICENSE file. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/emmintrin.h" +#include "libc/bits/emmintrin.internal.h" #include "libc/str/str.h" #include "third_party/zlib/deflate.h" #include "third_party/zlib/internal.h" diff --git a/tool/build/ar.c b/tool/build/ar.c index 4e484dd9..7261f702 100644 --- a/tool/build/ar.c +++ b/tool/build/ar.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/bits/bits.h" #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" @@ -29,6 +29,7 @@ #include "libc/errno.h" #include "libc/log/check.h" #include "libc/macros.h" +#include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/tool/build/blinkenlights.c b/tool/build/blinkenlights.c index 8e1823ab..53b57ea6 100644 --- a/tool/build/blinkenlights.c +++ b/tool/build/blinkenlights.c @@ -19,10 +19,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/scale/cdecimate2xuint8x8.h" #include "dsp/tty/tty.h" -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/iovec.h" @@ -34,12 +34,12 @@ #include "libc/conv/conv.h" #include "libc/conv/itoa.h" #include "libc/errno.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/fmt/fmt.h" #include "libc/intrin/pcmpeqb.h" #include "libc/intrin/pmovmskb.h" #include "libc/log/check.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/log.h" #include "libc/macros.h" #include "libc/math.h" @@ -50,8 +50,8 @@ #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/thompike.h" -#include "libc/str/tpdecode.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpdecode.internal.h" +#include "libc/str/tpencode.internal.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/exit.h" diff --git a/tool/build/calculator.c b/tool/build/calculator.c index 495f3502..83e6d42e 100644 --- a/tool/build/calculator.c +++ b/tool/build/calculator.c @@ -8,7 +8,7 @@ ╚─────────────────────────────────────────────────────────────────*/ #endif #include "dsp/tty/tty.h" -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/assert.h" #include "libc/bits/bits.h" #include "libc/bits/morton.h" @@ -19,7 +19,7 @@ #include "libc/dce.h" #include "libc/fmt/fmt.h" #include "libc/limits.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/log.h" #include "libc/macros.h" #include "libc/math.h" diff --git a/tool/build/emubin/metalsha256.c b/tool/build/emubin/metalsha256.c index dae5634b..031e2a3a 100644 --- a/tool/build/emubin/metalsha256.c +++ b/tool/build/emubin/metalsha256.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/intrin/repstosb.h" #include "tool/build/emubin/metalsha256.h" diff --git a/tool/build/helpop.c b/tool/build/helpop.c index 53860592..3196d415 100644 --- a/tool/build/helpop.c +++ b/tool/build/helpop.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/conv.h" #include "libc/macros.h" #include "libc/runtime/runtime.h" diff --git a/tool/build/img2code.c b/tool/build/img2code.c index 4c351f80..5e2a8e65 100644 --- a/tool/build/img2code.c +++ b/tool/build/img2code.c @@ -21,7 +21,7 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/conv/conv.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" diff --git a/tool/build/lib/breakpoint.c b/tool/build/lib/breakpoint.c index 2c8b43c5..73aabc90 100644 --- a/tool/build/lib/breakpoint.c +++ b/tool/build/lib/breakpoint.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/assert.h" #include "libc/log/log.h" #include "tool/build/lib/breakpoint.h" diff --git a/tool/build/lib/buffer.c b/tool/build/lib/buffer.c index 900404a3..74d781ea 100644 --- a/tool/build/lib/buffer.c +++ b/tool/build/lib/buffer.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" diff --git a/tool/build/lib/demangle.c b/tool/build/lib/demangle.c index 1ada7671..5023e888 100644 --- a/tool/build/lib/demangle.c +++ b/tool/build/lib/demangle.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" #include "libc/calls/struct/iovec.h" diff --git a/tool/build/lib/dis.c b/tool/build/lib/dis.c index 1da54f6c..6d9b2304 100644 --- a/tool/build/lib/dis.c +++ b/tool/build/lib/dis.c @@ -18,10 +18,10 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist2.h" -#include "libc/bits/safemacros.h" +#include "libc/alg/arraylist2.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/itoa.h" -#include "libc/fmt/bing.h" +#include "libc/fmt/bing.internal.h" #include "libc/fmt/fmt.h" #include "libc/log/check.h" #include "libc/log/log.h" @@ -29,7 +29,7 @@ #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" -#include "libc/str/tpencode.h" +#include "libc/str/tpencode.internal.h" #include "third_party/xed/x86.h" #include "tool/build/lib/case.h" #include "tool/build/lib/demangle.h" diff --git a/tool/build/lib/diself.c b/tool/build/lib/diself.c index 9dab5071..5f46ce81 100644 --- a/tool/build/lib/diself.c +++ b/tool/build/lib/diself.c @@ -58,7 +58,7 @@ static void DisLoadElfLoads(struct Dis *d, struct Elf *elf) { CHECK_NOTNULL(d->loads.p); } for (i = 0; i < n; ++i) { - phdr = getelfsegmentheaderaddress(elf->ehdr, elf->size, i); + phdr = GetElfSegmentHeaderAddress(elf->ehdr, elf->size, i); if (phdr->p_type != PT_LOAD) continue; d->loads.p[j].addr = phdr->p_vaddr; d->loads.p[j].size = phdr->p_memsz; diff --git a/tool/build/lib/disinst.c b/tool/build/lib/disinst.c index dfb7e47d..77eb212a 100644 --- a/tool/build/lib/disinst.c +++ b/tool/build/lib/disinst.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/check.h" -#include "libc/nexgen32e/tinystrcmp.h" +#include "libc/nexgen32e/tinystrcmp.internal.h" #include "libc/str/str.h" #include "third_party/zlib/zlib.h" #include "tool/build/lib/dis.h" diff --git a/tool/build/lib/elfwriter.c b/tool/build/lib/elfwriter.c index 6941826b..33b8c1e6 100644 --- a/tool/build/lib/elfwriter.c +++ b/tool/build/lib/elfwriter.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/log/check.h" diff --git a/tool/build/lib/fds.c b/tool/build/lib/fds.c index 24187658..57e29023 100644 --- a/tool/build/lib/fds.c +++ b/tool/build/lib/fds.c @@ -33,7 +33,7 @@ int MachineFdAdd(struct MachineFds *mf) { } else { DCHECK_LE(mf->i, mf->n); if (mf->i == mf->n) { - if (!grow(&mf->p, &mf->n, sizeof(struct MachineFd), 0)) { + if (!__grow(&mf->p, &mf->n, sizeof(struct MachineFd), 0)) { return -1; } } diff --git a/tool/build/lib/interner.c b/tool/build/lib/interner.c index cd852228..109b87cc 100644 --- a/tool/build/lib/interner.c +++ b/tool/build/lib/interner.c @@ -17,9 +17,9 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" -#include "libc/alg/arraylist2.h" -#include "libc/bits/safemacros.h" +#include "libc/alg/arraylist.internal.h" +#include "libc/alg/arraylist2.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/mem/mem.h" #include "libc/str/knuthmultiplicativehash.h" #include "libc/str/str.h" diff --git a/tool/build/lib/ioports.c b/tool/build/lib/ioports.c index b8b2a263..15021d22 100644 --- a/tool/build/lib/ioports.c +++ b/tool/build/lib/ioports.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/iovec.h" -#include "libc/nexgen32e/uart.h" +#include "libc/nexgen32e/uart.internal.h" #include "libc/sysv/consts/fileno.h" #include "tool/build/lib/ioports.h" diff --git a/tool/build/lib/loader.c b/tool/build/lib/loader.c index 95b315d7..f1f5f20d 100644 --- a/tool/build/lib/loader.c +++ b/tool/build/lib/loader.c @@ -25,7 +25,7 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.h" -#include "libc/nexgen32e/vendor.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/fileno.h" @@ -81,7 +81,7 @@ static void LoadElf(struct Machine *m, struct Elf *elf) { m->ip = elf->base = elf->ehdr->e_entry; VERBOSEF("LOADELF ENTRY %p", m->ip); for (i = 0; i < elf->ehdr->e_phnum; ++i) { - phdr = getelfsegmentheaderaddress(elf->ehdr, elf->size, i); + phdr = GetElfSegmentHeaderAddress(elf->ehdr, elf->size, i); switch (phdr->p_type) { case PT_LOAD: elf->base = MIN(elf->base, phdr->p_vaddr); diff --git a/tool/build/lib/panel.c b/tool/build/lib/panel.c index c144e800..b5adea96 100644 --- a/tool/build/lib/panel.c +++ b/tool/build/lib/panel.c @@ -17,11 +17,11 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/conv.h" #include "libc/mem/mem.h" #include "libc/str/str.h" -#include "libc/str/tpdecode.h" +#include "libc/str/tpdecode.internal.h" #include "libc/unicode/unicode.h" #include "tool/build/lib/buffer.h" #include "tool/build/lib/panel.h" diff --git a/tool/build/lib/pml4t.c b/tool/build/lib/pml4t.c index d7378638..18b80c36 100644 --- a/tool/build/lib/pml4t.c +++ b/tool/build/lib/pml4t.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "tool/build/lib/endian.h" #include "tool/build/lib/machine.h" #include "tool/build/lib/pml4t.h" diff --git a/tool/build/lib/pty.c b/tool/build/lib/pty.c index c7464602..b4022ca1 100644 --- a/tool/build/lib/pty.c +++ b/tool/build/lib/pty.c @@ -17,10 +17,10 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/conv.h" #include "libc/conv/itoa.h" #include "libc/log/check.h" diff --git a/tool/build/lib/syscall.c b/tool/build/lib/syscall.c index 7d7ea1c1..b5353a15 100644 --- a/tool/build/lib/syscall.c +++ b/tool/build/lib/syscall.c @@ -22,7 +22,7 @@ #include "libc/calls/ioctl.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/rusage.h" -#include "libc/calls/struct/sigaction-linux.h" +#include "libc/calls/struct/sigaction-linux.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/termios.h" @@ -35,9 +35,10 @@ #include "libc/log/log.h" #include "libc/macros.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/vendor.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/runtime/gc.h" #include "libc/runtime/runtime.h" +#include "libc/sock/select.h" #include "libc/sock/sock.h" #include "libc/str/str.h" #include "libc/sysv/consts/af.h" diff --git a/tool/build/lib/throw.c b/tool/build/lib/throw.c index 82f77f88..497acb6a 100644 --- a/tool/build/lib/throw.c +++ b/tool/build/lib/throw.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/check.h" #include "libc/log/log.h" -#include "libc/nexgen32e/vendor.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/runtime/gc.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" diff --git a/tool/build/mkdeps.c b/tool/build/mkdeps.c index 9bb62b91..0e56abdb 100644 --- a/tool/build/mkdeps.c +++ b/tool/build/mkdeps.c @@ -18,12 +18,12 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist.h" -#include "libc/alg/arraylist2.h" -#include "libc/alg/bisectcarleft.h" +#include "libc/alg/arraylist.internal.h" +#include "libc/alg/arraylist2.internal.h" +#include "libc/alg/bisectcarleft.internal.h" #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/errno.h" diff --git a/tool/build/package.c b/tool/build/package.c index 81a762a6..97e4a30a 100644 --- a/tool/build/package.c +++ b/tool/build/package.c @@ -18,12 +18,12 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" -#include "libc/alg/arraylist.h" -#include "libc/alg/bisect.h" -#include "libc/alg/bisectcarleft.h" +#include "libc/alg/arraylist.internal.h" +#include "libc/alg/bisect.internal.h" +#include "libc/alg/bisectcarleft.internal.h" #include "libc/assert.h" #include "libc/bits/bswap.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/conv/conv.h" @@ -263,7 +263,7 @@ void IndexSections(struct Object *obj) { struct XedDecodedInst xedd; for (i = 0; i < obj->elf->e_shnum; ++i) { memset(§, 0, sizeof(sect)); - CHECK_NOTNULL((shdr = getelfsectionheaderaddress(obj->elf, obj->size, i))); + CHECK_NOTNULL((shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i))); if (shdr->sh_type != SHT_NULL) { CHECK_NOTNULL((name = GetElfSectionName(obj->elf, obj->size, shdr))); if (startswith(name, ".sort.")) name += 5; @@ -289,7 +289,7 @@ void IndexSections(struct Object *obj) { sect.kind = kUndef; /* should always and only be section #0 */ } if (shdr->sh_flags & SHF_EXECINSTR) { - CHECK_NOTNULL((code = getelfsectionaddress(obj->elf, obj->size, shdr))); + CHECK_NOTNULL((code = GetElfSectionAddress(obj->elf, obj->size, shdr))); for (op.offset = 0; op.offset < shdr->sh_size; op.offset += op.length) { if (xed_instruction_length_decode( xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64), @@ -453,15 +453,15 @@ void OptimizeRelocations(struct Package *pkg, struct Packages *deps, unsigned char *code, *p; Elf64_Shdr *shdr, *shdrcode; for (i = 0; i < obj->elf->e_shnum; ++i) { - shdr = getelfsectionheaderaddress(obj->elf, obj->size, i); + shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i); if (shdr->sh_type == SHT_RELA) { CHECK_EQ(sizeof(struct Elf64_Rela), shdr->sh_entsize); - CHECK_NOTNULL((shdrcode = getelfsectionheaderaddress(obj->elf, obj->size, + CHECK_NOTNULL((shdrcode = GetElfSectionHeaderAddress(obj->elf, obj->size, shdr->sh_info))); if (!(shdrcode->sh_flags & SHF_EXECINSTR)) continue; CHECK_NOTNULL( - (code = getelfsectionaddress(obj->elf, obj->size, shdrcode))); - for (rela = getelfsectionaddress(obj->elf, obj->size, shdr); + (code = GetElfSectionAddress(obj->elf, obj->size, shdrcode))); + for (rela = GetElfSectionAddress(obj->elf, obj->size, shdr); ((uintptr_t)rela + shdr->sh_entsize <= min((uintptr_t)obj->elf + obj->size, (uintptr_t)obj->elf + shdr->sh_offset + shdr->sh_size)); @@ -594,12 +594,12 @@ void CompressLowEntropyReadOnlyDataSections(struct Package *pkg, memset(&rle, 0, sizeof(rle)); haverldecode = IsSymbolDirectlyReachable(pkg, deps, "rldecode"); for (i = 0; i < obj->elf->e_shnum; ++i) { - if ((shdr = getelfsectionheaderaddress(obj->elf, obj->size, i)) && + if ((shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i)) && shdr->sh_size >= 256 && (shdr->sh_type == SHT_PROGBITS && !(shdr->sh_flags & (SHF_WRITE | SHF_MERGE | SHF_STRINGS | SHF_COMPRESSED))) && - (p = getelfsectionaddress(obj->elf, obj->size, shdr)) && + (p = GetElfSectionAddress(obj->elf, obj->size, shdr)) && startswith((name = GetElfSectionName(obj->elf, obj->size, shdr)), ".rodata") && rlencode(&rle, p, shdr->sh_size) != -1) { diff --git a/tool/build/refactor.c b/tool/build/refactor.c index 349619a0..254d211a 100644 --- a/tool/build/refactor.c +++ b/tool/build/refactor.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" #include "libc/assert.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/stat.h" diff --git a/tool/build/rollup.c b/tool/build/rollup.c new file mode 100644 index 00000000..3da44bd0 --- /dev/null +++ b/tool/build/rollup.c @@ -0,0 +1,149 @@ +/*-*- 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 │ +│ │ +│ This program is free software; you can redistribute it and/or modify │ +│ it under the terms of the GNU General Public License as published by │ +│ the Free Software Foundation; version 2 of the License. │ +│ │ +│ This program is distributed in the hope that it will be useful, but │ +│ WITHOUT ANY WARRANTY; without even the implied warranty of │ +│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ +│ General Public License for more details. │ +│ │ +│ You should have received a copy of the GNU General Public License │ +│ along with this program; if not, write to the Free Software │ +│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ +│ 02110-1301 USA │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/alg/arraylist2.internal.h" +#include "libc/calls/calls.h" +#include "libc/calls/struct/stat.h" +#include "libc/conv/itoa.h" +#include "libc/log/check.h" +#include "libc/log/log.h" +#include "libc/mem/mem.h" +#include "libc/runtime/runtime.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/map.h" +#include "libc/sysv/consts/o.h" +#include "libc/sysv/consts/prot.h" + +#define LOOKINGAT(p, pe, s) LookingAt(p, pe, s, strlen(s)) +#define APPENDSTR(s) AppendData(s, strlen(s)) + +struct Output { + size_t i, n; + const char *p; +}; + +struct Visited { + size_t i, n; + const char **p; +}; + +static struct stat st; +static struct Output output; +static struct Visited visited; + +static void Visit(const char *); + +static bool HasVisited(const char *path) { + int i; + for (i = 0; i < visited.i; ++i) { + if (strcmp(path, visited.p[i]) == 0) { + return true; + } + } + return false; +} + +static void AppendData(const char *s, size_t n) { + CONCAT(&output.p, &output.i, &output.n, s, n); +} + +static void AppendInt(long x) { + char ibuf[21]; + AppendData(ibuf, int64toarray_radix10(x, ibuf)); +} + +static bool LookingAt(const char *p, const char *pe, const char *s, size_t n) { + return pe - p >= n && memcmp(p, s, n) == 0; +} + +static void Process(const char *p, const char *pe, const char *path, + bool isheader) { + int level; + bool noformat; + const char *p2, *dq, *name; + for (noformat = level = 0; p < pe; p = p2) { + p2 = memchr(p, '\n', pe - p); + p2 = p2 ? p2 + 1 : pe; + if (LOOKINGAT(p, pe, "#if")) { + if (isheader && !level++) continue; + } + if (LOOKINGAT(p, pe, "#endif")) { + if (isheader && !--level) continue; + } + if (LOOKINGAT(p, pe, "/* clang-format off */")) { + noformat = true; + } else if (LOOKINGAT(p, pe, "/* clang-format on */")) { + noformat = false; + } + if (LOOKINGAT(p, pe, "#include \"")) { + name = p + strlen("#include \""); + dq = memchr(name, '"', pe - name); + if (dq) { + Visit(strndup(name, dq - name)); + continue; + } + } + AppendData(p, p2 - p); + } + if (noformat) { + APPENDSTR("/* clang-format on */\n"); + } +} + +static void Visit(const char *path) { + int fd; + char *map; + bool isheader; + if (!endswith(path, ".h") && !endswith(path, ".inc")) return; + if (endswith(path, ".internal.h")) return; + if (endswith(path, "/internal.h")) return; + if (endswith(path, ".internal.inc")) return; + if (endswith(path, "/internal.inc")) return; + isheader = endswith(path, ".h"); + if (isheader && HasVisited(path)) return; + APPENDSTR("\n\f\n/*!BEGIN "); + APPENDSTR(path); + APPENDSTR(" */\n\n"); + APPEND(&visited.p, &visited.i, &visited.n, &path); + CHECK_NE(-1, (fd = open(path, O_RDONLY))); + CHECK_NE(-1, fstat(fd, &st)); + if (st.st_size) { + CHECK_NE(MAP_FAILED, + (map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0))); + Process(map, map + st.st_size, path, isheader); + LOGIFNEG1(munmap(map, st.st_size)); + } + LOGIFNEG1(close(fd)); +} + +int main(int argc, char *argv[]) { + int i; + APPENDSTR("#ifndef COSMOPOLITAN_H_\n"); + APPENDSTR("#define COSMOPOLITAN_H_\n"); + APPENDSTR("#define IMAGE_BASE_VIRTUAL "); + AppendInt(IMAGE_BASE_VIRTUAL); + APPENDSTR("\n"); + for (i = 1; i < argc; ++i) { + Visit(argv[i]); + } + APPENDSTR("\n"); + APPENDSTR("#endif /* COSMOPOLITAN_H_ */\n"); + CHECK_EQ(output.i, write(1, output.p, output.i)); + return 0; +} diff --git a/tool/build/runit.c b/tool/build/runit.c index d4de766e..d3619dc1 100644 --- a/tool/build/runit.c +++ b/tool/build/runit.c @@ -19,7 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/alg.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" #include "libc/calls/struct/itimerval.h" @@ -36,7 +36,7 @@ #include "libc/mem/mem.h" #include "libc/runtime/gc.h" #include "libc/runtime/runtime.h" -#include "libc/sock/ipclassify.h" +#include "libc/sock/ipclassify.internal.h" #include "libc/sock/sock.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -303,7 +303,7 @@ int ReadResponse(void) { } break; default: - die(); + __die(); } } while (n); } diff --git a/tool/build/runitd.c b/tool/build/runitd.c index d2614a83..9d4433ca 100644 --- a/tool/build/runitd.c +++ b/tool/build/runitd.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" #include "libc/calls/struct/sigaction.h" diff --git a/tool/build/winterm.c b/tool/build/winterm.c deleted file mode 100644 index e4fbabc5..00000000 --- a/tool/build/winterm.c +++ /dev/null @@ -1,89 +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 │ -│ │ -│ This program is free software; you can redistribute it and/or modify │ -│ it under the terms of the GNU General Public License as published by │ -│ the Free Software Foundation; version 2 of the License. │ -│ │ -│ This program is distributed in the hope that it will be useful, but │ -│ WITHOUT ANY WARRANTY; without even the implied warranty of │ -│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │ -│ General Public License for more details. │ -│ │ -│ You should have received a copy of the GNU General Public License │ -│ along with this program; if not, write to the Free Software │ -│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ -│ 02110-1301 USA │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/log/check.h" -#include "libc/log/log.h" -#include "libc/nt/dll.h" -#include "libc/nt/enum/color.h" -#include "libc/nt/enum/cw.h" -#include "libc/nt/enum/idc.h" -#include "libc/nt/enum/sw.h" -#include "libc/nt/enum/wm.h" -#include "libc/nt/enum/ws.h" -#include "libc/nt/events.h" -#include "libc/nt/paint.h" -#include "libc/nt/struct/msg.h" -#include "libc/nt/struct/paintstruct.h" -#include "libc/nt/struct/wndclass.h" -#include "libc/nt/windows.h" -#include "libc/runtime/missioncritical.h" -#include "libc/runtime/runtime.h" -#include "libc/runtime/winmain.h" -#include "libc/str/str.h" - -/** - * @fileoverview Incomplete Windows App. - */ - -static const char16_t kClassName[] = u"Sample Window Class"; - -int64_t WindowProcSysv(int64_t hwnd, uint32_t uMsg, uint64_t wParam, - int64_t lParam) { - int64_t hdc; - struct NtPaintStruct ps; - switch (uMsg) { - case kNtWmDestroy: - PostQuitMessage(0); - return 0; - case kNtWmPaint: - hdc = BeginPaint(hwnd, &ps); - FillRect(hdc, &ps.rcPaint, kNtColorWindow + 1); - EndPaint(hwnd, &ps); - return 0; - default: - return DefWindowProc(hwnd, uMsg, wParam, lParam); - } -} - -int64_t WindowProcNt(int64_t, uint32_t, uint64_t, int64_t); -asm("WindowProcNt:\n\t" - "lea\tWindowProcSysv(%rip),%rax\n\t" - "jmp\t__nt2sysv"); - -int main(int argc, char *argv[]) { - int64_t hwnd; - struct NtMsg msg; - struct NtWndClass wc; - memset(&wc, 0, sizeof(wc)); - wc.lpfnWndProc = WindowProcNt; - wc.hInstance = g_winmain.hInstance; - wc.hCursor = LoadCursor(0, kNtIdcIbeam); - wc.lpszClassName = kClassName; - CHECK(RegisterClass(&wc)); - CHECK((hwnd = CreateWindowEx(0, kClassName, u"Learn to Program Windows", - kNtWsOverlappedwindow, kNtCwUsedefault, - kNtCwUsedefault, kNtCwUsedefault, - kNtCwUsedefault, 0, 0, g_winmain.hInstance, 0))); - ShowWindow(hwnd, kNtSwNormal); - while (GetMessage(&msg, 0, 0, 0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - return 0; -} diff --git a/tool/build/zipobj.c b/tool/build/zipobj.c index 397c808a..b7ede745 100644 --- a/tool/build/zipobj.c +++ b/tool/build/zipobj.c @@ -17,13 +17,12 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/timespec.h" -#include "libc/dos.h" #include "libc/elf/def.h" #include "libc/limits.h" #include "libc/log/check.h" @@ -32,10 +31,10 @@ #include "libc/mem/alloca.h" #include "libc/nexgen32e/crc32.h" #include "libc/nt/enum/fileflagandattributes.h" -#include "libc/nt/struct/imageauxsymbolex.h" +#include "libc/nt/struct/imageauxsymbolex.internal.h" #include "libc/runtime/gc.h" #include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.h" +#include "libc/runtime/symbols.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" @@ -62,6 +61,11 @@ P[0] = V & 0xff, P[1] = V >> 010 & 0xff, P[2] = V >> 020 & 0xff, \ P[3] = V >> 030 & 0xff, P += 4 +#define DOS_DATE(YEAR, MONTH_IDX1, DAY_IDX1) \ + (((YEAR)-1980) << 9 | (MONTH_IDX1) << 5 | (DAY_IDX1)) +#define DOS_TIME(HOUR, MINUTE, SECOND) \ + ((HOUR) << 11 | (MINUTE) << 5 | (SECOND) >> 1) + char *symbol_; char *outpath_; char *yoink_; diff --git a/tool/calc/calc.c b/tool/calc/calc.c index 94e9594e..3ff56c7b 100644 --- a/tool/calc/calc.c +++ b/tool/calc/calc.c @@ -18,15 +18,19 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/conv/conv.h" #include "libc/errno.h" #include "libc/log/log.h" #include "libc/macros.h" +#include "libc/math.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/bsf.h" #include "libc/nexgen32e/bsr.h" +#include "libc/nexgen32e/ffs.h" +#include "libc/nexgen32e/x86feature.h" +#include "libc/rand/rand.h" #include "libc/str/str.h" #include "libc/sysv/consts/o.h" #include "libc/time/time.h" @@ -98,6 +102,34 @@ static long double ParseNumber(struct Token t) { } } +static long double FnRand(struct Numbers *a) { + return rand(); +} + +static long double FnRand32(struct Numbers *a) { + return rand32(); +} + +static long double FnRand64(struct Numbers *a) { + return rand64(); +} + +static long double FnRdrand(struct Numbers *a) { + if (X86_HAVE(RDRND)) { + return rdrand(); + } else { + return NAN; + } +} + +static long double FnRdseed(struct Numbers *a) { + if (X86_HAVE(RDSEED)) { + return rdseed(); + } else { + return NAN; + } +} + static long double FnAtan2(struct Numbers *a) { if (!a || !a->n) MissingArgumentError(); return atan2l(a->n->x, a->x); @@ -662,6 +694,11 @@ static const struct Fn { {"pow", FnPow}, {"powi", FnPowi}, {"print", FnPrint}, + {"rand", FnRand}, + {"rand32", FnRand32}, + {"rand64", FnRand64}, + {"rdrand", FnRdrand}, + {"rdseed", FnRdseed}, {"remainder", FnRemainder}, {"rint", FnRint}, {"rol", FnRol}, diff --git a/tool/calc/calc.mk b/tool/calc/calc.mk index 2b5c75e8..601d5e54 100644 --- a/tool/calc/calc.mk +++ b/tool/calc/calc.mk @@ -32,6 +32,7 @@ TOOL_CALC_DIRECTDEPS = \ LIBC_FMT \ LIBC_MEM \ LIBC_NEXGEN32E \ + LIBC_RAND \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STUBS \ diff --git a/tool/decode/elf.c b/tool/decode/elf.c index 739d7f5c..5127b8ef 100644 --- a/tool/decode/elf.c +++ b/tool/decode/elf.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/conv/conv.h" @@ -99,8 +99,8 @@ static void printelfehdr(void) { } static void printelfsegmentheader(int i) { - Elf64_Phdr *phdr = getelfsegmentheaderaddress(elf, st->st_size, i); - printf("/\tElf64_Phdr *phdr = getelfsegmentheaderaddress(elf, st->st_size, " + Elf64_Phdr *phdr = GetElfSegmentHeaderAddress(elf, st->st_size, i); + printf("/\tElf64_Phdr *phdr = GetElfSegmentHeaderAddress(elf, st->st_size, " "%d)\n", i); printf(".Lph%d:", i); @@ -127,8 +127,8 @@ static void printelfsegmentheaders(void) { static void printelfsectionheader(int i, char *shstrtab) { Elf64_Shdr *shdr; - shdr = getelfsectionheaderaddress(elf, st->st_size, i); - printf("/\tElf64_Shdr *shdr = getelfsectionheaderaddress(elf, st->st_size, " + shdr = GetElfSectionHeaderAddress(elf, st->st_size, i); + printf("/\tElf64_Shdr *shdr = GetElfSectionHeaderAddress(elf, st->st_size, " "%d)\n", i); printf(".Lsh%d:", i); @@ -154,7 +154,7 @@ static void printelfsectionheader(int i, char *shstrtab) { static void printelfsectionheaders(void) { Elf64_Half i; - char *shstrtab = getelfsectionnamestringtable(elf, st->st_size); + char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size); if (shstrtab) { printf("\n"); printf("\t.org\t%#x\n", elf->e_shoff); @@ -163,10 +163,10 @@ static void printelfsectionheaders(void) { } printf("\n/\t%s\n", "elf->e_shstrndx"); printf("\t.org\t%#x\n", - getelfsectionheaderaddress(elf, st->st_size, elf->e_shstrndx) + GetElfSectionHeaderAddress(elf, st->st_size, elf->e_shstrndx) ->sh_offset); for (i = 0; i < elf->e_shnum; ++i) { - Elf64_Shdr *shdr = getelfsectionheaderaddress(elf, st->st_size, i); + Elf64_Shdr *shdr = GetElfSectionHeaderAddress(elf, st->st_size, i); const char *str = GetElfString(elf, st->st_size, shstrtab, shdr->sh_name); show(".asciz", format(b1, "%`'s", str), NULL); } @@ -207,7 +207,7 @@ static void printelfsymbol(Elf64_Sym *sym, char *strtab, char *shstrtab) { sym->st_shndx < 0xff00 ? format(b1, "%`'s", GetElfString(elf, st->st_size, shstrtab, - getelfsectionheaderaddress( + GetElfSectionHeaderAddress( elf, st->st_size, sym->st_shndx) ->sh_name)) : findnamebyid(kElfSpecialSectionNames, sym->st_shndx))); @@ -219,7 +219,7 @@ static void printelfsymboltable(void) { size_t i, symcount = 0; Elf64_Sym *symtab = GetElfSymbolTable(elf, st->st_size, &symcount); char *strtab = GetElfStringTable(elf, st->st_size); - char *shstrtab = getelfsectionnamestringtable(elf, st->st_size); + char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size); if (symtab && strtab) { printf("\n\n"); printf("\t.org\t%#x\n", (intptr_t)symtab - (intptr_t)elf); @@ -238,7 +238,7 @@ static char *getelfsymbolname(const Elf64_Ehdr *elf, size_t mapsize, if (elf && sym && ((shstrtab && !sym->st_name && ELF64_ST_TYPE(sym->st_info) == STT_SECTION && - (shdr = getelfsectionheaderaddress(elf, mapsize, sym->st_shndx)) && + (shdr = GetElfSectionHeaderAddress(elf, mapsize, sym->st_shndx)) && (res = GetElfString(elf, mapsize, shstrtab, shdr->sh_name))) || (strtab && (res = GetElfString(elf, mapsize, strtab, sym->st_name))))) { return res; @@ -255,26 +255,26 @@ static void printelfrelocations(void) { const Elf64_Shdr *shdr, *boop; char *strtab, *shstrtab, *symbolname; strtab = GetElfStringTable(elf, st->st_size); - shstrtab = getelfsectionnamestringtable(elf, st->st_size); + shstrtab = GetElfSectionNameStringTable(elf, st->st_size); for (i = 0; i < elf->e_shnum; ++i) { - if ((shdr = getelfsectionheaderaddress(elf, st->st_size, i)) && + if ((shdr = GetElfSectionHeaderAddress(elf, st->st_size, i)) && shdr->sh_type == SHT_RELA && - (rela = getelfsectionaddress(elf, st->st_size, shdr))) { + (rela = GetElfSectionAddress(elf, st->st_size, shdr))) { printf("\n/\t%s\n", GetElfSectionName(elf, st->st_size, shdr)); printf("\t.org\t%#x\n", (intptr_t)rela - (intptr_t)elf); for (j = 0; ((uintptr_t)rela + sizeof(Elf64_Rela) <= min((uintptr_t)elf + st->st_size, (uintptr_t)elf + shdr->sh_offset + shdr->sh_size)); ++rela, ++j) { - boop = getelfsectionheaderaddress(elf, st->st_size, shdr->sh_link); - syms = getelfsectionaddress(elf, st->st_size, boop); + boop = GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_link); + syms = GetElfSectionAddress(elf, st->st_size, boop); sym = ELF64_R_SYM(rela->r_info); symbolname = getelfsymbolname(elf, st->st_size, strtab, shstrtab, &syms[sym]); printf("/\t%s+%#lx → %s%c%#lx\n", GetElfString( elf, st->st_size, shstrtab, - getelfsectionheaderaddress(elf, st->st_size, shdr->sh_info) + GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_info) ->sh_name), rela->r_offset, symbolname, rela->r_addend >= 0 ? '+' : '-', abs(rela->r_addend)); diff --git a/tool/decode/lib/asmcodegen.c b/tool/decode/lib/asmcodegen.c index 631f2a6c..1644ef4a 100644 --- a/tool/decode/lib/asmcodegen.c +++ b/tool/decode/lib/asmcodegen.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/fmt/fmt.h" #include "libc/mem/mem.h" #include "libc/runtime/gc.h" diff --git a/tool/decode/lib/flagger.c b/tool/decode/lib/flagger.c index e057da01..c2b9c672 100644 --- a/tool/decode/lib/flagger.c +++ b/tool/decode/lib/flagger.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/fmt/fmt.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/tool/decode/lib/machoidnames.c b/tool/decode/lib/machoidnames.c index 882c2685..e84db816 100644 --- a/tool/decode/lib/machoidnames.c +++ b/tool/decode/lib/machoidnames.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macho.h" +#include "libc/macho.internal.h" #include "tool/decode/lib/machoidnames.h" const struct IdName kMachoFileTypeNames[] = { diff --git a/tool/decode/lib/peidnames.c b/tool/decode/lib/peidnames.c index bde27272..c9910064 100644 --- a/tool/decode/lib/peidnames.c +++ b/tool/decode/lib/peidnames.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/pe.h" +#include "libc/nt/pedef.internal.h" #include "tool/decode/lib/peidnames.h" const struct IdName kNtImageFileMachineNames[] = { diff --git a/tool/decode/macho.c b/tool/decode/macho.c index f84b9fe6..a4e5b0da 100644 --- a/tool/decode/macho.c +++ b/tool/decode/macho.c @@ -18,11 +18,11 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/conv/conv.h" -#include "libc/macho.h" +#include "libc/macho.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/map.h" @@ -44,7 +44,7 @@ static size_t machosize; static void startfile(void) { showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/macho", NULL, NULL, &kModelineAsm); - printf("#include \"libc/macho.h\"\n\n", path); + printf("#include \"libc/macho.internal.h\"\n\n", path); } static void showmachoheader(void) { diff --git a/tool/decode/mkcombos.c b/tool/decode/mkcombos.c index b5cd4cb0..f9ae8a55 100644 --- a/tool/decode/mkcombos.c +++ b/tool/decode/mkcombos.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/conv/conv.h" #include "libc/log/check.h" diff --git a/tool/decode/mkwides.c b/tool/decode/mkwides.c index 5acc454d..02a9e49c 100644 --- a/tool/decode/mkwides.c +++ b/tool/decode/mkwides.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/fmt/fmt.h" #include "libc/log/check.h" #include "libc/mem/mem.h" diff --git a/tool/decode/pe2.c b/tool/decode/pe2.c index 3d490475..bde7bd53 100644 --- a/tool/decode/pe2.c +++ b/tool/decode/pe2.c @@ -17,13 +17,13 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/conv/conv.h" -#include "libc/nt/struct/imagentheaders.h" -#include "libc/nt/struct/imageoptionalheader.h" -#include "libc/pe.h" +#include "libc/nt/struct/imagedosheader.internal.h" +#include "libc/nt/struct/imagentheaders.internal.h" +#include "libc/nt/struct/imageoptionalheader.internal.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" @@ -57,7 +57,23 @@ static struct XedDecodedInst *ildreal(void *addr) { static void startfile(void) { showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/pe", NULL, NULL, &kModelineAsm); - printf("#include \"libc/pe.h\"\n\n", path); + printf("#include \"libc/nt/pedef.internal.h\"\n\n", path); +} + +static void *pecheckaddress(struct NtImageDosHeader *mz, size_t mzsize, + void *addr, uint32_t addrsize) { +#if !(TRUSTWORTHY + PE_TRUSTWORTHY + 0) + if ((intptr_t)addr < (intptr_t)mz || + (intptr_t)addr + addrsize > (intptr_t)mz + mzsize) { + abort(); + } +#endif + return addr; +} + +static void *pecomputerva(struct NtImageDosHeader *mz, size_t mzsize, + uint32_t reladdr, uint32_t addrsize) { + return pecheckaddress(mz, mzsize, (void *)((intptr_t)mz + reladdr), addrsize); } static void showmzheader(void) { diff --git a/tool/decode/zip.c b/tool/decode/zip.c index d86e6818..0721b79f 100644 --- a/tool/decode/zip.c +++ b/tool/decode/zip.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/conv/conv.h" diff --git a/tool/emacs/c.lang b/tool/emacs/c.lang new file mode 100644 index 00000000..8f74affb --- /dev/null +++ b/tool/emacs/c.lang @@ -0,0 +1,1991 @@ +-- C Language Definition for Unix `highlight` Command, e.g. +-- sudo cp tool/emacs/c.lang /usr/share/highlight/langDefs/ +-- { printf '\n\n'; highlight -Ohtml --encoding=utf-8 --class-name=NONE --src-lang=c tool/viz/life.c; } >life.c.html +-- .num { color: #000000; } /* number */ +-- .esc { color: #80216b; } /* escape sequence */ +-- .ipl { color: #008080; } /* string interpolation */ +-- .str { color: #5a5127; } /* string */ +-- .ppc { color: #685809; } /* preprocessor */ +-- .pps { color: #273122; } /* preprocessor string */ +-- .com { color: #0e6729; } /* multiline comment */ +-- .slc { color: #0e6729; } /* single line comment */ +-- .lin { color: #75715e; } /* wut */ +-- .opt { color: #000000; } /* operator */ +-- .kwa { color: #5332d8; } /* keyword */ +-- .kwb { color: #8c1a94; } /* type */ +-- .kwc { color: #6b2c75; } /* builtin */ +-- .kwd { color: #9609a7; } /* constant */ + +Description="C" +Categories = {"source"} +Digits = [[ (?:0x|0X|0b)[0-9a-fA-F']+|\d*[\.]?\d+(?:[eE][\-\+]\d+)?[lLuU]* ]] + +Keywords={ + + { Id=1, + List={ +"case", +"do", +"return", +"struct", +"for", +"default", +"auto", +"while", +"else", +"break", +"union", +"switch", +"continue", +"extern", +"sizeof", +"if", +"goto", +"static", +"sizeof", +"if", +"typedef", +"const", +"struct", +"for", +"union", +"switch", +"volatile", +"do", +"return", +"goto", +"auto", +"enum", +"else", +"break", +"extern", +"case", +"default", +"register", +"while", +"continue", +"inline", +"restrict", +"_Imaginary", +"_Bool", +"_Pragma", +"_Complex", +"_Atomic", +"_Alignas", +"_Alignof", +"_Noreturn", +"_Generic", +"_Thread_local", +"_Static_assert", +"_Complex_I", +"_Imaginary_I", +"__inline", +"__msabi", +"offsetof", +"microarchitecture", +"targetclones", +"testonly", +"forcealignargpointer", +"textexit", +"externinline", +"noinline", +"noclone", +"donothing", +"printfesque", +"flattenout", +"mallocesque", +"vallocesque", +"paramsnonnull", +"returnspointerwithnoaliases", +"alignas", +"nosideeffect", +"decltype", +"forceinline", +"nocallersavedregisters", +"nothrow", +"nooptimize", +"optimizesize", +"optimizespeed", +"alignof", +"relegated", +"antiquity", +"memcpyesque", +"libcesque", +"artificial", +"returnstwice", +"returnsaligned", +"noprune", +"reallocesque", +"nullterminated", +"unreachable", +"hidden", +"privileged", +"hasatleast", +"nodebuginfo", +"frownedupon", +"noreturn", +"initarray", +"mayalias", +"noinstrument", +"interruptfn", +"nocallback", +"textstartup", +"warnifused", +"attributeallocsize", +"attributeallocalign", +"nodiscard", +"nointerpose", +"compatfn", +"returnsnonnull", +"strftimeesque", +"firstclass", +"preinitarray", +"scanfesque", +"pureconst", +"thatispacked", +"strlenesque", +"textwindows", +"aligned", +"typeof", +"textreal", +"autotype", +"_Section", +"_Vector_size", +"__thread", +"__alignof", +"__typeof", +"__restrict", +"__const__", +"__label__", +"__noinline__", +"__noclone__", +"__force_align_arg_pointer__", +"__always_inline__", +"__gnu_inline__", +"__alignof__", +"__asm__", +"__attribute__", +"__auto_type", +"__byte__", +"__complex__", +"__imag__", +"__may_alias__", +"__noreturn__", +"__packed__", +"__pointer__", +"__printf__", +"__real__", +"__restrict__", +"__scanf__", +"__strfmon__", +"__strftime__", +"__strong__", +"__target__", +"__transparent_union__", +"__typeof__", +"__volatile__", +"__word__", +"__alias__", +"__aligned__", +"__alloc_align__", +"__alloc_size__", +"__artificial__", +"__assume_aligned__", +"__cold__", +"__constructor__", +"__destructor__", +"__copy__", +"__deprecated__", +"__error__", +"__warning__", +"__externally_visible__", +"__flatten__", +"__format__", +"__gnu_format__", +"__gnu_printf__", +"__gnu_scanf__", +"__format_arg__", +"__hot__", +"__ifunc__", +"__interrupt__", +"__interrupt_handler__", +"__leaf__", +"__no_caller_saved_registers__", +"__malloc__", +"__no_icf__", +"__no_instrument_function__", +"__no_profile_instrument_function__", +"__no_reorder__", +"__no_sanitize__", +"__no_sanitize_address__", +"__no_address_safety_analysis__", +"__no_sanitize_thread__", +"__leaf__", +"__no_sanitize_undefined__", +"__no_split_stack__", +"__no_stack_limit__", +"__noclone__", +"__noipa__", +"__nonnull__", +"__noplt__", +"__nothrow__", +"__optimize__", +"__pure__", +"__patchable_function_entry__", +"__returns_nonnull__", +"__returns_twice__", +"__section__", +"__sentinel__", +"__simd__", +"__target_clones__", +"__unused__", +"__used__", +"__visibility__", +"__warn_unused_result__", +"__params_nonnull__", +"__weak__", +"__vector_size__", +"__ms_abi__", +"__mode__", +"__optnone__", +"__nodebug__", +-- "goto", "break", "return", "continue", "asm", "case", "default", "if", "else", "switch", "while", "for", "do", "sizeof", +-- "typeof", "stdcall", "const_cast", "delete", "dynamic_cast", "goto", "namespace", "new", "true", "false", +-- "reinterpret_cast", "static_cast", "this", "throw", "try", "catch", "using", "assert", "static_assert", "static", +-- "alignas","alignof","concept","consteval","constexpr","constinit","co_await","co_return","co_yield","decltype", +-- "noexcept","requires","thread_local", +-- "compl", "and_eq", "or_eq", "xor_eq", "not", "not_eq", "bitand", "and", "bitor", "or", "xor", "pascal", "cdecl", + } + }, + + { Id=2, + List= { +"void", +"int", +"long", +"short", +"char", +"signed", +"unsigned", +"float", +"double", +"size_t", +"wint_t", +"wchar_t", +"bool", +"_Bool", +"int32_t", +"uint_least64_t", +"intptr_t", +"uintmax_t", +"int_fast32_t", +"int16_t", +"int64_t", +"int_fast16_t", +"int_fast64_t", +"errno_t", +"uint_fast32_t", +"int_least8_t", +"uint_least16_t", +"char16_t", +"uint_least32_t", +"int_least64_t", +"int_least16_t", +"int_fast8_t", +"uint_least8_t", +"uintptr_t", +"ssize_t", +"int8_t", +"int_least32_t", +"uint8_t", +"uint_fast64_t", +"intmax_t", +"uint_fast16_t", +"uint32_t", +"ptrdiff_t", +"char32_t", +"uint64_t", +"uint16_t", +"uint_fast8_t", +"complex", +"atomic_uintptr_t", +"atomic_uchar", +"atomic_int_least32_t", +"atomic_uint_least64_t", +"atomic_int_fast32_t", +"atomic_uint_least16_t", +"atomic_short", +"atomic_size_t", +"atomic_uint", +"atomic_char16_t", +"atomic_ullong", +"atomic_uint_fast16_t", +"atomic_int_fast8_t", +"atomic_uint_least32_t", +"atomic_ptrdiff_t", +"atomic_uintmax_t", +"atomic_int_least16_t", +"atomic_long", +"atomic_int", +"atomic_int_fast16_t", +"atomic_uint_least8_t", +"atomic_ushort", +"atomic_int_least8_t", +"atomic_ulong", +"atomic_char32_t", +"atomic_schar", +"atomic_intmax_t", +"atomic_int_least64_t", +"atomic_uint_fast64_t", +"atomic_wchar_t", +"atomic_uint_fast8_t", +"atomic_int_fast64_t", +"atomic_llong", +"atomic_bool", +"atomic_intptr_t", +"atomic_uint_fast32_t", +"atomic_char", +"__int128", +"_Float16", +"_Complex", +"_Float16x", +"_Float32", +"_Float32x", +"_Float64", +"_Float64x", +"_Float128", +"_Float128x", +"int_least128_t", +"int_fast128_t", +"bool32", +"int128_t", +"uint128_t", +"axdx_t", +"__v8hu", +"__v16qi", +"__v4su", +"__v8su", +"__v16qu", +"__v16qs", +"__v8hi", +"__v4hi", +"__v2df", +"__v2di", +"__v4si", +"__v8si", +"__m1", +"__v2du", +"__m2", +"__v1di", +"__v4sf", +"__v8sf", +"__v2si", +"__m64", +"__v2sf", +"__v8qi", +"__v32qi", +"__m128", +"__m128d", +"__m128i", +"__m128_u", +"__m128d_u", +"__m128i_u", +"__m256", +"__m256d", +"__m256i", +"__m256_u", +"__m256d_u", +"__m256i_u", +-- "int", "long", "short", "char", "void", "signed", "unsigned", "float", "double", "size_t", "wchar_t", +-- "ptrdiff_t", "sig_atomic_t", "fpos_t", "clock_t", "time_t", "va_list", "jmp_buf", "FILE", "DIR", "div_t", "ldiv_t", +-- "mbstate_t", "wctrans_t", "wint_t", "wctype_t", "const", "bool", "complex", "struct", "union", "enum", +-- "int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t", "int_least8_t", "int_least16_t", +-- "int_least32_t", "int_least64_t", "uint_least8_t", "uint_least16_t", "uint_least32_t", "uint_least64_t", +-- "int_fast8_t", "int_fast16_t", "int_fast32_t", "int_fast64_t", "uint_fast8_t", "uint_fast16_t", "uint_fast32_t", +-- "uint_fast64_t", "intptr_t", "uintptr_t", "intmax_t", "uintmax_t", "char8_t","char16_t","char32_t" + } + }, + + { Id=3, + List= { +"static_assert", +"__VA_OPT__", +"__COUNTER__", +"__SIG_ATOMIC_TYPE__", +"__INT8_TYPE__", +"__INT16_TYPE__", +"__INT32_TYPE__", +"__INT64_TYPE__", +"__UINT8_TYPE__", +"__UINT16_TYPE__", +"__UINT32_TYPE__", +"__UINT64_TYPE__", +"__INT_LEAST8_TYPE__", +"__INT_LEAST16_TYPE__", +"__INT_LEAST32_TYPE__", +"__INT_LEAST64_TYPE__", +"__UINT_LEAST8_TYPE__", +"__UINT_LEAST16_TYPE__", +"__UINT_LEAST32_TYPE__", +"__UINT_LEAST64_TYPE__", +"__INT_FAST8_TYPE__", +"__INT_FAST16_TYPE__", +"__INT_FAST32_TYPE__", +"__INT_FAST64_TYPE__", +"__UINT_FAST8_TYPE__", +"__UINT_FAST16_TYPE__", +"__UINT_FAST32_TYPE__", +"__UINT_FAST64_TYPE__", +"__INTPTR_TYPE__", +"__UINTPTR_TYPE__", +"__INT8_C", +"__INT16_C", +"__INT32_C", +"__INT64_C", +"__UINT8_C", +"__UINT16_C", +"__UINT32_C", +"__UINT64_C", +"__INTMAX_C", +"__UINTMAX_C", +"__TIMESTAMP__", +"__FP_FAST_FMA", +"__FP_FAST_FMAF", +"__FP_FAST_FMAL", +"__FP_FAST_FMAF16", +"__FP_FAST_FMAF32", +"__FP_FAST_FMAF64", +"__FP_FAST_FMAF128", +"__FP_FAST_FMAF32X", +"__FP_FAST_FMAF64X", +"__FP_FAST_FMAF128X", +"__builtin_va_list", +"__has_attribute", +"__has_builtin", +"__has_cpp_attribute", +"__builtin_va_arg", +"__builtin_va_copy", +"__builtin_va_start", +"__builtin_va_end", +"__builtin_abs", +"__builtin_strcpy", +"__builtin_stpcpy", +"__builtin_setjmp", +"__builtin_longjmp", +"__builtin_apply_args", +"__builtin_apply", +"__builtin_return", +"__builtin_va_arg_pack", +"__builtin_va_arg_pack_len", +"__builtin_constant_p", +"__builtin_return_address", +"__builtin_extract_return_addr", +"__builtin_frob_return_address", +"__builtin_frame_address", +"__builtin_shuffle", +"__builtin_convertvector", +"__builtin_offsetof", +"__builtin_add_overflow", +"__builtin_sadd_overflow", +"__builtin_saddl_overflow", +"__builtin_saddll_overflow", +"__builtin_uadd_overflow", +"__builtin_uaddl_overflow", +"__builtin_uaddll_overflow", +"__builtin_sub_overflow", +"__builtin_ssub_overflow", +"__builtin_ssubl_overflow", +"__builtin_ssubll_overflow", +"__builtin_usub_overflow", +"__builtin_usubl_overflow", +"__builtin_usubll_overflow", +"__builtin_mul_overflow", +"__builtin_smul_overflow", +"__builtin_smull_overflow", +"__builtin_smulll_overflow", +"__builtin_umul_overflow", +"__builtin_umull_overflow", +"__builtin_umulll_overflow", +"__builtin_add_overflow_p", +"__builtin_sub_overflow_p", +"__builtin_mul_overflow_p", +"__builtin_object_size", +"__builtin___memcpy_chk", +"__builtin___sprintf_chk", +"__builtin___snprintf_chk", +"__builtin___vsprintf_chk", +"__builtin___vsnprintf_chk", +"__builtin_alloca", +"__builtin_alloca_with_align", +"__builtin_alloc", +"__builtin_alloca_with_align_and_max", +"__builtin_has_attribute", +"__builtin_speculation_safe_value", +"__builtin_types_compatible_p", +"__builtin_call_with_static_chain", +"__builtin_choose_expr", +"__builtin_tgmath", +"__builtin_complex", +"__builtin_is_constant_evaluated", +"__builtin_expect", +"__builtin_trap", +"__builtin_unreachable", +"__builtin_assume_aligned", +"__builtin_LINE", +"__builtin_FUNCTION", +"__builtin_FILE", +"__builtin___clear_cache", +"__builtin_prefetch", +"__builtin_huge_val", +"__builtin_huge_valf", +"__builtin_huge_vall", +"__builtin_huge_valfn", +"__builtin_huge_valfnx", +"__builtin_fpclassify", +"__builtin_inf", +"__builtin_infd32", +"__builtin_infd64", +"__builtin_infd128", +"__builtin_inff", +"__builtin_infl", +"__builtin_inffn", +"__builtin_inffnx", +"__builtin_isnan", +"__builtin_signbit", +"__builtin_signbitf", +"__builtin_signbitl", +"__builtin_isfinite", +"__builtin_isinf", +"__builtin_isinfinite", +"__builtin_isnormal", +"__builtin_isinf_sign", +"__builtin_isgreater", +"__builtin_isgreaterequal", +"__builtin_isgreater", +"__builtin_isgreaterequal", +"__builtin_isless", +"__builtin_islessequal", +"__builtin_islessgreater", +"__builtin_isunordered", +"__builtin_nan", +"__builtin_nand32", +"__builtin_nand64", +"__builtin_nand128", +"__builtin_nanf", +"__builtin_nanl", +"__builtin_nanfn", +"__builtin_nanfnx", +"__builtin_nans", +"__builtin_nansf", +"__builtin_nansl", +"__builtin_nansfn", +"__builtin_nansfnx", +"__builtin_ffs", +"__builtin_clz", +"__builtin_ctz", +"__builtin_clrsb", +"__builtin_popcount", +"__builtin_parity", +"__builtin_ffsl", +"__builtin_clzl", +"__builtin_ctzl", +"__builtin_clrsbl", +"__builtin_popcountl", +"__builtin_parityl", +"__builtin_ffsll", +"__builtin_clzll", +"__builtin_ctzll", +"__builtin_clrsbll", +"__builtin_popcountll", +"__builtin_parityll", +"__builtin_powi", +"__builtin_powif", +"__builtin_powil", +"__builtin_bswap16", +"__builtin_bswap32", +"__builtin_bswap64", +"__builtin_extend_pointer", +"__builtin_goacc_parlevel_id", +"__builtin_goacc_parlevel_size", +"__builtin_fabsq", +"__builtin_copysignq", +"__builtin_infq", +"__builtin_huge_valq", +"__builtin_nanq", +"__builtin_nansq", +"__builtin_copysign", +"__builtin_copysignf", +"__builtin_copysignl", +"__builtin_fabs", +"__builtin_fabsf", +"__builtin_fabsl", +"__builtin_ceil", +"__builtin_ceilf", +"__builtin_ceill", +"__builtin_floor", +"__builtin_floorf", +"__builtin_floorl", +"__builtin_trunc", +"__builtin_truncf", +"__builtin_truncl", +"__builtin_round", +"__builtin_roundf", +"__builtin_roundl", +"__builtin_lround", +"__builtin_lroundf", +"__builtin_lroundl", +"__builtin_nearbyint", +"__builtin_nearbyintf", +"__builtin_nearbyintl", +"__builtin_scalbn", +"__builtin_scalbnf", +"__builtin_scalbnl", +"__builtin_logb", +"__builtin_logbf", +"__builtin_logbl", +"__builtin_fmax", +"__builtin_fmaxf", +"__builtin_fmaxl", +"__builtin_fmin", +"__builtin_fminf", +"__builtin_fminl", +"__builtin_rint", +"__builtin_rintf", +"__builtin_rintl", +"__builtin_lrint", +"__builtin_lrintf", +"__builtin_lrintl", +"__builtin_memcpy", +"__builtin_memcmp", +"__builtin_memset", +"__builtin_strlen", +"__atomic_load_n", +"__atomic_load", +"__atomic_store", +"__atomic_store_n", +"__atomic_exchange_n", +"__atomic_exchange", +"__atomic_compare_exchange_n", +"__atomic_compare_exchange", +"__atomic_add_fetch", +"__atomic_sub_fetch", +"__atomic_and_fetch", +"__atomic_xor_fetch", +"__atomic_or_fetch", +"__atomic_nand_fetch", +"__atomic_fetch_add", +"__atomic_fetch_sub", +"__atomic_fetch_and", +"__atomic_fetch_xor", +"__atomic_fetch_or", +"__atomic_fetch_nand", +"__atomic_test_and_set", +"__atomic_clear", +"__atomic_thread_fence", +"__atomic_signal_fence", +"__atomic_always_lock_free", +"__atomic_is_lock_free", +"__sync_fetch_and_add", +"__sync_fetch_and_sub", +"__sync_fetch_and_or", +"__sync_fetch_and_and", +"__sync_fetch_and_xor", +"__sync_fetch_and_nand", +"__sync_add_and_fetch", +"__sync_sub_and_fetch", +"__sync_or_and_fetch", +"__sync_and_and_fetch", +"__sync_xor_and_fetch", +"__sync_nand_and_fetch", +"__sync_bool_compare_and_swap", +"__sync_val_compare_and_swap", +"__sync_synchronize", +"__sync_lock_test_and_set", +"__sync_lock_release", +"__builtin_ia32_pause", +"__builtin_ia32_paddb", +"__builtin_ia32_paddw", +"__builtin_ia32_paddd", +"__builtin_ia32_psubb", +"__builtin_ia32_psubw", +"__builtin_ia32_psubd", +"__builtin_ia32_paddsb", +"__builtin_ia32_paddsw", +"__builtin_ia32_psubsb", +"__builtin_ia32_psubsw", +"__builtin_ia32_paddusb", +"__builtin_ia32_paddusw", +"__builtin_ia32_psubusb", +"__builtin_ia32_psubusw", +"__builtin_ia32_pmullw", +"__builtin_ia32_pmulhw", +"__builtin_ia32_pand", +"__builtin_ia32_pandn", +"__builtin_ia32_por", +"__builtin_ia32_pxor", +"__builtin_ia32_pcmpeqb", +"__builtin_ia32_pcmpeqw", +"__builtin_ia32_pcmpeqd", +"__builtin_ia32_pcmpgtb", +"__builtin_ia32_pcmpgtw", +"__builtin_ia32_pcmpgtd", +"__builtin_ia32_punpckhbw", +"__builtin_ia32_punpckhwd", +"__builtin_ia32_punpckhdq", +"__builtin_ia32_punpcklbw", +"__builtin_ia32_punpcklwd", +"__builtin_ia32_punpckldq", +"__builtin_ia32_packsswb", +"__builtin_ia32_packssdw", +"__builtin_ia32_packuswb", +"__builtin_ia32_psllw", +"__builtin_ia32_pslld", +"__builtin_ia32_psllq", +"__builtin_ia32_psrlw", +"__builtin_ia32_psrld", +"__builtin_ia32_psrlq", +"__builtin_ia32_psraw", +"__builtin_ia32_psrad", +"__builtin_ia32_psllwi", +"__builtin_ia32_pslldi", +"__builtin_ia32_psllqi", +"__builtin_ia32_psrlwi", +"__builtin_ia32_psrldi", +"__builtin_ia32_psrlqi", +"__builtin_ia32_psrawi", +"__builtin_ia32_psradi", +"__builtin_ia32_pmulhuw", +"__builtin_ia32_pavgb", +"__builtin_ia32_pavgw", +"__builtin_ia32_psadbw", +"__builtin_ia32_pmaxub", +"__builtin_ia32_pmaxsw", +"__builtin_ia32_pminub", +"__builtin_ia32_pminsw", +"__builtin_ia32_pmovmskb", +"__builtin_ia32_maskmovq", +"__builtin_ia32_movntq", +"__builtin_ia32_sfence", +"__builtin_ia32_comieq", +"__builtin_ia32_comineq", +"__builtin_ia32_comilt", +"__builtin_ia32_comile", +"__builtin_ia32_comigt", +"__builtin_ia32_comige", +"__builtin_ia32_ucomieq", +"__builtin_ia32_ucomineq", +"__builtin_ia32_ucomilt", +"__builtin_ia32_ucomile", +"__builtin_ia32_ucomigt", +"__builtin_ia32_ucomige", +"__builtin_ia32_addps", +"__builtin_ia32_subps", +"__builtin_ia32_mulps", +"__builtin_ia32_divps", +"__builtin_ia32_addss", +"__builtin_ia32_subss", +"__builtin_ia32_mulss", +"__builtin_ia32_divss", +"__builtin_ia32_cmpeqps", +"__builtin_ia32_cmpltps", +"__builtin_ia32_cmpleps", +"__builtin_ia32_cmpgtps", +"__builtin_ia32_cmpgeps", +"__builtin_ia32_cmpunordps", +"__builtin_ia32_cmpneqps", +"__builtin_ia32_cmpnltps", +"__builtin_ia32_cmpnleps", +"__builtin_ia32_cmpngtps", +"__builtin_ia32_cmpngeps", +"__builtin_ia32_cmpordps", +"__builtin_ia32_cmpeqss", +"__builtin_ia32_cmpltss", +"__builtin_ia32_cmpless", +"__builtin_ia32_cmpunordss", +"__builtin_ia32_cmpneqss", +"__builtin_ia32_cmpnltss", +"__builtin_ia32_cmpnless", +"__builtin_ia32_cmpordss", +"__builtin_ia32_maxps", +"__builtin_ia32_maxss", +"__builtin_ia32_minps", +"__builtin_ia32_minss", +"__builtin_ia32_andps", +"__builtin_ia32_andnps", +"__builtin_ia32_orps", +"__builtin_ia32_xorps", +"__builtin_ia32_movss", +"__builtin_ia32_movhlps", +"__builtin_ia32_movlhps", +"__builtin_ia32_unpckhps", +"__builtin_ia32_unpcklps", +"__builtin_ia32_cvtpi2ps", +"__builtin_ia32_cvtsi2ss", +"__builtin_ia32_cvtps2pi", +"__builtin_ia32_cvtss2si", +"__builtin_ia32_cvttps2pi", +"__builtin_ia32_cvttss2si", +"__builtin_ia32_rcpps", +"__builtin_ia32_rsqrtps", +"__builtin_ia32_sqrtps", +"__builtin_ia32_rcpss", +"__builtin_ia32_rsqrtss", +"__builtin_ia32_sqrtss", +"__builtin_ia32_shufps", +"__builtin_ia32_movntps", +"__builtin_ia32_movmskps", +"__builtin_ia32_loadups", +"__builtin_ia32_storeups", +"__builtin_ia32_loadss", +"__builtin_ia32_loadhps", +"__builtin_ia32_loadlps", +"__builtin_ia32_storehps", +"__builtin_ia32_storelps", +"__builtin_ia32_comisdeq", +"__builtin_ia32_comisdlt", +"__builtin_ia32_comisdle", +"__builtin_ia32_comisdgt", +"__builtin_ia32_comisdge", +"__builtin_ia32_comisdneq", +"__builtin_ia32_ucomisdeq", +"__builtin_ia32_ucomisdlt", +"__builtin_ia32_ucomisdle", +"__builtin_ia32_ucomisdgt", +"__builtin_ia32_ucomisdge", +"__builtin_ia32_ucomisdneq", +"__builtin_ia32_cmpeqpd", +"__builtin_ia32_cmpltpd", +"__builtin_ia32_cmplepd", +"__builtin_ia32_cmpgtpd", +"__builtin_ia32_cmpgepd", +"__builtin_ia32_cmpunordpd", +"__builtin_ia32_cmpneqpd", +"__builtin_ia32_cmpnltpd", +"__builtin_ia32_cmpnlepd", +"__builtin_ia32_cmpngtpd", +"__builtin_ia32_cmpngepd", +"__builtin_ia32_cmpordpd", +"__builtin_ia32_cmpeqsd", +"__builtin_ia32_cmpltsd", +"__builtin_ia32_cmplesd", +"__builtin_ia32_cmpunordsd", +"__builtin_ia32_cmpneqsd", +"__builtin_ia32_cmpnltsd", +"__builtin_ia32_cmpnlesd", +"__builtin_ia32_cmpordsd", +"__builtin_ia32_paddq", +"__builtin_ia32_psubq", +"__builtin_ia32_addpd", +"__builtin_ia32_subpd", +"__builtin_ia32_mulpd", +"__builtin_ia32_divpd", +"__builtin_ia32_addsd", +"__builtin_ia32_subsd", +"__builtin_ia32_mulsd", +"__builtin_ia32_divsd", +"__builtin_ia32_minpd", +"__builtin_ia32_maxpd", +"__builtin_ia32_minsd", +"__builtin_ia32_maxsd", +"__builtin_ia32_andpd", +"__builtin_ia32_andnpd", +"__builtin_ia32_orpd", +"__builtin_ia32_xorpd", +"__builtin_ia32_movsd", +"__builtin_ia32_unpckhpd", +"__builtin_ia32_unpcklpd", +"__builtin_ia32_paddb128", +"__builtin_ia32_paddw128", +"__builtin_ia32_paddd128", +"__builtin_ia32_paddq128", +"__builtin_ia32_psubb128", +"__builtin_ia32_psubw128", +"__builtin_ia32_psubd128", +"__builtin_ia32_psubq128", +"__builtin_ia32_pmullw128", +"__builtin_ia32_pmulhw128", +"__builtin_ia32_pand128", +"__builtin_ia32_pandn128", +"__builtin_ia32_por128", +"__builtin_ia32_pxor128", +"__builtin_ia32_pavgb128", +"__builtin_ia32_pavgw128", +"__builtin_ia32_pcmpeqb128", +"__builtin_ia32_pcmpeqw128", +"__builtin_ia32_pcmpeqd128", +"__builtin_ia32_pcmpgtb128", +"__builtin_ia32_pcmpgtw128", +"__builtin_ia32_pcmpgtd128", +"__builtin_ia32_pmaxub128", +"__builtin_ia32_pmaxsw128", +"__builtin_ia32_pminub128", +"__builtin_ia32_pminsw128", +"__builtin_ia32_punpckhbw128", +"__builtin_ia32_punpckhwd128", +"__builtin_ia32_punpckhdq128", +"__builtin_ia32_punpckhqdq128", +"__builtin_ia32_punpcklbw128", +"__builtin_ia32_punpcklwd128", +"__builtin_ia32_punpckldq128", +"__builtin_ia32_punpcklqdq128", +"__builtin_ia32_packsswb128", +"__builtin_ia32_packssdw128", +"__builtin_ia32_packuswb128", +"__builtin_ia32_pmulhuw128", +"__builtin_ia32_maskmovdqu", +"__builtin_ia32_loadupd", +"__builtin_ia32_storeupd", +"__builtin_ia32_loadhpd", +"__builtin_ia32_loadlpd", +"__builtin_ia32_movmskpd", +"__builtin_ia32_pmovmskb128", +"__builtin_ia32_movnti", +"__builtin_ia32_movnti64", +"__builtin_ia32_movntpd", +"__builtin_ia32_movntdq", +"__builtin_ia32_pshufd", +"__builtin_ia32_pshuflw", +"__builtin_ia32_pshufhw", +"__builtin_ia32_psadbw128", +"__builtin_ia32_sqrtpd", +"__builtin_ia32_sqrtsd", +"__builtin_ia32_shufpd", +"__builtin_ia32_cvtdq2pd", +"__builtin_ia32_cvtdq2ps", +"__builtin_ia32_cvtpd2dq", +"__builtin_ia32_cvtpd2pi", +"__builtin_ia32_cvtpd2ps", +"__builtin_ia32_cvttpd2dq", +"__builtin_ia32_cvttpd2pi", +"__builtin_ia32_cvtpi2pd", +"__builtin_ia32_cvtsd2si", +"__builtin_ia32_cvttsd2si", +"__builtin_ia32_cvtsd2si64", +"__builtin_ia32_cvttsd2si64", +"__builtin_ia32_cvtps2dq", +"__builtin_ia32_cvtps2pd", +"__builtin_ia32_cvttps2dq", +"__builtin_ia32_cvtsi2sd", +"__builtin_ia32_cvtsi642sd", +"__builtin_ia32_cvtsd2ss", +"__builtin_ia32_cvtss2sd", +"__builtin_ia32_clflush", +"__builtin_ia32_lfence", +"__builtin_ia32_mfence", +"__builtin_ia32_loaddqu", +"__builtin_ia32_storedqu", +"__builtin_ia32_pmuludq", +"__builtin_ia32_pmuludq128", +"__builtin_ia32_psllw128", +"__builtin_ia32_pslld128", +"__builtin_ia32_psllq128", +"__builtin_ia32_psrlw128", +"__builtin_ia32_psrld128", +"__builtin_ia32_psrlq128", +"__builtin_ia32_psraw128", +"__builtin_ia32_psrad128", +"__builtin_ia32_pslldqi128", +"__builtin_ia32_psllwi128", +"__builtin_ia32_pslldi128", +"__builtin_ia32_psllqi128", +"__builtin_ia32_psrldqi128", +"__builtin_ia32_psrlwi128", +"__builtin_ia32_psrldi128", +"__builtin_ia32_psrlqi128", +"__builtin_ia32_psrawi128", +"__builtin_ia32_psradi128", +"__builtin_ia32_pmaddwd128", +"__builtin_ia32_movq128", +"__builtin_ia32_addsubpd", +"__builtin_ia32_addsubps", +"__builtin_ia32_haddpd", +"__builtin_ia32_haddps", +"__builtin_ia32_hsubpd", +"__builtin_ia32_hsubps", +"__builtin_ia32_lddqu", +"__builtin_ia32_monitor", +"__builtin_ia32_movshdup", +"__builtin_ia32_movsldup", +"__builtin_ia32_mwait", +"__builtin_ia32_phaddd", +"__builtin_ia32_phaddw", +"__builtin_ia32_phaddsw", +"__builtin_ia32_phsubd", +"__builtin_ia32_phsubw", +"__builtin_ia32_phsubsw", +"__builtin_ia32_pmaddubsw", +"__builtin_ia32_pmulhrsw", +"__builtin_ia32_pshufb", +"__builtin_ia32_psignb", +"__builtin_ia32_psignd", +"__builtin_ia32_psignw", +"__builtin_ia32_palignr", +"__builtin_ia32_pabsb", +"__builtin_ia32_pabsd", +"__builtin_ia32_pabsw", +"__builtin_ia32_phaddd128", +"__builtin_ia32_phaddw128", +"__builtin_ia32_phaddsw128", +"__builtin_ia32_phsubd128", +"__builtin_ia32_phsubw128", +"__builtin_ia32_phsubsw128", +"__builtin_ia32_pmaddubsw128", +"__builtin_ia32_pmulhrsw128", +"__builtin_ia32_pshufb128", +"__builtin_ia32_psignb128", +"__builtin_ia32_psignd128", +"__builtin_ia32_psignw128", +"__builtin_ia32_palignr128", +"__builtin_ia32_pabsb128", +"__builtin_ia32_pabsd128", +"__builtin_ia32_pabsw128", +"__builtin_ia32_blendpd", +"__builtin_ia32_blendps", +"__builtin_ia32_blendvpd", +"__builtin_ia32_blendvps", +"__builtin_ia32_dppd", +"__builtin_ia32_dpps", +"__builtin_ia32_insertps128", +"__builtin_ia32_movntdqa", +"__builtin_ia32_mpsadbw128", +"__builtin_ia32_packusdw128", +"__builtin_ia32_pblendvb128", +"__builtin_ia32_pblendw128", +"__builtin_ia32_pcmpeqq", +"__builtin_ia32_phminposuw128", +"__builtin_ia32_pmaxsb128", +"__builtin_ia32_pmaxsd128", +"__builtin_ia32_pmaxud128", +"__builtin_ia32_pmaxuw128", +"__builtin_ia32_pminsb128", +"__builtin_ia32_pminsd128", +"__builtin_ia32_pminud128", +"__builtin_ia32_pminuw128", +"__builtin_ia32_pmovsxbd128", +"__builtin_ia32_pmovsxbq128", +"__builtin_ia32_pmovsxbw128", +"__builtin_ia32_pmovsxdq128", +"__builtin_ia32_pmovsxwd128", +"__builtin_ia32_pmovsxwq128", +"__builtin_ia32_pmovzxbd128", +"__builtin_ia32_pmovzxbq128", +"__builtin_ia32_pmovzxbw128", +"__builtin_ia32_pmovzxdq128", +"__builtin_ia32_pmovzxwd128", +"__builtin_ia32_pmovzxwq128", +"__builtin_ia32_pmuldq128", +"__builtin_ia32_pmulld128", +"__builtin_ia32_ptestc128", +"__builtin_ia32_ptestnzc128", +"__builtin_ia32_ptestz128", +"__builtin_ia32_roundpd", +"__builtin_ia32_roundps", +"__builtin_ia32_roundsd", +"__builtin_ia32_roundss", +"__builtin_ia32_vec_set_v4sf", +"__builtin_ia32_vec_ext_v16qi", +"__builtin_ia32_vec_set_v16qi", +"__builtin_ia32_vec_set_v4si", +"__builtin_ia32_vec_set_v2di", +"__builtin_ia32_vec_ext_v4sf", +"__builtin_ia32_vec_ext_v4si", +"__builtin_ia32_vec_ext_v2di", +"__builtin_ia32_pcmpestrm128", +"__builtin_ia32_pcmpestri128", +"__builtin_ia32_pcmpestria128", +"__builtin_ia32_pcmpestric128", +"__builtin_ia32_pcmpestrio128", +"__builtin_ia32_pcmpestris128", +"__builtin_ia32_pcmpestriz128", +"__builtin_ia32_pcmpistrm128", +"__builtin_ia32_pcmpistri128", +"__builtin_ia32_pcmpistria128", +"__builtin_ia32_pcmpistric128", +"__builtin_ia32_pcmpistrio128", +"__builtin_ia32_pcmpistris128", +"__builtin_ia32_pcmpistriz128", +"__builtin_ia32_pcmpgtq", +"__builtin_ia32_crc32qi", +"__builtin_ia32_crc32hi", +"__builtin_ia32_crc32si", +"__builtin_ia32_crc32di", +"__builtin_ia32_addpd256", +"__builtin_ia32_addps256", +"__builtin_ia32_addsubpd256", +"__builtin_ia32_addsubps256", +"__builtin_ia32_andnpd256", +"__builtin_ia32_andnps256", +"__builtin_ia32_andpd256", +"__builtin_ia32_andps256", +"__builtin_ia32_blendpd256", +"__builtin_ia32_blendps256", +"__builtin_ia32_blendvpd256", +"__builtin_ia32_blendvps256", +"__builtin_ia32_cmppd", +"__builtin_ia32_cmppd256", +"__builtin_ia32_cmpps", +"__builtin_ia32_cmpps256", +"__builtin_ia32_cmpsd", +"__builtin_ia32_cmpss", +"__builtin_ia32_cvtdq2pd256", +"__builtin_ia32_cvtdq2ps256", +"__builtin_ia32_cvtpd2dq256", +"__builtin_ia32_cvtpd2ps256", +"__builtin_ia32_cvtps2dq256", +"__builtin_ia32_cvtps2pd256", +"__builtin_ia32_cvttpd2dq256", +"__builtin_ia32_cvttps2dq256", +"__builtin_ia32_divpd256", +"__builtin_ia32_divps256", +"__builtin_ia32_dpps256", +"__builtin_ia32_haddpd256", +"__builtin_ia32_haddps256", +"__builtin_ia32_hsubpd256", +"__builtin_ia32_hsubps256", +"__builtin_ia32_lddqu256", +"__builtin_ia32_loaddqu256", +"__builtin_ia32_loadupd256", +"__builtin_ia32_loadups256", +"__builtin_ia32_maskloadpd", +"__builtin_ia32_maskloadpd256", +"__builtin_ia32_maskloadps", +"__builtin_ia32_maskloadps256", +"__builtin_ia32_maskstorepd", +"__builtin_ia32_maskstorepd256", +"__builtin_ia32_maskstoreps", +"__builtin_ia32_maskstoreps256", +"__builtin_ia32_maxpd256", +"__builtin_ia32_maxps256", +"__builtin_ia32_minpd256", +"__builtin_ia32_minps256", +"__builtin_ia32_movddup256", +"__builtin_ia32_movmskpd256", +"__builtin_ia32_movmskps256", +"__builtin_ia32_movshdup256", +"__builtin_ia32_movsldup256", +"__builtin_ia32_mulpd256", +"__builtin_ia32_mulps256", +"__builtin_ia32_orpd256", +"__builtin_ia32_orps256", +"__builtin_ia32_pd_pd256", +"__builtin_ia32_pd256_pd", +"__builtin_ia32_ps_ps256", +"__builtin_ia32_ps256_ps", +"__builtin_ia32_ptestc256", +"__builtin_ia32_ptestnzc256", +"__builtin_ia32_ptestz256", +"__builtin_ia32_rcpps256", +"__builtin_ia32_roundpd256", +"__builtin_ia32_roundps256", +"__builtin_ia32_rsqrtps_nr256", +"__builtin_ia32_rsqrtps256", +"__builtin_ia32_shufpd256", +"__builtin_ia32_shufps256", +"__builtin_ia32_si_si256", +"__builtin_ia32_si256_si", +"__builtin_ia32_sqrtpd256", +"__builtin_ia32_sqrtps_nr256", +"__builtin_ia32_sqrtps256", +"__builtin_ia32_storedqu256", +"__builtin_ia32_storeupd256", +"__builtin_ia32_storeups256", +"__builtin_ia32_subpd256", +"__builtin_ia32_subps256", +"__builtin_ia32_unpckhpd256", +"__builtin_ia32_unpckhps256", +"__builtin_ia32_unpcklpd256", +"__builtin_ia32_unpcklps256", +"__builtin_ia32_vbroadcastf128_pd256", +"__builtin_ia32_vbroadcastf128_ps256", +"__builtin_ia32_vbroadcastsd256", +"__builtin_ia32_vbroadcastss", +"__builtin_ia32_vbroadcastss256", +"__builtin_ia32_vextractf128_pd256", +"__builtin_ia32_vextractf128_ps256", +"__builtin_ia32_vextractf128_si256", +"__builtin_ia32_vinsertf128_pd256", +"__builtin_ia32_vinsertf128_ps256", +"__builtin_ia32_vinsertf128_si256", +"__builtin_ia32_vperm2f128_pd256", +"__builtin_ia32_vperm2f128_ps256", +"__builtin_ia32_vperm2f128_si256", +"__builtin_ia32_vpermil2pd", +"__builtin_ia32_vpermil2pd256", +"__builtin_ia32_vpermil2ps", +"__builtin_ia32_vpermil2ps256", +"__builtin_ia32_vpermilpd", +"__builtin_ia32_vpermilpd256", +"__builtin_ia32_vpermilps", +"__builtin_ia32_vpermilps256", +"__builtin_ia32_vpermilvarpd", +"__builtin_ia32_vpermilvarpd256", +"__builtin_ia32_vpermilvarps", +"__builtin_ia32_vpermilvarps256", +"__builtin_ia32_vtestcpd", +"__builtin_ia32_vtestcpd256", +"__builtin_ia32_vtestcps", +"__builtin_ia32_vtestcps256", +"__builtin_ia32_vtestnzcpd", +"__builtin_ia32_vtestnzcpd256", +"__builtin_ia32_vtestnzcps", +"__builtin_ia32_vtestnzcps256", +"__builtin_ia32_vtestzpd", +"__builtin_ia32_vtestzpd256", +"__builtin_ia32_vtestzps", +"__builtin_ia32_vtestzps256", +"__builtin_ia32_vzeroall", +"__builtin_ia32_vzeroupper", +"__builtin_ia32_xorpd256", +"__builtin_ia32_xorps256", +"__builtin_ia32_mpsadbw256", +"__builtin_ia32_pabsb256", +"__builtin_ia32_pabsw256", +"__builtin_ia32_pabsd256", +"__builtin_ia32_packssdw256", +"__builtin_ia32_packsswb256", +"__builtin_ia32_packusdw256", +"__builtin_ia32_packuswb256", +"__builtin_ia32_paddb256", +"__builtin_ia32_paddw256", +"__builtin_ia32_paddd256", +"__builtin_ia32_paddq256", +"__builtin_ia32_paddsb256", +"__builtin_ia32_paddsw256", +"__builtin_ia32_paddusb256", +"__builtin_ia32_paddusw256", +"__builtin_ia32_palignr256", +"__builtin_ia32_andsi256", +"__builtin_ia32_andnotsi256", +"__builtin_ia32_pavgb256", +"__builtin_ia32_pavgw256", +"__builtin_ia32_pblendvb256", +"__builtin_ia32_pblendw256", +"__builtin_ia32_pcmpeqb256", +"__builtin_ia32_pcmpeqw256", +"__builtin_ia32_pcmpeqd256", +"__builtin_ia32_pcmpeqq256", +"__builtin_ia32_pcmpgtb256", +"__builtin_ia32_pcmpgtw256", +"__builtin_ia32_pcmpgtd256", +"__builtin_ia32_pcmpgtq256", +"__builtin_ia32_phaddw256", +"__builtin_ia32_phaddd256", +"__builtin_ia32_phaddsw256", +"__builtin_ia32_phsubw256", +"__builtin_ia32_phsubd256", +"__builtin_ia32_phsubsw256", +"__builtin_ia32_pmaddubsw256", +"__builtin_ia32_pmaddwd256", +"__builtin_ia32_pmaxsb256", +"__builtin_ia32_pmaxsw256", +"__builtin_ia32_pmaxsd256", +"__builtin_ia32_pmaxub256", +"__builtin_ia32_pmaxuw256", +"__builtin_ia32_pmaxud256", +"__builtin_ia32_pminsb256", +"__builtin_ia32_pminsw256", +"__builtin_ia32_pminsd256", +"__builtin_ia32_pminub256", +"__builtin_ia32_pminuw256", +"__builtin_ia32_pminud256", +"__builtin_ia32_pmovmskb256", +"__builtin_ia32_pmovsxbw256", +"__builtin_ia32_pmovsxbd256", +"__builtin_ia32_pmovsxbq256", +"__builtin_ia32_pmovsxwd256", +"__builtin_ia32_pmovsxwq256", +"__builtin_ia32_pmovsxdq256", +"__builtin_ia32_pmovzxbw256", +"__builtin_ia32_pmovzxbd256", +"__builtin_ia32_pmovzxbq256", +"__builtin_ia32_pmovzxwd256", +"__builtin_ia32_pmovzxwq256", +"__builtin_ia32_pmovzxdq256", +"__builtin_ia32_pmuldq256", +"__builtin_ia32_pmulhrsw256", +"__builtin_ia32_pmulhuw256", +"__builtin_ia32_pmulhw256", +"__builtin_ia32_pmullw256", +"__builtin_ia32_pmulld256", +"__builtin_ia32_pmuludq256", +"__builtin_ia32_por256", +"__builtin_ia32_psadbw256", +"__builtin_ia32_pshufb256", +"__builtin_ia32_pshufd256", +"__builtin_ia32_pshufhw256", +"__builtin_ia32_pshuflw256", +"__builtin_ia32_psignb256", +"__builtin_ia32_psignw256", +"__builtin_ia32_psignd256", +"__builtin_ia32_pslldqi256", +"__builtin_ia32_psllwi256", +"__builtin_ia32_pslldi256", +"__builtin_ia32_psllqi256", +"__builtin_ia32_psrawi256", +"__builtin_ia32_psraw256", +"__builtin_ia32_psradi256", +"__builtin_ia32_psrad256", +"__builtin_ia32_psrldqi256", +"__builtin_ia32_psrlwi256", +"__builtin_ia32_psrlw256", +"__builtin_ia32_psrldi256", +"__builtin_ia32_psrld256", +"__builtin_ia32_psrlqi256", +"__builtin_ia32_psubb256", +"__builtin_ia32_psubw256", +"__builtin_ia32_psubd256", +"__builtin_ia32_psubq256", +"__builtin_ia32_psubsb256", +"__builtin_ia32_psubsw256", +"__builtin_ia32_psubusb256", +"__builtin_ia32_psubusw256", +"__builtin_ia32_punpckhbw256", +"__builtin_ia32_punpckhwd256", +"__builtin_ia32_punpckhdq256", +"__builtin_ia32_punpckhqdq256", +"__builtin_ia32_punpcklbw256", +"__builtin_ia32_punpcklwd256", +"__builtin_ia32_punpckldq256", +"__builtin_ia32_punpcklqdq256", +"__builtin_ia32_pxor256", +"__builtin_ia32_movntdqa256", +"__builtin_ia32_vbroadcastss_ps", +"__builtin_ia32_vbroadcastss_ps256", +"__builtin_ia32_vbroadcastsd_pd256", +"__builtin_ia32_vbroadcastsi256", +"__builtin_ia32_pblendd128", +"__builtin_ia32_pblendd256", +"__builtin_ia32_pbroadcastb256", +"__builtin_ia32_pbroadcastw256", +"__builtin_ia32_pbroadcastd256", +"__builtin_ia32_pbroadcastq256", +"__builtin_ia32_pbroadcastb128", +"__builtin_ia32_pbroadcastw128", +"__builtin_ia32_pbroadcastd128", +"__builtin_ia32_pbroadcastq128", +"__builtin_ia32_permvarsi256", +"__builtin_ia32_permdf256", +"__builtin_ia32_permvarsf256", +"__builtin_ia32_permdi256", +"__builtin_ia32_permti256", +"__builtin_ia32_extract128i256", +"__builtin_ia32_insert128i256", +"__builtin_ia32_maskloadd256", +"__builtin_ia32_maskloadq256", +"__builtin_ia32_maskloadd", +"__builtin_ia32_maskloadq", +"__builtin_ia32_maskstored256", +"__builtin_ia32_maskstoreq256", +"__builtin_ia32_maskstored", +"__builtin_ia32_maskstoreq", +"__builtin_ia32_psllv8si", +"__builtin_ia32_psllv4si", +"__builtin_ia32_psllv4di", +"__builtin_ia32_psllv2di", +"__builtin_ia32_psrav8si", +"__builtin_ia32_psrav4si", +"__builtin_ia32_psrlv8si", +"__builtin_ia32_psrlv4si", +"__builtin_ia32_psrlv4di", +"__builtin_ia32_psrlv2di", +"__builtin_ia32_gathersiv2df", +"__builtin_ia32_gathersiv4df", +"__builtin_ia32_gatherdiv2df", +"__builtin_ia32_gatherdiv4df", +"__builtin_ia32_gathersiv4sf", +"__builtin_ia32_gathersiv8sf", +"__builtin_ia32_gatherdiv4sf", +"__builtin_ia32_gatherdiv4sf256", +"__builtin_ia32_gathersiv2di", +"__builtin_ia32_gathersiv4di", +"__builtin_ia32_gatherdiv2di", +"__builtin_ia32_gatherdiv4di", +"__builtin_ia32_gathersiv4si", +"__builtin_ia32_gathersiv8si", +"__builtin_ia32_gatherdiv4si", +"__builtin_ia32_gatherdiv4si256", +"__builtin_ia32_aesenc128", +"__builtin_ia32_aesenclast128", +"__builtin_ia32_aesdec128", +"__builtin_ia32_aesdeclast128", +"__builtin_ia32_aeskeygenassist128", +"__builtin_ia32_aesimc128", +"__builtin_ia32_pclmulqdq128", +"__builtin_ia32_rdfsbase32", +"__builtin_ia32_rdfsbase64", +"__builtin_ia32_rdgsbase32", +"__builtin_ia32_rdgsbase64", +"__builtin_ia32_rdrand16_step", +"__builtin_ia32_rdrand32_step", +"__builtin_ia32_rdrand64_step", +"__builtin_ia32_ptwrite32", +"__builtin_ia32_ptwrite64", +"__builtin_ia32_movntsd", +"__builtin_ia32_movntss", +"__builtin_ia32_extrqi", +"__builtin_ia32_insertq", +"__builtin_ia32_insertqi", +"__builtin_ia32_vfrczpd", +"__builtin_ia32_vfrczps", +"__builtin_ia32_vfrczsd", +"__builtin_ia32_vfrczss", +"__builtin_ia32_vfrczpd256", +"__builtin_ia32_vfrczps256", +"__builtin_ia32_vpcmov", +"__builtin_ia32_vpcmov_v2di", +"__builtin_ia32_vpcmov_v4si", +"__builtin_ia32_vpcmov_v8hi", +"__builtin_ia32_vpcmov_v16qi", +"__builtin_ia32_vpcmov_v2df", +"__builtin_ia32_vpcmov_v4sf", +"__builtin_ia32_vpcmov_v4di256", +"__builtin_ia32_vpcmov_v8si256", +"__builtin_ia32_vpcmov_v16hi256", +"__builtin_ia32_vpcmov_v32qi256", +"__builtin_ia32_vpcmov_v4df256", +"__builtin_ia32_vpcmov_v8sf256", +"__builtin_ia32_vpcomeqb", +"__builtin_ia32_vpcomeqw", +"__builtin_ia32_vpcomeqd", +"__builtin_ia32_vpcomeqq", +"__builtin_ia32_vpcomequb", +"__builtin_ia32_vpcomequd", +"__builtin_ia32_vpcomequq", +"__builtin_ia32_vpcomequw", +"__builtin_ia32_vpcomfalseb", +"__builtin_ia32_vpcomfalsed", +"__builtin_ia32_vpcomfalseq", +"__builtin_ia32_vpcomfalseub", +"__builtin_ia32_vpcomfalseud", +"__builtin_ia32_vpcomfalseuq", +"__builtin_ia32_vpcomfalseuw", +"__builtin_ia32_vpcomfalsew", +"__builtin_ia32_vpcomgeb", +"__builtin_ia32_vpcomged", +"__builtin_ia32_vpcomgeq", +"__builtin_ia32_vpcomgeub", +"__builtin_ia32_vpcomgeud", +"__builtin_ia32_vpcomgeuq", +"__builtin_ia32_vpcomgeuw", +"__builtin_ia32_vpcomgew", +"__builtin_ia32_vpcomgtb", +"__builtin_ia32_vpcomgtd", +"__builtin_ia32_vpcomgtq", +"__builtin_ia32_vpcomgtub", +"__builtin_ia32_vpcomgtud", +"__builtin_ia32_vpcomgtuq", +"__builtin_ia32_vpcomgtuw", +"__builtin_ia32_vpcomgtw", +"__builtin_ia32_vpcomleb", +"__builtin_ia32_vpcomled", +"__builtin_ia32_vpcomleq", +"__builtin_ia32_vpcomleub", +"__builtin_ia32_vpcomleud", +"__builtin_ia32_vpcomleuq", +"__builtin_ia32_vpcomleuw", +"__builtin_ia32_vpcomlew", +"__builtin_ia32_vpcomltb", +"__builtin_ia32_vpcomltd", +"__builtin_ia32_vpcomltq", +"__builtin_ia32_vpcomltub", +"__builtin_ia32_vpcomltud", +"__builtin_ia32_vpcomltuq", +"__builtin_ia32_vpcomltuw", +"__builtin_ia32_vpcomltw", +"__builtin_ia32_vpcomneb", +"__builtin_ia32_vpcomned", +"__builtin_ia32_vpcomneq", +"__builtin_ia32_vpcomneub", +"__builtin_ia32_vpcomneud", +"__builtin_ia32_vpcomneuq", +"__builtin_ia32_vpcomneuw", +"__builtin_ia32_vpcomnew", +"__builtin_ia32_vpcomtrueb", +"__builtin_ia32_vpcomtrued", +"__builtin_ia32_vpcomtrueq", +"__builtin_ia32_vpcomtrueub", +"__builtin_ia32_vpcomtrueud", +"__builtin_ia32_vpcomtrueuq", +"__builtin_ia32_vpcomtrueuw", +"__builtin_ia32_vpcomtruew", +"__builtin_ia32_vphaddbd", +"__builtin_ia32_vphaddbq", +"__builtin_ia32_vphaddbw", +"__builtin_ia32_vphadddq", +"__builtin_ia32_vphaddubd", +"__builtin_ia32_vphaddubq", +"__builtin_ia32_vphaddubw", +"__builtin_ia32_vphaddudq", +"__builtin_ia32_vphadduwd", +"__builtin_ia32_vphadduwq", +"__builtin_ia32_vphaddwd", +"__builtin_ia32_vphaddwq", +"__builtin_ia32_vphsubbw", +"__builtin_ia32_vphsubdq", +"__builtin_ia32_vphsubwd", +"__builtin_ia32_vpmacsdd", +"__builtin_ia32_vpmacsdqh", +"__builtin_ia32_vpmacsdql", +"__builtin_ia32_vpmacssdd", +"__builtin_ia32_vpmacssdqh", +"__builtin_ia32_vpmacssdql", +"__builtin_ia32_vpmacsswd", +"__builtin_ia32_vpmacssww", +"__builtin_ia32_vpmacswd", +"__builtin_ia32_vpmacsww", +"__builtin_ia32_vpmadcsswd", +"__builtin_ia32_vpmadcswd", +"__builtin_ia32_vpperm", +"__builtin_ia32_vprotb", +"__builtin_ia32_vprotd", +"__builtin_ia32_vprotq", +"__builtin_ia32_vprotw", +"__builtin_ia32_vpshab", +"__builtin_ia32_vpshad", +"__builtin_ia32_vpshaq", +"__builtin_ia32_vpshaw", +"__builtin_ia32_vpshlb", +"__builtin_ia32_vpshld", +"__builtin_ia32_vpshlq", +"__builtin_ia32_vpshlw", +"__builtin_ia32_vfmaddpd", +"__builtin_ia32_vfmaddps", +"__builtin_ia32_vfmaddsd", +"__builtin_ia32_vfmaddss", +"__builtin_ia32_vfmsubpd", +"__builtin_ia32_vfmsubps", +"__builtin_ia32_vfmsubsd", +"__builtin_ia32_vfmsubss", +"__builtin_ia32_vfnmaddpd", +"__builtin_ia32_vfnmaddps", +"__builtin_ia32_vfnmaddsd", +"__builtin_ia32_vfnmaddss", +"__builtin_ia32_vfnmsubpd", +"__builtin_ia32_vfnmsubps", +"__builtin_ia32_vfnmsubsd", +"__builtin_ia32_vfnmsubss", +"__builtin_ia32_vfmaddpd256", +"__builtin_ia32_vfmaddps256", +"__builtin_ia32_vfmsubpd256", +"__builtin_ia32_vfmsubps256", +"__builtin_ia32_vfnmaddpd256", +"__builtin_ia32_vfnmaddps256", +"__builtin_ia32_vfnmsubpd256", +"__builtin_ia32_vfnmsubps256", +"__builtin_ia32_vfmaddsubpd256", +"__builtin_ia32_vfmaddsubps256", +"__builtin_ia32_vfmsubaddpd256", +"__builtin_ia32_vfmsubaddps256", +"__builtin_ia32_llwpcb16", +"__builtin_ia32_llwpcb32", +"__builtin_ia32_llwpcb64", +"__builtin_ia32_lwpval16", +"__builtin_ia32_lwpval32", +"__builtin_ia32_lwpval64", +"__builtin_ia32_lwpins16", +"__builtin_ia32_lwpins32", +"__builtin_ia32_lwpins64", +"__builtin_ia32_bextr_u64", +"__builtin_ia32_lzcnt_u64", +"__builtin_ia32_fxsave", +"__builtin_ia32_fxrstor", +"__builtin_ia32_fxsave64", +"__builtin_ia32_fxrstor64", +"__builtin_ia32_xsave", +"__builtin_ia32_xrstor", +"__builtin_ia32_xsave64", +"__builtin_ia32_xrstor64", +"__builtin_ia32_xsaveopt", +"__builtin_ia32_xsaveopt64", +"__builtin_ia32_bextri_u32", +"__builtin_ia32_bextri_u64", +"__builtin_ia32_femms", +"__builtin_ia32_pavgusb", +"__builtin_ia32_pf2id", +"__builtin_ia32_pfacc", +"__builtin_ia32_pfadd", +"__builtin_ia32_pfcmpeq", +"__builtin_ia32_pfcmpge", +"__builtin_ia32_pfcmpgt", +"__builtin_ia32_pfmax", +"__builtin_ia32_pfmin", +"__builtin_ia32_pfmul", +"__builtin_ia32_pfrcp", +"__builtin_ia32_pfrcpit1", +"__builtin_ia32_pfrcpit2", +"__builtin_ia32_pfrsqrt", +"__builtin_ia32_pfsub", +"__builtin_ia32_pfsubr", +"__builtin_ia32_pi2fd", +"__builtin_ia32_pmulhrw", +"__builtin_ia32_pf2iw", +"__builtin_ia32_pfnacc", +"__builtin_ia32_pfpnacc", +"__builtin_ia32_pi2fw", +"__builtin_ia32_pswapdsf", +"__builtin_ia32_pswapdsi", +"__builtin_ia32_xbegin", +"__builtin_ia32_xend", +"__builtin_ia32_xabort", +"__builtin_ia32_xtest", +"__builtin_ia32_monitorx", +"__builtin_ia32_mwaitx", +"__builtin_ia32_wrpkru", +"__builtin_ia32_rdpkru", +"__builtin_ia32_rdsspd", +"__builtin_ia32_rdsspq", +"__builtin_ia32_incsspd", +"__builtin_ia32_incsspq", +"__has_nothrow_assign", +"__has_trivial_assign", +"__has_nothrow_copy", +"__has_trivial_copy", +"__has_nothrow_constructor", +"__has_trivial_constructor", +"__is_pod", +"__has_trivial_destructor", +"__has_virtual_destructor", +"__is_abstract", +"__is_base_of", +"__is_class", +"__is_empty", +"__is_enum", +"__is_literal_type", +"__is_polymorphic", +"__is_standard_layout", +"__is_trivial", +"__is_union", +"__underlying_type", +"__integer_pack", +"__is_same", +"COSMOPOLITAN_CXX_START_", +"COSMOPOLITAN_CXX_END_", +"COSMOPOLITAN_CXX_USING_", +"COSMOPOLITAN_C_START_", +"COSMOPOLITAN_C_END_", +"MACHINE_CODE_ANALYSIS_BEGIN_", +"MACHINE_CODE_ANALYSIS_END_", +"typescompatible", +"DebugBreak", +"VEIL", +"CONCEAL", +"EXPROPRIATE", +"YOINK", +"STATIC_YOINK", +"STATIC_YOINK_SOURCE", +"STRINGIFY", +"isconstant", +"chooseexpr", +"likely", +"unlikely", +"assume", + } + }, + + { Id=4, + List= { +"NULL", +"true", +"false", +"__func__", +"__VA_ARGS__", +"__STDC__", +"__STDC_HOSTED__", +"__STDC_VERSION__", +"__TIME__", +"__STDC_ISO_10646__", +"__STDC_MB_MIGHT_NEQ_WC__", +"__STDC_UTF_16__", +"__STDC_UTF_32__", +"__STDC_ANALYZABLE__", +"__STDC_IEC_559_COMPLEX__", +"__STDC_LIB_EXT1__", +"__STDC_NO_ATOMICS__", +"__STDC_NO_COMPLEX__", +"__STDC_NO_THREADS__", +"__STDC_NO_VLA__", +"__STDC_WANT_LIB_EXT1__", +"IMAGE_BASE_VIRTUAL", +"IMAGE_BASE_REAL", +"IMAGE_BASE_PHYSICAL", +"SIZEOF_SHORT", +"SIZEOF_INT", +"SIZEOF_LONG", +"SIZEOF_LONG_LONG", +"SIZEOF_POINTER", +"SIZEOF_PTRDIFF_T", +"SIZEOF_SIZE_T", +"SIZEOF_WCHAR_T", +"SIZEOF_WINT_T", +"SIZEOF_FLOAT", +"SIZEOF_FLOAT128", +"SIZEOF_DOUBLE", +"SIZEOF_FLOAT80", +"SIZEOF_LONG_DOUBLE", +"SIZEOF_INTMAX", +"SCHAR_MAX", +"SHRT_MAX", +"INT_MAX", +"LONG_MAX", +"LLONG_MAX", +"LONG_LONG_MAX", +"SIZE_MAX", +"INT8_MAX", +"INT16_MAX", +"INT32_MAX", +"INT64_MAX", +"INT128_MAX", +"WINT_MAX", +"WCHAR_MAX", +"INTPTR_MAX", +"PTRDIFF_MAX", +"SCHAR_MIN", +"SHRT_MIN", +"UINT_MIN", +"INT_MIN", +"LONG_MIN", +"LLONG_MIN", +"LONG_LONG_MIN", +"SIZE_MIN", +"INT8_MIN", +"INT16_MIN", +"INT32_MIN", +"INT64_MIN", +"INT128_MIN", +"INTMAX_MIN", +"INTPTR_MIN", +"WINT_MIN", +"WCHAR_MIN", +"PTRDIFF_MIN", +"USHRT_MAX", +"UINT_MAX", +"ULONG_MAX", +"ULLONG_MAX", +"ULONG_LONG_MAX", +"UINTPTR_MAX", +"UINT8_MAX", +"UINT16_MAX", +"UINT32_MAX", +"UINT64_MAX", +"UINT128_MAX", +"USHRT_MIN", +"ULONG_MIN", +"ULLONG_MIN", +"ULONG_LONG_MIN", +"UINT8_MIN", +"UINT16_MIN", +"UINT32_MIN", +"UINT64_MIN", +"UINT128_MIN", +"UINTMAX_MIN", +"UINTPTR_MIN", +"MB_CUR_MAX", +"MB_LEN_MAX", +"INTMAX_MAX", +"UINTMAX_MAX", +"INTMAX_MAX", +"UINTMAX_MAX", +"DBL_MIN", +"DBL_MAX", +"FLT_MIN", +"FLT_MAX", +"__SAUCE__", +"PAGESIZE", +"FRAMESIZE", +"BIGPAGESIZE", +"STACKSIZE", +"ENV_MAX", +"ARG_MAX", +"CMD_MAX", +"PATH_MAX", +"BUFSIZ", +"CACHELINE", +"CHAR_BIT", +"NAME_MAX", +"NSIG", +"CHILD_MAX", +"OPEN_MAX", +"ATEXIT_MAX", +"IM_FEELING_NAUGHTY", +"__REAL_MODE__", +"__x86__", +"__i386__", +"__W__", +"__PG__", +"__MFENTRY__", +"__MNO_VZEROUPPER__", +"__FSANITIZE_UNDEFINED__", +"__MNOP_MCOUNT__", +"__MRECORD_MCOUNT__", +"__x86_64__", +"__amd64__", +"__WINT_MAX__", +"__BIGGEST_ALIGNMENT__", +"__SIZE_MAX__", +"__PTRDIFF_MAX__", +"__UINTMAX_MAX__", +"__SIG_ATOMIC_MAX__", +"__INT8_MAX__", +"__INT16_MAX__", +"__INT32_MAX__", +"__INT64_MAX__", +"__UINT8_MAX__", +"__UINT16_MAX__", +"__UINT32_MAX__", +"__UINT64_MAX__", +"__INT_LEAST8_MAX__", +"__INT_LEAST16_MAX__", +"__INT_LEAST32_MAX__", +"__INT_LEAST64_MAX__", +"__UINT_LEAST8_MAX__", +"__UINT_LEAST16_MAX__", +"__UINT_LEAST32_MAX__", +"__UINT_LEAST64_MAX__", +"__INT_FAST8_MAX__", +"__INT_FAST16_MAX__", +"__INT_FAST32_MAX__", +"__INT_FAST64_MAX__", +"__UINT_FAST8_MAX__", +"__UINT_FAST16_MAX__", +"__UINT_FAST32_MAX__", +"__UINT_FAST64_MAX__", +"__INTPTR_MAX__", +"__UINTPTR_MAX__", +"__WCHAR_MIN__", +"__WINT_MIN__", +"__SIG_ATOMIC_MIN__", +"__SCHAR_WIDTH__", +"__SHRT_WIDTH__", +"__INT_WIDTH__", +"__LONG_WIDTH__", +"__LONG_LONG_WIDTH__", +"__PTRDIFF_WIDTH__", +"__SIG_ATOMIC_WIDTH__", +"__SIZE_WIDTH__", +"__WCHAR_WIDTH__", +"__WINT_WIDTH__", +"__INT_LEAST8_WIDTH__", +"__INT_LEAST16_WIDTH__", +"__INT_LEAST32_WIDTH__", +"__INT_LEAST64_WIDTH__", +"__INT_FAST8_WIDTH__", +"__INT_FAST16_WIDTH__", +"__INT_FAST32_WIDTH__", +"__INT_FAST64_WIDTH__", +"__INTPTR_WIDTH__", +"__INTMAX_WIDTH__", +"__SIZEOF_INT__", +"__SIZEOF_INTMAX__", +"__SIZEOF_UINTMAX__", +"__SIZEOF_LONG__", +"__SIZEOF_LONG_LONG__", +"__SIZEOF_SHORT__", +"__SIZEOF_POINTER__", +"__SIZEOF_FLOAT__", +"__SIZEOF_DOUBLE__", +"__SIZEOF_LONG_DOUBLE__", +"__SIZEOF_SIZE_T__", +"__SIZEOF_WCHAR_T__", +"__SIZEOF_WINT_T__", +"__SIZEOF_PTRDIFF_T__", +"__TIMESTAMP__", +"__BASE_FILE__", +"__CHAR_BIT__", +"__FUNCTION__", +"__GNUC_MINOR__", +"__GNUC_PATCHLEVEL__", +"__GNUC__", +"__GNUG__", +"__INCLUDE_LEVEL__", +"__INTMAX_MAX__", +"__INT_MAX__", +"__LONG_LONG_MAX__", +"__LONG_MAX__", +"__SCHAR_MAX__", +"__SHRT_MAX__", +"__DBL_MIN__", +"__DBL_MAX__", +"__FLT_MIN__", +"__FLT_MAX__", +"__WCHAR_MAX__", +"__WCHAR_UNSIGNED__", +"__AES__", +"__AVX__", +"__AVX2__", +"__ABM__", +"__BMI__", +"__BMI2__", +"__FMA__", +"__ADX__", +"__PCLMUL__", +"__POPCNT__", +"__RDRND__", +"__RDSEED__", +"__SHA__", +"__SSE__", +"__SSE2__", +"__SSE3__", +"__SSSE3__", +"__SSE4_1__", +"__SSE4_2__", +"__XSAVE__", +"__CLFLUSHOPT__", +"__RDPID__", +"__STDC_IEC_559__", +"__FILE__", +"__LINE__", +"__DATE__", + } + }, + +-- { Id=3, +-- List= { +-- "typedef", "inline", "auto", "class", "explicit", "extern", "friend", "inline", "mutable", "operator", +-- "register", "template", "private", "protected", "public", "typeid", "virtual", "volatile", "constexpr", "nullptr", "decltype" +-- } +-- }, +-- { Id=3, +-- Regex=[[(\w+)\s*\:\:]] +-- }, +-- { Id=4, +-- Regex=[[(\w+)\s*\(]] +-- } +} + +Strings = { + Delimiter=[["|']], + RawPrefix="R", + Escape=[=[\\[abtnvfre\\\?'"]|\\\d{1,3}|\\x[[:xdigit:]]{2}]=], +} + +Comments = { + { Block=true, + Nested=false, + Delimiter = { [[\/\*]], [[\*\/]] } + }, + { + Block=false, + Delimiter = { [[//]] } + } +} + +IgnoreCase=false + +PreProcessor = { + Prefix=[[#]], + Continuation="\\", +} + +Operators=[[\(|\)|\[|\]|\{|\}|\,|\;|\.|\:|\&|<|>|\!|=|\/|\*|\%|\+|\-|\~|\||\^|\?]] + +EnableIndentation=true + +-- resolve issue with C++14 number separator syntax +function OnStateChange(oldState, newState, token) + + if token=="'" and oldState==HL_NUMBER and newState==HL_STRING then + return HL_NUMBER + end + + return newState +end diff --git a/tool/emacs/cosmo-c-builtins.el b/tool/emacs/cosmo-c-builtins.el index f8676939..e01b2529 100644 --- a/tool/emacs/cosmo-c-builtins.el +++ b/tool/emacs/cosmo-c-builtins.el @@ -1289,8 +1289,7 @@ "isconstant" "chooseexpr" "likely" - "unlikely" - "assume")) + "unlikely")) ) (concat "\\_<" diff --git a/tool/emacs/cosmo-c-keywords.el b/tool/emacs/cosmo-c-keywords.el index 6d7193bf..17aaa4d4 100644 --- a/tool/emacs/cosmo-c-keywords.el +++ b/tool/emacs/cosmo-c-keywords.el @@ -124,8 +124,7 @@ ;; "delete")) (cosmo - '("__rbx" - "__msabi" + '("__msabi" "offsetof" "microarchitecture" "targetclones" diff --git a/tool/net/echoserver.c b/tool/net/echoserver.c index 43eacfdc..71b9734c 100644 --- a/tool/net/echoserver.c +++ b/tool/net/echoserver.c @@ -17,8 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" -#include "libc/bits/safemacros.h" +#include "libc/alg/arraylist.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" #include "libc/errno.h" diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 1f6bd837..82ab65c0 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -17,10 +17,10 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist2.h" +#include "libc/alg/arraylist2.internal.h" #include "libc/bits/bits.h" #include "libc/bits/bswap.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/itimerval.h" @@ -38,7 +38,6 @@ #include "libc/nexgen32e/crc32.h" #include "libc/rand/rand.h" #include "libc/runtime/gc.h" -#include "libc/runtime/missioncritical.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/stdio/stdio.h" diff --git a/tool/tags/tags.c b/tool/tags/tags.c index f4ff10df..9efa0246 100644 --- a/tool/tags/tags.c +++ b/tool/tags/tags.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/conv/conv.h" #include "libc/errno.h" diff --git a/tool/viz/basicidea.c b/tool/viz/basicidea.c index b04bfa3a..2604fc21 100644 --- a/tool/viz/basicidea.c +++ b/tool/viz/basicidea.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" #include "libc/calls/ioctl.h" diff --git a/tool/viz/cpuid.c b/tool/viz/cpuid.c index 4cca2a28..6704d90c 100644 --- a/tool/viz/cpuid.c +++ b/tool/viz/cpuid.c @@ -17,9 +17,9 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/log.h" -#include "libc/nexgen32e/cpuid4.h" +#include "libc/nexgen32e/cpuid4.internal.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/rdtscp.h" #include "libc/nexgen32e/x86feature.h" diff --git a/tool/viz/deathstar.c b/tool/viz/deathstar.c index fc115063..e3f90ffe 100644 --- a/tool/viz/deathstar.c +++ b/tool/viz/deathstar.c @@ -1,9 +1,9 @@ #include "dsp/tty/tty.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/termios.h" #include "libc/log/check.h" -#include "libc/log/color.h" +#include "libc/log/color.internal.h" #include "libc/log/log.h" #include "libc/macros.h" #include "libc/math.h" diff --git a/tool/viz/fold.c b/tool/viz/fold.c index e54197e8..0590ccdb 100644 --- a/tool/viz/fold.c +++ b/tool/viz/fold.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/conv.h" #include "libc/errno.h" #include "libc/runtime/runtime.h" diff --git a/tool/viz/generatematrix.c b/tool/viz/generatematrix.c index d0471e8e..01746820 100644 --- a/tool/viz/generatematrix.c +++ b/tool/viz/generatematrix.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/conv.h" #include "libc/fmt/fmt.h" #include "libc/limits.h" diff --git a/tool/viz/lib/convolve.h b/tool/viz/lib/convolve.h index b6eefbe2..66ca3181 100644 --- a/tool/viz/lib/convolve.h +++ b/tool/viz/lib/convolve.h @@ -1,6 +1,6 @@ #ifndef COSMOPOLITAN_TOOL_VIZ_LIB_CONVOLVE_H_ #define COSMOPOLITAN_TOOL_VIZ_LIB_CONVOLVE_H_ -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/str/str.h" #include "tool/viz/lib/graphic.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) diff --git a/tool/viz/lib/formatstringtable-assembly.c b/tool/viz/lib/formatstringtable-assembly.c index e9ebe17a..bba29f7b 100644 --- a/tool/viz/lib/formatstringtable-assembly.c +++ b/tool/viz/lib/formatstringtable-assembly.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/itoa.h" #include "libc/runtime/gc.h" #include "libc/str/str.h" diff --git a/tool/viz/lib/formatstringtable-code.c b/tool/viz/lib/formatstringtable-code.c index e1e2fe6d..271c11ee 100644 --- a/tool/viz/lib/formatstringtable-code.c +++ b/tool/viz/lib/formatstringtable-code.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/itoa.h" #include "tool/viz/lib/formatstringtable.h" diff --git a/tool/viz/lib/formatstringtable.c b/tool/viz/lib/formatstringtable.c index 064ae58d..17fcf6f1 100644 --- a/tool/viz/lib/formatstringtable.c +++ b/tool/viz/lib/formatstringtable.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/unicode/unicode.h" #include "tool/viz/lib/formatstringtable.h" diff --git a/tool/viz/lib/gaussian.c b/tool/viz/lib/gaussian.c index 00da03c6..2b44abb5 100644 --- a/tool/viz/lib/gaussian.c +++ b/tool/viz/lib/gaussian.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/macros.h" #include "libc/mem/mem.h" #include "libc/str/str.h" diff --git a/tool/viz/lib/getxtermcodes.c b/tool/viz/lib/getxtermcodes.c index d83b7777..4cd87f94 100644 --- a/tool/viz/lib/getxtermcodes.c +++ b/tool/viz/lib/getxtermcodes.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/quant.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/macros.h" #include "tool/viz/lib/graphic.h" diff --git a/tool/viz/lib/perlin3.c b/tool/viz/lib/perlin3.c index a6722ffa..d4b6a76c 100644 --- a/tool/viz/lib/perlin3.c +++ b/tool/viz/lib/perlin3.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" -#include "libc/bits/initializer.h" +#include "libc/bits/initializer.internal.h" #include "libc/macros.h" #include "libc/math.h" #include "tool/viz/lib/graphic.h" diff --git a/tool/viz/lib/resizegraphic.c b/tool/viz/lib/resizegraphic.c index f291604f..0e184675 100644 --- a/tool/viz/lib/resizegraphic.c +++ b/tool/viz/lib/resizegraphic.c @@ -18,7 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/runtime/buffer.h" #include "tool/viz/lib/graphic.h" diff --git a/tool/viz/lib/ycbcr2rgb3.c b/tool/viz/lib/ycbcr2rgb3.c index 9a0feb0b..240320e6 100644 --- a/tool/viz/lib/ycbcr2rgb3.c +++ b/tool/viz/lib/ycbcr2rgb3.c @@ -26,7 +26,7 @@ #include "dsp/core/illumination.h" #include "dsp/core/q.h" #include "dsp/scale/scale.h" -#include "libc/bits/xmmintrin.h" +#include "libc/bits/xmmintrin.internal.h" #include "libc/calls/calls.h" #include "libc/calls/sigbits.h" #include "libc/calls/struct/sigset.h" @@ -36,7 +36,7 @@ #include "libc/macros.h" #include "libc/math.h" #include "libc/mem/mem.h" -#include "libc/nexgen32e/gc.h" +#include "libc/nexgen32e/gc.internal.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/x86feature.h" #include "libc/runtime/gc.h" diff --git a/tool/viz/life.c b/tool/viz/life.c index d1d110d5..2bb0ad93 100644 --- a/tool/viz/life.c +++ b/tool/viz/life.c @@ -17,26 +17,73 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "dsp/core/gamma.h" +#include "dsp/scale/scale.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/popcnt.h" +#include "libc/bits/safemacros.internal.h" +#include "libc/bits/xchg.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/termios.h" #include "libc/calls/struct/winsize.h" -#include "libc/calls/termios-internal.h" +#include "libc/calls/termios.internal.h" #include "libc/conv/conv.h" +#include "libc/conv/itoa.h" #include "libc/dce.h" #include "libc/errno.h" +#include "libc/fmt/fmt.h" +#include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.h" #include "libc/mem/mem.h" +#include "libc/nexgen32e/nt2sysv.h" +#include "libc/nt/comdlg.h" +#include "libc/nt/dll.h" +#include "libc/nt/enum/bitblt.h" +#include "libc/nt/enum/color.h" +#include "libc/nt/enum/cs.h" +#include "libc/nt/enum/cw.h" +#include "libc/nt/enum/ht.h" +#include "libc/nt/enum/idc.h" +#include "libc/nt/enum/mb.h" +#include "libc/nt/enum/mf.h" +#include "libc/nt/enum/mk.h" +#include "libc/nt/enum/ofn.h" +#include "libc/nt/enum/rdw.h" +#include "libc/nt/enum/sc.h" +#include "libc/nt/enum/size.h" +#include "libc/nt/enum/sw.h" +#include "libc/nt/enum/tpm.h" +#include "libc/nt/enum/vk.h" +#include "libc/nt/enum/wm.h" +#include "libc/nt/enum/ws.h" +#include "libc/nt/events.h" +#include "libc/nt/messagebox.h" +#include "libc/nt/paint.h" +#include "libc/nt/struct/msg.h" +#include "libc/nt/struct/openfilename.h" +#include "libc/nt/struct/paintstruct.h" +#include "libc/nt/struct/windowplacement.h" +#include "libc/nt/struct/wndclass.h" +#include "libc/nt/windows.h" +#include "libc/rand/rand.h" #include "libc/runtime/runtime.h" +#include "libc/sock/sock.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/tpenc.h" +#include "libc/sysv/consts/ex.h" +#include "libc/sysv/consts/exit.h" +#include "libc/sysv/consts/map.h" +#include "libc/sysv/consts/poll.h" +#include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/termios.h" +#include "libc/time/time.h" +#include "libc/unicode/unicode.h" #include "libc/x/x.h" +#include "third_party/getopt/getopt.h" /** * @fileoverview Conway's Game of Life @@ -46,18 +93,79 @@ * is Turing complete and can simulate a universal constructor or any * other Turing machine. * - * This program may be used by dragging the mouse in the terminal. Left - * mouse draws or erases cells. Right mouse scrolls or moves the plane. - * The space bar may be held down to move time forward. + * There's about 20 million Software Engineers in the world, which means + * Game of Life has likely been implemented 20 million times before. Why + * do we need this one? * - * This implementation uses bitboards on an n×m wraparound plane. For an - * explanation of how this technique works on an 8×8 plane see "Bitboard - * Methods for Games" by Cameron Browne. + * - It's a tutorial on how to build an Actually Portable Executable + * that'll run as a GUI on Windows, and as a TUI on Linux/Mac/BSDs + * using roughly one thousand lines of code. For a much better GUI + * that's not as hackable, try Golly: http://golly.sourceforge.net + * + * - It's a tutorial on how to implement XTERM mouse cursor dragging + * where zooming in/out can be performed too using ctrl+mousewheel + * which is an underused (but easily implemented) terminal feature + * that even the Windows10 Command Prompt supports these days. + * + * - It uses bitboards. That's almost as simple as the naive approach + * but goes significantly faster, needing 150 picoseconds per board + * position. See "Bitboard Methods for Games" by Cameron Browne for + * further details on how it works. More advanced algorithms exist, + * such as Hashlife: quadtree memoization to make humongous numbers + * of generations tractable. + * + * Here's how you can compile this program on Linux: + * + * git clone https://github.com/jart/cosmopolitan && cd cosmopolitan + * make -j12 o//tool/viz/life.com + * + * The output binary works on Linux, Windows, Mac, and FreeBSD: + * + * o//tool/viz/life.com + * + * @see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life + * @see https://www.conwaylife.com/wiki/Run_Length_Encoded + * @see http://golly.sourceforge.net/ */ +#define USAGE \ + " [-zNW] [-w WIDTH] [-h HEIGHT] [PATH]\n\ +\n\ +DESCRIPTION\n\ +\n\ + Conway's Game of Life\n\ +\n\ +FLAGS\n\ +\n\ + -? help\n\ + -z zoom\n\ + -w INT board width\n\ + -h INT board height\n\ + -N natural scrolling\n\ + -W white terminal background\n\ +\n\ +SHORTCUTS\n\ +\n\ + space step\n\ + left+drag draw\n\ + right+drag move\n\ + ctrl+wheel zoom\n\ + ctrl+t turbo\n\ + alt+t slowmo\n\ + R reset\n\ + q quit\n\ +\n" + +#define MAXZOOM 14 +#define VOIDSPACE "." +#define ALT (1 << 29) + #define INTERRUPTED 1 #define RESIZED 2 +#define IDM_ABOUT 0x10 +#define IDM_OPEN 0x20 + #define MOUSE_LEFT_DOWN 0 #define MOUSE_MIDDLE_DOWN 1 #define MOUSE_RIGHT_DOWN 2 @@ -72,6 +180,56 @@ #define MOUSE_CTRL_WHEEL_UP 80 #define MOUSE_CTRL_WHEEL_DOWN 81 +struct Buffer { + unsigned i, n; + char *p; +}; + +static bool erase; +static bool white; +static bool natural; +static bool mousemode; +static bool isdragging; +static bool dimensioned; + +static int out; +static int line; +static int column; +static int action; +static int color[2]; + +static long top; +static long bottom; +static long left; +static long right; +static long tyn; +static long txn; +static long byn; +static long bxn; +static long zoom; +static long speed; +static long save_y; +static long save_x; +static long save_top; +static long save_left; +static long generation; + +static uint64_t *board; +static uint64_t *board2; +static size_t boardsize; +static int64_t oldcursor; + +static struct Buffer buffer; +static struct termios oldterm; + +static char name[64]; +static char statusline[256]; +static char16_t statusline16[256]; + +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § game of life » algorithm ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + #define LEFT 0x0101010101010101ul #define RIGHT 0x8080808080808080ul #define TOP 0x00000000000000FFul @@ -90,16 +248,16 @@ #define ADD(X) \ do { \ uint64_t c1, c2; \ - c1 = r[0] & (X); \ - c2 = r[1] & c1; \ - r[0] ^= (X); \ - r[1] ^= c1; \ - r[2] |= c2; \ + c1 = r0 & (X); \ + c2 = r1 & c1; \ + r0 ^= (X); \ + r1 ^= c1; \ + r2 |= c2; \ } while (0) #define STEP(RES, B00, B01, B02, B10, B11, B12, B20, B21, B22) \ do { \ - uint64_t r[3] = {0}; \ + uint64_t r0 = 0, r1 = 0, r2 = 0; \ ADD(GORIGHT(GODOWN(B11)) | GORIGHT(BOTMOST(B01) >> 56) | \ GODOWN(RIGHTMOST(B10) >> 7) | BOTMOST(RIGHTMOST(B00)) >> 7 >> 56); \ ADD(GORIGHT(B11) | RIGHTMOST(B10) >> 7); \ @@ -112,48 +270,445 @@ ADD(GOLEFT(B11) | LEFTMOST(B12) << 7); \ ADD(GOLEFT(GOUP(B11)) | GOLEFT(TOPMOST(B21) << 56) | \ GOUP(LEFTMOST(B12) << 7) | TOPMOST(LEFTMOST(B22)) << 7 << 56); \ - RES = (B11 | r[0]) & r[1] & ~r[2]; \ + RES = (B11 | r0) & r1 & ~r2; \ } while (0) -struct Buffer { - unsigned i, n; +static void Step(void) { + long y, x, yn, xn; + yn = byn >> 3; + xn = bxn >> 3; + for (y = 0; y < yn; ++y) { + for (x = 0; x < xn; ++x) { + STEP(board2[y * xn + x], + board[(y ? y - 1 : yn - 1) * xn + (x ? x - 1 : xn - 1)], + board[(y ? y - 1 : yn - 1) * xn + x], + board[(y ? y - 1 : yn - 1) * xn + (x + 1 < xn ? x + 1 : 0)], + board[y * xn + (x ? x - 1 : xn - 1)], board[y * xn + x], + board[y * xn + (x + 1 < xn ? x + 1 : 0)], + board[(y + 1 < yn ? y + 1 : 0) * xn + (x ? x - 1 : xn - 1)], + board[(y + 1 < yn ? y + 1 : 0) * xn + x], + board[(y + 1 < yn ? y + 1 : 0) * xn + (x + 1 < xn ? x + 1 : 0)]); + } + } + xchg(&board, &board2); + ++generation; +} + +static bool Test(long y, long x) { + return (board[(bxn >> 3) * (y >> 3) + (x >> 3)] >> + (((y & 7) << 3) + (x & 7))) & + 1; +} + +static void Set(long y, long x) { + board[(bxn >> 3) * (y >> 3) + (x >> 3)] |= 1ul << (((y & 7) << 3) + (x & 7)); +} + +static void Unset(long y, long x) { + board[(bxn >> 3) * (y >> 3) + (x >> 3)] &= + ~(1ul << (((y & 7) << 3) + (x & 7))); +} + +static long Population(void) { + long i, n, p; + n = (byn * bxn) >> 6; + for (p = i = 0; i < n; ++i) { + p += popcnt(board[i]); + } + return p; +} + +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § game of life » buffer ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + +static void AppendData(char *data, unsigned len) { char *p; -}; + unsigned n; + if (buffer.i + len + 1 > buffer.n) { + n = MAX(buffer.i + len + 1, MAX(16, buffer.n + (buffer.n >> 1))); + if (!(p = realloc(buffer.p, n))) return; + buffer.p = p; + buffer.n = n; + } + memcpy(buffer.p + buffer.i, data, len); + buffer.p[buffer.i += len] = 0; +} -static bool erase; -static bool natural; -static bool mousemode; +static void AppendChar(char c) { + AppendData(&c, 1); +} -static int out; -static int action; +#define AppendStr(s) AppendData(s, strlen(s)) -static long top; -static long bottom; -static long left; -static long right; -static long tyn; -static long txn; -static long byn; -static long bxn; -static long save_y; -static long save_x; -static long save_top; -static long save_left; +static void AppendInt(long x) { + char ibuf[21]; + AppendData(ibuf, int64toarray_radix10(x, ibuf)); +} -static uint64_t *board; +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § game of life » board control ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ -static struct Buffer buffer; -static struct termios oldterm; +static void Generation(void) { + long i; + for (i = 0; i < speed; ++i) { + Step(); + } +} + +static void Dimension(void) { + if (!dimensioned) { + top = byn / 2 - tyn / 2; + left = bxn / 2 - txn / 2; + dimensioned = true; + } + right = left + txn; + bottom = top + tyn; +} + +static void Move(long dy, long dx) { + long yn, xn; + yn = zoom ? tyn * 2 : tyn; + xn = txn; + top = top + (dy << zoom); + left = left + (dx << zoom); + bottom = top + (yn << zoom); + right = left + (xn << zoom); +} + +static void OnUp(void) { + Move(-1, 0); +} + +static void OnDown(void) { + Move(+1, 0); +} + +static void OnLeft(void) { + Move(0, -1); +} + +static void OnRight(void) { + Move(0, +1); +} + +static void OnPageUp(void) { + Move(-(tyn - 2), 0); +} + +static void OnPageDown(void) { + Move(+(tyn - 2), 0); +} + +static void OnTurbo(void) { + ++speed; +} + +static void OnSlowmo(void) { + --speed; + if (speed < 1) speed = 1; +} + +static void SetZoom(long y, long x, int d) { + long a, b; + if ((0 <= y && y < tyn) && (0 <= x && x < txn)) { + a = zoom; + b = MIN(MAXZOOM, MAX(0, a + d)); + zoom = b; + Move(((y << (a + !!a)) - (y << (b + !!b))) >> b, + ((x << a) - (x << b)) >> b); + } +} + +static void OnZoom(long y, long x) { + SetZoom(y, x, +1); +} + +static void OnUnzoom(long y, long x) { + SetZoom(y, x, -1); +} + +static void OnMouseLeftDrag(long y, long x) { + if (y == save_y && x == save_x) return; + save_y = y; + save_x = x; + y = top + (y << (zoom + !!zoom)); + x = left + (x << zoom); + y += rand64() & ((1ul << (zoom + !!zoom)) - 1); + x += rand64() & ((1ul << zoom) - 1); + if (y < 0 || y >= byn) return; + if (x < 0 || x >= bxn) return; + if (erase) { + Unset(y, x); + } else { + Set(y, x); + } +} + +static void OnMouseLeftUp(long y, long x) { + isdragging = false; +} + +static void OnMouseLeftDown(long y, long x) { + isdragging = true; + save_y = y; + save_x = x; + y = top + (y << (zoom + !!zoom)); + x = left + (x << zoom); + erase = false; + if (y < 0 || y >= byn) return; + if (x < 0 || x >= bxn) return; + if ((erase = Test(y, x))) { + Unset(y, x); + } else { + Set(y, x); + } +} + +static void OnMouseRightUp(long y, long x) { + isdragging = false; +} + +static void OnMouseRightDown(long y, long x) { + isdragging = true; + save_y = y; + save_x = x; + save_top = top; + save_left = left; +} + +static void OnMouseRightDrag(long y, long x) { + long dy, dx, h, w; + dy = (save_y - y) << zoom; + dx = (save_x - x) << zoom; + if (zoom) dy <<= 1; + if (natural) { + dy = -dy; + dx = -dx; + } + h = bottom - top; + w = right - left; + top = save_top + dy; + left = save_left + dx; + bottom = top + h; + right = left + w; +} + +static void *NewBoard(size_t *out_size) { + char *p; + size_t s, n, k; + s = (byn * bxn) >> 3; + k = PAGESIZE + ROUNDUP(s, PAGESIZE); + n = ROUNDUP(k + PAGESIZE, FRAMESIZE); + p = mmap(NULL, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + mprotect(p, PAGESIZE, PROT_NONE); + mprotect(p + k, n - k, PROT_NONE); + if (out_size) *out_size = n; + return p + PAGESIZE; +} + +static void FreeBoard(void *p, size_t n) { + munmap((char *)p - PAGESIZE, n); +} + +static void AllocateBoardsWithHardwareAcceleratedMemorySafety(void) { + if (board) { + FreeBoard(board2, boardsize); + FreeBoard(board, boardsize); + } + board = NewBoard(&boardsize); + board2 = NewBoard(NULL); +} + +static void GenerateStatusLine(void) { + snprintf(statusline, sizeof(statusline), + "%s :: %,ldg %,ldp %lds %ldx %ld×%ld (%ld,%ld,%ld,%ld)", name, + generation, Population(), speed, zoom, byn, bxn, left, top, right, + bottom); +} + +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § game of life » files ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + +static void OnHeader(void) { + size_t n; + if (!buffer.i) return; + switch (buffer.p[0]) { + case 'N': + if (buffer.i > 2) { + n = MIN(buffer.i - 2, sizeof(name) - 1); + memcpy(name, buffer.p + 2, n); + name[n] = 0; + } + break; + default: + break; + } +} + +static int ReadChar(FILE *f) { + int c; + ++column; + if ((c = fgetc(f)) == -1) return -1; + if (c == '\n') { + ++line; + column = 0; + } + return c; +} + +static int GetChar(FILE *f) { + int c; + for (;;) { + if ((c = ReadChar(f)) == -1) return -1; + if (c == '#' && column == 1) { + for (;;) { + if ((c = ReadChar(f)) == -1) return -1; + if (c == '\r') { + continue; + } else if (c == '\n') { + OnHeader(); + break; + } + AppendChar(c); + } + continue; + } + return c; + } +} + +static int LoadFile(const char *path) { + FILE *f; + long c, y, x, i, j, n, yn, xn, yo, xo; + line = 0; + f = fopen(path, "r"); + if (GetChar(f) != 'x') goto ReadError; + if (GetChar(f) != ' ') goto ReadError; + if (GetChar(f) != '=') goto ReadError; + if (GetChar(f) != ' ') goto ReadError; + xn = 0; + for (;;) { + if ((c = GetChar(f)) == -1) goto ReadError; + if (!isdigit(c)) break; + xn *= 10; + xn += c - '0'; + } + do { + if ((c = GetChar(f)) == -1) goto ReadError; + } while (!isdigit(c)); + yn = 0; + do { + yn *= 10; + yn += c - '0'; + if ((c = GetChar(f)) == -1) goto ReadError; + } while (isdigit(c)); + while (c != '\n') { + if ((c = ReadChar(f)) == -1) goto ReadError; + } + if (yn > byn || xn > bxn) goto ReadError; + xchg(&board, &board2); + memset(board, 0, (byn * bxn) >> 3); + yo = byn / 2 - yn / 2; + xo = bxn / 2 - xn / 2; + y = 0; + x = 0; + for (;;) { + if ((c = GetChar(f)) == -1) goto ReadError; + if (c == '!') { + break; + } else if (isspace(c)) { + continue; + } + if (isdigit(c)) { + n = c - '0'; + for (;;) { + if ((c = GetChar(f)) == -1) goto ReadError; + if (!isdigit(c)) break; + n *= 10; + n += c - '0'; + } + } else { + n = 1; + } + if (c == '$') { + if (++y == yn) y = 0; + x = 0; + } else if (c == 'b' || c == 'o') { + for (i = 0; i < n; ++i) { + if (x >= xn) { + if (++y == yn) y = 0; + x = 0; + } + if (c == 'o') { + Set(yo + y, xo + x); + } + ++x; + } + } else { + goto ReadError; + } + } + fclose(f); + dimensioned = false; + return 0; +ReadError: + fclose(f); + xchg(&board, &board2); + return -1; +} + +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § game of life » terminal user interface ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ static int Write(const char *s) { return write(out, s, strlen(s)); } -static void HideCursor(void) { +static noreturn void PrintUsage(int rc) { + Write("SYNOPSIS\n\n "); + Write(program_invocation_name); + Write(USAGE); + exit(rc); +} + +static void GetOpts(int argc, char *argv[]) { + int opt; + while ((opt = getopt(argc, argv, "?hNWzw:h:")) != -1) { + switch (opt) { + case 'w': + bxn = strtol(optarg, NULL, 0); + bxn = ROUNDUP(MAX(8, bxn), 8); + break; + case 'h': + byn = strtol(optarg, NULL, 0); + byn = ROUNDUP(MAX(8, byn), 8); + break; + case 'z': + ++zoom; + break; + case 'N': + natural = true; + break; + case 'W': + white = true; + break; + case '?': + PrintUsage(EXIT_SUCCESS); + default: + PrintUsage(EX_USAGE); + } + } +} + +static void HideTtyCursor(void) { Write("\e[?25l"); } -static void ShowCursor(void) { +static void ShowTtyCursor(void) { Write("\e[?25h"); } @@ -168,15 +723,15 @@ static void DisableMouse(void) { } static void LeaveScreen(void) { - Write("\e[H\e[J"); + Write("\e[H\e[0m\e[J"); } static void GetTtySize(void) { struct winsize wsize; - wsize.ws_row = tyn; + wsize.ws_row = tyn + 1; wsize.ws_col = txn; getttysize(out, &wsize); - tyn = wsize.ws_row; + tyn = wsize.ws_row - 1; txn = wsize.ws_col; right = left + txn; bottom = top + tyn; @@ -197,7 +752,7 @@ static void EnableRaw(void) { static void OnExit(void) { LeaveScreen(); - ShowCursor(); + ShowTtyCursor(); DisableMouse(); ioctl(out, TCSETS, &oldterm); } @@ -210,174 +765,6 @@ static void OnSigWinch(int sig, struct siginfo *sa, struct ucontext *uc) { action |= RESIZED; } -static bool Test(long y, long x) { - return (board[(bxn >> 3) * (y >> 3) + (x >> 3)] >> - (((y & 7) << 3) + (x & 7))) & - 1; -} - -static void Set(long y, long x) { - board[(bxn >> 3) * (y >> 3) + (x >> 3)] |= 1ul << (((y & 7) << 3) + (x & 7)); -} - -static void Unset(long y, long x) { - board[(bxn >> 3) * (y >> 3) + (x >> 3)] &= - ~(1ul << (((y & 7) << 3) + (x & 7))); -} - -static void Setup(void) { - out = 1; - tyn = 80; - txn = 24; - byn = 64 * 4; - bxn = 64 * 8; - board = xcalloc((byn * bxn) >> 6, 8); - GetTtySize(); - top = byn / 2 - tyn / 2; - left = bxn / 2 - txn / 2; - right = left + txn; - bottom = top + tyn; - ioctl(out, TCGETS, &oldterm); - HideCursor(); - EnableRaw(); - EnableMouse(); - atexit(OnExit); - sigaction(SIGINT, &(struct sigaction){.sa_sigaction = OnSigInt}, NULL); - sigaction(SIGWINCH, &(struct sigaction){.sa_sigaction = OnSigWinch}, NULL); -} - -static void AppendData(char *data, unsigned len) { - char *p; - unsigned n; - if (buffer.i + len + 1 > buffer.n) { - n = MAX(buffer.i + len + 1, MAX(16, buffer.n + (buffer.n >> 1))); - if (!(p = realloc(buffer.p, n))) return; - buffer.p = p; - buffer.n = n; - } - memcpy(buffer.p + buffer.i, data, len); - buffer.p[buffer.i += len] = 0; -} - -static void AppendChar(char c) { - AppendData(&c, 1); -} - -static void AppendStr(const char *s) { - AppendData(s, strlen(s)); -} - -static void AppendWide(wint_t wc) { - unsigned i; - uint64_t wb; - char buf[8]; - i = 0; - wb = tpenc(wc); - do { - buf[i++] = wb & 0xFF; - wb >>= 8; - } while (wb); - AppendData(buf, i); -} - -static void Move(long dy, long dx) { - top = top + dy; - bottom = bottom + dy; - left = left + dx; - right = right + dx; -} - -static void OnUp(void) { - Move(-1, 0); -} - -static void OnDown(void) { - Move(+1, 0); -} - -static void OnLeft(void) { - Move(0, -1); -} - -static void OnRight(void) { - Move(0, +1); -} - -static void Generation(void) { - uint64_t *board2; - long y, x, yn, xn, yp, ym, xp, xm; - yn = byn >> 3; - xn = bxn >> 3; - board2 = xmalloc(yn * xn * 8); - for (y = 0; y < yn; ++y) { - for (x = 0; x < xn; ++x) { - ym = y ? y - 1 : yn - 1; - yp = y + 1 < yn ? y + 1 : 0; - xm = x ? x - 1 : xn - 1; - xp = x + 1 < xn ? x + 1 : 0; - STEP(board2[y * xn + x], board[ym * xn + xm], board[ym * xn + x], - board[ym * xn + xp], board[y * xn + xm], board[y * xn + x], - board[y * xn + xp], board[yp * xn + xm], board[yp * xn + x], - board[yp * xn + xp]); - } - } - free(board); - board = board2; -} - -static void OnMouseLeftDrag(long y, long x) { - if (y == save_y && x == save_x) return; - save_y = y; - save_x = x; - y += top; - x += left; - if (y < 0 || y >= byn) return; - if (x < 0 || x >= bxn) return; - if (erase) { - Unset(y, x); - } else { - Set(y, x); - } -} - -static void OnMouseLeftDown(long y, long x) { - save_y = y; - save_x = x; - y += top; - x += left; - erase = false; - if (y < 0 || y >= byn) return; - if (x < 0 || x >= bxn) return; - if ((erase = Test(y, x))) { - Unset(y, x); - } else { - Set(y, x); - } -} - -static void OnMouseRightDown(long y, long x) { - save_y = y; - save_x = x; - save_top = top; - save_left = left; -} - -static void OnMouseRightDrag(long y, long x) { - long dy, dx, h, w; - dy = save_y - y; - dx = save_x - x; - if (natural) { - dy = -dy; - dx = -dx; - } - h = bottom - top; - w = right - left; - top = save_top + dy; - left = save_left + dx; - bottom = top + h; - right = left + w; -} - static void OnMouse(char *p) { int e, x, y; e = strtol(p, &p, 10); @@ -409,18 +796,38 @@ static void OnMouse(char *p) { OnDown(); } break; + case MOUSE_CTRL_WHEEL_UP: + if (natural) { + OnZoom(y, x); + } else { + OnUnzoom(y, x); + } + break; + case MOUSE_CTRL_WHEEL_DOWN: + if (natural) { + OnUnzoom(y, x); + } else { + OnZoom(y, x); + } + break; case MOUSE_RIGHT_DOWN: OnMouseRightDown(y, x); break; case MOUSE_RIGHT_DRAG: OnMouseRightDrag(y, x); break; + case MOUSE_RIGHT_UP: + OnMouseRightUp(y, x); + break; case MOUSE_LEFT_DOWN: OnMouseLeftDown(y, x); break; case MOUSE_LEFT_DRAG: OnMouseLeftDrag(y, x); break; + case MOUSE_LEFT_UP: + OnMouseLeftUp(y, x); + break; default: break; } @@ -438,6 +845,7 @@ static void ReadKeyboard(void) { exit(0); case ' ': case 's': + case '\t': Generation(); break; case 'k': @@ -448,6 +856,9 @@ static void ReadKeyboard(void) { case CTRL('N'): OnDown(); break; + case CTRL('V'): + OnPageDown(); + break; case 'M': if (mousemode) { DisableMouse(); @@ -455,8 +866,20 @@ static void ReadKeyboard(void) { EnableMouse(); } break; + case 'R': + memset(board, 0, (byn * bxn) >> 3); + break; + case CTRL('T'): + OnTurbo(); + break; case '\e': switch (*p++) { + case 'v': + OnPageUp(); + break; + case 't': + OnSlowmo(); + break; case '[': switch (*p++) { case '<': @@ -474,6 +897,24 @@ static void ReadKeyboard(void) { case 'C': OnRight(); break; + case '5': + switch (*p++) { + case '~': + OnPageUp(); + break; + default: + break; + } + break; + case '6': + switch (*p++) { + case '~': + OnPageDown(); + break; + default: + break; + } + break; default: break; } @@ -487,41 +928,469 @@ static void ReadKeyboard(void) { } } -static void Draw(void) { +static int InvertXtermGreyscale(int x) { + return -(x - 232) + 255; +} + +static int ByteToColor(int x) { + uint8_t c; + c = x / 256. * 24 + 232; + if (white) c = InvertXtermGreyscale(c); + return c; +} + +static void SetColor(int x, bool isbg) { + if (x != color[isbg]) { + AppendStr("\e["); + AppendInt(38 + 10 * isbg); + AppendStr(";5;"); + AppendInt(x); + AppendStr("m"); + color[isbg] = x; + } +} + +static void SetFg(int x) { + SetColor(x, false); +} + +static void SetBg(int x) { + SetColor(x, true); +} + +static void BitsToBytes(uint8_t a[8], uint64_t x) { + a[0] = -((x >> 0) & 1); + a[1] = -((x >> 1) & 1); + a[2] = -((x >> 2) & 1); + a[3] = -((x >> 3) & 1); + a[4] = -((x >> 4) & 1); + a[5] = -((x >> 5) & 1); + a[6] = -((x >> 6) & 1); + a[7] = -((x >> 7) & 1); +} + +static void Raster(void) { long y, x; - buffer.i = 0; - AppendStr("\e[H"); + SetBg(ByteToColor(0)); + SetFg(ByteToColor(255)); for (y = top; y < bottom; ++y) { - if (y > top) AppendStr("\e[K\r\n"); for (x = left; x < right; ++x) { if ((0 <= y && y < byn) && (0 <= x && x < bxn)) { if (Test(y, x)) { - AppendWide(u'█'); + AppendStr("█"); } else { - AppendChar(' '); + AppendStr(" "); } } else { - AppendWide(u'∙'); + AppendStr(VOIDSPACE); } } } +} + +static void RasterZoomed(long t, long l, long b, long r, + uint8_t p[b - t][r - l]) { + uint64_t c; + uint8_t b1, b2; + long i, y, x, yn, xn; + for (y = MAX(0, t); y < MIN(b, byn); y += 8) { + for (x = MAX(0, l); x < MIN(r, bxn); x += 8) { + c = board[(bxn >> 3) * (y >> 3) + (x >> 3)]; + for (i = 0; i < 8; ++i) { + BitsToBytes(&p[y - t + i][x - l], c); + c >>= 8; + } + } + } + yn = b - t; + xn = r - l; + for (i = 0; i < zoom; ++i) { + Magikarp2xX(b - t, r - l, p, yn, xn); + Magikarp2xY(b - t, r - l, p, yn, xn); + yn >>= 1; + xn >>= 1; + } + for (y = top; y < bottom; y += 2ul << zoom) { + for (x = left; x < right; x += 1ul << zoom) { + if ((0 <= y && y < byn) && (0 <= x && x < bxn)) { + b1 = p[((top - t) + ((y + 0) - top)) >> zoom] + [((left - l) + (x - left)) >> zoom]; + b2 = y + (1ul << zoom) < bottom + ? p[((top - t) + ((y + 1) - top)) >> zoom] + [((left - l) + (x - left)) >> zoom] + : 0; + if (b1 || b2) { + SetBg(ByteToColor(b1)); + SetFg(ByteToColor(b2)); + AppendStr("▄"); + } else { + SetBg(ByteToColor(0)); + SetFg(ByteToColor(255)); + AppendStr(" "); + } + } else { + SetBg(ByteToColor(0)); + SetFg(ByteToColor(255)); + AppendStr(VOIDSPACE); + } + } + } +} + +static void Draw(void) { + void *m; + long t, l, b, r, i, n; + buffer.i = 0; + color[0] = -1; + color[1] = -1; + AppendStr("\e[H"); + if (!zoom) { + Raster(); + } else { + t = ROUNDDOWN(top, 16); + l = ROUNDDOWN(left, 16); + b = ROUNDUP(bottom, 16); + r = ROUNDUP(right, 16); + if ((m = calloc((b - t) * (r - l), 1))) { + RasterZoomed(t, l, b, r, m); + free(m); + } + } + AppendStr("\e[0;7m"); + GenerateStatusLine(); + AppendStr(statusline); + n = txn - strwidth(statusline); + for (i = 0; i < n; ++i) { + AppendStr(" "); + } + AppendStr("\e[0m"); write(out, buffer.p, buffer.i); } -static void Life(void) { +static bool HasPendingInput(void) { + struct pollfd fds[1]; + fds[0].fd = 0; + fds[0].events = POLLIN; + fds[0].revents = 0; + poll(fds, ARRAYLEN(fds), 0); + return fds[0].revents & (POLLIN | POLLERR); +} + +static bool ShouldDraw(void) { + long double now, rate; + static long double next; + if (!isdragging) return true; + now = nowl(); + rate = 1. / 24; + if (now > next && !HasPendingInput()) { + next = now + rate; + return true; + } else { + return false; + } +} + +static void Tui(void) { + GetTtySize(); + Dimension(); + ioctl(out, TCGETS, &oldterm); + HideTtyCursor(); + EnableRaw(); + EnableMouse(); + atexit(OnExit); + sigaction(SIGINT, &(struct sigaction){.sa_sigaction = OnSigInt}, NULL); + sigaction(SIGWINCH, &(struct sigaction){.sa_sigaction = OnSigWinch}, NULL); do { if (action & RESIZED) { GetTtySize(); action &= ~RESIZED; + Draw(); + } else if (ShouldDraw()) { + Draw(); } - Draw(); ReadKeyboard(); } while (!(action & INTERRUPTED)); } +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § game of life » graphical user interface ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + +static const char16_t kClassName[] = u"apelife"; + +static void OnMenuAbout(int64_t hwnd) { + MessageBox(hwnd, u"\ +Apelife\r\n\ +Cosmopolitan C Library\r\n\ +αcτµαlly pδrταblε εxεcµταblε\r\n\ +By Justine Tunney \r\n\ +In memory of John Horton Conway, 1937-2020\r\n\ +https://github.com/jart/cosmopolitan\r\n\ +\r\n\ +- Hold space to animate\r\n\ +- Hold left mouse to draw cells\r\n\ +- Hold right mouse to move view\r\n\ +- Press t or alt+t to adjust speed", + u"Conway's Game of Life", kNtMbOk | kNtMbIconinformation); +} + +static void OnMenuOpen(int64_t hwnd) { + char buf8[PATH_MAX]; + char16_t buf16[PATH_MAX]; + struct NtOpenFilename ofn; + memset(&ofn, 0, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = hwnd; + ofn.lpstrFile = buf16; + ofn.nMaxFile = ARRAYLEN(buf16); + ofn.lpstrFilter = u"RLE Format (*.RLE;*.LIF;*.LIFE)\0" + u"*.RLE;*.LIF;*.LIFE\0" + u"All (*.*)\0" + u"*.*\0"; + ofn.Flags = kNtOfnPathmustexist | kNtOfnFilemustexist | kNtOfnExplorer; + if (GetOpenFileName(&ofn)) { + tprecode16to8(buf8, sizeof(buf8), ofn.lpstrFile); + if (LoadFile(buf8) == -1) { + MessageBox(hwnd, u"Failed to open run-length encoded game file", + u"Open Failed", kNtMbOk | kNtMbIconerror); + } + RedrawWindow(hwnd, 0, 0, kNtRdwInvalidate); + } +} + +static bool IsMaximized(int64_t hwnd) { + struct NtWindowPlacement wp; + wp.length = sizeof(wp); + return GetWindowPlacement(hwnd, &wp) && wp.showCmd == kNtSwMaximize; +} + +static void OnWindowPaint(int64_t hwnd) { + int y, x; + int64_t mdc, mbm; + struct NtRect r, w; + struct NtPaintStruct ps; + BeginPaint(hwnd, &ps); + r.top = 0; + r.left = 0; + r.right = ps.rcPaint.right - ps.rcPaint.left; + r.bottom = ps.rcPaint.bottom - ps.rcPaint.top; + w.top = MAX(r.top, -(top + ps.rcPaint.top)); + w.left = MAX(r.left, -(left + ps.rcPaint.left)); + w.right = MIN(r.right, bxn - (left + ps.rcPaint.left)); + w.bottom = MIN(r.bottom, byn - (top + ps.rcPaint.top)); + mdc = CreateCompatibleDC(ps.hdc); + mbm = CreateCompatibleBitmap(ps.hdc, r.right, r.bottom); + SelectObject(mdc, mbm); + FillRect(mdc, &r, kNtColorInactiveborder); + FillRect(mdc, &w, kNtColorAppworkspace); + for (y = w.top; y < w.bottom; ++y) { + for (x = w.left; x < w.right; ++x) { + if (Test(top + ps.rcPaint.top + y, left + ps.rcPaint.left + x)) { + SetPixel(mdc, x, y, 0); + } + } + } + BitBlt(ps.hdc, ps.rcPaint.left, ps.rcPaint.top, r.right, r.bottom, mdc, 0, 0, + kNtSrccopy); + DeleteObject(mbm); + DeleteDC(mdc); + GenerateStatusLine(); + tprecode8to16(statusline16, ARRAYLEN(statusline16), statusline); + SetWindowText(hwnd, statusline16); + EndPaint(hwnd, &ps); +} + +static void OnWindowCharStep(int64_t hwnd, int64_t wParam, int64_t lParam) { + int i, repeats; + repeats = lParam & 0xFFFF; + for (i = 0; i < repeats; ++i) { + Generation(); + } + RedrawWindow(hwnd, 0, 0, kNtRdwInvalidate); +} + +static void OnWindowChar(int64_t hwnd, int64_t wParam, int64_t lParam) { + switch (wParam) { + case ' ': + case 's': + case '\t': + OnWindowCharStep(hwnd, wParam, lParam); + break; + case 't': + if (lParam & ALT) { + OnSlowmo(); + } else { + OnTurbo(); + } + break; + case '\r': + if (IsMaximized(hwnd)) { + SendMessage(hwnd, kNtWmSyscommand, kNtScRestore, 0); + } else { + SendMessage(hwnd, kNtWmSyscommand, kNtScMaximize, 0); + } + break; + default: + break; + } +} + +static void OnWindowSize(int64_t lParam) { + txn = (lParam & 0x0000FFFF) >> 000; + tyn = (lParam & 0xFFFF0000) >> 020; + Dimension(); +} + +static void OnWindowLbuttondown(int64_t hwnd, int64_t wParam, int64_t lParam) { + int y, x; + y = (lParam & 0xFFFF0000) >> 020; + x = (lParam & 0x0000FFFF) >> 000; + SetCapture(hwnd); + OnMouseLeftDown(y, x); + RedrawWindow(hwnd, &(struct NtRect){x, y, x + 1, y + 1}, 0, kNtRdwInvalidate); +} + +static void OnWindowLbuttonup(int64_t hwnd, int64_t wParam, int64_t lParam) { + int y, x; + y = (lParam & 0xFFFF0000) >> 020; + x = (lParam & 0x0000FFFF) >> 000; + OnMouseLeftUp(y, x); + ReleaseCapture(); +} + +static void OnWindowRbuttondown(int64_t hwnd, int64_t wParam, int64_t lParam) { + int y, x; + y = (lParam & 0xFFFF0000) >> 020; + x = (lParam & 0x0000FFFF) >> 000; + oldcursor = GetCursor(); + SetCapture(hwnd); + SetCursor(LoadCursor(0, kNtIdcSizeall)); + OnMouseRightDown(y, x); + RedrawWindow(hwnd, NULL, 0, kNtRdwInvalidate); +} + +static void OnWindowRbuttonup(int64_t hwnd, int64_t wParam, int64_t lParam) { + int y, x; + y = (lParam & 0xFFFF0000) >> 020; + x = (lParam & 0x0000FFFF) >> 000; + OnMouseRightUp(y, x); + SetCursor(oldcursor); + ReleaseCapture(); +} + +static void OnWindowMousemove(int64_t hwnd, int64_t wParam, int64_t lParam) { + int y, x, by, bx; + y = (lParam & 0xFFFF0000) >> 020; + x = (lParam & 0x0000FFFF) >> 000; + if (wParam & kNtMkLbutton) { + OnMouseLeftDrag(y, x); + RedrawWindow(hwnd, &(struct NtRect){x, y, x + 1, y + 1}, 0, + kNtRdwInvalidate); + } else if (wParam & kNtMkRbutton) { + OnMouseRightDrag(y, x); + RedrawWindow(hwnd, NULL, 0, kNtRdwInvalidate); + } +} + +static int64_t WindowProc(int64_t hwnd, uint32_t uMsg, uint64_t wParam, + int64_t lParam) { + switch (uMsg) { + case kNtWmDestroy: + PostQuitMessage(0); + return 0; + case kNtWmSize: + OnWindowSize(lParam); + return 0; + case kNtWmPaint: + OnWindowPaint(hwnd); + return 0; + case kNtWmChar: + OnWindowChar(hwnd, wParam, lParam); + return 0; + case kNtWmLbuttondown: + OnWindowLbuttondown(hwnd, wParam, lParam); + return 0; + case kNtWmLbuttonup: + OnWindowLbuttonup(hwnd, wParam, lParam); + return 0; + case kNtWmRbuttondown: + OnWindowRbuttondown(hwnd, wParam, lParam); + return 0; + case kNtWmRbuttonup: + OnWindowRbuttonup(hwnd, wParam, lParam); + return 0; + case kNtWmMousemove: + OnWindowMousemove(hwnd, wParam, lParam); + return 0; + case kNtWmCommand: + case kNtWmSyscommand: + switch (wParam & ~0xF) { + case IDM_ABOUT: + OnMenuAbout(hwnd); + return 0; + case IDM_OPEN: + OnMenuOpen(hwnd); + return 0; + } + /* fallthrough */ + default: + return DefWindowProc(hwnd, uMsg, wParam, lParam); + } +} + +static void Gui(void) { + int64_t hwnd, mh; + struct NtMsg msg; + struct NtWndClass wc; + memset(&wc, 0, sizeof(wc)); + wc.lpfnWndProc = NT2SYSV(WindowProc); + wc.hInstance = GetModuleHandle(NULL); + wc.hCursor = LoadCursor(0, kNtIdcCross); + wc.lpszClassName = kClassName; + wc.hbrBackground = kNtColorInactiveborder; + CHECK(RegisterClass(&wc)); + CHECK((hwnd = CreateWindowEx(0, kClassName, u"Conway's Game of Life", + kNtWsOverlappedwindow, kNtCwUsedefault, + kNtCwUsedefault, kNtCwUsedefault, + kNtCwUsedefault, 0, 0, wc.hInstance, 0))); + mh = GetSystemMenu(hwnd, false); + AppendMenu(mh, kNtMfSeparator, 0, 0); + AppendMenu(mh, kNtMfEnabled, IDM_OPEN, u"&Open File..."); + AppendMenu(mh, kNtMfEnabled, IDM_ABOUT, u"&About..."); + ShowWindow(hwnd, kNtSwNormal); + while (GetMessage(&msg, 0, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } +} + +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § game of life » program ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + int main(int argc, char *argv[]) { if (!NoDebug()) showcrashreports(); - Setup(); - Life(); + out = 1; + speed = 1; + tyn = right = 80; + txn = bottom = 24; + byn = 64 * 64; + bxn = 64 * 64; + strcpy(name, "apelife"); + GetOpts(argc, argv); + AllocateBoardsWithHardwareAcceleratedMemorySafety(); + if (optind < argc) { + if (LoadFile(argv[optind]) == -1) { + fprintf( + stderr, "%s:%d:%d: %s\n", argv[optind], line + 1, column, + "error: failed to load game of life run length encoded (rle) file"); + return 1; + } + } + if (IsWindows()) { + Gui(); + } else { + Tui(); + } return 0; } diff --git a/tool/viz/memzoom.c b/tool/viz/memzoom.c index f36a2164..1dc8b414 100644 --- a/tool/viz/memzoom.c +++ b/tool/viz/memzoom.c @@ -21,7 +21,7 @@ #include "libc/bits/bits.h" #include "libc/bits/hilbert.h" #include "libc/bits/morton.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/sigaction.h" @@ -55,7 +55,7 @@ #include "third_party/getopt/getopt.h" #define USAGE \ - " [-hznmH] [-p PID] [PATH]\n\ + " [-hznmHNW] [-p PID] [PATH]\n\ \n\ DESCRIPTION\n\ \n\ @@ -65,10 +65,10 @@ FLAGS\n\ \n\ -h help\n\ -z zoom\n\ - -w white bg color\n\ -m morton ordering\n\ -H hilbert ordering\n\ - -n natural scrolling\n\ + -N natural scrolling\n\ + -W white terminal background\n\ -p PID shows process virtual memory\n\ -f INT frames per second [default 10]\n\ \n\ @@ -276,7 +276,7 @@ static void SetupCanvas(void) { munmap(canvas, canvassize); munmap(buffer, buffersize); } - displaysize = ROUNDUP(ROUNDUP(tyn * txn * (1ul << zoom), 16), 1ul << zoom); + displaysize = ROUNDUP(ROUNDUP((tyn * txn) << zoom, 16), 1ul << zoom); canvassize = ROUNDUP(displaysize, FRAMESIZE); buffersize = ROUNDUP(tyn * txn * 16 + PAGESIZE, FRAMESIZE); canvas = Allocate(canvassize); @@ -341,7 +341,8 @@ static int GetCurrentRange(void) { } static void Move(long d) { - offset = MIN(highest, MAX(lowest, ROUNDDOWN(offset + d, 1L << zoom))); + d <<= zoom; + offset = MIN(highest, MAX(lowest, (offset + d) >> zoom << zoom)); } static void SetZoom(long y, long x, int d) { @@ -351,7 +352,7 @@ static void SetZoom(long y, long x, int d) { a = zoom; b = MIN(MAXZOOM, MAX(0, a + d)); zoom = b; - Move(i * (1L << a) - i * (1L << b)); + Move((i << a) - (i << b)); SetupCanvas(); } } @@ -365,19 +366,19 @@ static void OnUnzoom(long y, long x) { } static void OnUp(void) { - Move(-(txn * (1l << zoom))); + Move(-(txn)); } static void OnDown(void) { - Move(txn * (1l << zoom)); + Move(txn); } static void OnPageUp(void) { - Move(-(txn * (tyn - 2) * (1l << zoom))); + Move(-(txn * (tyn - 2))); } static void OnPageDown(void) { - Move(txn * (tyn - 2) * (1l << zoom)); + Move(txn * (tyn - 2)); } static void OnHome(void) { @@ -385,7 +386,7 @@ static void OnHome(void) { } static void OnEnd(void) { - offset = MAX(lowest, highest - txn * tyn * (1l << zoom)); + offset = MAX(lowest, highest - txn * tyn); } static void OnLinear(void) { @@ -425,7 +426,7 @@ static void OnPrev(void) { static void OnNextEnd(void) { long i, n; if ((i = GetCurrentRange()) != -1) { - n = tyn * txn * (1L << zoom); + n = (tyn * txn) << zoom; if (offset < ranges.p[i].b - n) { offset = ranges.p[i].b - n; } else if (i + 1 < ranges.i) { @@ -437,7 +438,7 @@ static void OnNextEnd(void) { static void OnPrevEnd(void) { long i, n; if ((i = GetCurrentRange()) != -1) { - n = tyn * txn * (1L << zoom); + n = (tyn * txn) << zoom; if (i) { offset = MAX(ranges.p[i - 1].a, ranges.p[i - 1].b - n); } @@ -753,7 +754,7 @@ static void Render(void) { } while (w); } p = stpcpy(p, "\e[0m "); - p += uint64toarray_radix16(offset + y * txn * (1ul << zoom), p); + p += uint64toarray_radix16(offset + ((y * txn) << zoom), p); p = stpcpy(p, "\e[K\r\n"); } p = stpcpy(p, "\e[7m\e[K"); @@ -772,7 +773,7 @@ static void Render(void) { p += uint64toarray_radix10(MIN(offset / (long double)size * 100, 100), p); p = stpcpy(p, "%-"); p += uint64toarray_radix10( - MIN((offset + tyn * txn * (1l << zoom)) / (long double)size * 100, 100), + MIN((offset + ((tyn * txn) << zoom)) / (long double)size * 100, 100), p); p = stpcpy(p, "% "); } @@ -800,7 +801,7 @@ static void Zoom(long have) { memset(canvas + n, 0, canvassize - n); } if (have != -1) { - n = have / (1L << zoom); + n = have >> zoom; i = n / txn; r = n % txn; if (r) ++i; @@ -827,7 +828,7 @@ static void RangesZoom(void) { LoadRanges(); memset(canvas, 1, canvassize); a = offset; - b = MIN(highest, offset + tyn * txn * (1ul << zoom)); + b = MIN(highest, offset + ((tyn * txn) << zoom)); for (i = 0; i < ranges.i; ++i) { if ((a >= ranges.p[i].a && a < ranges.p[i].b) || (b >= ranges.p[i].a && b < ranges.p[i].b) || @@ -871,23 +872,23 @@ static void GetOpts(int argc, char *argv[]) { int opt; char *p; fps = 10; - while ((opt = getopt(argc, argv, "hzHnwf:p:")) != -1) { + while ((opt = getopt(argc, argv, "hzHNWf:p:")) != -1) { switch (opt) { case 'z': ++zoom; break; - case 'n': - natural = true; - break; case 'm': order = MORTON; break; case 'H': order = HILBERT; break; - case 'w': + case 'W': white = true; break; + case 'N': + natural = true; + break; case 'f': fps = strtol(optarg, NULL, 0); fps = MAX(1, fps); diff --git a/tool/viz/printimage.c b/tool/viz/printimage.c index a14752e8..31c6dfe3 100644 --- a/tool/viz/printimage.c +++ b/tool/viz/printimage.c @@ -24,7 +24,7 @@ #include "dsp/tty/tty.h" #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/stat.h" diff --git a/tool/viz/printpeb.c b/tool/viz/printpeb.c index f0623811..bd8bfec9 100644 --- a/tool/viz/printpeb.c +++ b/tool/viz/printpeb.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/dce.h" @@ -133,7 +133,7 @@ void PrintSystemInfo(void) { #undef X } -const char *ft2str(enum NtFileType ft) { +const char *ft2str(int ft) { if (ft == kNtFileTypeUnknown) return "kNtFileTypeUnknown"; if (ft == kNtFileTypeDisk) return "kNtFileTypeDisk"; if (ft == kNtFileTypeChar) return "kNtFileTypeChar"; diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index ac4bc05f..afe19752 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -25,10 +25,10 @@ #include "dsp/tty/quant.h" #include "dsp/tty/tty.h" #include "libc/alg/alg.h" -#include "libc/alg/arraylist.h" +#include "libc/alg/arraylist.internal.h" #include "libc/assert.h" #include "libc/bits/bits.h" -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/bits/xchg.h" #include "libc/calls/calls.h" #include "libc/calls/hefty/spawn.h" diff --git a/tool/viz/tabalign.c b/tool/viz/tabalign.c index d150b8ae..53668bab 100644 --- a/tool/viz/tabalign.c +++ b/tool/viz/tabalign.c @@ -17,8 +17,8 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/alg/arraylist.h" -#include "libc/bits/safemacros.h" +#include "libc/alg/arraylist.internal.h" +#include "libc/bits/safemacros.internal.h" #include "libc/conv/conv.h" #include "libc/limits.h" #include "libc/log/check.h" diff --git a/tool/viz/tailf.c b/tool/viz/tailf.c index e9a663fc..f0fe3f77 100644 --- a/tool/viz/tailf.c +++ b/tool/viz/tailf.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/safemacros.h" +#include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/macros.h" diff --git a/tool/viz/viz.mk b/tool/viz/viz.mk index 1bb560fa..31870c9d 100644 --- a/tool/viz/viz.mk +++ b/tool/viz/viz.mk @@ -32,6 +32,9 @@ TOOL_VIZ_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_NT_KERNEL32 \ LIBC_NT_KERNELBASE \ + LIBC_NT_USER32 \ + LIBC_NT_GDI32 \ + LIBC_NT_COMDLG32 \ LIBC_RUNTIME \ LIBC_TESTLIB \ LIBC_STDIO \