diff --git a/.vscode/vscode.h b/.vscode/vscode.h index 8a7c4ad13..5953d67e0 100644 --- a/.vscode/vscode.h +++ b/.vscode/vscode.h @@ -1,4 +1,8 @@ +#define __VSCODE_INTELLISENSE__ 1 +#define __LP64__ /* TODO: this is a lazy kludge */ +#include "libc/integral/normalize.inc" +#if 0 #define __VSCODE_INTELLISENSE__ 1 #define __BIGGEST_ALIGNMENT__ 1 #define __CHAR_MAX__ 0x7F @@ -161,3 +165,4 @@ typedef struct { int ax, dx; } axdx_t; #endif /* UriKeyval */ #define _Static_assert(...) 0 +#endif /* 0 */ diff --git a/Makefile b/Makefile index a133bdc5b..6698c748a 100644 --- a/Makefile +++ b/Makefile @@ -135,7 +135,6 @@ include dsp/tty/tty.mk # ├──ONLINE RUNTIME include libc/dns/dns.mk # │ You can communicate with the network include libc/crypto/crypto.mk # │ include net/http/http.mk #─┘ -include third_party/lemon/lemon.mk include third_party/duktape/duktape.mk include third_party/regex/regex.mk include third_party/third_party.mk @@ -149,7 +148,6 @@ include third_party/chibicc/test/test.mk include tool/build/emucrt/emucrt.mk include tool/build/emubin/emubin.mk include tool/build/build.mk -include tool/calc/calc.mk include tool/decode/lib/decodelib.mk include tool/decode/decode.mk include tool/hash/hash.mk @@ -328,6 +326,14 @@ o/cosmopolitan.html: \ -fno-common -include libc/integral/normalize.inc -o $@ \ $(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS))) +$(SRCS): \ + libc/integral/normalize.inc \ + libc/integral/c.inc \ + libc/integral/cxx.inc \ + libc/integral/cxxtypescompat.inc \ + libc/integral/lp64arg.inc \ + libc/integral/lp64.inc + # UNSPECIFIED PREREQUISITES TUTORIAL # # A build rule must exist for all files that make needs to consider in diff --git a/README.md b/README.md index 2b00b5ab4..793536229 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![Cosmopolitan Honeybadger](usr/share/img/honeybadger.png) + # Cosmopolitan [Cosmopolitan Libc](https://justine.lol/cosmopolitan/index.html) makes C diff --git a/ape/ape.S b/ape/ape.S index 0463e0499..3c0cf479e 100644 --- a/ape/ape.S +++ b/ape/ape.S @@ -663,7 +663,7 @@ ape.macho: .quad 0 # r13 .quad 0 # r14 .quad 0 # r15 - .quad _start_xnu # rip + .quad _xnu # rip .quad 0 # rflags .quad 0 # cs .quad 0 # fs diff --git a/dsp/core/half.h b/dsp/core/half.h index 43d94749c..9a8fe8d1b 100644 --- a/dsp/core/half.h +++ b/dsp/core/half.h @@ -6,7 +6,7 @@ /** * Divides integer in half w/ rounding. */ -#define HALF(X) (((X) + 1) / (2 / TYPE_INTEGRAL(typeof(X)))) +#define HALF(X) (((X) + 1) / 2) #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_DSP_CORE_HALF_H_ */ diff --git a/examples/package/build.mk b/examples/package/build.mk index 0385856f5..fc604b2a2 100644 --- a/examples/package/build.mk +++ b/examples/package/build.mk @@ -41,6 +41,7 @@ EXAMPLES_PACKAGE_OBJS = \ # Note that linking stubs is always a good idea due to synthetic code. EXAMPLES_PACKAGE_DIRECTDEPS = \ EXAMPLES_PACKAGE_LIB \ + LIBC_INTRIN \ LIBC_STDIO \ LIBC_STUBS \ LIBC_TINYMATH diff --git a/examples/package/lib/build.mk b/examples/package/lib/build.mk index 80edf5f92..463c72dc4 100644 --- a/examples/package/lib/build.mk +++ b/examples/package/lib/build.mk @@ -70,6 +70,7 @@ EXAMPLES_PACKAGE_LIB_A_CHECKS = \ # Note that linking stubs is always a good idea due to synthetic code. EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS = \ LIBC_STDIO \ + LIBC_INTRIN \ LIBC_NEXGEN32E \ LIBC_STUBS diff --git a/libc/bits/bits.h b/libc/bits/bits.h index 44f9cd33e..e596f40d1 100644 --- a/libc/bits/bits.h +++ b/libc/bits/bits.h @@ -13,17 +13,17 @@ extern const uint8_t kReverseBits[256]; uint32_t gray(uint32_t) pureconst; uint32_t ungray(uint32_t) 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; +intptr_t lockxchg(void *, void *, size_t); +bool cmpxchg(void *, intptr_t, intptr_t, size_t); +bool lockcmpxchg(void *, intptr_t, intptr_t, size_t); /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § bits » no assembly required ─╬─│┼ @@ -70,38 +70,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; (uint64_t)((unsigned char *)(S))[6] << 010 | \ (uint64_t)((unsigned char *)(S))[7] << 000) -#define read16le(S) \ - ({ \ - unsigned char *Str = (unsigned char *)(S); \ - READ16LE(Str); \ - }) -#define read32le(S) \ - ({ \ - unsigned char *Str = (unsigned char *)(S); \ - READ32LE(Str); \ - }) -#define read64le(S) \ - ({ \ - unsigned char *Str = (unsigned char *)(S); \ - READ64LE(Str); \ - }) - -#define read16be(S) \ - ({ \ - unsigned char *Str = (unsigned char *)(S); \ - READ16BE(Str); \ - }) -#define read32be(S) \ - ({ \ - unsigned char *Str = (unsigned char *)(S); \ - READ32BE(Str); \ - }) -#define read64be(S) \ - ({ \ - unsigned char *Str = (unsigned char *)(S); \ - READ64BE(Str); \ - }) - #define WRITE16LE(P, V) \ do { \ uint8_t *Ple = (uint8_t *)(P); \ @@ -165,6 +133,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § bits » some assembly required ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) /* * Constraints for virtual machine flags. @@ -416,6 +385,14 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; OldBit; \ }) +#else +#define cmpxchg(MEM, CMP, VAL) \ + cmpxchg(MEM, (intptr_t)(CMP), (intptr_t)(VAL), sizeof(*(MEM))) +#define lockcmpxchg(MEM, CMP, VAL) \ + lockcmpxchg(MEM, (intptr_t)(CMP), (intptr_t)(VAL), sizeof(*(MEM))) +#define lockxchg(MEM, VAR) \ + lockxchg(MEM, VAR, sizeof(*(MEM)) / (sizeof(*(MEM)) == sizeof(*(VAR)))) +#endif /* __GNUC__ && !__STRICT_ANSI__ */ COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_H_ */ diff --git a/libc/str/decodentsutf16.c b/libc/bits/cmpxchg.c similarity index 64% rename from libc/str/decodentsutf16.c rename to libc/bits/cmpxchg.c index b0ff37546..8800d7c5d 100644 --- a/libc/str/decodentsutf16.c +++ b/libc/bits/cmpxchg.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,26 +16,32 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/str/str.h" -#include "libc/str/utf16.h" +#include "libc/bits/bits.h" /** - * Helps runtime decode UTF-16 with slightly smaller code size. + * Compares and exchanges. + * + * @param ifthing is uint𝑘_t[hasatleast 1] where 𝑘 ∈ {8,16,32,64} + * @param size is automatically supplied by macro wrapper + * @return true if value was exchanged, otherwise false + * @see lockcmpxchg() */ -wint_t DecodeNtsUtf16(const char16_t **s) { - wint_t x, y; - for (;;) { - if (!(x = *(*s)++)) break; - if (IsUtf16Cont(x)) continue; - if (IsUcs2(x)) { - return x; - } else { - if ((y = *(*s)++)) { - return MergeUtf16(x, y); - } else { - return 0; - } - } +bool(cmpxchg)(void *ifthing, intptr_t isequaltome, intptr_t replaceitwithme, + size_t size) { + switch (size) { + case 1: + return cmpxchg((int8_t *)ifthing, (int8_t)isequaltome, + (int8_t)replaceitwithme); + case 2: + return cmpxchg((int16_t *)ifthing, (int16_t)isequaltome, + (int16_t)replaceitwithme); + case 4: + return cmpxchg((int32_t *)ifthing, (int32_t)isequaltome, + (int32_t)replaceitwithme); + case 8: + return cmpxchg((int64_t *)ifthing, (int64_t)isequaltome, + (int64_t)replaceitwithme); + default: + return false; } - return x; } diff --git a/libc/bits/likely.h b/libc/bits/likely.h index 78e3dfc77..0464e9cd5 100644 --- a/libc/bits/likely.h +++ b/libc/bits/likely.h @@ -2,8 +2,8 @@ #define COSMOPOLITAN_LIBC_BITS_LIKELY_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) -#define likely(expr) __builtin_expect(!!(expr), 1) -#define unlikely(expr) __builtin_expect(!!(expr), 0) +#define LIKELY(expr) __builtin_expect(!!(expr), 1) +#define UNLIKELY(expr) __builtin_expect(!!(expr), 0) #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_LIKELY_H_ */ diff --git a/libc/calls/fprot2nt.c b/libc/bits/lockcmpxchg.c similarity index 63% rename from libc/calls/fprot2nt.c rename to libc/bits/lockcmpxchg.c index 25a54ce58..59121e835 100644 --- a/libc/calls/fprot2nt.c +++ b/libc/bits/lockcmpxchg.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,27 +16,32 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#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" - -#define HAS(X, BITS) (((X) & (BITS)) == (BITS)) +#include "libc/bits/bits.h" /** - * Converts System Five memory protection flags to Windows NT, Part 2. - * @see libc/sysv/consts.sh + * Compares and exchanges w/ lock prefix. + * + * @param ifthing is uint𝑘_t[hasatleast 1] where 𝑘 ∈ {8,16,32,64} + * @param size is automatically supplied by macro wrapper + * @return true if value was exchanged, otherwise false + * @see cmpxchg() */ -uint32_t fprot2nt(int prot, int flags) { - return (HAS(prot, PROT_READ) ? kNtFileMapRead : 0) | - (HAS(prot, PROT_WRITE) ? kNtFileMapWrite : 0) | - (HAS(prot, PROT_EXEC) ? kNtFileMapExecute : 0) | - (HAS(flags, kNtSecLargePages) ? kNtFileMapLargePages : 0) | - (HAS(flags, kNtSecReserve) ? kNtFileMapReserve : 0) | - ((HAS(flags, MAP_PRIVATE) && HAS(prot, PROT_READ) && - HAS(prot, PROT_WRITE)) - ? kNtFileMapCopy - : 0); +bool(lockcmpxchg)(void *ifthing, intptr_t isequaltome, intptr_t replaceitwithme, + size_t size) { + switch (size) { + case 1: + return lockcmpxchg((int8_t *)ifthing, (int8_t)isequaltome, + (int8_t)replaceitwithme); + case 2: + return lockcmpxchg((int16_t *)ifthing, (int16_t)isequaltome, + (int16_t)replaceitwithme); + case 4: + return lockcmpxchg((int32_t *)ifthing, (int32_t)isequaltome, + (int32_t)replaceitwithme); + case 8: + return lockcmpxchg((int64_t *)ifthing, (int64_t)isequaltome, + (int64_t)replaceitwithme); + default: + return false; + } } diff --git a/libc/calls/tunefd.c b/libc/bits/lockxchg.c similarity index 70% rename from libc/calls/tunefd.c rename to libc/bits/lockxchg.c index 1bd20263a..651e23052 100644 --- a/libc/calls/tunefd.c +++ b/libc/bits/lockxchg.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,19 +16,27 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/internal.h" +#include "libc/bits/bits.h" /** - * Modifies characteristics of open file descriptor. + * Compares and exchanges w/ lock prefix. + * + * @param memory is uint𝑘_t[hasatleast 1] where 𝑘 ∈ {8,16,32,64} + * @param size is automatically supplied by macro wrapper + * @return true if value was exchanged, otherwise false + * @see xchg() */ -int tunefd$sysv(int fd, int getcmd, int setcmd, int addflags) { - int current; - if (fd != -1 && addflags) { - if ((current = fcntl$sysv(fd, getcmd, 0)) == -1 || - fcntl$sysv(fd, setcmd, current | addflags) == -1) { - close$sysv(fd); - return -1; - } +intptr_t(lockxchg)(void *memory, void *localvar, size_t size) { + switch (size) { + case 1: + return lockxchg((int8_t *)memory, (int8_t *)localvar); + case 2: + return lockxchg((int16_t *)memory, (int16_t *)localvar); + case 4: + return lockxchg((int32_t *)memory, (int32_t *)localvar); + case 8: + return lockxchg((int64_t *)memory, (int64_t *)localvar); + default: + return false; } - return fd; } diff --git a/libc/bits/safemacros.h b/libc/bits/safemacros.h index d7b839b6e..01254d35b 100644 --- a/libc/bits/safemacros.h +++ b/libc/bits/safemacros.h @@ -1,6 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_ #define COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_ -#ifndef __STRICT_ANSI__ #include "libc/macros.h" #include "libc/runtime/runtime.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) @@ -84,5 +83,4 @@ uint64_t(unsignedsubtract)(uint64_t, uint64_t) pureconst; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* !ANSI */ #endif /* COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_ */ diff --git a/libc/bits/segmentation.h b/libc/bits/segmentation.h index ad36da681..66e281745 100644 --- a/libc/bits/segmentation.h +++ b/libc/bits/segmentation.h @@ -1,6 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ #define COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) /** * Reads scalar from memory, offset by segment. @@ -19,5 +20,6 @@ Pk; \ }) +#endif /* __GNUC__ && !__STRICT_ANSI__ */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ */ diff --git a/libc/calls/chdir-nt.c b/libc/calls/chdir-nt.c index 40869356d..979c715b2 100644 --- a/libc/calls/chdir-nt.c +++ b/libc/calls/chdir-nt.c @@ -23,7 +23,7 @@ #include "libc/nt/synchronization.h" #include "libc/sysv/errfuns.h" -textwindows int chdir$nt(const char *path) { +textwindows int sys_chdir_nt(const char *path) { int e, ms, len; char16_t path16[PATH_MAX]; if ((len = __mkntpath(path, path16)) == -1) return -1; diff --git a/libc/calls/chdir.c b/libc/calls/chdir.c index 4f95461e6..cb441d944 100644 --- a/libc/calls/chdir.c +++ b/libc/calls/chdir.c @@ -27,8 +27,8 @@ */ int chdir(const char *path) { if (!IsWindows()) { - return chdir$sysv(path); + return sys_chdir(path); } else { - return chdir$nt(path); + return sys_chdir_nt(path); } } diff --git a/libc/calls/chmod.c b/libc/calls/chmod.c index 7df6f93ad..7dba99b96 100644 --- a/libc/calls/chmod.c +++ b/libc/calls/chmod.c @@ -45,5 +45,5 @@ */ int chmod(const char *pathname, uint32_t mode) { if (!pathname) return efault(); - return fchmodat$sysv(AT_FDCWD, pathname, mode, 0); + return sys_fchmodat(AT_FDCWD, pathname, mode, 0); } diff --git a/libc/calls/chown.c b/libc/calls/chown.c index 090cb6ecc..28703169d 100644 --- a/libc/calls/chown.c +++ b/libc/calls/chown.c @@ -34,5 +34,5 @@ * @asyncsignalsafe */ int chown(const char *pathname, uint32_t uid, uint32_t gid) { - return fchownat$sysv(AT_FDCWD, pathname, uid, gid, 0); + return sys_fchownat(AT_FDCWD, pathname, uid, gid, 0); } diff --git a/libc/calls/clock_gettime.c b/libc/calls/clock_gettime.c index 042c6ea39..9d64dab2e 100644 --- a/libc/calls/clock_gettime.c +++ b/libc/calls/clock_gettime.c @@ -59,7 +59,7 @@ int clock_gettime(int clockid, struct timespec *out_ts) { out_ts->tv_sec = 0; out_ts->tv_nsec = 0; } - return clock_gettime$sysv(clockid, out_ts); + return sys_clock_gettime(clockid, out_ts); } else { int rc; _Static_assert(sizeof(struct timeval) == sizeof(struct timespec)); @@ -67,7 +67,7 @@ int clock_gettime(int clockid, struct timespec *out_ts) { out_ts->tv_sec = 0; out_ts->tv_nsec = 0; } - rc = gettimeofday$sysv((struct timeval *)out_ts, NULL); + rc = sys_gettimeofday((struct timeval *)out_ts, NULL); if (out_ts) { out_ts->tv_nsec *= 1000; } diff --git a/libc/calls/close-nt.c b/libc/calls/close-nt.c index 5c500b0b4..dbde6463e 100644 --- a/libc/calls/close-nt.c +++ b/libc/calls/close-nt.c @@ -22,7 +22,7 @@ #include "libc/nt/runtime.h" #include "libc/sysv/errfuns.h" -textwindows int close$nt(int fd) { +textwindows int sys_close_nt(int fd) { bool32 ok; if (g_fds.p[fd].kind == kFdFile && GetFileType(g_fds.p[fd].handle) == kNtFileTypeDisk) { diff --git a/libc/calls/close.c b/libc/calls/close.c index b5e83c52a..e242563c5 100644 --- a/libc/calls/close.c +++ b/libc/calls/close.c @@ -40,15 +40,15 @@ int close(int fd) { if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = weaken(__zipos_close)(fd); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdEpoll) { - rc = weaken(close$epoll)(fd); + rc = weaken(sys_close_epoll)(fd); } else if (!IsWindows()) { - rc = close$sysv(fd); + rc = sys_close(fd); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSocket) { - rc = weaken(closesocket$nt)(fd); + rc = weaken(sys_closesocket_nt)(fd); } else if (fd < g_fds.n && (g_fds.p[fd].kind == kFdFile || g_fds.p[fd].kind == kFdConsole || g_fds.p[fd].kind == kFdProcess)) { - rc = close$nt(fd); + rc = sys_close_nt(fd); } else { rc = ebadf(); } diff --git a/libc/calls/copyfile.c b/libc/calls/copyfile.c index d32e1801a..ebf917905 100644 --- a/libc/calls/copyfile.c +++ b/libc/calls/copyfile.c @@ -32,7 +32,7 @@ #include "libc/sysv/consts/o.h" #include "libc/time/time.h" -static textwindows int copyfile$nt(const char *src, const char *dst, +static textwindows int sys_copyfile_nt(const char *src, const char *dst, int flags) { int64_t fhsrc, fhdst; struct NtFileTime accessed, modified; @@ -58,7 +58,7 @@ static textwindows int copyfile$nt(const char *src, const char *dst, } } -static int copyfile$sysv(const char *src, const char *dst, int flags) { +static int sys_copyfile(const char *src, const char *dst, int flags) { struct stat st; size_t remaining; ssize_t transferred; @@ -66,12 +66,12 @@ static int copyfile$sysv(const char *src, const char *dst, int flags) { int64_t inoffset, outoffset; int rc, srcfd, dstfd, oflags, omode; rc = -1; - if ((srcfd = openat$sysv(AT_FDCWD, src, O_RDONLY, 0)) != -1) { - if (fstat$sysv(srcfd, &st) != -1) { + if ((srcfd = sys_openat(AT_FDCWD, src, O_RDONLY, 0)) != -1) { + if (sys_fstat(srcfd, &st) != -1) { omode = st.st_mode & 0777; oflags = O_WRONLY | O_CREAT; if (flags & COPYFILE_NOCLOBBER) oflags |= O_EXCL; - if ((dstfd = openat$sysv(AT_FDCWD, dst, oflags, omode)) != -1) { + if ((dstfd = sys_openat(AT_FDCWD, dst, oflags, omode)) != -1) { remaining = st.st_size; ftruncate(dstfd, remaining); inoffset = 0; @@ -86,13 +86,13 @@ static int copyfile$sysv(const char *src, const char *dst, int flags) { if (flags & COPYFILE_PRESERVE_TIMESTAMPS) { amtime[0] = st.st_atim; amtime[1] = st.st_mtim; - utimensat$sysv(dstfd, NULL, amtime, 0); + sys_utimensat(dstfd, NULL, amtime, 0); } } - rc |= close$sysv(dstfd); + rc |= sys_close(dstfd); } } - rc |= close$sysv(srcfd); + rc |= sys_close(srcfd); } return rc; } @@ -102,8 +102,8 @@ static int copyfile$sysv(const char *src, const char *dst, int flags) { */ int copyfile(const char *src, const char *dst, int flags) { if (!IsWindows()) { - return copyfile$sysv(src, dst, flags); + return sys_copyfile(src, dst, flags); } else { - return copyfile$nt(src, dst, flags); + return sys_copyfile_nt(src, dst, flags); } } diff --git a/libc/calls/dup-nt.c b/libc/calls/dup-nt.c index 1e8437009..4e8a1a507 100644 --- a/libc/calls/dup-nt.c +++ b/libc/calls/dup-nt.c @@ -28,7 +28,7 @@ /** * Implements dup(), dup2(), and dup3() for Windows NT. */ -textwindows int dup$nt(int oldfd, int newfd, int flags) { +textwindows int sys_dup_nt(int oldfd, int newfd, int flags) { int64_t proc; if (oldfd < 0) return einval(); if (oldfd >= g_fds.n || diff --git a/libc/calls/dup.c b/libc/calls/dup.c index 998c51754..c23521d47 100644 --- a/libc/calls/dup.c +++ b/libc/calls/dup.c @@ -30,8 +30,8 @@ */ nodiscard int dup(int fd) { if (!IsWindows()) { - return dup$sysv(fd); + return sys_dup(fd); } else { - return dup$nt(fd, -1, 0); + return sys_dup_nt(fd, -1, 0); } } diff --git a/libc/calls/dup2.c b/libc/calls/dup2.c index 9a21a8bce..1288cb5e2 100644 --- a/libc/calls/dup2.c +++ b/libc/calls/dup2.c @@ -33,8 +33,8 @@ int dup2(int oldfd, int newfd) { if (oldfd == newfd) return newfd; if (!IsWindows()) { - return dup3$sysv(oldfd, newfd, 0); + return sys_dup3(oldfd, newfd, 0); } else { - return dup$nt(oldfd, newfd, 0); + return sys_dup_nt(oldfd, newfd, 0); } } diff --git a/libc/calls/dup3-sysv.c b/libc/calls/dup3-sysv.c index f231daf3b..400e7a638 100644 --- a/libc/calls/dup3-sysv.c +++ b/libc/calls/dup3-sysv.c @@ -21,12 +21,12 @@ #define __NR_dup3_linux 0x0124 /*RHEL5:CVE-2010-3301*/ -int32_t dup3$sysv(int32_t oldfd, int32_t newfd, int flags) { +int32_t sys_dup3(int32_t oldfd, int32_t newfd, int flags) { static bool once, demodernize; int olderr, fd; if (!once) { olderr = errno; - fd = __dup3$sysv(oldfd, newfd, flags); + fd = __sys_dup3(oldfd, newfd, flags); if ((fd == -1 && errno == ENOSYS) || fd == __NR_dup3_linux) { demodernize = true; once = true; @@ -36,7 +36,7 @@ int32_t dup3$sysv(int32_t oldfd, int32_t newfd, int flags) { return fd; } } else if (!demodernize) { - return __dup3$sysv(oldfd, newfd, flags); + return __sys_dup3(oldfd, newfd, flags); } - return fixupnewfd$sysv(dup2$sysv(oldfd, newfd), flags); + return __fixupnewfd(sys_dup2(oldfd, newfd), flags); } diff --git a/libc/calls/dup3.c b/libc/calls/dup3.c index 920414084..fe437e5db 100644 --- a/libc/calls/dup3.c +++ b/libc/calls/dup3.c @@ -36,8 +36,8 @@ */ int dup3(int oldfd, int newfd, int flags) { if (!IsWindows()) { - return dup3$sysv(oldfd, newfd, flags); + return sys_dup3(oldfd, newfd, flags); } else { - return dup$nt(oldfd, newfd, flags); + return sys_dup_nt(oldfd, newfd, flags); } } diff --git a/libc/calls/execve-nt.c b/libc/calls/execve-nt.c index c6c5a476e..ceba6b69b 100644 --- a/libc/calls/execve-nt.c +++ b/libc/calls/execve-nt.c @@ -29,7 +29,7 @@ #include "libc/str/str.h" #include "libc/sysv/consts/o.h" -textwindows int execve$nt(const char *program, char *const argv[], +textwindows int sys_execve_nt(const char *program, char *const argv[], char *const envp[]) { int rc; size_t i; diff --git a/libc/calls/execve-sysv.c b/libc/calls/execve-sysv.c index 3814ad813..f687ae637 100644 --- a/libc/calls/execve-sysv.c +++ b/libc/calls/execve-sysv.c @@ -24,10 +24,10 @@ #include "libc/paths.h" #include "libc/str/str.h" -int execve$sysv(const char *prog, char *const argv[], char *const envp[]) { +int sys_execve(const char *prog, char *const argv[], char *const envp[]) { size_t i; char **shargs; - if (__execve$sysv(prog, argv, envp) != -1) return 0; + if (__sys_execve(prog, argv, envp) != -1) return 0; if (errno != ENOEXEC) return -1; for (i = 0; argv[i];) ++i; shargs = alloca((i + 2) * sizeof(char *)); @@ -36,5 +36,5 @@ int execve$sysv(const char *prog, char *const argv[], char *const envp[]) { : firstnonnull(commandv("bash", alloca(PATH_MAX)), _PATH_BSHELL); shargs[1] = prog; - return __execve$sysv(shargs[0], shargs, envp); + return __sys_execve(shargs[0], shargs, envp); } diff --git a/libc/calls/execve.c b/libc/calls/execve.c index 0b292d4a1..c927279de 100644 --- a/libc/calls/execve.c +++ b/libc/calls/execve.c @@ -35,8 +35,8 @@ */ int execve(const char *program, char *const argv[], char *const envp[]) { if (!IsWindows()) { - return execve$sysv(program, argv, envp); + return sys_execve(program, argv, envp); } else { - return execve$nt(program, argv, envp); + return sys_execve_nt(program, argv, envp); } } diff --git a/libc/calls/faccessat-nt.c b/libc/calls/faccessat-nt.c index d08ebafd3..94078c8e1 100644 --- a/libc/calls/faccessat-nt.c +++ b/libc/calls/faccessat-nt.c @@ -20,7 +20,7 @@ #include "libc/sysv/consts/at.h" #include "libc/sysv/errfuns.h" -int faccessat$nt(int dirfd, const char *path, int mode, uint32_t flags) { +int sys_faccessat_nt(int dirfd, const char *path, int mode, uint32_t flags) { char16_t path16[PATH_MAX]; if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; return ntaccesscheck(path16, mode); diff --git a/libc/calls/faccessat.c b/libc/calls/faccessat.c index 9e9483671..651500676 100644 --- a/libc/calls/faccessat.c +++ b/libc/calls/faccessat.c @@ -36,8 +36,8 @@ int faccessat(int dirfd, const char *path, int mode, uint32_t flags) { if (!path) return efault(); if (!IsWindows()) { - return faccessat$sysv(dirfd, path, mode, flags); + return sys_faccessat(dirfd, path, mode, flags); } else { - return faccessat$nt(dirfd, path, mode, flags); + return sys_faccessat_nt(dirfd, path, mode, flags); } } diff --git a/libc/calls/fadvise-nt.c b/libc/calls/fadvise-nt.c index 5104f9359..2c2881fde 100644 --- a/libc/calls/fadvise-nt.c +++ b/libc/calls/fadvise-nt.c @@ -30,7 +30,7 @@ #include "libc/runtime/runtime.h" #include "libc/sysv/errfuns.h" -textwindows int fadvise$nt(int fd, uint64_t offset, uint64_t len, int advice) { +textwindows int sys_fadvise_nt(int fd, uint64_t offset, uint64_t len, int advice) { int64_t h2; NtStatus status; uint32_t sharemode; diff --git a/libc/calls/fadvise.c b/libc/calls/fadvise.c index 959884b6a..f464228be 100644 --- a/libc/calls/fadvise.c +++ b/libc/calls/fadvise.c @@ -32,8 +32,8 @@ */ int fadvise(int fd, uint64_t offset, uint64_t len, int advice) { if (!IsWindows()) { - return fadvise$sysv(fd, offset, len, advice); /* linux & freebsd */ + return sys_fadvise(fd, offset, len, advice); /* linux & freebsd */ } else { - return fadvise$nt(fd, offset, len, advice); + return sys_fadvise_nt(fd, offset, len, advice); } } diff --git a/libc/calls/fallocate.c b/libc/calls/fallocate.c index e3c983c1b..fb1ff43f1 100644 --- a/libc/calls/fallocate.c +++ b/libc/calls/fallocate.c @@ -45,11 +45,11 @@ int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) { if (mode == -1 /* our sysvconsts definition */) return eopnotsupp(); if (!mode && !length) return ftruncate(fd, offset); if (IsLinux()) { - rc = fallocate$sysv(fd, mode, offset, length); + rc = sys_fallocate(fd, mode, offset, length); if (rc == 0x011d) rc = enosys(); /*RHEL5:CVE-2010-3301*/ return rc; } else if (!IsWindows()) { - return posix_fallocate$sysv(fd, offset, length); + return sys_posix_fallocate(fd, offset, length); } else if (IsWindows()) { if (!__isfdkind(fd, kFdFile)) return ebadf(); if (mode == FALLOC_FL_ZERO_RANGE) { @@ -66,7 +66,7 @@ int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) { * this should commit physical space * but not guaranteed zero'd like linux */ - return ftruncate$nt(fd, length); + return sys_ftruncate_nt(fd, length); } else { return enosys(); } diff --git a/libc/calls/fchdir-nt.c b/libc/calls/fchdir-nt.c index 740dfbcbd..ab8db742c 100644 --- a/libc/calls/fchdir-nt.c +++ b/libc/calls/fchdir-nt.c @@ -22,7 +22,7 @@ #include "libc/nt/files.h" #include "libc/sysv/errfuns.h" -textwindows int fchdir$nt(int dirfd) { +textwindows int sys_fchdir_nt(int dirfd) { uint32_t len; char16_t dir[PATH_MAX]; if (!__isfdkind(dirfd, kFdFile)) return ebadf(); diff --git a/libc/calls/fchdir.c b/libc/calls/fchdir.c index d44aab121..a9e9b0987 100644 --- a/libc/calls/fchdir.c +++ b/libc/calls/fchdir.c @@ -28,8 +28,8 @@ */ int fchdir(int dirfd) { if (!IsWindows()) { - return fchdir$sysv(dirfd); + return sys_fchdir(dirfd); } else { - return fchdir$nt(dirfd); + return sys_fchdir_nt(dirfd); } } diff --git a/libc/calls/fchmod.c b/libc/calls/fchmod.c index 7c32f492f..509f9ecef 100644 --- a/libc/calls/fchmod.c +++ b/libc/calls/fchmod.c @@ -43,5 +43,5 @@ */ int fchmod(int fd, uint32_t mode) { /* TODO(jart): Windows */ - return fchmod$sysv(fd, mode); + return sys_fchmod(fd, mode); } diff --git a/libc/calls/fchown.c b/libc/calls/fchown.c index 92e821868..0baa409df 100644 --- a/libc/calls/fchown.c +++ b/libc/calls/fchown.c @@ -31,5 +31,5 @@ */ int fchown(int fd, uint32_t uid, uint32_t gid) { /* TODO(jart): Windows? */ - return fchown$sysv(fd, uid, gid); + return sys_fchown(fd, uid, gid); } diff --git a/libc/calls/fchownat.c b/libc/calls/fchownat.c index 2a4fa4c99..ae3664220 100644 --- a/libc/calls/fchownat.c +++ b/libc/calls/fchownat.c @@ -34,5 +34,5 @@ */ int fchownat(int dirfd, const char *pathname, uint32_t uid, uint32_t gid, uint32_t flags) { - return fchownat$sysv(dirfd, pathname, uid, gid, flags); + return sys_fchownat(dirfd, pathname, uid, gid, flags); } diff --git a/libc/calls/fcntl-nt.c b/libc/calls/fcntl-nt.c index e67b855d5..7dce493b9 100644 --- a/libc/calls/fcntl-nt.c +++ b/libc/calls/fcntl-nt.c @@ -27,7 +27,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/errfuns.h" -textwindows int fcntl$nt(int fd, int cmd, unsigned arg) { +textwindows int sys_fcntl_nt(int fd, int cmd, unsigned arg) { uint32_t flags; if (__isfdkind(fd, kFdFile) || __isfdkind(fd, kFdSocket)) { switch (cmd) { diff --git a/libc/calls/fcntl.c b/libc/calls/fcntl.c index 954daff77..665a2acd1 100644 --- a/libc/calls/fcntl.c +++ b/libc/calls/fcntl.c @@ -37,8 +37,8 @@ int fcntl(int fd, int cmd, ...) { arg = va_arg(va, unsigned); va_end(va); if (!IsWindows()) { - return fcntl$sysv(fd, cmd, arg); + return sys_fcntl(fd, cmd, arg); } else { - return fcntl$nt(fd, cmd, arg); + return sys_fcntl_nt(fd, cmd, arg); } } diff --git a/libc/calls/fdatasync-nt.c b/libc/calls/fdatasync-nt.c index d2dff480a..43c5323ba 100644 --- a/libc/calls/fdatasync-nt.c +++ b/libc/calls/fdatasync-nt.c @@ -20,7 +20,7 @@ #include "libc/nt/files.h" #include "libc/sysv/errfuns.h" -textwindows int fdatasync$nt(int fd) { +textwindows int sys_fdatasync_nt(int fd) { if (!__isfdkind(fd, kFdFile)) return ebadf(); /* * XXX: On Windows NT this might be more analagous to fflush() and diff --git a/libc/calls/fdatasync.c b/libc/calls/fdatasync.c index 9eacbbff3..7da2a6f30 100644 --- a/libc/calls/fdatasync.c +++ b/libc/calls/fdatasync.c @@ -29,8 +29,8 @@ */ int fdatasync(int fd) { if (!IsWindows()) { - return fdatasync$sysv(fd); + return sys_fdatasync(fd); } else { - return fdatasync$nt(fd); + return sys_fdatasync_nt(fd); } } diff --git a/libc/calls/fixupnewfd.c b/libc/calls/fixupnewfd.c index 579a5cf0b..893601ba2 100644 --- a/libc/calls/fixupnewfd.c +++ b/libc/calls/fixupnewfd.c @@ -23,12 +23,12 @@ /** * Applies file descriptor fixups on XNU or old Linux. - * @see fixupnewsockfd$sysv() for socket file descriptors + * @see __fixupnewsockfd() for socket file descriptors */ -int fixupnewfd$sysv(int fd, int flags) { +int __fixupnewfd(int fd, int flags) { if (fd != -1) { if (flags & O_CLOEXEC) { - fcntl$sysv(fd, F_SETFD, FD_CLOEXEC); + sys_fcntl(fd, F_SETFD, FD_CLOEXEC); } } return fd; diff --git a/libc/calls/flock-nt.c b/libc/calls/flock-nt.c index 781c4f656..9d22f08a7 100644 --- a/libc/calls/flock-nt.c +++ b/libc/calls/flock-nt.c @@ -25,7 +25,7 @@ #include "libc/sysv/consts/lock.h" #include "libc/sysv/errfuns.h" -textwindows int flock$nt(int fd, int op) { +textwindows int sys_flock_nt(int fd, int op) { struct NtOverlapped ov; struct NtByHandleFileInformation info; if (!__isfdkind(fd, kFdFile)) return ebadf(); diff --git a/libc/calls/flock.c b/libc/calls/flock.c index 5657cf285..1fbdae7ba 100644 --- a/libc/calls/flock.c +++ b/libc/calls/flock.c @@ -29,8 +29,8 @@ */ int flock(int fd, int op) { if (!IsWindows()) { - return flock$sysv(fd, op); + return sys_flock(fd, op); } else { - return flock$nt(fd, op); + return sys_flock_nt(fd, op); } } diff --git a/libc/calls/fstat-nt.c b/libc/calls/fstat-nt.c index 179b93cbd..82228d054 100644 --- a/libc/calls/fstat-nt.c +++ b/libc/calls/fstat-nt.c @@ -30,7 +30,7 @@ #include "libc/str/str.h" #include "libc/sysv/consts/s.h" -textwindows int fstat$nt(int64_t handle, struct stat *st) { +textwindows int sys_fstat_nt(int64_t handle, struct stat *st) { int filetype; uint64_t actualsize; struct NtFileCompressionInfo fci; diff --git a/libc/calls/fstat-sysv.c b/libc/calls/fstat-sysv.c index 253c46e24..341cb8051 100644 --- a/libc/calls/fstat-sysv.c +++ b/libc/calls/fstat-sysv.c @@ -22,10 +22,10 @@ * Supports fstat(), etc. implementations. * @asyncsignalsafe */ -textstartup int32_t fstat$sysv(int32_t fd, struct stat *st) { +textstartup int32_t sys_fstat(int32_t fd, struct stat *st) { int res; - if ((res = __fstat$sysv(fd, st)) != -1) { - stat2linux(st); + if ((res = __sys_fstat(fd, st)) != -1) { + __stat2linux(st); } return res; } diff --git a/libc/calls/fstat.c b/libc/calls/fstat.c index c82c128e6..7e0bff932 100644 --- a/libc/calls/fstat.c +++ b/libc/calls/fstat.c @@ -33,12 +33,12 @@ int fstat(int fd, struct stat *st) { (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st); } else if (!IsWindows()) { if (!IsMetal()) { - return fstat$sysv(fd, st); + return sys_fstat(fd, st); } else { return fstat$metal(fd, st); } } else { if (!__isfdkind(fd, kFdFile)) return ebadf(); - return fstat$nt(g_fds.p[fd].handle, st); + return sys_fstat_nt(g_fds.p[fd].handle, st); } } diff --git a/libc/calls/fstatat-nt.c b/libc/calls/fstatat-nt.c index 4aa6717f6..fcdec0b4b 100644 --- a/libc/calls/fstatat-nt.c +++ b/libc/calls/fstatat-nt.c @@ -26,7 +26,7 @@ #include "libc/nt/runtime.h" #include "libc/runtime/runtime.h" -textwindows int fstatat$nt(int dirfd, const char *path, struct stat *st, +textwindows int sys_fstatat_nt(int dirfd, const char *path, struct stat *st, uint32_t flags) { int rc; int64_t fh; @@ -37,7 +37,7 @@ textwindows int fstatat$nt(int dirfd, const char *path, struct stat *st, kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, NULL, kNtOpenExisting, kNtFileAttributeNormal | kNtFileFlagBackupSemantics, 0)) != -1) { - rc = fstat$nt(fh, st); + rc = sys_fstat_nt(fh, st); CloseHandle(fh); return rc; } else { diff --git a/libc/calls/fstatat-sysv.c b/libc/calls/fstatat-sysv.c index 148eb083d..4ce4c878e 100644 --- a/libc/calls/fstatat-sysv.c +++ b/libc/calls/fstatat-sysv.c @@ -22,11 +22,11 @@ * Supports stat(), lstat(), fstatat(), etc. implementations. * @asyncsignalsafe */ -int32_t fstatat$sysv(int32_t dirfd, const char *pathname, struct stat *st, - int32_t flags) { +int32_t sys_fstatat(int32_t dirfd, const char *pathname, struct stat *st, + int32_t flags) { int32_t rc; - if ((rc = __fstatat$sysv(dirfd, pathname, st, flags)) != -1) { - stat2linux(st); + if ((rc = __sys_fstatat(dirfd, pathname, st, flags)) != -1) { + __stat2linux(st); } return rc; } diff --git a/libc/calls/fstatat.c b/libc/calls/fstatat.c index 9bd871e79..cb6c4a55e 100644 --- a/libc/calls/fstatat.c +++ b/libc/calls/fstatat.c @@ -39,8 +39,8 @@ int fstatat(int dirfd, const char *path, struct stat *st, uint32_t flags) { if (weaken(__zipos_stat) && weaken(__zipos_parseuri)(path, &zipname) != -1) { return weaken(__zipos_stat)(&zipname, st); } else if (!IsWindows()) { - return fstatat$sysv(dirfd, path, st, flags); + return sys_fstatat(dirfd, path, st, flags); } else { - return fstatat$nt(dirfd, path, st, flags); + return sys_fstatat_nt(dirfd, path, st, flags); } } diff --git a/libc/calls/fsync.c b/libc/calls/fsync.c index c33285c81..39a8b4476 100644 --- a/libc/calls/fsync.c +++ b/libc/calls/fsync.c @@ -29,8 +29,8 @@ */ int fsync(int fd) { if (!IsWindows()) { - return fsync$sysv(fd); + return sys_fsync(fd); } else { - return fdatasync$nt(fd); + return sys_fdatasync_nt(fd); } } diff --git a/libc/calls/ftruncate-nt.c b/libc/calls/ftruncate-nt.c index f22c6456c..a3f21ba03 100644 --- a/libc/calls/ftruncate-nt.c +++ b/libc/calls/ftruncate-nt.c @@ -21,7 +21,7 @@ #include "libc/nt/files.h" #include "libc/sysv/errfuns.h" -textwindows int ftruncate$nt(int fd, uint64_t length) { +textwindows int sys_ftruncate_nt(int fd, uint64_t length) { bool32 ok; int64_t tell; if (!__isfdkind(fd, kFdFile)) return ebadf(); diff --git a/libc/calls/ftruncate.c b/libc/calls/ftruncate.c index fcbc67fa8..0fe03ff90 100644 --- a/libc/calls/ftruncate.c +++ b/libc/calls/ftruncate.c @@ -33,8 +33,8 @@ */ int ftruncate(int fd, int64_t length) { if (!IsWindows()) { - return ftruncate$sysv(fd, length); + return sys_ftruncate(fd, length); } else { - return ftruncate$nt(fd, length); + return sys_ftruncate_nt(fd, length); } } diff --git a/libc/calls/g_ntstartupinfo.c b/libc/calls/g_ntstartupinfo.c index d1d1973a4..5193f47b7 100644 --- a/libc/calls/g_ntstartupinfo.c +++ b/libc/calls/g_ntstartupinfo.c @@ -20,6 +20,6 @@ #include "libc/nt/startupinfo.h" #include "libc/nt/struct/startupinfo.h" -hidden struct NtStartupInfo g_ntstartupinfo; +hidden struct NtStartupInfo __nt_startupinfo; -STATIC_YOINK("_init_g_ntstartupinfo"); +STATIC_YOINK("_init___nt_startupinfo"); diff --git a/libc/calls/g_ntstartupinfo_init.S b/libc/calls/g_ntstartupinfo_init.S index aae03ba7b..5e248ec27 100644 --- a/libc/calls/g_ntstartupinfo_init.S +++ b/libc/calls/g_ntstartupinfo_init.S @@ -19,8 +19,8 @@ #include "libc/macros.h" .source __FILE__ - .init.start 400,_init_g_ntstartupinfo - ezlea g_ntstartupinfo,cx + .init.start 400,_init___nt_startupinfo + ezlea __nt_startupinfo,cx mov %rsp,%rbp ntcall __imp_GetStartupInfoW - .init.end 400,_init_g_ntstartupinfo,globl,hidden + .init.end 400,_init___nt_startupinfo,globl,hidden diff --git a/libc/calls/g_ntsysteminfo.c b/libc/calls/g_ntsysteminfo.c index 4b6766b42..50ed77428 100644 --- a/libc/calls/g_ntsysteminfo.c +++ b/libc/calls/g_ntsysteminfo.c @@ -20,6 +20,6 @@ #include "libc/nt/struct/systeminfo.h" #include "libc/nt/systeminfo.h" -hidden struct NtSystemInfo g_ntsysteminfo; +hidden struct NtSystemInfo __nt_systeminfo; -STATIC_YOINK("_init_g_ntsysteminfo"); +STATIC_YOINK("_init___nt_systeminfo"); diff --git a/libc/calls/g_ntsysteminfo_init.S b/libc/calls/g_ntsysteminfo_init.S index fef43f424..2e7629895 100644 --- a/libc/calls/g_ntsysteminfo_init.S +++ b/libc/calls/g_ntsysteminfo_init.S @@ -19,8 +19,8 @@ #include "libc/macros.h" .source __FILE__ - .init.start 400,_init_g_ntsysteminfo - ezlea g_ntsysteminfo,cx + .init.start 400,_init___nt_systeminfo + ezlea __nt_systeminfo,cx mov %rsp,%rbp ntcall __imp_GetSystemInfo - .init.end 400,_init_g_ntsysteminfo,globl,hidden + .init.end 400,_init___nt_systeminfo,globl,hidden diff --git a/libc/calls/getauxval.c b/libc/calls/getauxval.c index 435eb7952..4b4ab9d5e 100644 --- a/libc/calls/getauxval.c +++ b/libc/calls/getauxval.c @@ -36,26 +36,10 @@ unsigned long getauxval(unsigned long at) { if (at != -1) { if (!IsWindows()) { if (!g_auxv) return 0; - if (IsXnu()) { - if (at) { - const char *name = - at == AT_EXECFN ? "executable_path" : (const char *)at; - const char **auxv = (const char **)g_auxv; - unsigned namelen = strlen(name); - for (int i = 0; auxv[i]; ++i) { - if (strncmp(auxv[i], name, namelen) == 0 && - auxv[i][namelen] == '=') { - res = (intptr_t)&auxv[i][namelen + 1]; - break; - } - } - } - } else { - for (const unsigned long *ap = g_auxv; *ap; ap += 2) { - if (ap[0] == at) { - res = ap[1]; - break; - } + for (const unsigned long *ap = g_auxv; *ap; ap += 2) { + if (ap[0] == at) { + res = ap[1]; + break; } } } else { diff --git a/libc/calls/getcwd-nt.c b/libc/calls/getcwd-nt.c index 5a2fcaa2e..4c4a8550d 100644 --- a/libc/calls/getcwd-nt.c +++ b/libc/calls/getcwd-nt.c @@ -22,7 +22,7 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -textwindows char *getcwd$nt(char *buf, size_t size) { +textwindows char *sys_getcwd_nt(char *buf, size_t size) { uint16_t name16[PATH_MAX]; if (GetCurrentDirectory(ARRAYLEN(name16), name16)) { tprecode16to8(buf, size, name16); diff --git a/libc/calls/getcwd-xnu.c b/libc/calls/getcwd-xnu.c index c0029e65e..4da7837f0 100644 --- a/libc/calls/getcwd-xnu.c +++ b/libc/calls/getcwd-xnu.c @@ -27,15 +27,15 @@ #define XNU_F_GETPATH 50 #define XNU_MAXPATHLEN 1024 -char *getcwd$xnu(char *res, size_t size) { +char *sys_getcwd_xnu(char *res, size_t size) { int fd; struct stat st[2]; char buf[XNU_MAXPATHLEN], *ret = NULL; - if ((fd = openat$sysv(AT_FDCWD, ".", O_RDONLY | O_DIRECTORY)) != -1) { - if (fstat$sysv(fd, &st[0]) != -1) { + if ((fd = sys_openat(AT_FDCWD, ".", O_RDONLY | O_DIRECTORY)) != -1) { + if (sys_fstat(fd, &st[0]) != -1) { if (st[0].st_dev && st[0].st_ino) { - if (fcntl$sysv(fd, XNU_F_GETPATH, buf) != -1) { - if (fstatat$sysv(AT_FDCWD, buf, &st[1], 0) != -1) { + if (sys_fcntl(fd, XNU_F_GETPATH, buf) != -1) { + if (sys_fstatat(AT_FDCWD, buf, &st[1], 0) != -1) { if (st[0].st_dev == st[1].st_dev && st[0].st_ino == st[1].st_ino) { if (memccpy(res, buf, '\0', size)) { ret = res; diff --git a/libc/calls/getcwd.c b/libc/calls/getcwd.c index 43f3c1a1e..17353ebeb 100644 --- a/libc/calls/getcwd.c +++ b/libc/calls/getcwd.c @@ -35,13 +35,13 @@ char *(getcwd)(char *buf, size_t size) { if (buf && size) buf[0] = '\0'; if (!IsWindows()) { if (IsXnu()) { - return getcwd$xnu(buf, size); - } else if (getcwd$sysv(buf, size) != (void *)-1) { + return sys_getcwd_xnu(buf, size); + } else if (sys_getcwd(buf, size) != (void *)-1) { return buf; } else { return NULL; } } else { - return getcwd$nt(buf, size); + return sys_getcwd_nt(buf, size); } } diff --git a/libc/calls/getitimer.c b/libc/calls/getitimer.c index ed2524677..3f17e0914 100644 --- a/libc/calls/getitimer.c +++ b/libc/calls/getitimer.c @@ -29,8 +29,8 @@ */ int getitimer(int which, struct itimerval *curvalue) { if (!IsWindows()) { - return getitimer$sysv(which, curvalue); + return sys_getitimer(which, curvalue); } else { - return setitimer$nt(which, NULL, curvalue); + return sys_setitimer_nt(which, NULL, curvalue); } } diff --git a/libc/calls/getpid.c b/libc/calls/getpid.c index ce9ad3689..bb25e57ab 100644 --- a/libc/calls/getpid.c +++ b/libc/calls/getpid.c @@ -28,7 +28,7 @@ static int __pid; static int __getpid(void) { if (!IsWindows()) { - return getpid$sysv(); + return sys_getpid(); } else { return GetCurrentProcessId(); } @@ -46,7 +46,7 @@ static void __updatepid(void) { int getpid(void) { static bool once; if (__vforked) { - return getpid$sysv(); + return sys_getpid(); } if (!once) { __updatepid(); diff --git a/libc/calls/getppid-nt.c b/libc/calls/getppid-nt.c index c95cd61eb..b6f7c0d5a 100644 --- a/libc/calls/getppid-nt.c +++ b/libc/calls/getppid-nt.c @@ -24,7 +24,7 @@ #include "libc/nt/runtime.h" #include "libc/nt/struct/processbasicinformation.h" -textwindows int getppid$nt(void) { +textwindows int sys_getppid_nt(void) { struct NtProcessBasicInformation ProcessInformation; uint32_t gotsize = 0; if (!NtError( diff --git a/libc/calls/getppid.c b/libc/calls/getppid.c index 5801ec599..1f93a3924 100644 --- a/libc/calls/getppid.c +++ b/libc/calls/getppid.c @@ -24,8 +24,8 @@ */ int32_t getppid(void) { if (!IsWindows()) { - return getppid$sysv(); + return sys_getppid(); } else { - return getppid$nt(); + return sys_getppid_nt(); } } diff --git a/libc/calls/getpriority-nt.c b/libc/calls/getpriority-nt.c index 4132be760..3f89a9401 100644 --- a/libc/calls/getpriority-nt.c +++ b/libc/calls/getpriority-nt.c @@ -31,7 +31,7 @@ #include "libc/sysv/consts/prio.h" #include "libc/sysv/errfuns.h" -textwindows int getpriority$nt(int ignored) { +textwindows int sys_getpriority_nt(int ignored) { size_t i; uint32_t tier, lg2tier, wut; if ((tier = GetPriorityClass(GetCurrentProcess())) != 0 && diff --git a/libc/calls/getpriority.c b/libc/calls/getpriority.c index 6ce38a9e5..31a8df634 100644 --- a/libc/calls/getpriority.c +++ b/libc/calls/getpriority.c @@ -29,8 +29,8 @@ */ int getpriority(int which, unsigned who) { if (!IsWindows()) { - return getpriority$sysv(which, who) - 20; + return sys_getpriority(which, who) - 20; } else { - return getsetpriority$nt(which, who, 0, getpriority$nt); + return sys_getsetpriority_nt(which, who, 0, sys_getpriority_nt); } } diff --git a/libc/calls/getrlimit.c b/libc/calls/getrlimit.c index 6c0c6c11d..fd7685b99 100644 --- a/libc/calls/getrlimit.c +++ b/libc/calls/getrlimit.c @@ -31,5 +31,5 @@ */ int getrlimit(int resource, struct rlimit *rlim) { if (resource == -1) return einval(); - return getrlimit$sysv(resource, rlim); + return sys_getrlimit(resource, rlim); } diff --git a/libc/calls/getrusage-nt.c b/libc/calls/getrusage-nt.c index bef32e6c9..fe8d22df9 100644 --- a/libc/calls/getrusage-nt.c +++ b/libc/calls/getrusage-nt.c @@ -26,7 +26,7 @@ #include "libc/str/str.h" #include "libc/sysv/consts/rusage.h" -textwindows int getrusage$nt(int who, struct rusage *usage) { +textwindows int sys_getrusage_nt(int who, struct rusage *usage) { struct NtFileTime CreationFileTime; struct NtFileTime ExitFileTime; struct NtFileTime KernelFileTime; diff --git a/libc/calls/getrusage.c b/libc/calls/getrusage.c index f15f4ccc2..aa9b63915 100644 --- a/libc/calls/getrusage.c +++ b/libc/calls/getrusage.c @@ -30,8 +30,8 @@ int getrusage(int who, struct rusage *usage) { if (who == 99) return enosys(); /* @see libc/sysv/consts.sh */ if (!usage) return efault(); if (!IsWindows()) { - return getrusage$sysv(who, usage); + return sys_getrusage(who, usage); } else { - return getrusage$nt(who, usage); + return sys_getrusage_nt(who, usage); } } diff --git a/libc/calls/getsetpriority-nt.c b/libc/calls/getsetpriority-nt.c index a190d6a03..a318aac65 100644 --- a/libc/calls/getsetpriority-nt.c +++ b/libc/calls/getsetpriority-nt.c @@ -21,7 +21,7 @@ #include "libc/sysv/consts/prio.h" #include "libc/sysv/errfuns.h" -textwindows int getsetpriority$nt(int which, unsigned who, int value, +textwindows int sys_getsetpriority_nt(int which, unsigned who, int value, int (*impl)(int)) { if (which != PRIO_PROCESS && which != PRIO_PGRP) return einval(); if (who && abs(who) != getpid() && abs(who) != gettid()) return eopnotsupp(); diff --git a/libc/calls/getsid.c b/libc/calls/getsid.c index 8cc0123c2..a2f057528 100644 --- a/libc/calls/getsid.c +++ b/libc/calls/getsid.c @@ -23,5 +23,5 @@ * Creates session and sets the process group id. */ uint32_t getsid(int pid) { - return getsid$sysv(pid); + return sys_getsid(pid); } diff --git a/libc/calls/gettid.c b/libc/calls/gettid.c index 9ce70c89c..001718807 100644 --- a/libc/calls/gettid.c +++ b/libc/calls/gettid.c @@ -28,7 +28,7 @@ uint32_t gettid(void) { uint32_t res; if (!IsWindows()) { - res = gettid$sysv(); + res = sys_gettid(); if (res <= 0) { res = getpid(); } diff --git a/libc/calls/gettimeofday-nt.c b/libc/calls/gettimeofday-nt.c index fa246836b..52ca8380e 100644 --- a/libc/calls/gettimeofday-nt.c +++ b/libc/calls/gettimeofday-nt.c @@ -25,7 +25,7 @@ #include "libc/str/str.h" #include "libc/time/struct/timezone.h" -int gettimeofday$nt(struct timeval *tv, struct timezone *tz) { +int sys_gettimeofday_nt(struct timeval *tv, struct timezone *tz) { struct NtFileTime ft; GetSystemTimeAsFileTime(&ft); FileTimeToTimeVal(tv, ft); diff --git a/libc/calls/gettimeofday-sysv.S b/libc/calls/gettimeofday-sysv.S index 344938ec7..f713c38f5 100644 --- a/libc/calls/gettimeofday-sysv.S +++ b/libc/calls/gettimeofday-sysv.S @@ -26,7 +26,7 @@ / @return always zero / @see clock_gettime() for nanosecond precision / @see strftime() for string formatting -gettimeofday$sysv: +sys_gettimeofday: push %rbp mov %rsp,%rbp .profilable @@ -36,7 +36,7 @@ gettimeofday$sysv: pop (%rsi) 1: xor %esi,%esi # no one zones this way. xor %edx,%edx # i64*mach_absolute_time - call __gettimeofday$sysv + call __sys_gettimeofday #if SupportsXnu() testb IsXnu() # XNU might do %rax:%rdx jz 1f @@ -50,4 +50,4 @@ gettimeofday$sysv: 1: xor %eax,%eax # nevar fail pop %rbp ret - .endfn gettimeofday$sysv,globl,hidden + .endfn sys_gettimeofday,globl,hidden diff --git a/libc/calls/gettimeofday.c b/libc/calls/gettimeofday.c index eda652152..457581d83 100644 --- a/libc/calls/gettimeofday.c +++ b/libc/calls/gettimeofday.c @@ -33,8 +33,8 @@ */ int gettimeofday(struct timeval *tv, struct timezone *tz) { if (!IsWindows()) { - return gettimeofday$sysv(tv, tz); + return sys_gettimeofday(tv, tz); } else { - return gettimeofday$nt(tv, tz); + return sys_gettimeofday_nt(tv, tz); } } diff --git a/libc/calls/getuid.c b/libc/calls/getuid.c index 6a07e5788..3dd15f487 100644 --- a/libc/calls/getuid.c +++ b/libc/calls/getuid.c @@ -63,7 +63,7 @@ static uint32_t getuidgid(int at, uint32_t impl(void)) { * @asyncsignalsafe */ uint32_t getuid(void) { - return getuidgid(AT_UID, getuid$sysv); + return getuidgid(AT_UID, sys_getuid); } /** @@ -76,5 +76,5 @@ uint32_t getuid(void) { * @asyncsignalsafe */ uint32_t getgid(void) { - return getuidgid(AT_GID, getgid$sysv); + return getuidgid(AT_GID, sys_getgid); } diff --git a/libc/calls/internal.h b/libc/calls/internal.h index abec85bcf..c9d4161f3 100644 --- a/libc/calls/internal.h +++ b/libc/calls/internal.h @@ -1,6 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_ #define COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_ -#ifndef __STRICT_ANSI__ #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/itimerval.h" @@ -69,8 +68,8 @@ hidden extern volatile bool __interrupted; hidden extern int __vforked; hidden extern unsigned __sighandrvas[NSIG]; hidden extern struct Fds g_fds; -hidden extern struct NtSystemInfo g_ntsysteminfo; -hidden extern struct NtStartupInfo g_ntstartupinfo; +hidden extern struct NtSystemInfo __nt_systeminfo; +hidden extern struct NtStartupInfo __nt_startupinfo; hidden extern const struct NtSecurityAttributes kNtIsInheritable; int __reservefd(void) hidden; @@ -104,108 +103,108 @@ forceinline size_t clampio(size_t size) { │ cosmopolitan § syscalls » system five » synthetic jump slots ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -char *getcwd$sysv(char *, u64) hidden; -char *getcwd$xnu(char *, u64) hidden; -i32 __dup3$sysv(i32, i32, i32) hidden; -i32 __execve$sysv(const char *, char *const[], char *const[]) hidden; -i32 __fstat$sysv(i32, struct stat *) hidden; -i32 __fstatat$sysv(i32, const char *, struct stat *, i32) hidden; -i32 __pipe2$sysv(i32[hasatleast 2], u32) hidden; -i32 __utimensat$sysv(i32, const char *, const struct timespec *, i32) hidden; -i32 chdir$sysv(const char *) hidden; -i32 clock_gettime$sysv(i32, struct timespec *) hidden; -i32 close$sysv(i32) hidden; -i32 dup$sysv(i32) hidden; -i32 dup2$sysv(i32, i32) hidden; -i32 dup3$sysv(i32, i32, i32) hidden; -i32 execve$sysv(const char *, char *const[], char *const[]) hidden; -i32 faccessat$sysv(i32, const char *, i32, u32) hidden; -i32 fadvise$sysv(i32, i64, i64, i32) hidden; -i32 fallocate$sysv(i64, i32, i64, i64) hidden; -i32 fchdir$sysv(i32) hidden; -i32 fchmod$sysv(i32, u32) hidden; -i32 fchmodat$sysv(i32, const char *, u32, u32) hidden; -i32 fchown$sysv(i64, u32, u32) hidden; -i32 fchownat$sysv(i32, const char *, u32, u32, u32) hidden; -i32 fcntl$sysv(i32, i32, ...) hidden; -i32 fdatasync$sysv(i32) hidden; -i32 flock$sysv(i32, i32) hidden; -i32 fork$sysv(void) hidden; -i32 fstat$sysv(i32, struct stat *) hidden; -i32 fstatat$sysv(i32, const char *, struct stat *, i32) hidden; -i32 fsync$sysv(i32) hidden; -i32 ftruncate$sysv(i32, i64) hidden; -i32 futimes$sysv(i32, const struct timeval *) hidden; -i32 futimesat$sysv(i32, const char *, const struct timeval *) hidden; +char *sys_getcwd(char *, u64) hidden; +char *sys_getcwd_xnu(char *, u64) hidden; +i32 __sys_dup3(i32, i32, i32) hidden; +i32 __sys_execve(const char *, char *const[], char *const[]) hidden; +i32 __sys_fstat(i32, struct stat *) hidden; +i32 __sys_fstatat(i32, const char *, struct stat *, i32) hidden; +i32 __sys_pipe2(i32[hasatleast 2], u32) hidden; +i32 __sys_utimensat(i32, const char *, const struct timespec *, i32) hidden; i32 getdents(i32, char *, u32, i64 *) hidden; -i32 getitimer$sysv(i32, struct itimerval *) hidden; -i32 getppid$sysv(void) hidden; -i32 getpriority$sysv(i32, u32) hidden; -i32 getrlimit$sysv(i32, struct rlimit *) hidden; -i32 getrusage$sysv(i32, struct rusage *) hidden; -i32 gettimeofday$sysv(struct timeval *, struct timezone *) hidden; -i32 ioctl$sysv(i32, u64, void *) hidden; -i32 kill$sysv(i32, i32, i32) hidden; -i32 linkat$sysv(i32, const char *, i32, const char *, i32) hidden; -i32 lseek$sysv(i32, i64, i32) hidden; -i32 lutimes$sysv(const char *, const struct timeval *) hidden; -i32 madvise$sysv(void *, size_t, i32) hidden; -i32 memfd_create$sysv(const char *, u32) hidden; -i32 mkdirat$sysv(i32, const char *, u32) hidden; -i32 mkfifo$sysv(const char *, u32) hidden; -i32 mknod$sysv(const char *, u32, u64) hidden; -i32 mprotect$sysv(void *, u64, i32) hidden; -i32 msync$sysv(void *, u64, i32) hidden; -i32 munmap$sysv(void *, u64) hidden; -i32 nanosleep$sysv(const struct timespec *, struct timespec *) hidden; -i32 openat$sysv(i32, const char *, i32, ...) hidden; -i32 pause$sysv(void) hidden; -i32 pipe$sysv(i32[hasatleast 2]) hidden; -i32 pipe2$sysv(i32[hasatleast 2], u32) hidden; -i32 posix_fallocate$sysv(i64, i64, i64) hidden; -i32 posix_openpt$sysv(i32) hidden; -i32 renameat$sysv(i32, const char *, i32, const char *) hidden; -i32 sched_setaffinity$sysv(i32, u64, const void *) hidden; -i32 sched_yield$sysv(void) hidden; -i32 setitimer$sysv(i32, const struct itimerval *, struct itimerval *) hidden; -i32 setpriority$sysv(i32, u32, i32) hidden; -i32 setresgid$sysv(uint32_t, uint32_t, uint32_t) hidden; -i32 setresuid$sysv(uint32_t, uint32_t, uint32_t) hidden; -i32 setrlimit$sysv(i32, const struct rlimit *) hidden; -i32 setsid$sysv(void) hidden; -i32 sigaction$sysv(i32, const void *, void *, i64) hidden; -i32 sigprocmask$sysv(i32, const sigset *, sigset *, u64) hidden; -i32 sigsuspend$sysv(const sigset *, u64) hidden; -i32 symlinkat$sysv(const char *, i32, const char *) hidden; -i32 sync$sysv(void) hidden; -i32 sync_file_range$sysv(i32, i64, i64, u32) hidden; -i32 sysinfo$sysv(struct sysinfo *) hidden; -i32 truncate$sysv(const char *, u64) hidden; -i32 uname$sysv(char *) hidden; -i32 unlinkat$sysv(i32, const char *, i32) hidden; -i32 utime$sysv(const char *, const struct utimbuf *) hidden; -i32 utimensat$sysv(i32, const char *, const struct timespec *, i32) hidden; -i32 utimes$sysv(const char *, const struct timeval *) hidden; -i32 wait4$sysv(i32, i32 *, i32, struct rusage *) hidden; -i64 copy_file_range$sysv(i32, long *, i32, long *, u64, u32) hidden; -i64 getrandom$sysv(void *, u64, u32) hidden; -i64 pread$sysv(i32, void *, u64, i64) hidden; -i64 preadv$sysv(i32, struct iovec *, i32, i64) hidden; -i64 ptrace$sysv(int, i32, void *, void *) hidden; -i64 pwrite$sysv(i32, const void *, u64, i64) hidden; -i64 pwritev$sysv(i32, const struct iovec *, i32, i64) hidden; -i64 read$sysv(i32, void *, u64) hidden; -i64 sendfile$sysv(i32, i32, i64 *, u64) hidden; -i64 splice$sysv(i32, i64 *, i32, i64 *, u64, u32) hidden; -i64 vmsplice$sysv(i32, const struct iovec *, i64, u32) hidden; -i64 write$sysv(i32, const void *, u64) hidden; -u32 getgid$sysv(void) hidden; -u32 getpid$sysv(void) hidden; -u32 getsid$sysv(int) hidden; -u32 gettid$sysv(void) hidden; -u32 getuid$sysv(void) hidden; -void *mmap$sysv(void *, u64, u32, u32, i64, i64) hidden; -void *mremap$sysv(void *, u64, u64, i32, void *) hidden; +i32 sys_chdir(const char *) hidden; +i32 sys_clock_gettime(i32, struct timespec *) hidden; +i32 sys_close(i32) hidden; +i32 sys_dup(i32) hidden; +i32 sys_dup2(i32, i32) hidden; +i32 sys_dup3(i32, i32, i32) hidden; +i32 sys_execve(const char *, char *const[], char *const[]) hidden; +i32 sys_faccessat(i32, const char *, i32, u32) hidden; +i32 sys_fadvise(i32, i64, i64, i32) hidden; +i32 sys_fallocate(i64, i32, i64, i64) hidden; +i32 sys_fchdir(i32) hidden; +i32 sys_fchmod(i32, u32) hidden; +i32 sys_fchmodat(i32, const char *, u32, u32) hidden; +i32 sys_fchown(i64, u32, u32) hidden; +i32 sys_fchownat(i32, const char *, u32, u32, u32) hidden; +i32 sys_fcntl(i32, i32, ...) hidden; +i32 sys_fdatasync(i32) hidden; +i32 sys_flock(i32, i32) hidden; +i32 sys_fork(void) hidden; +i32 sys_fstat(i32, struct stat *) hidden; +i32 sys_fstatat(i32, const char *, struct stat *, i32) hidden; +i32 sys_fsync(i32) hidden; +i32 sys_ftruncate(i32, i64) hidden; +i32 sys_futimes(i32, const struct timeval *) hidden; +i32 sys_futimesat(i32, const char *, const struct timeval *) hidden; +i32 sys_getitimer(i32, struct itimerval *) hidden; +i32 sys_getppid(void) hidden; +i32 sys_getpriority(i32, u32) hidden; +i32 sys_getrlimit(i32, struct rlimit *) hidden; +i32 sys_getrusage(i32, struct rusage *) hidden; +i32 sys_gettimeofday(struct timeval *, struct timezone *) hidden; +i32 sys_ioctl(i32, u64, void *) hidden; +i32 sys_kill(i32, i32, i32) hidden; +i32 sys_linkat(i32, const char *, i32, const char *, i32) hidden; +i32 sys_lseek(i32, i64, i32) hidden; +i32 sys_lutimes(const char *, const struct timeval *) hidden; +i32 sys_madvise(void *, size_t, i32) hidden; +i32 sys_memfd_create(const char *, u32) hidden; +i32 sys_mkdirat(i32, const char *, u32) hidden; +i32 sys_mkfifo(const char *, u32) hidden; +i32 sys_mknod(const char *, u32, u64) hidden; +i32 sys_mprotect(void *, u64, i32) hidden; +i32 sys_msync(void *, u64, i32) hidden; +i32 sys_munmap(void *, u64) hidden; +i32 sys_nanosleep(const struct timespec *, struct timespec *) hidden; +i32 sys_openat(i32, const char *, i32, ...) hidden; +i32 sys_pause(void) hidden; +i32 sys_pipe(i32[hasatleast 2]) hidden; +i32 sys_pipe2(i32[hasatleast 2], u32) hidden; +i32 sys_posix_fallocate(i64, i64, i64) hidden; +i32 sys_posix_openpt(i32) hidden; +i32 sys_renameat(i32, const char *, i32, const char *) hidden; +i32 sys_sched_setaffinity(i32, u64, const void *) hidden; +i32 sys_sched_yield(void) hidden; +i32 sys_setitimer(i32, const struct itimerval *, struct itimerval *) hidden; +i32 sys_setpriority(i32, u32, i32) hidden; +i32 sys_setresgid(uint32_t, uint32_t, uint32_t) hidden; +i32 sys_setresuid(uint32_t, uint32_t, uint32_t) hidden; +i32 sys_setrlimit(i32, const struct rlimit *) hidden; +i32 sys_setsid(void) hidden; +i32 sys_sigaction(i32, const void *, void *, i64) hidden; +i32 sys_sigprocmask(i32, const sigset *, sigset *, u64) hidden; +i32 sys_sigsuspend(const sigset *, u64) hidden; +i32 sys_symlinkat(const char *, i32, const char *) hidden; +i32 sys_sync(void) hidden; +i32 sys_sync_file_range(i32, i64, i64, u32) hidden; +i32 sys_sysinfo(struct sysinfo *) hidden; +i32 sys_truncate(const char *, u64) hidden; +i32 sys_uname(char *) hidden; +i32 sys_unlinkat(i32, const char *, i32) hidden; +i32 sys_utime(const char *, const struct utimbuf *) hidden; +i32 sys_utimensat(i32, const char *, const struct timespec *, i32) hidden; +i32 sys_utimes(const char *, const struct timeval *) hidden; +i32 sys_wait4(i32, i32 *, i32, struct rusage *) hidden; +i64 sys_copy_file_range(i32, long *, i32, long *, u64, u32) hidden; +i64 sys_getrandom(void *, u64, u32) hidden; +i64 sys_pread(i32, void *, u64, i64) hidden; +i64 sys_preadv(i32, struct iovec *, i32, i64) hidden; +i64 sys_ptrace(int, i32, void *, void *) hidden; +i64 sys_pwrite(i32, const void *, u64, i64) hidden; +i64 sys_pwritev(i32, const struct iovec *, i32, i64) hidden; +i64 sys_read(i32, void *, u64) hidden; +i64 sys_sendfile(i32, i32, i64 *, u64) hidden; +i64 sys_splice(i32, i64 *, i32, i64 *, u64, u32) hidden; +i64 sys_vmsplice(i32, const struct iovec *, i64, u32) hidden; +i64 sys_write(i32, const void *, u64) hidden; +u32 sys_getgid(void) hidden; +u32 sys_getpid(void) hidden; +u32 sys_getsid(int) hidden; +u32 sys_gettid(void) hidden; +u32 sys_getuid(void) hidden; +void *sys_mmap(void *, u64, u32, u32, i64, i64) hidden; +void *sys_mremap(void *, u64, u64, i32, void *) hidden; /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § syscalls » system five » support ─╬─│┼ @@ -213,64 +212,62 @@ void *mremap$sysv(void *, u64, u64, i32, void *) hidden; void __onfork(void) hidden; bool32 __sigenter(i32, struct siginfo *, struct ucontext *) hidden; -i32 fixupnewfd$sysv(i32, i32) hidden; -i32 tunefd$sysv(i32, i32, i32, i32) hidden; -u32 fprot2nt(i32, i32) hidden; -u32 prot2nt(i32, i32) privileged; +i32 __fixupnewfd(i32, i32) hidden; +u32 __prot2nt(i32, i32) privileged; void __restore_rt() hidden; -void __sigenter$xnu(void *, i32, i32, void *, void *) hidden wontreturn; -int utimensat$xnu(int, const char *, const struct timespec *, int) hidden; -int nanosleep$xnu(const struct timespec *, struct timespec *) hidden; -void stat2linux(void *) hidden; -void xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *, - const struct __darwin_ucontext *) hidden wontreturn; +void __sigenter_xnu(void *, i32, i32, void *, void *) hidden wontreturn; +int sys_utimensat_xnu(int, const char *, const struct timespec *, int) hidden; +int sys_nanosleep_xnu(const struct timespec *, struct timespec *) hidden; +void __stat2linux(void *) hidden; +void __xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *, + const struct __darwin_ucontext *) hidden wontreturn; /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § syscalls » windows nt » veneers ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -bool32 isatty$nt(int) hidden; -char *getcwd$nt(char *, size_t) hidden; -i64 lseek$nt(int, i64, int) hidden; -int chdir$nt(const char *) hidden; -int close$nt(int) hidden; -int dup$nt(int, int, int) hidden; -int execve$nt(const char *, char *const[], char *const[]) hidden; -int faccessat$nt(int, const char *, int, uint32_t) hidden; -int fadvise$nt(int, u64, u64, int) hidden; -int fchdir$nt(int) hidden; -int fcntl$nt(int, int, unsigned) hidden; -int fdatasync$nt(int) hidden; -int flock$nt(int, int) hidden; -int fork$nt(void) hidden; -int fstat$nt(i64, struct stat *) hidden; -int fstatat$nt(int, const char *, struct stat *, uint32_t) hidden; -int ftruncate$nt(int, u64) hidden; -int getppid$nt(void) hidden; -int getpriority$nt(int) hidden; -int getrusage$nt(int, struct rusage *) hidden; -int gettimeofday$nt(struct timeval *, struct timezone *) hidden; -int kill$nt(int, int) hidden; -int link$nt(const char *, const char *) hidden; -int lstat$nt(const char *, struct stat *) hidden; -int madvise$nt(void *, size_t, int) hidden; -int mkdirat$nt(int, const char *, uint32_t) hidden; -int msync$nt(void *, size_t, int) hidden; -int nanosleep$nt(const struct timespec *, struct timespec *) hidden; -int pipe$nt(int[hasatleast 2], unsigned) hidden; -int renameat$nt(int, const char *, int, const char *) hidden; -int sched_yield$nt(void) hidden; -int setitimer$nt(int, const struct itimerval *, struct itimerval *) hidden; -int setpriority$nt(int) hidden; -int symlinkat$nt(const char *, int, const char *) hidden; -int sync$nt(void) hidden; -int sysinfo$nt(struct sysinfo *) hidden; -int truncate$nt(const char *, u64) hidden; -int unlinkat$nt(int, const char *, int) hidden; -int utimensat$nt(int, const char *, const struct timespec *, int) hidden; -ssize_t open$nt(int, const char *, u32, i32) nodiscard 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; +bool32 sys_isatty_nt(int) hidden; +char *sys_getcwd_nt(char *, size_t) hidden; +i64 sys_lseek_nt(int, i64, int) hidden; +int sys_chdir_nt(const char *) hidden; +int sys_close_nt(int) hidden; +int sys_dup_nt(int, int, int) hidden; +int sys_execve_nt(const char *, char *const[], char *const[]) hidden; +int sys_faccessat_nt(int, const char *, int, uint32_t) hidden; +int sys_fadvise_nt(int, u64, u64, int) hidden; +int sys_fchdir_nt(int) hidden; +int sys_fcntl_nt(int, int, unsigned) hidden; +int sys_fdatasync_nt(int) hidden; +int sys_flock_nt(int, int) hidden; +int sys_fork_nt(void) hidden; +int sys_fstat_nt(i64, struct stat *) hidden; +int sys_fstatat_nt(int, const char *, struct stat *, uint32_t) hidden; +int sys_ftruncate_nt(int, u64) hidden; +int sys_getppid_nt(void) hidden; +int sys_getpriority_nt(int) hidden; +int sys_getrusage_nt(int, struct rusage *) hidden; +int sys_gettimeofday_nt(struct timeval *, struct timezone *) hidden; +int sys_kill_nt(int, int) hidden; +int sys_link_nt(const char *, const char *) hidden; +int sys_lstat_nt(const char *, struct stat *) hidden; +int sys_madvise_nt(void *, size_t, int) hidden; +int sys_mkdirat_nt(int, const char *, uint32_t) hidden; +int sys_msync_nt(void *, size_t, int) hidden; +int sys_nanosleep_nt(const struct timespec *, struct timespec *) hidden; +int sys_pipe_nt(int[hasatleast 2], unsigned) hidden; +int sys_renameat_nt(int, const char *, int, const char *) hidden; +int sys_sched_yield_nt(void) hidden; +int sys_setitimer_nt(int, const struct itimerval *, struct itimerval *) hidden; +int sys_setpriority_nt(int) hidden; +int sys_symlinkat_nt(const char *, int, const char *) hidden; +int sys_sync_nt(void) hidden; +int sys_sysinfo_nt(struct sysinfo *) hidden; +int sys_truncate_nt(const char *, u64) hidden; +int sys_unlinkat_nt(int, const char *, int) hidden; +int sys_utimensat_nt(int, const char *, const struct timespec *, int) hidden; +ssize_t sys_open_nt(int, const char *, u32, i32) nodiscard hidden; +ssize_t sys_read_nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden; +ssize_t sys_write_nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden; /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § syscalls » windows nt » support ─╬─│┼ @@ -279,7 +276,7 @@ ssize_t write$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden; int64_t ntreturn(uint32_t); void WinMainForked(void) hidden; void *GetProcAddressModule(const char *, const char *) hidden; -int getsetpriority$nt(int, unsigned, int, int (*)(int)); +int sys_getsetpriority_nt(int, unsigned, int, int (*)(int)); void ntcontext2linux(struct ucontext *, const struct NtContext *) hidden; struct NtOverlapped *offset2overlap(int64_t, struct NtOverlapped *) hidden; bool32 ntsetprivilege(i64, const char16_t *, u32) hidden; @@ -289,7 +286,7 @@ int64_t __winerr(void) nocallback privileged; int __mkntpath(const char *, char16_t[hasatleast PATH_MAX - 16]) hidden; int __mkntpath2(const char *, char16_t[hasatleast PATH_MAX - 16], int) hidden; int __mkntpathat(int, const char *, int, char16_t[PATH_MAX]) hidden; -unsigned __wincrash$nt(struct NtExceptionPointers *); +unsigned __wincrash_nt(struct NtExceptionPointers *); /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § syscalls » metal ─╬─│┼ @@ -311,5 +308,4 @@ ssize_t writev$serial(struct Fd *, const struct iovec *, int) hidden; #undef u64 COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* !ANSI */ #endif /* COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_ */ diff --git a/libc/calls/ioctl-default.c b/libc/calls/ioctl-default.c index 5079cad06..9cb782aac 100644 --- a/libc/calls/ioctl-default.c +++ b/libc/calls/ioctl-default.c @@ -27,11 +27,11 @@ int ioctl$default(int fd, uint64_t request, void *memory) { int rc; int64_t handle; if (!IsWindows()) { - return ioctl$sysv(fd, request, memory); + return sys_ioctl(fd, request, memory); } else if (__isfdopen(fd)) { if (g_fds.p[fd].kind == kFdSocket) { handle = g_fds.p[fd].handle; - if ((rc = weaken(__ioctlsocket$nt)(handle, request, memory)) != -1) { + if ((rc = weaken(__sys_ioctlsocket_nt)(handle, request, memory)) != -1) { return rc; } else { return weaken(__winsockerr)(); diff --git a/libc/calls/ioctl-tcgets-nt.c b/libc/calls/ioctl-tcgets-nt.c index 7bf6f4aa4..7c5828542 100644 --- a/libc/calls/ioctl-tcgets-nt.c +++ b/libc/calls/ioctl-tcgets-nt.c @@ -27,7 +27,7 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" -textwindows int ioctl$tcgets$nt(int ignored, struct termios *tio) { +textwindows int ioctl$sys_tcgets_nt(int ignored, struct termios *tio) { int64_t in, out; bool32 inok, outok; uint32_t inmode, outmode; diff --git a/libc/calls/ioctl-tcgets.c b/libc/calls/ioctl-tcgets.c index 705cbe70c..1a168fed4 100644 --- a/libc/calls/ioctl-tcgets.c +++ b/libc/calls/ioctl-tcgets.c @@ -21,12 +21,12 @@ #include "libc/calls/termios.internal.h" #include "libc/sysv/consts/termios.h" -int ioctl$tcgets$nt(int, struct termios *); +int ioctl$sys_tcgets_nt(int, struct termios *); -static int ioctl$tcgets$sysv(int fd, struct termios *tio) { +static int ioctl$sys_tcgets(int fd, struct termios *tio) { int rc; union metatermios t; - if ((rc = ioctl$sysv(fd, TCGETS, &t)) != -1) { + if ((rc = sys_ioctl(fd, TCGETS, &t)) != -1) { termios2linux(tio, &t); } return rc; @@ -41,8 +41,8 @@ static int ioctl$tcgets$sysv(int fd, struct termios *tio) { */ int ioctl$tcgets(int fd, struct termios *tio) { if (!IsWindows()) { - return ioctl$tcgets$sysv(fd, tio); + return ioctl$sys_tcgets(fd, tio); } else { - return ioctl$tcgets$nt(fd, tio); + return ioctl$sys_tcgets_nt(fd, tio); } } diff --git a/libc/calls/ioctl-tcsets-nt.c b/libc/calls/ioctl-tcsets-nt.c index abe4052c0..51bccad9d 100644 --- a/libc/calls/ioctl-tcsets-nt.c +++ b/libc/calls/ioctl-tcsets-nt.c @@ -26,7 +26,7 @@ #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" -textwindows int ioctl$tcsets$nt(int ignored, uint64_t request, +textwindows int ioctl$sys_tcsets_nt(int ignored, uint64_t request, const struct termios *tio) { int64_t in, out; bool32 inok, outok; diff --git a/libc/calls/ioctl-tcsets.c b/libc/calls/ioctl-tcsets.c index 4f293a420..ff347efa7 100644 --- a/libc/calls/ioctl-tcsets.c +++ b/libc/calls/ioctl-tcsets.c @@ -22,12 +22,12 @@ #include "libc/dce.h" #include "libc/sysv/consts/termios.h" -int ioctl$tcsets$nt(int, uint64_t, const struct termios *); +int ioctl$sys_tcsets_nt(int, uint64_t, const struct termios *); -static int ioctl$tcsets$sysv(int fd, uint64_t request, +static int ioctl$sys_tcsets(int fd, uint64_t request, const struct termios *tio) { union metatermios t; - return ioctl$sysv(fd, request, termios2host(&t, tio)); + return sys_ioctl(fd, request, termios2host(&t, tio)); } /** @@ -39,8 +39,8 @@ static int ioctl$tcsets$sysv(int fd, uint64_t request, */ int ioctl$tcsets(int fd, uint64_t request, const struct termios *tio) { if (!IsWindows()) { - return ioctl$tcsets$sysv(fd, request, tio); + return ioctl$sys_tcsets(fd, request, tio); } else { - return ioctl$tcsets$nt(fd, request, tio); + return ioctl$sys_tcsets_nt(fd, request, tio); } } diff --git a/libc/calls/ioctl-tiocgwinsz-nt.c b/libc/calls/ioctl-tiocgwinsz-nt.c index ce45c4197..fab5c541b 100644 --- a/libc/calls/ioctl-tiocgwinsz-nt.c +++ b/libc/calls/ioctl-tiocgwinsz-nt.c @@ -26,7 +26,7 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -textwindows int ioctl$tiocgwinsz$nt(int fd, struct winsize *ws) { +textwindows int ioctl$sys_tiocgwinsz_nt(int fd, struct winsize *ws) { int i, fds[3]; uint32_t mode; struct NtConsoleScreenBufferInfoEx sbinfo; @@ -42,9 +42,9 @@ textwindows int ioctl$tiocgwinsz$nt(int fd, struct winsize *ws) { ws->ws_xpixel = 0; ws->ws_ypixel = 0; return 0; - } else if (g_ntstartupinfo.dwFlags & kNtStartfUsecountchars) { - ws->ws_col = g_ntstartupinfo.dwXCountChars; - ws->ws_row = g_ntstartupinfo.dwYCountChars; + } else if (__nt_startupinfo.dwFlags & kNtStartfUsecountchars) { + ws->ws_col = __nt_startupinfo.dwXCountChars; + ws->ws_row = __nt_startupinfo.dwYCountChars; ws->ws_xpixel = 0; ws->ws_ypixel = 0; return 0; diff --git a/libc/calls/ioctl-tiocgwinsz.c b/libc/calls/ioctl-tiocgwinsz.c index 671f68084..f76204df9 100644 --- a/libc/calls/ioctl-tiocgwinsz.c +++ b/libc/calls/ioctl-tiocgwinsz.c @@ -21,7 +21,7 @@ #include "libc/dce.h" #include "libc/sysv/consts/termios.h" -int ioctl$tiocgwinsz$nt(int, struct winsize *); +int ioctl$sys_tiocgwinsz_nt(int, struct winsize *); /** * Returns width and height of terminal. @@ -30,8 +30,8 @@ int ioctl$tiocgwinsz$nt(int, struct winsize *); */ int ioctl$tiocgwinsz(int fd, struct winsize *ws) { if (!IsWindows()) { - return ioctl$sysv(fd, TIOCGWINSZ, ws); + return sys_ioctl(fd, TIOCGWINSZ, ws); } else { - return ioctl$tiocgwinsz$nt(fd, ws); + return ioctl$sys_tiocgwinsz_nt(fd, ws); } } diff --git a/libc/calls/ioctl-tiocswinsz-nt.c b/libc/calls/ioctl-tiocswinsz-nt.c index 93d3321aa..0d7a87957 100644 --- a/libc/calls/ioctl-tiocswinsz-nt.c +++ b/libc/calls/ioctl-tiocswinsz-nt.c @@ -24,7 +24,7 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -textwindows int ioctl$tiocswinsz$nt(int fd, const struct winsize *ws) { +textwindows int ioctl$sys_tiocswinsz_nt(int fd, const struct winsize *ws) { uint32_t mode; struct NtCoord coord; if (!ws) return efault(); diff --git a/libc/calls/ioctl-tiocswinsz.c b/libc/calls/ioctl-tiocswinsz.c index bd77aba25..922a1cfd7 100644 --- a/libc/calls/ioctl-tiocswinsz.c +++ b/libc/calls/ioctl-tiocswinsz.c @@ -21,7 +21,7 @@ #include "libc/dce.h" #include "libc/sysv/consts/termios.h" -int ioctl$tiocswinsz$nt(int, const struct winsize *); +int ioctl$sys_tiocswinsz_nt(int, const struct winsize *); /** * Returns width and height of terminal. @@ -30,8 +30,8 @@ int ioctl$tiocswinsz$nt(int, const struct winsize *); */ int ioctl$tiocswinsz(int fd, const struct winsize *ws) { if (!IsWindows()) { - return ioctl$sysv(fd, TIOCSWINSZ, ws); + return sys_ioctl(fd, TIOCSWINSZ, ws); } else { - return ioctl$tiocswinsz$nt(fd, ws); + return ioctl$sys_tiocswinsz_nt(fd, ws); } } diff --git a/libc/calls/ioctl.h b/libc/calls/ioctl.h index fb6a7f938..d04132a04 100644 --- a/libc/calls/ioctl.h +++ b/libc/calls/ioctl.h @@ -29,13 +29,13 @@ int ioctl(int, uint64_t, void *); } while (0) int ioctl$tcgets(int, void *); -int ioctl$tcgets$nt(int, void *); +int ioctl$sys_tcgets_nt(int, void *); int ioctl$tcsets(int, uint64_t, void *); -int ioctl$tcsets$nt(int, uint64_t, void *); +int ioctl$sys_tcsets_nt(int, uint64_t, void *); int ioctl$tiocgwinsz(int, void *); -int ioctl$tiocgwinsz$nt(int, void *); +int ioctl$sys_tiocgwinsz_nt(int, void *); int ioctl$tiocswinsz(int, void *); -int ioctl$tiocswinsz$nt(int, void *); +int ioctl$sys_tiocswinsz_nt(int, void *); int ioctl$default(int, uint64_t, void *); forceinline int ioctl$dispatch(int fd, uint64_t request, void *memory) { diff --git a/libc/calls/isatty-nt.c b/libc/calls/isatty-nt.c index d4d367d5d..d6e3726aa 100644 --- a/libc/calls/isatty-nt.c +++ b/libc/calls/isatty-nt.c @@ -21,7 +21,7 @@ #include "libc/nt/files.h" #include "libc/sysv/errfuns.h" -textwindows bool32 isatty$nt(int fd) { +textwindows bool32 sys_isatty_nt(int fd) { if (!__isfdkind(fd, kFdFile)) return ebadf(); return GetFileType(g_fds.p[fd].handle) == kNtFileTypeChar; } diff --git a/libc/calls/isatty.c b/libc/calls/isatty.c index ae607fda6..3d7b6aeec 100644 --- a/libc/calls/isatty.c +++ b/libc/calls/isatty.c @@ -28,8 +28,8 @@ bool32 isatty(int fd) { _Alignas(short) char buf[sizeof(uint16_t) * 4]; if (!IsWindows()) { - return ioctl$sysv(fd, TIOCGWINSZ, &buf) != -1; + return sys_ioctl(fd, TIOCGWINSZ, &buf) != -1; } else { - return isatty$nt(fd); + return sys_isatty_nt(fd); } } diff --git a/libc/calls/isdebuggerpresent.c b/libc/calls/isdebuggerpresent.c index 844d128b1..d4096575e 100644 --- a/libc/calls/isdebuggerpresent.c +++ b/libc/calls/isdebuggerpresent.c @@ -54,12 +54,12 @@ int IsDebuggerPresent(bool force) { if (IsWindows()) { res = NtBeingDebugged(); } else if (IsLinux()) { - if ((fd = openat$sysv(AT_FDCWD, kProcStatus, O_RDONLY, 0)) != -1) { - if ((got = read$sysv(fd, buf, sizeof(buf) - sizeof(kPid))) != -1) { + if ((fd = sys_openat(AT_FDCWD, kProcStatus, O_RDONLY, 0)) != -1) { + if ((got = sys_read(fd, buf, sizeof(buf) - sizeof(kPid))) != -1) { buf[got] = '\0'; res = atoi(firstnonnull(strstr(buf, kPid), kPid) + strlen(kPid)); } - close$sysv(fd); + sys_close(fd); } } return res; diff --git a/libc/calls/kill-nt.c b/libc/calls/kill-nt.c index d09f908cb..077d97479 100644 --- a/libc/calls/kill-nt.c +++ b/libc/calls/kill-nt.c @@ -24,7 +24,7 @@ #include "libc/nt/process.h" #include "libc/sysv/errfuns.h" -textwindows int kill$nt(int pid, int sig) { +textwindows int sys_kill_nt(int pid, int sig) { int target; uint32_t event; if (!pid) return raise(sig); diff --git a/libc/calls/kill.c b/libc/calls/kill.c index 60fbd1627..f72bab6e4 100644 --- a/libc/calls/kill.c +++ b/libc/calls/kill.c @@ -39,8 +39,8 @@ */ int kill(int pid, int sig) { if (!IsWindows()) { - return kill$sysv(pid, sig, 1); + return sys_kill(pid, sig, 1); } else { - return kill$nt(pid, sig); + return sys_kill_nt(pid, sig); } } diff --git a/libc/calls/lchown.c b/libc/calls/lchown.c index 61a98b82e..ed5ff5f33 100644 --- a/libc/calls/lchown.c +++ b/libc/calls/lchown.c @@ -31,5 +31,5 @@ * @see /etc/group for group ids */ int lchown(const char *pathname, uint32_t uid, uint32_t gid) { - return fchownat$sysv(AT_FDCWD, pathname, uid, gid, AT_SYMLINK_NOFOLLOW); + return sys_fchownat(AT_FDCWD, pathname, uid, gid, AT_SYMLINK_NOFOLLOW); } diff --git a/libc/calls/link-nt.c b/libc/calls/link-nt.c index e359ac53a..a1f2000c1 100644 --- a/libc/calls/link-nt.c +++ b/libc/calls/link-nt.c @@ -21,7 +21,7 @@ #include "libc/nt/files.h" #include "libc/nt/runtime.h" -textwindows int link$nt(const char *existingpath, const char *newpath) { +textwindows int sys_link_nt(const char *existingpath, const char *newpath) { char16_t newpath16[PATH_MAX]; char16_t existingpath16[PATH_MAX]; if (__mkntpath(existingpath, existingpath16) != -1 && diff --git a/libc/calls/link.c b/libc/calls/link.c index 9634308f4..69a975c12 100644 --- a/libc/calls/link.c +++ b/libc/calls/link.c @@ -34,8 +34,8 @@ int link(const char *existingpath, const char *newpath) { if (!existingpath || !newpath) return efault(); if (!IsWindows()) { - return linkat$sysv(AT_FDCWD, existingpath, AT_FDCWD, newpath, 0); + return sys_linkat(AT_FDCWD, existingpath, AT_FDCWD, newpath, 0); } else { - return link$nt(existingpath, newpath); + return sys_link_nt(existingpath, newpath); } } diff --git a/libc/calls/lseek-nt.c b/libc/calls/lseek-nt.c index 5ce0e9f14..dc1954787 100644 --- a/libc/calls/lseek-nt.c +++ b/libc/calls/lseek-nt.c @@ -20,7 +20,7 @@ #include "libc/nt/files.h" #include "libc/sysv/errfuns.h" -textwindows int64_t lseek$nt(int fd, int64_t offset, int whence) { +textwindows int64_t sys_lseek_nt(int fd, int64_t offset, int whence) { int64_t res; if (!__isfdkind(fd, kFdFile)) return ebadf(); if (SetFilePointerEx(g_fds.p[fd].handle, offset, &res, whence)) { diff --git a/libc/calls/lseek.c b/libc/calls/lseek.c index f9eab0efe..d63daec35 100644 --- a/libc/calls/lseek.c +++ b/libc/calls/lseek.c @@ -31,8 +31,8 @@ */ int64_t lseek(int fd, int64_t offset, int whence) { if (!IsWindows()) { - return lseek$sysv(fd, offset, whence); + return sys_lseek(fd, offset, whence); } else { - return lseek$nt(fd, offset, whence); + return sys_lseek_nt(fd, offset, whence); } } diff --git a/libc/calls/madvise-nt.c b/libc/calls/madvise-nt.c index 780e57b8c..a1c1aef0b 100644 --- a/libc/calls/madvise-nt.c +++ b/libc/calls/madvise-nt.c @@ -47,7 +47,7 @@ forceinline typeof(OfferVirtualMemory) *GetOfferVirtualMemory(void) { return OfferVirtualMemory_; } -textwindows int madvise$nt(void *addr, size_t length, int advice) { +textwindows int sys_madvise_nt(void *addr, size_t length, int advice) { uint32_t rangecount; struct NtMemoryRangeEntry ranges[1]; if ((advice & (int)MADV_WILLNEED) == (int)MADV_WILLNEED || diff --git a/libc/calls/madvise.c b/libc/calls/madvise.c index 1bf6fdcdf..3825d063d 100644 --- a/libc/calls/madvise.c +++ b/libc/calls/madvise.c @@ -30,8 +30,8 @@ */ int madvise(void *addr, size_t length, int advice) { if (!IsWindows()) { - return madvise$sysv(addr, length, advice); + return sys_madvise(addr, length, advice); } else { - return madvise$nt(addr, length, advice); + return sys_madvise_nt(addr, length, advice); } } diff --git a/libc/calls/mkdirat-nt.c b/libc/calls/mkdirat-nt.c index 03b25ffbb..c269daa4d 100644 --- a/libc/calls/mkdirat-nt.c +++ b/libc/calls/mkdirat-nt.c @@ -36,7 +36,7 @@ static textwindows bool SubpathExistsThatsNotDirectory(char16_t *path) { return false; } -textwindows int mkdirat$nt(int dirfd, const char *path, uint32_t mode) { +textwindows int sys_mkdirat_nt(int dirfd, const char *path, uint32_t mode) { int e; char16_t *p, path16[PATH_MAX]; if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; diff --git a/libc/calls/mkdirat.c b/libc/calls/mkdirat.c index 403495c08..9e3623cf5 100644 --- a/libc/calls/mkdirat.c +++ b/libc/calls/mkdirat.c @@ -35,8 +35,8 @@ */ int mkdirat(int dirfd, const char *path, unsigned mode) { if (!IsWindows()) { - return mkdirat$sysv(dirfd, path, mode); + return sys_mkdirat(dirfd, path, mode); } else { - return mkdirat$nt(dirfd, path, mode); + return sys_mkdirat_nt(dirfd, path, mode); } } diff --git a/libc/calls/mkfifo.c b/libc/calls/mkfifo.c index fe4b8782f..ae37d9398 100644 --- a/libc/calls/mkfifo.c +++ b/libc/calls/mkfifo.c @@ -34,8 +34,8 @@ int mkfifo(const char *pathname, unsigned mode) { /* TODO(jart): Windows? */ if (IsLinux()) { - return mknod$sysv(pathname, mode | S_IFIFO, 0); + return sys_mknod(pathname, mode | S_IFIFO, 0); } else { - return mkfifo$sysv(pathname, mode); + return sys_mkfifo(pathname, mode); } } diff --git a/libc/calls/mknod.c b/libc/calls/mknod.c index b32de29ee..c84803674 100644 --- a/libc/calls/mknod.c +++ b/libc/calls/mknod.c @@ -42,7 +42,7 @@ int mknod(const char *path, uint32_t mode, uint64_t dev) { if (mode & S_IFIFO) return mkfifo(path, mode & ~S_IFIFO); if (!IsWindows()) { /* TODO(jart): Whys there code out there w/ S_xxx passed via dev? */ - return mknod$sysv(path, mode, dev); + return sys_mknod(path, mode, dev); } else { return enosys(); } diff --git a/libc/calls/mprotect.greg.c b/libc/calls/mprotect.greg.c index 8c6558afc..c2a755d90 100644 --- a/libc/calls/mprotect.greg.c +++ b/libc/calls/mprotect.greg.c @@ -52,7 +52,7 @@ textsyscall int mprotect(void *addr, uint64_t len, int prot) { } return rc; } else { - if (__imp_VirtualProtect(addr, len, prot2nt(prot, 0), &oldprot)) { + if (__imp_VirtualProtect(addr, len, __prot2nt(prot, 0), &oldprot)) { return 0; } else { return __winerr(); diff --git a/libc/calls/nanosleep-nt.c b/libc/calls/nanosleep-nt.c index 9af2be68f..53810c01d 100644 --- a/libc/calls/nanosleep-nt.c +++ b/libc/calls/nanosleep-nt.c @@ -25,7 +25,7 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -textwindows int nanosleep$nt(const struct timespec *req, struct timespec *rem) { +textwindows int sys_nanosleep_nt(const struct timespec *req, struct timespec *rem) { int64_t millis, hectonanos, relasleep; if (rem) memcpy(rem, req, sizeof(*rem)); hectonanos = req->tv_sec * 10000000ull + div100int64(req->tv_nsec); diff --git a/libc/calls/nanosleep-xnu.c b/libc/calls/nanosleep-xnu.c index f9e4eb793..3c5d84bda 100644 --- a/libc/calls/nanosleep-xnu.c +++ b/libc/calls/nanosleep-xnu.c @@ -22,9 +22,9 @@ #include "libc/nexgen32e/nexgen32e.h" #include "libc/sock/internal.h" -int nanosleep$xnu(const struct timespec *req, struct timespec *rem) { +int sys_nanosleep_xnu(const struct timespec *req, struct timespec *rem) { long millis; millis = div1000int64(req->tv_nsec); millis = MAX(1, millis); - return select$sysv(0, 0, 0, 0, &(struct timeval){req->tv_sec, millis}); + return sys_select(0, 0, 0, 0, &(struct timeval){req->tv_sec, millis}); } diff --git a/libc/calls/nanosleep.c b/libc/calls/nanosleep.c index 9232381e2..58581590f 100644 --- a/libc/calls/nanosleep.c +++ b/libc/calls/nanosleep.c @@ -29,14 +29,14 @@ int nanosleep(const struct timespec *req, struct timespec *rem) { if (!IsWindows()) { if (!IsMetal()) { if (!IsXnu()) { - return nanosleep$sysv(req, rem); + return sys_nanosleep(req, rem); } else { - return nanosleep$xnu(req, rem); + return sys_nanosleep_xnu(req, rem); } } else { return enosys(); /* TODO: Sleep on Metal */ } } else { - return nanosleep$nt(req, rem); + return sys_nanosleep_nt(req, rem); } } diff --git a/libc/calls/onntconsoleevent_init.S b/libc/calls/onntconsoleevent_init.S index 024c04b5a..deb6a748d 100644 --- a/libc/calls/onntconsoleevent_init.S +++ b/libc/calls/onntconsoleevent_init.S @@ -20,7 +20,7 @@ .source __FILE__ .init.start 300,_init_onntconsoleevent - ezlea __onntconsoleevent$nt,cx + ezlea __onntconsoleevent_nt,cx pushpop 1,%rdx ntcall __imp_SetConsoleCtrlHandler .init.end 300,_init_onntconsoleevent,globl,hidden diff --git a/libc/calls/open-nt.c b/libc/calls/open-nt.c index 1a381b0c0..167dad94f 100644 --- a/libc/calls/open-nt.c +++ b/libc/calls/open-nt.c @@ -35,7 +35,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/errfuns.h" -static textwindows int64_t open$nt$impl(int dirfd, const char *path, +static textwindows int64_t sys_open_nt$impl(int dirfd, const char *path, uint32_t flags, int32_t mode) { uint32_t br; int64_t handle; @@ -76,7 +76,7 @@ static textwindows int64_t open$nt$impl(int dirfd, const char *path, } } -static textwindows ssize_t open$nt$console(int dirfd, +static textwindows ssize_t sys_open_nt$console(int dirfd, const struct NtMagicPaths *mp, uint32_t flags, int32_t mode, size_t fd) { @@ -84,11 +84,11 @@ static textwindows ssize_t open$nt$console(int dirfd, GetFileType(g_fds.p[STDOUT_FILENO].handle) == kNtFileTypeChar) { g_fds.p[fd].handle = g_fds.p[STDIN_FILENO].handle; g_fds.p[fd].extra = g_fds.p[STDOUT_FILENO].handle; - } else if ((g_fds.p[fd].handle = open$nt$impl( + } else if ((g_fds.p[fd].handle = sys_open_nt$impl( dirfd, mp->conin, (flags & ~O_ACCMODE) | O_RDONLY, mode)) != -1) { g_fds.p[fd].extra = - open$nt$impl(dirfd, mp->conout, (flags & ~O_ACCMODE) | O_WRONLY, mode); + sys_open_nt$impl(dirfd, mp->conout, (flags & ~O_ACCMODE) | O_WRONLY, mode); assert(g_fds.p[fd].extra != -1); } else { return -1; @@ -98,10 +98,10 @@ static textwindows ssize_t open$nt$console(int dirfd, return fd; } -static textwindows ssize_t open$nt$file(int dirfd, const char *file, +static textwindows ssize_t sys_open_nt$file(int dirfd, const char *file, uint32_t flags, int32_t mode, size_t fd) { - if ((g_fds.p[fd].handle = open$nt$impl(dirfd, file, flags, mode)) != -1) { + if ((g_fds.p[fd].handle = sys_open_nt$impl(dirfd, file, flags, mode)) != -1) { g_fds.p[fd].kind = kFdFile; g_fds.p[fd].flags = flags; return fd; @@ -110,15 +110,15 @@ static textwindows ssize_t open$nt$file(int dirfd, const char *file, } } -textwindows ssize_t open$nt(int dirfd, const char *file, uint32_t flags, +textwindows ssize_t sys_open_nt(int dirfd, const char *file, uint32_t flags, int32_t mode) { int fd; ssize_t rc; if ((fd = __reservefd()) == -1) return -1; if ((flags & O_ACCMODE) == O_RDWR && !strcmp(file, kNtMagicPaths.devtty)) { - rc = open$nt$console(dirfd, &kNtMagicPaths, flags, mode, fd); + rc = sys_open_nt$console(dirfd, &kNtMagicPaths, flags, mode, fd); } else { - rc = open$nt$file(dirfd, file, flags, mode, fd); + rc = sys_open_nt$file(dirfd, file, flags, mode, fd); } if (rc == -1) { __releasefd(fd); diff --git a/libc/calls/openanon.c b/libc/calls/openanon.c index f86061501..aff3a67a8 100644 --- a/libc/calls/openanon.c +++ b/libc/calls/openanon.c @@ -62,7 +62,7 @@ static int openanon$impl(const char *name, unsigned flags, openanon$genpath(name, state, pathbuf); flags |= O_RDWR | O_CREAT | O_EXCL | O_TRUNC; if (!IsWindows()) { - if ((fd = openat$sysv(AT_FDCWD, pathbuf, flags, 0600)) != -1) { + if ((fd = sys_openat(AT_FDCWD, pathbuf, flags, 0600)) != -1) { unlink(pathbuf); } return fd; diff --git a/libc/calls/openat.c b/libc/calls/openat.c index 5955a85cb..79820ae97 100644 --- a/libc/calls/openat.c +++ b/libc/calls/openat.c @@ -52,8 +52,8 @@ nodiscard int openat(int dirfd, const char *file, int flags, ...) { if (dirfd != AT_FDCWD) return einval(); return weaken(__zipos_open)(&zipname, flags, mode); } else if (!IsWindows()) { - return openat$sysv(dirfd, file, flags, mode); + return sys_openat(dirfd, file, flags, mode); } else { - return open$nt(dirfd, file, flags, mode); + return sys_open_nt(dirfd, file, flags, mode); } } diff --git a/libc/calls/pause.c b/libc/calls/pause.c index 0a721dad1..1ce657307 100644 --- a/libc/calls/pause.c +++ b/libc/calls/pause.c @@ -36,7 +36,7 @@ int pause(void) { int rc, olderr; sigset_t oldmask; olderr = errno; - if ((rc = pause$sysv()) == -1 && errno == ENOSYS) { + if ((rc = sys_pause()) == -1 && errno == ENOSYS) { errno = olderr; if (sigprocmask(SIG_BLOCK, NULL, &oldmask) == -1) return -1; rc = sigsuspend(&oldmask); diff --git a/libc/calls/pipe-nt.c b/libc/calls/pipe-nt.c index fad391c1e..79782dedd 100644 --- a/libc/calls/pipe-nt.c +++ b/libc/calls/pipe-nt.c @@ -53,7 +53,7 @@ static char16_t *CreatePipeName(char16_t *a) { return a; } -textwindows int pipe$nt(int pipefd[2], unsigned flags) { +textwindows int sys_pipe_nt(int pipefd[2], unsigned flags) { int64_t hin, hout; int reader, writer; char16_t pipename[64]; diff --git a/libc/calls/pipe-sysv.S b/libc/calls/pipe-sysv.S index a435f4107..5ec2f82f6 100644 --- a/libc/calls/pipe-sysv.S +++ b/libc/calls/pipe-sysv.S @@ -27,13 +27,13 @@ / @asyncsignalsafe / @see libc/sysv/syscalls.sh / @see pipe2() -pipe$sysv: +sys_pipe: push %rbp mov %rsp,%rbp #if SupportsFreebsd() xor %esi,%esi #endif - call __pipe$sysv + call __sys_pipe #if SupportsXnu() testb IsXnu() jz 1f @@ -45,4 +45,4 @@ pipe$sysv: #endif 1: pop %rbp ret - .endfn pipe$sysv,globl,hidden + .endfn sys_pipe,globl,hidden diff --git a/libc/calls/pipe.c b/libc/calls/pipe.c index 0fe2ca1a4..0d27bd2da 100644 --- a/libc/calls/pipe.c +++ b/libc/calls/pipe.c @@ -32,8 +32,8 @@ int pipe(int pipefd[hasatleast 2]) { if (!pipefd) return efault(); if (!IsWindows()) { - return pipe$sysv(pipefd); + return sys_pipe(pipefd); } else { - return pipe$nt(pipefd, 0); + return sys_pipe_nt(pipefd, 0); } } diff --git a/libc/calls/pipe2-sysv.c b/libc/calls/pipe2-sysv.c index 2e5433b6b..ab75113a1 100644 --- a/libc/calls/pipe2-sysv.c +++ b/libc/calls/pipe2-sysv.c @@ -22,18 +22,18 @@ #define __NR_pipe2_linux 0x0125 /*RHEL5:CVE-2010-3301*/ -int32_t pipe2$sysv(int pipefd[hasatleast 2], unsigned flags) { +int32_t sys_pipe2(int pipefd[hasatleast 2], unsigned flags) { int rc, olderr; if (!flags) goto OldSkool; olderr = errno; - rc = __pipe2$sysv(pipefd, flags); + rc = __sys_pipe2(pipefd, flags); if ((rc == -1 && errno == ENOSYS) || (SupportsLinux() && rc == __NR_pipe2_linux)) { errno = olderr; OldSkool: - if ((rc = pipe$sysv(pipefd)) != -1) { - fixupnewfd$sysv(pipefd[0], flags); - fixupnewfd$sysv(pipefd[1], flags); + if ((rc = sys_pipe(pipefd)) != -1) { + __fixupnewfd(pipefd[0], flags); + __fixupnewfd(pipefd[1], flags); } } return rc; diff --git a/libc/calls/pipe2.c b/libc/calls/pipe2.c index e111775f7..638ffa85e 100644 --- a/libc/calls/pipe2.c +++ b/libc/calls/pipe2.c @@ -31,8 +31,8 @@ int pipe2(int pipefd[hasatleast 2], int flags) { if (!pipefd) return efault(); if (!IsWindows()) { - return pipe2$sysv(pipefd, flags); + return sys_pipe2(pipefd, flags); } else { - return pipe$nt(pipefd, flags); + return sys_pipe_nt(pipefd, flags); } } diff --git a/libc/calls/posix_openpt.c b/libc/calls/posix_openpt.c index ed9423fe5..13fedf2f2 100644 --- a/libc/calls/posix_openpt.c +++ b/libc/calls/posix_openpt.c @@ -36,7 +36,7 @@ int posix_openpt(int flags) { struct IoctlPtmGet ptm; if ((flags & O_ACCMODE) != O_RDWR) return einval(); if (SupportsFreebsd() && - ((fd = posix_openpt$sysv(flags)) != -1 || errno != ENOSYS)) { + ((fd = sys_posix_openpt(flags)) != -1 || errno != ENOSYS)) { return fd; } else if ((fd = open("/dev/ptmx", flags)) != -1 || errno != ENOENT) { return fd; diff --git a/libc/calls/pread.c b/libc/calls/pread.c index 786adefbc..68c2406a0 100644 --- a/libc/calls/pread.c +++ b/libc/calls/pread.c @@ -47,9 +47,9 @@ ssize_t pread(int fd, void *buf, size_t size, int64_t offset) { rc = weaken(__zipos_read)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, buf, size, offset); } else if (!IsWindows()) { - rc = pread$sysv(fd, buf, size, offset); + rc = sys_pread(fd, buf, size, offset); } else if (__isfdkind(fd, kFdFile)) { - rc = read$nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset); + rc = sys_read_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset); } else { rc = ebadf(); } diff --git a/libc/calls/preadv.c b/libc/calls/preadv.c index 5a95e808d..076dfe516 100644 --- a/libc/calls/preadv.c +++ b/libc/calls/preadv.c @@ -58,7 +58,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) { demodernize = true; } else { olderr = errno; - rc = preadv$sysv(fd, iovec, count, off); + rc = sys_preadv(fd, iovec, count, off); if (rc == -1 && errno == ENOSYS) { errno = olderr; demodernize = true; @@ -71,7 +71,7 @@ ssize_t preadv(int fd, struct iovec *iovec, int count, int64_t off) { } if (!demodernize) { - return preadv$sysv(fd, iovec, count, off); + return sys_preadv(fd, iovec, count, off); } else { return pread(fd, iovec[0].iov_base, iovec[0].iov_len, off); } diff --git a/libc/calls/prot2nt.greg.c b/libc/calls/prot2nt.greg.c index 0df895c14..ab53d9663 100644 --- a/libc/calls/prot2nt.greg.c +++ b/libc/calls/prot2nt.greg.c @@ -28,7 +28,7 @@ * Converts System Five memory protection flags to Windows NT, Part 1. * @see libc/sysv/consts.sh */ -privileged uint32_t prot2nt(int prot, int flags) { +privileged uint32_t __prot2nt(int prot, int flags) { return (HAS(prot, PROT_READ | PROT_WRITE | PROT_EXEC) ? (HAS(flags, MAP_SHARED) || HAS(flags, MAP_ANONYMOUS)) ? kNtPageExecuteReadwrite diff --git a/libc/calls/ptrace.c b/libc/calls/ptrace.c index 6b801da62..8866ca608 100644 --- a/libc/calls/ptrace.c +++ b/libc/calls/ptrace.c @@ -28,5 +28,5 @@ long ptrace(int request, int pid, void *addr, void *data) { /* TODO(jart): FreeBSD addr and data args are different */ if (request == -1) return einval(); /* see consts.sh */ - return ptrace$sysv(request, pid, addr, data); + return sys_ptrace(request, pid, addr, data); } diff --git a/libc/calls/pwrite.c b/libc/calls/pwrite.c index 53c355cd6..8c78108cc 100644 --- a/libc/calls/pwrite.c +++ b/libc/calls/pwrite.c @@ -43,9 +43,9 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) { if (fd == -1 || offset < 0) return einval(); size = MIN(size, 0x7ffff000); if (!IsWindows()) { - rc = pwrite$sysv(fd, buf, size, offset); + rc = sys_pwrite(fd, buf, size, offset); } else if (__isfdkind(fd, kFdFile)) { - rc = write$nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset); + rc = sys_write_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, offset); } else { return ebadf(); } diff --git a/libc/calls/pwritev.c b/libc/calls/pwritev.c index d7068fdf5..e3f1e9b72 100644 --- a/libc/calls/pwritev.c +++ b/libc/calls/pwritev.c @@ -63,7 +63,7 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) { demodernize = true; } else { olderr = errno; - rc = pwritev$sysv(fd, iovec, count, off); + rc = sys_pwritev(fd, iovec, count, off); if (rc == -1 && errno == ENOSYS) { errno = olderr; demodernize = true; @@ -77,7 +77,7 @@ ssize_t pwritev(int fd, const struct iovec *iovec, int count, int64_t off) { } if (!demodernize) { - return pwritev$sysv(fd, iovec, count, off); + return sys_pwritev(fd, iovec, count, off); } else { return pwrite(fd, iovec[0].iov_base, iovec[0].iov_len, off); } diff --git a/libc/calls/raise.c b/libc/calls/raise.c index 2236518da..d547c6d4d 100644 --- a/libc/calls/raise.c +++ b/libc/calls/raise.c @@ -54,7 +54,7 @@ int raise(int sig) { return 0; } if (!IsWindows()) { - return kill$sysv(getpid(), sig, 1); + return sys_kill(getpid(), sig, 1); } else { if (GenerateConsoleCtrlEvent(GetCtrlEvent(sig), 0)) { return 0; diff --git a/libc/calls/read-nt.c b/libc/calls/read-nt.c index e21494442..e9b92f138 100644 --- a/libc/calls/read-nt.c +++ b/libc/calls/read-nt.c @@ -27,7 +27,7 @@ #include "libc/nt/struct/teb.h" #include "libc/sysv/errfuns.h" -textwindows ssize_t read$nt(struct Fd *fd, const struct iovec *iov, +textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov, size_t iovlen, ssize_t opt_offset) { uint32_t got; struct NtOverlapped overlap; diff --git a/libc/calls/readv.c b/libc/calls/readv.c index ba728f5d7..6fc7d21f7 100644 --- a/libc/calls/readv.c +++ b/libc/calls/readv.c @@ -39,12 +39,12 @@ ssize_t readv(int fd, const struct iovec *iov, int iovlen) { } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSerial) { return readv$serial(&g_fds.p[fd], iov, iovlen); } else if (!IsWindows()) { - return readv$sysv(fd, iov, iovlen); + return sys_readv(fd, iov, iovlen); } else if (fd < g_fds.n && (g_fds.p[fd].kind == kFdFile || g_fds.p[fd].kind == kFdConsole)) { - return read$nt(&g_fds.p[fd], iov, iovlen, -1); + return sys_read_nt(&g_fds.p[fd], iov, iovlen, -1); } else if (fd < g_fds.n && (g_fds.p[fd].kind == kFdSocket)) { - return weaken(recvfrom$nt)(&g_fds.p[fd], iov, iovlen, 0, NULL, 0); + return weaken(sys_recvfrom_nt)(&g_fds.p[fd], iov, iovlen, 0, NULL, 0); } else { return ebadf(); } diff --git a/libc/calls/renameat-nt.c b/libc/calls/renameat-nt.c index 31e670c39..5f0940d83 100644 --- a/libc/calls/renameat-nt.c +++ b/libc/calls/renameat-nt.c @@ -23,7 +23,7 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -textwindows int renameat$nt(int olddirfd, const char *oldpath, int newdirfd, +textwindows int sys_renameat_nt(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { char16_t oldpath16[PATH_MAX]; char16_t newpath16[PATH_MAX]; diff --git a/libc/calls/renameat.c b/libc/calls/renameat.c index 2285f62d6..ad4ff00a4 100644 --- a/libc/calls/renameat.c +++ b/libc/calls/renameat.c @@ -34,8 +34,8 @@ int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { if (!oldpath || !newpath) return efault(); if (!IsWindows()) { - return renameat$sysv(olddirfd, oldpath, newdirfd, newpath); + return sys_renameat(olddirfd, oldpath, newdirfd, newpath); } else { - return renameat$nt(olddirfd, oldpath, newdirfd, newpath); + return sys_renameat_nt(olddirfd, oldpath, newdirfd, newpath); } } diff --git a/libc/calls/sched_setaffinity.c b/libc/calls/sched_setaffinity.c index 4677069df..8aaecf9af 100644 --- a/libc/calls/sched_setaffinity.c +++ b/libc/calls/sched_setaffinity.c @@ -28,7 +28,7 @@ #include "libc/nt/thread.h" #include "libc/str/str.h" -static textwindows noinline int sched_setaffinity$nt(int pid, +static textwindows noinline int sys_sched_setaffinity_nt(int pid, uint64_t bitsetsize, const void *bitset) { int rc; @@ -69,8 +69,8 @@ static textwindows noinline int sched_setaffinity$nt(int pid, */ int sched_setaffinity(int pid, uint64_t bitsetsize, const void *bitset) { if (!IsWindows()) { - return sched_setaffinity$sysv(pid, bitsetsize, bitset); + return sys_sched_setaffinity(pid, bitsetsize, bitset); } else { - return sched_setaffinity$nt(pid, bitsetsize, bitset); + return sys_sched_setaffinity_nt(pid, bitsetsize, bitset); } } diff --git a/libc/calls/sched_yield-nt.c b/libc/calls/sched_yield-nt.c index cab2520ff..47a9fec3d 100644 --- a/libc/calls/sched_yield-nt.c +++ b/libc/calls/sched_yield-nt.c @@ -20,7 +20,7 @@ #include "libc/nt/enum/status.h" #include "libc/nt/ntdll.h" -textwindows int sched_yield$nt(void) { +textwindows int sys_sched_yield_nt(void) { size_t i; if (NtYieldExecution() == kNtStatusDllNotFound) { for (i = 0; i < 16; ++i) asm("pause"); diff --git a/libc/calls/sched_yield.c b/libc/calls/sched_yield.c index 09c50e205..c268fa279 100644 --- a/libc/calls/sched_yield.c +++ b/libc/calls/sched_yield.c @@ -25,8 +25,8 @@ */ int sched_yield(void) { if (!IsWindows()) { - return sched_yield$sysv(); + return sys_sched_yield(); } else { - return sched_yield$nt(); + return sys_sched_yield_nt(); } } diff --git a/libc/calls/setitimer-nt.c b/libc/calls/setitimer-nt.c index 3008b7c58..dc19d0381 100644 --- a/libc/calls/setitimer-nt.c +++ b/libc/calls/setitimer-nt.c @@ -60,7 +60,7 @@ static uint32_t ItimerWorker(void *arg) { return 0; } -textwindows int setitimer$nt(int which, const struct itimerval *newvalue, +textwindows int sys_setitimer_nt(int which, const struct itimerval *newvalue, struct itimerval *out_opt_oldvalue) { int32_t period; int64_t ith, duetime; diff --git a/libc/calls/setitimer.c b/libc/calls/setitimer.c index cdf0a7e2f..205ca9acc 100644 --- a/libc/calls/setitimer.c +++ b/libc/calls/setitimer.c @@ -63,11 +63,11 @@ int setitimer(int which, const struct itimerval *newvalue, struct itimerval *out_opt_oldvalue) { if (!IsWindows()) { if (newvalue) { - return setitimer$sysv(which, newvalue, out_opt_oldvalue); + return sys_setitimer(which, newvalue, out_opt_oldvalue); } else { - return getitimer$sysv(which, out_opt_oldvalue); + return sys_getitimer(which, out_opt_oldvalue); } } else { - return setitimer$nt(which, newvalue, out_opt_oldvalue); + return sys_setitimer_nt(which, newvalue, out_opt_oldvalue); } } diff --git a/libc/calls/setpriority-nt.c b/libc/calls/setpriority-nt.c index fc9881254..162f378e9 100644 --- a/libc/calls/setpriority-nt.c +++ b/libc/calls/setpriority-nt.c @@ -38,7 +38,7 @@ static textwindows struct NtPriorityCombo findntprio(int nice) { return kNtPriorityCombos[max(0, l - 1)]; } -textwindows int setpriority$nt(int nice) { +textwindows int sys_setpriority_nt(int nice) { uint32_t tier; struct NtPriorityCombo p; p = findntprio(nice); diff --git a/libc/calls/setpriority.c b/libc/calls/setpriority.c index 765198f35..682e62e54 100644 --- a/libc/calls/setpriority.c +++ b/libc/calls/setpriority.c @@ -30,8 +30,8 @@ */ int setpriority(int which, unsigned who, int value) { if (!IsWindows()) { - return setpriority$sysv(which, who, value); /* TODO(jart): -20 */ + return sys_setpriority(which, who, value); /* TODO(jart): -20 */ } else { - return getsetpriority$nt(which, who, value, setpriority$nt); + return sys_getsetpriority_nt(which, who, value, sys_setpriority_nt); } } diff --git a/libc/calls/setresgid.c b/libc/calls/setresgid.c index e69b1ebe0..b1af4e79d 100644 --- a/libc/calls/setresgid.c +++ b/libc/calls/setresgid.c @@ -29,5 +29,5 @@ */ int setresgid(uint32_t real, uint32_t effective, uint32_t saved) { if (saved == -1) return setregid(real, effective); - return setresgid$sysv(real, effective, saved); + return sys_setresgid(real, effective, saved); } diff --git a/libc/calls/setresuid.c b/libc/calls/setresuid.c index 62869c4ee..c4bc134de 100644 --- a/libc/calls/setresuid.c +++ b/libc/calls/setresuid.c @@ -29,5 +29,5 @@ */ int setresuid(uint32_t real, uint32_t effective, uint32_t saved) { if (saved == -1) return setreuid(real, effective); - return setresuid$sysv(real, effective, saved); + return sys_setresuid(real, effective, saved); } diff --git a/libc/calls/setrlimit.c b/libc/calls/setrlimit.c index a5a6b4e67..4a7671325 100644 --- a/libc/calls/setrlimit.c +++ b/libc/calls/setrlimit.c @@ -32,7 +32,7 @@ int setrlimit(int resource, const struct rlimit *rlim) { if (resource == -1) return einval(); if (!IsWindows()) { - return setrlimit$sysv(resource, rlim); + return sys_setrlimit(resource, rlim); } else { return enosys(); /* TODO(jart): Implement me! */ } diff --git a/libc/calls/setsid.c b/libc/calls/setsid.c index d728238fa..e4cde3710 100644 --- a/libc/calls/setsid.c +++ b/libc/calls/setsid.c @@ -23,5 +23,5 @@ * Creates session and sets the process group id. */ int setsid(void) { - return setsid$sysv(); + return sys_setsid(); } diff --git a/libc/calls/sigaction.c b/libc/calls/sigaction.c index 977f5c086..67eedd1e3 100644 --- a/libc/calls/sigaction.c +++ b/libc/calls/sigaction.c @@ -39,11 +39,11 @@ union metasigaction { struct sigaction cosmo; - struct sigaction$linux linux; - struct sigaction$freebsd freebsd; - struct sigaction$openbsd openbsd; - struct sigaction$xnu_in xnu_in; - struct sigaction$xnu_out xnu_out; + struct sigaction_linux linux; + struct sigaction_freebsd freebsd; + struct sigaction_openbsd openbsd; + struct sigaction_xnu_in xnu_in; + struct sigaction_xnu_out xnu_out; }; #ifndef SWITCHEROO @@ -124,11 +124,11 @@ static void sigaction$native2cosmo(union metasigaction *sa) { * @vforksafe */ int(sigaction)(int sig, const struct sigaction *act, struct sigaction *oldact) { - _Static_assert(sizeof(struct sigaction) > sizeof(struct sigaction$linux) && - sizeof(struct sigaction) > sizeof(struct sigaction$xnu_in) && - sizeof(struct sigaction) > sizeof(struct sigaction$xnu_out) && - sizeof(struct sigaction) > sizeof(struct sigaction$freebsd) && - sizeof(struct sigaction) > sizeof(struct sigaction$openbsd)); + _Static_assert(sizeof(struct sigaction) > sizeof(struct sigaction_linux) && + sizeof(struct sigaction) > sizeof(struct sigaction_xnu_in) && + sizeof(struct sigaction) > sizeof(struct sigaction_xnu_out) && + sizeof(struct sigaction) > sizeof(struct sigaction_freebsd) && + sizeof(struct sigaction) > sizeof(struct sigaction_openbsd)); int rc, rva, oldrva; struct sigaction *ap, copy; if (!(0 < sig && sig < NSIG)) return einval(); @@ -152,8 +152,8 @@ int(sigaction)(int sig, const struct sigaction *act, struct sigaction *oldact) { memcpy(©, act, sizeof(copy)); ap = © if (IsXnu()) { - ap->sa_restorer = (void *)&xnutrampoline; - ap->sa_handler = (void *)&xnutrampoline; + ap->sa_restorer = (void *)&__xnutrampoline; + ap->sa_handler = (void *)&__xnutrampoline; } else if (IsLinux()) { if (!(ap->sa_flags & SA_RESTORER)) { ap->sa_flags |= SA_RESTORER; @@ -166,7 +166,7 @@ int(sigaction)(int sig, const struct sigaction *act, struct sigaction *oldact) { } else { ap = NULL; } - rc = sigaction$sysv( + rc = sys_sigaction( sig, ap, oldact, (!IsXnu() ? 8 /* or linux whines */ : (int64_t)(intptr_t)oldact /* from go code */)); diff --git a/libc/calls/sigprocmask.c b/libc/calls/sigprocmask.c index 02185798f..94cb7c188 100644 --- a/libc/calls/sigprocmask.c +++ b/libc/calls/sigprocmask.c @@ -38,7 +38,7 @@ */ int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) { if (!IsWindows()) { - return sigprocmask$sysv(how, opt_set, opt_out_oldset, 8); + return sys_sigprocmask(how, opt_set, opt_out_oldset, 8); } else { return 0; /* TODO(jart): Implement me! */ } diff --git a/libc/calls/sigsuspend.c b/libc/calls/sigsuspend.c index 96b526f29..6f91a49d3 100644 --- a/libc/calls/sigsuspend.c +++ b/libc/calls/sigsuspend.c @@ -32,7 +32,7 @@ int sigsuspend(const sigset_t *ignore) { if (!ignore) return efault(); if (!IsWindows()) { - return sigsuspend$sysv(ignore, 8); + return sys_sigsuspend(ignore, 8); } else { return enosys(); /* TODO(jart): Implement me! */ } diff --git a/libc/calls/splice.c b/libc/calls/splice.c index a29d98194..bfe272af7 100644 --- a/libc/calls/splice.c +++ b/libc/calls/splice.c @@ -52,7 +52,7 @@ static ssize_t splicer(int infd, int64_t *inoffset, int outfd, ssize_t splice(int infd, int64_t *inopt_out_inoffset, int outfd, int64_t *inopt_out_outoffset, size_t uptobytes, uint32_t flags) { return splicer(infd, inopt_out_inoffset, outfd, inopt_out_outoffset, - uptobytes, flags, splice$sysv); + uptobytes, flags, sys_splice); } /** @@ -68,5 +68,5 @@ ssize_t copy_file_range(int infd, int64_t *inopt_out_inoffset, int outfd, int64_t *inopt_out_outoffset, size_t uptobytes, uint32_t flags) { return splicer(infd, inopt_out_inoffset, outfd, inopt_out_outoffset, - uptobytes, flags, copy_file_range$sysv); + uptobytes, flags, sys_copy_file_range); } diff --git a/libc/calls/stat2linux.c b/libc/calls/stat2linux.c index d815c51be..ba6b0ea66 100644 --- a/libc/calls/stat2linux.c +++ b/libc/calls/stat2linux.c @@ -52,19 +52,19 @@ } while (0); #endif -forceinline void stat2linux_xnu(union metastat *ms) { +static textstartup void __stat2linux_xnu(union metastat *ms) { SWITCHEROO(ms->xnu, ms->linux, st_dev, st_ino, st_nlink, st_mode, st_uid, st_gid, st_rdev, st_size, st_blksize, st_blocks, st_atim, st_mtim, st_ctim); } -forceinline void stat2linux_freebsd(union metastat *ms) { +static textstartup void __stat2linux_freebsd(union metastat *ms) { SWITCHEROO(ms->freebsd, ms->linux, st_dev, st_ino, st_nlink, st_mode, st_uid, st_gid, st_rdev, st_size, st_blksize, st_blocks, st_atim, st_mtim, st_ctim); } -forceinline void stat2linux_openbsd(union metastat *ms) { +static textstartup void __stat2linux_openbsd(union metastat *ms) { SWITCHEROO(ms->openbsd, ms->linux, st_dev, st_ino, st_nlink, st_mode, st_uid, st_gid, st_rdev, st_size, st_blksize, st_blocks, st_atim, st_mtim, st_ctim); @@ -74,14 +74,14 @@ forceinline void stat2linux_openbsd(union metastat *ms) { * Transcodes “The Dismal Data Structure” from BSD→Linux ABI. * @asyncsignalsafe */ -textstartup void stat2linux(void *ms) { +textstartup void __stat2linux(void *ms) { if (ms) { if (SupportsXnu() && IsXnu()) { - stat2linux_xnu((union metastat *)ms); + __stat2linux_xnu((union metastat *)ms); } else if (SupportsFreebsd() && IsFreebsd()) { - stat2linux_freebsd((union metastat *)ms); + __stat2linux_freebsd((union metastat *)ms); } else if (SupportsOpenbsd() && IsOpenbsd()) { - stat2linux_openbsd((union metastat *)ms); + __stat2linux_openbsd((union metastat *)ms); } } } diff --git a/libc/calls/struct/metastat.internal.h b/libc/calls/struct/metastat.internal.h index 9bcc4607e..3e3dca72a 100644 --- a/libc/calls/struct/metastat.internal.h +++ b/libc/calls/struct/metastat.internal.h @@ -5,50 +5,53 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +struct stat_xnu { + int32_t st_dev; + uint16_t st_mode, st_nlink; + uint64_t st_ino; + uint32_t st_uid, st_gid; + int32_t st_rdev; + struct timespec st_atim, st_mtim, st_ctim, st_birthtim; + int64_t st_size, st_blocks; + int32_t st_blksize; + uint32_t st_flags, st_gen; + int32_t st_lspare; + int64_t st_qspare[2]; +}; + +struct stat_freebsd { + uint64_t st_dev, st_ino, st_nlink; + uint16_t st_mode; + int16_t st_padding0; + uint32_t st_uid, st_gid; + int32_t st_padding1; + uint64_t st_rdev; + struct timespec st_atim, st_mtim, st_ctim, st_birthtim; + int64_t st_size, st_blocks; + int32_t st_blksize; + uint32_t st_flags; + uint64_t st_gen; + unsigned long st_spare[10]; +}; + +struct stat_openbsd { + uint32_t st_mode; + int32_t st_dev; + uint64_t st_ino; + uint32_t st_nlink, st_uid, st_gid; + int32_t st_rdev; + struct timespec st_atim, st_mtim, st_ctim; + int64_t st_size, st_blocks; + int32_t st_blksize; + uint32_t st_flags, st_gen; + struct timespec __st_birthtim; +}; + union metastat { struct stat linux; - - struct stat$xnu { - int32_t st_dev; - uint16_t st_mode, st_nlink; - uint64_t st_ino; - uint32_t st_uid, st_gid; - int32_t st_rdev; - struct timespec st_atim, st_mtim, st_ctim, st_birthtim; - int64_t st_size, st_blocks; - int32_t st_blksize; - uint32_t st_flags, st_gen; - int32_t st_lspare; - int64_t st_qspare[2]; - } xnu; - - struct stat$freebsd { - uint64_t st_dev, st_ino, st_nlink; - uint16_t st_mode; - int16_t st_padding0; - uint32_t st_uid, st_gid; - int32_t st_padding1; - uint64_t st_rdev; - struct timespec st_atim, st_mtim, st_ctim, st_birthtim; - int64_t st_size, st_blocks; - int32_t st_blksize; - uint32_t st_flags; - uint64_t st_gen; - unsigned long st_spare[10]; - } freebsd; - - struct stat$openbsd { - uint32_t st_mode; - int32_t st_dev; - uint64_t st_ino; - uint32_t st_nlink, st_uid, st_gid; - int32_t st_rdev; - struct timespec st_atim, st_mtim, st_ctim; - int64_t st_size, st_blocks; - int32_t st_blksize; - uint32_t st_flags, st_gen; - struct timespec __st_birthtim; - } openbsd; + struct stat_xnu xnu; + struct stat_freebsd freebsd; + struct stat_openbsd openbsd; }; COSMOPOLITAN_C_END_ diff --git a/libc/calls/struct/metatermios.internal.h b/libc/calls/struct/metatermios.internal.h index f78b52b56..02b31cd0e 100644 --- a/libc/calls/struct/metatermios.internal.h +++ b/libc/calls/struct/metatermios.internal.h @@ -5,7 +5,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct termios$xnu { +struct termios_xnu { uint64_t c_iflag; uint64_t c_oflag; uint64_t c_cflag; @@ -15,7 +15,7 @@ struct termios$xnu { uint64_t c_ospeed; }; -struct termios$bsd { +struct termios_bsd { uint32_t c_iflag; uint32_t c_oflag; uint32_t c_cflag; @@ -27,8 +27,8 @@ struct termios$bsd { union metatermios { struct termios linux; - struct termios$xnu xnu; - struct termios$bsd bsd; + struct termios_xnu xnu; + struct termios_bsd bsd; }; COSMOPOLITAN_C_END_ diff --git a/libc/calls/struct/sigaction-freebsd.internal.h b/libc/calls/struct/sigaction-freebsd.internal.h index aac23d131..ee111086a 100644 --- a/libc/calls/struct/sigaction-freebsd.internal.h +++ b/libc/calls/struct/sigaction-freebsd.internal.h @@ -2,12 +2,14 @@ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_FREEBSD_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) -struct sigaction$freebsd { +struct sigset_freebsd { + uint32_t sig[4]; +}; + +struct sigaction_freebsd { intptr_t sa_handler; uint32_t sa_flags; - struct sigset$freebsd { - uint32_t sig[4]; - } sa_mask; + struct sigset_freebsd sa_mask; }; #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/struct/sigaction-linux.internal.h b/libc/calls/struct/sigaction-linux.internal.h index 5a4e3f93b..b5f09de6a 100644 --- a/libc/calls/struct/sigaction-linux.internal.h +++ b/libc/calls/struct/sigaction-linux.internal.h @@ -2,13 +2,15 @@ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_LINUX_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) -struct sigaction$linux { +struct sigset_linux { + uint32_t sig[2]; +}; + +struct sigaction_linux { intptr_t sa_handler; uint64_t sa_flags; void (*sa_restorer)(void); - struct sigset$linux { - uint32_t sig[2]; - } sa_mask; + struct sigset_linux sa_mask; }; #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/struct/sigaction-openbsd.internal.h b/libc/calls/struct/sigaction-openbsd.internal.h index 47c629ea5..226883f5a 100644 --- a/libc/calls/struct/sigaction-openbsd.internal.h +++ b/libc/calls/struct/sigaction-openbsd.internal.h @@ -2,11 +2,13 @@ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_OPENBSD_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) -struct sigaction$openbsd { +struct sigset_openbsd { + uint32_t sig[1]; +}; + +struct sigaction_openbsd { intptr_t sa_handler; - struct sigset$openbsd { - uint32_t sig[1]; - } sa_mask; + struct sigset_openbsd sa_mask; int32_t sa_flags; }; diff --git a/libc/calls/struct/sigaction-xnu.internal.h b/libc/calls/struct/sigaction-xnu.internal.h index e69329591..24ab6ffc7 100644 --- a/libc/calls/struct/sigaction-xnu.internal.h +++ b/libc/calls/struct/sigaction-xnu.internal.h @@ -5,21 +5,21 @@ struct __darwin_ucontext; struct __darwin_siginfo; -struct sigset$xnu { +struct sigset_xnu { uint32_t sig[1]; }; -struct sigaction$xnu_in { +struct sigaction_xnu_in { intptr_t sa_handler; void (*sa_restorer)(void *, int, int, const struct __darwin_siginfo *, const struct __darwin_ucontext *); - struct sigset$xnu sa_mask; + struct sigset_xnu sa_mask; int32_t sa_flags; }; -struct sigaction$xnu_out { +struct sigaction_xnu_out { intptr_t sa_handler; - struct sigset$xnu sa_mask; + struct sigset_xnu sa_mask; int32_t sa_flags; }; diff --git a/libc/calls/struct/user_regs_struct.h b/libc/calls/struct/user_regs_struct.h index 32a7cf762..7caad2a7a 100644 --- a/libc/calls/struct/user_regs_struct.h +++ b/libc/calls/struct/user_regs_struct.h @@ -39,7 +39,7 @@ struct user_regs_struct { uint64_t gs; }; -struct useregs_struct$freebsd { +struct useregs_struct_freebsd { int64_t r15; int64_t r14; int64_t r13; diff --git a/libc/calls/symlinkat-nt.c b/libc/calls/symlinkat-nt.c index 509a17736..c34ff9cc2 100644 --- a/libc/calls/symlinkat-nt.c +++ b/libc/calls/symlinkat-nt.c @@ -20,7 +20,7 @@ #include "libc/calls/internal.h" #include "libc/nt/files.h" -textwindows int symlinkat$nt(const char *target, int newdirfd, +textwindows int sys_symlinkat_nt(const char *target, int newdirfd, const char *linkpath) { uint32_t flags; char16_t target16[PATH_MAX]; diff --git a/libc/calls/symlinkat.c b/libc/calls/symlinkat.c index d1ebaf26b..2c08c469b 100644 --- a/libc/calls/symlinkat.c +++ b/libc/calls/symlinkat.c @@ -36,8 +36,8 @@ */ int symlinkat(const char *target, int newdirfd, const char *linkpath) { if (!IsWindows()) { - return symlinkat$sysv(target, newdirfd, linkpath); + return sys_symlinkat(target, newdirfd, linkpath); } else { - return symlinkat$nt(target, newdirfd, linkpath); + return sys_symlinkat_nt(target, newdirfd, linkpath); } } diff --git a/libc/calls/sync-nt.c b/libc/calls/sync-nt.c index e3597cbb9..5188199f0 100644 --- a/libc/calls/sync-nt.c +++ b/libc/calls/sync-nt.c @@ -29,7 +29,7 @@ /** * Flushes all open file handles and, if possible, all disk drives. */ -int sync$nt(void) { +int sys_sync_nt(void) { unsigned i; int64_t volume; uint32_t drives; diff --git a/libc/calls/sync.c b/libc/calls/sync.c index 219b2548c..c6f80f994 100644 --- a/libc/calls/sync.c +++ b/libc/calls/sync.c @@ -25,8 +25,8 @@ */ void sync(void) { if (!IsWindows()) { - sync$sysv(); + sys_sync(); } else { - sync$nt(); + sys_sync_nt(); } } diff --git a/libc/calls/sync_file_range.c b/libc/calls/sync_file_range.c index 78e1de969..54110b570 100644 --- a/libc/calls/sync_file_range.c +++ b/libc/calls/sync_file_range.c @@ -34,7 +34,7 @@ int sync_file_range(int fd, int64_t offset, int64_t bytes, unsigned flags) { int rc, olderr; olderr = errno; - if ((rc = sync_file_range$sysv(fd, offset, bytes, flags)) != -1 || + if ((rc = sys_sync_file_range(fd, offset, bytes, flags)) != -1 || errno != ENOSYS) { return rc; } else { diff --git a/libc/calls/sysinfo-nt.c b/libc/calls/sysinfo-nt.c index de1947415..8b7317e10 100644 --- a/libc/calls/sysinfo-nt.c +++ b/libc/calls/sysinfo-nt.c @@ -23,13 +23,13 @@ #include "libc/nt/struct/systeminfo.h" #include "libc/nt/systeminfo.h" -textwindows int sysinfo$nt(struct sysinfo *info) { +textwindows int sys_sysinfo_nt(struct sysinfo *info) { struct NtMemoryStatusEx memstat; memstat.dwLength = sizeof(struct NtMemoryStatusEx); if (GlobalMemoryStatusEx(&memstat)) { info->totalram = memstat.ullTotalPhys; info->freeram = memstat.ullAvailPhys; - info->procs = g_ntsysteminfo.dwNumberOfProcessors; + info->procs = __nt_systeminfo.dwNumberOfProcessors; info->mem_unit = 1; return 0; } else { diff --git a/libc/calls/sysinfo.c b/libc/calls/sysinfo.c index 0c7db1889..752d5b54b 100644 --- a/libc/calls/sysinfo.c +++ b/libc/calls/sysinfo.c @@ -37,9 +37,9 @@ int sysinfo(struct sysinfo *info) { int rc; memset(info, 0, sizeof(*info)); if (!IsWindows()) { - rc = sysinfo$sysv(info); + rc = sys_sysinfo(info); } else { - rc = sysinfo$nt(info); + rc = sys_sysinfo_nt(info); } info->procs = max(1, info->procs); info->mem_unit = max(1, info->mem_unit); diff --git a/libc/calls/thunks/fork-sysv.S b/libc/calls/thunks/fork-sysv.S index ee5d150b4..55f2cb11d 100644 --- a/libc/calls/thunks/fork-sysv.S +++ b/libc/calls/thunks/fork-sysv.S @@ -22,11 +22,11 @@ / Makes fork() kernel ABI consistent across UNIX systems. / / @return 0 if parent, pid if child, or -1 on error -fork$sysv: +sys_fork: push %rbp mov %rsp,%rbp .profilable - call __fork$sysv + call __sys_fork #if SupportsXnu() testb IsXnu() jz 1f @@ -38,4 +38,4 @@ fork$sysv: #endif 1: pop %rbp ret - .endfn fork$sysv,globl,hidden + .endfn sys_fork,globl,hidden diff --git a/libc/calls/thunks/ftruncate-sysv.S b/libc/calls/thunks/ftruncate-sysv.S index 050fa168f..e07623f84 100644 --- a/libc/calls/thunks/ftruncate-sysv.S +++ b/libc/calls/thunks/ftruncate-sysv.S @@ -20,7 +20,7 @@ .source __FILE__ / Directly calls ftruncate() impl on host o/s if available. -ftruncate$sysv: +sys_ftruncate: mov %rsi,%rdx # openbsd:pad - jmp __ftruncate$sysv - .endfn ftruncate$sysv,globl,hidden + jmp __sys_ftruncate + .endfn sys_ftruncate,globl,hidden diff --git a/libc/calls/thunks/lseek-sysv.S b/libc/calls/thunks/lseek-sysv.S index 7eece2cfb..03965beb1 100644 --- a/libc/calls/thunks/lseek-sysv.S +++ b/libc/calls/thunks/lseek-sysv.S @@ -21,15 +21,15 @@ .source __FILE__ / Directly calls lseek() impl on host o/s if available. -lseek$sysv: +sys_lseek: #if SupportsOpenbsd() testb IsOpenbsd() # openbsd:evilpad cmovnz %rdx,%rcx cmovnz %rsi,%rdx cmovnz .Lzero(%rip),%rsi #endif - jmp __lseek$sysv - .endfn lseek$sysv,globl,hidden + jmp __sys_lseek + .endfn sys_lseek,globl,hidden .rodata.cst8 .Lzero: .quad 0 diff --git a/libc/calls/thunks/mmap-sysv.S b/libc/calls/thunks/mmap-sysv.S index 34574efe0..93647faa7 100644 --- a/libc/calls/thunks/mmap-sysv.S +++ b/libc/calls/thunks/mmap-sysv.S @@ -20,11 +20,11 @@ .source __FILE__ / Directly calls mmap() on system five host o/s. -mmap$sysv: +sys_mmap: push %rbp mov %rsp,%rbp push %r9 # openbsd:pad - call __mmap$sysv + call __sys_mmap leave ret - .endfn mmap$sysv,globl,hidden + .endfn sys_mmap,globl,hidden diff --git a/libc/calls/thunks/onntconsoleevent.S b/libc/calls/thunks/onntconsoleevent.S index 1126da796..264158940 100644 --- a/libc/calls/thunks/onntconsoleevent.S +++ b/libc/calls/thunks/onntconsoleevent.S @@ -20,7 +20,7 @@ .text.windows .source __FILE__ -__onntconsoleevent$nt: +__onntconsoleevent_nt: ezlea __onntconsoleevent,ax jmp __nt2sysv - .endfn __onntconsoleevent$nt,globl,hidden + .endfn __onntconsoleevent_nt,globl,hidden diff --git a/libc/calls/thunks/onwincrash.S b/libc/calls/thunks/onwincrash.S index 8f74e9f38..187c1606d 100644 --- a/libc/calls/thunks/onwincrash.S +++ b/libc/calls/thunks/onwincrash.S @@ -20,7 +20,7 @@ .text.windows .source __FILE__ -__wincrash$nt: +__wincrash_nt: ezlea __wincrash,ax jmp __nt2sysv - .endfn __wincrash$nt,globl,hidden + .endfn __wincrash_nt,globl,hidden diff --git a/libc/calls/thunks/pread-sysv.S b/libc/calls/thunks/pread-sysv.S index ca544e247..805cd3c01 100644 --- a/libc/calls/thunks/pread-sysv.S +++ b/libc/calls/thunks/pread-sysv.S @@ -20,7 +20,7 @@ .source __FILE__ / Directly calls pread() impl on host o/s if available. -pread$sysv: +sys_pread: mov %rcx,%r8 # openbsd:pad - jmp __pread$sysv - .endfn pread$sysv,globl,hidden + jmp __sys_pread + .endfn sys_pread,globl,hidden diff --git a/libc/calls/thunks/preadv-sysv.S b/libc/calls/thunks/preadv-sysv.S index 717695b01..bf3bc3e2b 100644 --- a/libc/calls/thunks/preadv-sysv.S +++ b/libc/calls/thunks/preadv-sysv.S @@ -20,7 +20,7 @@ .source __FILE__ / Directly calls preadv() impl on host o/s if available. -preadv$sysv: +sys_preadv: mov %rcx,%r8 # openbsd:pad - jmp __preadv$sysv - .endfn preadv$sysv,globl,hidden + jmp __sys_preadv + .endfn sys_preadv,globl,hidden diff --git a/libc/calls/thunks/pwrite-sysv.S b/libc/calls/thunks/pwrite-sysv.S index 2cea4f805..1f3c8e4ef 100644 --- a/libc/calls/thunks/pwrite-sysv.S +++ b/libc/calls/thunks/pwrite-sysv.S @@ -20,7 +20,7 @@ .source __FILE__ / Directly calls pwrite() impl on host o/s if available. -pwrite$sysv: +sys_pwrite: mov %rcx,%r8 # openbsd:pad - jmp __pwrite$sysv - .endfn pwrite$sysv,globl,hidden + jmp __sys_pwrite + .endfn sys_pwrite,globl,hidden diff --git a/libc/calls/thunks/pwritev-sysv.S b/libc/calls/thunks/pwritev-sysv.S index 832174437..831f2e1a6 100644 --- a/libc/calls/thunks/pwritev-sysv.S +++ b/libc/calls/thunks/pwritev-sysv.S @@ -20,7 +20,7 @@ .source __FILE__ / Directly calls pwritev() impl on host o/s if available. -pwritev$sysv: +sys_pwritev: mov %rcx,%r8 # openbsd:pad - jmp __pwritev$sysv - .endfn pwritev$sysv,globl,hidden + jmp __sys_pwritev + .endfn sys_pwritev,globl,hidden diff --git a/libc/calls/thunks/truncate-sysv.S b/libc/calls/thunks/truncate-sysv.S index bac70ef04..80a52ae0d 100644 --- a/libc/calls/thunks/truncate-sysv.S +++ b/libc/calls/thunks/truncate-sysv.S @@ -20,7 +20,7 @@ .source __FILE__ / Directly calls truncate() impl on host o/s if available. -truncate$sysv: +sys_truncate: mov %rsi,%rdx # openbsd:pad - jmp __truncate$sysv - .endfn truncate$sysv,globl,hidden + jmp __sys_truncate + .endfn sys_truncate,globl,hidden diff --git a/libc/calls/thunks/winalarm.S b/libc/calls/thunks/winalarm.S index 3025404bd..292758094 100644 --- a/libc/calls/thunks/winalarm.S +++ b/libc/calls/thunks/winalarm.S @@ -20,7 +20,7 @@ .text.windows .source __FILE__ -__winalarm$nt: +__winalarm_nt: ezlea __winalarm,ax jmp __nt2sysv - .endfn __winalarm$nt,globl,hidden + .endfn __winalarm_nt,globl,hidden diff --git a/libc/calls/truncate-nt.c b/libc/calls/truncate-nt.c index 18a1407d5..01d82ec37 100644 --- a/libc/calls/truncate-nt.c +++ b/libc/calls/truncate-nt.c @@ -24,14 +24,14 @@ #include "libc/nt/enum/filesharemode.h" #include "libc/nt/runtime.h" -textwindows int truncate$nt(const char *path, uint64_t length) { +textwindows int sys_truncate_nt(const char *path, uint64_t length) { bool32 ok; int64_t fh; uint16_t path16[PATH_MAX]; if (__mkntpath(path, path16) == -1) return -1; if ((fh = CreateFile(path16, kNtGenericWrite, kNtFileShareRead, NULL, kNtOpenExisting, kNtFileAttributeNormal, 0)) != -1) { - ok = ftruncate$nt(fh, length); + ok = sys_ftruncate_nt(fh, length); CloseHandle(fh); if (ok) return 0; } diff --git a/libc/calls/truncate.c b/libc/calls/truncate.c index 7588281a4..bc4f8c295 100644 --- a/libc/calls/truncate.c +++ b/libc/calls/truncate.c @@ -34,8 +34,8 @@ int truncate(const char *path, uint64_t length) { if (!path) return efault(); if (!IsWindows()) { - return truncate$sysv(path, length); + return sys_truncate(path, length); } else { - return truncate$nt(path, length); + return sys_truncate_nt(path, length); } } diff --git a/libc/calls/ttyname_r.c b/libc/calls/ttyname_r.c index 272b56de4..ee60dba64 100644 --- a/libc/calls/ttyname_r.c +++ b/libc/calls/ttyname_r.c @@ -27,7 +27,7 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -static textwindows noinline int ttyname$nt(int fd, char *buf, size_t size) { +static textwindows noinline int sys_ttyname_nt(int fd, char *buf, size_t size) { uint32_t mode; if (GetConsoleMode(g_fds.p[fd].handle, &mode)) { if (mode & kNtEnableVirtualTerminalInput) { @@ -42,7 +42,7 @@ static textwindows noinline int ttyname$nt(int fd, char *buf, size_t size) { } } -static int ttyname$freebsd(int fd, char *buf, size_t size) { +static int ttyname_freebsd(int fd, char *buf, size_t size) { const unsigned FIODGNAME = 2148558456; struct fiodgname_arg { int len; @@ -50,11 +50,11 @@ static int ttyname$freebsd(int fd, char *buf, size_t size) { } fg; fg.buf = buf; fg.len = size; - if (ioctl$sysv(fd, FIODGNAME, &fg) != -1) return 0; + if (sys_ioctl(fd, FIODGNAME, &fg) != -1) return 0; return enotty(); } -static int ttyname$linux(int fd, char *buf, size_t size) { +static int ttyname_linux(int fd, char *buf, size_t size) { struct stat st1, st2; if (!isatty(fd)) return errno; char name[PATH_MAX]; @@ -71,12 +71,12 @@ static int ttyname$linux(int fd, char *buf, size_t size) { int ttyname_r(int fd, char *buf, size_t size) { if (IsLinux()) { - return ttyname$linux(fd, buf, size); + return ttyname_linux(fd, buf, size); } else if (IsFreebsd()) { - return ttyname$freebsd(fd, buf, size); + return ttyname_freebsd(fd, buf, size); } else if (IsWindows()) { if (__isfdkind(fd, kFdFile)) { - return ttyname$nt(fd, buf, size); + return sys_ttyname_nt(fd, buf, size); } else { return ebadf(); } diff --git a/libc/calls/uname.c b/libc/calls/uname.c index 2929090fd..888e2920c 100644 --- a/libc/calls/uname.c +++ b/libc/calls/uname.c @@ -30,7 +30,7 @@ int uname(struct utsname *lool) { size_t i, j, len; char tmp[sizeof(struct utsname)]; memset(tmp, 0, sizeof(tmp)); - if (uname$sysv(tmp) != -1) { + if (sys_uname(tmp) != -1) { out = (char *)lool; i = 0; j = 0; diff --git a/libc/calls/unlinkat-nt.c b/libc/calls/unlinkat-nt.c index b6066b3f8..c690109d3 100644 --- a/libc/calls/unlinkat-nt.c +++ b/libc/calls/unlinkat-nt.c @@ -24,7 +24,7 @@ #include "libc/nt/synchronization.h" #include "libc/sysv/consts/at.h" -static textwindows int unlink$nt(const char16_t *path) { +static textwindows int sys_unlink_nt(const char16_t *path) { if (DeleteFile(path)) { return 0; } else { @@ -32,7 +32,7 @@ static textwindows int unlink$nt(const char16_t *path) { } } -static textwindows int rmdir$nt(const char16_t *path) { +static textwindows int sys_rmdir_nt(const char16_t *path) { int e, ms; for (ms = 1;; ms *= 2) { if (RemoveDirectory(path)) return 0; @@ -54,12 +54,12 @@ static textwindows int rmdir$nt(const char16_t *path) { return -1; } -textwindows int unlinkat$nt(int dirfd, const char *path, int flags) { +textwindows int sys_unlinkat_nt(int dirfd, const char *path, int flags) { uint16_t path16[PATH_MAX]; if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; if (flags & AT_REMOVEDIR) { - return rmdir$nt(path16); + return sys_rmdir_nt(path16); } else { - return unlink$nt(path16); + return sys_unlink_nt(path16); } } diff --git a/libc/calls/unlinkat.c b/libc/calls/unlinkat.c index 0c682db90..5097fdc29 100644 --- a/libc/calls/unlinkat.c +++ b/libc/calls/unlinkat.c @@ -32,8 +32,8 @@ */ int unlinkat(int dirfd, const char *path, int flags) { if (!IsWindows()) { - return unlinkat$sysv(dirfd, path, flags); + return sys_unlinkat(dirfd, path, flags); } else { - return unlinkat$nt(dirfd, path, flags); + return sys_unlinkat_nt(dirfd, path, flags); } } diff --git a/libc/calls/utimensat-nt.c b/libc/calls/utimensat-nt.c index fbe249901..1ba55e415 100644 --- a/libc/calls/utimensat-nt.c +++ b/libc/calls/utimensat-nt.c @@ -31,7 +31,7 @@ #include "libc/sysv/errfuns.h" #include "libc/time/time.h" -textwindows int utimensat$nt(int dirfd, const char *path, +textwindows int sys_utimensat_nt(int dirfd, const char *path, const struct timespec ts[2], int flags) { int i, rc; int64_t fh; diff --git a/libc/calls/utimensat-sysv.c b/libc/calls/utimensat-sysv.c index 803328051..7df8fbdeb 100644 --- a/libc/calls/utimensat-sysv.c +++ b/libc/calls/utimensat-sysv.c @@ -19,11 +19,11 @@ #include "libc/calls/internal.h" #include "libc/time/time.h" -int utimensat$sysv(int dirfd, const char *path, const struct timespec ts[2], - int flags) { +int sys_utimensat(int dirfd, const char *path, const struct timespec ts[2], + int flags) { if (!IsXnu()) { - return __utimensat$sysv(dirfd, path, ts, flags); + return __sys_utimensat(dirfd, path, ts, flags); } else { - return utimensat$xnu(dirfd, path, ts, flags); + return sys_utimensat_xnu(dirfd, path, ts, flags); } } diff --git a/libc/calls/utimensat-xnu.c b/libc/calls/utimensat-xnu.c index e4c783a4a..e7ebb91ec 100644 --- a/libc/calls/utimensat-xnu.c +++ b/libc/calls/utimensat-xnu.c @@ -23,8 +23,8 @@ #include "libc/sysv/errfuns.h" #include "libc/time/time.h" -int utimensat$xnu(int dirfd, const char *path, const struct timespec ts[2], - int flags) { +int sys_utimensat_xnu(int dirfd, const char *path, const struct timespec ts[2], + int flags) { int i; struct timeval now, tv[2]; if (flags) return einval(); @@ -48,13 +48,13 @@ int utimensat$xnu(int dirfd, const char *path, const struct timespec ts[2], } if (path) { if (dirfd == AT_FDCWD) { - return utimes$sysv(path, tv); + return sys_utimes(path, tv); } else { return enosys(); } } else { if (dirfd != AT_FDCWD) { - return futimes$sysv(dirfd, tv); + return sys_futimes(dirfd, tv); } else { return einval(); } diff --git a/libc/calls/utimensat.c b/libc/calls/utimensat.c index 0d8a1ca22..2b33be08f 100644 --- a/libc/calls/utimensat.c +++ b/libc/calls/utimensat.c @@ -29,8 +29,8 @@ int utimensat(int dirfd, const char *path, const struct timespec ts[hasatleast 2], int flags) { if (!IsWindows()) { - return utimensat$sysv(dirfd, path, ts, flags); + return sys_utimensat(dirfd, path, ts, flags); } else { - return utimensat$nt(dirfd, path, ts, flags); + return sys_utimensat_nt(dirfd, path, ts, flags); } } diff --git a/libc/calls/vmsplice.c b/libc/calls/vmsplice.c index 0196f2bd4..1f07e1797 100644 --- a/libc/calls/vmsplice.c +++ b/libc/calls/vmsplice.c @@ -32,7 +32,7 @@ ssize_t vmsplice(int fd, const struct iovec *chunks, int64_t count, int olderr; ssize_t wrote; olderr = errno; - if ((wrote = vmsplice$sysv(fd, chunks, count, flags)) == -1) { + if ((wrote = sys_vmsplice(fd, chunks, count, flags)) == -1) { errno = olderr; if (count) { wrote = write(fd, chunks[0].iov_base, chunks[0].iov_len); diff --git a/libc/calls/wait3.c b/libc/calls/wait3.c index 5e73975de..952b568cb 100644 --- a/libc/calls/wait3.c +++ b/libc/calls/wait3.c @@ -33,7 +33,7 @@ */ int wait3(int *opt_out_wstatus, int options, struct rusage *opt_out_rusage) { if (!IsWindows()) { - return wait4$sysv(-1, opt_out_wstatus, options, opt_out_rusage); + return sys_wait4(-1, opt_out_wstatus, options, opt_out_rusage); } else { return enosys(); /* TODO(jart) */ } diff --git a/libc/calls/wait4-nt.c b/libc/calls/wait4-nt.c index ffe3eb8c9..0c1f8094e 100644 --- a/libc/calls/wait4-nt.c +++ b/libc/calls/wait4-nt.c @@ -32,7 +32,7 @@ #include "libc/sysv/consts/w.h" #include "libc/sysv/errfuns.h" -textwindows int wait4$nt(int pid, int *opt_out_wstatus, int options, +textwindows int sys_wait4_nt(int pid, int *opt_out_wstatus, int options, struct rusage *opt_out_rusage) { int pids[64]; int64_t handles[64]; diff --git a/libc/calls/wait4.c b/libc/calls/wait4.c index bae7e0385..564a64848 100644 --- a/libc/calls/wait4.c +++ b/libc/calls/wait4.c @@ -36,8 +36,8 @@ int wait4(int pid, int *opt_out_wstatus, int options, struct rusage *opt_out_rusage) { if (!IsWindows()) { - return wait4$sysv(pid, opt_out_wstatus, options, opt_out_rusage); + return sys_wait4(pid, opt_out_wstatus, options, opt_out_rusage); } else { - return wait4$nt(pid, opt_out_wstatus, options, opt_out_rusage); + return sys_wait4_nt(pid, opt_out_wstatus, options, opt_out_rusage); } } diff --git a/libc/calls/wait4.h b/libc/calls/wait4.h index 03ea3ba20..51507989d 100644 --- a/libc/calls/wait4.h +++ b/libc/calls/wait4.h @@ -4,7 +4,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -int wait4$nt(int, int *, int, struct rusage *) hidden; +int sys_wait4_nt(int, int *, int, struct rusage *) hidden; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/wincrash_init.S b/libc/calls/wincrash_init.S index 62b839b38..093ddf653 100644 --- a/libc/calls/wincrash_init.S +++ b/libc/calls/wincrash_init.S @@ -21,6 +21,6 @@ .init.start 300,_init_wincrash pushpop 1,%rcx - ezlea __wincrash$nt,dx + ezlea __wincrash_nt,dx ntcall __imp_AddVectoredExceptionHandler .init.end 300,_init_wincrash,globl,hidden diff --git a/libc/calls/write-nt.c b/libc/calls/write-nt.c index bc414cd08..c508a5725 100644 --- a/libc/calls/write-nt.c +++ b/libc/calls/write-nt.c @@ -33,7 +33,7 @@ static size_t SumIovecLen(const struct iovec *v, size_t n) { return sum; } -textwindows ssize_t write$nt(struct Fd *fd, const struct iovec *iov, +textwindows ssize_t sys_write_nt(struct Fd *fd, const struct iovec *iov, size_t iovlen, ssize_t opt_offset) { uint32_t wrote; struct NtOverlapped overlap; diff --git a/libc/calls/writev.c b/libc/calls/writev.c index 0bc9e9e65..9bbc68fae 100644 --- a/libc/calls/writev.c +++ b/libc/calls/writev.c @@ -42,12 +42,12 @@ ssize_t writev(int fd, const struct iovec *iov, int iovlen) { } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSerial) { return writev$serial(&g_fds.p[fd], iov, iovlen); } else if (!IsWindows()) { - return writev$sysv(fd, iov, iovlen); + return sys_writev(fd, iov, iovlen); } else if (fd < g_fds.n && (g_fds.p[fd].kind == kFdFile || g_fds.p[fd].kind == kFdConsole)) { - return write$nt(&g_fds.p[fd], iov, iovlen, -1); + return sys_write_nt(&g_fds.p[fd], iov, iovlen, -1); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSocket) { - return weaken(sendto$nt)(&g_fds.p[fd], iov, iovlen, 0, NULL, 0); + return weaken(sys_sendto_nt)(&g_fds.p[fd], iov, iovlen, 0, NULL, 0); } else { return ebadf(); } diff --git a/libc/calls/xnutrampoline.c b/libc/calls/xnutrampoline.c index ee0b7eb20..2e8a9a676 100644 --- a/libc/calls/xnutrampoline.c +++ b/libc/calls/xnutrampoline.c @@ -424,9 +424,9 @@ static void xnussefpustate2linux(struct FpuState *fs, memcpy(fs->st, &xnufs->__fpu_stmm0, (8 + 16) * sizeof(uint128_t)); } -wontreturn void xnutrampoline(void *fn, int infostyle, int sig, - const struct __darwin_siginfo *xnuinfo, - const struct __darwin_ucontext *xnuctx) { +wontreturn void __xnutrampoline(void *fn, int infostyle, int sig, + const struct __darwin_siginfo *xnuinfo, + const struct __darwin_ucontext *xnuctx) { /* note: this function impl can't access static memory */ intptr_t ax; struct Goodies { diff --git a/libc/crt/crt.S b/libc/crt/crt.S index ad70ccc6e..f65ac82db 100644 --- a/libc/crt/crt.S +++ b/libc/crt/crt.S @@ -52,17 +52,29 @@ _start: test %rdi,%rdi mov %rdx,%rdi repnz scasq mov %rdi,%rcx # auxv - mov %ebx,%edi +#if SupportsXnu() + testb IsXnu() + jz 1f # polyfill xnu auxv + push $0 # auxv[1][1]=0 + push $0 # auxv[1][0]=0 + mov (%rcx),%rax # executable_path=BIN + lea 16(%rax),%rax # BIN + push %rax # auxv[0][0]=BIN + push $31 # auxv[0][0]=AT_EXECFN + mov %rsp,%rcx # auxv +#endif +1: mov %ebx,%edi call cosmo 9: ud2 .endfn _start,weak,hidden +#if SupportsXnu() / Macintosh userspace program entrypoint. / / @param rsp is [n,argv₀..argvₙ₋₁,0,envp₀..,0,auxv₀..,0,..] / @note FreeBSD is special (see freebsd/lib/csu/amd64/...) / @noreturn -_start_xnu: - movb $XNU,__hostos(%rip) +_xnu: movb $XNU,__hostos(%rip) jmp 0b - .endfn _start_xnu,weak,hidden + .endfn _xnu,weak,hidden +#endif diff --git a/libc/dns/dnsheader.c b/libc/dns/dnsheader.c index 090a7c1e9..f26392aac 100644 --- a/libc/dns/dnsheader.c +++ b/libc/dns/dnsheader.c @@ -52,12 +52,12 @@ int serializednsheader(uint8_t *buf, size_t size, int deserializednsheader(struct DnsHeader *header, const uint8_t *buf, size_t size) { if (size < 12) return ebadmsg(); - header->id = read16be(buf + 0); + header->id = READ16BE(buf + 0); header->bf1 = buf[2]; header->bf2 = buf[3]; - header->qdcount = read16be(buf + 4); - header->ancount = read16be(buf + 6); - header->nscount = read16be(buf + 8); - header->arcount = read16be(buf + 10); + header->qdcount = READ16BE(buf + 4); + header->ancount = READ16BE(buf + 6); + header->nscount = READ16BE(buf + 8); + header->arcount = READ16BE(buf + 10); return 12; } diff --git a/libc/dns/resolvedns.c b/libc/dns/resolvedns.c index a54e809df..8870e7616 100644 --- a/libc/dns/resolvedns.c +++ b/libc/dns/resolvedns.c @@ -94,7 +94,7 @@ int resolvedns(const struct ResolvConf *resolvconf, int af, const char *name, rtype = READ16BE(p), p += 2; rclass = READ16BE(p), p += 2; /* ttl */ p += 4; - rdlength = read16be(p), p += 2; + rdlength = READ16BE(p), p += 2; if (p + rdlength <= pe && rdlength == 4 && (rtype == DNS_TYPE_A && rclass == DNS_CLASS_IN)) { res = 1; diff --git a/libc/errno.h b/libc/errno.h index 935ba5264..8fa10fa50 100644 --- a/libc/errno.h +++ b/libc/errno.h @@ -6,137 +6,137 @@ * @see libc/sysv/consts.sh for numbers */ -#define EPERM EPERM // operation not permitted -#define ENOENT ENOENT // no such file or directory -#define ESRCH ESRCH // no such process -#define EINTR EINTR // interrupted system call -#define EIO EIO // input/output error -#define ENXIO ENXIO // no such device or address -#define E2BIG E2BIG // argument list too long -#define ENOEXEC ENOEXEC // exec format error -#define EBADF EBADF // bad file descriptor -#define ECHILD ECHILD // no child processes -#define EAGAIN EAGAIN // resource temporarily unavailable -#define ENOMEM ENOMEM // not enough space -#define EACCES EACCES // permission denied -#define EFAULT EFAULT // bad address -#define ENOTBLK ENOTBLK // block device required -#define EBUSY EBUSY // device or resource busy -#define EEXIST EEXIST // file exists -#define EXDEV EXDEV // improper link -#define ENODEV ENODEV // no such device -#define ENOTDIR ENOTDIR // not a directory -#define EISDIR EISDIR // is a directory -#define EINVAL EINVAL // invalid argument -#define ENFILE ENFILE // too many open files in system -#define EMFILE EMFILE // too many open files -#define ENOTTY ENOTTY // inappropriate I/O control op -#define ETXTBSY ETXTBSY // text file busy -#define EFBIG EFBIG // file too large -#define ENOSPC ENOSPC // no space left on device -#define ESPIPE ESPIPE // invalid seek -#define EROFS EROFS // read-only filesystem -#define EMLINK EMLINK // too many links -#define EPIPE EPIPE // broken pipe -#define EDOM EDOM // argument out of function domain -#define ERANGE ERANGE // result too large -#define EDEADLK EDEADLK // resource deadlock avoided -#define ENAMETOOLONG ENAMETOOLONG // filename too long -#define ENOLCK ENOLCK // no locks available -#define ENOSYS ENOSYS // system call not implemented -#define ENOTEMPTY ENOTEMPTY // directory not empty -#define ELOOP ELOOP // too many levels of symbolic links -#define ENOMSG ENOMSG // no message of the desired type -#define EIDRM EIDRM // identifier removed -#define ECHRNG ECHRNG // channel number out of range -#define EL2NSYNC EL2NSYNC // level 2 not synchronized -#define EL3HLT EL3HLT // level 3 halted -#define EL3RST EL3RST // level 3 halted -#define ELNRNG ELNRNG // link number out of range -#define EUNATCH EUNATCH // protocol driver not attached -#define ENOCSI ENOCSI // no csi structure available -#define EL2HLT EL2HLT // level 2 halted -#define EBADE EBADE // invalid exchange -#define EBADR EBADR // invalid request descriptor -#define EXFULL EXFULL // exchange full -#define ENOANO ENOANO // no anode -#define EBADRQC EBADRQC // invalid request code -#define EBADSLT EBADSLT // invalid slot -#define ENOSTR ENOSTR // no string -#define ENODATA ENODATA // no data -#define ETIME ETIME // timer expired -#define ENOSR ENOSR // out of streams resources -#define ENONET ENONET // no network -#define ENOPKG ENOPKG // package not installed -#define EREMOTE EREMOTE // object is remote -#define ENOLINK ENOLINK // link severed -#define EADV EADV // todo -#define ESRMNT ESRMNT // todo -#define ECOMM ECOMM // communication error on send -#define EPROTO EPROTO // protocol error -#define EMULTIHOP EMULTIHOP // multihop attempted -#define EDOTDOT EDOTDOT // todo -#define EBADMSG EBADMSG // bad message -#define EOVERFLOW EOVERFLOW // value too large for type -#define ENOTUNIQ ENOTUNIQ // name not unique on network -#define EBADFD EBADFD // fd in bad *state* (cf. EBADF) -#define EREMCHG EREMCHG // remote address changed -#define ELIBACC ELIBACC // cannot access dso -#define ELIBBAD ELIBBAD // corrupted shared library -#define ELIBSCN ELIBSCN // a.out section corrupted -#define ELIBMAX ELIBMAX // too many shared libraries -#define ELIBEXEC ELIBEXEC // cannot exec a dso directly -#define EILSEQ EILSEQ // invalid wide character -#define ERESTART ERESTART // please restart syscall -#define ESTRPIPE ESTRPIPE // streams pipe error -#define EUSERS EUSERS // too many users -#define ENOTSOCK ENOTSOCK // not a socket -#define EDESTADDRREQ EDESTADDRREQ // dest address needed -#define EMSGSIZE EMSGSIZE // message too long -#define EPROTOTYPE EPROTOTYPE // protocol wrong for socket -#define ENOPROTOOPT ENOPROTOOPT // protocol not available -#define EPROTONOSUPPORT EPROTONOSUPPORT // protocol not supported -#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT // socket type not supported -#define EOPNOTSUPP EOPNOTSUPP // operation not supported on socket -#define EPFNOSUPPORT EPFNOSUPPORT // protocol family not supported -#define EAFNOSUPPORT EAFNOSUPPORT // address family not supported -#define EADDRINUSE EADDRINUSE // address already in use -#define EADDRNOTAVAIL EADDRNOTAVAIL // address not available -#define ENETDOWN ENETDOWN // network is down -#define ENETUNREACH ENETUNREACH // network unreachable -#define ENETRESET ENETRESET // connection aborted by network -#define ECONNABORTED ECONNABORTED // connection aborted -#define ECONNRESET ECONNRESET // connection reset -#define ENOBUFS ENOBUFS // no buffer space available -#define EISCONN EISCONN // socket is connected -#define ENOTCONN ENOTCONN // the socket is not connected -#define ESHUTDOWN ESHUTDOWN // no send after endpoint shutdown -#define ETOOMANYREFS ETOOMANYREFS // too many refs -#define ETIMEDOUT ETIMEDOUT // connection timed out -#define ECONNREFUSED ECONNREFUSED // connection refused -#define EHOSTDOWN EHOSTDOWN // host is down -#define EHOSTUNREACH EHOSTUNREACH // host is unreachable -#define EALREADY EALREADY // connection already in progress -#define EINPROGRESS EINPROGRESS // operation in progress -#define ESTALE ESTALE // stale file handle -#define EUCLEAN EUCLEAN // structure needs cleaning -#define ENOTNAM ENOTNAM // todo -#define ENAVAIL ENAVAIL // todo -#define EISNAM EISNAM // is a named type file -#define EREMOTEIO EREMOTEIO // remote i/o error -#define EDQUOT EDQUOT // disk quota exceeded -#define ENOMEDIUM ENOMEDIUM // no medium found -#define EMEDIUMTYPE EMEDIUMTYPE // wrong medium type -#define ECANCELED ECANCELED // operation canceled -#define ENOKEY ENOKEY // required key not available -#define EKEYEXPIRED EKEYEXPIRED // key has expired -#define EKEYREVOKED EKEYREVOKED // key has been revoked -#define EKEYREJECTED EKEYREJECTED // key was rejected by service -#define EOWNERDEAD EOWNERDEAD // owner died -#define ENOTRECOVERABLE ENOTRECOVERABLE // state not recoverable -#define ERFKILL ERFKILL // can't op b/c RF-kill -#define EHWPOISON EHWPOISON // mempage has h/w error -#define EWOULDBLOCK EAGAIN // poll fd and try again +#define EPERM EPERM /* operation not permitted */ +#define ENOENT ENOENT /* no such file or directory */ +#define ESRCH ESRCH /* no such process */ +#define EINTR EINTR /* interrupted system call */ +#define EIO EIO /* input/output error */ +#define ENXIO ENXIO /* no such device or address */ +#define E2BIG E2BIG /* argument list too long */ +#define ENOEXEC ENOEXEC /* exec format error */ +#define EBADF EBADF /* bad file descriptor */ +#define ECHILD ECHILD /* no child processes */ +#define EAGAIN EAGAIN /* resource temporarily unavailable */ +#define ENOMEM ENOMEM /* not enough space */ +#define EACCES EACCES /* permission denied */ +#define EFAULT EFAULT /* bad address */ +#define ENOTBLK ENOTBLK /* block device required */ +#define EBUSY EBUSY /* device or resource busy */ +#define EEXIST EEXIST /* file exists */ +#define EXDEV EXDEV /* improper link */ +#define ENODEV ENODEV /* no such device */ +#define ENOTDIR ENOTDIR /* not a directory */ +#define EISDIR EISDIR /* is a directory */ +#define EINVAL EINVAL /* invalid argument */ +#define ENFILE ENFILE /* too many open files in system */ +#define EMFILE EMFILE /* too many open files */ +#define ENOTTY ENOTTY /* inappropriate I/O control op */ +#define ETXTBSY ETXTBSY /* text file busy */ +#define EFBIG EFBIG /* file too large */ +#define ENOSPC ENOSPC /* no space left on device */ +#define ESPIPE ESPIPE /* invalid seek */ +#define EROFS EROFS /* read-only filesystem */ +#define EMLINK EMLINK /* too many links */ +#define EPIPE EPIPE /* broken pipe */ +#define EDOM EDOM /* argument out of function domain */ +#define ERANGE ERANGE /* result too large */ +#define EDEADLK EDEADLK /* resource deadlock avoided */ +#define ENAMETOOLONG ENAMETOOLONG /* filename too long */ +#define ENOLCK ENOLCK /* no locks available */ +#define ENOSYS ENOSYS /* system call not implemented */ +#define ENOTEMPTY ENOTEMPTY /* directory not empty */ +#define ELOOP ELOOP /* too many levels of symbolic links */ +#define ENOMSG ENOMSG /* no message of the desired type */ +#define EIDRM EIDRM /* identifier removed */ +#define ECHRNG ECHRNG /* channel number out of range */ +#define EL2NSYNC EL2NSYNC /* level 2 not synchronized */ +#define EL3HLT EL3HLT /* level 3 halted */ +#define EL3RST EL3RST /* level 3 halted */ +#define ELNRNG ELNRNG /* link number out of range */ +#define EUNATCH EUNATCH /* protocol driver not attached */ +#define ENOCSI ENOCSI /* no csi structure available */ +#define EL2HLT EL2HLT /* level 2 halted */ +#define EBADE EBADE /* invalid exchange */ +#define EBADR EBADR /* invalid request descriptor */ +#define EXFULL EXFULL /* exchange full */ +#define ENOANO ENOANO /* no anode */ +#define EBADRQC EBADRQC /* invalid request code */ +#define EBADSLT EBADSLT /* invalid slot */ +#define ENOSTR ENOSTR /* no string */ +#define ENODATA ENODATA /* no data */ +#define ETIME ETIME /* timer expired */ +#define ENOSR ENOSR /* out of streams resources */ +#define ENONET ENONET /* no network */ +#define ENOPKG ENOPKG /* package not installed */ +#define EREMOTE EREMOTE /* object is remote */ +#define ENOLINK ENOLINK /* link severed */ +#define EADV EADV /* todo */ +#define ESRMNT ESRMNT /* todo */ +#define ECOMM ECOMM /* communication error on send */ +#define EPROTO EPROTO /* protocol error */ +#define EMULTIHOP EMULTIHOP /* multihop attempted */ +#define EDOTDOT EDOTDOT /* todo */ +#define EBADMSG EBADMSG /* bad message */ +#define EOVERFLOW EOVERFLOW /* value too large for type */ +#define ENOTUNIQ ENOTUNIQ /* name not unique on network */ +#define EBADFD EBADFD /* fd in bad *state* (cf. EBADF) */ +#define EREMCHG EREMCHG /* remote address changed */ +#define ELIBACC ELIBACC /* cannot access dso */ +#define ELIBBAD ELIBBAD /* corrupted shared library */ +#define ELIBSCN ELIBSCN /* a.out section corrupted */ +#define ELIBMAX ELIBMAX /* too many shared libraries */ +#define ELIBEXEC ELIBEXEC /* cannot exec a dso directly */ +#define EILSEQ EILSEQ /* invalid wide character */ +#define ERESTART ERESTART /* please restart syscall */ +#define ESTRPIPE ESTRPIPE /* streams pipe error */ +#define EUSERS EUSERS /* too many users */ +#define ENOTSOCK ENOTSOCK /* not a socket */ +#define EDESTADDRREQ EDESTADDRREQ /* dest address needed */ +#define EMSGSIZE EMSGSIZE /* message too long */ +#define EPROTOTYPE EPROTOTYPE /* protocol wrong for socket */ +#define ENOPROTOOPT ENOPROTOOPT /* protocol not available */ +#define EPROTONOSUPPORT EPROTONOSUPPORT /* protocol not supported */ +#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT /* socket type not supported */ +#define EOPNOTSUPP EOPNOTSUPP /* operation not supported on socket */ +#define EPFNOSUPPORT EPFNOSUPPORT /* protocol family not supported */ +#define EAFNOSUPPORT EAFNOSUPPORT /* address family not supported */ +#define EADDRINUSE EADDRINUSE /* address already in use */ +#define EADDRNOTAVAIL EADDRNOTAVAIL /* address not available */ +#define ENETDOWN ENETDOWN /* network is down */ +#define ENETUNREACH ENETUNREACH /* network unreachable */ +#define ENETRESET ENETRESET /* connection aborted by network */ +#define ECONNABORTED ECONNABORTED /* connection aborted */ +#define ECONNRESET ECONNRESET /* connection reset */ +#define ENOBUFS ENOBUFS /* no buffer space available */ +#define EISCONN EISCONN /* socket is connected */ +#define ENOTCONN ENOTCONN /* the socket is not connected */ +#define ESHUTDOWN ESHUTDOWN /* no send after endpoint shutdown */ +#define ETOOMANYREFS ETOOMANYREFS /* too many refs */ +#define ETIMEDOUT ETIMEDOUT /* connection timed out */ +#define ECONNREFUSED ECONNREFUSED /* connection refused */ +#define EHOSTDOWN EHOSTDOWN /* host is down */ +#define EHOSTUNREACH EHOSTUNREACH /* host is unreachable */ +#define EALREADY EALREADY /* connection already in progress */ +#define EINPROGRESS EINPROGRESS /* operation in progress */ +#define ESTALE ESTALE /* stale file handle */ +#define EUCLEAN EUCLEAN /* structure needs cleaning */ +#define ENOTNAM ENOTNAM /* todo */ +#define ENAVAIL ENAVAIL /* todo */ +#define EISNAM EISNAM /* is a named type file */ +#define EREMOTEIO EREMOTEIO /* remote i/o error */ +#define EDQUOT EDQUOT /* disk quota exceeded */ +#define ENOMEDIUM ENOMEDIUM /* no medium found */ +#define EMEDIUMTYPE EMEDIUMTYPE /* wrong medium type */ +#define ECANCELED ECANCELED /* operation canceled */ +#define ENOKEY ENOKEY /* required key not available */ +#define EKEYEXPIRED EKEYEXPIRED /* key has expired */ +#define EKEYREVOKED EKEYREVOKED /* key has been revoked */ +#define EKEYREJECTED EKEYREJECTED /* key was rejected by service */ +#define EOWNERDEAD EOWNERDEAD /* owner died */ +#define ENOTRECOVERABLE ENOTRECOVERABLE /* state not recoverable */ +#define ERFKILL ERFKILL /* can't op b/c RF-kill */ +#define EHWPOISON EHWPOISON /* mempage has h/w error */ +#define EWOULDBLOCK EAGAIN /* poll fd and try again */ #define ENOTSUP ENOTSUP #if !(__ASSEMBLER__ + __LINKER__ + 0) diff --git a/libc/fmt/fmt.h b/libc/fmt/fmt.h index 4733e36f7..8cbbb62dd 100644 --- a/libc/fmt/fmt.h +++ b/libc/fmt/fmt.h @@ -26,7 +26,6 @@ int sscanf(const char *, const char *, ...) scanfesque(2); int vsscanf(const char *, const char *, va_list); int vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *, va_list); -char *strerror(int) returnsnonnull nothrow nocallback; int strerror_r(int, char *, size_t) nothrow nocallback; int palandprintf(void *, void *, const char *, va_list) hidden; char *itoa(int, char *, int) compatfn; diff --git a/libc/fmt/leb128.h b/libc/fmt/leb128.h index 13e4ebeb9..8550c9677 100644 --- a/libc/fmt/leb128.h +++ b/libc/fmt/leb128.h @@ -3,8 +3,10 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +#ifndef __STRICT_ANSI__ int sleb128(const void *, size_t, int128_t); int unsleb128(const void *, size_t, int128_t *); +#endif /* ANSI */ COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/fmt/pflink.h b/libc/fmt/pflink.h index 0d1021515..1c7ca5249 100644 --- a/libc/fmt/pflink.h +++ b/libc/fmt/pflink.h @@ -61,23 +61,44 @@ */ #pragma GCC diagnostic ignored "-Wformat-security" #endif /* __GNUC__ + 0 < 6 */ - #else #define PFLINK(FMT) FMT #define SFLINK(FMT) FMT -asm(".section .yoink\n\t" - "nop\tntoa(%rip)\n\t" - "nop\tftoa(%rip)\n\t" - "nop\tkCp437(%rip)\n\t" - "nop\tstrerror(%rip)\n\t" - "nop\tstrnwidth(%rip)\n\t" - "nop\tstrnwidth16(%rip)\n\t" - "nop\twcsnwidth(%rip)\n\t" - "nop\tmalloc(%rip)\n\t" - "nop\tcalloc(%rip)\n\t" - "nop\tfree_s(%rip)\n\t" - "nop\t__grow(%rip)\n\t" - ".previous"); +#ifdef __GNUC__ +__asm__(".section .yoink\n\t" + "nop\tntoa(%rip)\n\t" + "nop\tftoa(%rip)\n\t" + "nop\tkCp437(%rip)\n\t" + "nop\tstrerror(%rip)\n\t" + "nop\tstrnwidth(%rip)\n\t" + "nop\tstrnwidth16(%rip)\n\t" + "nop\twcsnwidth(%rip)\n\t" + "nop\tmalloc(%rip)\n\t" + "nop\tcalloc(%rip)\n\t" + "nop\tfree_s(%rip)\n\t" + "nop\t__grow(%rip)\n\t" + ".previous"); +#else +#include "libc/fmt/palandprintf.internal.h" +#include "libc/mem/mem.h" +#include "libc/runtime/runtime.h" +#include "libc/str/str.h" +#include "libc/unicode/unicode.h" +static long __pflink(long x) { + x |= kCp437[0]; + x |= ntoa(0, 0, 0, 0, 0, 0, 0, 0, 0); + x |= ftoa(0, 0, 0, 0, 0, 0); + x |= strnwidth(0, 0); + x |= strnwidth16(0, 0); + x |= wcsnwidth(0, 0); + x |= malloc(0); + x |= __grow(0, 0, 0, 0); + x |= (intptr_t)strerror(0); + x |= (intptr_t)calloc(0, 0); + free_s(0); + return x; +} +#endif #endif /* __STRICT_ANSI__ */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_FMT_PFLINK_H_ */ diff --git a/libc/integral/c.inc b/libc/integral/c.inc index 9978f3e85..b4347d57a 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -10,10 +10,6 @@ #define COSMOPOLITAN_CXX_USING_ #endif -#ifdef __STRICT_ANSI__ -#define asm __asm__ -#endif - #ifndef __ia16__ #define __far #endif @@ -605,7 +601,13 @@ typedef uint64_t uintmax_t; #endif #ifndef unreachable +#if defined(__GNUC__) && !defined(__STRICT_ANSI) #define unreachable __builtin_unreachable() +#else +#define unreachable \ + do { \ + } while (1) +#endif #endif #define donothing \ @@ -758,30 +760,45 @@ typedef uint64_t uintmax_t; #endif /* ANSI */ #endif /* -w */ +#ifndef __STRICT_ANSI__ #define DebugBreak() asm("int3") +#else +#define DebugBreak() (void)0 +#endif -#ifndef VEIL +#ifndef __STRICT_ANSI__ #define VEIL(CONSTRAINT, EXPRESSION) \ ({ \ autotype(EXPRESSION) VeiledValue = (EXPRESSION); \ asm("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \ VeiledValue; \ }) -#endif /* VEIL */ +#else +#define VEIL(CONSTRAINT, EXPRESSION) (EXPRESSION) +#endif +#ifndef __STRICT_ANSI__ #define CONCEAL(CONSTRAINT, EXPRESSION) \ ({ \ autotype(EXPRESSION) VeiledValue = (EXPRESSION); \ asm volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \ VeiledValue; \ }) +#else +#define CONCEAL(CONSTRAINT, EXPRESSION) (EXPRESSION) +#endif +#ifndef __STRICT_ANSI__ #define EXPROPRIATE(EXPRESSION) \ ({ \ asm volatile("" ::"g"(EXPRESSION) : "memory"); \ 0; \ }) +#else +#define EXPROPRIATE(EXPRESSION) (EXPRESSION) +#endif +#ifndef __STRICT_ANSI__ #define YOINK(SYMBOL) \ do { \ _Static_assert(!__builtin_types_compatible_p(typeof(SYMBOL), char[]), \ @@ -792,11 +809,18 @@ typedef uint64_t uintmax_t; : /* no outputs */ \ : "X"(SYMBOL)); \ } while (0) +#else +#define YOINK(SYMBOL) (void)0 +#endif +#ifndef __STRICT_ANSI__ #define STATIC_YOINK(SYMBOLSTR) \ asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous") +#else +#define STATIC_YOINK(SYMBOLSTR) +#endif -#if !defined(IM_FEELING_NAUGHTY) && !defined(__STRICT_ANSI__) +#if !defined(IM_FEELING_NAUGHTY) #define STATIC_YOINK_SOURCE(PATH) STATIC_YOINK(PATH) #else #define STATIC_YOINK_SOURCE(PATH) diff --git a/libc/integral/normalize.inc b/libc/integral/normalize.inc index d704d4e19..22026bbcc 100644 --- a/libc/integral/normalize.inc +++ b/libc/integral/normalize.inc @@ -34,6 +34,13 @@ #define __x86__ 1 #endif +#ifdef _MSC_VER +#define __STRICT_ANSI__ +#ifndef __STDC__ +#define __STDC__ +#endif +#endif + #ifndef __has_attribute #define __has_attribute(x) 0 #endif diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index e9c604c58..3d029d2dd 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/alg/reverse.h" #include "libc/bits/bits.h" +#include "libc/bits/likely.h" #include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/dce.h" @@ -76,12 +77,11 @@ STATIC_YOINK("_init_asan"); } \ } while (0) -#define REQUIRE(FUNC) \ - do { \ - if (!weaken(FUNC)) { \ - __asan_write_string("asan needs " #FUNC "\n"); \ - __asan_exit(100); \ - } \ +#define REQUIRE(FUNC) \ + do { \ + if (!weaken(FUNC)) { \ + __asan_die("error: asan needs " #FUNC "\n"); \ + } \ } while (0) struct AsanSourceLocation { @@ -325,7 +325,7 @@ void __asan_poison(uintptr_t p, size_t n, int kind) { int k; char *s; if (!n) return; - if (p & 7) { + if (UNLIKELY(p & 7)) { k = MIN(8 - (p & 7), n); s = SHADOW(p); if (*s == 0 || *s > (p & 7)) { @@ -347,7 +347,7 @@ void __asan_unpoison(uintptr_t p, size_t n) { int k; char *s; if (!n) return; - if (p & 7) { + if (UNLIKELY(p & 7)) { k = MIN(8 - (p & 7), n); s = SHADOW(p); *s = 0; @@ -447,7 +447,6 @@ static ssize_t __asan_write_string(const char *s) { static wontreturn void __asan_abort(void) { if (weaken(__die)) weaken(__die)(); - if (weaken(abort)) weaken(abort)(); __asan_exit(134); } @@ -752,7 +751,7 @@ void __asan_map_shadow(uintptr_t p, size_t n) { weaken(TrackMemoryInterval)( m, a, a, sm.maphandle, PROT_READ | PROT_WRITE, MAP_PRIVATE | *weaken(MAP_ANONYMOUS) | MAP_FIXED) == -1) { - __asan_abort(); + __asan_die("error: could not map asan shadow memory\n"); } __asan_repstosb((void *)((uintptr_t)a << 16), kAsanUnmapped, 1 << 16); } diff --git a/libc/log/gdb.h b/libc/log/gdb.h index 09dcf87ac..0eccb440e 100644 --- a/libc/log/gdb.h +++ b/libc/log/gdb.h @@ -51,7 +51,7 @@ int attachdebugger(intptr_t); "d"(OPTIONS), "g"(OPT_OUT_RUSAGE) \ : "rcx", "r10", "r11", "cc", "memory"); \ } else { \ - WaAx = wait4$nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \ + WaAx = sys_wait4_nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \ } \ WaAx; \ }) diff --git a/libc/log/logerrno.c b/libc/log/logerrno.c index 5a0b015df..450ebb32f 100644 --- a/libc/log/logerrno.c +++ b/libc/log/logerrno.c @@ -20,6 +20,7 @@ #include "libc/fmt/fmt.h" #include "libc/log/log.h" #include "libc/stdio/stdio.h" +#include "libc/str/str.h" void __logerrno(const char *file, int line, const char *form) { flogf(kLogWarn, file, line, NULL, PFLINK("%s → %s"), form, strerror(errno)); diff --git a/libc/log/perror.c b/libc/log/perror.c index 7523a2cda..e8ea6e21e 100644 --- a/libc/log/perror.c +++ b/libc/log/perror.c @@ -22,6 +22,7 @@ #include "libc/log/log.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" +#include "libc/str/str.h" /** * Writes error messages to standard error. diff --git a/libc/mem/asprintf.c b/libc/mem/asprintf.c index 2615d63a9..5d20342d0 100644 --- a/libc/mem/asprintf.c +++ b/libc/mem/asprintf.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/mem.h" +#include "libc/mem/fmt.h" /** * Formats string, allocating needed memory. diff --git a/libc/mem/fmt.h b/libc/mem/fmt.h new file mode 100644 index 000000000..1351d4885 --- /dev/null +++ b/libc/mem/fmt.h @@ -0,0 +1,18 @@ +#ifndef COSMOPOLITAN_LIBC_MEM_FMT_H_ +#define COSMOPOLITAN_LIBC_MEM_FMT_H_ +#include "libc/fmt/pflink.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int asprintf(char **, const char *, ...) printfesque(2) + paramsnonnull((1, 2)) libcesque; +int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque; + +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) +#define asprintf(SP, FMT, ...) (asprintf)(SP, PFLINK(FMT), ##__VA_ARGS__) +#define vasprintf(SP, FMT, VA) (vasprintf)(SP, PFLINK(FMT), VA) +#endif + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_MEM_FMT_H_ */ diff --git a/libc/mem/mem.h b/libc/mem/mem.h index 5f14d0c62..d7b12dc35 100644 --- a/libc/mem/mem.h +++ b/libc/mem/mem.h @@ -1,6 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_MEM_MEM_H_ #define COSMOPOLITAN_LIBC_MEM_MEM_H_ -#include "libc/fmt/pflink.h" #define M_TRIM_THRESHOLD (-1) #define M_GRANULARITY (-2) @@ -34,10 +33,6 @@ size_t malloc_usable_size(const void *); void **independent_calloc(size_t, size_t, void **); void **independent_comalloc(size_t, size_t *, void **); -int asprintf(char **, const char *, ...) printfesque(2) - paramsnonnull((1, 2)) libcesque; -int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque; - wchar_t *wcsdup(const wchar_t *) strlenesque nodiscard; struct mallinfo { @@ -63,15 +58,6 @@ size_t malloc_set_footprint_limit(size_t); void malloc_inspect_all(void (*handler)(void *, void *, size_t, void *), void *); -/*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § dynamic memory » optimizations ─╬─│┼ -╚────────────────────────────────────────────────────────────────────────────│*/ - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#define asprintf(SP, FMT, ...) (asprintf)(SP, PFLINK(FMT), ##__VA_ARGS__) -#define vasprintf(SP, FMT, VA) (vasprintf)(SP, PFLINK(FMT), VA) -#endif - COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_MEM_MEM_H_ */ diff --git a/libc/nexgen32e/lolendian.S b/libc/nexgen32e/lolendian.S index 24cf64819..0a53fde7e 100644 --- a/libc/nexgen32e/lolendian.S +++ b/libc/nexgen32e/lolendian.S @@ -26,8 +26,8 @@ / To protect their legacy, all 19 functions have been implemented / in just 17 bytes. / +/ @see READ32LE(), READ32BE(), etc. / @asyncsignalsafe -/ @see read32le(), read32be(), etc. bswap_64: htobe64: diff --git a/libc/nexgen32e/lz4.h b/libc/nexgen32e/lz4.h index ef2f1c0be..ea3beb7da 100644 --- a/libc/nexgen32e/lz4.h +++ b/libc/nexgen32e/lz4.h @@ -27,7 +27,7 @@ COSMOPOLITAN_C_START_ │ cosmopolitan § lz4 » frames ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -#define LZ4_MAGIC(FRAME) read32le(FRAME) +#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) @@ -40,10 +40,10 @@ COSMOPOLITAN_C_START_ #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) + (LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? READ64LE((FRAME) + 4 + 1 + 1) : 0) #define LZ4_FRAME_DICTIONARYID(FRAME) \ (LZ4_FRAME_DICTIONARYIDFLAG(FRAME) \ - ? read32le(((FRAME) + 4 + 1 + 1 + \ + ? READ32LE(((FRAME) + 4 + 1 + 1 + \ 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME))) \ : 0) #define LZ4_FRAME_HEADERCHECKSUM(FRAME) \ @@ -60,9 +60,9 @@ COSMOPOLITAN_C_START_ ╚────────────────────────────────────────────────────────────────────────────│*/ #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_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) + \ (LZ4_FRAME_BLOCKCHECKSUMFLAG(frame) ? sizeof(uint8_t) : 0)) diff --git a/libc/nt/KernelBase/time.s b/libc/nt/KernelBase/time.s deleted file mode 100644 index 9eef0252b..000000000 --- a/libc/nt/KernelBase/time.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_time,time,1865 diff --git a/libc/nt/KernelBase/wprintf.s b/libc/nt/KernelBase/wprintf.s deleted file mode 100644 index 3a0966d4c..000000000 --- a/libc/nt/KernelBase/wprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_wprintf,wprintf,1866 diff --git a/libc/nt/gdi32/vSetPldc.s b/libc/nt/gdi32/vSetPldc.s deleted file mode 100644 index b246449e7..000000000 --- a/libc/nt/gdi32/vSetPldc.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp gdi32,__imp_vSetPldc,vSetPldc,1966 diff --git a/libc/nt/kernel32/lstrcatA.s b/libc/nt/kernel32/lstrcatA.s deleted file mode 100644 index 69039a38d..000000000 --- a/libc/nt/kernel32/lstrcatA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcatA,lstrcatA,1592 diff --git a/libc/nt/kernel32/lstrcatW.s b/libc/nt/kernel32/lstrcatW.s deleted file mode 100644 index 5a541e075..000000000 --- a/libc/nt/kernel32/lstrcatW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcatW,lstrcatW,1593 diff --git a/libc/nt/kernel32/lstrcmpA.s b/libc/nt/kernel32/lstrcmpA.s deleted file mode 100644 index 00c9584e5..000000000 --- a/libc/nt/kernel32/lstrcmpA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcmpA,lstrcmpA,0 diff --git a/libc/nt/kernel32/lstrcmpW.s b/libc/nt/kernel32/lstrcmpW.s deleted file mode 100644 index e99ec473a..000000000 --- a/libc/nt/kernel32/lstrcmpW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcmpW,lstrcmpW,0 diff --git a/libc/nt/kernel32/lstrcmpiA.s b/libc/nt/kernel32/lstrcmpiA.s deleted file mode 100644 index e26758124..000000000 --- a/libc/nt/kernel32/lstrcmpiA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcmpiA,lstrcmpiA,0 diff --git a/libc/nt/kernel32/lstrcmpiW.s b/libc/nt/kernel32/lstrcmpiW.s deleted file mode 100644 index 54d49e9b2..000000000 --- a/libc/nt/kernel32/lstrcmpiW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcmpiW,lstrcmpiW,0 diff --git a/libc/nt/kernel32/lstrcpyA.s b/libc/nt/kernel32/lstrcpyA.s deleted file mode 100644 index 61e877d2c..000000000 --- a/libc/nt/kernel32/lstrcpyA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcpyA,lstrcpyA,1601 diff --git a/libc/nt/kernel32/lstrcpyW.s b/libc/nt/kernel32/lstrcpyW.s deleted file mode 100644 index 0a1f0d751..000000000 --- a/libc/nt/kernel32/lstrcpyW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcpyW,lstrcpyW,1602 diff --git a/libc/nt/kernel32/lstrcpynA.s b/libc/nt/kernel32/lstrcpynA.s deleted file mode 100644 index 8eb89acee..000000000 --- a/libc/nt/kernel32/lstrcpynA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcpynA,lstrcpynA,0 diff --git a/libc/nt/kernel32/lstrcpynW.s b/libc/nt/kernel32/lstrcpynW.s deleted file mode 100644 index 7d068e41c..000000000 --- a/libc/nt/kernel32/lstrcpynW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrcpynW,lstrcpynW,0 diff --git a/libc/nt/kernel32/lstrlenA.s b/libc/nt/kernel32/lstrlenA.s deleted file mode 100644 index 7e48aab7e..000000000 --- a/libc/nt/kernel32/lstrlenA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrlenA,lstrlenA,0 diff --git a/libc/nt/kernel32/lstrlenW.s b/libc/nt/kernel32/lstrlenW.s deleted file mode 100644 index a7ab48262..000000000 --- a/libc/nt/kernel32/lstrlenW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_lstrlenW,lstrlenW,0 diff --git a/libc/nt/kernel32/uaw_lstrcmpW.s b/libc/nt/kernel32/uaw_lstrcmpW.s deleted file mode 100644 index 807501a42..000000000 --- a/libc/nt/kernel32/uaw_lstrcmpW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_uaw_lstrcmpW,uaw_lstrcmpW,1614 diff --git a/libc/nt/kernel32/uaw_lstrcmpiW.s b/libc/nt/kernel32/uaw_lstrcmpiW.s deleted file mode 100644 index 5a894917e..000000000 --- a/libc/nt/kernel32/uaw_lstrcmpiW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_uaw_lstrcmpiW,uaw_lstrcmpiW,1615 diff --git a/libc/nt/kernel32/uaw_lstrlenW.s b/libc/nt/kernel32/uaw_lstrlenW.s deleted file mode 100644 index da7f470dd..000000000 --- a/libc/nt/kernel32/uaw_lstrlenW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_uaw_lstrlenW,uaw_lstrlenW,1616 diff --git a/libc/nt/kernel32/uaw_wcschr.s b/libc/nt/kernel32/uaw_wcschr.s deleted file mode 100644 index 888a7421d..000000000 --- a/libc/nt/kernel32/uaw_wcschr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_uaw_wcschr,uaw_wcschr,1617 diff --git a/libc/nt/kernel32/uaw_wcscpy.s b/libc/nt/kernel32/uaw_wcscpy.s deleted file mode 100644 index 4eae5f314..000000000 --- a/libc/nt/kernel32/uaw_wcscpy.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_uaw_wcscpy,uaw_wcscpy,1618 diff --git a/libc/nt/kernel32/uaw_wcsicmp.s b/libc/nt/kernel32/uaw_wcsicmp.s deleted file mode 100644 index e58af7050..000000000 --- a/libc/nt/kernel32/uaw_wcsicmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_uaw_wcsicmp,uaw_wcsicmp,1619 diff --git a/libc/nt/kernel32/uaw_wcslen.s b/libc/nt/kernel32/uaw_wcslen.s deleted file mode 100644 index daca04a43..000000000 --- a/libc/nt/kernel32/uaw_wcslen.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_uaw_wcslen,uaw_wcslen,1620 diff --git a/libc/nt/kernel32/uaw_wcsrchr.s b/libc/nt/kernel32/uaw_wcsrchr.s deleted file mode 100644 index e42fbf951..000000000 --- a/libc/nt/kernel32/uaw_wcsrchr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_uaw_wcsrchr,uaw_wcsrchr,1621 diff --git a/libc/nt/master.sh b/libc/nt/master.sh index eab157802..e98dc6f03 100755 --- a/libc/nt/master.sh +++ b/libc/nt/master.sh @@ -22,9 +22,6 @@ # » so many sections # # Name Actual DLL Hint Arity -imp 'A_SHAInit' A_SHAInit ntdll 10 -imp 'A_SHAUpdate' A_SHAUpdate ntdll 11 -imp 'A_SHAFinal' A_SHAFinal ntdll 9 imp 'AbortDoc' AbortDoc gdi32 1011 imp 'AbortPath' AbortPath gdi32 1012 imp 'AbortSystemShutdownA' AbortSystemShutdownA advapi32 1005 @@ -2973,7 +2970,7 @@ imp 'IsChild' IsChild user32 2059 2 imp 'IsClipboardFormatAvailable' IsClipboardFormatAvailable user32 2060 imp 'IsDBCSLeadByte' IsDBCSLeadByte kernel32 0 # KernelBase imp 'IsDBCSLeadByteEx' IsDBCSLeadByteEx kernel32 0 # KernelBase -imp 'IsDebuggerPresent$nt' IsDebuggerPresent KernelBase 903 +imp 'sys_IsDebuggerPresent_nt' IsDebuggerPresent KernelBase 903 imp 'IsDesktopExplorerProcess' IsDesktopExplorerProcess shell32 942 imp 'IsDeveloperModeEnabled' IsDeveloperModeEnabled KernelBase 904 imp 'IsDeveloperModePolicyApplied' IsDeveloperModePolicyApplied KernelBase 905 @@ -3340,9 +3337,6 @@ imp 'MB_GetString' MB_GetString user32 2127 imp 'MD4Final' MD4Final ntdll 188 imp 'MD4Init' MD4Init ntdll 189 imp 'MD4Update' MD4Update ntdll 190 -imp 'MD5Final$nt' MD5Final ntdll 191 -imp 'MD5Init$nt' MD5Init ntdll 192 -imp 'MD5Update$nt' MD5Update ntdll 193 imp 'MIDL_user_free_Ext' MIDL_user_free_Ext advapi32 1507 imp 'MIMEAssociationDialogA' MIMEAssociationDialogA url 107 imp 'MIMEAssociationDialog' MIMEAssociationDialogW url 108 @@ -7684,21 +7678,13 @@ imp '_atoi64' _atoi64 ntdll 2180 imp '_c_exit' _c_exit KernelBase 1839 imp '_cexit' _cexit KernelBase 1840 imp '_errno' _errno ntdll 2181 -imp '_exit$nt' _exit KernelBase 1841 +imp 'sys__exit_nt' _exit KernelBase 1841 imp '_fltused' _fltused ntdll 2182 imp '_hread' _hread kernel32 1582 imp '_hwrite' _hwrite kernel32 1583 -imp '_i64toa' _i64toa ntdll 2183 -imp '_i64toa_s' _i64toa_s ntdll 2184 -imp '_i64tow' _i64tow ntdll 2185 -imp '_i64tow_s' _i64tow_s ntdll 2186 imp '_initterm' _initterm KernelBase 1842 imp '_initterm_e' _initterm_e KernelBase 1843 imp '_invalid_parameter' _invalid_parameter KernelBase 1844 -imp '_itoa' _itoa ntdll 2187 -imp '_itoa_s' _itoa_s ntdll 2188 -imp '_itow' _itow ntdll 2189 -imp '_itow_s' _itow_s ntdll 2190 imp '_lclose' _lclose kernel32 1584 imp '_lcreat' _lcreat kernel32 1585 imp '_lfind' _lfind ntdll 2191 @@ -7706,269 +7692,95 @@ imp '_llseek' _llseek kernel32 1586 imp '_local_unwind' _local_unwind ntdll 2192 imp '_lopen' _lopen kernel32 1588 imp '_lread' _lread kernel32 1589 -imp '_ltoa' _ltoa ntdll 2193 -imp '_ltoa_s' _ltoa_s ntdll 2194 -imp '_ltow' _ltow ntdll 2195 -imp '_ltow_s' _ltow_s ntdll 2196 imp '_lwrite' _lwrite kernel32 1590 imp '_makepath_s' _makepath_s ntdll 2197 imp '_memccpy' _memccpy ntdll 2198 imp '_memicmp' _memicmp ntdll 2199 imp '_onexit' _onexit KernelBase 1846 imp '_purecall' _purecall KernelBase 1847 -imp '_setjmp$nt' _setjmp ntdll 2200 +imp 'sys__setjmp_nt' _setjmp ntdll 2200 imp '_setjmpex' _setjmpex ntdll 2201 -imp '_snprintf' _snprintf ntdll 2202 -imp '_snprintf_s' _snprintf_s ntdll 2203 -imp '_snscanf_s' _snscanf_s ntdll 2204 -imp '_snwprintf' _snwprintf ntdll 2205 -imp '_snwprintf_s' _snwprintf_s ntdll 2206 -imp '_snwscanf_s' _snwscanf_s ntdll 2207 -imp '_splitpath' _splitpath ntdll 2208 -imp '_splitpath_s' _splitpath_s ntdll 2209 -imp '_strcmpi' _strcmpi ntdll 2210 -imp '_stricmp' _stricmp ntdll 2211 -imp '_strlwr' _strlwr ntdll 2212 -imp '_strlwr_s' _strlwr_s ntdll 2213 -imp '_strnicmp' _strnicmp ntdll 2214 -imp '_strnset_s' _strnset_s ntdll 2215 -imp '_strset_s' _strset_s ntdll 2216 -imp '_strupr' _strupr ntdll 2217 -imp '_strupr_s' _strupr_s ntdll 2218 -imp '_swprintf' _swprintf ntdll 2219 imp '_time64' _time64 KernelBase 1848 -imp '_ui64toa' _ui64toa ntdll 2220 -imp '_ui64toa_s' _ui64toa_s ntdll 2221 -imp '_ui64tow' _ui64tow ntdll 2222 -imp '_ui64tow_s' _ui64tow_s ntdll 2223 -imp '_ultoa' _ultoa ntdll 2224 -imp '_ultoa_s' _ultoa_s ntdll 2225 -imp '_ultow' _ultow ntdll 2226 -imp '_ultow_s' _ultow_s ntdll 2227 -imp '_vscprintf' _vscprintf ntdll 2228 -imp '_vscwprintf' _vscwprintf ntdll 2229 -imp '_vsnprintf' _vsnprintf ntdll 2230 -imp '_vsnprintf_s' _vsnprintf_s ntdll 2231 -imp '_vsnwprintf' _vsnwprintf ntdll 2232 -imp '_vsnwprintf_s' _vsnwprintf_s ntdll 2233 -imp '_vswprintf' _vswprintf ntdll 2234 -imp '_wcsicmp' _wcsicmp ntdll 2235 -imp '_wcslwr' _wcslwr ntdll 2236 -imp '_wcslwr_s' _wcslwr_s ntdll 2237 -imp '_wcsnicmp' _wcsnicmp ntdll 2238 -imp '_wcsnset_s' _wcsnset_s ntdll 2239 -imp '_wcsset_s' _wcsset_s ntdll 2240 -imp '_wcstoi64' _wcstoi64 ntdll 2241 -imp '_wcstoui64' _wcstoui64 ntdll 2242 -imp '_wcsupr' _wcsupr ntdll 2243 -imp '_wcsupr_s' _wcsupr_s ntdll 2244 imp '_wmakepath_s' _wmakepath_s ntdll 2245 imp '_wsplitpath_s' _wsplitpath_s ntdll 2246 imp '_wtoi' _wtoi ntdll 2247 imp '_wtoi64' _wtoi64 ntdll 2248 imp '_wtol' _wtol ntdll 2249 -imp 'abs$nt' abs ntdll 2250 -imp '__accept$nt' accept ws2_32 1 -imp 'atan$nt' atan ntdll 2251 -imp 'atan2$nt' atan2 ntdll 2252 -imp 'atexit$nt' atexit KernelBase 1849 -imp 'atoi$nt' atoi ntdll 2253 -imp 'atol$nt' atol ntdll 2254 +imp 'sys_abs_nt' abs ntdll 2250 +imp '__sys_accept_nt' accept ws2_32 1 +imp 'sys_atan_nt' atan ntdll 2251 +imp 'sys_atan2_nt' atan2 ntdll 2252 +imp 'sys_atexit_nt' atexit KernelBase 1849 +imp 'sys_atoi_nt' atoi ntdll 2253 +imp 'sys_atol_nt' atol ntdll 2254 imp 'bCreateDCW' bCreateDCW gdi32 1948 imp 'bDeleteLDC' bDeleteLDC gdi32 1949 imp 'bInitSystemAndFontsDirectories' bInitSystemAndFontsDirectoriesW gdi32 1950 imp 'bMakePathName' bMakePathNameW gdi32 1951 -imp '__bind$nt' bind ws2_32 2 3 -imp 'bsearch$nt' bsearch ntdll 2255 +imp '__sys_bind_nt' bind ws2_32 2 3 +imp 'sys_bsearch_nt' bsearch ntdll 2255 imp 'bsearch_s' bsearch_s ntdll 2256 imp 'cGetTTFFromFOT' cGetTTFFromFOT gdi32 1952 -imp 'ceil$nt' ceil ntdll 2257 -imp '__closesocket$nt' closesocket ws2_32 3 1 -imp '__connect$nt' connect ws2_32 4 -imp 'cos$nt' cos ntdll 2258 +imp 'sys_ceil_nt' ceil ntdll 2257 +imp '__sys_closesocket_nt' closesocket ws2_32 3 1 +imp '__sys_connect_nt' connect ws2_32 4 +imp 'sys_cos_nt' cos ntdll 2258 imp 'dwLBSubclass' dwLBSubclass comdlg32 128 imp 'dwOKSubclass' dwOKSubclass comdlg32 129 -imp 'exit$nt' exit KernelBase 1850 -imp 'fabs$nt' fabs ntdll 2259 -imp 'floor$nt' floor ntdll 2260 +imp 'sys_exit_nt' exit KernelBase 1850 +imp 'sys_fabs_nt' fabs ntdll 2259 +imp 'sys_floor_nt' floor ntdll 2260 imp 'fpClosePrinter' fpClosePrinter gdi32 1953 -imp 'freeaddrinfo$nt' freeaddrinfo ws2_32 190 +imp 'sys_freeaddrinfo_nt' freeaddrinfo ws2_32 190 imp 'gMaxGdiHandleCount' gMaxGdiHandleCount gdi32 1955 imp 'gSharedInfo' gSharedInfo user32 2547 imp 'gW32PID' gW32PID gdi32 1956 imp 'g_systemCallFilterId' g_systemCallFilterId gdi32 1957 imp 'gapfnScSendMessage' gapfnScSendMessage user32 2562 imp 'gdiPlaySpoolStream' gdiPlaySpoolStream gdi32 1958 -imp 'getaddrinfo$nt' getaddrinfo ws2_32 191 -imp 'gethostbyaddr$nt' gethostbyaddr ws2_32 51 -imp 'gethostbyname$nt' gethostbyname ws2_32 52 -imp 'gethostname$nt' gethostname ws2_32 57 -imp 'getnameinfo$nt' getnameinfo ws2_32 192 -imp '__getpeername$nt' getpeername ws2_32 5 3 -imp 'getprotobyname$nt' getprotobyname ws2_32 53 -imp 'getprotobynumber$nt' getprotobynumber ws2_32 54 -imp 'getservbyname$nt' getservbyname ws2_32 55 -imp 'getservbyport$nt' getservbyport ws2_32 56 -imp '__getsockname$nt' getsockname ws2_32 6 3 -imp '__getsockopt$nt' getsockopt ws2_32 7 5 +imp 'sys_getaddrinfo_nt' getaddrinfo ws2_32 191 +imp 'sys_gethostbyaddr_nt' gethostbyaddr ws2_32 51 +imp 'sys_gethostbyname_nt' gethostbyname ws2_32 52 +imp 'sys_gethostname_nt' gethostname ws2_32 57 +imp 'sys_getnameinfo_nt' getnameinfo ws2_32 192 +imp '__sys_getpeername_nt' getpeername ws2_32 5 3 +imp 'sys_getprotobyname_nt' getprotobyname ws2_32 53 +imp 'sys_getprotobynumber_nt' getprotobynumber ws2_32 54 +imp 'sys_getservbyname_nt' getservbyname ws2_32 55 +imp 'sys_getservbyport_nt' getservbyport ws2_32 56 +imp '__sys_getsockname_nt' getsockname ws2_32 6 3 +imp '__sys_getsockopt_nt' getsockopt ws2_32 7 5 imp 'ghICM' ghICM gdi32 1959 imp 'hGetPEBHandle' hGetPEBHandle gdi32 1960 imp 'hgets' hgets KernelBase 1851 -imp 'htonl$nt' htonl ws2_32 8 -imp 'htons$nt' htons ws2_32 9 imp 'hwprintf' hwprintf KernelBase 1852 -imp 'inet_addr$nt' inet_addr ws2_32 11 -imp 'inet_ntoa$nt' inet_ntoa ws2_32 12 -imp 'inet_ntop$nt' inet_ntop ws2_32 193 -imp 'inet_pton$nt' inet_pton ws2_32 194 -imp '__ioctlsocket$nt' ioctlsocket ws2_32 10 3 -imp 'isalnum$nt' isalnum ntdll 2261 -imp 'isalpha$nt' isalpha ntdll 2262 -imp 'iscntrl$nt' iscntrl ntdll 2263 -imp 'isdigit$nt' isdigit ntdll 2264 -imp 'isgraph$nt' isgraph ntdll 2265 -imp 'islower$nt' islower ntdll 2266 -imp 'isprint$nt' isprint ntdll 2267 -imp 'ispunct$nt' ispunct ntdll 2268 -imp 'isspace$nt' isspace ntdll 2269 -imp 'isupper$nt' isupper ntdll 2270 -imp 'iswalnum$nt' iswalnum ntdll 2271 -imp 'iswalpha$nt' iswalpha ntdll 2272 +imp '__sys_ioctlsocket_nt' ioctlsocket ws2_32 10 3 imp 'iswascii' iswascii ntdll 2273 -imp 'iswctype$nt' iswctype ntdll 2274 -imp 'iswdigit$nt' iswdigit ntdll 2275 -imp 'iswgraph$nt' iswgraph ntdll 2276 -imp 'iswlower$nt' iswlower ntdll 2277 -imp 'iswprint$nt' iswprint ntdll 2278 -imp 'iswspace$nt' iswspace ntdll 2279 -imp 'iswxdigit$nt' iswxdigit ntdll 2280 -imp 'isxdigit$nt' isxdigit ntdll 2281 imp 'keybd_event' keybd_event user32 2580 -imp 'labs$nt' labs ntdll 2282 -imp '__listen$nt' listen ws2_32 13 2 -imp 'log$nt' log ntdll 2283 -imp 'longjmp$nt' longjmp ntdll 2284 -imp 'lstrcatA' lstrcatA kernel32 1592 -imp 'lstrcat' lstrcatW kernel32 1593 -imp 'lstrcmpA' lstrcmpA kernel32 0 # KernelBase -imp 'lstrcmp' lstrcmpW kernel32 0 # KernelBase -imp 'lstrcmpiA' lstrcmpiA kernel32 0 # KernelBase -imp 'lstrcmpi' lstrcmpiW kernel32 0 # KernelBase -imp 'lstrcpyA' lstrcpyA kernel32 1601 -imp 'lstrcpy' lstrcpyW kernel32 1602 -imp 'lstrcpynA' lstrcpynA kernel32 0 # KernelBase -imp 'lstrcpyn' lstrcpynW kernel32 0 # KernelBase -imp 'lstrlenA' lstrlenA kernel32 0 # KernelBase -imp 'lstrlen' lstrlenW kernel32 0 # KernelBase -imp 'mbstowcs$nt' mbstowcs ntdll 2285 -imp 'memchr$nt' memchr ntdll 2286 -imp 'memcmp$nt' memcmp ntdll 2287 -imp 'memcpy$nt' memcpy ntdll 2288 -imp 'memcpy_s' memcpy_s ntdll 2289 -imp 'memmove$nt' memmove ntdll 2290 -imp 'memmove_s' memmove_s ntdll 2291 -imp 'memset$nt' memset ntdll 2292 +imp 'sys_labs_nt' labs ntdll 2282 +imp '__sys_listen_nt' listen ws2_32 13 2 +imp 'sys_log_nt' log ntdll 2283 +imp 'sys_longjmp_nt' longjmp ntdll 2284 imp 'mouse_event' mouse_event user32 2583 -imp 'ntohl$nt' ntohl ws2_32 14 -imp 'ntohs$nt' ntohs ws2_32 15 imp 'pGdiDevCaps' pGdiDevCaps gdi32 1961 imp 'pGdiSharedHandleTable' pGdiSharedHandleTable gdi32 1962 imp 'pGdiSharedMemory' pGdiSharedMemory gdi32 1963 imp 'pldcGet' pldcGet gdi32 1964 -imp 'pow$nt' pow ntdll 2293 -imp 'qsort$nt' qsort ntdll 2294 -imp 'qsort_s$nt' qsort_s ntdll 2295 -imp 'recv$nt' recv ws2_32 16 -imp '__recvfrom$nt' recvfrom ws2_32 17 -imp '__select$nt' select ws2_32 18 5 +imp 'sys_recv_nt' recv ws2_32 16 +imp '__sys_recvfrom_nt' recvfrom ws2_32 17 +imp '__sys_select_nt' select ws2_32 18 5 imp 'semDxTrimNotification' semDxTrimNotification gdi32 1965 -imp 'send$nt' send ws2_32 19 -imp '__sendto$nt' sendto ws2_32 20 -imp '__setsockopt$nt' setsockopt ws2_32 21 5 -imp '__shutdown$nt' shutdown ws2_32 22 2 -imp 'sin$nt' sin ntdll 2296 -imp '__socket$nt' socket ws2_32 23 -imp 'sprintf$nt' sprintf ntdll 2297 -imp 'sprintf_s$nt' sprintf_s ntdll 2298 -imp 'sqrt$nt' sqrt ntdll 2299 -imp 'sscanf$nt' sscanf ntdll 2300 -imp 'sscanf_s$nt' sscanf_s ntdll 2301 -imp 'strcat$nt' strcat ntdll 2302 -imp 'strcat_s$nt' strcat_s ntdll 2303 -imp 'strchr$nt' strchr ntdll 2304 -imp 'strcmp$nt' strcmp ntdll 2305 -imp 'strcpy$nt' strcpy ntdll 2306 -imp 'strcpy_s$nt' strcpy_s ntdll 2307 -imp 'strcspn$nt' strcspn ntdll 2308 -imp 'strlen$nt' strlen ntdll 2309 -imp 'strncat$nt' strncat ntdll 2310 -imp 'strncat_s$nt' strncat_s ntdll 2311 -imp 'strncmp$nt' strncmp ntdll 2312 -imp 'strncpy$nt' strncpy ntdll 2313 -imp 'strncpy_s$nt' strncpy_s ntdll 2314 -imp 'strnlen$nt' strnlen ntdll 2315 -imp 'strpbrk$nt' strpbrk ntdll 2316 -imp 'strrchr$nt' strrchr ntdll 2317 -imp 'strspn$nt' strspn ntdll 2318 -imp 'strstr$nt' strstr ntdll 2319 -imp 'strtok_s$nt' strtok_s ntdll 2320 -imp 'strtol$nt' strtol ntdll 2321 -imp 'strtoul$nt' strtoul ntdll 2322 -imp 'swprintf$nt' swprintf ntdll 2323 -imp 'swprintf_s' swprintf_s ntdll 2324 -imp 'swscanf_s' swscanf_s ntdll 2325 -imp 'tan$nt' tan ntdll 2326 -imp 'time$nt' time KernelBase 1865 +imp 'sys_send_nt' send ws2_32 19 +imp '__sys_sendto_nt' sendto ws2_32 20 +imp '__sys_setsockopt_nt' setsockopt ws2_32 21 5 +imp '__sys_shutdown_nt' shutdown ws2_32 22 2 +imp 'sys_sin_nt' sin ntdll 2296 +imp '__sys_socket_nt' socket ws2_32 23 imp 'timeBeginPeriod' timeBeginPeriod kernel32 1609 imp 'timeEndPeriod' timeEndPeriod kernel32 1610 imp 'timeGetDevCaps' timeGetDevCaps kernel32 1611 imp 'timeGetSystemTime' timeGetSystemTime kernel32 1612 imp 'timeGetTime' timeGetTime kernel32 1613 -imp 'tolower$nt' tolower ntdll 2327 -imp 'toupper$nt' toupper ntdll 2328 -imp 'towlower$nt' towlower ntdll 2329 -imp 'towupper$nt' towupper ntdll 2330 -imp 'uaw_lstrcmp' uaw_lstrcmpW kernel32 1614 -imp 'uaw_lstrcmpi' uaw_lstrcmpiW kernel32 1615 -imp 'uaw_lstrlen' uaw_lstrlenW kernel32 1616 -imp 'uaw_wcschr' uaw_wcschr kernel32 1617 -imp 'uaw_wcscpy' uaw_wcscpy kernel32 1618 -imp 'uaw_wcsicmp' uaw_wcsicmp kernel32 1619 -imp 'uaw_wcslen' uaw_wcslen kernel32 1620 -imp 'uaw_wcsrchr' uaw_wcsrchr kernel32 1621 -imp 'vDbgPrintEx' vDbgPrintEx ntdll 2331 -imp 'vDbgPrintExWithPrefix' vDbgPrintExWithPrefix ntdll 2332 -imp 'vSetPldc' vSetPldc gdi32 1966 -imp 'vsprintf$nt' vsprintf ntdll 2333 -imp 'vsprintf_s' vsprintf_s ntdll 2334 -imp 'vswprintf_s' vswprintf_s ntdll 2335 -imp 'wcscat$nt' wcscat ntdll 2336 -imp 'wcscat_s' wcscat_s ntdll 2337 -imp 'wcschr$nt' wcschr ntdll 2338 -imp 'wcscmp$nt' wcscmp ntdll 2339 -imp 'wcscpy$nt' wcscpy ntdll 2340 -imp 'wcscpy_s' wcscpy_s ntdll 2341 -imp 'wcscspn$nt' wcscspn ntdll 2342 -imp 'wcslen$nt' wcslen ntdll 2343 -imp 'wcsncat$nt' wcsncat ntdll 2344 -imp 'wcsncat_s' wcsncat_s ntdll 2345 -imp 'wcsncmp$nt' wcsncmp ntdll 2346 -imp 'wcsncpy$nt' wcsncpy ntdll 2347 -imp 'wcsncpy_s' wcsncpy_s ntdll 2348 -imp 'wcsnlen$nt' wcsnlen ntdll 2349 -imp 'wcspbrk$nt' wcspbrk ntdll 2350 -imp 'wcsrchr$nt' wcsrchr ntdll 2351 -imp 'wcsspn$nt' wcsspn ntdll 2352 -imp 'wcsstr$nt' wcsstr ntdll 2353 -imp 'wcstok_s' wcstok_s ntdll 2354 -imp 'wcstol$nt' wcstol ntdll 2355 -imp 'wcstombs$nt' wcstombs ntdll 2356 -imp 'wcstoul$nt' wcstoul ntdll 2357 -imp 'wprintf$nt' wprintf KernelBase 1866 -imp 'wsprintfA' wsprintfA user32 2596 -imp 'wsprintf' wsprintfW user32 2601 -imp 'wvsprintfA' wvsprintfA user32 2602 -imp 'wvsprintf' wvsprintfW user32 2603 imp 'InitializeCriticalSection' InitializeCriticalSection kernel32 0 1 # KernelBase imp 'EnterCriticalSection' EnterCriticalSection kernel32 0 1 # KernelBase diff --git a/libc/nt/ntdll.h b/libc/nt/ntdll.h index 829500632..e111c5b10 100644 --- a/libc/nt/ntdll.h +++ b/libc/nt/ntdll.h @@ -41,7 +41,7 @@ COSMOPOLITAN_C_START_ Windows to the next, and possibly even between service packs for each release.” ──Quoth MSDN */ -#define g_nt_system_call_dispatcher (wambda *)0x7ffe0308 +#define __nt_system_call_dispatcher (wambda *)0x7ffe0308 extern const struct NtUnicodeString *const RtlNtdllName; diff --git a/libc/nt/ntdll/A_SHAFinal.s b/libc/nt/ntdll/A_SHAFinal.s deleted file mode 100644 index be95a48d4..000000000 --- a/libc/nt/ntdll/A_SHAFinal.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp A_SHAFinal diff --git a/libc/nt/ntdll/A_SHAInit.s b/libc/nt/ntdll/A_SHAInit.s deleted file mode 100644 index 16290c4e5..000000000 --- a/libc/nt/ntdll/A_SHAInit.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp A_SHAInit diff --git a/libc/nt/ntdll/A_SHAUpdate.s b/libc/nt/ntdll/A_SHAUpdate.s deleted file mode 100644 index ea0c3283d..000000000 --- a/libc/nt/ntdll/A_SHAUpdate.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp A_SHAUpdate diff --git a/libc/nt/ntdll/MD5Final.s b/libc/nt/ntdll/MD5Final.s deleted file mode 100644 index d800a5ee2..000000000 --- a/libc/nt/ntdll/MD5Final.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp MD5Final diff --git a/libc/nt/ntdll/MD5Init.s b/libc/nt/ntdll/MD5Init.s deleted file mode 100644 index 5103d62ce..000000000 --- a/libc/nt/ntdll/MD5Init.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp MD5Init diff --git a/libc/nt/ntdll/MD5Update.s b/libc/nt/ntdll/MD5Update.s deleted file mode 100644 index d5965eb86..000000000 --- a/libc/nt/ntdll/MD5Update.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp MD5Update diff --git a/libc/nt/ntdll/_i64toa.s b/libc/nt/ntdll/_i64toa.s deleted file mode 100644 index cd9c82778..000000000 --- a/libc/nt/ntdll/_i64toa.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _i64toa diff --git a/libc/nt/ntdll/_i64toa_s.s b/libc/nt/ntdll/_i64toa_s.s deleted file mode 100644 index 3e160227a..000000000 --- a/libc/nt/ntdll/_i64toa_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _i64toa_s diff --git a/libc/nt/ntdll/_i64tow.s b/libc/nt/ntdll/_i64tow.s deleted file mode 100644 index af09db1ba..000000000 --- a/libc/nt/ntdll/_i64tow.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _i64tow diff --git a/libc/nt/ntdll/_i64tow_s.s b/libc/nt/ntdll/_i64tow_s.s deleted file mode 100644 index 8436028af..000000000 --- a/libc/nt/ntdll/_i64tow_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _i64tow_s diff --git a/libc/nt/ntdll/_itoa.s b/libc/nt/ntdll/_itoa.s deleted file mode 100644 index d5acc31d8..000000000 --- a/libc/nt/ntdll/_itoa.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _itoa diff --git a/libc/nt/ntdll/_itoa_s.s b/libc/nt/ntdll/_itoa_s.s deleted file mode 100644 index f8147967c..000000000 --- a/libc/nt/ntdll/_itoa_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _itoa_s diff --git a/libc/nt/ntdll/_itow.s b/libc/nt/ntdll/_itow.s deleted file mode 100644 index b03576f21..000000000 --- a/libc/nt/ntdll/_itow.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _itow diff --git a/libc/nt/ntdll/_itow_s.s b/libc/nt/ntdll/_itow_s.s deleted file mode 100644 index 1d497c0c2..000000000 --- a/libc/nt/ntdll/_itow_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _itow_s diff --git a/libc/nt/ntdll/_ltoa.s b/libc/nt/ntdll/_ltoa.s deleted file mode 100644 index 5e4720fff..000000000 --- a/libc/nt/ntdll/_ltoa.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ltoa diff --git a/libc/nt/ntdll/_ltoa_s.s b/libc/nt/ntdll/_ltoa_s.s deleted file mode 100644 index 4e8d6e155..000000000 --- a/libc/nt/ntdll/_ltoa_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ltoa_s diff --git a/libc/nt/ntdll/_ltow.s b/libc/nt/ntdll/_ltow.s deleted file mode 100644 index c652c26fc..000000000 --- a/libc/nt/ntdll/_ltow.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ltow diff --git a/libc/nt/ntdll/_ltow_s.s b/libc/nt/ntdll/_ltow_s.s deleted file mode 100644 index bf077f47e..000000000 --- a/libc/nt/ntdll/_ltow_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ltow_s diff --git a/libc/nt/ntdll/_snprintf.s b/libc/nt/ntdll/_snprintf.s deleted file mode 100644 index 9c4f2e0e3..000000000 --- a/libc/nt/ntdll/_snprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _snprintf diff --git a/libc/nt/ntdll/_snprintf_s.s b/libc/nt/ntdll/_snprintf_s.s deleted file mode 100644 index e0db57926..000000000 --- a/libc/nt/ntdll/_snprintf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _snprintf_s diff --git a/libc/nt/ntdll/_snscanf_s.s b/libc/nt/ntdll/_snscanf_s.s deleted file mode 100644 index 0dc68773a..000000000 --- a/libc/nt/ntdll/_snscanf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _snscanf_s diff --git a/libc/nt/ntdll/_snwprintf.s b/libc/nt/ntdll/_snwprintf.s deleted file mode 100644 index 6d250cceb..000000000 --- a/libc/nt/ntdll/_snwprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _snwprintf diff --git a/libc/nt/ntdll/_snwprintf_s.s b/libc/nt/ntdll/_snwprintf_s.s deleted file mode 100644 index 8b0c7be7c..000000000 --- a/libc/nt/ntdll/_snwprintf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _snwprintf_s diff --git a/libc/nt/ntdll/_snwscanf_s.s b/libc/nt/ntdll/_snwscanf_s.s deleted file mode 100644 index 805bbbf39..000000000 --- a/libc/nt/ntdll/_snwscanf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _snwscanf_s diff --git a/libc/nt/ntdll/_splitpath.s b/libc/nt/ntdll/_splitpath.s deleted file mode 100644 index f353e3ac3..000000000 --- a/libc/nt/ntdll/_splitpath.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _splitpath diff --git a/libc/nt/ntdll/_splitpath_s.s b/libc/nt/ntdll/_splitpath_s.s deleted file mode 100644 index eddcea76d..000000000 --- a/libc/nt/ntdll/_splitpath_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _splitpath_s diff --git a/libc/nt/ntdll/_strcmpi.s b/libc/nt/ntdll/_strcmpi.s deleted file mode 100644 index 9c11325b0..000000000 --- a/libc/nt/ntdll/_strcmpi.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _strcmpi diff --git a/libc/nt/ntdll/_stricmp.s b/libc/nt/ntdll/_stricmp.s deleted file mode 100644 index e32e57ccd..000000000 --- a/libc/nt/ntdll/_stricmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _stricmp diff --git a/libc/nt/ntdll/_strlwr.s b/libc/nt/ntdll/_strlwr.s deleted file mode 100644 index 55b948b05..000000000 --- a/libc/nt/ntdll/_strlwr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _strlwr diff --git a/libc/nt/ntdll/_strlwr_s.s b/libc/nt/ntdll/_strlwr_s.s deleted file mode 100644 index e5a58c1fc..000000000 --- a/libc/nt/ntdll/_strlwr_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _strlwr_s diff --git a/libc/nt/ntdll/_strnicmp.s b/libc/nt/ntdll/_strnicmp.s deleted file mode 100644 index 739a724fd..000000000 --- a/libc/nt/ntdll/_strnicmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _strnicmp diff --git a/libc/nt/ntdll/_strnset_s.s b/libc/nt/ntdll/_strnset_s.s deleted file mode 100644 index c3425d0f7..000000000 --- a/libc/nt/ntdll/_strnset_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _strnset_s diff --git a/libc/nt/ntdll/_strset_s.s b/libc/nt/ntdll/_strset_s.s deleted file mode 100644 index 27478a759..000000000 --- a/libc/nt/ntdll/_strset_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _strset_s diff --git a/libc/nt/ntdll/_strupr.s b/libc/nt/ntdll/_strupr.s deleted file mode 100644 index 618424b73..000000000 --- a/libc/nt/ntdll/_strupr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _strupr diff --git a/libc/nt/ntdll/_strupr_s.s b/libc/nt/ntdll/_strupr_s.s deleted file mode 100644 index e3f3b110b..000000000 --- a/libc/nt/ntdll/_strupr_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _strupr_s diff --git a/libc/nt/ntdll/_swprintf.s b/libc/nt/ntdll/_swprintf.s deleted file mode 100644 index c4e629b5a..000000000 --- a/libc/nt/ntdll/_swprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _swprintf diff --git a/libc/nt/ntdll/_ui64toa.s b/libc/nt/ntdll/_ui64toa.s deleted file mode 100644 index 2f3a46f2c..000000000 --- a/libc/nt/ntdll/_ui64toa.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ui64toa diff --git a/libc/nt/ntdll/_ui64toa_s.s b/libc/nt/ntdll/_ui64toa_s.s deleted file mode 100644 index 4125819b5..000000000 --- a/libc/nt/ntdll/_ui64toa_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ui64toa_s diff --git a/libc/nt/ntdll/_ui64tow.s b/libc/nt/ntdll/_ui64tow.s deleted file mode 100644 index fb18658eb..000000000 --- a/libc/nt/ntdll/_ui64tow.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ui64tow diff --git a/libc/nt/ntdll/_ui64tow_s.s b/libc/nt/ntdll/_ui64tow_s.s deleted file mode 100644 index d287e98bd..000000000 --- a/libc/nt/ntdll/_ui64tow_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ui64tow_s diff --git a/libc/nt/ntdll/_ultoa.s b/libc/nt/ntdll/_ultoa.s deleted file mode 100644 index 55bae46d9..000000000 --- a/libc/nt/ntdll/_ultoa.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ultoa diff --git a/libc/nt/ntdll/_ultoa_s.s b/libc/nt/ntdll/_ultoa_s.s deleted file mode 100644 index c2206e602..000000000 --- a/libc/nt/ntdll/_ultoa_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ultoa_s diff --git a/libc/nt/ntdll/_ultow.s b/libc/nt/ntdll/_ultow.s deleted file mode 100644 index 9299dffc2..000000000 --- a/libc/nt/ntdll/_ultow.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ultow diff --git a/libc/nt/ntdll/_ultow_s.s b/libc/nt/ntdll/_ultow_s.s deleted file mode 100644 index 8092cf55c..000000000 --- a/libc/nt/ntdll/_ultow_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _ultow_s diff --git a/libc/nt/ntdll/_vscprintf.s b/libc/nt/ntdll/_vscprintf.s deleted file mode 100644 index 6c8643c7b..000000000 --- a/libc/nt/ntdll/_vscprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _vscprintf diff --git a/libc/nt/ntdll/_vscwprintf.s b/libc/nt/ntdll/_vscwprintf.s deleted file mode 100644 index c55d727fa..000000000 --- a/libc/nt/ntdll/_vscwprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _vscwprintf diff --git a/libc/nt/ntdll/_vsnprintf.s b/libc/nt/ntdll/_vsnprintf.s deleted file mode 100644 index f4ef3825e..000000000 --- a/libc/nt/ntdll/_vsnprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _vsnprintf diff --git a/libc/nt/ntdll/_vsnprintf_s.s b/libc/nt/ntdll/_vsnprintf_s.s deleted file mode 100644 index 921ff5988..000000000 --- a/libc/nt/ntdll/_vsnprintf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _vsnprintf_s diff --git a/libc/nt/ntdll/_vsnwprintf.s b/libc/nt/ntdll/_vsnwprintf.s deleted file mode 100644 index ae82c6a4e..000000000 --- a/libc/nt/ntdll/_vsnwprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _vsnwprintf diff --git a/libc/nt/ntdll/_vsnwprintf_s.s b/libc/nt/ntdll/_vsnwprintf_s.s deleted file mode 100644 index 5024b7de8..000000000 --- a/libc/nt/ntdll/_vsnwprintf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _vsnwprintf_s diff --git a/libc/nt/ntdll/_vswprintf.s b/libc/nt/ntdll/_vswprintf.s deleted file mode 100644 index 3dc1c8ede..000000000 --- a/libc/nt/ntdll/_vswprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _vswprintf diff --git a/libc/nt/ntdll/_wcsicmp.s b/libc/nt/ntdll/_wcsicmp.s deleted file mode 100644 index b9187e0d1..000000000 --- a/libc/nt/ntdll/_wcsicmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcsicmp diff --git a/libc/nt/ntdll/_wcslwr.s b/libc/nt/ntdll/_wcslwr.s deleted file mode 100644 index 5446d978c..000000000 --- a/libc/nt/ntdll/_wcslwr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcslwr diff --git a/libc/nt/ntdll/_wcslwr_s.s b/libc/nt/ntdll/_wcslwr_s.s deleted file mode 100644 index b7171b0f8..000000000 --- a/libc/nt/ntdll/_wcslwr_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcslwr_s diff --git a/libc/nt/ntdll/_wcsnicmp.s b/libc/nt/ntdll/_wcsnicmp.s deleted file mode 100644 index f65f0e4cc..000000000 --- a/libc/nt/ntdll/_wcsnicmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcsnicmp diff --git a/libc/nt/ntdll/_wcsnset_s.s b/libc/nt/ntdll/_wcsnset_s.s deleted file mode 100644 index f564b2db6..000000000 --- a/libc/nt/ntdll/_wcsnset_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcsnset_s diff --git a/libc/nt/ntdll/_wcsset_s.s b/libc/nt/ntdll/_wcsset_s.s deleted file mode 100644 index e8da96d4b..000000000 --- a/libc/nt/ntdll/_wcsset_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcsset_s diff --git a/libc/nt/ntdll/_wcstoi64.s b/libc/nt/ntdll/_wcstoi64.s deleted file mode 100644 index 52f9f7a42..000000000 --- a/libc/nt/ntdll/_wcstoi64.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcstoi64 diff --git a/libc/nt/ntdll/_wcstoui64.s b/libc/nt/ntdll/_wcstoui64.s deleted file mode 100644 index 16e682775..000000000 --- a/libc/nt/ntdll/_wcstoui64.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcstoui64 diff --git a/libc/nt/ntdll/_wcsupr.s b/libc/nt/ntdll/_wcsupr.s deleted file mode 100644 index 84e916e98..000000000 --- a/libc/nt/ntdll/_wcsupr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcsupr diff --git a/libc/nt/ntdll/_wcsupr_s.s b/libc/nt/ntdll/_wcsupr_s.s deleted file mode 100644 index a334fd7f0..000000000 --- a/libc/nt/ntdll/_wcsupr_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp _wcsupr_s diff --git a/libc/nt/ntdll/isalnum.s b/libc/nt/ntdll/isalnum.s deleted file mode 100644 index 04d202cac..000000000 --- a/libc/nt/ntdll/isalnum.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp isalnum diff --git a/libc/nt/ntdll/isalpha.s b/libc/nt/ntdll/isalpha.s deleted file mode 100644 index afc7608e3..000000000 --- a/libc/nt/ntdll/isalpha.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp isalpha diff --git a/libc/nt/ntdll/iscntrl.s b/libc/nt/ntdll/iscntrl.s deleted file mode 100644 index 72f4a3dae..000000000 --- a/libc/nt/ntdll/iscntrl.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iscntrl diff --git a/libc/nt/ntdll/isdigit.s b/libc/nt/ntdll/isdigit.s deleted file mode 100644 index 0eab8659c..000000000 --- a/libc/nt/ntdll/isdigit.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp isdigit diff --git a/libc/nt/ntdll/isgraph.s b/libc/nt/ntdll/isgraph.s deleted file mode 100644 index 57fcd7b58..000000000 --- a/libc/nt/ntdll/isgraph.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp isgraph diff --git a/libc/nt/ntdll/islower.s b/libc/nt/ntdll/islower.s deleted file mode 100644 index bf1a77452..000000000 --- a/libc/nt/ntdll/islower.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp islower diff --git a/libc/nt/ntdll/isprint.s b/libc/nt/ntdll/isprint.s deleted file mode 100644 index bc6eaee3b..000000000 --- a/libc/nt/ntdll/isprint.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp isprint diff --git a/libc/nt/ntdll/ispunct.s b/libc/nt/ntdll/ispunct.s deleted file mode 100644 index a772c0acd..000000000 --- a/libc/nt/ntdll/ispunct.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp ispunct diff --git a/libc/nt/ntdll/isspace.s b/libc/nt/ntdll/isspace.s deleted file mode 100644 index 0668588d3..000000000 --- a/libc/nt/ntdll/isspace.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp isspace diff --git a/libc/nt/ntdll/isupper.s b/libc/nt/ntdll/isupper.s deleted file mode 100644 index 98b5b1abf..000000000 --- a/libc/nt/ntdll/isupper.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp isupper diff --git a/libc/nt/ntdll/iswalnum.s b/libc/nt/ntdll/iswalnum.s deleted file mode 100644 index 30416e3fb..000000000 --- a/libc/nt/ntdll/iswalnum.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswalnum diff --git a/libc/nt/ntdll/iswalpha.s b/libc/nt/ntdll/iswalpha.s deleted file mode 100644 index 4303e716e..000000000 --- a/libc/nt/ntdll/iswalpha.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswalpha diff --git a/libc/nt/ntdll/iswctype.s b/libc/nt/ntdll/iswctype.s deleted file mode 100644 index 96d43c62c..000000000 --- a/libc/nt/ntdll/iswctype.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswctype diff --git a/libc/nt/ntdll/iswdigit.s b/libc/nt/ntdll/iswdigit.s deleted file mode 100644 index 8333385e4..000000000 --- a/libc/nt/ntdll/iswdigit.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswdigit diff --git a/libc/nt/ntdll/iswgraph.s b/libc/nt/ntdll/iswgraph.s deleted file mode 100644 index a9ef4d9c0..000000000 --- a/libc/nt/ntdll/iswgraph.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswgraph diff --git a/libc/nt/ntdll/iswlower.s b/libc/nt/ntdll/iswlower.s deleted file mode 100644 index 11b333e73..000000000 --- a/libc/nt/ntdll/iswlower.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswlower diff --git a/libc/nt/ntdll/iswprint.s b/libc/nt/ntdll/iswprint.s deleted file mode 100644 index 254cd09a6..000000000 --- a/libc/nt/ntdll/iswprint.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswprint diff --git a/libc/nt/ntdll/iswspace.s b/libc/nt/ntdll/iswspace.s deleted file mode 100644 index cd424bb9b..000000000 --- a/libc/nt/ntdll/iswspace.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswspace diff --git a/libc/nt/ntdll/iswxdigit.s b/libc/nt/ntdll/iswxdigit.s deleted file mode 100644 index 96409f8a7..000000000 --- a/libc/nt/ntdll/iswxdigit.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp iswxdigit diff --git a/libc/nt/ntdll/isxdigit.s b/libc/nt/ntdll/isxdigit.s deleted file mode 100644 index 955b96256..000000000 --- a/libc/nt/ntdll/isxdigit.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp isxdigit diff --git a/libc/nt/ntdll/mbstowcs.s b/libc/nt/ntdll/mbstowcs.s deleted file mode 100644 index 7e6f30ab7..000000000 --- a/libc/nt/ntdll/mbstowcs.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp mbstowcs diff --git a/libc/nt/ntdll/memchr.s b/libc/nt/ntdll/memchr.s deleted file mode 100644 index ce56543cc..000000000 --- a/libc/nt/ntdll/memchr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp memchr diff --git a/libc/nt/ntdll/memcmp.s b/libc/nt/ntdll/memcmp.s deleted file mode 100644 index 0d655958c..000000000 --- a/libc/nt/ntdll/memcmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp memcmp diff --git a/libc/nt/ntdll/memcpy.s b/libc/nt/ntdll/memcpy.s deleted file mode 100644 index 42542b3e9..000000000 --- a/libc/nt/ntdll/memcpy.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp memcpy diff --git a/libc/nt/ntdll/memcpy_s.s b/libc/nt/ntdll/memcpy_s.s deleted file mode 100644 index 35f1ea680..000000000 --- a/libc/nt/ntdll/memcpy_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp memcpy_s diff --git a/libc/nt/ntdll/memmove.s b/libc/nt/ntdll/memmove.s deleted file mode 100644 index 3b9da6930..000000000 --- a/libc/nt/ntdll/memmove.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp memmove diff --git a/libc/nt/ntdll/memmove_s.s b/libc/nt/ntdll/memmove_s.s deleted file mode 100644 index 6492335af..000000000 --- a/libc/nt/ntdll/memmove_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp memmove_s diff --git a/libc/nt/ntdll/memset.s b/libc/nt/ntdll/memset.s deleted file mode 100644 index 0bd1ea332..000000000 --- a/libc/nt/ntdll/memset.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp memset diff --git a/libc/nt/ntdll/pow.s b/libc/nt/ntdll/pow.s deleted file mode 100644 index 386f2ec74..000000000 --- a/libc/nt/ntdll/pow.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp pow diff --git a/libc/nt/ntdll/qsort.s b/libc/nt/ntdll/qsort.s deleted file mode 100644 index 9fe292cf5..000000000 --- a/libc/nt/ntdll/qsort.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp qsort diff --git a/libc/nt/ntdll/qsort_s.s b/libc/nt/ntdll/qsort_s.s deleted file mode 100644 index b43952269..000000000 --- a/libc/nt/ntdll/qsort_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp qsort_s diff --git a/libc/nt/ntdll/sprintf.s b/libc/nt/ntdll/sprintf.s deleted file mode 100644 index ec2ac1cd8..000000000 --- a/libc/nt/ntdll/sprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp sprintf diff --git a/libc/nt/ntdll/sprintf_s.s b/libc/nt/ntdll/sprintf_s.s deleted file mode 100644 index b500799e2..000000000 --- a/libc/nt/ntdll/sprintf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp sprintf_s diff --git a/libc/nt/ntdll/sqrt.s b/libc/nt/ntdll/sqrt.s deleted file mode 100644 index ab0cabd5f..000000000 --- a/libc/nt/ntdll/sqrt.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp sqrt diff --git a/libc/nt/ntdll/sscanf.s b/libc/nt/ntdll/sscanf.s deleted file mode 100644 index 31e921f65..000000000 --- a/libc/nt/ntdll/sscanf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp sscanf diff --git a/libc/nt/ntdll/sscanf_s.s b/libc/nt/ntdll/sscanf_s.s deleted file mode 100644 index 5ccd0c879..000000000 --- a/libc/nt/ntdll/sscanf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp sscanf_s diff --git a/libc/nt/ntdll/strcat.s b/libc/nt/ntdll/strcat.s deleted file mode 100644 index 9030d1547..000000000 --- a/libc/nt/ntdll/strcat.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strcat diff --git a/libc/nt/ntdll/strcat_s.s b/libc/nt/ntdll/strcat_s.s deleted file mode 100644 index 519507596..000000000 --- a/libc/nt/ntdll/strcat_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strcat_s diff --git a/libc/nt/ntdll/strchr.s b/libc/nt/ntdll/strchr.s deleted file mode 100644 index 148957c20..000000000 --- a/libc/nt/ntdll/strchr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strchr diff --git a/libc/nt/ntdll/strcmp.s b/libc/nt/ntdll/strcmp.s deleted file mode 100644 index 8c9c12403..000000000 --- a/libc/nt/ntdll/strcmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strcmp diff --git a/libc/nt/ntdll/strcpy.s b/libc/nt/ntdll/strcpy.s deleted file mode 100644 index 2b15bf99a..000000000 --- a/libc/nt/ntdll/strcpy.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strcpy diff --git a/libc/nt/ntdll/strcpy_s.s b/libc/nt/ntdll/strcpy_s.s deleted file mode 100644 index ee06532cf..000000000 --- a/libc/nt/ntdll/strcpy_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strcpy_s diff --git a/libc/nt/ntdll/strcspn.s b/libc/nt/ntdll/strcspn.s deleted file mode 100644 index 1e50f15b1..000000000 --- a/libc/nt/ntdll/strcspn.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strcspn diff --git a/libc/nt/ntdll/strlen.s b/libc/nt/ntdll/strlen.s deleted file mode 100644 index 935529289..000000000 --- a/libc/nt/ntdll/strlen.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strlen diff --git a/libc/nt/ntdll/strncat.s b/libc/nt/ntdll/strncat.s deleted file mode 100644 index acc90be95..000000000 --- a/libc/nt/ntdll/strncat.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strncat diff --git a/libc/nt/ntdll/strncat_s.s b/libc/nt/ntdll/strncat_s.s deleted file mode 100644 index 8407a9665..000000000 --- a/libc/nt/ntdll/strncat_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strncat_s diff --git a/libc/nt/ntdll/strncmp.s b/libc/nt/ntdll/strncmp.s deleted file mode 100644 index 220f11958..000000000 --- a/libc/nt/ntdll/strncmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strncmp diff --git a/libc/nt/ntdll/strncpy.s b/libc/nt/ntdll/strncpy.s deleted file mode 100644 index b8ebdc033..000000000 --- a/libc/nt/ntdll/strncpy.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strncpy diff --git a/libc/nt/ntdll/strncpy_s.s b/libc/nt/ntdll/strncpy_s.s deleted file mode 100644 index 33fa1d17e..000000000 --- a/libc/nt/ntdll/strncpy_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strncpy_s diff --git a/libc/nt/ntdll/strnlen.s b/libc/nt/ntdll/strnlen.s deleted file mode 100644 index a6ea8ef64..000000000 --- a/libc/nt/ntdll/strnlen.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strnlen diff --git a/libc/nt/ntdll/strpbrk.s b/libc/nt/ntdll/strpbrk.s deleted file mode 100644 index 28f7cd02c..000000000 --- a/libc/nt/ntdll/strpbrk.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strpbrk diff --git a/libc/nt/ntdll/strrchr.s b/libc/nt/ntdll/strrchr.s deleted file mode 100644 index 3c407175c..000000000 --- a/libc/nt/ntdll/strrchr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strrchr diff --git a/libc/nt/ntdll/strspn.s b/libc/nt/ntdll/strspn.s deleted file mode 100644 index 893c01122..000000000 --- a/libc/nt/ntdll/strspn.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strspn diff --git a/libc/nt/ntdll/strstr.s b/libc/nt/ntdll/strstr.s deleted file mode 100644 index 32696bace..000000000 --- a/libc/nt/ntdll/strstr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strstr diff --git a/libc/nt/ntdll/strtok_s.s b/libc/nt/ntdll/strtok_s.s deleted file mode 100644 index f8a8b9e41..000000000 --- a/libc/nt/ntdll/strtok_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strtok_s diff --git a/libc/nt/ntdll/strtol.s b/libc/nt/ntdll/strtol.s deleted file mode 100644 index 70e5b8628..000000000 --- a/libc/nt/ntdll/strtol.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strtol diff --git a/libc/nt/ntdll/strtoul.s b/libc/nt/ntdll/strtoul.s deleted file mode 100644 index 0e4ae1ec4..000000000 --- a/libc/nt/ntdll/strtoul.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp strtoul diff --git a/libc/nt/ntdll/swprintf.s b/libc/nt/ntdll/swprintf.s deleted file mode 100644 index a80315eb1..000000000 --- a/libc/nt/ntdll/swprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp swprintf diff --git a/libc/nt/ntdll/swprintf_s.s b/libc/nt/ntdll/swprintf_s.s deleted file mode 100644 index 095ad94f8..000000000 --- a/libc/nt/ntdll/swprintf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp swprintf_s diff --git a/libc/nt/ntdll/swscanf_s.s b/libc/nt/ntdll/swscanf_s.s deleted file mode 100644 index 78e3e9a08..000000000 --- a/libc/nt/ntdll/swscanf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp swscanf_s diff --git a/libc/nt/ntdll/tan.s b/libc/nt/ntdll/tan.s deleted file mode 100644 index 8441ce1a4..000000000 --- a/libc/nt/ntdll/tan.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp tan diff --git a/libc/nt/ntdll/tolower.s b/libc/nt/ntdll/tolower.s deleted file mode 100644 index 745a39a39..000000000 --- a/libc/nt/ntdll/tolower.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp tolower diff --git a/libc/nt/ntdll/toupper.s b/libc/nt/ntdll/toupper.s deleted file mode 100644 index b7f2f1456..000000000 --- a/libc/nt/ntdll/toupper.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp toupper diff --git a/libc/nt/ntdll/towlower.s b/libc/nt/ntdll/towlower.s deleted file mode 100644 index ba462a67d..000000000 --- a/libc/nt/ntdll/towlower.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp towlower diff --git a/libc/nt/ntdll/towupper.s b/libc/nt/ntdll/towupper.s deleted file mode 100644 index 8c066c6e1..000000000 --- a/libc/nt/ntdll/towupper.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp towupper diff --git a/libc/nt/ntdll/vDbgPrintEx.s b/libc/nt/ntdll/vDbgPrintEx.s deleted file mode 100644 index 60b395445..000000000 --- a/libc/nt/ntdll/vDbgPrintEx.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp vDbgPrintEx diff --git a/libc/nt/ntdll/vDbgPrintExWithPrefix.s b/libc/nt/ntdll/vDbgPrintExWithPrefix.s deleted file mode 100644 index 1222cbd20..000000000 --- a/libc/nt/ntdll/vDbgPrintExWithPrefix.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp vDbgPrintExWithPrefix diff --git a/libc/nt/ntdll/vsprintf.s b/libc/nt/ntdll/vsprintf.s deleted file mode 100644 index 514c99096..000000000 --- a/libc/nt/ntdll/vsprintf.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp vsprintf diff --git a/libc/nt/ntdll/vsprintf_s.s b/libc/nt/ntdll/vsprintf_s.s deleted file mode 100644 index d29daf33a..000000000 --- a/libc/nt/ntdll/vsprintf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp vsprintf_s diff --git a/libc/nt/ntdll/vswprintf_s.s b/libc/nt/ntdll/vswprintf_s.s deleted file mode 100644 index 2a1f9b33b..000000000 --- a/libc/nt/ntdll/vswprintf_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp vswprintf_s diff --git a/libc/nt/ntdll/wcscat.s b/libc/nt/ntdll/wcscat.s deleted file mode 100644 index 47b7e318a..000000000 --- a/libc/nt/ntdll/wcscat.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcscat diff --git a/libc/nt/ntdll/wcscat_s.s b/libc/nt/ntdll/wcscat_s.s deleted file mode 100644 index 0774f6377..000000000 --- a/libc/nt/ntdll/wcscat_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcscat_s diff --git a/libc/nt/ntdll/wcschr.s b/libc/nt/ntdll/wcschr.s deleted file mode 100644 index 65441f192..000000000 --- a/libc/nt/ntdll/wcschr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcschr diff --git a/libc/nt/ntdll/wcscmp.s b/libc/nt/ntdll/wcscmp.s deleted file mode 100644 index 24947caa2..000000000 --- a/libc/nt/ntdll/wcscmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcscmp diff --git a/libc/nt/ntdll/wcscpy.s b/libc/nt/ntdll/wcscpy.s deleted file mode 100644 index 232e55e75..000000000 --- a/libc/nt/ntdll/wcscpy.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcscpy diff --git a/libc/nt/ntdll/wcscpy_s.s b/libc/nt/ntdll/wcscpy_s.s deleted file mode 100644 index f8743bacc..000000000 --- a/libc/nt/ntdll/wcscpy_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcscpy_s diff --git a/libc/nt/ntdll/wcscspn.s b/libc/nt/ntdll/wcscspn.s deleted file mode 100644 index f8fa5adca..000000000 --- a/libc/nt/ntdll/wcscspn.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcscspn diff --git a/libc/nt/ntdll/wcslen.s b/libc/nt/ntdll/wcslen.s deleted file mode 100644 index 853b44281..000000000 --- a/libc/nt/ntdll/wcslen.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcslen diff --git a/libc/nt/ntdll/wcsncat.s b/libc/nt/ntdll/wcsncat.s deleted file mode 100644 index e727952c2..000000000 --- a/libc/nt/ntdll/wcsncat.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsncat diff --git a/libc/nt/ntdll/wcsncat_s.s b/libc/nt/ntdll/wcsncat_s.s deleted file mode 100644 index 358c3a591..000000000 --- a/libc/nt/ntdll/wcsncat_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsncat_s diff --git a/libc/nt/ntdll/wcsncmp.s b/libc/nt/ntdll/wcsncmp.s deleted file mode 100644 index 8bb3fff45..000000000 --- a/libc/nt/ntdll/wcsncmp.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsncmp diff --git a/libc/nt/ntdll/wcsncpy.s b/libc/nt/ntdll/wcsncpy.s deleted file mode 100644 index ce4275659..000000000 --- a/libc/nt/ntdll/wcsncpy.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsncpy diff --git a/libc/nt/ntdll/wcsncpy_s.s b/libc/nt/ntdll/wcsncpy_s.s deleted file mode 100644 index 395fd0150..000000000 --- a/libc/nt/ntdll/wcsncpy_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsncpy_s diff --git a/libc/nt/ntdll/wcsnlen.s b/libc/nt/ntdll/wcsnlen.s deleted file mode 100644 index 72f4a19dd..000000000 --- a/libc/nt/ntdll/wcsnlen.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsnlen diff --git a/libc/nt/ntdll/wcspbrk.s b/libc/nt/ntdll/wcspbrk.s deleted file mode 100644 index 725ee657e..000000000 --- a/libc/nt/ntdll/wcspbrk.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcspbrk diff --git a/libc/nt/ntdll/wcsrchr.s b/libc/nt/ntdll/wcsrchr.s deleted file mode 100644 index ddc9ded20..000000000 --- a/libc/nt/ntdll/wcsrchr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsrchr diff --git a/libc/nt/ntdll/wcsspn.s b/libc/nt/ntdll/wcsspn.s deleted file mode 100644 index a5d579d62..000000000 --- a/libc/nt/ntdll/wcsspn.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsspn diff --git a/libc/nt/ntdll/wcsstr.s b/libc/nt/ntdll/wcsstr.s deleted file mode 100644 index c8593e336..000000000 --- a/libc/nt/ntdll/wcsstr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcsstr diff --git a/libc/nt/ntdll/wcstok_s.s b/libc/nt/ntdll/wcstok_s.s deleted file mode 100644 index ef7843e51..000000000 --- a/libc/nt/ntdll/wcstok_s.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcstok_s diff --git a/libc/nt/ntdll/wcstol.s b/libc/nt/ntdll/wcstol.s deleted file mode 100644 index 9f39db066..000000000 --- a/libc/nt/ntdll/wcstol.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcstol diff --git a/libc/nt/ntdll/wcstombs.s b/libc/nt/ntdll/wcstombs.s deleted file mode 100644 index a8a678880..000000000 --- a/libc/nt/ntdll/wcstombs.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcstombs diff --git a/libc/nt/ntdll/wcstoul.s b/libc/nt/ntdll/wcstoul.s deleted file mode 100644 index 2af779ac1..000000000 --- a/libc/nt/ntdll/wcstoul.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/ntdllimport.inc" -.ntimp wcstoul diff --git a/libc/nt/ntdllimport.S b/libc/nt/ntdllimport.S index 5d8fceb62..d30bdf933 100644 --- a/libc/nt/ntdllimport.S +++ b/libc/nt/ntdllimport.S @@ -25,18 +25,18 @@ / that ensures executables won't fail to load in the future, / should Microsoft ever choose to delete these APIs. - .initro 202,_init_ntdll.1 + .initro 202,sys__init_ntdll.1 .type kNtdllProcRvas,@object kNtdllProcRvas: .previous/* ... decentralized content ... - */.initro 202,_init_ntdll.3 + */.initro 202,sys__init_ntdll.3 .quad 0 .previous - .init.start 202,_init_ntdll + .init.start 202,sys__init_ntdll push %r12 push %r13 lea ntdllmissingno(%rip),%r13 @@ -57,7 +57,7 @@ kNtdllProcRvas: 1: add $32,%rsp pop %r13 pop %r12 - .init.end 202,_init_ntdll,globl,hidden + .init.end 202,sys__init_ntdll,globl,hidden .text.windows ntdllmissingno: diff --git a/libc/nt/ntdllimport.h b/libc/nt/ntdllimport.h index d4248788a..675685458 100644 --- a/libc/nt/ntdllimport.h +++ b/libc/nt/ntdllimport.h @@ -6,13 +6,13 @@ /* clang-format off */ .macro .ntimp fn:req - yoink _init_ntdll - .initbss 202,_init_ntdll.\fn + yoink sys__init_ntdll + .initbss 202,sys__init_ntdll.\fn __imp_\fn: .quad 0 .endobj __imp_\fn,globl,hidden .previous - .initro 202,_init_ntdll.2.\fn + .initro 202,sys__init_ntdll.2.\fn .quad RVA(.L\fn) .previous .section .rodata.str1.1,"aSM",@progbits,1 diff --git a/libc/nt/struct/pollfd.h b/libc/nt/struct/pollfd.h index b8fc63234..5e71997cf 100644 --- a/libc/nt/struct/pollfd.h +++ b/libc/nt/struct/pollfd.h @@ -2,7 +2,7 @@ #define COSMOPOLITAN_LIBC_NT_STRUCT_POLLFD_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) -struct pollfd$nt { +struct sys_pollfd_nt { int64_t handle; int16_t events; int16_t revents; diff --git a/libc/nt/struct/teb.h b/libc/nt/struct/teb.h index 38d870229..cf1e7f008 100644 --- a/libc/nt/struct/teb.h +++ b/libc/nt/struct/teb.h @@ -3,6 +3,7 @@ #include "libc/bits/segmentation.h" #include "libc/nt/struct/peb.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) /* * These macros address directly into NT's TEB a.k.a. TIB @@ -22,5 +23,6 @@ #define _NtGetRpc() gs((void **)(0x50)) #define _NtGetTls() gs((void **)(0x58)) +#endif /* __GNUC__ && !__STRICT_ANSI__ */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_TEB_H_ */ diff --git a/libc/nt/synchronization.h b/libc/nt/synchronization.h index 8b6567559..764a2e854 100644 --- a/libc/nt/synchronization.h +++ b/libc/nt/synchronization.h @@ -59,8 +59,8 @@ uint32_t SleepEx(uint32_t dwMilliseconds, bool32 bAlertable); void GetSystemTime(struct NtSystemTime *lpSystemTime); bool32 SystemTimeToFileTime(const struct NtSystemTime *lpSystemTime, struct NtFileTime *lpFileTime); -void GetSystemTimeAsFileTime(struct NtFileTime *); // win8+ -void GetSystemTimePreciseAsFileTime(struct NtFileTime *); // win8+ +void GetSystemTimeAsFileTime(struct NtFileTime *); /* win8+ */ +void GetSystemTimePreciseAsFileTime(struct NtFileTime *); /* win8+ */ uint32_t WaitForSingleObject(int64_t hHandle, uint32_t dwMilliseconds); uint32_t WaitForMultipleObjects(uint32_t nCount, const int64_t *lpHandles, diff --git a/libc/nt/user32/wsprintfA.s b/libc/nt/user32/wsprintfA.s deleted file mode 100644 index 59fc8b677..000000000 --- a/libc/nt/user32/wsprintfA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp user32,__imp_wsprintfA,wsprintfA,2596 diff --git a/libc/nt/user32/wsprintfW.s b/libc/nt/user32/wsprintfW.s deleted file mode 100644 index fb207c7a1..000000000 --- a/libc/nt/user32/wsprintfW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp user32,__imp_wsprintfW,wsprintfW,2601 diff --git a/libc/nt/user32/wvsprintfA.s b/libc/nt/user32/wvsprintfA.s deleted file mode 100644 index 28aeda0cf..000000000 --- a/libc/nt/user32/wvsprintfA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp user32,__imp_wvsprintfA,wvsprintfA,2602 diff --git a/libc/nt/user32/wvsprintfW.s b/libc/nt/user32/wvsprintfW.s deleted file mode 100644 index 9fa280dc2..000000000 --- a/libc/nt/user32/wvsprintfW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp user32,__imp_wvsprintfW,wvsprintfW,2603 diff --git a/libc/nt/winsock.h b/libc/nt/winsock.h index 5cad3bc92..9be8aac38 100644 --- a/libc/nt/winsock.h +++ b/libc/nt/winsock.h @@ -326,16 +326,16 @@ int WSACleanup(void); int WSAGetLastError(void); void WSASetLastError(int); -int __bind$nt(uint64_t, const void *, int); -int __closesocket$nt(uint64_t); -int __getpeername$nt(uint64_t, void *, uint32_t *); -int __getsockname$nt(uint64_t, void *, uint32_t *); -int __getsockopt$nt(uint64_t, int, int, void *, uint32_t *); -int __ioctlsocket$nt(uint64_t, int32_t, uint32_t *); -int __listen$nt(uint64_t, int); -int __setsockopt$nt(uint64_t, int, int, const void *, int); -int __shutdown$nt(uint64_t, int); -int __select$nt(int, struct NtFdSet *, struct NtFdSet *, struct NtFdSet *, +int __sys_bind_nt(uint64_t, const void *, int); +int __sys_closesocket_nt(uint64_t); +int __sys_getpeername_nt(uint64_t, void *, uint32_t *); +int __sys_getsockname_nt(uint64_t, void *, uint32_t *); +int __sys_getsockopt_nt(uint64_t, int, int, void *, uint32_t *); +int __sys_ioctlsocket_nt(uint64_t, int32_t, uint32_t *); +int __sys_listen_nt(uint64_t, int); +int __sys_setsockopt_nt(uint64_t, int, int, const void *, int); +int __sys_shutdown_nt(uint64_t, int); +int __sys_select_nt(int, struct NtFdSet *, struct NtFdSet *, struct NtFdSet *, struct NtTimeval *); uint64_t WSASocket(int af, int type, int protocol, @@ -393,7 +393,7 @@ int WSASendTo(uint64_t s, const struct NtIovec *lpBuffers, const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine) paramsnonnull((2)); -int WSAPoll(struct pollfd$nt *inout_fdArray, uint32_t nfds, signed timeout_ms) +int WSAPoll(struct sys_pollfd_nt *inout_fdArray, uint32_t nfds, signed timeout_ms) paramsnonnull(); int WSARecv(uint64_t s, const struct NtIovec *out_lpBuffers, diff --git a/libc/nt/ws2_32/bind.s b/libc/nt/ws2_32/bind.s index f41c85c0b..61b2d996c 100644 --- a/libc/nt/ws2_32/bind.s +++ b/libc/nt/ws2_32/bind.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_bind,bind,2 .text.windows -__bind$nt: +__sys_bind_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_bind(%rip),%rax jmp __sysv2nt - .endfn __bind$nt,globl + .endfn __sys_bind_nt,globl .previous diff --git a/libc/nt/ws2_32/closesocket.s b/libc/nt/ws2_32/closesocket.s index dd3331384..9bd7862c2 100644 --- a/libc/nt/ws2_32/closesocket.s +++ b/libc/nt/ws2_32/closesocket.s @@ -2,7 +2,7 @@ .imp ws2_32,__imp_closesocket,closesocket,3 .text.windows -__closesocket$nt: +__sys_closesocket_nt: push %rbp mov %rsp,%rbp .profilable @@ -11,5 +11,5 @@ __closesocket$nt: call *__imp_closesocket(%rip) leave ret - .endfn __closesocket$nt,globl + .endfn __sys_closesocket_nt,globl .previous diff --git a/libc/nt/ws2_32/getpeername.s b/libc/nt/ws2_32/getpeername.s index 3bcc0b0c1..612b7389e 100644 --- a/libc/nt/ws2_32/getpeername.s +++ b/libc/nt/ws2_32/getpeername.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_getpeername,getpeername,5 .text.windows -__getpeername$nt: +__sys_getpeername_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_getpeername(%rip),%rax jmp __sysv2nt - .endfn __getpeername$nt,globl + .endfn __sys_getpeername_nt,globl .previous diff --git a/libc/nt/ws2_32/getsockname.s b/libc/nt/ws2_32/getsockname.s index b3e878869..b9bb433aa 100644 --- a/libc/nt/ws2_32/getsockname.s +++ b/libc/nt/ws2_32/getsockname.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_getsockname,getsockname,6 .text.windows -__getsockname$nt: +__sys_getsockname_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_getsockname(%rip),%rax jmp __sysv2nt - .endfn __getsockname$nt,globl + .endfn __sys_getsockname_nt,globl .previous diff --git a/libc/nt/ws2_32/getsockopt.s b/libc/nt/ws2_32/getsockopt.s index fe9d7b5df..c02e46c6b 100644 --- a/libc/nt/ws2_32/getsockopt.s +++ b/libc/nt/ws2_32/getsockopt.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_getsockopt,getsockopt,7 .text.windows -__getsockopt$nt: +__sys_getsockopt_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_getsockopt(%rip),%rax jmp __sysv2nt6 - .endfn __getsockopt$nt,globl + .endfn __sys_getsockopt_nt,globl .previous diff --git a/libc/nt/ws2_32/htonl.s b/libc/nt/ws2_32/htonl.s deleted file mode 100644 index 0e2ce8eca..000000000 --- a/libc/nt/ws2_32/htonl.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp ws2_32,__imp_htonl,htonl,8 diff --git a/libc/nt/ws2_32/htons.s b/libc/nt/ws2_32/htons.s deleted file mode 100644 index 651a21c39..000000000 --- a/libc/nt/ws2_32/htons.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp ws2_32,__imp_htons,htons,9 diff --git a/libc/nt/ws2_32/inet_addr.s b/libc/nt/ws2_32/inet_addr.s deleted file mode 100644 index 4665fbd99..000000000 --- a/libc/nt/ws2_32/inet_addr.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp ws2_32,__imp_inet_addr,inet_addr,11 diff --git a/libc/nt/ws2_32/inet_ntoa.s b/libc/nt/ws2_32/inet_ntoa.s deleted file mode 100644 index 9ffc86f67..000000000 --- a/libc/nt/ws2_32/inet_ntoa.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp ws2_32,__imp_inet_ntoa,inet_ntoa,12 diff --git a/libc/nt/ws2_32/inet_ntop.s b/libc/nt/ws2_32/inet_ntop.s deleted file mode 100644 index 1ad0aaea3..000000000 --- a/libc/nt/ws2_32/inet_ntop.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp ws2_32,__imp_inet_ntop,inet_ntop,193 diff --git a/libc/nt/ws2_32/inet_pton.s b/libc/nt/ws2_32/inet_pton.s deleted file mode 100644 index 853936d20..000000000 --- a/libc/nt/ws2_32/inet_pton.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp ws2_32,__imp_inet_pton,inet_pton,194 diff --git a/libc/nt/ws2_32/ioctlsocket.s b/libc/nt/ws2_32/ioctlsocket.s index 008b1099d..73455b464 100644 --- a/libc/nt/ws2_32/ioctlsocket.s +++ b/libc/nt/ws2_32/ioctlsocket.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_ioctlsocket,ioctlsocket,10 .text.windows -__ioctlsocket$nt: +__sys_ioctlsocket_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_ioctlsocket(%rip),%rax jmp __sysv2nt - .endfn __ioctlsocket$nt,globl + .endfn __sys_ioctlsocket_nt,globl .previous diff --git a/libc/nt/ws2_32/listen.s b/libc/nt/ws2_32/listen.s index ffebfa4d8..f00b2fdd7 100644 --- a/libc/nt/ws2_32/listen.s +++ b/libc/nt/ws2_32/listen.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_listen,listen,13 .text.windows -__listen$nt: +__sys_listen_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_listen(%rip),%rax jmp __sysv2nt - .endfn __listen$nt,globl + .endfn __sys_listen_nt,globl .previous diff --git a/libc/nt/ws2_32/ntohl.s b/libc/nt/ws2_32/ntohl.s deleted file mode 100644 index 334821f3f..000000000 --- a/libc/nt/ws2_32/ntohl.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp ws2_32,__imp_ntohl,ntohl,14 diff --git a/libc/nt/ws2_32/ntohs.s b/libc/nt/ws2_32/ntohs.s deleted file mode 100644 index d61c94c4e..000000000 --- a/libc/nt/ws2_32/ntohs.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp ws2_32,__imp_ntohs,ntohs,15 diff --git a/libc/nt/ws2_32/select.s b/libc/nt/ws2_32/select.s index e38fa07f8..e101d1466 100644 --- a/libc/nt/ws2_32/select.s +++ b/libc/nt/ws2_32/select.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_select,select,18 .text.windows -__select$nt: +__sys_select_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_select(%rip),%rax jmp __sysv2nt6 - .endfn __select$nt,globl + .endfn __sys_select_nt,globl .previous diff --git a/libc/nt/ws2_32/setsockopt.s b/libc/nt/ws2_32/setsockopt.s index a334f22b4..70fb3ca75 100644 --- a/libc/nt/ws2_32/setsockopt.s +++ b/libc/nt/ws2_32/setsockopt.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_setsockopt,setsockopt,21 .text.windows -__setsockopt$nt: +__sys_setsockopt_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_setsockopt(%rip),%rax jmp __sysv2nt6 - .endfn __setsockopt$nt,globl + .endfn __sys_setsockopt_nt,globl .previous diff --git a/libc/nt/ws2_32/shutdown.s b/libc/nt/ws2_32/shutdown.s index 5f5233aa1..8494e7a22 100644 --- a/libc/nt/ws2_32/shutdown.s +++ b/libc/nt/ws2_32/shutdown.s @@ -2,11 +2,11 @@ .imp ws2_32,__imp_shutdown,shutdown,22 .text.windows -__shutdown$nt: +__sys_shutdown_nt: push %rbp mov %rsp,%rbp .profilable mov __imp_shutdown(%rip),%rax jmp __sysv2nt - .endfn __shutdown$nt,globl + .endfn __sys_shutdown_nt,globl .previous diff --git a/libc/rand/devrand.c b/libc/rand/devrand.c index e651aa57b..044cd7300 100644 --- a/libc/rand/devrand.c +++ b/libc/rand/devrand.c @@ -38,16 +38,16 @@ int devrand(void *buf, size_t size) { unsigned char *p, *pe; fd = -1; if (IsWindows()) return enosys(); - if ((fd = openat$sysv(AT_FDCWD, "/dev/urandom", O_RDONLY, 0)) == -1) { + if ((fd = sys_openat(AT_FDCWD, "/dev/urandom", O_RDONLY, 0)) == -1) { return -1; } p = buf; pe = p + size; while (p < pe) { - if ((rc = read$sysv(fd, p, pe - p)) == -1) break; + if ((rc = sys_read(fd, p, pe - p)) == -1) break; if (!(got = (size_t)rc)) break; p += got; } - close$sysv(fd); + sys_close(fd); return p == pe ? 0 : -1; } diff --git a/libc/rand/g_rando32.c b/libc/rand/g_rando32.c index cd6f4876a..79d9e7783 100644 --- a/libc/rand/g_rando32.c +++ b/libc/rand/g_rando32.c @@ -31,7 +31,7 @@ textstartup static void g_rando32_init() { for (; *auxvp; auxvp += 2) { if (*auxvp == AT_RANDOM) { uint8_t(*sysrandseed)[16] = (uint8_t(*)[16])auxvp[1]; - if (sysrandseed) g_rando32 ^= read32le(&(*sysrandseed)[8]); + if (sysrandseed) g_rando32 ^= READ32LE(&(*sysrandseed)[8]); return; } } diff --git a/libc/rand/g_rando64.c b/libc/rand/g_rando64.c index 089fbb61a..fa5722d2e 100644 --- a/libc/rand/g_rando64.c +++ b/libc/rand/g_rando64.c @@ -31,7 +31,7 @@ textstartup static void g_rando64_init() { for (; auxvp[0]; auxvp += 2) { if (auxvp[0] == AT_RANDOM) { uint8_t(*sysrandseed)[16] = (uint8_t(*)[16])auxvp[1]; - if (sysrandseed) g_rando64 ^= read64le(&(*sysrandseed)[0]); + if (sysrandseed) g_rando64 ^= READ64LE(&(*sysrandseed)[0]); return; } } diff --git a/libc/rand/getrandom.c b/libc/rand/getrandom.c index 69a99f415..95403ffe5 100644 --- a/libc/rand/getrandom.c +++ b/libc/rand/getrandom.c @@ -34,7 +34,7 @@ * from fallback sources no matter what */ ssize_t getrandom(void *buf, size_t size, unsigned flags) { - ssize_t rc = getrandom$sysv(buf, size, flags); + ssize_t rc = sys_getrandom(buf, size, flags); size_t i = rc == -1 ? 0 : (size_t)rc; if (i > size) abort(); if (i < size) { diff --git a/libc/rand/rand.mk b/libc/rand/rand.mk index 1fb297001..64dc2011c 100644 --- a/libc/rand/rand.mk +++ b/libc/rand/rand.mk @@ -25,6 +25,7 @@ LIBC_RAND_A_CHECKS = \ LIBC_RAND_A_DIRECTDEPS = \ LIBC_CALLS \ + LIBC_INTRIN \ LIBC_NEXGEN32E \ LIBC_NT_KERNEL32 \ LIBC_STR \ diff --git a/libc/runtime/abort-nt.c b/libc/runtime/abort-nt.c index 4491d2bb5..b78dd60fe 100644 --- a/libc/runtime/abort-nt.c +++ b/libc/runtime/abort-nt.c @@ -23,7 +23,7 @@ #include "libc/str/str.h" #include "libc/sysv/consts/sig.h" -textwindows wontreturn void abort$nt(void) { +textwindows wontreturn void sys_abort_nt(void) { siginfo_t info; memset(&info, 0, sizeof(info)); info.si_signo = SIGABRT; diff --git a/libc/runtime/abort.S b/libc/runtime/abort.S index a2a24c9c5..d43631663 100644 --- a/libc/runtime/abort.S +++ b/libc/runtime/abort.S @@ -48,7 +48,7 @@ abort: push %rbp pop (%rsi) xor %edx,%edx # don't care about old sigmask pushpop 4*4,%r10 # sizeof(sigset_t) for systemd - mov __NR_sigprocmask,%eax # sigprocmask$sysv is hookable + mov __NR_sigprocmask,%eax # sys_sigprocmask is hookable syscall mov __NR_getpid,%eax syscall @@ -56,5 +56,5 @@ abort: push %rbp mov SIGABRT,%esi mov __NR_kill,%eax syscall # avoid hook and less bt noise -2: call abort$nt +2: call sys_abort_nt .endfn abort,globl,protected diff --git a/libc/runtime/arch_prctl.c b/libc/runtime/arch_prctl.c index 4f784b66a..59fcc4972 100644 --- a/libc/runtime/arch_prctl.c +++ b/libc/runtime/arch_prctl.c @@ -40,9 +40,9 @@ * operating systems. */ -int arch_prctl$sysv(int, int64_t) hidden; +int sys_arch_prctl(int, int64_t) hidden; -static inline int arch_prctl$fsgsbase(int code, int64_t addr) { +static inline int arch_prctl_fsgsbase(int code, int64_t addr) { switch (code) { case ARCH_SET_GS: asm volatile("wrgsbase\t%0" : /* no outputs */ : "r"(addr)); @@ -61,7 +61,7 @@ static inline int arch_prctl$fsgsbase(int code, int64_t addr) { } } -static int arch_prctl$msr(int code, int64_t addr) { +static int arch_prctl_msr(int code, int64_t addr) { switch (code) { case ARCH_SET_GS: wrmsr(MSR_IA32_GS_BASE, addr); @@ -80,22 +80,22 @@ static int arch_prctl$msr(int code, int64_t addr) { } } -static int arch_prctl$freebsd(int code, int64_t addr) { +static int arch_prctl_freebsd(int code, int64_t addr) { switch (code) { case ARCH_GET_FS: - return arch_prctl$sysv(128, addr); + return sys_arch_prctl(128, addr); case ARCH_SET_FS: - return arch_prctl$sysv(129, addr); + return sys_arch_prctl(129, addr); case ARCH_GET_GS: - return arch_prctl$sysv(130, addr); + return sys_arch_prctl(130, addr); case ARCH_SET_GS: - return arch_prctl$sysv(131, addr); + return sys_arch_prctl(131, addr); default: return einval(); } } -static textsyscall int arch_prctl$xnu(int code, int64_t addr) { +static textsyscall int arch_prctl_xnu(int code, int64_t addr) { int ax; switch (code) { case ARCH_SET_GS: @@ -113,7 +113,7 @@ static textsyscall int arch_prctl$xnu(int code, int64_t addr) { } } -static textsyscall int arch_prctl$openbsd(int code, int64_t addr) { +static textsyscall int arch_prctl_openbsd(int code, int64_t addr) { int64_t rax; switch (code) { case ARCH_GET_FS: @@ -144,7 +144,7 @@ static struct InterruptibleCall g_fsgs_icall; * Don't bother. */ int arch_prctl(int code, int64_t addr) { - void *fn = arch_prctl$fsgsbase; + void *fn = arch_prctl_fsgsbase; if (!g_fsgs_once) { g_fsgs_once = true; if (X86_HAVE(FSGSBASE)) { @@ -162,21 +162,21 @@ int arch_prctl(int code, int64_t addr) { } } if (g_fsgs_once == 2) { - return arch_prctl$fsgsbase(code, addr); + return arch_prctl_fsgsbase(code, addr); } switch (__hostos) { case METAL: - return arch_prctl$msr(code, addr); + return arch_prctl_msr(code, addr); case FREEBSD: /* claims support but it appears not */ - return arch_prctl$freebsd(code, addr); + return arch_prctl_freebsd(code, addr); case OPENBSD: - return arch_prctl$openbsd(code, addr); + return arch_prctl_openbsd(code, addr); case LINUX: - return arch_prctl$sysv(code, addr); + return sys_arch_prctl(code, addr); case XNU: /* probably won't work */ - return arch_prctl$xnu(code, addr); + return arch_prctl_xnu(code, addr); default: return enosys(); } diff --git a/libc/runtime/directmap.c b/libc/runtime/directmap.c index c72769e18..c6d473c12 100644 --- a/libc/runtime/directmap.c +++ b/libc/runtime/directmap.c @@ -31,10 +31,10 @@ noasan struct DirectMap __mmap(void *addr, size_t size, unsigned prot, unsigned flags, int fd, int64_t off) { if (!IsWindows()) { - return (struct DirectMap){mmap$sysv(addr, size, prot, flags, fd, off), + return (struct DirectMap){sys_mmap(addr, size, prot, flags, fd, off), kNtInvalidHandleValue}; } else { - return __mmap$nt(addr, size, prot, + return __sys_mmap_nt(addr, size, prot, fd != -1 ? g_fds.p[fd].handle : kNtInvalidHandleValue, off); } diff --git a/libc/runtime/directmap.h b/libc/runtime/directmap.h index 4419c093b..8d4dda0ff 100644 --- a/libc/runtime/directmap.h +++ b/libc/runtime/directmap.h @@ -9,7 +9,7 @@ struct DirectMap { }; struct DirectMap __mmap(void *, size_t, unsigned, unsigned, int, int64_t); -struct DirectMap __mmap$nt(void *, size_t, unsigned, int64_t, int64_t); +struct DirectMap __sys_mmap_nt(void *, size_t, unsigned, int64_t, int64_t); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/runtime/directmapnt.c b/libc/runtime/directmapnt.c index 19833004b..a628c0ab7 100644 --- a/libc/runtime/directmapnt.c +++ b/libc/runtime/directmapnt.c @@ -25,7 +25,7 @@ #include "libc/runtime/directmap.h" #include "libc/sysv/consts/prot.h" -textwindows noasan struct DirectMap __mmap$nt(void *addr, size_t size, +textwindows noasan struct DirectMap __sys_mmap_nt(void *addr, size_t size, unsigned prot, int64_t handle, int64_t off) { struct DirectMap dm; diff --git a/libc/runtime/fork-nt.c b/libc/runtime/fork-nt.c index 4ecefb6b1..37799199b 100644 --- a/libc/runtime/fork-nt.c +++ b/libc/runtime/fork-nt.c @@ -97,7 +97,7 @@ textwindows noasan void WinMainForked(void) { size = ((uint64_t)(_mmi.p[i].y - _mmi.p[i].x) << 16) + FRAMESIZE; if (_mmi.p[i].flags & MAP_PRIVATE) { CloseHandle(_mmi.p[i].h); - _mmi.p[i].h = __mmap$nt(addr, size, _mmi.p[i].prot, -1, 0).maphandle; + _mmi.p[i].h = __sys_mmap_nt(addr, size, _mmi.p[i].prot, -1, 0).maphandle; ReadAll(reader, addr, size); } else { MapViewOfFileExNuma( @@ -111,13 +111,13 @@ textwindows noasan void WinMainForked(void) { ReadAll(reader, _edata, _end - _edata); CloseHandle(reader); CloseHandle(writer); - if (weaken(__wincrash$nt)) { - AddVectoredExceptionHandler(1, (void *)weaken(__wincrash$nt)); + if (weaken(__wincrash_nt)) { + AddVectoredExceptionHandler(1, (void *)weaken(__wincrash_nt)); } longjmp(jb, 1); } -textwindows int fork$nt(void) { +textwindows int sys_fork_nt(void) { jmp_buf jb; char exe[PATH_MAX]; int64_t reader, writer; diff --git a/libc/runtime/fork.c b/libc/runtime/fork.c index b578d9f8f..3199c8469 100644 --- a/libc/runtime/fork.c +++ b/libc/runtime/fork.c @@ -30,9 +30,9 @@ int fork(void) { int rc; if (!IsWindows()) { - rc = fork$sysv(); + rc = sys_fork(); } else { - rc = fork$nt(); + rc = sys_fork_nt(); } if (rc == 0) { __onfork(); diff --git a/libc/runtime/memtrack.h b/libc/runtime/memtrack.h index 6490e5e48..eab6a19e8 100644 --- a/libc/runtime/memtrack.h +++ b/libc/runtime/memtrack.h @@ -7,8 +7,8 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -#define _kAutomapStart 0x0000100080000000 // asan can't spread its poison here -#define _kAutomapSize 0x00000fff80000000 +#define _kAutomapStart 0x0000100080000000 /* asan can't spread its poison */ +#define _kAutomapSize 0x00000fff80000000 /* beyond the above mem address */ #define _kFixedmapStart 0x0000200000000000 /* diff --git a/libc/runtime/msync-nt.c b/libc/runtime/msync-nt.c index 43c0f3c58..72a309b1d 100644 --- a/libc/runtime/msync-nt.c +++ b/libc/runtime/msync-nt.c @@ -22,7 +22,7 @@ #include "libc/nt/memory.h" #include "libc/runtime/memtrack.h" -textwindows int msync$nt(void *addr, size_t size, int flags) { +textwindows int sys_msync_nt(void *addr, size_t size, int flags) { int x, y, l, r, i; x = ROUNDDOWN((intptr_t)addr, FRAMESIZE) >> 16; y = ROUNDDOWN((intptr_t)addr + size - 1, FRAMESIZE) >> 16; diff --git a/libc/runtime/msync.c b/libc/runtime/msync.c index 6359652da..060ce9a08 100644 --- a/libc/runtime/msync.c +++ b/libc/runtime/msync.c @@ -35,8 +35,8 @@ int msync(void *addr, size_t size, int flags) { assert(((flags & MS_SYNC) ^ (flags & MS_ASYNC)) || !(MS_SYNC && MS_ASYNC)); if (!IsWindows()) { - return msync$sysv(addr, size, flags); + return sys_msync(addr, size, flags); } else { - return msync$nt(addr, size, flags); + return sys_msync_nt(addr, size, flags); } } diff --git a/libc/runtime/munmap.c b/libc/runtime/munmap.c index 891c43db6..6a008e6bd 100644 --- a/libc/runtime/munmap.c +++ b/libc/runtime/munmap.c @@ -46,5 +46,5 @@ int munmap(void *addr, size_t size) { if (!ALIGNED(addr) || !CANONICAL(addr) || !size) return einval(); if (UntrackMemoryIntervals(addr, size) == -1) return -1; if (IsWindows()) return 0; - return munmap$sysv(addr, size); + return sys_munmap(addr, size); } diff --git a/libc/runtime/print.greg.c b/libc/runtime/print.greg.c index 7b176dd89..469a152a2 100644 --- a/libc/runtime/print.greg.c +++ b/libc/runtime/print.greg.c @@ -28,7 +28,7 @@ #define WasImported(SLOT) \ ((void *)*SLOT && *SLOT != (void *)&missingno /* see libc/crt/crt.S */) -static void __print$nt(const void *data, size_t len) { +static void __sys_print_nt(const void *data, size_t len) { int64_t hand; char xmm[256]; uint32_t wrote; @@ -51,7 +51,7 @@ static void __print$nt(const void *data, size_t len) { textsyscall void __print(const void *data, size_t len) { int64_t ax, ordinal; if (WasImported(__imp_WriteFile)) { - __print$nt(data, len); + __sys_print_nt(data, len); } else { ordinal = __NR_write > 0 ? __NR_write : IsXnu() ? 0x2000004 : 4; asm volatile("syscall" diff --git a/libc/runtime/vfork.S b/libc/runtime/vfork.S index 021160cd2..5d66a9e7d 100644 --- a/libc/runtime/vfork.S +++ b/libc/runtime/vfork.S @@ -37,7 +37,7 @@ vfork: #if SupportsWindows() testb IsWindows() - jnz fork$nt + jnz sys_fork_nt #endif mov __NR_vfork(%rip),%eax pop %rsi # saves return address in a register diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index d0e2e8944..00f8010a2 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -107,9 +107,9 @@ static noasan textwindows wontreturn void WinMainNew(void) { *(/*unconst*/ int *)&__hostos = WINDOWS; addr = NtGetVersion() < kNtVersionWindows10 ? 0xff00000 : 0x777000000000; size = ROUNDUP(STACKSIZE + sizeof(struct WinArgs), FRAMESIZE); - _mmi.p[0].h = - __mmap$nt((char *)addr, size, PROT_READ | PROT_WRITE | PROT_EXEC, -1, 0) - .maphandle; + _mmi.p[0].h = __sys_mmap_nt((char *)addr, size, + PROT_READ | PROT_WRITE | PROT_EXEC, -1, 0) + .maphandle; _mmi.p[0].x = addr >> 16; _mmi.p[0].y = (addr >> 16) + ((size >> 16) - 1); _mmi.p[0].prot = PROT_READ | PROT_WRITE | PROT_EXEC; @@ -167,7 +167,7 @@ static noasan textwindows wontreturn void WinMainNew(void) { noasan textwindows int64_t WinMain(int64_t hInstance, int64_t hPrevInstance, const char *lpCmdLine, int nCmdShow) { MakeLongDoubleLongAgain(); - if (weaken(winsockinit)) weaken(winsockinit)(); + if (weaken(__winsockinit)) weaken(__winsockinit)(); if (weaken(WinMainForked)) weaken(WinMainForked)(); WinMainNew(); } diff --git a/libc/sock/accept-nt.c b/libc/sock/accept-nt.c index 76aaaa332..f3f140231 100644 --- a/libc/sock/accept-nt.c +++ b/libc/sock/accept-nt.c @@ -27,19 +27,19 @@ #include "libc/sysv/consts/sock.h" #include "libc/sysv/errfuns.h" -textwindows int accept$nt(struct Fd *fd, void *addr, uint32_t *addrsize, +textwindows int sys_accept_nt(struct Fd *fd, void *addr, uint32_t *addrsize, int flags) { int64_t h; int client; uint32_t yes; for (;;) { - if (!WSAPoll(&(struct pollfd$nt){fd->handle, POLLIN}, 1, 1000)) continue; + if (!WSAPoll(&(struct sys_pollfd_nt){fd->handle, POLLIN}, 1, 1000)) continue; if ((client = __reservefd()) == -1) return -1; if ((h = WSAAccept(fd->handle, addr, (int32_t *)addrsize, 0, 0)) != -1) { if (flags & SOCK_NONBLOCK) { yes = 1; - if (__ioctlsocket$nt(g_fds.p[client].handle, FIONBIO, &yes) == -1) { - __closesocket$nt(g_fds.p[client].handle); + if (__sys_ioctlsocket_nt(g_fds.p[client].handle, FIONBIO, &yes) == -1) { + __sys_closesocket_nt(g_fds.p[client].handle); __releasefd(client); return __winsockerr(); } diff --git a/libc/sock/accept-sysv.c b/libc/sock/accept-sysv.c index b1a5afbf2..3d8b0d854 100644 --- a/libc/sock/accept-sysv.c +++ b/libc/sock/accept-sysv.c @@ -19,9 +19,9 @@ #include "libc/dce.h" #include "libc/sock/internal.h" -int accept$sysv(int server, void *addr, uint32_t *addrsize) { +int sys_accept(int server, void *addr, uint32_t *addrsize) { int client; - if ((client = __accept$sysv(server, addr, addrsize, 0)) != -1 && IsBsd()) { + if ((client = __sys_accept(server, addr, addrsize, 0)) != -1 && IsBsd()) { sockaddr2linux(addr); } return client; diff --git a/libc/sock/accept4-sysv.c b/libc/sock/accept4-sysv.c index 6f67da58e..84b9751f0 100644 --- a/libc/sock/accept4-sysv.c +++ b/libc/sock/accept4-sysv.c @@ -23,17 +23,16 @@ #define __NR_accept4_linux 0x0120 /* rhel5:enosysevil */ -int accept4$sysv(int server, void *addr, uint32_t *addrsize, int flags) { +int sys_accept4(int server, void *addr, uint32_t *addrsize, int flags) { static bool once, demodernize; int olderr, client; if (!flags || demodernize) goto TriedAndTrue; olderr = errno; - client = __accept4$sysv(server, addr, addrsize, flags); + client = __sys_accept4(server, addr, addrsize, flags); if (client == -1 && errno == ENOSYS) { errno = olderr; TriedAndTrue: - client = - fixupnewsockfd$sysv(__accept$sysv(server, addr, addrsize, 0), flags); + client = __fixupnewsockfd(__sys_accept(server, addr, addrsize, 0), flags); } else if (SupportsLinux() && !once) { once = true; if (client == __NR_accept4_linux) { diff --git a/libc/sock/accept4.c b/libc/sock/accept4.c index 9aaa36152..e92d3331e 100644 --- a/libc/sock/accept4.c +++ b/libc/sock/accept4.c @@ -37,9 +37,9 @@ int accept4(int fd, void *out_addr, uint32_t *inout_addrsize, int flags) { if (!out_addr) return efault(); if (!inout_addrsize) return efault(); if (!IsWindows()) { - return accept4$sysv(fd, out_addr, inout_addrsize, flags); + return sys_accept4(fd, out_addr, inout_addrsize, flags); } else if (__isfdkind(fd, kFdSocket)) { - return accept$nt(&g_fds.p[fd], out_addr, inout_addrsize, flags); + return sys_accept_nt(&g_fds.p[fd], out_addr, inout_addrsize, flags); } else { return ebadf(); } diff --git a/libc/sock/bind-nt.c b/libc/sock/bind-nt.c index 75c6ea5e8..616a60220 100644 --- a/libc/sock/bind-nt.c +++ b/libc/sock/bind-nt.c @@ -23,9 +23,9 @@ #include "libc/sock/yoink.inc" #include "libc/sysv/errfuns.h" -textwindows int bind$nt(struct Fd *fd, const void *addr, uint32_t addrsize) { +textwindows int sys_bind_nt(struct Fd *fd, const void *addr, uint32_t addrsize) { assert(fd->kind == kFdSocket); - if (__bind$nt(fd->handle, addr, addrsize) != -1) { + if (__sys_bind_nt(fd->handle, addr, addrsize) != -1) { return 0; } else { return __winsockerr(); diff --git a/libc/sock/bind.c b/libc/sock/bind.c index 496e74c34..28aecfd6a 100644 --- a/libc/sock/bind.c +++ b/libc/sock/bind.c @@ -38,17 +38,17 @@ int bind(int fd, const void *addr, uint32_t addrsize) { if (addrsize == sizeof(struct sockaddr_in)) { if (!IsWindows()) { if (!IsBsd()) { - return bind$sysv(fd, addr, addrsize); + return sys_bind(fd, addr, addrsize); } else { - struct sockaddr_in$bsd addr2; + struct sockaddr_in_bsd addr2; _Static_assert(sizeof(struct sockaddr_in) == - sizeof(struct sockaddr_in$bsd)); + sizeof(struct sockaddr_in_bsd)); memcpy(&addr2, addr, sizeof(struct sockaddr_in)); sockaddr2bsd(&addr2); - return bind$sysv(fd, &addr2, addrsize); + return sys_bind(fd, &addr2, addrsize); } } else if (__isfdkind(fd, kFdSocket)) { - return bind$nt(&g_fds.p[fd], addr, addrsize); + return sys_bind_nt(&g_fds.p[fd], addr, addrsize); } else { return ebadf(); } diff --git a/libc/sock/closesocket-nt.c b/libc/sock/closesocket-nt.c index 864ebef92..ee7b4c8ea 100644 --- a/libc/sock/closesocket-nt.c +++ b/libc/sock/closesocket-nt.c @@ -23,10 +23,10 @@ #include "libc/sock/yoink.inc" #include "libc/sysv/errfuns.h" -textwindows int closesocket$nt(int fd) { +textwindows int sys_closesocket_nt(int fd) { int rc; if (!__isfdkind(fd, kFdSocket)) return ebadf(); - if (__closesocket$nt(g_fds.p[fd].handle) != -1) { + if (__sys_closesocket_nt(g_fds.p[fd].handle) != -1) { rc = 0; } else { rc = __winsockerr(); diff --git a/libc/sock/connect-nt.c b/libc/sock/connect-nt.c index 3d98ed4bc..1481edfcf 100644 --- a/libc/sock/connect-nt.c +++ b/libc/sock/connect-nt.c @@ -23,9 +23,10 @@ #include "libc/sock/yoink.inc" #include "libc/sysv/errfuns.h" -textwindows int connect$nt(struct Fd *fd, const void *addr, uint32_t addrsize) { +textwindows int sys_connect_nt(struct Fd *fd, const void *addr, + uint32_t addrsize) { assert(fd->kind == kFdSocket); - return winsockblock( + return __winsockblock( fd->handle, FD_CONNECT_BIT, WSAConnect(fd->handle, addr, addrsize, NULL, NULL, NULL, NULL)); } diff --git a/libc/sock/connect-sysv.c b/libc/sock/connect-sysv.c index 72b22708a..5c546437f 100644 --- a/libc/sock/connect-sysv.c +++ b/libc/sock/connect-sysv.c @@ -21,16 +21,16 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -int connect$sysv(int fd, const void *addr, uint32_t addrsize) { +int sys_connect(int fd, const void *addr, uint32_t addrsize) { if (addrsize != sizeof(struct sockaddr_in)) return einval(); if (!IsBsd()) { - return __connect$sysv(fd, addr, addrsize); + return __sys_connect(fd, addr, addrsize); } else { - struct sockaddr_in$bsd addr2; + struct sockaddr_in_bsd addr2; _Static_assert(sizeof(struct sockaddr_in) == - sizeof(struct sockaddr_in$bsd)); + sizeof(struct sockaddr_in_bsd)); memcpy(&addr2, addr, sizeof(struct sockaddr_in)); sockaddr2bsd(&addr2); - return connect$sysv(fd, &addr2, addrsize); + return sys_connect(fd, &addr2, addrsize); } } diff --git a/libc/sock/connect.c b/libc/sock/connect.c index e41a9d98a..9cbb2515e 100644 --- a/libc/sock/connect.c +++ b/libc/sock/connect.c @@ -35,9 +35,9 @@ int connect(int fd, const void *addr, uint32_t addrsize) { if (!addr) return efault(); if (!IsWindows()) { - return connect$sysv(fd, addr, addrsize); + return sys_connect(fd, addr, addrsize); } else if (__isfdkind(fd, kFdSocket)) { - return connect$nt(&g_fds.p[fd], addr, addrsize); + return sys_connect_nt(&g_fds.p[fd], addr, addrsize); } else { return ebadf(); } diff --git a/libc/sock/epoll.c b/libc/sock/epoll.c index 63de0727e..42c0230b8 100644 --- a/libc/sock/epoll.c +++ b/libc/sock/epoll.c @@ -284,12 +284,12 @@ static int64_t reflock__keyed_event; static struct TsTree epoll__handle_tree; static textwindows void err_map_win_error(void) { - errno = MapDosErrorToErrno(GetLastError()); + errno = __dos2errno(GetLastError()); } static textwindows void err_set_win_error(uint32_t error) { SetLastError(error); - errno = MapDosErrorToErrno(error); + errno = __dos2errno(error); } static textwindows int err_check_handle(int64_t handle) { @@ -1318,7 +1318,7 @@ static textwindows struct PortState *port_state_from_handle_tree_node( return CONTAINOF(tree_node, struct PortState, handle_tree_node); } -static textwindows noinline int epoll_create1$nt(uint32_t flags) { +static textwindows noinline int sys_epoll_create1_nt(uint32_t flags) { int fd; int64_t ephnd; struct PortState *port_state; @@ -1344,13 +1344,13 @@ static textwindows noinline int epoll_create1$nt(uint32_t flags) { return fd; } -static textwindows noinline int epoll_ctl$nt(int epfd, int op, int fd, - struct epoll_event *ev) { +static textwindows noinline int sys_epoll_ctl_nt(int epfd, int op, int fd, + struct epoll_event *ev) { int r; struct PortState *port_state; struct TsTreeNode *tree_node; if (!IsWindows()) { - return epoll_ctl$sysv(epfd, op, fd, ev); + return sys_epoll_ctl(epfd, op, fd, ev); } else { if (wepoll_init() < 0) return -1; if (!__isfdopen(fd)) return ebadf(); @@ -1374,9 +1374,10 @@ static textwindows noinline int epoll_ctl$nt(int epfd, int op, int fd, } } -static textwindows noinline int epoll_wait$nt(int epfd, - struct epoll_event *events, - int maxevents, int timeoutms) { +static textwindows noinline int sys_epoll_wait_nt(int epfd, + struct epoll_event *events, + int maxevents, + int timeoutms) { int num_events; struct PortState *port_state; struct TsTreeNode *tree_node; @@ -1398,7 +1399,7 @@ err: return -1; } -static textwindows noinline int close$epoll$nt(int fd) { +static textwindows noinline int sys_close_epoll_nt(int fd) { struct PortState *port_state; struct TsTreeNode *tree_node; if (wepoll_init() < 0) return -1; @@ -1416,11 +1417,11 @@ err: return -1; } -int close$epoll(int fd) { +int sys_close_epoll(int fd) { if (!IsWindows()) { - return close$sysv(fd); + return sys_close(fd); } else { - return close$epoll$nt(fd); + return sys_close_epoll_nt(fd); } } @@ -1447,9 +1448,9 @@ int epoll_create1(int flags) { int fd; if (flags & ~O_CLOEXEC) return einval(); if (!IsWindows()) { - return __ensurefds(fixupnewfd$sysv(epoll_create$sysv(1337), flags)); + return __ensurefds(__fixupnewfd(sys_epoll_create(1337), flags)); } else { - return epoll_create1$nt(flags); + return sys_epoll_create1_nt(flags); } } @@ -1487,9 +1488,9 @@ int epoll_create1(int flags) { */ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev) { if (!IsWindows()) { - return epoll_ctl$sysv(epfd, op, fd, ev); + return sys_epoll_ctl(epfd, op, fd, ev); } else { - return epoll_ctl$nt(epfd, op, fd, ev); + return sys_epoll_ctl_nt(epfd, op, fd, ev); } } @@ -1504,8 +1505,8 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev) { int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeoutms) { if (!IsWindows()) { - return epoll_wait$sysv(epfd, events, maxevents, timeoutms); + return sys_epoll_wait(epfd, events, maxevents, timeoutms); } else { - return epoll_wait$nt(epfd, events, maxevents, timeoutms); + return sys_epoll_wait_nt(epfd, events, maxevents, timeoutms); } } diff --git a/libc/sock/fixupnewsockfd.c b/libc/sock/fixupnewsockfd.c index 174636512..f73bc85c6 100644 --- a/libc/sock/fixupnewsockfd.c +++ b/libc/sock/fixupnewsockfd.c @@ -26,7 +26,7 @@ * * @param fd of -1 means no-op */ -int fixupnewsockfd$sysv(int fd, int flags) { - return fixupnewfd$sysv(fd, (((flags & SOCK_CLOEXEC) ? O_CLOEXEC : 0) | - ((flags & SOCK_NONBLOCK) ? O_NONBLOCK : 0))); +int __fixupnewsockfd(int fd, int flags) { + return __fixupnewfd(fd, (((flags & SOCK_CLOEXEC) ? O_CLOEXEC : 0) | + ((flags & SOCK_NONBLOCK) ? O_NONBLOCK : 0))); } diff --git a/libc/sock/getpeername-nt.c b/libc/sock/getpeername-nt.c index 432c1d9c6..cee74ca31 100644 --- a/libc/sock/getpeername-nt.c +++ b/libc/sock/getpeername-nt.c @@ -24,10 +24,10 @@ #include "libc/sock/yoink.inc" #include "libc/sysv/errfuns.h" -textwindows int getpeername$nt(struct Fd *fd, void *out_addr, +textwindows int sys_getpeername_nt(struct Fd *fd, void *out_addr, uint32_t *out_addrsize) { assert(fd->kind == kFdSocket); - if (__getpeername$nt(fd->handle, out_addr, out_addrsize) != -1) { + if (__sys_getpeername_nt(fd->handle, out_addr, out_addrsize) != -1) { return 0; } else { return __winsockerr(); diff --git a/libc/sock/getpeername-sysv.c b/libc/sock/getpeername-sysv.c index 38e2acbd1..61160801e 100644 --- a/libc/sock/getpeername-sysv.c +++ b/libc/sock/getpeername-sysv.c @@ -19,8 +19,8 @@ #include "libc/dce.h" #include "libc/sock/internal.h" -int getpeername$sysv(int fd, void *out_addr, uint32_t *out_addrsize) { - int rc = __getpeername$sysv(fd, out_addr, out_addrsize); +int sys_getpeername(int fd, void *out_addr, uint32_t *out_addrsize) { + int rc = __sys_getpeername(fd, out_addr, out_addrsize); if (rc != -1 && IsBsd()) { sockaddr2linux(out_addr); } diff --git a/libc/sock/getpeername.c b/libc/sock/getpeername.c index 7cd6980e0..0da57eb99 100644 --- a/libc/sock/getpeername.c +++ b/libc/sock/getpeername.c @@ -29,9 +29,9 @@ */ int getpeername(int fd, void *out_addr, uint32_t *out_addrsize) { if (!IsWindows()) { - return getpeername$sysv(fd, out_addr, out_addrsize); + return sys_getpeername(fd, out_addr, out_addrsize); } else if (__isfdkind(fd, kFdSocket)) { - return getpeername$nt(&g_fds.p[fd], out_addr, out_addrsize); + return sys_getpeername_nt(&g_fds.p[fd], out_addr, out_addrsize); } else { return ebadf(); } diff --git a/libc/sock/getsockname-nt.c b/libc/sock/getsockname-nt.c index 99d06166f..765c3357a 100644 --- a/libc/sock/getsockname-nt.c +++ b/libc/sock/getsockname-nt.c @@ -24,10 +24,10 @@ #include "libc/sock/yoink.inc" #include "libc/sysv/errfuns.h" -textwindows int getsockname$nt(struct Fd *fd, void *out_addr, +textwindows int sys_getsockname_nt(struct Fd *fd, void *out_addr, uint32_t *out_addrsize) { assert(fd->kind == kFdSocket); - if (__getsockname$nt(fd->handle, out_addr, out_addrsize) != -1) { + if (__sys_getsockname_nt(fd->handle, out_addr, out_addrsize) != -1) { return 0; } else { return __winsockerr(); diff --git a/libc/sock/getsockname-sysv.c b/libc/sock/getsockname-sysv.c index 3e6b41bcc..f62259e05 100644 --- a/libc/sock/getsockname-sysv.c +++ b/libc/sock/getsockname-sysv.c @@ -19,8 +19,8 @@ #include "libc/dce.h" #include "libc/sock/internal.h" -int getsockname$sysv(int fd, void *out_addr, uint32_t *out_addrsize) { - int rc = __getsockname$sysv(fd, out_addr, out_addrsize); +int sys_getsockname(int fd, void *out_addr, uint32_t *out_addrsize) { + int rc = __sys_getsockname(fd, out_addr, out_addrsize); if (rc != -1 && IsBsd()) { sockaddr2linux(out_addr); } diff --git a/libc/sock/getsockname.c b/libc/sock/getsockname.c index de5792354..70409656b 100644 --- a/libc/sock/getsockname.c +++ b/libc/sock/getsockname.c @@ -29,9 +29,9 @@ */ int getsockname(int fd, void *out_addr, uint32_t *out_addrsize) { if (!IsWindows()) { - return getsockname$sysv(fd, out_addr, out_addrsize); + return sys_getsockname(fd, out_addr, out_addrsize); } else if (__isfdkind(fd, kFdSocket)) { - return getsockname$nt(&g_fds.p[fd], out_addr, out_addrsize); + return sys_getsockname_nt(&g_fds.p[fd], out_addr, out_addrsize); } else { return ebadf(); } diff --git a/libc/sock/getsockopt-nt.c b/libc/sock/getsockopt-nt.c index 0d96b9ab7..7f589a176 100644 --- a/libc/sock/getsockopt-nt.c +++ b/libc/sock/getsockopt-nt.c @@ -23,11 +23,11 @@ #include "libc/sock/yoink.inc" #include "libc/sysv/errfuns.h" -textwindows int getsockopt$nt(struct Fd *fd, int level, int optname, +textwindows int sys_getsockopt_nt(struct Fd *fd, int level, int optname, void *out_opt_optval, uint32_t *out_optlen) { /* TODO(jart): Use WSAIoctl? */ assert(fd->kind == kFdSocket); - if (__getsockopt$nt(fd->handle, level, optname, out_opt_optval, out_optlen) != + if (__sys_getsockopt_nt(fd->handle, level, optname, out_opt_optval, out_optlen) != -1) { return 0; } else { diff --git a/libc/sock/getsockopt.c b/libc/sock/getsockopt.c index 805979a06..2b5a9f673 100644 --- a/libc/sock/getsockopt.c +++ b/libc/sock/getsockopt.c @@ -37,9 +37,9 @@ int getsockopt(int fd, int level, int optname, void *out_opt_optval, if (!level || !optname) return enoprotoopt(); /* our sysvconsts definition */ if (optname == -1) return 0; /* our sysvconsts definition */ if (!IsWindows()) { - return getsockopt$sysv(fd, level, optname, out_opt_optval, out_optlen); + return sys_getsockopt(fd, level, optname, out_opt_optval, out_optlen); } else if (__isfdkind(fd, kFdSocket)) { - return getsockopt$nt(&g_fds.p[fd], level, optname, out_opt_optval, + return sys_getsockopt_nt(&g_fds.p[fd], level, optname, out_opt_optval, out_optlen); } else { return ebadf(); diff --git a/libc/sock/internal.h b/libc/sock/internal.h index 6aaeefd58..d568be9aa 100644 --- a/libc/sock/internal.h +++ b/libc/sock/internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_ #define COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_ -#ifndef __STRICT_ANSI__ #include "libc/bits/bits.h" +#include "libc/calls/internal.h" #include "libc/nt/winsock.h" #include "libc/sock/select.h" #include "libc/sock/sock.h" @@ -21,17 +21,13 @@ COSMOPOLITAN_C_START_ #define FD_CLOSE (1 << FD_CLOSE_BIT) #define FD_CLOSE_BIT 5 -struct Fd; -struct iovec; -struct timeval; - -struct sockaddr$bsd { +struct sockaddr_bsd { uint8_t sa_len; /* « different type */ uint8_t sa_family; /* « different type */ char sa_data[14]; }; -struct sockaddr_in$bsd { +struct sockaddr_in_bsd { uint8_t sin_len; /* « different type */ uint8_t sin_family; /* « different type */ uint16_t sin_port; @@ -39,7 +35,7 @@ struct sockaddr_in$bsd { uint8_t sin_zero[8]; }; -struct msghdr$bsd { +struct msghdr_bsd { void *msg_name; uint32_t msg_namelen; struct iovec *msg_iov; @@ -49,83 +45,81 @@ struct msghdr$bsd { uint32_t msg_flags; /* « different type */ }; -errno_t MapDosErrorToErrno(uint32_t); +errno_t __dos2errno(uint32_t); -int32_t __accept$sysv(int32_t, void *, uint32_t *, int) nodiscard hidden; -int32_t __accept4$sysv(int32_t, void *, uint32_t *, int) nodiscard hidden; -int32_t __connect$sysv(int32_t, const void *, uint32_t) hidden; -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 __sys_accept(int32_t, void *, uint32_t *, int) nodiscard hidden; +int32_t __sys_accept4(int32_t, void *, uint32_t *, int) nodiscard hidden; +int32_t __sys_connect(int32_t, const void *, uint32_t) hidden; +int32_t __sys_socket(int32_t, int32_t, int32_t) hidden; +int32_t __sys_getsockname(int32_t, void *, uint32_t *) hidden; +int32_t __sys_getpeername(int32_t, void *, uint32_t *) hidden; -int32_t accept4$sysv(int32_t, void *, uint32_t *, int) nodiscard hidden; -int32_t accept$sysv(int32_t, void *, uint32_t *) hidden; -int32_t bind$sysv(int32_t, const void *, uint32_t) hidden; -int32_t connect$sysv(int32_t, const void *, uint32_t) hidden; -int32_t getsockopt$sysv(int32_t, int32_t, int32_t, void *, uint32_t *) hidden; -int32_t listen$sysv(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 poll$sysv(struct pollfd *, uint64_t, signed) hidden; -int32_t shutdown$sysv(int32_t, int32_t) hidden; -int32_t socket$sysv(int32_t, int32_t, int32_t) hidden; -int64_t readv$sysv(int32_t, const struct iovec *, int32_t) hidden; -int64_t writev$sysv(int32_t, const struct iovec *, int32_t) hidden; -ssize_t recvfrom$sysv(int, void *, size_t, int, void *, uint32_t *) hidden; -ssize_t sendto$sysv(int, const void *, size_t, int, const void *, - uint32_t) hidden; -int32_t select$sysv(int32_t, fd_set *, fd_set *, fd_set *, - struct timeval *) hidden; -int setsockopt$sysv(int, int, int, const void *, uint32_t) hidden; -int32_t epoll_create$sysv(int32_t) hidden; -int32_t epoll_ctl$sysv(int32_t, int32_t, int32_t, void *) hidden; -int32_t epoll_wait$sysv(int32_t, void *, int32_t, int32_t) hidden; +int32_t sys_accept4(int32_t, void *, uint32_t *, int) nodiscard hidden; +int32_t sys_accept(int32_t, void *, uint32_t *) hidden; +int32_t sys_bind(int32_t, const void *, uint32_t) hidden; +int32_t sys_connect(int32_t, const void *, uint32_t) hidden; +int32_t sys_getsockopt(int32_t, int32_t, int32_t, void *, uint32_t *) hidden; +int32_t sys_listen(int32_t, int32_t) hidden; +int32_t sys_getsockname(int32_t, void *, uint32_t *) hidden; +int32_t sys_getpeername(int32_t, void *, uint32_t *) hidden; +int32_t sys_poll(struct pollfd *, uint64_t, signed) hidden; +int32_t sys_shutdown(int32_t, int32_t) hidden; +int32_t sys_socket(int32_t, int32_t, int32_t) hidden; +int64_t sys_readv(int32_t, const struct iovec *, int32_t) hidden; +int64_t sys_writev(int32_t, const struct iovec *, int32_t) hidden; +ssize_t sys_recvfrom(int, void *, size_t, int, void *, uint32_t *) hidden; +ssize_t sys_sendto(int, const void *, size_t, int, const void *, + uint32_t) hidden; +int32_t sys_select(int32_t, fd_set *, fd_set *, fd_set *, + struct timeval *) hidden; +int sys_setsockopt(int, int, int, const void *, uint32_t) hidden; +int32_t sys_epoll_create(int32_t) hidden; +int32_t sys_epoll_ctl(int32_t, int32_t, int32_t, void *) hidden; +int32_t sys_epoll_wait(int32_t, void *, int32_t, int32_t) hidden; -int poll$nt(struct pollfd *, uint64_t, uint64_t) hidden; -int getsockopt$nt(struct Fd *, int, int, void *, uint32_t *) hidden; -int getsockname$nt(struct Fd *, void *, uint32_t *) hidden; -int getpeername$nt(struct Fd *, void *, uint32_t *) hidden; -int listen$nt(struct Fd *, int) hidden; -int connect$nt(struct Fd *, const void *, uint32_t) hidden; -int bind$nt(struct Fd *, const void *, uint32_t); -int accept$nt(struct Fd *, void *, uint32_t *, int) hidden; -int closesocket$nt(int) hidden; -int socket$nt(int, int, int) hidden; -int select$nt(int, fd_set *, fd_set *, fd_set *, struct timeval *) hidden; -int shutdown$nt(struct Fd *, int) hidden; +int sys_poll_nt(struct pollfd *, uint64_t, uint64_t) hidden; +int sys_getsockopt_nt(struct Fd *, int, int, void *, uint32_t *) hidden; +int sys_getsockname_nt(struct Fd *, void *, uint32_t *) hidden; +int sys_getpeername_nt(struct Fd *, void *, uint32_t *) hidden; +int sys_listen_nt(struct Fd *, int) hidden; +int sys_connect_nt(struct Fd *, const void *, uint32_t) hidden; +int sys_bind_nt(struct Fd *, const void *, uint32_t); +int sys_accept_nt(struct Fd *, void *, uint32_t *, int) hidden; +int sys_closesocket_nt(int) hidden; +int sys_socket_nt(int, int, int) hidden; +int sys_select_nt(int, fd_set *, fd_set *, fd_set *, struct timeval *) hidden; +int sys_shutdown_nt(struct Fd *, int) hidden; -size_t iovec2nt(struct NtIovec[hasatleast 16], const struct iovec *, - size_t) hidden; -ssize_t sendto$nt(struct Fd *, const struct iovec *, size_t, uint32_t, void *, - uint32_t) hidden; -ssize_t recvfrom$nt(struct Fd *, const struct iovec *, size_t, uint32_t, void *, - uint32_t *) hidden; +size_t __iovec2nt(struct NtIovec[hasatleast 16], const struct iovec *, + size_t) hidden; +ssize_t sys_sendto_nt(struct Fd *, const struct iovec *, size_t, uint32_t, + void *, uint32_t) hidden; +ssize_t sys_recvfrom_nt(struct Fd *, const struct iovec *, size_t, uint32_t, + void *, uint32_t *) hidden; -void winsockinit(void) hidden; +void __winsockinit(void) hidden; int64_t __winsockerr(void) nocallback hidden; -int fixupnewsockfd$sysv(int, int) hidden; -ssize_t WinSendRecv(int64_t, void *, size_t, uint32_t, struct sockaddr *, - uint32_t *, bool) hidden; -int64_t winsockblock(int64_t, unsigned, int64_t) hidden; +int __fixupnewsockfd(int, int) hidden; +int64_t __winsockblock(int64_t, unsigned, int64_t) hidden; -int close$epoll(int) hidden; +int sys_close_epoll(int) hidden; /** - * Converts sockaddr (Linux/Windows) → sockaddr$bsd (XNU/BSD). + * Converts sockaddr (Linux/Windows) → sockaddr_bsd (XNU/BSD). */ forceinline void sockaddr2bsd(void *saddr) { uint8_t *p; uint16_t fam; if (saddr) { p = saddr; - fam = read16le(p); - p[0] = sizeof(struct sockaddr_in$bsd); + fam = READ16LE(p); + p[0] = sizeof(struct sockaddr_in_bsd); p[1] = fam; } } /** - * Converts sockaddr_in$bsd (XNU/BSD) → sockaddr (Linux/Windows). + * Converts sockaddr_in_bsd (XNU/BSD) → sockaddr (Linux/Windows). */ forceinline void sockaddr2linux(void *saddr) { uint8_t *p, fam; @@ -138,5 +132,4 @@ forceinline void sockaddr2linux(void *saddr) { COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* !ANSI */ #endif /* COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_ */ diff --git a/libc/sock/iovec2nt.c b/libc/sock/iovec2nt.c index 78c786c69..ba35fcd3a 100644 --- a/libc/sock/iovec2nt.c +++ b/libc/sock/iovec2nt.c @@ -28,8 +28,8 @@ * @return effective iovlen * @see IOV_MAX */ -textwindows size_t iovec2nt(struct NtIovec iovnt[hasatleast 16], - const struct iovec *iov, size_t iovlen) { +textwindows size_t __iovec2nt(struct NtIovec iovnt[hasatleast 16], + const struct iovec *iov, size_t iovlen) { size_t i, limit; for (limit = 0x7ffff000, i = 0; i < MIN(16, iovlen); ++i) { iovnt[i].buf = iov[i].iov_base; diff --git a/libc/sock/kntwsadata.c b/libc/sock/kntwsadata.c index bf21ef8fc..5a931f830 100644 --- a/libc/sock/kntwsadata.c +++ b/libc/sock/kntwsadata.c @@ -33,13 +33,13 @@ */ hidden struct NtWsaData kNtWsaData; -static textwindows void winsockfini(void) { +static textwindows void __winsockfini(void) { WSACleanup(); } -textwindows noasan void winsockinit(void) { +textwindows noasan void __winsockinit(void) { int rc; - atexit(winsockfini); + atexit(__winsockfini); if ((rc = WSAStartup(VERSION, &kNtWsaData)) != 0 || kNtWsaData.wVersion != VERSION) { ExitProcess(123); diff --git a/libc/sock/listen-nt.c b/libc/sock/listen-nt.c index ffe38dca9..be8800b4f 100644 --- a/libc/sock/listen-nt.c +++ b/libc/sock/listen-nt.c @@ -23,9 +23,9 @@ #include "libc/sock/yoink.inc" #include "libc/sysv/errfuns.h" -textwindows int listen$nt(struct Fd *fd, int backlog) { +textwindows int sys_listen_nt(struct Fd *fd, int backlog) { assert(fd->kind == kFdSocket); - if (__listen$nt(fd->handle, backlog) != -1) { + if (__sys_listen_nt(fd->handle, backlog) != -1) { return 0; } else { return __winsockerr(); diff --git a/libc/sock/listen.c b/libc/sock/listen.c index bf1875792..65c1465c1 100644 --- a/libc/sock/listen.c +++ b/libc/sock/listen.c @@ -35,9 +35,9 @@ */ int listen(int fd, int backlog) { if (!IsWindows()) { - return listen$sysv(fd, backlog); + return sys_listen(fd, backlog); } else if (__isfdkind(fd, kFdSocket)) { - return listen$nt(&g_fds.p[fd], backlog); + return sys_listen_nt(&g_fds.p[fd], backlog); } else { return ebadf(); } diff --git a/libc/sock/mapdoserrortoerrno.c b/libc/sock/mapdoserrortoerrno.c index 9109a58ca..ea901d5d7 100644 --- a/libc/sock/mapdoserrortoerrno.c +++ b/libc/sock/mapdoserrortoerrno.c @@ -23,7 +23,7 @@ /** * Translates Windows error using superset of consts.sh. */ -textwindows errno_t MapDosErrorToErrno(uint32_t error) { +textwindows errno_t __dos2errno(uint32_t error) { switch (error) { case kNtErrorModNotFound: return ENOSYS; diff --git a/libc/sock/poll-nt.c b/libc/sock/poll-nt.c index b9c5e68b4..f566a3b3d 100644 --- a/libc/sock/poll-nt.c +++ b/libc/sock/poll-nt.c @@ -26,11 +26,11 @@ #include "libc/sysv/consts/poll.h" #include "libc/sysv/errfuns.h" -textwindows int poll$nt(struct pollfd *fds, uint64_t nfds, uint64_t timeoutms) { +textwindows int sys_poll_nt(struct pollfd *fds, uint64_t nfds, uint64_t timeoutms) { int got; size_t i; uint64_t waitfor; - struct pollfd$nt ntfds[64]; + struct sys_pollfd_nt ntfds[64]; if (nfds > 64) return einval(); for (i = 0; i < nfds; ++i) { if (!__isfdkind(fds[i].fd, kFdSocket)) return ebadf(); diff --git a/libc/sock/poll.c b/libc/sock/poll.c index 6003c26d7..ab8c5a07f 100644 --- a/libc/sock/poll.c +++ b/libc/sock/poll.c @@ -38,8 +38,8 @@ */ int poll(struct pollfd *fds, uint64_t nfds, int32_t timeout_ms) { if (!IsWindows()) { - return poll$sysv(fds, nfds, timeout_ms); + return sys_poll(fds, nfds, timeout_ms); } else { - return poll$nt(fds, nfds, timeout_ms); + return sys_poll_nt(fds, nfds, timeout_ms); } } diff --git a/libc/sock/recvfrom-nt.c b/libc/sock/recvfrom-nt.c index 1a536152b..ac1f8a732 100644 --- a/libc/sock/recvfrom-nt.c +++ b/libc/sock/recvfrom-nt.c @@ -27,15 +27,16 @@ * @param fd must be a socket * @return number of bytes received, or -1 w/ errno */ -textwindows ssize_t recvfrom$nt(struct Fd *fd, const struct iovec *iov, - size_t iovlen, uint32_t flags, - void *opt_out_srcaddr, - uint32_t *opt_inout_srcaddrsize) { +textwindows ssize_t sys_recvfrom_nt(struct Fd *fd, const struct iovec *iov, + size_t iovlen, uint32_t flags, + void *opt_out_srcaddr, + uint32_t *opt_inout_srcaddrsize) { uint32_t got; struct NtIovec iovnt[16]; got = 0; - if (WSARecvFrom(fd->handle, iovnt, iovec2nt(iovnt, iov, iovlen), &got, &flags, - opt_out_srcaddr, opt_inout_srcaddrsize, NULL, NULL) != -1) { + if (WSARecvFrom(fd->handle, iovnt, __iovec2nt(iovnt, iov, iovlen), &got, + &flags, opt_out_srcaddr, opt_inout_srcaddrsize, NULL, + NULL) != -1) { return got; } else { return __winsockerr(); diff --git a/libc/sock/recvfrom.c b/libc/sock/recvfrom.c index 2c899e7df..8adcfa258 100644 --- a/libc/sock/recvfrom.c +++ b/libc/sock/recvfrom.c @@ -44,14 +44,14 @@ ssize_t recvfrom(int fd, void *buf, size_t size, uint32_t flags, void *opt_out_srcaddr, uint32_t *opt_inout_srcaddrsize) { ssize_t got; if (!IsWindows()) { - got = recvfrom$sysv(fd, buf, size, flags, opt_out_srcaddr, + got = sys_recvfrom(fd, buf, size, flags, opt_out_srcaddr, opt_inout_srcaddrsize); if (opt_out_srcaddr && IsBsd() && got != -1) { sockaddr2linux(opt_out_srcaddr); } return got; } else if (__isfdkind(fd, kFdSocket)) { - return recvfrom$nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, flags, + return sys_recvfrom_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, flags, opt_out_srcaddr, opt_inout_srcaddrsize); } else { return ebadf(); diff --git a/libc/sock/select-nt.c b/libc/sock/select-nt.c index e77c51bc3..971e27264 100644 --- a/libc/sock/select-nt.c +++ b/libc/sock/select-nt.c @@ -92,7 +92,7 @@ static struct NtTimeval *TimevalToNtTimeval(struct timeval *tv, } } -int select$nt(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, +int sys_select_nt(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { int n, rc; struct NtTimeval nttimeout, *nttimeoutp; @@ -102,7 +102,7 @@ int select$nt(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, ntwritefds = FdSetToNtFdSet(nfds, writefds); ntexceptfds = FdSetToNtFdSet(nfds, exceptfds); nttimeoutp = TimevalToNtTimeval(timeout, &nttimeout); - rc = __select$nt(0, ntreadfds, ntwritefds, ntexceptfds, nttimeoutp); + rc = __sys_select_nt(0, ntreadfds, ntwritefds, ntexceptfds, nttimeoutp); NtFdSetToFdSet(nfds, readfds, ntreadfds); NtFdSetToFdSet(nfds, writefds, ntwritefds); NtFdSetToFdSet(nfds, exceptfds, ntexceptfds); diff --git a/libc/sock/select.c b/libc/sock/select.c index a7e8d41c5..887872fcd 100644 --- a/libc/sock/select.c +++ b/libc/sock/select.c @@ -28,8 +28,8 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { if (!IsWindows()) { - return select$sysv(nfds, readfds, writefds, exceptfds, timeout); + return sys_select(nfds, readfds, writefds, exceptfds, timeout); } else { - return select$nt(nfds, readfds, writefds, exceptfds, timeout); + return sys_select_nt(nfds, readfds, writefds, exceptfds, timeout); } } diff --git a/libc/sock/sendfile.c b/libc/sock/sendfile.c index 794f9889c..65a065e2c 100644 --- a/libc/sock/sendfile.c +++ b/libc/sock/sendfile.c @@ -25,7 +25,7 @@ #include "libc/str/str.h" #include "libc/sysv/errfuns.h" -static textwindows ssize_t sendfile$linux2nt(int outfd, int infd, +static textwindows ssize_t sendfile_linux2nt(int outfd, int infd, int64_t *inout_opt_inoffset, size_t uptobytes) { struct NtOverlapped Overlapped; @@ -48,18 +48,18 @@ static textwindows ssize_t sendfile$linux2nt(int outfd, int infd, } } -static ssize_t sendfile$linux2netflix(int outfd, int infd, +static ssize_t sendfile_linux2netflix(int outfd, int infd, int64_t *inout_opt_inoffset, size_t uptobytes) { int sendfile$netflix(int32_t infd, int32_t outfd, int64_t offset, size_t nbytes, const void *opt_hdtr, int64_t *out_opt_sbytes, - int32_t flags) asm("sendfile$sysv") hidden; + int32_t flags) asm("sys_sendfile") hidden; int rc; int64_t offset, sbytes; if (inout_opt_inoffset) { offset = *inout_opt_inoffset; - } else if ((offset = lseek$sysv(infd, 0, SEEK_CUR)) == -1) { + } else if ((offset = sys_lseek(infd, 0, SEEK_CUR)) == -1) { return -1; } if ((rc = sendfile$netflix(infd, outfd, offset, uptobytes, NULL, &sbytes, @@ -90,11 +90,11 @@ ssize_t sendfile(int outfd, int infd, int64_t *inout_opt_inoffset, if (uptobytes > 0x7ffffffe /* Microsoft's off-by-one */) return eoverflow(); if (IsModeDbg() && uptobytes > 1) uptobytes >>= 1; if (IsLinux()) { - return sendfile$sysv(outfd, infd, inout_opt_inoffset, uptobytes); + return sys_sendfile(outfd, infd, inout_opt_inoffset, uptobytes); } else if (IsFreebsd() || IsXnu()) { - return sendfile$linux2netflix(outfd, infd, inout_opt_inoffset, uptobytes); + return sendfile_linux2netflix(outfd, infd, inout_opt_inoffset, uptobytes); } else if (IsWindows()) { - return sendfile$linux2nt(outfd, infd, inout_opt_inoffset, uptobytes); + return sendfile_linux2nt(outfd, infd, inout_opt_inoffset, uptobytes); } else { return copyfd(infd, inout_opt_inoffset, outfd, NULL, uptobytes, 0); } diff --git a/libc/sock/sendto-nt.c b/libc/sock/sendto-nt.c index 082a4846e..c2b034478 100644 --- a/libc/sock/sendto-nt.c +++ b/libc/sock/sendto-nt.c @@ -30,12 +30,12 @@ * @param fd must be a socket * @return number of bytes handed off, or -1 w/ errno */ -textwindows ssize_t sendto$nt(struct Fd *fd, const struct iovec *iov, - size_t iovlen, uint32_t flags, void *opt_in_addr, - uint32_t in_addrsize) { +textwindows ssize_t sys_sendto_nt(struct Fd *fd, const struct iovec *iov, + size_t iovlen, uint32_t flags, + void *opt_in_addr, uint32_t in_addrsize) { uint32_t sent; struct NtIovec iovnt[16]; - if (WSASendTo(fd->handle, iovnt, iovec2nt(iovnt, iov, iovlen), &sent, flags, + if (WSASendTo(fd->handle, iovnt, __iovec2nt(iovnt, iov, iovlen), &sent, flags, opt_in_addr, in_addrsize, NULL, NULL) != -1) { return sent; } else { diff --git a/libc/sock/sendto.c b/libc/sock/sendto.c index 52e522b98..014becaf9 100644 --- a/libc/sock/sendto.c +++ b/libc/sock/sendto.c @@ -46,19 +46,19 @@ */ ssize_t sendto(int fd, const void *buf, size_t size, uint32_t flags, const void *opt_addr, uint32_t addrsize) { - _Static_assert(sizeof(struct sockaddr_in) == sizeof(struct sockaddr_in$bsd)); + _Static_assert(sizeof(struct sockaddr_in) == sizeof(struct sockaddr_in_bsd)); if (!IsWindows()) { if (!IsBsd() || !opt_addr) { - return sendto$sysv(fd, buf, size, flags, opt_addr, addrsize); + return sys_sendto(fd, buf, size, flags, opt_addr, addrsize); } else { - struct sockaddr_in$bsd addr2; + struct sockaddr_in_bsd addr2; if (addrsize != sizeof(addr2)) return einval(); memcpy(&addr2, opt_addr, sizeof(struct sockaddr_in)); sockaddr2bsd(&addr2); - return sendto$sysv(fd, buf, size, flags, &addr2, addrsize); + return sys_sendto(fd, buf, size, flags, &addr2, addrsize); } } else if (__isfdkind(fd, kFdSocket)) { - return sendto$nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, flags, + return sys_sendto_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, flags, opt_addr, addrsize); } else { return ebadf(); diff --git a/libc/sock/setsockopt.c b/libc/sock/setsockopt.c index 45a39dfe2..adc808662 100644 --- a/libc/sock/setsockopt.c +++ b/libc/sock/setsockopt.c @@ -33,9 +33,9 @@ static bool setsockopt_polyfill(int *optname) { return false; } -static textwindows int setsockopt$nt(struct Fd *fd, int level, int optname, +static textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname, const void *optval, uint32_t optlen) { - if (__setsockopt$nt(fd->handle, level, optname, optval, optlen) != -1) { + if (__sys_setsockopt_nt(fd->handle, level, optname, optval, optlen) != -1) { return 0; } else { return __winsockerr(); @@ -64,13 +64,13 @@ int setsockopt(int fd, int level, int optname, const void *optval, if (optname == -1) return 0; /* our sysvconsts definition */ if (!IsWindows()) { do { - if (setsockopt$sysv(fd, level, optname, optval, optlen) != -1) { + if (sys_setsockopt(fd, level, optname, optval, optlen) != -1) { return 0; } } while (setsockopt_polyfill(&optname)); return -1; } else if (__isfdkind(fd, kFdSocket)) { - return setsockopt$nt(&g_fds.p[fd], level, optname, optval, optlen); + return sys_setsockopt_nt(&g_fds.p[fd], level, optname, optval, optlen); } else { return ebadf(); } diff --git a/libc/sock/shutdown-nt.c b/libc/sock/shutdown-nt.c index 3dde5fb15..d6433526b 100644 --- a/libc/sock/shutdown-nt.c +++ b/libc/sock/shutdown-nt.c @@ -20,8 +20,8 @@ #include "libc/nt/winsock.h" #include "libc/sock/internal.h" -textwindows int shutdown$nt(struct Fd *fd, int how) { - if (__shutdown$nt(fd->handle, how) != -1) { +textwindows int sys_shutdown_nt(struct Fd *fd, int how) { + if (__sys_shutdown_nt(fd->handle, how) != -1) { return 0; } else { return __winsockerr(); diff --git a/libc/sock/shutdown.c b/libc/sock/shutdown.c index c0f2ca868..2183b2f2f 100644 --- a/libc/sock/shutdown.c +++ b/libc/sock/shutdown.c @@ -32,9 +32,9 @@ */ int shutdown(int fd, int how) { if (!IsWindows()) { - return shutdown$sysv(fd, how); + return sys_shutdown(fd, how); } else if (__isfdkind(fd, kFdSocket)) { - return shutdown$nt(&g_fds.p[fd], how); + return sys_shutdown_nt(&g_fds.p[fd], how); } else { return ebadf(); } diff --git a/libc/sock/socket-nt.c b/libc/sock/socket-nt.c index 31254eb40..fc199f5a0 100644 --- a/libc/sock/socket-nt.c +++ b/libc/sock/socket-nt.c @@ -26,7 +26,7 @@ #define CLOEXEC 0x00080000 #define NONBLOCK 0x00000800 -textwindows int socket$nt(int family, int type, int protocol) { +textwindows int sys_socket_nt(int family, int type, int protocol) { int fd; uint32_t yes; if ((fd = __reservefd()) == -1) return -1; @@ -34,8 +34,8 @@ textwindows int socket$nt(int family, int type, int protocol) { protocol, NULL, 0, 0)) != -1) { if (type & NONBLOCK) { yes = 1; - if (__ioctlsocket$nt(g_fds.p[fd].handle, FIONBIO, &yes) == -1) { - __closesocket$nt(g_fds.p[fd].handle); + if (__sys_ioctlsocket_nt(g_fds.p[fd].handle, FIONBIO, &yes) == -1) { + __sys_closesocket_nt(g_fds.p[fd].handle); return __winsockerr(); } } diff --git a/libc/sock/socket-sysv.c b/libc/sock/socket-sysv.c index 42c7541ad..c40cab59c 100644 --- a/libc/sock/socket-sysv.c +++ b/libc/sock/socket-sysv.c @@ -21,16 +21,16 @@ #include "libc/sock/internal.h" #include "libc/sysv/consts/sock.h" -int socket$sysv(int family, int type, int protocol) { +int sys_socket(int family, int type, int protocol) { int rc, olderr, modernflags; olderr = errno; - rc = __socket$sysv(family, type, protocol); + rc = __sys_socket(family, type, protocol); if ((SupportsLinux() || SupportsXnu()) && (rc == -1 && errno == EINVAL /* rhel5 behavior */) && (modernflags = (type & (SOCK_CLOEXEC | SOCK_NONBLOCK)))) { errno = olderr; - rc = fixupnewsockfd$sysv( - __socket$sysv(family, type & ~modernflags, protocol), modernflags); + rc = __fixupnewsockfd(__sys_socket(family, type & ~modernflags, protocol), + modernflags); } return rc; } diff --git a/libc/sock/socket.c b/libc/sock/socket.c index d086df1e4..af0c96a36 100644 --- a/libc/sock/socket.c +++ b/libc/sock/socket.c @@ -45,8 +45,8 @@ int socket(int family, int type, int protocol) { return epfnosupport(); } if (!IsWindows()) { - return socket$sysv(family, type, protocol); + return sys_socket(family, type, protocol); } else { - return socket$nt(family, type, protocol); + return sys_socket_nt(family, type, protocol); } } diff --git a/libc/sock/winsockblock.c b/libc/sock/winsockblock.c index fada0f5ef..cacffa124 100644 --- a/libc/sock/winsockblock.c +++ b/libc/sock/winsockblock.c @@ -23,7 +23,7 @@ #include "libc/sock/sock.h" #include "libc/str/str.h" -textwindows int64_t winsockblock(int64_t fh, unsigned eventbit, int64_t rc) { +textwindows int64_t __winsockblock(int64_t fh, unsigned eventbit, int64_t rc) { int64_t eh; struct NtWsaNetworkEvents ev; if (rc != -1) return rc; diff --git a/libc/sock/winsockerr.c b/libc/sock/winsockerr.c index 870e21363..4d73176d6 100644 --- a/libc/sock/winsockerr.c +++ b/libc/sock/winsockerr.c @@ -24,6 +24,6 @@ * Error return path for winsock wrappers. */ textwindows int64_t __winsockerr(void) { - errno = MapDosErrorToErrno(WSAGetLastError()); + errno = __dos2errno(WSAGetLastError()); return -1; } diff --git a/libc/sock/xinet_ntop.c b/libc/sock/xinet_ntop.c index 0ae53b50f..ce1914156 100644 --- a/libc/sock/xinet_ntop.c +++ b/libc/sock/xinet_ntop.c @@ -29,7 +29,7 @@ * @param src is the binary-encoded address, e.g. &addr->sin_addr * @return allocated IP address string, which must be free()'d */ -char *xinet_ntop(int af, const void *src) { +char *sys_xinet_ntop(int af, const void *src) { char *res, ip[16]; if (inet_ntop(af, src, ip, sizeof(ip)) && (res = strdup(ip))) { return res; diff --git a/libc/sock/yoink.inc b/libc/sock/yoink.inc index 45d50cb40..f17e7eb2f 100644 --- a/libc/sock/yoink.inc +++ b/libc/sock/yoink.inc @@ -1,4 +1,4 @@ -STATIC_YOINK("kNtWsaData"); // for winmain -STATIC_YOINK("closesocket$nt"); // for close -STATIC_YOINK("recvfrom$nt"); // for readv -STATIC_YOINK("sendto$nt"); // for writev +STATIC_YOINK("kNtWsaData"); // for winmain +STATIC_YOINK("sys_closesocket_nt"); // for close +STATIC_YOINK("sys_recvfrom_nt"); // for readv +STATIC_YOINK("sys_sendto_nt"); // for writev diff --git a/libc/stdio/dirstream.c b/libc/stdio/dirstream.c index 8632e1574..d281432ba 100644 --- a/libc/stdio/dirstream.c +++ b/libc/stdio/dirstream.c @@ -65,7 +65,7 @@ struct dirstream { /** * FreeBSD getdents() and XNU getdirentries() ABI. */ -struct dirent$bsd { +struct dirent_bsd { uint32_t d_fileno; uint16_t d_reclen; uint8_t d_type; @@ -76,7 +76,7 @@ struct dirent$bsd { /** * OpenBSD getdents() ABI. */ -struct dirent$openbsd { +struct dirent_openbsd { uint64_t d_fileno; int64_t d_off; uint16_t d_reclen; @@ -86,7 +86,7 @@ struct dirent$openbsd { char d_name[256]; }; -static textwindows noinline DIR *opendir$nt(const char *name) { +static textwindows noinline DIR *opendir_nt(const char *name) { int len; DIR *res; char16_t name16[PATH_MAX]; @@ -106,7 +106,7 @@ static textwindows noinline DIR *opendir$nt(const char *name) { } } -static textwindows noinline struct dirent *readdir$nt(DIR *dir) { +static textwindows noinline struct dirent *readdir_nt(DIR *dir) { if (!dir->isdone) { memset(&dir->ent, 0, sizeof(dir->ent)); dir->ent.d_ino = 0; @@ -166,7 +166,7 @@ DIR *opendir(const char *name) { } return res; } else { - return opendir$nt(name); + return opendir_nt(name); } } @@ -204,8 +204,8 @@ struct dirent *readdir(DIR *dir) { int rc; long basep; struct dirent *ent; - struct dirent$bsd *bsd; - struct dirent$openbsd *obsd; + struct dirent_bsd *bsd; + struct dirent_openbsd *obsd; if (!IsWindows()) { if (dir->buf_pos >= dir->buf_end) { basep = dir->tell; /* <- what does xnu do */ @@ -219,7 +219,7 @@ struct dirent *readdir(DIR *dir) { dir->buf_pos += ent->d_reclen; dir->tell = ent->d_off; } else if (IsOpenbsd()) { - obsd = (struct dirent$openbsd *)(dir->buf + dir->buf_pos); + obsd = (struct dirent_openbsd *)(dir->buf + dir->buf_pos); dir->buf_pos += obsd->d_reclen; ent = &dir->ent; ent->d_ino = obsd->d_fileno; @@ -228,7 +228,7 @@ struct dirent *readdir(DIR *dir) { ent->d_type = obsd->d_type; memcpy(ent->d_name, obsd->d_name, obsd->d_namlen + 1); } else { - bsd = (struct dirent$bsd *)(dir->buf + dir->buf_pos); + bsd = (struct dirent_bsd *)(dir->buf + dir->buf_pos); dir->buf_pos += bsd->d_reclen; ent = &dir->ent; ent->d_ino = bsd->d_fileno; @@ -239,7 +239,7 @@ struct dirent *readdir(DIR *dir) { } return ent; } else { - return readdir$nt(dir); + return readdir_nt(dir); } } diff --git a/libc/stdio/stdio.h b/libc/stdio/stdio.h index 7fc71fff4..583de9738 100644 --- a/libc/stdio/stdio.h +++ b/libc/stdio/stdio.h @@ -10,19 +10,19 @@ COSMOPOLITAN_C_START_ ╚────────────────────────────────────────────────────────────────────────────│*/ typedef struct FILE { - uint8_t bufmode; // 0x00 _IOFBF, etc. (ignored if fd=-1) - bool noclose; // 0x01 for fake dup() - uint32_t iomode; // 0x04 O_RDONLY, etc. (ignored if fd=-1) - int32_t state; // 0x08 0=OK, -1=EOF, >0=errno - int fd; // 0x0c ≥0=fd, -1=closed|buffer - uint32_t beg; // 0x10 - uint32_t end; // 0x14 - uint8_t *buf; // 0x18 - uint32_t size; // 0x20 - uint32_t nofree; // 0x24 - int (*reader)(struct FILE *); // 0x28 - int (*writer)(struct FILE *); // 0x30 - int pid; // 0x34 + uint8_t bufmode; /* 0x00 _IOFBF, etc. (ignored if fd=-1) */ + bool noclose; /* 0x01 for fake dup() */ + uint32_t iomode; /* 0x04 O_RDONLY, etc. (ignored if fd=-1) */ + int32_t state; /* 0x08 0=OK, -1=EOF, >0=errno */ + int fd; /* 0x0c ≥0=fd, -1=closed|buffer */ + uint32_t beg; /* 0x10 */ + uint32_t end; /* 0x14 */ + uint8_t *buf; /* 0x18 */ + uint32_t size; /* 0x20 */ + uint32_t nofree; /* 0x24 */ + int (*reader)(struct FILE *); /* 0x28 */ + int (*writer)(struct FILE *); /* 0x30 */ + int pid; /* 0x34 */ } FILE; extern FILE *stdin; diff --git a/libc/str/lz4cpy.c b/libc/str/lz4cpy.c index bedca8cce..8f3e3add7 100644 --- a/libc/str/lz4cpy.c +++ b/libc/str/lz4cpy.c @@ -45,7 +45,7 @@ textstartup void *lz4cpy(void *dest, const void *blockdata, size_t blocksize) { } repmovsb(&op, &ip, length); if (ip >= ipe) break; - offset = read16le(ip); + offset = READ16LE(ip); matchlen = token & fifteen; ip += 2; if (matchlen == fifteen) { diff --git a/libc/str/str.h b/libc/str/str.h index 5def2bd4e..e71ad7d8d 100644 --- a/libc/str/str.h +++ b/libc/str/str.h @@ -181,6 +181,7 @@ compatfn wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque; int timingsafe_memcmp(const void *, const void *, size_t); void *memmem(const void *, size_t, const void *, size_t) paramsnonnull() nothrow nocallback nosideeffect; +char *strerror(int) returnsnonnull nothrow nocallback; char *tinystrstr(const char *, const char *) strlenesque; char16_t *tinystrstr16(const char16_t *, const char16_t *) strlenesque; diff --git a/libc/str/undeflate.c b/libc/str/undeflate.c index 9c7523159..b79ed1e5a 100644 --- a/libc/str/undeflate.c +++ b/libc/str/undeflate.c @@ -69,8 +69,8 @@ static const struct DeflateConsts { {{144, 8}, {112, 9}, {24, 7}, {8, 8}, {32, 5}, {0, 0}}, }; -static noasan uint32_t undeflatetree(struct DeflateState *ds, uint32_t *tree, - const uint8_t *lens, size_t symcount) { +static uint32_t undeflatetree(struct DeflateState *ds, uint32_t *tree, + const uint8_t *lens, size_t symcount) { size_t i, len; uint32_t code, slot; uint16_t codes[16], first[16], counts[16]; @@ -96,10 +96,10 @@ static noasan uint32_t undeflatetree(struct DeflateState *ds, uint32_t *tree, return first[15]; } -static noasan struct DeflateHold undeflatesymbol(struct DeflateHold hold, - const uint32_t *tree, - size_t treecount, - uint32_t *out_symbol) { +static struct DeflateHold undeflatesymbol(struct DeflateHold hold, + const uint32_t *tree, + size_t treecount, + uint32_t *out_symbol) { size_t left, right, m; uint32_t search, key; left = 0; @@ -122,8 +122,6 @@ static noasan struct DeflateHold undeflatesymbol(struct DeflateHold hold, return hold; } -/* TODO(jart): Do we really need noasan? */ - /** * Decompresses raw DEFLATE data. * @@ -134,8 +132,8 @@ static noasan struct DeflateHold undeflatesymbol(struct DeflateHold hold, * are part of the design of this algorithm * @note h/t Phil Katz, David Huffman, Claude Shannon */ -noasan ssize_t undeflate(void *output, size_t outputsize, void *input, - size_t inputsize, struct DeflateState *ds) { +ssize_t undeflate(void *output, size_t outputsize, void *input, + size_t inputsize, struct DeflateState *ds) { struct DeflateHold hold; bool isfinalblock; size_t i, nlit, ndist; diff --git a/libc/stubs/xnu.S b/libc/stubs/xnu.S index 23ad0dd76..68ed799af 100644 --- a/libc/stubs/xnu.S +++ b/libc/stubs/xnu.S @@ -19,6 +19,5 @@ #include "libc/macros.h" .source __FILE__ -_start_xnu: - ud2 - .endfn _start_xnu,weak +_xnu: ud2 + .endfn _xnu,weak diff --git a/libc/sysv/calls/__accept-sysv.s b/libc/sysv/calls/__accept-sysv.s deleted file mode 100644 index 030a04879..000000000 --- a/libc/sysv/calls/__accept-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __accept$sysv 0x001e021d201e002b globl hidden diff --git a/libc/sysv/calls/__accept4-sysv.s b/libc/sysv/calls/__accept4-sysv.s deleted file mode 100644 index ed926bf1e..000000000 --- a/libc/sysv/calls/__accept4-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __accept4$sysv 0x005d021dffff0120 globl hidden diff --git a/libc/sysv/calls/__bsd_setegid.s b/libc/sysv/calls/__bsd_setegid.s new file mode 100644 index 000000000..a13fe9809 --- /dev/null +++ b/libc/sysv/calls/__bsd_setegid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __bsd_setegid 0x00b600b620b6ffff globl hidden diff --git a/libc/sysv/calls/__bsd_seteuid.s b/libc/sysv/calls/__bsd_seteuid.s new file mode 100644 index 000000000..5f1a083ae --- /dev/null +++ b/libc/sysv/calls/__bsd_seteuid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __bsd_seteuid 0x00b700b720b7ffff globl hidden diff --git a/libc/sysv/calls/__connect-sysv.s b/libc/sysv/calls/__connect-sysv.s deleted file mode 100644 index a5c2c1e5c..000000000 --- a/libc/sysv/calls/__connect-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __connect$sysv 0x006200622062002a globl hidden diff --git a/libc/sysv/calls/__dup3-sysv.s b/libc/sysv/calls/__dup3-sysv.s deleted file mode 100644 index f6387f08e..000000000 --- a/libc/sysv/calls/__dup3-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __dup3$sysv 0x0066ffffffff0124 globl hidden diff --git a/libc/sysv/calls/__execve-sysv.s b/libc/sysv/calls/__execve-sysv.s deleted file mode 100644 index bddbd0051..000000000 --- a/libc/sysv/calls/__execve-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __execve$sysv 0x003b003b203b003b globl hidden diff --git a/libc/sysv/calls/__fork-sysv.s b/libc/sysv/calls/__fork-sysv.s deleted file mode 100644 index 68c35c37f..000000000 --- a/libc/sysv/calls/__fork-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __fork$sysv 0x0002000220020039 globl hidden diff --git a/libc/sysv/calls/__fstat-sysv.s b/libc/sysv/calls/__fstat-sysv.s deleted file mode 100644 index 93cc758d5..000000000 --- a/libc/sysv/calls/__fstat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __fstat$sysv 0x0035022721530005 globl hidden diff --git a/libc/sysv/calls/__fstatat-sysv.s b/libc/sysv/calls/__fstatat-sysv.s deleted file mode 100644 index 272a20e5e..000000000 --- a/libc/sysv/calls/__fstatat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __fstatat$sysv 0x002a022821d60106 globl hidden diff --git a/libc/sysv/calls/__ftruncate-sysv.s b/libc/sysv/calls/__ftruncate-sysv.s deleted file mode 100644 index 5c4e48374..000000000 --- a/libc/sysv/calls/__ftruncate-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __ftruncate$sysv 0x00c901e020c9004d globl hidden diff --git a/libc/sysv/calls/__getpeername-sysv.s b/libc/sysv/calls/__getpeername-sysv.s deleted file mode 100644 index be60d3772..000000000 --- a/libc/sysv/calls/__getpeername-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __getpeername$sysv 0x001f008d201f0034 globl hidden diff --git a/libc/sysv/calls/__getsockname-sysv.s b/libc/sysv/calls/__getsockname-sysv.s deleted file mode 100644 index fba9bb1ce..000000000 --- a/libc/sysv/calls/__getsockname-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __getsockname$sysv 0x0020002020200033 globl hidden diff --git a/libc/sysv/calls/__gettimeofday-sysv.s b/libc/sysv/calls/__gettimeofday-sysv.s deleted file mode 100644 index bcb89e624..000000000 --- a/libc/sysv/calls/__gettimeofday-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __gettimeofday$sysv 0x0043007420740060 globl hidden diff --git a/libc/sysv/calls/__lseek-sysv.s b/libc/sysv/calls/__lseek-sysv.s deleted file mode 100644 index b95df615d..000000000 --- a/libc/sysv/calls/__lseek-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __lseek$sysv 0x00c701de20c70008 globl hidden diff --git a/libc/sysv/calls/__lstat-sysv.s b/libc/sysv/calls/__lstat-sysv.s deleted file mode 100644 index e1f2b9577..000000000 --- a/libc/sysv/calls/__lstat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __lstat$sysv 0x0028002821540006 globl hidden diff --git a/libc/sysv/calls/__mmap-sysv.s b/libc/sysv/calls/__mmap-sysv.s deleted file mode 100644 index df1a27965..000000000 --- a/libc/sysv/calls/__mmap-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __mmap$sysv 0x00c501dd20c50009 globl hidden diff --git a/libc/sysv/calls/__pipe-sysv.s b/libc/sysv/calls/__pipe-sysv.s deleted file mode 100644 index d2ad254cd..000000000 --- a/libc/sysv/calls/__pipe-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __pipe$sysv 0x0107021e202a0016 globl hidden diff --git a/libc/sysv/calls/__pipe2-sysv.s b/libc/sysv/calls/__pipe2-sysv.s deleted file mode 100644 index d8db06b7a..000000000 --- a/libc/sysv/calls/__pipe2-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __pipe2$sysv 0x0065021effff0125 globl hidden diff --git a/libc/sysv/calls/__pread-sysv.s b/libc/sysv/calls/__pread-sysv.s deleted file mode 100644 index 2cddd8d43..000000000 --- a/libc/sysv/calls/__pread-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __pread$sysv 0x00ad01db20990011 globl hidden diff --git a/libc/sysv/calls/__preadv-sysv.s b/libc/sysv/calls/__preadv-sysv.s deleted file mode 100644 index fc0005f53..000000000 --- a/libc/sysv/calls/__preadv-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __preadv$sysv 0x010b0121ffff0127 globl hidden diff --git a/libc/sysv/calls/__pwrite-sysv.s b/libc/sysv/calls/__pwrite-sysv.s deleted file mode 100644 index 8e61e8a18..000000000 --- a/libc/sysv/calls/__pwrite-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __pwrite$sysv 0x00ae01dc209a0012 globl hidden diff --git a/libc/sysv/calls/__pwritev-sysv.s b/libc/sysv/calls/__pwritev-sysv.s deleted file mode 100644 index 9e05b52bd..000000000 --- a/libc/sysv/calls/__pwritev-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __pwritev$sysv 0x010c0122ffff0128 globl hidden diff --git a/libc/sysv/calls/__setegid-bsd.s b/libc/sysv/calls/__setegid-bsd.s deleted file mode 100644 index 3df0458c8..000000000 --- a/libc/sysv/calls/__setegid-bsd.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __setegid$bsd 0x00b600b620b6ffff globl hidden diff --git a/libc/sysv/calls/__seteuid-bsd.s b/libc/sysv/calls/__seteuid-bsd.s deleted file mode 100644 index 0e91cf663..000000000 --- a/libc/sysv/calls/__seteuid-bsd.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __seteuid$bsd 0x00b700b720b7ffff globl hidden diff --git a/libc/sysv/calls/__socket-sysv.s b/libc/sysv/calls/__socket-sysv.s deleted file mode 100644 index fee2df701..000000000 --- a/libc/sysv/calls/__socket-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __socket$sysv 0x0061006120610029 globl hidden diff --git a/libc/sysv/calls/__stat-sysv.s b/libc/sysv/calls/__stat-sysv.s deleted file mode 100644 index eeee0c617..000000000 --- a/libc/sysv/calls/__stat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __stat$sysv 0x0026ffff21520004 globl hidden diff --git a/libc/sysv/calls/__sys_accept.s b/libc/sysv/calls/__sys_accept.s new file mode 100644 index 000000000..494b7274f --- /dev/null +++ b/libc/sysv/calls/__sys_accept.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_accept 0x001e021d201e002b globl hidden diff --git a/libc/sysv/calls/__sys_accept4.s b/libc/sysv/calls/__sys_accept4.s new file mode 100644 index 000000000..b8125d4b0 --- /dev/null +++ b/libc/sysv/calls/__sys_accept4.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_accept4 0x005d021dffff0120 globl hidden diff --git a/libc/sysv/calls/__sys_connect.s b/libc/sysv/calls/__sys_connect.s new file mode 100644 index 000000000..ea753bdd9 --- /dev/null +++ b/libc/sysv/calls/__sys_connect.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_connect 0x006200622062002a globl hidden diff --git a/libc/sysv/calls/__sys_dup3.s b/libc/sysv/calls/__sys_dup3.s new file mode 100644 index 000000000..d3b353f3f --- /dev/null +++ b/libc/sysv/calls/__sys_dup3.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_dup3 0x0066ffffffff0124 globl hidden diff --git a/libc/sysv/calls/__sys_execve.s b/libc/sysv/calls/__sys_execve.s new file mode 100644 index 000000000..c014295e0 --- /dev/null +++ b/libc/sysv/calls/__sys_execve.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_execve 0x003b003b203b003b globl hidden diff --git a/libc/sysv/calls/__sys_fork.s b/libc/sysv/calls/__sys_fork.s new file mode 100644 index 000000000..c3398e5db --- /dev/null +++ b/libc/sysv/calls/__sys_fork.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_fork 0x0002000220020039 globl hidden diff --git a/libc/sysv/calls/__sys_fstat.s b/libc/sysv/calls/__sys_fstat.s new file mode 100644 index 000000000..9968b54a7 --- /dev/null +++ b/libc/sysv/calls/__sys_fstat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_fstat 0x0035022721530005 globl hidden diff --git a/libc/sysv/calls/__sys_fstatat.s b/libc/sysv/calls/__sys_fstatat.s new file mode 100644 index 000000000..0a636dc1c --- /dev/null +++ b/libc/sysv/calls/__sys_fstatat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_fstatat 0x002a022821d60106 globl hidden diff --git a/libc/sysv/calls/__sys_ftruncate.s b/libc/sysv/calls/__sys_ftruncate.s new file mode 100644 index 000000000..333fa59d5 --- /dev/null +++ b/libc/sysv/calls/__sys_ftruncate.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_ftruncate 0x00c901e020c9004d globl hidden diff --git a/libc/sysv/calls/__sys_getpeername.s b/libc/sysv/calls/__sys_getpeername.s new file mode 100644 index 000000000..5e818064f --- /dev/null +++ b/libc/sysv/calls/__sys_getpeername.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_getpeername 0x001f008d201f0034 globl hidden diff --git a/libc/sysv/calls/__sys_getsockname.s b/libc/sysv/calls/__sys_getsockname.s new file mode 100644 index 000000000..def85d1ac --- /dev/null +++ b/libc/sysv/calls/__sys_getsockname.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_getsockname 0x0020002020200033 globl hidden diff --git a/libc/sysv/calls/__sys_gettimeofday.s b/libc/sysv/calls/__sys_gettimeofday.s new file mode 100644 index 000000000..e09f7ad6d --- /dev/null +++ b/libc/sysv/calls/__sys_gettimeofday.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_gettimeofday 0x0043007420740060 globl hidden diff --git a/libc/sysv/calls/__sys_lseek.s b/libc/sysv/calls/__sys_lseek.s new file mode 100644 index 000000000..53fa7740d --- /dev/null +++ b/libc/sysv/calls/__sys_lseek.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_lseek 0x00c701de20c70008 globl hidden diff --git a/libc/sysv/calls/__sys_lstat.s b/libc/sysv/calls/__sys_lstat.s new file mode 100644 index 000000000..ad3a61e64 --- /dev/null +++ b/libc/sysv/calls/__sys_lstat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_lstat 0x0028002821540006 globl hidden diff --git a/libc/sysv/calls/__sys_mmap.s b/libc/sysv/calls/__sys_mmap.s new file mode 100644 index 000000000..0932ee11f --- /dev/null +++ b/libc/sysv/calls/__sys_mmap.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_mmap 0x00c501dd20c50009 globl hidden diff --git a/libc/sysv/calls/__sys_pipe.s b/libc/sysv/calls/__sys_pipe.s new file mode 100644 index 000000000..a74fa08dd --- /dev/null +++ b/libc/sysv/calls/__sys_pipe.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_pipe 0x0107021e202a0016 globl hidden diff --git a/libc/sysv/calls/__sys_pipe2.s b/libc/sysv/calls/__sys_pipe2.s new file mode 100644 index 000000000..bac9997cf --- /dev/null +++ b/libc/sysv/calls/__sys_pipe2.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_pipe2 0x0065021effff0125 globl hidden diff --git a/libc/sysv/calls/__sys_pread.s b/libc/sysv/calls/__sys_pread.s new file mode 100644 index 000000000..eb8d02105 --- /dev/null +++ b/libc/sysv/calls/__sys_pread.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_pread 0x00ad01db20990011 globl hidden diff --git a/libc/sysv/calls/__sys_preadv.s b/libc/sysv/calls/__sys_preadv.s new file mode 100644 index 000000000..59e97f0b2 --- /dev/null +++ b/libc/sysv/calls/__sys_preadv.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_preadv 0x010b0121ffff0127 globl hidden diff --git a/libc/sysv/calls/__sys_pwrite.s b/libc/sysv/calls/__sys_pwrite.s new file mode 100644 index 000000000..793e9d5cf --- /dev/null +++ b/libc/sysv/calls/__sys_pwrite.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_pwrite 0x00ae01dc209a0012 globl hidden diff --git a/libc/sysv/calls/__sys_pwritev.s b/libc/sysv/calls/__sys_pwritev.s new file mode 100644 index 000000000..15862baec --- /dev/null +++ b/libc/sysv/calls/__sys_pwritev.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_pwritev 0x010c0122ffff0128 globl hidden diff --git a/libc/sysv/calls/__sys_socket.s b/libc/sysv/calls/__sys_socket.s new file mode 100644 index 000000000..8a66d3dc9 --- /dev/null +++ b/libc/sysv/calls/__sys_socket.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_socket 0x0061006120610029 globl hidden diff --git a/libc/sysv/calls/__sys_stat.s b/libc/sysv/calls/__sys_stat.s new file mode 100644 index 000000000..f730084aa --- /dev/null +++ b/libc/sysv/calls/__sys_stat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_stat 0x0026ffff21520004 globl hidden diff --git a/libc/sysv/calls/__sys_truncate.s b/libc/sysv/calls/__sys_truncate.s new file mode 100644 index 000000000..f524591f6 --- /dev/null +++ b/libc/sysv/calls/__sys_truncate.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_truncate 0x00c801df20c8004c globl hidden diff --git a/libc/sysv/calls/__sys_utimensat.s b/libc/sysv/calls/__sys_utimensat.s new file mode 100644 index 000000000..ad7952f15 --- /dev/null +++ b/libc/sysv/calls/__sys_utimensat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall __sys_utimensat 0x00540223ffff0118 globl hidden diff --git a/libc/sysv/calls/__truncate-sysv.s b/libc/sysv/calls/__truncate-sysv.s deleted file mode 100644 index 1488286c9..000000000 --- a/libc/sysv/calls/__truncate-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __truncate$sysv 0x00c801df20c8004c globl hidden diff --git a/libc/sysv/calls/__utimensat-sysv.s b/libc/sysv/calls/__utimensat-sysv.s deleted file mode 100644 index 53ab72e96..000000000 --- a/libc/sysv/calls/__utimensat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall __utimensat$sysv 0x00540223ffff0118 globl hidden diff --git a/libc/sysv/calls/access-sysv.s b/libc/sysv/calls/access-sysv.s deleted file mode 100644 index dc4bec94f..000000000 --- a/libc/sysv/calls/access-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall access$sysv 0x0021002120210015 globl hidden diff --git a/libc/sysv/calls/alarm-sysv.s b/libc/sysv/calls/alarm-sysv.s deleted file mode 100644 index f5cf64708..000000000 --- a/libc/sysv/calls/alarm-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall alarm$sysv 0xffffffffffff0025 globl hidden diff --git a/libc/sysv/calls/arch_prctl-sysv.s b/libc/sysv/calls/arch_prctl-sysv.s deleted file mode 100644 index 619abbd68..000000000 --- a/libc/sysv/calls/arch_prctl-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall arch_prctl$sysv 0x00a500a5ffff009e globl hidden diff --git a/libc/sysv/calls/bind-sysv.s b/libc/sysv/calls/bind-sysv.s deleted file mode 100644 index 82c0a96af..000000000 --- a/libc/sysv/calls/bind-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall bind$sysv 0x0068006820680031 globl hidden diff --git a/libc/sysv/calls/chdir-sysv.s b/libc/sysv/calls/chdir-sysv.s deleted file mode 100644 index 6e3161b53..000000000 --- a/libc/sysv/calls/chdir-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall chdir$sysv 0x000c000c200c0050 globl hidden diff --git a/libc/sysv/calls/chmod-sysv.s b/libc/sysv/calls/chmod-sysv.s deleted file mode 100644 index 803556333..000000000 --- a/libc/sysv/calls/chmod-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall chmod$sysv 0x000f000f200f005a globl hidden diff --git a/libc/sysv/calls/chown-sysv.s b/libc/sysv/calls/chown-sysv.s deleted file mode 100644 index 6017050a3..000000000 --- a/libc/sysv/calls/chown-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall chown$sysv 0x001000102010005c globl hidden diff --git a/libc/sysv/calls/clock_gettime-sysv.s b/libc/sysv/calls/clock_gettime-sysv.s deleted file mode 100644 index 6c18b9add..000000000 --- a/libc/sysv/calls/clock_gettime-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall clock_gettime$sysv 0x005700e8ffff00e4 globl hidden diff --git a/libc/sysv/calls/close-sysv.s b/libc/sysv/calls/close-sysv.s deleted file mode 100644 index c6e325dd1..000000000 --- a/libc/sysv/calls/close-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall close$sysv 0x0006000620060003 globl hidden diff --git a/libc/sysv/calls/copy_file_range-sysv.s b/libc/sysv/calls/copy_file_range-sysv.s deleted file mode 100644 index adc6ded93..000000000 --- a/libc/sysv/calls/copy_file_range-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall copy_file_range$sysv 0xffff0239ffff0146 globl hidden diff --git a/libc/sysv/calls/creat-sysv.s b/libc/sysv/calls/creat-sysv.s deleted file mode 100644 index 697a7c7ed..000000000 --- a/libc/sysv/calls/creat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall creat$sysv 0xffff0008ffff0055 globl hidden diff --git a/libc/sysv/calls/dup-sysv.s b/libc/sysv/calls/dup-sysv.s deleted file mode 100644 index 9352bf1d2..000000000 --- a/libc/sysv/calls/dup-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall dup$sysv 0x0029002920290020 globl hidden diff --git a/libc/sysv/calls/dup2-sysv.s b/libc/sysv/calls/dup2-sysv.s deleted file mode 100644 index c1cb9dc40..000000000 --- a/libc/sysv/calls/dup2-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall dup2$sysv 0x005a005a205a0021 globl hidden diff --git a/libc/sysv/calls/epoll_create-sysv.s b/libc/sysv/calls/epoll_create-sysv.s deleted file mode 100644 index 375fabf95..000000000 --- a/libc/sysv/calls/epoll_create-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall epoll_create$sysv 0xffffffffffff00d5 globl diff --git a/libc/sysv/calls/epoll_create1-sysv.s b/libc/sysv/calls/epoll_create1-sysv.s deleted file mode 100644 index a78cc5391..000000000 --- a/libc/sysv/calls/epoll_create1-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall epoll_create1$sysv 0xffffffffffff0123 globl diff --git a/libc/sysv/calls/epoll_ctl-sysv.s b/libc/sysv/calls/epoll_ctl-sysv.s deleted file mode 100644 index ae2a35d47..000000000 --- a/libc/sysv/calls/epoll_ctl-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall epoll_ctl$sysv 0xffffffffffff00e9 globl diff --git a/libc/sysv/calls/epoll_wait-sysv.s b/libc/sysv/calls/epoll_wait-sysv.s deleted file mode 100644 index a0ecd50d6..000000000 --- a/libc/sysv/calls/epoll_wait-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall epoll_wait$sysv 0xffffffffffff00e8 globl diff --git a/libc/sysv/calls/exit-sysv.s b/libc/sysv/calls/exit-sysv.s deleted file mode 100644 index eda258687..000000000 --- a/libc/sysv/calls/exit-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall exit$sysv 0x00010001200100e7 globl hidden diff --git a/libc/sysv/calls/faccessat-sysv.s b/libc/sysv/calls/faccessat-sysv.s deleted file mode 100644 index 2e98fed6f..000000000 --- a/libc/sysv/calls/faccessat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall faccessat$sysv 0x013901e921d2010d globl hidden diff --git a/libc/sysv/calls/fadvise-sysv.s b/libc/sysv/calls/fadvise-sysv.s deleted file mode 100644 index 89ddabdd1..000000000 --- a/libc/sysv/calls/fadvise-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fadvise$sysv 0xffff0213ffff00dd globl hidden diff --git a/libc/sysv/calls/fallocate-sysv.s b/libc/sysv/calls/fallocate-sysv.s deleted file mode 100644 index 47b137239..000000000 --- a/libc/sysv/calls/fallocate-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fallocate$sysv 0xffffffffffff011d globl hidden diff --git a/libc/sysv/calls/fchdir-sysv.s b/libc/sysv/calls/fchdir-sysv.s deleted file mode 100644 index 9111c3285..000000000 --- a/libc/sysv/calls/fchdir-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fchdir$sysv 0x000d000d200d0051 globl hidden diff --git a/libc/sysv/calls/fchmod-sysv.s b/libc/sysv/calls/fchmod-sysv.s deleted file mode 100644 index 48db6d6af..000000000 --- a/libc/sysv/calls/fchmod-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fchmod$sysv 0x007c007c207c005b globl hidden diff --git a/libc/sysv/calls/fchmodat-sysv.s b/libc/sysv/calls/fchmodat-sysv.s deleted file mode 100644 index 59a95202b..000000000 --- a/libc/sysv/calls/fchmodat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fchmodat$sysv 0x013a01ea21d3010c globl hidden diff --git a/libc/sysv/calls/fchown-sysv.s b/libc/sysv/calls/fchown-sysv.s deleted file mode 100644 index f88e0efd5..000000000 --- a/libc/sysv/calls/fchown-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fchown$sysv 0x007b007b207b005d globl hidden diff --git a/libc/sysv/calls/fchownat-sysv.s b/libc/sysv/calls/fchownat-sysv.s deleted file mode 100644 index 15d15b704..000000000 --- a/libc/sysv/calls/fchownat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fchownat$sysv 0x013b01eb21d40104 globl hidden diff --git a/libc/sysv/calls/fcntl-sysv.s b/libc/sysv/calls/fcntl-sysv.s deleted file mode 100644 index 34f8a7c87..000000000 --- a/libc/sysv/calls/fcntl-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fcntl$sysv 0x005c005c205c0048 globl hidden diff --git a/libc/sysv/calls/fdatasync-sysv.s b/libc/sysv/calls/fdatasync-sysv.s deleted file mode 100644 index 1255135b9..000000000 --- a/libc/sysv/calls/fdatasync-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fdatasync$sysv 0x005f022620bb004b globl hidden diff --git a/libc/sysv/calls/flock-sysv.s b/libc/sysv/calls/flock-sysv.s deleted file mode 100644 index ff75cb34a..000000000 --- a/libc/sysv/calls/flock-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall flock$sysv 0x0083008320830049 globl hidden diff --git a/libc/sysv/calls/fsync-sysv.s b/libc/sysv/calls/fsync-sysv.s deleted file mode 100644 index 4c7db0888..000000000 --- a/libc/sysv/calls/fsync-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall fsync$sysv 0x005f005f205f004a globl hidden diff --git a/libc/sysv/calls/futimens-sysv.s b/libc/sysv/calls/futimens-sysv.s deleted file mode 100644 index 00834a3b2..000000000 --- a/libc/sysv/calls/futimens-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall futimens$sysv 0x00550222ffffffff globl hidden diff --git a/libc/sysv/calls/futimes-sysv.s b/libc/sysv/calls/futimes-sysv.s deleted file mode 100644 index ec6216b86..000000000 --- a/libc/sysv/calls/futimes-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall futimes$sysv 0x004d00ce208bffff globl hidden diff --git a/libc/sysv/calls/futimesat-sysv.s b/libc/sysv/calls/futimesat-sysv.s deleted file mode 100644 index c24382cce..000000000 --- a/libc/sysv/calls/futimesat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall futimesat$sysv 0xffff01eeffff0105 globl hidden diff --git a/libc/sysv/calls/getcwd-sysv.s b/libc/sysv/calls/getcwd-sysv.s deleted file mode 100644 index 92875de7c..000000000 --- a/libc/sysv/calls/getcwd-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getcwd$sysv 0x01300146ffff004f globl hidden diff --git a/libc/sysv/calls/getgid-sysv.s b/libc/sysv/calls/getgid-sysv.s deleted file mode 100644 index 81175946e..000000000 --- a/libc/sysv/calls/getgid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getgid$sysv 0x002f002f202f0068 globl hidden diff --git a/libc/sysv/calls/getitimer-sysv.s b/libc/sysv/calls/getitimer-sysv.s deleted file mode 100644 index 32a059d59..000000000 --- a/libc/sysv/calls/getitimer-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getitimer$sysv 0x0046005620560024 globl hidden diff --git a/libc/sysv/calls/getpagesize-freebsd.s b/libc/sysv/calls/getpagesize-freebsd.s deleted file mode 100644 index d31897834..000000000 --- a/libc/sysv/calls/getpagesize-freebsd.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getpagesize$freebsd 0xffff0040ffffffff globl hidden diff --git a/libc/sysv/calls/getpagesize_freebsd.s b/libc/sysv/calls/getpagesize_freebsd.s new file mode 100644 index 000000000..e5d174780 --- /dev/null +++ b/libc/sysv/calls/getpagesize_freebsd.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall getpagesize_freebsd 0xffff0040ffffffff globl hidden diff --git a/libc/sysv/calls/getpid-sysv.s b/libc/sysv/calls/getpid-sysv.s deleted file mode 100644 index 17d95fe22..000000000 --- a/libc/sysv/calls/getpid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getpid$sysv 0x0014001420140027 globl hidden diff --git a/libc/sysv/calls/getppid-sysv.s b/libc/sysv/calls/getppid-sysv.s deleted file mode 100644 index fb39b6e60..000000000 --- a/libc/sysv/calls/getppid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getppid$sysv 0x002700272027006e globl hidden diff --git a/libc/sysv/calls/getpriority-sysv.s b/libc/sysv/calls/getpriority-sysv.s deleted file mode 100644 index d1933e333..000000000 --- a/libc/sysv/calls/getpriority-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getpriority$sysv 0x006400642064008c globl hidden diff --git a/libc/sysv/calls/getrandom-sysv.s b/libc/sysv/calls/getrandom-sysv.s deleted file mode 100644 index 7990bf7ca..000000000 --- a/libc/sysv/calls/getrandom-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getrandom$sysv 0x0007023321f4013e globl hidden diff --git a/libc/sysv/calls/getrlimit-sysv.s b/libc/sysv/calls/getrlimit-sysv.s deleted file mode 100644 index a6e725fba..000000000 --- a/libc/sysv/calls/getrlimit-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getrlimit$sysv 0x00c200c220c20061 globl hidden diff --git a/libc/sysv/calls/getrusage-sysv.s b/libc/sysv/calls/getrusage-sysv.s deleted file mode 100644 index 6cbb532b9..000000000 --- a/libc/sysv/calls/getrusage-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getrusage$sysv 0x0013007520750062 globl hidden diff --git a/libc/sysv/calls/getsid-sysv.s b/libc/sysv/calls/getsid-sysv.s deleted file mode 100644 index fddc57275..000000000 --- a/libc/sysv/calls/getsid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getsid$sysv 0x00ff01362136007c globl hidden diff --git a/libc/sysv/calls/getsockopt-sysv.s b/libc/sysv/calls/getsockopt-sysv.s deleted file mode 100644 index c36a70d14..000000000 --- a/libc/sysv/calls/getsockopt-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getsockopt$sysv 0x0076007620760037 globl hidden diff --git a/libc/sysv/calls/gettid-sysv.s b/libc/sysv/calls/gettid-sysv.s deleted file mode 100644 index 3cf348785..000000000 --- a/libc/sysv/calls/gettid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall gettid$sysv 0xffffffff211e00ba globl hidden diff --git a/libc/sysv/calls/getuid-sysv.s b/libc/sysv/calls/getuid-sysv.s deleted file mode 100644 index c3137597c..000000000 --- a/libc/sysv/calls/getuid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall getuid$sysv 0x0018001820180066 globl hidden diff --git a/libc/sysv/calls/ioctl-sysv.s b/libc/sysv/calls/ioctl-sysv.s deleted file mode 100644 index b19bb11d7..000000000 --- a/libc/sysv/calls/ioctl-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall ioctl$sysv 0x0036003620360010 globl hidden diff --git a/libc/sysv/calls/kill-sysv.s b/libc/sysv/calls/kill-sysv.s deleted file mode 100644 index 2334e53fc..000000000 --- a/libc/sysv/calls/kill-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall kill$sysv 0x007a00252025003e globl hidden diff --git a/libc/sysv/calls/killpg-sysv.s b/libc/sysv/calls/killpg-sysv.s deleted file mode 100644 index 3ead81bb8..000000000 --- a/libc/sysv/calls/killpg-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall killpg$sysv 0xffff0092ffffffff globl hidden diff --git a/libc/sysv/calls/lchown-sysv.s b/libc/sysv/calls/lchown-sysv.s deleted file mode 100644 index 555546ba4..000000000 --- a/libc/sysv/calls/lchown-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall lchown$sysv 0x00fe00fe216c005e globl hidden diff --git a/libc/sysv/calls/link-sysv.s b/libc/sysv/calls/link-sysv.s deleted file mode 100644 index 5a0664630..000000000 --- a/libc/sysv/calls/link-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall link$sysv 0x0009000920090056 globl hidden diff --git a/libc/sysv/calls/linkat-sysv.s b/libc/sysv/calls/linkat-sysv.s deleted file mode 100644 index 58a1b54cf..000000000 --- a/libc/sysv/calls/linkat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall linkat$sysv 0x013d01ef21d70109 globl hidden diff --git a/libc/sysv/calls/listen-sysv.s b/libc/sysv/calls/listen-sysv.s deleted file mode 100644 index ecfd359c9..000000000 --- a/libc/sysv/calls/listen-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall listen$sysv 0x006a006a206a0032 globl hidden diff --git a/libc/sysv/calls/madvise-sysv.s b/libc/sysv/calls/madvise-sysv.s deleted file mode 100644 index 53cea3a05..000000000 --- a/libc/sysv/calls/madvise-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall madvise$sysv 0x004b004b204b001c globl hidden diff --git a/libc/sysv/calls/mkdir-sysv.s b/libc/sysv/calls/mkdir-sysv.s deleted file mode 100644 index 791aadbdc..000000000 --- a/libc/sysv/calls/mkdir-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall mkdir$sysv 0x0088008820880053 globl hidden diff --git a/libc/sysv/calls/mkdirat-sysv.s b/libc/sysv/calls/mkdirat-sysv.s deleted file mode 100644 index f08871047..000000000 --- a/libc/sysv/calls/mkdirat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall mkdirat$sysv 0x013e01f021db0102 globl hidden diff --git a/libc/sysv/calls/mkfifo-sysv.s b/libc/sysv/calls/mkfifo-sysv.s deleted file mode 100644 index a594d8522..000000000 --- a/libc/sysv/calls/mkfifo-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall mkfifo$sysv 0x008400842084ffff globl hidden diff --git a/libc/sysv/calls/mknod-sysv.s b/libc/sysv/calls/mknod-sysv.s deleted file mode 100644 index 3a141926d..000000000 --- a/libc/sysv/calls/mknod-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall mknod$sysv 0x000e000e200e0085 globl hidden diff --git a/libc/sysv/calls/mprotect-sysv.s b/libc/sysv/calls/mprotect-sysv.s deleted file mode 100644 index c63fbdccb..000000000 --- a/libc/sysv/calls/mprotect-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall mprotect$sysv 0x004a004a204a000a globl hidden diff --git a/libc/sysv/calls/mremap-sysv.s b/libc/sysv/calls/mremap-sysv.s deleted file mode 100644 index 31c582181..000000000 --- a/libc/sysv/calls/mremap-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall mremap$sysv 0xffffffffffff0019 globl hidden diff --git a/libc/sysv/calls/msync-sysv.s b/libc/sysv/calls/msync-sysv.s deleted file mode 100644 index ef7b5841c..000000000 --- a/libc/sysv/calls/msync-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall msync$sysv 0x010000412041001a globl hidden diff --git a/libc/sysv/calls/munmap-sysv.s b/libc/sysv/calls/munmap-sysv.s deleted file mode 100644 index c90b9251d..000000000 --- a/libc/sysv/calls/munmap-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall munmap$sysv 0x004900492049000b globl hidden diff --git a/libc/sysv/calls/nanosleep-sysv.s b/libc/sysv/calls/nanosleep-sysv.s deleted file mode 100644 index d935cdca6..000000000 --- a/libc/sysv/calls/nanosleep-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall nanosleep$sysv 0x005b00f0ffff0023 globl hidden diff --git a/libc/sysv/calls/open-sysv.s b/libc/sysv/calls/open-sysv.s deleted file mode 100644 index 491808e9e..000000000 --- a/libc/sysv/calls/open-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall open$sysv 0x0005000520050002 globl hidden diff --git a/libc/sysv/calls/openat-sysv.s b/libc/sysv/calls/openat-sysv.s deleted file mode 100644 index 7ad761deb..000000000 --- a/libc/sysv/calls/openat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall openat$sysv 0x014101f321cf0101 globl hidden diff --git a/libc/sysv/calls/pause-sysv.s b/libc/sysv/calls/pause-sysv.s deleted file mode 100644 index 135094403..000000000 --- a/libc/sysv/calls/pause-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall pause$sysv 0xffffffffffff0022 globl hidden diff --git a/libc/sysv/calls/poll-sysv.s b/libc/sysv/calls/poll-sysv.s deleted file mode 100644 index f340dc588..000000000 --- a/libc/sysv/calls/poll-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall poll$sysv 0x00fc00d120e60007 globl hidden diff --git a/libc/sysv/calls/posix_fallocate-sysv.s b/libc/sysv/calls/posix_fallocate-sysv.s deleted file mode 100644 index 2480e552e..000000000 --- a/libc/sysv/calls/posix_fallocate-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall posix_fallocate$sysv 0xffff0212ffffffff globl hidden diff --git a/libc/sysv/calls/posix_openpt-sysv.s b/libc/sysv/calls/posix_openpt-sysv.s deleted file mode 100644 index bc4fbc33f..000000000 --- a/libc/sysv/calls/posix_openpt-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall posix_openpt$sysv 0xffff01f8ffffffff globl hidden diff --git a/libc/sysv/calls/posix_spawn-sysv.s b/libc/sysv/calls/posix_spawn-sysv.s deleted file mode 100644 index 8cb423bab..000000000 --- a/libc/sysv/calls/posix_spawn-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall posix_spawn$sysv 0xffffffff20f4ffff globl hidden diff --git a/libc/sysv/calls/ppoll-sysv.s b/libc/sysv/calls/ppoll-sysv.s deleted file mode 100644 index 033b55164..000000000 --- a/libc/sysv/calls/ppoll-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall ppoll$sysv 0x006d0221ffff010f globl hidden diff --git a/libc/sysv/calls/ptrace-sysv.s b/libc/sysv/calls/ptrace-sysv.s deleted file mode 100644 index 738265a62..000000000 --- a/libc/sysv/calls/ptrace-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall ptrace$sysv 0x001a001a201a0065 globl hidden diff --git a/libc/sysv/calls/read-sysv.s b/libc/sysv/calls/read-sysv.s deleted file mode 100644 index 7bd081abf..000000000 --- a/libc/sysv/calls/read-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall read$sysv 0x0003000320030000 globl hidden diff --git a/libc/sysv/calls/readlinkat-sysv.s b/libc/sysv/calls/readlinkat-sysv.s deleted file mode 100644 index 87b70a2ed..000000000 --- a/libc/sysv/calls/readlinkat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall readlinkat$sysv 0x014201f421d9010b globl hidden diff --git a/libc/sysv/calls/readv-sysv.s b/libc/sysv/calls/readv-sysv.s deleted file mode 100644 index a4a27209d..000000000 --- a/libc/sysv/calls/readv-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall readv$sysv 0x0078007820780013 globl hidden diff --git a/libc/sysv/calls/recvfrom-sysv.s b/libc/sysv/calls/recvfrom-sysv.s deleted file mode 100644 index c5d1a8bb7..000000000 --- a/libc/sysv/calls/recvfrom-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall recvfrom$sysv 0x001d001d201d002d globl hidden diff --git a/libc/sysv/calls/recvmsg-sysv.s b/libc/sysv/calls/recvmsg-sysv.s deleted file mode 100644 index dd4ab65c1..000000000 --- a/libc/sysv/calls/recvmsg-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall recvmsg$sysv 0x001b001b201b002f globl hidden diff --git a/libc/sysv/calls/rename-sysv.s b/libc/sysv/calls/rename-sysv.s deleted file mode 100644 index 19cee5cc2..000000000 --- a/libc/sysv/calls/rename-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall rename$sysv 0x0080008020800052 globl hidden diff --git a/libc/sysv/calls/renameat-sysv.s b/libc/sysv/calls/renameat-sysv.s deleted file mode 100644 index cadbf3c10..000000000 --- a/libc/sysv/calls/renameat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall renameat$sysv 0x014301f521d10108 globl hidden diff --git a/libc/sysv/calls/rmdir-sysv.s b/libc/sysv/calls/rmdir-sysv.s deleted file mode 100644 index 20e031f45..000000000 --- a/libc/sysv/calls/rmdir-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall rmdir$sysv 0x0089008920890054 globl hidden diff --git a/libc/sysv/calls/sched_setaffinity-sysv.s b/libc/sysv/calls/sched_setaffinity-sysv.s deleted file mode 100644 index 3c69e1b0a..000000000 --- a/libc/sysv/calls/sched_setaffinity-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sched_setaffinity$sysv 0xffffffffffff00cb globl hidden diff --git a/libc/sysv/calls/sched_yield-sysv.s b/libc/sysv/calls/sched_yield-sysv.s deleted file mode 100644 index 9385fe14f..000000000 --- a/libc/sysv/calls/sched_yield-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sched_yield$sysv 0x012a014b103c0018 globl hidden diff --git a/libc/sysv/calls/select-sysv.s b/libc/sysv/calls/select-sysv.s deleted file mode 100644 index 125cae736..000000000 --- a/libc/sysv/calls/select-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall select$sysv 0x0047005d205d0017 globl hidden diff --git a/libc/sysv/calls/sendfile-sysv.s b/libc/sysv/calls/sendfile-sysv.s deleted file mode 100644 index 019ad7f3c..000000000 --- a/libc/sysv/calls/sendfile-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sendfile$sysv 0xffff018921510028 globl hidden diff --git a/libc/sysv/calls/sendmsg-sysv.s b/libc/sysv/calls/sendmsg-sysv.s deleted file mode 100644 index 7fd6f23f5..000000000 --- a/libc/sysv/calls/sendmsg-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sendmsg$sysv 0x001c001c201c002e globl hidden diff --git a/libc/sysv/calls/sendto-sysv.s b/libc/sysv/calls/sendto-sysv.s deleted file mode 100644 index d0dcb235c..000000000 --- a/libc/sysv/calls/sendto-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sendto$sysv 0x008500852085002c globl hidden diff --git a/libc/sysv/calls/setitimer-sysv.s b/libc/sysv/calls/setitimer-sysv.s deleted file mode 100644 index 6480f1d82..000000000 --- a/libc/sysv/calls/setitimer-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall setitimer$sysv 0x0045005320530026 globl hidden diff --git a/libc/sysv/calls/setpriority-sysv.s b/libc/sysv/calls/setpriority-sysv.s deleted file mode 100644 index 0f290732b..000000000 --- a/libc/sysv/calls/setpriority-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall setpriority$sysv 0x006000602060008d globl hidden diff --git a/libc/sysv/calls/setresgid-sysv.s b/libc/sysv/calls/setresgid-sysv.s deleted file mode 100644 index 9a23240ec..000000000 --- a/libc/sysv/calls/setresgid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall setresgid$sysv 0x011c0138ffff0077 globl hidden diff --git a/libc/sysv/calls/setresuid-sysv.s b/libc/sysv/calls/setresuid-sysv.s deleted file mode 100644 index e0b506441..000000000 --- a/libc/sysv/calls/setresuid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall setresuid$sysv 0x011a0137ffff0075 globl hidden diff --git a/libc/sysv/calls/setrlimit-sysv.s b/libc/sysv/calls/setrlimit-sysv.s deleted file mode 100644 index 492272364..000000000 --- a/libc/sysv/calls/setrlimit-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall setrlimit$sysv 0x00c300c320c300a0 globl hidden diff --git a/libc/sysv/calls/setsid-sysv.s b/libc/sysv/calls/setsid-sysv.s deleted file mode 100644 index a91f3e73d..000000000 --- a/libc/sysv/calls/setsid-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall setsid$sysv 0x0093009320930070 globl hidden diff --git a/libc/sysv/calls/setsockopt-sysv.s b/libc/sysv/calls/setsockopt-sysv.s deleted file mode 100644 index bf94b5427..000000000 --- a/libc/sysv/calls/setsockopt-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall setsockopt$sysv 0x0069006920690036 globl hidden diff --git a/libc/sysv/calls/shutdown-sysv.s b/libc/sysv/calls/shutdown-sysv.s deleted file mode 100644 index 36aa06c3d..000000000 --- a/libc/sysv/calls/shutdown-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall shutdown$sysv 0x0086008620860030 globl hidden diff --git a/libc/sysv/calls/sigaction-sysv.s b/libc/sysv/calls/sigaction-sysv.s deleted file mode 100644 index 974854e7a..000000000 --- a/libc/sysv/calls/sigaction-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sigaction$sysv 0x002e01a0202e000d globl hidden diff --git a/libc/sysv/calls/sigprocmask-sysv.s b/libc/sysv/calls/sigprocmask-sysv.s deleted file mode 100644 index f235e7cc4..000000000 --- a/libc/sysv/calls/sigprocmask-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sigprocmask$sysv 0x003001542030000e globl hidden diff --git a/libc/sysv/calls/sigsuspend-sysv.s b/libc/sysv/calls/sigsuspend-sysv.s deleted file mode 100644 index 8f5a25785..000000000 --- a/libc/sysv/calls/sigsuspend-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sigsuspend$sysv 0x006f0155206f0082 globl hidden diff --git a/libc/sysv/calls/socketpair-sysv.s b/libc/sysv/calls/socketpair-sysv.s deleted file mode 100644 index 8197f5860..000000000 --- a/libc/sysv/calls/socketpair-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall socketpair$sysv 0x0087008720870035 globl hidden diff --git a/libc/sysv/calls/splice-sysv.s b/libc/sysv/calls/splice-sysv.s deleted file mode 100644 index 54f4c4d71..000000000 --- a/libc/sysv/calls/splice-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall splice$sysv 0xffffffffffff0113 globl hidden diff --git a/libc/sysv/calls/symlink-sysv.s b/libc/sysv/calls/symlink-sysv.s deleted file mode 100644 index 94fb2b24d..000000000 --- a/libc/sysv/calls/symlink-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall symlink$sysv 0x0039003920390058 globl hidden diff --git a/libc/sysv/calls/symlinkat-sysv.s b/libc/sysv/calls/symlinkat-sysv.s deleted file mode 100644 index 7a95c27e0..000000000 --- a/libc/sysv/calls/symlinkat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall symlinkat$sysv 0x014401f621da010a globl hidden diff --git a/libc/sysv/calls/sync-sysv.s b/libc/sysv/calls/sync-sysv.s deleted file mode 100644 index 395d5e596..000000000 --- a/libc/sysv/calls/sync-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sync$sysv 0x00240024202400a2 globl hidden diff --git a/libc/sysv/calls/sync_file_range-sysv.s b/libc/sysv/calls/sync_file_range-sysv.s deleted file mode 100644 index d72f3d712..000000000 --- a/libc/sysv/calls/sync_file_range-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sync_file_range$sysv 0xffffffffffff0115 globl hidden diff --git a/libc/sysv/calls/sys_access.s b/libc/sysv/calls/sys_access.s new file mode 100644 index 000000000..bd683c194 --- /dev/null +++ b/libc/sysv/calls/sys_access.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_access 0x0021002120210015 globl hidden diff --git a/libc/sysv/calls/sys_alarm.s b/libc/sysv/calls/sys_alarm.s new file mode 100644 index 000000000..5b1db11d9 --- /dev/null +++ b/libc/sysv/calls/sys_alarm.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_alarm 0xffffffffffff0025 globl hidden diff --git a/libc/sysv/calls/sys_arch_prctl.s b/libc/sysv/calls/sys_arch_prctl.s new file mode 100644 index 000000000..47d1d7a6a --- /dev/null +++ b/libc/sysv/calls/sys_arch_prctl.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_arch_prctl 0x00a500a5ffff009e globl hidden diff --git a/libc/sysv/calls/sys_bind.s b/libc/sysv/calls/sys_bind.s new file mode 100644 index 000000000..8159cf61f --- /dev/null +++ b/libc/sysv/calls/sys_bind.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_bind 0x0068006820680031 globl hidden diff --git a/libc/sysv/calls/sys_chdir.s b/libc/sysv/calls/sys_chdir.s new file mode 100644 index 000000000..db34d1ae9 --- /dev/null +++ b/libc/sysv/calls/sys_chdir.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_chdir 0x000c000c200c0050 globl hidden diff --git a/libc/sysv/calls/sys_chmod.s b/libc/sysv/calls/sys_chmod.s new file mode 100644 index 000000000..9d59d5a55 --- /dev/null +++ b/libc/sysv/calls/sys_chmod.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_chmod 0x000f000f200f005a globl hidden diff --git a/libc/sysv/calls/sys_chown.s b/libc/sysv/calls/sys_chown.s new file mode 100644 index 000000000..66ed272b3 --- /dev/null +++ b/libc/sysv/calls/sys_chown.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_chown 0x001000102010005c globl hidden diff --git a/libc/sysv/calls/sys_clock_gettime.s b/libc/sysv/calls/sys_clock_gettime.s new file mode 100644 index 000000000..31bf45d10 --- /dev/null +++ b/libc/sysv/calls/sys_clock_gettime.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_clock_gettime 0x005700e8ffff00e4 globl hidden diff --git a/libc/sysv/calls/sys_close.s b/libc/sysv/calls/sys_close.s new file mode 100644 index 000000000..d805a11c4 --- /dev/null +++ b/libc/sysv/calls/sys_close.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_close 0x0006000620060003 globl hidden diff --git a/libc/sysv/calls/sys_copy_file_range.s b/libc/sysv/calls/sys_copy_file_range.s new file mode 100644 index 000000000..a91148dd1 --- /dev/null +++ b/libc/sysv/calls/sys_copy_file_range.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_copy_file_range 0xffff0239ffff0146 globl hidden diff --git a/libc/sysv/calls/sys_creat.s b/libc/sysv/calls/sys_creat.s new file mode 100644 index 000000000..7f1158015 --- /dev/null +++ b/libc/sysv/calls/sys_creat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_creat 0xffff0008ffff0055 globl hidden diff --git a/libc/sysv/calls/sys_dup.s b/libc/sysv/calls/sys_dup.s new file mode 100644 index 000000000..98bfff00f --- /dev/null +++ b/libc/sysv/calls/sys_dup.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_dup 0x0029002920290020 globl hidden diff --git a/libc/sysv/calls/sys_dup2.s b/libc/sysv/calls/sys_dup2.s new file mode 100644 index 000000000..236d02371 --- /dev/null +++ b/libc/sysv/calls/sys_dup2.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_dup2 0x005a005a205a0021 globl hidden diff --git a/libc/sysv/calls/sys_epoll_create.s b/libc/sysv/calls/sys_epoll_create.s new file mode 100644 index 000000000..842e29961 --- /dev/null +++ b/libc/sysv/calls/sys_epoll_create.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_epoll_create 0xffffffffffff00d5 globl diff --git a/libc/sysv/calls/sys_epoll_create1.s b/libc/sysv/calls/sys_epoll_create1.s new file mode 100644 index 000000000..6a00b574f --- /dev/null +++ b/libc/sysv/calls/sys_epoll_create1.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_epoll_create1 0xffffffffffff0123 globl diff --git a/libc/sysv/calls/sys_epoll_ctl.s b/libc/sysv/calls/sys_epoll_ctl.s new file mode 100644 index 000000000..8bf800787 --- /dev/null +++ b/libc/sysv/calls/sys_epoll_ctl.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_epoll_ctl 0xffffffffffff00e9 globl diff --git a/libc/sysv/calls/sys_epoll_wait.s b/libc/sysv/calls/sys_epoll_wait.s new file mode 100644 index 000000000..d05bd0ab4 --- /dev/null +++ b/libc/sysv/calls/sys_epoll_wait.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_epoll_wait 0xffffffffffff00e8 globl diff --git a/libc/sysv/calls/sys_exit.s b/libc/sysv/calls/sys_exit.s new file mode 100644 index 000000000..5b83eb6ac --- /dev/null +++ b/libc/sysv/calls/sys_exit.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_exit 0x00010001200100e7 globl hidden diff --git a/libc/sysv/calls/sys_faccessat.s b/libc/sysv/calls/sys_faccessat.s new file mode 100644 index 000000000..600cde9e4 --- /dev/null +++ b/libc/sysv/calls/sys_faccessat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_faccessat 0x013901e921d2010d globl hidden diff --git a/libc/sysv/calls/sys_fadvise.s b/libc/sysv/calls/sys_fadvise.s new file mode 100644 index 000000000..063582532 --- /dev/null +++ b/libc/sysv/calls/sys_fadvise.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fadvise 0xffff0213ffff00dd globl hidden diff --git a/libc/sysv/calls/sys_fallocate.s b/libc/sysv/calls/sys_fallocate.s new file mode 100644 index 000000000..80dc0589d --- /dev/null +++ b/libc/sysv/calls/sys_fallocate.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fallocate 0xffffffffffff011d globl hidden diff --git a/libc/sysv/calls/sys_fchdir.s b/libc/sysv/calls/sys_fchdir.s new file mode 100644 index 000000000..3b627c435 --- /dev/null +++ b/libc/sysv/calls/sys_fchdir.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fchdir 0x000d000d200d0051 globl hidden diff --git a/libc/sysv/calls/sys_fchmod.s b/libc/sysv/calls/sys_fchmod.s new file mode 100644 index 000000000..f54357760 --- /dev/null +++ b/libc/sysv/calls/sys_fchmod.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fchmod 0x007c007c207c005b globl hidden diff --git a/libc/sysv/calls/sys_fchmodat.s b/libc/sysv/calls/sys_fchmodat.s new file mode 100644 index 000000000..ddfcf236c --- /dev/null +++ b/libc/sysv/calls/sys_fchmodat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fchmodat 0x013a01ea21d3010c globl hidden diff --git a/libc/sysv/calls/sys_fchown.s b/libc/sysv/calls/sys_fchown.s new file mode 100644 index 000000000..ad99e3162 --- /dev/null +++ b/libc/sysv/calls/sys_fchown.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fchown 0x007b007b207b005d globl hidden diff --git a/libc/sysv/calls/sys_fchownat.s b/libc/sysv/calls/sys_fchownat.s new file mode 100644 index 000000000..ab2b77222 --- /dev/null +++ b/libc/sysv/calls/sys_fchownat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fchownat 0x013b01eb21d40104 globl hidden diff --git a/libc/sysv/calls/sys_fcntl.s b/libc/sysv/calls/sys_fcntl.s new file mode 100644 index 000000000..f273388a9 --- /dev/null +++ b/libc/sysv/calls/sys_fcntl.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fcntl 0x005c005c205c0048 globl hidden diff --git a/libc/sysv/calls/sys_fdatasync.s b/libc/sysv/calls/sys_fdatasync.s new file mode 100644 index 000000000..17c7f2965 --- /dev/null +++ b/libc/sysv/calls/sys_fdatasync.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fdatasync 0x005f022620bb004b globl hidden diff --git a/libc/sysv/calls/sys_flock.s b/libc/sysv/calls/sys_flock.s new file mode 100644 index 000000000..26ff2a8b0 --- /dev/null +++ b/libc/sysv/calls/sys_flock.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_flock 0x0083008320830049 globl hidden diff --git a/libc/sysv/calls/sys_fsync.s b/libc/sysv/calls/sys_fsync.s new file mode 100644 index 000000000..6882d4801 --- /dev/null +++ b/libc/sysv/calls/sys_fsync.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_fsync 0x005f005f205f004a globl hidden diff --git a/libc/sysv/calls/sys_futimens.s b/libc/sysv/calls/sys_futimens.s new file mode 100644 index 000000000..6004436cc --- /dev/null +++ b/libc/sysv/calls/sys_futimens.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_futimens 0x00550222ffffffff globl hidden diff --git a/libc/sysv/calls/sys_futimes.s b/libc/sysv/calls/sys_futimes.s new file mode 100644 index 000000000..66d38d5cf --- /dev/null +++ b/libc/sysv/calls/sys_futimes.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_futimes 0x004d00ce208bffff globl hidden diff --git a/libc/sysv/calls/sys_futimesat.s b/libc/sysv/calls/sys_futimesat.s new file mode 100644 index 000000000..b3a1ed18b --- /dev/null +++ b/libc/sysv/calls/sys_futimesat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_futimesat 0xffff01eeffff0105 globl hidden diff --git a/libc/sysv/calls/sys_getcwd.s b/libc/sysv/calls/sys_getcwd.s new file mode 100644 index 000000000..cc7f22e27 --- /dev/null +++ b/libc/sysv/calls/sys_getcwd.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getcwd 0x01300146ffff004f globl hidden diff --git a/libc/sysv/calls/sys_getgid.s b/libc/sysv/calls/sys_getgid.s new file mode 100644 index 000000000..b8aff476c --- /dev/null +++ b/libc/sysv/calls/sys_getgid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getgid 0x002f002f202f0068 globl hidden diff --git a/libc/sysv/calls/sys_getitimer.s b/libc/sysv/calls/sys_getitimer.s new file mode 100644 index 000000000..9b2d6080b --- /dev/null +++ b/libc/sysv/calls/sys_getitimer.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getitimer 0x0046005620560024 globl hidden diff --git a/libc/sysv/calls/sys_getpid.s b/libc/sysv/calls/sys_getpid.s new file mode 100644 index 000000000..f4f5139ad --- /dev/null +++ b/libc/sysv/calls/sys_getpid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getpid 0x0014001420140027 globl hidden diff --git a/libc/sysv/calls/sys_getppid.s b/libc/sysv/calls/sys_getppid.s new file mode 100644 index 000000000..2af623220 --- /dev/null +++ b/libc/sysv/calls/sys_getppid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getppid 0x002700272027006e globl hidden diff --git a/libc/sysv/calls/sys_getpriority.s b/libc/sysv/calls/sys_getpriority.s new file mode 100644 index 000000000..f7625d030 --- /dev/null +++ b/libc/sysv/calls/sys_getpriority.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getpriority 0x006400642064008c globl hidden diff --git a/libc/sysv/calls/sys_getrandom.s b/libc/sysv/calls/sys_getrandom.s new file mode 100644 index 000000000..ae490dbf6 --- /dev/null +++ b/libc/sysv/calls/sys_getrandom.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getrandom 0x0007023321f4013e globl hidden diff --git a/libc/sysv/calls/sys_getrlimit.s b/libc/sysv/calls/sys_getrlimit.s new file mode 100644 index 000000000..2e990f6d2 --- /dev/null +++ b/libc/sysv/calls/sys_getrlimit.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getrlimit 0x00c200c220c20061 globl hidden diff --git a/libc/sysv/calls/sys_getrusage.s b/libc/sysv/calls/sys_getrusage.s new file mode 100644 index 000000000..82059f39f --- /dev/null +++ b/libc/sysv/calls/sys_getrusage.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getrusage 0x0013007520750062 globl hidden diff --git a/libc/sysv/calls/sys_getsid.s b/libc/sysv/calls/sys_getsid.s new file mode 100644 index 000000000..9238c4e19 --- /dev/null +++ b/libc/sysv/calls/sys_getsid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getsid 0x00ff01362136007c globl hidden diff --git a/libc/sysv/calls/sys_getsockopt.s b/libc/sysv/calls/sys_getsockopt.s new file mode 100644 index 000000000..9b895c4b2 --- /dev/null +++ b/libc/sysv/calls/sys_getsockopt.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getsockopt 0x0076007620760037 globl hidden diff --git a/libc/sysv/calls/sys_gettid.s b/libc/sysv/calls/sys_gettid.s new file mode 100644 index 000000000..bb32d96d1 --- /dev/null +++ b/libc/sysv/calls/sys_gettid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_gettid 0xffffffff211e00ba globl hidden diff --git a/libc/sysv/calls/sys_getuid.s b/libc/sysv/calls/sys_getuid.s new file mode 100644 index 000000000..3143e3c3b --- /dev/null +++ b/libc/sysv/calls/sys_getuid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_getuid 0x0018001820180066 globl hidden diff --git a/libc/sysv/calls/sys_ioctl.s b/libc/sysv/calls/sys_ioctl.s new file mode 100644 index 000000000..c5f0a8d54 --- /dev/null +++ b/libc/sysv/calls/sys_ioctl.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_ioctl 0x0036003620360010 globl hidden diff --git a/libc/sysv/calls/sys_kill.s b/libc/sysv/calls/sys_kill.s new file mode 100644 index 000000000..107c91b08 --- /dev/null +++ b/libc/sysv/calls/sys_kill.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_kill 0x007a00252025003e globl hidden diff --git a/libc/sysv/calls/sys_killpg.s b/libc/sysv/calls/sys_killpg.s new file mode 100644 index 000000000..89e71a7d6 --- /dev/null +++ b/libc/sysv/calls/sys_killpg.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_killpg 0xffff0092ffffffff globl hidden diff --git a/libc/sysv/calls/sys_lchown.s b/libc/sysv/calls/sys_lchown.s new file mode 100644 index 000000000..bab85a1b9 --- /dev/null +++ b/libc/sysv/calls/sys_lchown.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_lchown 0x00fe00fe216c005e globl hidden diff --git a/libc/sysv/calls/sys_link.s b/libc/sysv/calls/sys_link.s new file mode 100644 index 000000000..a6be7aba6 --- /dev/null +++ b/libc/sysv/calls/sys_link.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_link 0x0009000920090056 globl hidden diff --git a/libc/sysv/calls/sys_linkat.s b/libc/sysv/calls/sys_linkat.s new file mode 100644 index 000000000..6cc4c1229 --- /dev/null +++ b/libc/sysv/calls/sys_linkat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_linkat 0x013d01ef21d70109 globl hidden diff --git a/libc/sysv/calls/sys_listen.s b/libc/sysv/calls/sys_listen.s new file mode 100644 index 000000000..a6b02da53 --- /dev/null +++ b/libc/sysv/calls/sys_listen.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_listen 0x006a006a206a0032 globl hidden diff --git a/libc/sysv/calls/sys_madvise.s b/libc/sysv/calls/sys_madvise.s new file mode 100644 index 000000000..89d0c633f --- /dev/null +++ b/libc/sysv/calls/sys_madvise.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_madvise 0x004b004b204b001c globl hidden diff --git a/libc/sysv/calls/sys_mkdir.s b/libc/sysv/calls/sys_mkdir.s new file mode 100644 index 000000000..95d9a8d16 --- /dev/null +++ b/libc/sysv/calls/sys_mkdir.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_mkdir 0x0088008820880053 globl hidden diff --git a/libc/sysv/calls/sys_mkdirat.s b/libc/sysv/calls/sys_mkdirat.s new file mode 100644 index 000000000..657149b79 --- /dev/null +++ b/libc/sysv/calls/sys_mkdirat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_mkdirat 0x013e01f021db0102 globl hidden diff --git a/libc/sysv/calls/sys_mkfifo.s b/libc/sysv/calls/sys_mkfifo.s new file mode 100644 index 000000000..2c85eae43 --- /dev/null +++ b/libc/sysv/calls/sys_mkfifo.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_mkfifo 0x008400842084ffff globl hidden diff --git a/libc/sysv/calls/sys_mknod.s b/libc/sysv/calls/sys_mknod.s new file mode 100644 index 000000000..a9e823535 --- /dev/null +++ b/libc/sysv/calls/sys_mknod.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_mknod 0x000e000e200e0085 globl hidden diff --git a/libc/sysv/calls/sys_mprotect.s b/libc/sysv/calls/sys_mprotect.s new file mode 100644 index 000000000..eaca0f50e --- /dev/null +++ b/libc/sysv/calls/sys_mprotect.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_mprotect 0x004a004a204a000a globl hidden diff --git a/libc/sysv/calls/sys_mremap.s b/libc/sysv/calls/sys_mremap.s new file mode 100644 index 000000000..1f0bad1e5 --- /dev/null +++ b/libc/sysv/calls/sys_mremap.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_mremap 0xffffffffffff0019 globl hidden diff --git a/libc/sysv/calls/sys_msync.s b/libc/sysv/calls/sys_msync.s new file mode 100644 index 000000000..29ade6246 --- /dev/null +++ b/libc/sysv/calls/sys_msync.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_msync 0x010000412041001a globl hidden diff --git a/libc/sysv/calls/sys_munmap.s b/libc/sysv/calls/sys_munmap.s new file mode 100644 index 000000000..f5eba48e5 --- /dev/null +++ b/libc/sysv/calls/sys_munmap.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_munmap 0x004900492049000b globl hidden diff --git a/libc/sysv/calls/sys_nanosleep.s b/libc/sysv/calls/sys_nanosleep.s new file mode 100644 index 000000000..a1de7da5b --- /dev/null +++ b/libc/sysv/calls/sys_nanosleep.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_nanosleep 0x005b00f0ffff0023 globl hidden diff --git a/libc/sysv/calls/sys_open.s b/libc/sysv/calls/sys_open.s new file mode 100644 index 000000000..01a54065e --- /dev/null +++ b/libc/sysv/calls/sys_open.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_open 0x0005000520050002 globl hidden diff --git a/libc/sysv/calls/sys_openat.s b/libc/sysv/calls/sys_openat.s new file mode 100644 index 000000000..571cfb9c1 --- /dev/null +++ b/libc/sysv/calls/sys_openat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_openat 0x014101f321cf0101 globl hidden diff --git a/libc/sysv/calls/sys_pause.s b/libc/sysv/calls/sys_pause.s new file mode 100644 index 000000000..f59f8ef1f --- /dev/null +++ b/libc/sysv/calls/sys_pause.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_pause 0xffffffffffff0022 globl hidden diff --git a/libc/sysv/calls/sys_poll.s b/libc/sysv/calls/sys_poll.s new file mode 100644 index 000000000..483a275aa --- /dev/null +++ b/libc/sysv/calls/sys_poll.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_poll 0x00fc00d120e60007 globl hidden diff --git a/libc/sysv/calls/sys_posix_fallocate.s b/libc/sysv/calls/sys_posix_fallocate.s new file mode 100644 index 000000000..401454e25 --- /dev/null +++ b/libc/sysv/calls/sys_posix_fallocate.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_posix_fallocate 0xffff0212ffffffff globl hidden diff --git a/libc/sysv/calls/sys_posix_openpt.s b/libc/sysv/calls/sys_posix_openpt.s new file mode 100644 index 000000000..37ecabd07 --- /dev/null +++ b/libc/sysv/calls/sys_posix_openpt.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_posix_openpt 0xffff01f8ffffffff globl hidden diff --git a/libc/sysv/calls/sys_posix_spawn.s b/libc/sysv/calls/sys_posix_spawn.s new file mode 100644 index 000000000..0012ba62c --- /dev/null +++ b/libc/sysv/calls/sys_posix_spawn.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_posix_spawn 0xffffffff20f4ffff globl hidden diff --git a/libc/sysv/calls/sys_ppoll.s b/libc/sysv/calls/sys_ppoll.s new file mode 100644 index 000000000..a39263971 --- /dev/null +++ b/libc/sysv/calls/sys_ppoll.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_ppoll 0x006d0221ffff010f globl hidden diff --git a/libc/sysv/calls/sys_ptrace.s b/libc/sysv/calls/sys_ptrace.s new file mode 100644 index 000000000..ac50394f3 --- /dev/null +++ b/libc/sysv/calls/sys_ptrace.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_ptrace 0x001a001a201a0065 globl hidden diff --git a/libc/sysv/calls/sys_read.s b/libc/sysv/calls/sys_read.s new file mode 100644 index 000000000..450ba018a --- /dev/null +++ b/libc/sysv/calls/sys_read.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_read 0x0003000320030000 globl hidden diff --git a/libc/sysv/calls/sys_readlinkat.s b/libc/sysv/calls/sys_readlinkat.s new file mode 100644 index 000000000..0a22b6956 --- /dev/null +++ b/libc/sysv/calls/sys_readlinkat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_readlinkat 0x014201f421d9010b globl hidden diff --git a/libc/sysv/calls/sys_readv.s b/libc/sysv/calls/sys_readv.s new file mode 100644 index 000000000..8986a6dcd --- /dev/null +++ b/libc/sysv/calls/sys_readv.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_readv 0x0078007820780013 globl hidden diff --git a/libc/sysv/calls/sys_recvfrom.s b/libc/sysv/calls/sys_recvfrom.s new file mode 100644 index 000000000..f7601691d --- /dev/null +++ b/libc/sysv/calls/sys_recvfrom.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_recvfrom 0x001d001d201d002d globl hidden diff --git a/libc/sysv/calls/sys_recvmsg.s b/libc/sysv/calls/sys_recvmsg.s new file mode 100644 index 000000000..64f2a7954 --- /dev/null +++ b/libc/sysv/calls/sys_recvmsg.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_recvmsg 0x001b001b201b002f globl hidden diff --git a/libc/sysv/calls/sys_rename.s b/libc/sysv/calls/sys_rename.s new file mode 100644 index 000000000..51c737369 --- /dev/null +++ b/libc/sysv/calls/sys_rename.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_rename 0x0080008020800052 globl hidden diff --git a/libc/sysv/calls/sys_renameat.s b/libc/sysv/calls/sys_renameat.s new file mode 100644 index 000000000..ccc3b08de --- /dev/null +++ b/libc/sysv/calls/sys_renameat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_renameat 0x014301f521d10108 globl hidden diff --git a/libc/sysv/calls/sys_rmdir.s b/libc/sysv/calls/sys_rmdir.s new file mode 100644 index 000000000..5023afcc5 --- /dev/null +++ b/libc/sysv/calls/sys_rmdir.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_rmdir 0x0089008920890054 globl hidden diff --git a/libc/sysv/calls/sys_sched_setaffinity.s b/libc/sysv/calls/sys_sched_setaffinity.s new file mode 100644 index 000000000..21741a7a3 --- /dev/null +++ b/libc/sysv/calls/sys_sched_setaffinity.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sched_setaffinity 0xffffffffffff00cb globl hidden diff --git a/libc/sysv/calls/sys_sched_yield.s b/libc/sysv/calls/sys_sched_yield.s new file mode 100644 index 000000000..fc5fc4ac8 --- /dev/null +++ b/libc/sysv/calls/sys_sched_yield.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sched_yield 0x012a014b103c0018 globl hidden diff --git a/libc/sysv/calls/sys_select.s b/libc/sysv/calls/sys_select.s new file mode 100644 index 000000000..fd314c44f --- /dev/null +++ b/libc/sysv/calls/sys_select.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_select 0x0047005d205d0017 globl hidden diff --git a/libc/sysv/calls/sys_sendfile.s b/libc/sysv/calls/sys_sendfile.s new file mode 100644 index 000000000..01baf4c50 --- /dev/null +++ b/libc/sysv/calls/sys_sendfile.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sendfile 0xffff018921510028 globl hidden diff --git a/libc/sysv/calls/sys_sendmsg.s b/libc/sysv/calls/sys_sendmsg.s new file mode 100644 index 000000000..cc8a877ac --- /dev/null +++ b/libc/sysv/calls/sys_sendmsg.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sendmsg 0x001c001c201c002e globl hidden diff --git a/libc/sysv/calls/sys_sendto.s b/libc/sysv/calls/sys_sendto.s new file mode 100644 index 000000000..405896b6e --- /dev/null +++ b/libc/sysv/calls/sys_sendto.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sendto 0x008500852085002c globl hidden diff --git a/libc/sysv/calls/sys_setitimer.s b/libc/sysv/calls/sys_setitimer.s new file mode 100644 index 000000000..ea979d80a --- /dev/null +++ b/libc/sysv/calls/sys_setitimer.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_setitimer 0x0045005320530026 globl hidden diff --git a/libc/sysv/calls/sys_setpriority.s b/libc/sysv/calls/sys_setpriority.s new file mode 100644 index 000000000..c91840a73 --- /dev/null +++ b/libc/sysv/calls/sys_setpriority.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_setpriority 0x006000602060008d globl hidden diff --git a/libc/sysv/calls/sys_setresgid.s b/libc/sysv/calls/sys_setresgid.s new file mode 100644 index 000000000..244f1c025 --- /dev/null +++ b/libc/sysv/calls/sys_setresgid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_setresgid 0x011c0138ffff0077 globl hidden diff --git a/libc/sysv/calls/sys_setresuid.s b/libc/sysv/calls/sys_setresuid.s new file mode 100644 index 000000000..f7df8191a --- /dev/null +++ b/libc/sysv/calls/sys_setresuid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_setresuid 0x011a0137ffff0075 globl hidden diff --git a/libc/sysv/calls/sys_setrlimit.s b/libc/sysv/calls/sys_setrlimit.s new file mode 100644 index 000000000..9d5e361d1 --- /dev/null +++ b/libc/sysv/calls/sys_setrlimit.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_setrlimit 0x00c300c320c300a0 globl hidden diff --git a/libc/sysv/calls/sys_setsid.s b/libc/sysv/calls/sys_setsid.s new file mode 100644 index 000000000..576237073 --- /dev/null +++ b/libc/sysv/calls/sys_setsid.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_setsid 0x0093009320930070 globl hidden diff --git a/libc/sysv/calls/sys_setsockopt.s b/libc/sysv/calls/sys_setsockopt.s new file mode 100644 index 000000000..e67c9040e --- /dev/null +++ b/libc/sysv/calls/sys_setsockopt.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_setsockopt 0x0069006920690036 globl hidden diff --git a/libc/sysv/calls/sys_shutdown.s b/libc/sysv/calls/sys_shutdown.s new file mode 100644 index 000000000..57a83e083 --- /dev/null +++ b/libc/sysv/calls/sys_shutdown.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_shutdown 0x0086008620860030 globl hidden diff --git a/libc/sysv/calls/sys_sigaction.s b/libc/sysv/calls/sys_sigaction.s new file mode 100644 index 000000000..9f57594e1 --- /dev/null +++ b/libc/sysv/calls/sys_sigaction.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sigaction 0x002e01a0202e000d globl hidden diff --git a/libc/sysv/calls/sys_sigprocmask.s b/libc/sysv/calls/sys_sigprocmask.s new file mode 100644 index 000000000..4187a59ea --- /dev/null +++ b/libc/sysv/calls/sys_sigprocmask.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sigprocmask 0x003001542030000e globl hidden diff --git a/libc/sysv/calls/sys_sigsuspend.s b/libc/sysv/calls/sys_sigsuspend.s new file mode 100644 index 000000000..7d66ac4bc --- /dev/null +++ b/libc/sysv/calls/sys_sigsuspend.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sigsuspend 0x006f0155206f0082 globl hidden diff --git a/libc/sysv/calls/sys_socketpair.s b/libc/sysv/calls/sys_socketpair.s new file mode 100644 index 000000000..d881b2560 --- /dev/null +++ b/libc/sysv/calls/sys_socketpair.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_socketpair 0x0087008720870035 globl hidden diff --git a/libc/sysv/calls/sys_splice.s b/libc/sysv/calls/sys_splice.s new file mode 100644 index 000000000..baf3c82a3 --- /dev/null +++ b/libc/sysv/calls/sys_splice.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_splice 0xffffffffffff0113 globl hidden diff --git a/libc/sysv/calls/sys_symlink.s b/libc/sysv/calls/sys_symlink.s new file mode 100644 index 000000000..dbb57a713 --- /dev/null +++ b/libc/sysv/calls/sys_symlink.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_symlink 0x0039003920390058 globl hidden diff --git a/libc/sysv/calls/sys_symlinkat.s b/libc/sysv/calls/sys_symlinkat.s new file mode 100644 index 000000000..98ffff630 --- /dev/null +++ b/libc/sysv/calls/sys_symlinkat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_symlinkat 0x014401f621da010a globl hidden diff --git a/libc/sysv/calls/sys_sync.s b/libc/sysv/calls/sys_sync.s new file mode 100644 index 000000000..5ef92433e --- /dev/null +++ b/libc/sysv/calls/sys_sync.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sync 0x00240024202400a2 globl hidden diff --git a/libc/sysv/calls/sys_sync_file_range.s b/libc/sysv/calls/sys_sync_file_range.s new file mode 100644 index 000000000..46c7aa946 --- /dev/null +++ b/libc/sysv/calls/sys_sync_file_range.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sync_file_range 0xffffffffffff0115 globl hidden diff --git a/libc/sysv/calls/sys_sysinfo.s b/libc/sysv/calls/sys_sysinfo.s new file mode 100644 index 000000000..13dcc93ce --- /dev/null +++ b/libc/sysv/calls/sys_sysinfo.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_sysinfo 0xffffffffffff0063 globl hidden diff --git a/libc/sysv/calls/sys_times.s b/libc/sysv/calls/sys_times.s new file mode 100644 index 000000000..3af59a5aa --- /dev/null +++ b/libc/sysv/calls/sys_times.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_times 0xffffffffffff0064 globl hidden diff --git a/libc/sysv/calls/sys_uname.s b/libc/sysv/calls/sys_uname.s new file mode 100644 index 000000000..d1ae2799d --- /dev/null +++ b/libc/sysv/calls/sys_uname.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_uname 0xffff00a4ffff003f globl hidden diff --git a/libc/sysv/calls/sys_unlink.s b/libc/sysv/calls/sys_unlink.s new file mode 100644 index 000000000..3a68345ef --- /dev/null +++ b/libc/sysv/calls/sys_unlink.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_unlink 0x000a000a200a0057 globl hidden diff --git a/libc/sysv/calls/sys_unlinkat.s b/libc/sysv/calls/sys_unlinkat.s new file mode 100644 index 000000000..480d6637f --- /dev/null +++ b/libc/sysv/calls/sys_unlinkat.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_unlinkat 0x014501f721d80107 globl hidden diff --git a/libc/sysv/calls/sys_utime.s b/libc/sysv/calls/sys_utime.s new file mode 100644 index 000000000..9f234ba2a --- /dev/null +++ b/libc/sysv/calls/sys_utime.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_utime 0xffffffffffff0084 globl hidden diff --git a/libc/sysv/calls/sys_utimes.s b/libc/sysv/calls/sys_utimes.s new file mode 100644 index 000000000..17525b26e --- /dev/null +++ b/libc/sysv/calls/sys_utimes.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_utimes 0x004c008a208a00eb globl hidden diff --git a/libc/sysv/calls/sys_vmsplice.s b/libc/sysv/calls/sys_vmsplice.s new file mode 100644 index 000000000..8b18cb3be --- /dev/null +++ b/libc/sysv/calls/sys_vmsplice.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_vmsplice 0xffffffffffff0116 globl hidden diff --git a/libc/sysv/calls/sys_wait4.s b/libc/sysv/calls/sys_wait4.s new file mode 100644 index 000000000..9a7230618 --- /dev/null +++ b/libc/sysv/calls/sys_wait4.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_wait4 0x000b00072007003d globl hidden diff --git a/libc/sysv/calls/sys_write.s b/libc/sysv/calls/sys_write.s new file mode 100644 index 000000000..bfea8884d --- /dev/null +++ b/libc/sysv/calls/sys_write.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_write 0x0004000420040001 globl hidden diff --git a/libc/sysv/calls/sys_writev.s b/libc/sysv/calls/sys_writev.s new file mode 100644 index 000000000..c4c3af777 --- /dev/null +++ b/libc/sysv/calls/sys_writev.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall sys_writev 0x0079007920790014 globl hidden diff --git a/libc/sysv/calls/sysinfo-sysv.s b/libc/sysv/calls/sysinfo-sysv.s deleted file mode 100644 index 238269010..000000000 --- a/libc/sysv/calls/sysinfo-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall sysinfo$sysv 0xffffffffffff0063 globl hidden diff --git a/libc/sysv/calls/times-sysv.s b/libc/sysv/calls/times-sysv.s deleted file mode 100644 index 7f504bfd9..000000000 --- a/libc/sysv/calls/times-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall times$sysv 0xffffffffffff0064 globl hidden diff --git a/libc/sysv/calls/uname-sysv.s b/libc/sysv/calls/uname-sysv.s deleted file mode 100644 index 3e245a60c..000000000 --- a/libc/sysv/calls/uname-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall uname$sysv 0xffff00a4ffff003f globl hidden diff --git a/libc/sysv/calls/unlink-sysv.s b/libc/sysv/calls/unlink-sysv.s deleted file mode 100644 index ebf9a4f06..000000000 --- a/libc/sysv/calls/unlink-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall unlink$sysv 0x000a000a200a0057 globl hidden diff --git a/libc/sysv/calls/unlinkat-sysv.s b/libc/sysv/calls/unlinkat-sysv.s deleted file mode 100644 index f95f158ff..000000000 --- a/libc/sysv/calls/unlinkat-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall unlinkat$sysv 0x014501f721d80107 globl hidden diff --git a/libc/sysv/calls/utime-sysv.s b/libc/sysv/calls/utime-sysv.s deleted file mode 100644 index 41a5a42de..000000000 --- a/libc/sysv/calls/utime-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall utime$sysv 0xffffffffffff0084 globl hidden diff --git a/libc/sysv/calls/utimes-sysv.s b/libc/sysv/calls/utimes-sysv.s deleted file mode 100644 index cdae3bcd8..000000000 --- a/libc/sysv/calls/utimes-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall utimes$sysv 0x004c008a208a00eb globl hidden diff --git a/libc/sysv/calls/vmsplice-sysv.s b/libc/sysv/calls/vmsplice-sysv.s deleted file mode 100644 index a6967d05d..000000000 --- a/libc/sysv/calls/vmsplice-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall vmsplice$sysv 0xffffffffffff0116 globl hidden diff --git a/libc/sysv/calls/wait4-sysv.s b/libc/sysv/calls/wait4-sysv.s deleted file mode 100644 index f82e9ef99..000000000 --- a/libc/sysv/calls/wait4-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall wait4$sysv 0x000b00072007003d globl hidden diff --git a/libc/sysv/calls/write-sysv.s b/libc/sysv/calls/write-sysv.s deleted file mode 100644 index f11a54238..000000000 --- a/libc/sysv/calls/write-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall write$sysv 0x0004000420040001 globl hidden diff --git a/libc/sysv/calls/writev-sysv.s b/libc/sysv/calls/writev-sysv.s deleted file mode 100644 index daa2124c4..000000000 --- a/libc/sysv/calls/writev-sysv.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall writev$sysv 0x0079007920790014 globl hidden diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 451a081b5..a8d798b50 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -461,7 +461,7 @@ syscon auxv AT_UCACHEBSIZE 21 0 0 0 0 syscon auxv AT_SECURE 23 0 0 0 0 syscon auxv AT_BASE_PLATFORM 24 0 0 0 0 syscon auxv AT_RANDOM 25 0 0 0 0 # address of sixteen bytes of random data -syscon auxv AT_EXECFN 31 999 999 999 999 # address of string containing first argument passed to execve() used when running program [faked on non-linux] +syscon auxv AT_EXECFN 31 31 999 999 999 # address of string containing first argument passed to execve() used when running program [faked on non-linux] syscon auxv AT_SYSINFO_EHDR 33 0 0 0 0 syscon auxv AT_NO_AUTOMOUNT 0x0800 0 0 0 0 diff --git a/libc/sysv/consts/AT_EXECFN.s b/libc/sysv/consts/AT_EXECFN.s index 621655d9f..97900473b 100644 --- a/libc/sysv/consts/AT_EXECFN.s +++ b/libc/sysv/consts/AT_EXECFN.s @@ -1,2 +1,2 @@ .include "libc/sysv/consts/syscon.inc" -.syscon auxv AT_EXECFN 31 999 999 999 999 +.syscon auxv AT_EXECFN 31 31 999 999 999 diff --git a/libc/sysv/errfuns.h b/libc/sysv/errfuns.h index 90805b523..6b2ad156a 100644 --- a/libc/sysv/errfuns.h +++ b/libc/sysv/errfuns.h @@ -21,15 +21,146 @@ * @see libc/sysv/errfuns.inc (for implementation) */ +intptr_t einval(void) relegated; +intptr_t eperm(void) relegated; +intptr_t enoent(void) relegated; +intptr_t esrch(void) relegated; +intptr_t eintr(void) relegated; +intptr_t eio(void) relegated; +intptr_t enxio(void) relegated; +intptr_t e2big(void) relegated; +intptr_t enoexec(void) relegated; +intptr_t ebadf(void) relegated; +intptr_t echild(void) relegated; +intptr_t eagain(void) relegated; +intptr_t enomem(void) relegated; +intptr_t eacces(void) relegated; +intptr_t efault(void) relegated; +intptr_t enotblk(void) relegated; +intptr_t ebusy(void) relegated; +intptr_t eexist(void) relegated; +intptr_t exdev(void) relegated; +intptr_t enodev(void) relegated; +intptr_t enotdir(void) relegated; +intptr_t eisdir(void) relegated; +intptr_t enfile(void) relegated; +intptr_t emfile(void) relegated; +intptr_t enotty(void) relegated; +intptr_t enotsup(void) relegated; +intptr_t etxtbsy(void) relegated; +intptr_t efbig(void) relegated; +intptr_t enospc(void) relegated; +intptr_t espipe(void) relegated; +intptr_t erofs(void) relegated; +intptr_t emlink(void) relegated; +intptr_t epipe(void) relegated; +intptr_t edom(void) relegated; +intptr_t erange(void) relegated; +intptr_t edeadlk(void) relegated; +intptr_t enametoolong(void) relegated; +intptr_t enolck(void) relegated; +intptr_t enosys(void) relegated; +intptr_t enotempty(void) relegated; +intptr_t eloop(void) relegated; +intptr_t enomsg(void) relegated; +intptr_t eidrm(void) relegated; +intptr_t echrng(void) relegated; +intptr_t el2nsync(void) relegated; +intptr_t el3hlt(void) relegated; +intptr_t el3rst(void) relegated; +intptr_t elnrng(void) relegated; +intptr_t eunatch(void) relegated; +intptr_t enocsi(void) relegated; +intptr_t el2hlt(void) relegated; +intptr_t ebade(void) relegated; +intptr_t ebadr(void) relegated; +intptr_t exfull(void) relegated; +intptr_t enoano(void) relegated; +intptr_t ebadrqc(void) relegated; +intptr_t ebadslt(void) relegated; +intptr_t enostr(void) relegated; +intptr_t enodata(void) relegated; +intptr_t etime(void) relegated; +intptr_t enosr(void) relegated; +intptr_t enonet(void) relegated; +intptr_t enopkg(void) relegated; +intptr_t eremote(void) relegated; +intptr_t enolink(void) relegated; +intptr_t eadv(void) relegated; +intptr_t esrmnt(void) relegated; +intptr_t ecomm(void) relegated; +intptr_t eproto(void) relegated; +intptr_t emultihop(void) relegated; +intptr_t edotdot(void) relegated; +intptr_t ebadmsg(void) relegated; +intptr_t eoverflow(void) relegated; +intptr_t enotuniq(void) relegated; +intptr_t ebadfd(void) relegated; +intptr_t eremchg(void) relegated; +intptr_t elibacc(void) relegated; +intptr_t elibbad(void) relegated; +intptr_t elibscn(void) relegated; +intptr_t elibmax(void) relegated; +intptr_t elibexec(void) relegated; +intptr_t eilseq(void) relegated; +intptr_t erestart(void) relegated; +intptr_t estrpipe(void) relegated; +intptr_t eusers(void) relegated; +intptr_t enotsock(void) relegated; +intptr_t edestaddrreq(void) relegated; +intptr_t emsgsize(void) relegated; +intptr_t eprototype(void) relegated; +intptr_t enoprotoopt(void) relegated; +intptr_t eprotonosupport(void) relegated; +intptr_t esocktnosupport(void) relegated; +intptr_t eopnotsupp(void) relegated; +intptr_t epfnosupport(void) relegated; +intptr_t eafnosupport(void) relegated; +intptr_t eaddrinuse(void) relegated; +intptr_t eaddrnotavail(void) relegated; +intptr_t enetdown(void) relegated; +intptr_t enetunreach(void) relegated; +intptr_t enetreset(void) relegated; +intptr_t econnaborted(void) relegated; +intptr_t econnreset(void) relegated; +intptr_t enobufs(void) relegated; +intptr_t eisconn(void) relegated; +intptr_t enotconn(void) relegated; +intptr_t eshutdown(void) relegated; +intptr_t etoomanyrefs(void) relegated; +intptr_t etimedout(void) relegated; +intptr_t econnrefused(void) relegated; +intptr_t ehostdown(void) relegated; +intptr_t ehostunreach(void) relegated; +intptr_t ealready(void) relegated; +intptr_t einprogress(void) relegated; +intptr_t estale(void) relegated; +intptr_t euclean(void) relegated; +intptr_t enotnam(void) relegated; +intptr_t enavail(void) relegated; +intptr_t eisnam(void) relegated; +intptr_t eremoteio(void) relegated; +intptr_t edquot(void) relegated; +intptr_t enomedium(void) relegated; +intptr_t emediumtype(void) relegated; +intptr_t ecanceled(void) relegated; +intptr_t enokey(void) relegated; +intptr_t ekeyexpired(void) relegated; +intptr_t ekeyrevoked(void) relegated; +intptr_t ekeyrejected(void) relegated; +intptr_t eownerdead(void) relegated; +intptr_t enotrecoverable(void) relegated; +intptr_t erfkill(void) relegated; +intptr_t ehwpoison(void) relegated; + +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) #define __ERRFUN(FUNC) \ ({ \ intptr_t NegOne; \ asm("call\t" FUNC : "=a"(NegOne), "=m"(errno)); \ NegOne; \ }) - -int einval(void) relegated; - +#define einval() __ERRFUN("einval") #define eperm() __ERRFUN("eperm") #define enoent() __ERRFUN("enoent") #define esrch() __ERRFUN("esrch") @@ -160,6 +291,7 @@ int einval(void) relegated; #define enotrecoverable() __ERRFUN("enotrecoverable") #define erfkill() __ERRFUN("erfkill") #define ehwpoison() __ERRFUN("ehwpoison") +#endif #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_SYSV_ERRFUNS_H_ */ diff --git a/libc/sysv/nr.py b/libc/sysv/nr.py index f3b74d207..d1d08a3ee 100644 --- a/libc/sysv/nr.py +++ b/libc/sysv/nr.py @@ -9,9 +9,9 @@ for line in lines: if name.startswith("'"): name = name[1:] if name.endswith("'"): name = name[:-1] if name.startswith("__"): name = name[2:] - if name.endswith("$sysv"): name = name[:-5] - if name.endswith("$bsd"): name = name[:-4] - if name.endswith("$freebsd"): name = name[:-8] + if name.startswith("sys_"): name = name[:-5] + if name.endswith("_bsd"): name = name[:-4] + if name.endswith("_freebsd"): name = name[:-8] numbers = int(fields[2][2:], 16) systemd = (numbers >> 000) & 0xffff xnu = (numbers >> 020) & 0x0fff | ((numbers >> 28) & 0xf) << 20 diff --git a/libc/sysv/syscalls.sh b/libc/sysv/syscalls.sh index 15b540241..33af52bba 100755 --- a/libc/sysv/syscalls.sh +++ b/libc/sysv/syscalls.sh @@ -22,86 +22,86 @@ dir=libc/sysv/calls # The Fifth Bell System Interface, Community Edition ┌─────────────────────────┐ # » so many numbers │ legend │ # ├─────────────────────────┤ -# GNU/Systemd┐ │ ffff │ unavailable │ -# 2.6.18+│ │ $ │ wrapped │ -# Mac OS X┐ │ │ __ │ wrapped twice │ +# GNU/Systemd┐ │ ffff │ unavailable │ +# 2.6.18+│ │ sys_ │ wrapped │ +# Mac OS X┐ │ │ __sys_ │ wrapped twice │ # 15.6+│ │ └─────────────────────────┘ # FreeBSD┐ │ │ # 12+│ ┌─│───│── XnuClass{1:Mach,2:Unix} # OpenBSD┐ │ │ │ │ # 6.4+│ │ │ │ │ # Symbol ┌─┴┐┌─┴┐│┬┴┐┌─┴┐ Directives & Commentary -scall 'exit$sysv' 0x00010001200100e7 globl hidden # a.k.a. exit_group -scall 'read$sysv' 0x0003000320030000 globl hidden -scall 'write$sysv' 0x0004000420040001 globl hidden -scall 'open$sysv' 0x0005000520050002 globl hidden -scall 'close$sysv' 0x0006000620060003 globl hidden -scall '__stat$sysv' 0x0026ffff21520004 globl hidden # FreeBSD 11→12 fumble; use fstatat$sysv(); blocked on Android -scall '__fstat$sysv' 0x0035022721530005 globl hidden # needs stat2linux() -scall '__lstat$sysv' 0x0028002821540006 globl hidden # needs stat2linux(); blocked on Android -scall 'poll$sysv' 0x00fc00d120e60007 globl hidden -scall 'ppoll$sysv' 0x006d0221ffff010f globl hidden # consider INTON/INTOFF tutorial in examples/unbourne.c -scall '__lseek$sysv' 0x00c701de20c70008 globl hidden # openbsd:evilpad -scall '__mmap$sysv' 0x00c501dd20c50009 globl hidden # openbsd:pad -scall 'msync$sysv' 0x010000412041001a globl hidden -scall 'mprotect$sysv' 0x004a004a204a000a globl hidden -scall 'munmap$sysv' 0x004900492049000b globl hidden -scall 'sigaction$sysv' 0x002e01a0202e000d globl hidden # rt_sigaction on Lunix -scall 'sigprocmask$sysv' 0x003001542030000e globl hidden # a.k.a. rt_sigprocmask -scall 'ioctl$sysv' 0x0036003620360010 globl hidden -scall '__pread$sysv' 0x00ad01db20990011 globl hidden # a.k.a. pread64; openbsd:pad -scall '__pwrite$sysv' 0x00ae01dc209a0012 globl hidden # a.k.a. pwrite64; openbsd:pad -scall 'readv$sysv' 0x0078007820780013 globl hidden -scall 'writev$sysv' 0x0079007920790014 globl hidden -scall 'access$sysv' 0x0021002120210015 globl hidden -scall '__pipe$sysv' 0x0107021e202a0016 globl hidden # NOTE: pipe2() on FreeBSD; XNU is pipe(void)→eax:edx -scall 'select$sysv' 0x0047005d205d0017 globl hidden +scall sys_exit 0x00010001200100e7 globl hidden # a.k.a. exit_group +scall sys_read 0x0003000320030000 globl hidden +scall sys_write 0x0004000420040001 globl hidden +scall sys_open 0x0005000520050002 globl hidden +scall sys_close 0x0006000620060003 globl hidden +scall __sys_stat 0x0026ffff21520004 globl hidden # FreeBSD 11→12 fumble; use sys_fstatat(); blocked on Android +scall __sys_fstat 0x0035022721530005 globl hidden # needs __stat2linux() +scall __sys_lstat 0x0028002821540006 globl hidden # needs __stat2linux(); blocked on Android +scall sys_poll 0x00fc00d120e60007 globl hidden +scall sys_ppoll 0x006d0221ffff010f globl hidden # consider INTON/INTOFF tutorial in examples/unbourne.c +scall __sys_lseek 0x00c701de20c70008 globl hidden # openbsd:evilpad +scall __sys_mmap 0x00c501dd20c50009 globl hidden # openbsd:pad +scall sys_msync 0x010000412041001a globl hidden +scall sys_mprotect 0x004a004a204a000a globl hidden +scall sys_munmap 0x004900492049000b globl hidden +scall sys_sigaction 0x002e01a0202e000d globl hidden # rt_sigaction on Lunix +scall sys_sigprocmask 0x003001542030000e globl hidden # a.k.a. rt_sigprocmask +scall sys_ioctl 0x0036003620360010 globl hidden +scall __sys_pread 0x00ad01db20990011 globl hidden # a.k.a. pread64; openbsd:pad +scall __sys_pwrite 0x00ae01dc209a0012 globl hidden # a.k.a. pwrite64; openbsd:pad +scall sys_readv 0x0078007820780013 globl hidden +scall sys_writev 0x0079007920790014 globl hidden +scall sys_access 0x0021002120210015 globl hidden +scall __sys_pipe 0x0107021e202a0016 globl hidden # NOTE: pipe2() on FreeBSD; XNU is pipe(void)→eax:edx +scall sys_select 0x0047005d205d0017 globl hidden scall pselect 0x006e020a218affff globl scall pselect6 0xffffffffffff010e globl -scall 'sched_yield$sysv' 0x012a014b103c0018 globl hidden # swtch() on xnu -scall 'mremap$sysv' 0xffffffffffff0019 globl hidden +scall sys_sched_yield 0x012a014b103c0018 globl hidden # swtch() on xnu +scall sys_mremap 0xffffffffffff0019 globl hidden scall mincore 0x004e004e204e001b globl -scall 'madvise$sysv' 0x004b004b204b001c globl hidden +scall sys_madvise 0x004b004b204b001c globl hidden scall shmget 0x012100e72109001d globl # consider mmap scall shmat 0x00e400e42106001e globl # consider mmap scall shmctl 0x012802002107001f globl # consider mmap -scall 'dup$sysv' 0x0029002920290020 globl hidden -scall 'dup2$sysv' 0x005a005a205a0021 globl hidden -scall 'pause$sysv' 0xffffffffffff0022 globl hidden -scall 'nanosleep$sysv' 0x005b00f0ffff0023 globl hidden -scall 'getitimer$sysv' 0x0046005620560024 globl hidden -scall 'setitimer$sysv' 0x0045005320530026 globl hidden -scall 'alarm$sysv' 0xffffffffffff0025 globl hidden -scall 'getpid$sysv' 0x0014001420140027 globl hidden -scall 'sendfile$sysv' 0xffff018921510028 globl hidden # Linux vs. XNU/BSD ABIs very different -scall '__socket$sysv' 0x0061006120610029 globl hidden -scall '__connect$sysv' 0x006200622062002a globl hidden -scall '__accept$sysv' 0x001e021d201e002b globl hidden # accept4 on freebsd -scall 'sendto$sysv' 0x008500852085002c globl hidden -scall 'recvfrom$sysv' 0x001d001d201d002d globl hidden -scall 'sendmsg$sysv' 0x001c001c201c002e globl hidden -scall 'recvmsg$sysv' 0x001b001b201b002f globl hidden -scall 'shutdown$sysv' 0x0086008620860030 globl hidden -scall 'bind$sysv' 0x0068006820680031 globl hidden -scall 'listen$sysv' 0x006a006a206a0032 globl hidden -scall '__getsockname$sysv' 0x0020002020200033 globl hidden -scall '__getpeername$sysv' 0x001f008d201f0034 globl hidden -scall 'socketpair$sysv' 0x0087008720870035 globl hidden -scall 'setsockopt$sysv' 0x0069006920690036 globl hidden -scall 'getsockopt$sysv' 0x0076007620760037 globl hidden -scall '__fork$sysv' 0x0002000220020039 globl hidden # xnu needs eax=~-edx b/c eax always holds pid and edx is 0 for parent and 1 for child +scall sys_dup 0x0029002920290020 globl hidden +scall sys_dup2 0x005a005a205a0021 globl hidden +scall sys_pause 0xffffffffffff0022 globl hidden +scall sys_nanosleep 0x005b00f0ffff0023 globl hidden +scall sys_getitimer 0x0046005620560024 globl hidden +scall sys_setitimer 0x0045005320530026 globl hidden +scall sys_alarm 0xffffffffffff0025 globl hidden +scall sys_getpid 0x0014001420140027 globl hidden +scall sys_sendfile 0xffff018921510028 globl hidden # Linux vs. XNU/BSD ABIs very different +scall __sys_socket 0x0061006120610029 globl hidden +scall __sys_connect 0x006200622062002a globl hidden +scall __sys_accept 0x001e021d201e002b globl hidden # accept4 on freebsd +scall sys_sendto 0x008500852085002c globl hidden +scall sys_recvfrom 0x001d001d201d002d globl hidden +scall sys_sendmsg 0x001c001c201c002e globl hidden +scall sys_recvmsg 0x001b001b201b002f globl hidden +scall sys_shutdown 0x0086008620860030 globl hidden +scall sys_bind 0x0068006820680031 globl hidden +scall sys_listen 0x006a006a206a0032 globl hidden +scall __sys_getsockname 0x0020002020200033 globl hidden +scall __sys_getpeername 0x001f008d201f0034 globl hidden +scall sys_socketpair 0x0087008720870035 globl hidden +scall sys_setsockopt 0x0069006920690036 globl hidden +scall sys_getsockopt 0x0076007620760037 globl hidden +scall __sys_fork 0x0002000220020039 globl hidden # xnu needs eax=~-edx b/c eax always holds pid and edx is 0 for parent and 1 for child #scall vfork 0x004200422042003a globl # this syscall is from the moon so we implement it by hand in libc/calls/hefty/vfork.S -scall 'posix_spawn$sysv' 0xffffffff20f4ffff globl hidden # good luck figuring out how xnu defines this -scall '__execve$sysv' 0x003b003b203b003b globl hidden -scall 'wait4$sysv' 0x000b00072007003d globl hidden -scall 'kill$sysv' 0x007a00252025003e globl hidden # kill(pid, sig, 1) b/c xnu -scall 'killpg$sysv' 0xffff0092ffffffff globl hidden +scall sys_posix_spawn 0xffffffff20f4ffff globl hidden # good luck figuring out how xnu defines this +scall __sys_execve 0x003b003b203b003b globl hidden +scall sys_wait4 0x000b00072007003d globl hidden +scall sys_kill 0x007a00252025003e globl hidden # kill(pid, sig, 1) b/c xnu +scall sys_killpg 0xffff0092ffffffff globl hidden scall clone 0xffffffffffff0038 globl scall tkill 0xffffffffffff00c8 globl scall futex 0x0053ffffffff00ca globl scall set_robust_list 0xffffffffffff0111 globl scall get_robust_list 0xffffffffffff0112 globl -scall 'uname$sysv' 0xffff00a4ffff003f globl hidden +scall sys_uname 0xffff00a4ffff003f globl hidden scall semget 0x00dd00dd20ff0040 globl # won't polyfill for windows scall semop 0x012200de21000041 globl # won't polyfill for windows scall semctl 0x012701fe20fe0042 globl # won't polyfill for windows @@ -110,42 +110,42 @@ scall msgget 0x00e100e121030044 globl # won't polyfill for windows scall msgsnd 0x00e200e221040045 globl # won't polyfill for windows scall msgrcv 0x00e300e321050046 globl # won't polyfill for windows scall msgctl 0x012901ff21020047 globl # won't polyfill for windows -scall 'fcntl$sysv' 0x005c005c205c0048 globl hidden -scall 'flock$sysv' 0x0083008320830049 globl hidden -scall 'fsync$sysv' 0x005f005f205f004a globl hidden -scall 'fdatasync$sysv' 0x005f022620bb004b globl hidden # fsync() on openbsd -scall '__truncate$sysv' 0x00c801df20c8004c globl hidden # openbsd:pad -scall '__ftruncate$sysv' 0x00c901e020c9004d globl hidden # openbsd:pad -scall 'getcwd$sysv' 0x01300146ffff004f globl hidden -scall 'chdir$sysv' 0x000c000c200c0050 globl hidden -scall 'fchdir$sysv' 0x000d000d200d0051 globl hidden -scall 'rename$sysv' 0x0080008020800052 globl hidden -scall 'mkdir$sysv' 0x0088008820880053 globl hidden -scall 'rmdir$sysv' 0x0089008920890054 globl hidden -scall 'creat$sysv' 0xffff0008ffff0055 globl hidden -scall 'link$sysv' 0x0009000920090056 globl hidden -scall 'unlink$sysv' 0x000a000a200a0057 globl hidden -scall 'symlink$sysv' 0x0039003920390058 globl hidden +scall sys_fcntl 0x005c005c205c0048 globl hidden +scall sys_flock 0x0083008320830049 globl hidden +scall sys_fsync 0x005f005f205f004a globl hidden +scall sys_fdatasync 0x005f022620bb004b globl hidden # fsync() on openbsd +scall __sys_truncate 0x00c801df20c8004c globl hidden # openbsd:pad +scall __sys_ftruncate 0x00c901e020c9004d globl hidden # openbsd:pad +scall sys_getcwd 0x01300146ffff004f globl hidden +scall sys_chdir 0x000c000c200c0050 globl hidden +scall sys_fchdir 0x000d000d200d0051 globl hidden +scall sys_rename 0x0080008020800052 globl hidden +scall sys_mkdir 0x0088008820880053 globl hidden +scall sys_rmdir 0x0089008920890054 globl hidden +scall sys_creat 0xffff0008ffff0055 globl hidden +scall sys_link 0x0009000920090056 globl hidden +scall sys_unlink 0x000a000a200a0057 globl hidden +scall sys_symlink 0x0039003920390058 globl hidden scall readlink 0x003a003a203a0059 globl # usually an anti-pattern -scall 'chmod$sysv' 0x000f000f200f005a globl hidden -scall 'fchmod$sysv' 0x007c007c207c005b globl hidden -scall 'chown$sysv' 0x001000102010005c globl hidden # impl. w/ fchownat() @asyncsignalsafe -scall 'fchown$sysv' 0x007b007b207b005d globl hidden # @asyncsignalsafe -scall 'lchown$sysv' 0x00fe00fe216c005e globl hidden # impl. w/ fchownat() +scall sys_chmod 0x000f000f200f005a globl hidden +scall sys_fchmod 0x007c007c207c005b globl hidden +scall sys_chown 0x001000102010005c globl hidden # impl. w/ fchownat() @asyncsignalsafe +scall sys_fchown 0x007b007b207b005d globl hidden # @asyncsignalsafe +scall sys_lchown 0x00fe00fe216c005e globl hidden # impl. w/ fchownat() scall umask 0x003c003c203c005f globl -scall '__gettimeofday$sysv' 0x0043007420740060 globl hidden # xnu esi/edx=0 -scall 'getrlimit$sysv' 0x00c200c220c20061 globl hidden -scall 'getrusage$sysv' 0x0013007520750062 globl hidden -scall 'sysinfo$sysv' 0xffffffffffff0063 globl hidden -scall 'times$sysv' 0xffffffffffff0064 globl hidden -scall 'ptrace$sysv' 0x001a001a201a0065 globl hidden +scall __sys_gettimeofday 0x0043007420740060 globl hidden # xnu esi/edx=0 +scall sys_getrlimit 0x00c200c220c20061 globl hidden +scall sys_getrusage 0x0013007520750062 globl hidden +scall sys_sysinfo 0xffffffffffff0063 globl hidden +scall sys_times 0xffffffffffff0064 globl hidden +scall sys_ptrace 0x001a001a201a0065 globl hidden scall syslog 0xffffffffffff0067 globl -scall 'getuid$sysv' 0x0018001820180066 globl hidden -scall 'getgid$sysv' 0x002f002f202f0068 globl hidden -scall 'getppid$sysv' 0x002700272027006e globl hidden +scall sys_getuid 0x0018001820180066 globl hidden +scall sys_getgid 0x002f002f202f0068 globl hidden +scall sys_getppid 0x002700272027006e globl hidden scall getpgrp 0x005100512051006f globl -scall 'setsid$sysv' 0x0093009320930070 globl hidden -scall 'getsid$sysv' 0x00ff01362136007c globl hidden +scall sys_setsid 0x0093009320930070 globl hidden +scall sys_getsid 0x00ff01362136007c globl hidden scall getpgid 0x00cf00cf20970079 globl scall setpgid 0x005200522052006d globl scall geteuid 0x001900192019006b globl @@ -156,28 +156,28 @@ scall setreuid 0x007e007e207e0071 globl scall setregid 0x007f007f207f0072 globl scall setuid 0x0017001720170069 globl scall setgid 0x00b500b520b5006a globl -scall 'setresuid$sysv' 0x011a0137ffff0075 globl hidden # polyfilled for xnu -scall 'setresgid$sysv' 0x011c0138ffff0077 globl hidden # polyfilled for xnu +scall sys_setresuid 0x011a0137ffff0075 globl hidden # polyfilled for xnu +scall sys_setresgid 0x011c0138ffff0077 globl hidden # polyfilled for xnu scall getresuid 0x01190168ffff0076 globl # semantics aren't well-defined scall getresgid 0x011b0169ffff0078 globl # semantics aren't well-defined scall sigpending 0x003400342034007f globl -scall 'sigsuspend$sysv' 0x006f0155206f0082 globl hidden +scall sys_sigsuspend 0x006f0155206f0082 globl hidden scall sigaltstack 0x0120003520350083 globl -scall 'mknod$sysv' 0x000e000e200e0085 globl hidden +scall sys_mknod 0x000e000e200e0085 globl hidden scall mknodat 0x0140022fffff0103 globl # FreeBSD 12+ -scall 'mkfifo$sysv' 0x008400842084ffff globl hidden +scall sys_mkfifo 0x008400842084ffff globl hidden scall mkfifoat 0x013f01f1ffffffff globl scall statfs 0x003f022b21590089 globl scall fstatfs 0x0040022c215a008a globl -scall 'getpriority$sysv' 0x006400642064008c globl hidden -scall 'setpriority$sysv' 0x006000602060008d globl hidden # modern nice() +scall sys_getpriority 0x006400642064008c globl hidden +scall sys_setpriority 0x006000602060008d globl hidden # modern nice() scall mlock 0x00cb00cb20cb0095 globl scall munlock 0x00cc00cc20cc0096 globl scall mlockall 0x010f014421440097 globl scall munlockall 0x0110014521450098 globl -scall 'setrlimit$sysv' 0x00c300c320c300a0 globl hidden +scall sys_setrlimit 0x00c300c320c300a0 globl hidden scall chroot 0x003d003d203d00a1 globl -scall 'sync$sysv' 0x00240024202400a2 globl hidden +scall sys_sync 0x00240024202400a2 globl hidden scall acct 0x00330033203300a3 globl scall settimeofday 0x0044007a207a00a4 globl scall mount 0x0015001520a700a5 globl @@ -204,7 +204,7 @@ scall modify_ldt 0xffffffffffff009a globl scall pivot_root 0xffffffffffff009b globl scall _sysctl 0xffffffffffff009c globl scall prctl 0xffffffffffff009d globl -scall 'arch_prctl$sysv' 0x00a500a5ffff009e globl hidden # sysarch() on bsd +scall sys_arch_prctl 0x00a500a5ffff009e globl hidden # sysarch() on bsd scall adjtimex 0xffffffffffff009f globl scall umount2 0xffffffffffff00a6 globl scall swapon 0xffff0055205500a7 globl @@ -215,7 +215,7 @@ scall iopl 0xffffffffffff00ac globl scall ioperm 0xffffffffffff00ad globl scall init_module 0xffffffffffff00af globl scall delete_module 0xffffffffffff00b0 globl -scall 'gettid$sysv' 0xffffffff211e00ba globl hidden +scall sys_gettid 0xffffffff211e00ba globl hidden scall readahead 0xffffffffffff00bb globl # consider fadvise() / madvise() scall setxattr 0xffffffff20ec00bc globl scall fsetxattr 0xffffffff20ed00be globl @@ -229,7 +229,7 @@ scall lsetxattr 0xffffffffffff00bd globl scall lgetxattr 0xffffffffffff00c0 globl scall llistxattr 0xffffffffffff00c3 globl scall lremovexattr 0xffffffffffff00c6 globl -scall 'sched_setaffinity$sysv' 0xffffffffffff00cb globl hidden +scall sys_sched_setaffinity 0xffffffffffff00cb globl hidden scall sched_getaffinity 0xffffffffffff00cc globl scall cpuset_getaffinity 0xffff01e7ffffffff globl scall cpuset_setaffinity 0xffff01e8ffffffff globl @@ -239,21 +239,21 @@ scall io_getevents 0xffffffffffff00d0 globl scall io_submit 0xffffffffffff00d1 globl scall io_cancel 0xffffffffffff00d2 globl scall lookup_dcookie 0xffffffffffff00d4 globl -scall 'epoll_create$sysv' 0xffffffffffff00d5 globl -scall 'epoll_wait$sysv' 0xffffffffffff00e8 globl -scall 'epoll_ctl$sysv' 0xffffffffffff00e9 globl +scall sys_epoll_create 0xffffffffffff00d5 globl +scall sys_epoll_wait 0xffffffffffff00e8 globl +scall sys_epoll_ctl 0xffffffffffff00e9 globl scall getdents 0x0063011020c400d9 globl hidden # four args b/c xnu, getdirentries on xnu, 32-bit on xnu/freebsd, getdents64 on linux, 64-bit on openbsd scall set_tid_address 0xffffffffffff00da globl scall restart_syscall 0xffffffffffff00db globl scall semtimedop 0xffffffffffff00dc globl -scall 'fadvise$sysv' 0xffff0213ffff00dd globl hidden +scall sys_fadvise 0xffff0213ffff00dd globl hidden scall timer_create 0xffffffffffff00de globl scall timer_settime 0xffffffffffff00df globl scall timer_gettime 0xffffffffffff00e0 globl scall timer_getoverrun 0xffffffffffff00e1 globl scall timer_delete 0xffffffffffff00e2 globl scall clock_settime 0x005800e9ffff00e3 globl -scall 'clock_gettime$sysv' 0x005700e8ffff00e4 globl hidden # Linux 2.6+ (c. 2003); XNU uses magic address +scall sys_clock_gettime 0x005700e8ffff00e4 globl hidden # Linux 2.6+ (c. 2003); XNU uses magic address scall clock_getres 0x005900eaffff00e5 globl scall clock_nanosleep 0xffff00f4ffff00e6 globl scall tgkill 0xffffffffffff00ea globl @@ -276,40 +276,40 @@ scall ioprio_get 0xffffffffffff00fc globl scall inotify_init 0xffffffffffff00fd globl # wicked scall inotify_add_watch 0xffffffffffff00fe globl scall inotify_rm_watch 0xffffffffffff00ff globl -scall 'openat$sysv' 0x014101f321cf0101 globl hidden # Linux 2.6.16+ (c. 2007) -scall 'mkdirat$sysv' 0x013e01f021db0102 globl hidden -scall 'fchownat$sysv' 0x013b01eb21d40104 globl hidden # @asyncsignalsafe -scall 'utime$sysv' 0xffffffffffff0084 globl hidden -scall 'utimes$sysv' 0x004c008a208a00eb globl hidden -scall 'futimesat$sysv' 0xffff01eeffff0105 globl hidden # @asyncsignalsafe -scall 'futimes$sysv' 0x004d00ce208bffff globl hidden -scall 'futimens$sysv' 0x00550222ffffffff globl hidden -scall '__fstatat$sysv' 0x002a022821d60106 globl hidden # a.k.a. newfstatat(); FreeBSD 12+; needs stat2linux() -scall 'unlinkat$sysv' 0x014501f721d80107 globl hidden -scall 'renameat$sysv' 0x014301f521d10108 globl hidden -scall 'linkat$sysv' 0x013d01ef21d70109 globl hidden -scall 'symlinkat$sysv' 0x014401f621da010a globl hidden -scall 'readlinkat$sysv' 0x014201f421d9010b globl hidden -scall 'fchmodat$sysv' 0x013a01ea21d3010c globl hidden -scall 'faccessat$sysv' 0x013901e921d2010d globl hidden +scall sys_openat 0x014101f321cf0101 globl hidden # Linux 2.6.16+ (c. 2007) +scall sys_mkdirat 0x013e01f021db0102 globl hidden +scall sys_fchownat 0x013b01eb21d40104 globl hidden # @asyncsignalsafe +scall sys_utime 0xffffffffffff0084 globl hidden +scall sys_utimes 0x004c008a208a00eb globl hidden +scall sys_futimesat 0xffff01eeffff0105 globl hidden # @asyncsignalsafe +scall sys_futimes 0x004d00ce208bffff globl hidden +scall sys_futimens 0x00550222ffffffff globl hidden +scall __sys_fstatat 0x002a022821d60106 globl hidden # a.k.a. newfstatat(); FreeBSD 12+; needs __stat2linux() +scall sys_unlinkat 0x014501f721d80107 globl hidden +scall sys_renameat 0x014301f521d10108 globl hidden +scall sys_linkat 0x013d01ef21d70109 globl hidden +scall sys_symlinkat 0x014401f621da010a globl hidden +scall sys_readlinkat 0x014201f421d9010b globl hidden +scall sys_fchmodat 0x013a01ea21d3010c globl hidden +scall sys_faccessat 0x013901e921d2010d globl hidden scall unshare 0xffffffffffff0110 globl -scall 'splice$sysv' 0xffffffffffff0113 globl hidden # Linux 2.6.17+ (c. 2007) +scall sys_splice 0xffffffffffff0113 globl hidden # Linux 2.6.17+ (c. 2007) scall tee 0xffffffffffff0114 globl # Linux 2.6.17+ -scall 'sync_file_range$sysv' 0xffffffffffff0115 globl hidden # Linux 2.6.17+ -scall 'vmsplice$sysv' 0xffffffffffff0116 globl hidden +scall sys_sync_file_range 0xffffffffffff0115 globl hidden # Linux 2.6.17+ +scall sys_vmsplice 0xffffffffffff0116 globl hidden scall migrate_pages 0xffffffffffff0100 globl # numa numa yay scall move_pages 0xffffffffffff0117 globl # NOTE: We view Red Hat versions as "epochs" for all distros. #──────────────────────RHEL 5.0 LIMIT──────────────────────── # ←┬─ last distro with gplv2 licensed compiler c. 2007 -scall '__preadv$sysv' 0x010b0121ffff0127 globl hidden # ├─ last distro with system v shell script init -scall '__pwritev$sysv' 0x010c0122ffff0128 globl hidden # ├─ rob landley unleashes busybox gpl lawsuits -scall '__utimensat$sysv' 0x00540223ffff0118 globl hidden # ├─ python modules need this due to pep513 -scall 'fallocate$sysv' 0xffffffffffff011d globl hidden # ├─ end of life 2020-11-30 (extended) -scall 'posix_fallocate$sysv' 0xffff0212ffffffff globl hidden # └─ cosmopolitan supports rhel5+ -scall '__accept4$sysv' 0x005d021dffff0120 globl hidden # Linux 2.6.28+ -scall '__dup3$sysv' 0x0066ffffffff0124 globl hidden # Linux 2.6.27+ -scall '__pipe2$sysv' 0x0065021effff0125 globl hidden # Linux 2.6.27+ +scall __sys_preadv 0x010b0121ffff0127 globl hidden # ├─ last distro with system v shell script init +scall __sys_pwritev 0x010c0122ffff0128 globl hidden # ├─ rob landley unleashes busybox gpl lawsuits +scall __sys_utimensat 0x00540223ffff0118 globl hidden # ├─ python modules need this due to pep513 +scall sys_fallocate 0xffffffffffff011d globl hidden # ├─ end of life 2020-11-30 (extended) +scall sys_posix_fallocate 0xffff0212ffffffff globl hidden # └─ cosmopolitan supports rhel5+ +scall __sys_accept4 0x005d021dffff0120 globl hidden # Linux 2.6.28+ +scall __sys_dup3 0x0066ffffffff0124 globl hidden # Linux 2.6.27+ +scall __sys_pipe2 0x0065021effff0125 globl hidden # Linux 2.6.27+ scall epoll_pwait 0xffffffffffff0119 globl -scall 'epoll_create1$sysv' 0xffffffffffff0123 globl +scall sys_epoll_create1 0xffffffffffff0123 globl scall perf_event_open 0xffffffffffff012a globl scall inotify_init1 0xffffffffffff0126 globl scall rt_tgsigqueueinfo 0xffffffffffff0129 globl @@ -341,7 +341,7 @@ scall sched_setattr 0xffffffffffff013a globl # ├─ desktop replaced with ta scall sched_getattr 0xffffffffffff013b globl # ├─ karen sandler requires systemd init and boot for tablet gui scall renameat2 0xffffffffffff013c globl # └─ debian founder ian murdock found strangled with vacuum cord scall seccomp 0xffffffffffff013d globl -scall 'getrandom$sysv' 0x0007023321f4013e globl hidden # Linux 3.17+ and getentropy() on XNU/OpenBSD +scall sys_getrandom 0x0007023321f4013e globl hidden # Linux 3.17+ and getentropy() on XNU/OpenBSD scall memfd_create 0xffffffffffff013f globl # wut scall kexec_file_load 0xffffffffffff0140 globl scall bpf 0xffffffffffff0141 globl @@ -349,7 +349,7 @@ scall execveat 0xffffffffffff0142 globl scall userfaultfd 0xffffffffffff0143 globl # Linux 4.3+ (c. 2015) scall membarrier 0xffffffffffff0144 globl # Linux 4.3+ (c. 2015) scall mlock2 0xffffffffffff0145 globl # Linux 4.5+ (c. 2016) -scall 'copy_file_range$sysv' 0xffff0239ffff0146 globl hidden # Linux 4.5+ (c. 2016), FreeBSD 13+ +scall sys_copy_file_range 0xffff0239ffff0146 globl hidden # Linux 4.5+ (c. 2016), FreeBSD 13+ scall preadv2 0xffffffffffff0147 globl scall pwritev2 0xffffffffffff0148 globl scall pkey_mprotect 0xffffffffffff0149 globl @@ -385,8 +385,8 @@ scall getfsstat 0x003e022d215bffff globl scall nfssvc 0x009b009b209bffff globl scall adjtime 0x008c008c208cffff globl scall fchflags 0x002300232023ffff globl -scall '__seteuid$bsd' 0x00b700b720b7ffff globl hidden # wrapped via setreuid() -scall '__setegid$bsd' 0x00b600b620b6ffff globl hidden # wrapped via setregid() +scall __bsd_seteuid 0x00b700b720b7ffff globl hidden # wrapped via setreuid() +scall __bsd_setegid 0x00b600b620b6ffff globl hidden # wrapped via setregid() scall fpathconf 0x00c000c020c0ffff globl scall fhopen 0x0108012a20f8ffff globl scall unmount 0x00160016209fffff globl @@ -656,7 +656,7 @@ scall gethostid 0xffff008effffffff globl #scall gethostname 0xffff0057ffffffff globl scall getkerninfo 0xffff003fffffffff globl scall getloginclass 0xffff020bffffffff globl -scall 'getpagesize$freebsd' 0xffff0040ffffffff globl hidden +scall getpagesize_freebsd 0xffff0040ffffffff globl hidden scall gssd_syscall 0xffff01f9ffffffff globl scall jail 0xffff0152ffffffff globl scall jail_attach 0xffff01b4ffffffff globl @@ -711,7 +711,7 @@ scall nstat 0xffff0116ffffffff globl scall pdfork 0xffff0206ffffffff globl scall pdgetpid 0xffff0208ffffffff globl scall pdkill 0xffff0207ffffffff globl -scall 'posix_openpt$sysv' 0xffff01f8ffffffff globl hidden +scall sys_posix_openpt 0xffff01f8ffffffff globl hidden scall procctl 0xffff0220ffffffff globl scall psynch_cvwait 0xffffffff2131ffff globl scall quota 0xffff0095ffffffff globl diff --git a/libc/testlib/showerror.c b/libc/testlib/showerror.c index 2776d4dab..06ef39c90 100644 --- a/libc/testlib/showerror.c +++ b/libc/testlib/showerror.c @@ -26,14 +26,15 @@ #include "libc/nt/runtime.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" +#include "libc/str/str.h" #include "libc/testlib/testlib.h" testonly void testlib_showerror(const char *file, int line, const char *func, const char *method, const char *symbol, const char *code, char *v1, char *v2) { /* TODO(jart): Pay off tech debt re duplication */ - getpid$sysv(); /* make strace easier to read */ - getpid$sysv(); + sys_getpid(); /* make strace easier to read */ + sys_getpid(); fprintf(stderr, "%s%s%s%s:%s:%d%s: %s() %s %s(%s)\n" "\t%s\n" diff --git a/libc/testlib/testmain.c b/libc/testlib/testmain.c index 091c44007..75b572d3e 100644 --- a/libc/testlib/testmain.c +++ b/libc/testlib/testmain.c @@ -74,7 +74,7 @@ testonly int main(int argc, char *argv[]) { GetOpts(argc, argv); showcrashreports(); g_testlib_shoulddebugbreak = IsDebuggerPresent(false); - getpid$sysv(); /* make strace easier to read */ + sys_getpid(); /* make strace easier to read */ testlib_clearxmmregisters(); testlib_runalltests(); if (!g_testlib_failed && runbenchmarks_ && weaken(testlib_runallbenchmarks)) { diff --git a/libc/testlib/testrunner.c b/libc/testlib/testrunner.c index 6a226016b..806c367d5 100644 --- a/libc/testlib/testrunner.c +++ b/libc/testlib/testrunner.c @@ -77,11 +77,11 @@ testonly void testlib_runtestcases(testfn_t *start, testfn_t *end, if (weaken(SetUp)) weaken(SetUp)(); errno = 0; SetLastError(0); - getpid$sysv(); + sys_getpid(); if (warmup) warmup(); testlib_clearxmmregisters(); (*fn)(); - getpid$sysv(); + sys_getpid(); if (weaken(TearDown)) weaken(TearDown)(); if (weaken(testlib_enable_tmp_setup_teardown)) { CHECK_NE(-1, chdir(cwd)); diff --git a/libc/time/xiso8601.c b/libc/time/xiso8601.c index 1e0d8fb40..6d6b515ed 100644 --- a/libc/time/xiso8601.c +++ b/libc/time/xiso8601.c @@ -20,6 +20,7 @@ #include "libc/calls/struct/timeval.h" #include "libc/dce.h" #include "libc/errno.h" +#include "libc/mem/fmt.h" #include "libc/mem/mem.h" #include "libc/sysv/consts/clock.h" #include "libc/time/struct/tm.h" diff --git a/libc/unicode/wcwidth.c b/libc/unicode/wcwidth.c index 3d8c9282f..fbb95490f 100644 --- a/libc/unicode/wcwidth.c +++ b/libc/unicode/wcwidth.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/likely.h" #include "libc/unicode/unicode.h" extern const uint8_t kEastAsianWidth[]; @@ -26,15 +27,18 @@ extern const uint32_t kCombiningCharsBits; /** * Returns cell width of monospace character. */ -int wcwidth(wchar_t ucs) { - if (ucs == 0) return 0; - if ((0 <= ucs && ucs < 32) || (0x7f <= ucs && ucs < 0xA0)) { - return -1; - } else if ((0 <= ucs && ucs < kCombiningCharsBits) && - !!(kCombiningChars[ucs >> 3] & (1 << (ucs & 7)))) { +int wcwidth(wchar_t c) { + if (LIKELY(32 <= c && c < 127)) { + return 1; + } else if (!c) { return 0; - } else if (0 <= ucs && ucs < kEastAsianWidthBits) { - return 1 + !!(kEastAsianWidth[ucs >> 3] & (1 << (ucs & 7))); + } else if ((0 < c && c < 32) || (0x7f <= c && c < 0xA0)) { + return -1; + } else if ((0 <= c && c < kCombiningCharsBits) && + !!(kCombiningChars[c >> 3] & (1 << (c & 7)))) { + return 0; + } else if (0 <= c && c < kEastAsianWidthBits) { + return 1 + !!(kEastAsianWidth[c >> 3] & (1 << (c & 7))); } else { return 1; } diff --git a/libc/x/xvasprintf.c b/libc/x/xvasprintf.c index 5857f44b5..ff70d2666 100644 --- a/libc/x/xvasprintf.c +++ b/libc/x/xvasprintf.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/log/log.h" +#include "libc/mem/fmt.h" #include "libc/mem/mem.h" #include "libc/x/x.h" diff --git a/libc/zipos/close.c b/libc/zipos/close.c index 6be9b02d4..4edce2397 100644 --- a/libc/zipos/close.c +++ b/libc/zipos/close.c @@ -31,7 +31,7 @@ int __zipos_close(int fd) { struct ZiposHandle *h; h = (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle; if (!IsWindows()) { - close$sysv(fd); + sys_close(fd); } else { CloseHandle(h->handle); } diff --git a/test/libc/release/test.mk b/test/libc/release/test.mk index a7850ca27..f16692933 100644 --- a/test/libc/release/test.mk +++ b/test/libc/release/test.mk @@ -67,9 +67,37 @@ o/$(MODE)/test/libc/release/smokecxx.com.dbg: \ o/$(MODE)/ape/ape.o \ o/$(MODE)/cosmopolitan.a +o/$(MODE)/test/libc/release/smokeansi.com.dbg: \ + 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=ANSI build/compile $(CC) \ + -o $@ \ + -Os \ + -ansi \ + -static \ + -no-pie \ + -fno-pie \ + -nostdlib \ + -nostdinc \ + -mno-red-zone \ + -Wl,--gc-sections \ + -Wl,-z,max-page-size=0x1000 \ + -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 \ o/$(MODE)/test/libc/release/smokecxx.com \ - o/$(MODE)/test/libc/release/smokecxx.com.runs + o/$(MODE)/test/libc/release/smokecxx.com.runs \ + o/$(MODE)/test/libc/release/smokeansi.com \ + o/$(MODE)/test/libc/release/smokeansi.com.runs diff --git a/third_party/dlmalloc/dlmalloc.c b/third_party/dlmalloc/dlmalloc.c index 4e02470dc..3fdcfba37 100644 --- a/third_party/dlmalloc/dlmalloc.c +++ b/third_party/dlmalloc/dlmalloc.c @@ -836,7 +836,7 @@ textstartup void dlmalloc_init(void) { if (g_mparams.magic == 0) { size_t magic; size_t psize = PAGESIZE; - size_t gsize = MAX(g_ntsysteminfo.dwAllocationGranularity, 64 * 1024); + size_t gsize = MAX(__nt_systeminfo.dwAllocationGranularity, 64 * 1024); /* Sanity-check configuration: size_t must be unsigned and as wide as pointer type. ints must be at least 4 bytes. diff --git a/third_party/lemon/README b/third_party/lemon/README deleted file mode 100644 index 0179f0c4f..000000000 --- a/third_party/lemon/README +++ /dev/null @@ -1,1022 +0,0 @@ - The Lemon Parser Generator - - Lemon is an LALR(1) parser generator for C. It does the same job as - "bison" and "yacc". But Lemon is not a bison or yacc clone. Lemon uses a - different grammar syntax which is designed to reduce the number of coding - errors. Lemon also uses a parsing engine that is faster than yacc and - bison and which is both reentrant and threadsafe. (Update: Since the - previous sentence was written, bison has also been updated so that it too - can generate a reentrant and threadsafe parser.) Lemon also implements - features that can be used to eliminate resource leaks, making it suitable - for use in long-running programs such as graphical user interfaces or - embedded controllers. - - This document is an introduction to the Lemon parser generator. - -1.0 Table of Contents - - * Introduction - * 1.0 Table of Contents - * 2.0 Security Notes - * 3.0 Theory of Operation - * 3.1 Command Line Options - * 3.2 The Parser Interface - * 3.2.1 Allocating The Parse Object On Stack - * 3.2.2 Interface Summary - * 3.3 Differences With YACC and BISON - * 3.4 Building The "lemon" Or "lemon.exe" Executable - * 4.0 Input File Syntax - * 4.1 Terminals and Nonterminals - * 4.2 Grammar Rules - * 4.3 Precedence Rules - * 4.4 Special Directives - * 5.0 Error Processing - * 6.0 History of Lemon - * 7.0 Copyright - -2.0 Security Note - - The language parser code created by Lemon is very robust and is - well-suited for use in internet-facing applications that need to safely - process maliciously crafted inputs. - - The "lemon.exe" command-line tool itself works great when given a valid - input grammar file and almost always gives helpful error messages for - malformed inputs. However, it is possible for a malicious user to craft a - grammar file that will cause lemon.exe to crash. We do not see this as a - problem, as lemon.exe is not intended to be used with hostile inputs. To - summarize: - - * Parser code generated by lemon → Robust and secure - * The "lemon.exe" command line tool itself → Not so much - -3.0 Theory of Operation - - Lemon is computer program that translates a context free grammar (CFG) for - a particular language into C code that implements a parser for that - language. The Lemon program has two inputs: - - * The grammar specification. - * A parser template file. - - Typically, only the grammar specification is supplied by the programmer. - Lemon comes with a default parser template ("lempar.c") that works fine - for most applications. But the user is free to substitute a different - parser template if desired. - - Depending on command-line options, Lemon will generate up to three output - files. - - * C code to implement a parser for the input grammar. - * A header file defining an integer ID for each terminal symbol (or - "token"). - * An information file that describes the states of the generated parser - automaton. - - By default, all three of these output files are generated. The header file - is suppressed if the "-m" command-line option is used and the report file - is omitted when "-q" is selected. - - The grammar specification file uses a ".y" suffix, by convention. In the - examples used in this document, we'll assume the name of the grammar file - is "gram.y". A typical use of Lemon would be the following command: - - lemon gram.y - - This command will generate three output files named "gram.c", "gram.h" and - "gram.out". The first is C code to implement the parser. The second is the - header file that defines numerical values for all terminal symbols, and - the last is the report that explains the states used by the parser - automaton. - - 3.1 Command Line Options - - The behavior of Lemon can be modified using command-line options. You can - obtain a list of the available command-line options together with a brief - explanation of what each does by typing - - lemon "-?" - - As of this writing, the following command-line options are supported: - - * -b Show only the basis for each parser state in the report file. - * -c Do not compress the generated action tables. The parser will be a - little larger and slower, but it will detect syntax errors sooner. - * -ddirectory Write all output files into directory. Normally, output - files are written into the directory that contains the input grammar - file. - * -Dname Define C preprocessor macro name. This macro is usable by - "%ifdef", "%ifndef", and "%if lines in the grammar file. - * -E Run the "%if" preprocessor step only and print the revised grammar - file. - * -g Do not generate a parser. Instead write the input grammar to - standard output with all comments, actions, and other extraneous text - removed. - * -l Omit "#line" directives in the generated parser C code. - * -m Cause the output C source code to be compatible with the - "makeheaders" program. - * -p Display all conflicts that are resolved by precedence rules. - * -q Suppress generation of the report file. - * -r Do not sort or renumber the parser states as part of optimization. - * -s Show parser statistics before exiting. - * -Tfile Use file as the template for the generated C-code parser - implementation. - * -x Print the Lemon version number. - - 3.2 The Parser Interface - - Lemon doesn't generate a complete, working program. It only generates a - few subroutines that implement a parser. This section describes the - interface to those subroutines. It is up to the programmer to call these - subroutines in an appropriate way in order to produce a complete system. - - Before a program begins using a Lemon-generated parser, the program must - first create the parser. A new parser is created as follows: - - void *pParser = ParseAlloc( malloc ); - - The ParseAlloc() routine allocates and initializes a new parser and - returns a pointer to it. The actual data structure used to represent a - parser is opaque — its internal structure is not visible or usable by the - calling routine. For this reason, the ParseAlloc() routine returns a - pointer to void rather than a pointer to some particular structure. The - sole argument to the ParseAlloc() routine is a pointer to the subroutine - used to allocate memory. Typically this means malloc(). - - After a program is finished using a parser, it can reclaim all memory - allocated by that parser by calling - - ParseFree(pParser, free); - - The first argument is the same pointer returned by ParseAlloc(). The - second argument is a pointer to the function used to release bulk memory - back to the system. - - After a parser has been allocated using ParseAlloc(), the programmer must - supply the parser with a sequence of tokens (terminal symbols) to be - parsed. This is accomplished by calling the following function once for - each token: - - Parse(pParser, hTokenID, sTokenData, pArg); - - The first argument to the Parse() routine is the pointer returned by - ParseAlloc(). The second argument is a small positive integer that tells - the parser the type of the next token in the data stream. There is one - token type for each terminal symbol in the grammar. The gram.h file - generated by Lemon contains #define statements that map symbolic terminal - symbol names into appropriate integer values. A value of 0 for the second - argument is a special flag to the parser to indicate that the end of input - has been reached. The third argument is the value of the given token. By - default, the type of the third argument is "void*", but the grammar will - usually redefine this type to be some kind of structure. Typically the - second argument will be a broad category of tokens such as "identifier" or - "number" and the third argument will be the name of the identifier or the - value of the number. - - The Parse() function may have either three or four arguments, depending on - the grammar. If the grammar specification file requests it (via the - %extra_argument directive), the Parse() function will have a fourth - parameter that can be of any type chosen by the programmer. The parser - doesn't do anything with this argument except to pass it through to action - routines. This is a convenient mechanism for passing state information - down to the action routines without having to use global variables. - - A typical use of a Lemon parser might look something like the following: - - 1 ParseTree *ParseFile(const char *zFilename){ - 2 Tokenizer *pTokenizer; - 3 void *pParser; - 4 Token sToken; - 5 int hTokenId; - 6 ParserState sState; - 7 - 8 pTokenizer = TokenizerCreate(zFilename); - 9 pParser = ParseAlloc( malloc ); - 10 InitParserState(&sState); - 11 while( GetNextToken(pTokenizer, &hTokenId, &sToken) ){ - 12 Parse(pParser, hTokenId, sToken, &sState); - 13 } - 14 Parse(pParser, 0, sToken, &sState); - 15 ParseFree(pParser, free ); - 16 TokenizerFree(pTokenizer); - 17 return sState.treeRoot; - 18 } - - This example shows a user-written routine that parses a file of text and - returns a pointer to the parse tree. (All error-handling code is omitted - from this example to keep it simple.) We assume the existence of some kind - of tokenizer which is created using TokenizerCreate() on line 8 and - deleted by TokenizerFree() on line 16. The GetNextToken() function on line - 11 retrieves the next token from the input file and puts its type in the - integer variable hTokenId. The sToken variable is assumed to be some kind - of structure that contains details about each token, such as its complete - text, what line it occurs on, etc. - - This example also assumes the existence of a structure of type ParserState - that holds state information about a particular parse. An instance of such - a structure is created on line 6 and initialized on line 10. A pointer to - this structure is passed into the Parse() routine as the optional 4th - argument. The action routine specified by the grammar for the parser can - use the ParserState structure to hold whatever information is useful and - appropriate. In the example, we note that the treeRoot field of the - ParserState structure is left pointing to the root of the parse tree. - - The core of this example as it relates to Lemon is as follows: - - ParseFile(){ - pParser = ParseAlloc( malloc ); - while( GetNextToken(pTokenizer,&hTokenId, &sToken) ){ - Parse(pParser, hTokenId, sToken); - } - Parse(pParser, 0, sToken); - ParseFree(pParser, free ); - } - - Basically, what a program has to do to use a Lemon-generated parser is - first create the parser, then send it lots of tokens obtained by - tokenizing an input source. When the end of input is reached, the Parse() - routine should be called one last time with a token type of 0. This step - is necessary to inform the parser that the end of input has been reached. - Finally, we reclaim memory used by the parser by calling ParseFree(). - - There is one other interface routine that should be mentioned before we - move on. The ParseTrace() function can be used to generate debugging - output from the parser. A prototype for this routine is as follows: - - ParseTrace(FILE *stream, char *zPrefix); - - After this routine is called, a short (one-line) message is written to the - designated output stream every time the parser changes states or calls an - action routine. Each such message is prefaced using the text given by - zPrefix. This debugging output can be turned off by calling ParseTrace() - again with a first argument of NULL (0). - - 3.2.1 Allocating The Parse Object On Stack - - If all calls to the Parse() interface are made from within %code - directives, then the parse object can be allocated from the stack rather - than from the heap. These are the steps: - * Declare a local variable of type "yyParser" - * Initialize the variable using ParseInit() - * Pass a pointer to the variable in calls ot Parse() - * Deallocate substructure in the parse variable using ParseFinalize(). - - The following code illustrates how this is done: - - ParseFile(){ - yyParser x; - ParseInit( &x ); - while( GetNextToken(pTokenizer,&hTokenId, &sToken) ){ - Parse(&x, hTokenId, sToken); - } - Parse(&x, 0, sToken); - ParseFinalize( &x ); - } - - 3.2.2 Interface Summary - - Here is a quick overview of the C-language interface to a Lemon-generated - parser: - - void *ParseAlloc( (void*(*malloc)(size_t) ); - void ParseFree(void *pParser, (void(*free)(void*) ); - void Parse(void *pParser, int tokenCode, ParseTOKENTYPE token, ...); - void ParseTrace(FILE *stream, char *zPrefix); - - Notes: - - * Use the %name directive to change the "Parse" prefix names of the - procedures in the interface. - * Use the %token_type directive to define the "ParseTOKENTYPE" type. - * Use the %extra_argument directive to specify the type and name of the - 4th parameter to the Parse() function. - - 3.3 Differences With YACC and BISON - - Programmers who have previously used the yacc or bison parser generator - will notice several important differences between yacc and/or bison and - Lemon. - - * In yacc and bison, the parser calls the tokenizer. In Lemon, the - tokenizer calls the parser. - * Lemon uses no global variables. Yacc and bison use global variables to - pass information between the tokenizer and parser. - * Lemon allows multiple parsers to be running simultaneously. Yacc and - bison do not. - - These differences may cause some initial confusion for programmers with - prior yacc and bison experience. But after years of experience using - Lemon, I firmly believe that the Lemon way of doing things is better. - - Updated as of 2016-02-16: The text above was written in the 1990s. We are - told that Bison has lately been enhanced to support the - tokenizer-calls-parser paradigm used by Lemon, eliminating the need for - global variables. - - 3.4 Building The "lemon" or "lemon.exe" Executable - - The "lemon" or "lemon.exe" program is built from a single file of C-code - named "lemon.c". The Lemon source code is generic C89 code that uses no - unusual or non-standard libraries. Any reasonable C compiler should - suffice to compile the lemon program. A command-line like the following - will usually work: - - cc -o lemon lemon.c - - On Windows machines with Visual C++ installed, bring up a "VS20NN x64 - Native Tools Command Prompt" window and enter: - - cl lemon.c - - Compiling Lemon really is that simple. Additional compiler options such as - "-O2" or "-g" or "-Wall" can be added if desired, but they are not - necessary. - -4.0 Input File Syntax - - The main purpose of the grammar specification file for Lemon is to define - the grammar for the parser. But the input file also specifies additional - information Lemon requires to do its job. Most of the work in using Lemon - is in writing an appropriate grammar file. - - The grammar file for Lemon is, for the most part, a free format. It does - not have sections or divisions like yacc or bison. Any declaration can - occur at any point in the file. Lemon ignores whitespace (except where it - is needed to separate tokens), and it honors the same commenting - conventions as C and C++. - - 4.1 Terminals and Nonterminals - - A terminal symbol (token) is any string of alphanumeric and/or underscore - characters that begins with an uppercase letter. A terminal can contain - lowercase letters after the first character, but the usual convention is - to make terminals all uppercase. A nonterminal, on the other hand, is any - string of alphanumeric and underscore characters than begins with a - lowercase letter. Again, the usual convention is to make nonterminals use - all lowercase letters. - - In Lemon, terminal and nonterminal symbols do not need to be declared or - identified in a separate section of the grammar file. Lemon is able to - generate a list of all terminals and nonterminals by examining the grammar - rules, and it can always distinguish a terminal from a nonterminal by - checking the case of the first character of the name. - - Yacc and bison allow terminal symbols to have either alphanumeric names or - to be individual characters included in single quotes, like this: ')' or - '$'. Lemon does not allow this alternative form for terminal symbols. With - Lemon, all symbols, terminals and nonterminals, must have alphanumeric - names. - - 4.2 Grammar Rules - - The main component of a Lemon grammar file is a sequence of grammar rules. - Each grammar rule consists of a nonterminal symbol followed by the special - symbol "::=" and then a list of terminals and/or nonterminals. The rule is - terminated by a period. The list of terminals and nonterminals on the - right-hand side of the rule can be empty. Rules can occur in any order, - except that the left-hand side of the first rule is assumed to be the - start symbol for the grammar (unless specified otherwise using the - %start_symbol directive described below.) A typical sequence of grammar - rules might look something like this: - - expr ::= expr PLUS expr. - expr ::= expr TIMES expr. - expr ::= LPAREN expr RPAREN. - expr ::= VALUE. - - There is one non-terminal in this example, "expr", and five terminal - symbols or tokens: "PLUS", "TIMES", "LPAREN", "RPAREN" and "VALUE". - - Like yacc and bison, Lemon allows the grammar to specify a block of C code - that will be executed whenever a grammar rule is reduced by the parser. In - Lemon, this action is specified by putting the C code (contained within - curly braces {...}) immediately after the period that closes the rule. For - example: - - expr ::= expr PLUS expr. { printf("Doing an addition...\n"); } - - In order to be useful, grammar actions must normally be linked to their - associated grammar rules. In yacc and bison, this is accomplished by - embedding a "$$" in the action to stand for the value of the left-hand - side of the rule and symbols "$1", "$2", and so forth to stand for the - value of the terminal or nonterminal at position 1, 2 and so forth on the - right-hand side of the rule. This idea is very powerful, but it is also - very error-prone. The single most common source of errors in a yacc or - bison grammar is to miscount the number of symbols on the right-hand side - of a grammar rule and say "$7" when you really mean "$8". - - Lemon avoids the need to count grammar symbols by assigning symbolic names - to each symbol in a grammar rule and then using those symbolic names in - the action. In yacc or bison, one would write this: - - expr -> expr PLUS expr { $$ = $1 + $3; }; - - But in Lemon, the same rule becomes the following: - - expr(A) ::= expr(B) PLUS expr(C). { A = B+C; } - - In the Lemon rule, any symbol in parentheses after a grammar rule symbol - becomes a place holder for that symbol in the grammar rule. This place - holder can then be used in the associated C action to stand for the value - of that symbol. - - The Lemon notation for linking a grammar rule with its reduce action is - superior to yacc/bison on several counts. First, as mentioned above, the - Lemon method avoids the need to count grammar symbols. Secondly, if a - terminal or nonterminal in a Lemon grammar rule includes a linking symbol - in parentheses but that linking symbol is not actually used in the reduce - action, then an error message is generated. For example, the rule - - expr(A) ::= expr(B) PLUS expr(C). { A = B; } - - will generate an error because the linking symbol "C" is used in the - grammar rule but not in the reduce action. - - The Lemon notation for linking grammar rules to reduce actions also - facilitates the use of destructors for reclaiming memory allocated by the - values of terminals and nonterminals on the right-hand side of a rule. - - 4.3 Precedence Rules - - Lemon resolves parsing ambiguities in exactly the same way as yacc and - bison. A shift-reduce conflict is resolved in favor of the shift, and a - reduce-reduce conflict is resolved by reducing whichever rule comes first - in the grammar file. - - Just like in yacc and bison, Lemon allows a measure of control over the - resolution of parsing conflicts using precedence rules. A precedence value - can be assigned to any terminal symbol using the %left, %right or - %nonassoc directives. Terminal symbols mentioned in earlier directives - have a lower precedence than terminal symbols mentioned in later - directives. For example: - - %left AND. - %left OR. - %nonassoc EQ NE GT GE LT LE. - %left PLUS MINUS. - %left TIMES DIVIDE MOD. - %right EXP NOT. - - In the preceding sequence of directives, the AND operator is defined to - have the lowest precedence. The OR operator is one precedence level - higher. And so forth. Hence, the grammar would attempt to group the - ambiguous expression - - a AND b OR c - - like this - - a AND (b OR c). - - The associativity (left, right or nonassoc) is used to determine the - grouping when the precedence is the same. AND is left-associative in our - example, so - - a AND b AND c - - is parsed like this - - (a AND b) AND c. - - The EXP operator is right-associative, though, so - - a EXP b EXP c - - is parsed like this - - a EXP (b EXP c). - - The nonassoc precedence is used for non-associative operators. So - - a EQ b EQ c - - is an error. - - The precedence of non-terminals is transferred to rules as follows: The - precedence of a grammar rule is equal to the precedence of the left-most - terminal symbol in the rule for which a precedence is defined. This is - normally what you want, but in those cases where you want the precedence - of a grammar rule to be something different, you can specify an - alternative precedence symbol by putting the symbol in square braces after - the period at the end of the rule and before any C-code. For example: - - expr = MINUS expr. [NOT] - - This rule has a precedence equal to that of the NOT symbol, not the MINUS - symbol as would have been the case by default. - - With the knowledge of how precedence is assigned to terminal symbols and - individual grammar rules, we can now explain precisely how parsing - conflicts are resolved in Lemon. Shift-reduce conflicts are resolved as - follows: - - * If either the token to be shifted or the rule to be reduced lacks - precedence information, then resolve in favor of the shift, but report - a parsing conflict. - * If the precedence of the token to be shifted is greater than the - precedence of the rule to reduce, then resolve in favor of the shift. - No parsing conflict is reported. - * If the precedence of the token to be shifted is less than the - precedence of the rule to reduce, then resolve in favor of the reduce - action. No parsing conflict is reported. - * If the precedences are the same and the shift token is - right-associative, then resolve in favor of the shift. No parsing - conflict is reported. - * If the precedences are the same and the shift token is - left-associative, then resolve in favor of the reduce. No parsing - conflict is reported. - * Otherwise, resolve the conflict by doing the shift, and report a - parsing conflict. - - Reduce-reduce conflicts are resolved this way: - - * If either reduce rule lacks precedence information, then resolve in - favor of the rule that appears first in the grammar, and report a - parsing conflict. - * If both rules have precedence and the precedence is different, then - resolve the dispute in favor of the rule with the highest precedence, - and do not report a conflict. - * Otherwise, resolve the conflict by reducing by the rule that appears - first in the grammar, and report a parsing conflict. - - 4.4 Special Directives - - The input grammar to Lemon consists of grammar rules and special - directives. We've described all the grammar rules, so now we'll talk about - the special directives. - - Directives in Lemon can occur in any order. You can put them before the - grammar rules, or after the grammar rules, or in the midst of the grammar - rules. It doesn't matter. The relative order of directives used to assign - precedence to terminals is important, but other than that, the order of - directives in Lemon is arbitrary. - - Lemon supports the following special directives: - - * %code - * %default_destructor - * %default_type - * %destructor - * %else - * %endif - * %extra_argument - * %fallback - * %if - * %ifdef - * %ifndef - * %include - * %left - * %name - * %nonassoc - * %parse_accept - * %parse_failure - * %right - * %stack_overflow - * %stack_size - * %start_symbol - * %syntax_error - * %token_class - * %token_destructor - * %token_prefix - * %token_type - * %type - * %wildcard - - Each of these directives will be described separately in the following - sections: - - 4.4.1 The %code directive - - The %code directive is used to specify additional C code that is added to - the end of the main output file. This is similar to the %include directive - except that %include is inserted at the beginning of the main output file. - - %code is typically used to include some action routines or perhaps a - tokenizer or even the "main()" function as part of the output file. - - There can be multiple %code directives. The arguments of all %code - directives are concatenated. - - 4.4.2 The %default_destructor directive - - The %default_destructor directive specifies a destructor to use for - non-terminals that do not have their own destructor specified by a - separate %destructor directive. See the documentation on the %destructor - directive below for additional information. - - In some grammars, many different non-terminal symbols have the same data - type and hence the same destructor. This directive is a convenient way to - specify the same destructor for all those non-terminals using a single - statement. - - 4.4.3 The %default_type directive - - The %default_type directive specifies the data type of non-terminal - symbols that do not have their own data type defined using a separate - %type directive. - - 4.4.4 The %destructor directive - - The %destructor directive is used to specify a destructor for a - non-terminal symbol. (See also the %token_destructor directive which is - used to specify a destructor for terminal symbols.) - - A non-terminal's destructor is called to dispose of the non-terminal's - value whenever the non-terminal is popped from the stack. This includes - all of the following circumstances: - - * When a rule reduces and the value of a non-terminal on the right-hand - side is not linked to C code. - * When the stack is popped during error processing. - * When the ParseFree() function runs. - - The destructor can do whatever it wants with the value of the - non-terminal, but its design is to deallocate memory or other resources - held by that non-terminal. - - Consider an example: - - %type nt {void*} - %destructor nt { free($$); } - nt(A) ::= ID NUM. { A = malloc( 100 ); } - - This example is a bit contrived, but it serves to illustrate how - destructors work. The example shows a non-terminal named "nt" that holds - values of type "void*". When the rule for an "nt" reduces, it sets the - value of the non-terminal to space obtained from malloc(). Later, when the - nt non-terminal is popped from the stack, the destructor will fire and - call free() on this malloced space, thus avoiding a memory leak. (Note - that the symbol "$$" in the destructor code is replaced by the value of - the non-terminal.) - - It is important to note that the value of a non-terminal is passed to the - destructor whenever the non-terminal is removed from the stack, unless the - non-terminal is used in a C-code action. If the non-terminal is used by - C-code, then it is assumed that the C-code will take care of destroying - it. More commonly, the value is used to build some larger structure, and - we don't want to destroy it, which is why the destructor is not called in - this circumstance. - - Destructors help avoid memory leaks by automatically freeing allocated - objects when they go out of scope. To do the same using yacc or bison is - much more difficult. - - 4.4.5 The %extra_argument directive - - The %extra_argument directive instructs Lemon to add a 4th parameter to - the parameter list of the Parse() function it generates. Lemon doesn't do - anything itself with this extra argument, but it does make the argument - available to C-code action routines, destructors, and so forth. For - example, if the grammar file contains: - - %extra_argument { MyStruct *pAbc } - - Then the Parse() function generated will have an 4th parameter of type - "MyStruct*" and all action routines will have access to a variable named - "pAbc" that is the value of the 4th parameter in the most recent call to - Parse(). - - The %extra_context directive works the same except that it is passed in on - the ParseAlloc() or ParseInit() routines instead of on Parse(). - - 4.4.6 The %extra_context directive - - The %extra_context directive instructs Lemon to add a 2nd parameter to the - parameter list of the ParseAlloc() and ParseInit() functions. Lemon - doesn't do anything itself with these extra argument, but it does store - the value make it available to C-code action routines, destructors, and so - forth. For example, if the grammar file contains: - - %extra_context { MyStruct *pAbc } - - Then the ParseAlloc() and ParseInit() functions will have an 2nd parameter - of type "MyStruct*" and all action routines will have access to a variable - named "pAbc" that is the value of that 2nd parameter. - - The %extra_argument directive works the same except that it is passed in - on the Parse() routine instead of on ParseAlloc()/ParseInit(). - - 4.4.7 The %fallback directive - - The %fallback directive specifies an alternative meaning for one or more - tokens. The alternative meaning is tried if the original token would have - generated a syntax error. - - The %fallback directive was added to support robust parsing of SQL syntax - in SQLite. The SQL language contains a large assortment of keywords, each - of which appears as a different token to the language parser. SQL contains - so many keywords that it can be difficult for programmers to keep up with - them all. Programmers will, therefore, sometimes mistakenly use an obscure - language keyword for an identifier. The %fallback directive provides a - mechanism to tell the parser: "If you are unable to parse this keyword, - try treating it as an identifier instead." - - The syntax of %fallback is as follows: - - %fallback ID TOKEN... . - - In words, the %fallback directive is followed by a list of token names - terminated by a period. The first token name is the fallback token — the - token to which all the other tokens fall back to. The second and - subsequent arguments are tokens which fall back to the token identified by - the first argument. - - 4.4.8 The %if directive and its friends - - The %if, %ifdef, %ifndef, %else, and %endif directives are similar to #if, - #ifdef, #ifndef, #else, and #endif in the C-preprocessor, just not as - general. Each of these directives must begin at the left margin. No - whitespace is allowed between the "%" and the directive name. - - Grammar text in between "%ifdef MACRO" and the next nested "%endif" is - ignored unless the "-DMACRO" command-line option is used. Grammar text - betwen "%ifndef MACRO" and the next nested "%endif" is included except - when the "-DMACRO" command-line option is used. - - The text in between "%if CONDITIONAL" and its corresponding %endif is - included only if CONDITIONAL is true. The CONDITION is one or more macro - names, optionally connected using the "||" and "&&" binary operators, the - "!" unary operator, and grouped using balanced parentheses. Each term is - true if the corresponding macro exists, and false if it does not exist. - - An optional "%else" directive can occur anywhere in between a %ifdef, - %ifndef, or %if directive and its corresponding %endif. - - Note that the argument to %ifdef and %ifndef is intended to be a single - preprocessor symbol name, not a general expression. Use the "%if" - directive for general expressions. - - 4.4.9 The %include directive - - The %include directive specifies C code that is included at the top of the - generated parser. You can include any text you want — the Lemon parser - generator copies it blindly. If you have multiple %include directives in - your grammar file, their values are concatenated so that all %include code - ultimately appears near the top of the generated parser, in the same order - as it appeared in the grammar. - - The %include directive is very handy for getting some extra #include - preprocessor statements at the beginning of the generated parser. For - example: - - %include {#include } - - This might be needed, for example, if some of the C actions in the grammar - call functions that are prototyped in unistd.h. - - Use the %code directive to add code to the end of the generated parser. - - 4.4.10 The %left directive - - The %left directive is used (along with the %right and %nonassoc - directives) to declare precedences of terminal symbols. Every terminal - symbol whose name appears after a %left directive but before the next - period (".") is given the same left-associative precedence value. - Subsequent %left directives have higher precedence. For example: - - %left AND. - %left OR. - %nonassoc EQ NE GT GE LT LE. - %left PLUS MINUS. - %left TIMES DIVIDE MOD. - %right EXP NOT. - - Note the period that terminates each %left, %right or %nonassoc directive. - - LALR(1) grammars can get into a situation where they require a large - amount of stack space if you make heavy use or right-associative - operators. For this reason, it is recommended that you use %left rather - than %right whenever possible. - - 4.4.11 The %name directive - - By default, the functions generated by Lemon all begin with the - five-character string "Parse". You can change this string to something - different using the %name directive. For instance: - - %name Abcde - - Putting this directive in the grammar file will cause Lemon to generate - functions named - - * AbcdeAlloc(), - * AbcdeFree(), - * AbcdeTrace(), and - * Abcde(). - The %name directive allows you to generate two or more different parsers - and link them all into the same executable. - - 4.4.12 The %nonassoc directive - - This directive is used to assign non-associative precedence to one or more - terminal symbols. See the section on precedence rules or on the %left - directive for additional information. - - 4.4.13 The %parse_accept directive - - The %parse_accept directive specifies a block of C code that is executed - whenever the parser accepts its input string. To "accept" an input string - means that the parser was able to process all tokens without error. - - For example: - - %parse_accept { - printf("parsing complete!\n"); - } - - 4.4.14 The %parse_failure directive - - The %parse_failure directive specifies a block of C code that is executed - whenever the parser fails complete. This code is not executed until the - parser has tried and failed to resolve an input error using is usual error - recovery strategy. The routine is only invoked when parsing is unable to - continue. - - %parse_failure { - fprintf(stderr,"Giving up. Parser is hopelessly lost...\n"); - } - - 4.4.15 The %right directive - - This directive is used to assign right-associative precedence to one or - more terminal symbols. See the section on precedence rules or on the %left - directive for additional information. - - 4.4.16 The %stack_overflow directive - - The %stack_overflow directive specifies a block of C code that is executed - if the parser's internal stack ever overflows. Typically this just prints - an error message. After a stack overflow, the parser will be unable to - continue and must be reset. - - %stack_overflow { - fprintf(stderr,"Giving up. Parser stack overflow\n"); - } - - You can help prevent parser stack overflows by avoiding the use of right - recursion and right-precedence operators in your grammar. Use left - recursion and and left-precedence operators instead to encourage rules to - reduce sooner and keep the stack size down. For example, do rules like - this: - - list ::= list element. // left-recursion. Good! - list ::= . - - Not like this: - - list ::= element list. // right-recursion. Bad! - list ::= . - - 4.4.17 The %stack_size directive - - If stack overflow is a problem and you can't resolve the trouble by using - left-recursion, then you might want to increase the size of the parser's - stack using this directive. Put an positive integer after the %stack_size - directive and Lemon will generate a parse with a stack of the requested - size. The default value is 100. - - %stack_size 2000 - - 4.4.18 The %start_symbol directive - - By default, the start symbol for the grammar that Lemon generates is the - first non-terminal that appears in the grammar file. But you can choose a - different start symbol using the %start_symbol directive. - - %start_symbol prog - - 4.4.19 The %syntax_error directive - - See Error Processing. - - 4.4.20 The %token_class directive - - Undocumented. Appears to be related to the MULTITERMINAL concept. - Implementation. - - 4.4.21 The %token_destructor directive - - The %destructor directive assigns a destructor to a non-terminal symbol. - (See the description of the %destructor directive above.) The - %token_destructor directive does the same thing for all terminal symbols. - - Unlike non-terminal symbols, which may each have a different data type for - their values, terminals all use the same data type (defined by the - %token_type directive) and so they use a common destructor. Other than - that, the token destructor works just like the non-terminal destructors. - - 4.4.22 The %token_prefix directive - - Lemon generates #defines that assign small integer constants to each - terminal symbol in the grammar. If desired, Lemon will add a prefix - specified by this directive to each of the #defines it generates. - - So if the default output of Lemon looked like this: - - #define AND 1 - #define MINUS 2 - #define OR 3 - #define PLUS 4 - - You can insert a statement into the grammar like this: - - %token_prefix TOKEN_ - - to cause Lemon to produce these symbols instead: - - #define TOKEN_AND 1 - #define TOKEN_MINUS 2 - #define TOKEN_OR 3 - #define TOKEN_PLUS 4 - - 4.4.23 The %token_type and %type directives - - These directives are used to specify the data types for values on the - parser's stack associated with terminal and non-terminal symbols. The - values of all terminal symbols must be of the same type. This turns out to - be the same data type as the 3rd parameter to the Parse() function - generated by Lemon. Typically, you will make the value of a terminal - symbol be a pointer to some kind of token structure. Like this: - - %token_type {Token*} - - If the data type of terminals is not specified, the default value is - "void*". - - Non-terminal symbols can each have their own data types. Typically the - data type of a non-terminal is a pointer to the root of a parse tree - structure that contains all information about that non-terminal. For - example: - - %type expr {Expr*} - - Each entry on the parser's stack is actually a union containing instances - of all data types for every non-terminal and terminal symbol. Lemon will - automatically use the correct element of this union depending on what the - corresponding non-terminal or terminal symbol is. But the grammar designer - should keep in mind that the size of the union will be the size of its - largest element. So if you have a single non-terminal whose data type - requires 1K of storage, then your 100 entry parser stack will require 100K - of heap space. If you are willing and able to pay that price, fine. You - just need to know. - - 4.4.24 The %wildcard directive - - The %wildcard directive is followed by a single token name and a period. - This directive specifies that the identified token should match any input - token. - - When the generated parser has the choice of matching an input against the - wildcard token and some other token, the other token is always used. The - wildcard token is only matched if there are no alternatives. - -5.0 Error Processing - - After extensive experimentation over several years, it has been discovered - that the error recovery strategy used by yacc is about as good as it gets. - And so that is what Lemon uses. - - When a Lemon-generated parser encounters a syntax error, it first invokes - the code specified by the %syntax_error directive, if any. It then enters - its error recovery strategy. The error recovery strategy is to begin - popping the parsers stack until it enters a state where it is permitted to - shift a special non-terminal symbol named "error". It then shifts this - non-terminal and continues parsing. The %syntax_error routine will not be - called again until at least three new tokens have been successfully - shifted. - - If the parser pops its stack until the stack is empty, and it still is - unable to shift the error symbol, then the %parse_failure routine is - invoked and the parser resets itself to its start state, ready to begin - parsing a new file. This is what will happen at the very first syntax - error, of course, if there are no instances of the "error" non-terminal in - your grammar. - -6.0 History of Lemon - - Lemon was originally written by Richard Hipp sometime in the late 1980s on - a Sun4 Workstation using K&R C. There was a companion LL(1) parser - generator program named "Lime", the source code to which as been lost. - - The lemon.c source file was originally many separate files that were - compiled together to generate the "lemon" executable. Sometime in the - 1990s, the individual source code files were combined together into the - current single large "lemon.c" source file. You can still see traces of - original filenames in the code. - - Since 2001, Lemon has been part of the SQLite project and the source code - to Lemon has been managed as a part of the SQLite source tree in the - following files: - - * tool/lemon.c - * tool/lempar.c - * doc/lemon.html - -7.0 Copyright - - All of the source code to Lemon, including the template parser file - "lempar.c" and this documentation file ("lemon.html") are in the public - domain. You can use the code for any purpose and without attribution. - - The code comes with no warranty. If it breaks, you get to keep both - pieces. diff --git a/third_party/lemon/lemon.c b/third_party/lemon/lemon.c deleted file mode 100644 index 61a0e9b30..000000000 --- a/third_party/lemon/lemon.c +++ /dev/null @@ -1,5968 +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/alg/alg.h" -#include "libc/assert.h" -#include "libc/calls/calls.h" -#include "libc/fmt/conv.h" -#include "libc/fmt/fmt.h" -#include "libc/mem/mem.h" -#include "libc/runtime/gc.h" -#include "libc/runtime/runtime.h" -#include "libc/stdio/stdio.h" -#include "libc/str/str.h" -#include "libc/x/x.h" -#include "third_party/gdtoa/gdtoa.h" - -/* -** This file contains all sources (including headers) to the LEMON -** LALR(1) parser generator. The sources have been combined into a -** single file to make it easy to include LEMON in the source tree -** and Makefile of another program. -** -** The author of this program disclaims copyright. -*/ - -#define ISSPACE(X) isspace((unsigned char)(X)) -#define ISDIGIT(X) isdigit((unsigned char)(X)) -#define ISALNUM(X) isalnum((unsigned char)(X)) -#define ISALPHA(X) isalpha((unsigned char)(X)) -#define ISUPPER(X) isupper((unsigned char)(X)) -#define ISLOWER(X) islower((unsigned char)(X)) - -#define PRIVATE static -/* #define PRIVATE */ - -#ifdef TEST -#define MAXRHS 5 /* Set low to exercise exception code */ -#else -#define MAXRHS 1000 -#endif - -extern void memory_error(); -static int showPrecedenceConflict = 0; -static char *msort(char *, char **, int (*)(const char *, const char *)); - -/* -** Compilers are getting increasingly pedantic about type conversions -** as C evolves ever closer to Ada.... To work around the latest problems -** we have to define the following variant of strlen(). -*/ -#define lemonStrlen(X) ((int)strlen(X)) - -/* -** Compilers are starting to complain about the use of sprintf() and strcpy(), -** saying they are unsafe. So we define our own versions of those routines too. -** -** There are three routines here: lemon_sprintf(), lemon_vsprintf(), and -** lemon_addtext(). The first two are replacements for sprintf() and vsprintf(). -** The third is a helper routine for vsnprintf() that adds texts to the end of a -** buffer, making sure the buffer is always zero-terminated. -** -** The string formatter is a minimal subset of stdlib sprintf() supporting only -** a few simply conversions: -** -** %d -** %s -** %.*s -** -*/ -static void lemon_addtext( - char *zBuf, /* The buffer to which text is added */ - int *pnUsed, /* Slots of the buffer used so far */ - const char *zIn, /* Text to add */ - int nIn, /* Bytes of text to add. -1 to use strlen() */ - int iWidth /* Field width. Negative to left justify */ -) { - if (nIn < 0) - for (nIn = 0; zIn[nIn]; nIn++) { - } - while (iWidth > nIn) { - zBuf[(*pnUsed)++] = ' '; - iWidth--; - } - if (nIn == 0) return; - memcpy(&zBuf[*pnUsed], zIn, nIn); - *pnUsed += nIn; - while ((-iWidth) > nIn) { - zBuf[(*pnUsed)++] = ' '; - iWidth++; - } - zBuf[*pnUsed] = 0; -} -static int lemon_vsprintf(char *str, const char *zFormat, va_list ap) { - int i, j, k, c; - int nUsed = 0; - const char *z; - char zTemp[50]; - str[0] = 0; - for (i = j = 0; (c = zFormat[i]) != 0; i++) { - if (c == '%') { - int iWidth = 0; - lemon_addtext(str, &nUsed, &zFormat[j], i - j, 0); - c = zFormat[++i]; - if (ISDIGIT(c) || (c == '-' && ISDIGIT(zFormat[i + 1]))) { - if (c == '-') i++; - while (ISDIGIT(zFormat[i])) iWidth = iWidth * 10 + zFormat[i++] - '0'; - if (c == '-') iWidth = -iWidth; - c = zFormat[i]; - } - if (c == 'd') { - int v = va_arg(ap, int); - if (v < 0) { - lemon_addtext(str, &nUsed, "-", 1, iWidth); - v = -v; - } else if (v == 0) { - lemon_addtext(str, &nUsed, "0", 1, iWidth); - } - k = 0; - while (v > 0) { - k++; - zTemp[sizeof(zTemp) - k] = (v % 10) + '0'; - v /= 10; - } - lemon_addtext(str, &nUsed, &zTemp[sizeof(zTemp) - k], k, iWidth); - } else if (c == 's') { - z = va_arg(ap, const char *); - lemon_addtext(str, &nUsed, z, -1, iWidth); - } else if (c == '.' && memcmp(&zFormat[i], ".*s", 3) == 0) { - i += 2; - k = va_arg(ap, int); - z = va_arg(ap, const char *); - lemon_addtext(str, &nUsed, z, k, iWidth); - } else if (c == '%') { - lemon_addtext(str, &nUsed, "%", 1, 0); - } else { - fprintf(stderr, "illegal format\n"); - exit(1); - } - j = i + 1; - } - } - lemon_addtext(str, &nUsed, &zFormat[j], i - j, 0); - return nUsed; -} -static int lemon_sprintf(char *str, const char *format, ...) { - va_list ap; - int rc; - va_start(ap, format); - rc = lemon_vsprintf(str, format, ap); - va_end(ap); - return rc; -} -static void lemon_strcpy(char *dest, const char *src) { - while ((*(dest++) = *(src++)) != 0) { - } -} -static void lemon_strcat(char *dest, const char *src) { - while (*dest) dest++; - lemon_strcpy(dest, src); -} - -/* a few forward declarations... */ -struct rule; -struct lemon; -struct action; - -static struct action *Action_new(void); -static struct action *Action_sort(struct action *); - -/********** From the file "build.h" ************************************/ -void FindRulePrecedences(struct lemon *); -void FindFirstSets(struct lemon *); -void FindStates(struct lemon *); -void FindLinks(struct lemon *); -void FindFollowSets(struct lemon *); -void FindActions(struct lemon *); - -/********* From the file "configlist.h" *********************************/ -void Configlist_init(void); -struct config *Configlist_add(struct rule *, int); -struct config *Configlist_addbasis(struct rule *, int); -void Configlist_closure(struct lemon *); -void Configlist_sort(void); -void Configlist_sortbasis(void); -struct config *Configlist_return(void); -struct config *Configlist_basis(void); -void Configlist_eat(struct config *); -void Configlist_reset(void); - -/********* From the file "error.h" ***************************************/ -void ErrorMsg(const char *, int, const char *, ...); - -/****** From the file "option.h" ******************************************/ -enum option_type { - OPT_FLAG = 1, - OPT_INT, - OPT_DBL, - OPT_STR, - OPT_FFLAG, - OPT_FINT, - OPT_FDBL, - OPT_FSTR -}; -struct s_options { - enum option_type type; - const char *label; - char *arg; - const char *message; -}; -int OptInit(char **, struct s_options *, FILE *); -int OptNArgs(void); -char *OptArg(int); -void OptErr(int); -void OptPrint(void); - -/******** From the file "parse.h" *****************************************/ -void Parse(struct lemon *lemp); - -/********* From the file "plink.h" ***************************************/ -struct plink *Plink_new(void); -void Plink_add(struct plink **, struct config *); -void Plink_copy(struct plink **, struct plink *); -void Plink_delete(struct plink *); - -/********** From the file "report.h" *************************************/ -void Reprint(struct lemon *); -void ReportOutput(struct lemon *); -void ReportTable(struct lemon *, int, int); -void ReportHeader(struct lemon *); -void CompressTables(struct lemon *); -void ResortStates(struct lemon *); - -/********** From the file "set.h" ****************************************/ -void SetSize(int); /* All sets will be of size N */ -char *SetNew(void); /* A new set for element 0..N */ -void SetFree(char *); /* Deallocate a set */ -int SetAdd(char *, int); /* Add element to a set */ -int SetUnion(char *, char *); /* A <- A U B, thru element N */ -#define SetFind(X, Y) (X[Y]) /* True if Y is in set X */ - -/********** From the file "struct.h" *************************************/ -/* -** Principal data structures for the LEMON parser generator. -*/ - -typedef enum { LEMON_FALSE = 0, LEMON_TRUE } Boolean; - -/* Symbols (terminals and nonterminals) of the grammar are stored -** in the following: */ -enum symbol_type { TERMINAL, NONTERMINAL, MULTITERMINAL }; -enum e_assoc { LEFT, RIGHT, NONE, UNK }; -struct symbol { - const char *name; /* Name of the symbol */ - int index; /* Index number for this symbol */ - enum symbol_type type; /* Symbols are all either TERMINALS or NTs */ - struct rule *rule; /* Linked list of rules of this (if an NT) */ - struct symbol *fallback; /* fallback token in case this token doesn't parse */ - int prec; /* Precedence if defined (-1 otherwise) */ - enum e_assoc assoc; /* Associativity if precedence is defined */ - char *firstset; /* First-set for all rules of this symbol */ - Boolean lambda; /* True if NT and can generate an empty string */ - int useCnt; /* Number of times used */ - char *destructor; /* Code which executes whenever this symbol is - ** popped from the stack during error processing */ - int destLineno; /* Line number for start of destructor. Set to - ** -1 for duplicate destructors. */ - char *datatype; /* The data type of information held by this - ** object. Only used if type==NONTERMINAL */ - int dtnum; /* The data type number. In the parser, the value - ** stack is a union. The .yy%d element of this - ** union is the correct data type for this object */ - int bContent; /* True if this symbol ever carries content - if - ** it is ever more than just syntax */ - /* The following fields are used by MULTITERMINALs only */ - int nsubsym; /* Number of constituent symbols in the MULTI */ - struct symbol **subsym; /* Array of constituent symbols */ -}; - -/* Each production rule in the grammar is stored in the following -** structure. */ -struct rule { - struct symbol *lhs; /* Left-hand side of the rule */ - const char *lhsalias; /* Alias for the LHS (NULL if none) */ - int lhsStart; /* True if left-hand side is the start symbol */ - int ruleline; /* Line number for the rule */ - int nrhs; /* Number of RHS symbols */ - struct symbol **rhs; /* The RHS symbols */ - const char **rhsalias; /* An alias for each RHS symbol (NULL if none) */ - int line; /* Line number at which code begins */ - const char *code; /* The code executed when this rule is reduced */ - const char *codePrefix; /* Setup code before code[] above */ - const char *codeSuffix; /* Breakdown code after code[] above */ - struct symbol *precsym; /* Precedence symbol for this rule */ - int index; /* An index number for this rule */ - int iRule; /* Rule number as used in the generated tables */ - Boolean noCode; /* True if this rule has no associated C code */ - Boolean codeEmitted; /* True if the code has been emitted already */ - Boolean canReduce; /* True if this rule is ever reduced */ - Boolean doesReduce; /* Reduce actions occur after optimization */ - Boolean neverReduce; /* Reduce is theoretically possible, but prevented - ** by actions or other outside implementation */ - struct rule *nextlhs; /* Next rule with the same LHS */ - struct rule *next; /* Next rule in the global list */ -}; - -/* A configuration is a production rule of the grammar together with -** a mark (dot) showing how much of that rule has been processed so far. -** Configurations also contain a follow-set which is a list of terminal -** symbols which are allowed to immediately follow the end of the rule. -** Every configuration is recorded as an instance of the following: */ -enum cfgstatus { COMPLETE, INCOMPLETE }; -struct config { - struct rule *rp; /* The rule upon which the configuration is based */ - int dot; /* The parse point */ - char *fws; /* Follow-set for this configuration only */ - struct plink *fplp; /* Follow-set forward propagation links */ - struct plink *bplp; /* Follow-set backwards propagation links */ - struct state *stp; /* Pointer to state which contains this */ - enum cfgstatus status; /* used during followset and shift computations */ - struct config *next; /* Next configuration in the state */ - struct config *bp; /* The next basis configuration */ -}; - -enum e_action { - SHIFT, - ACCEPT, - REDUCE, - ERROR, - SSCONFLICT, /* A shift/shift conflict */ - SRCONFLICT, /* Was a reduce, but part of a conflict */ - RRCONFLICT, /* Was a reduce, but part of a conflict */ - SH_RESOLVED, /* Was a shift. Precedence resolved conflict */ - RD_RESOLVED, /* Was reduce. Precedence resolved conflict */ - NOT_USED, /* Deleted by compression */ - SHIFTREDUCE /* Shift first, then reduce */ -}; - -/* Every shift or reduce operation is stored as one of the following */ -struct action { - struct symbol *sp; /* The look-ahead symbol */ - enum e_action type; - union { - struct state *stp; /* The new state, if a shift */ - struct rule *rp; /* The rule, if a reduce */ - } x; - struct symbol *spOpt; /* SHIFTREDUCE optimization to this symbol */ - struct action *next; /* Next action for this state */ - struct action *collide; /* Next action with the same hash */ -}; - -/* Each state of the generated parser's finite state machine -** is encoded as an instance of the following structure. */ -struct state { - struct config *bp; /* The basis configurations for this state */ - struct config *cfp; /* All configurations in this set */ - int statenum; /* Sequential number for this state */ - struct action *ap; /* List of actions for this state */ - int nTknAct, nNtAct; /* Number of actions on terminals and nonterminals */ - int iTknOfst, iNtOfst; /* yy_action[] offset for terminals and nonterms */ - int iDfltReduce; /* Default action is to REDUCE by this rule */ - struct rule *pDfltReduce; /* The default REDUCE rule. */ - int autoReduce; /* True if this is an auto-reduce state */ -}; -#define NO_OFFSET (-2147483647) - -/* A followset propagation link indicates that the contents of one -** configuration followset should be propagated to another whenever -** the first changes. */ -struct plink { - struct config *cfp; /* The configuration to which linked */ - struct plink *next; /* The next propagate link */ -}; - -/* The state vector for the entire parser generator is recorded as -** follows. (LEMON uses no global variables and makes little use of -** static variables. Fields in the following structure can be thought -** of as begin global variables in the program.) */ -struct lemon { - struct state **sorted; /* Table of states sorted by state number */ - struct rule *rule; /* List of all rules */ - struct rule *startRule; /* First rule */ - int nstate; /* Number of states */ - int nxstate; /* nstate with tail degenerate states removed */ - int nrule; /* Number of rules */ - int nruleWithAction; /* Number of rules with actions */ - int nsymbol; /* Number of terminal and nonterminal symbols */ - int nterminal; /* Number of terminal symbols */ - int minShiftReduce; /* Minimum shift-reduce action value */ - int errAction; /* Error action value */ - int accAction; /* Accept action value */ - int noAction; /* No-op action value */ - int minReduce; /* Minimum reduce action */ - int maxAction; /* Maximum action value of any kind */ - struct symbol **symbols; /* Sorted array of pointers to symbols */ - int errorcnt; /* Number of errors */ - struct symbol *errsym; /* The error symbol */ - struct symbol *wildcard; /* Token that matches anything */ - char *name; /* Name of the generated parser */ - char *arg; /* Declaration of the 3th argument to parser */ - char *ctx; /* Declaration of 2nd argument to constructor */ - char *tokentype; /* Type of terminal symbols in the parser stack */ - char *vartype; /* The default type of non-terminal symbols */ - char *start; /* Name of the start symbol for the grammar */ - char *stacksize; /* Size of the parser stack */ - char *include; /* Code to put at the start of the C file */ - char *error; /* Code to execute when an error is seen */ - char *overflow; /* Code to execute on a stack overflow */ - char *failure; /* Code to execute on parser failure */ - char *accept; /* Code to execute when the parser excepts */ - char *extracode; /* Code appended to the generated file */ - char *tokendest; /* Code to execute to destroy token data */ - char *vardest; /* Code for the default non-terminal destructor */ - char *filename; /* Name of the input file */ - char *outname; /* Name of the current output file */ - char *tokenprefix; /* A prefix added to token names in the .h file */ - int nconflict; /* Number of parsing conflicts */ - int nactiontab; /* Number of entries in the yy_action[] table */ - int nlookaheadtab; /* Number of entries in yy_lookahead[] */ - int tablesize; /* Total table size of all tables in bytes */ - int basisflag; /* Print only basis configurations */ - int printPreprocessed; /* Show preprocessor output on stdout */ - int has_fallback; /* True if any %fallback is seen in the grammar */ - int nolinenosflag; /* True if #line statements should not be printed */ - char *argv0; /* Name of the program */ -}; - -#define MemoryCheck(X) \ - if ((X) == 0) { \ - memory_error(); \ - } - -/**************** From the file "table.h" *********************************/ -/* -** All code in this file has been automatically generated -** from a specification in the file -** "table.q" -** by the associative array code building program "aagen". -** Do not edit this file! Instead, edit the specification -** file, then rerun aagen. -*/ -/* -** Code for processing tables in the LEMON parser generator. -*/ -/* Routines for handling a strings */ - -const char *Strsafe(const char *); - -void Strsafe_init(void); -int Strsafe_insert(const char *); -const char *Strsafe_find(const char *); - -/* Routines for handling symbols of the grammar */ - -struct symbol *Symbol_new(const char *); -int Symbolcmpp(const void *, const void *); -void Symbol_init(void); -int Symbol_insert(struct symbol *, const char *); -struct symbol *Symbol_find(const char *); -struct symbol *Symbol_Nth(int); -int Symbol_count(void); -struct symbol **Symbol_arrayof(void); - -/* Routines to manage the state table */ - -int Configcmp(const char *, const char *); -struct state *State_new(void); -void State_init(void); -int State_insert(struct state *, struct config *); -struct state *State_find(struct config *); -struct state **State_arrayof(void); - -/* Routines used for efficiency in Configlist_add */ - -void Configtable_init(void); -int Configtable_insert(struct config *); -struct config *Configtable_find(struct config *); -void Configtable_clear(int (*)(struct config *)); - -/****************** From the file "action.c" *******************************/ -/* -** Routines processing parser actions in the LEMON parser generator. -*/ - -/* Allocate a new parser action */ -static struct action *Action_new(void) { - static struct action *actionfreelist = 0; - struct action *newaction; - - if (actionfreelist == 0) { - int i; - int amt = 100; - actionfreelist = (struct action *)calloc(amt, sizeof(struct action)); - if (actionfreelist == 0) { - fprintf(stderr, "Unable to allocate memory for a new parser action."); - exit(1); - } - for (i = 0; i < amt - 1; i++) - actionfreelist[i].next = &actionfreelist[i + 1]; - actionfreelist[amt - 1].next = 0; - } - newaction = actionfreelist; - actionfreelist = actionfreelist->next; - return newaction; -} - -/* Compare two actions for sorting purposes. Return negative, zero, or -** positive if the first action is less than, equal to, or greater than -** the first -*/ -static int actioncmp(struct action *ap1, struct action *ap2) { - int rc; - rc = ap1->sp->index - ap2->sp->index; - if (rc == 0) { - rc = (int)ap1->type - (int)ap2->type; - } - if (rc == 0 && (ap1->type == REDUCE || ap1->type == SHIFTREDUCE)) { - rc = ap1->x.rp->index - ap2->x.rp->index; - } - if (rc == 0) { - rc = (int)(ap2 - ap1); - } - return rc; -} - -/* Sort parser actions */ -static struct action *Action_sort(struct action *ap) { - ap = (struct action *)msort((char *)ap, (char **)&ap->next, - (int (*)(const char *, const char *))actioncmp); - return ap; -} - -void Action_add(struct action **app, enum e_action type, struct symbol *sp, - char *arg) { - struct action *newaction; - newaction = Action_new(); - newaction->next = *app; - *app = newaction; - newaction->type = type; - newaction->sp = sp; - newaction->spOpt = 0; - if (type == SHIFT) { - newaction->x.stp = (struct state *)arg; - } else { - newaction->x.rp = (struct rule *)arg; - } -} -/********************** New code to implement the "acttab" module ***********/ -/* -** This module implements routines use to construct the yy_action[] table. -*/ - -/* -** The state of the yy_action table under construction is an instance of -** the following structure. -** -** The yy_action table maps the pair (state_number, lookahead) into an -** action_number. The table is an array of integers pairs. The state_number -** determines an initial offset into the yy_action array. The lookahead -** value is then added to this initial offset to get an index X into the -** yy_action array. If the aAction[X].lookahead equals the value of the -** of the lookahead input, then the value of the action_number output is -** aAction[X].action. If the lookaheads do not match then the -** default action for the state_number is returned. -** -** All actions associated with a single state_number are first entered -** into aLookahead[] using multiple calls to acttab_action(). Then the -** actions for that single state_number are placed into the aAction[] -** array with a single call to acttab_insert(). The acttab_insert() call -** also resets the aLookahead[] array in preparation for the next -** state number. -*/ -struct lookahead_action { - int lookahead; /* Value of the lookahead token */ - int action; /* Action to take on the given lookahead */ -}; -typedef struct acttab acttab; -struct acttab { - int nAction; /* Number of used slots in aAction[] */ - int nActionAlloc; /* Slots allocated for aAction[] */ - struct lookahead_action - *aAction, /* The yy_action[] table under construction */ - *aLookahead; /* A single new transaction set */ - int mnLookahead; /* Minimum aLookahead[].lookahead */ - int mnAction; /* Action associated with mnLookahead */ - int mxLookahead; /* Maximum aLookahead[].lookahead */ - int nLookahead; /* Used slots in aLookahead[] */ - int nLookaheadAlloc; /* Slots allocated in aLookahead[] */ - int nterminal; /* Number of terminal symbols */ - int nsymbol; /* total number of symbols */ -}; - -/* Return the number of entries in the yy_action table */ -#define acttab_lookahead_size(X) ((X)->nAction) - -/* The value for the N-th entry in yy_action */ -#define acttab_yyaction(X, N) ((X)->aAction[N].action) - -/* The value for the N-th entry in yy_lookahead */ -#define acttab_yylookahead(X, N) ((X)->aAction[N].lookahead) - -/* Free all memory associated with the given acttab */ -void acttab_free(acttab *p) { - free(p->aAction); - free(p->aLookahead); - free(p); -} - -/* Allocate a new acttab structure */ -acttab *acttab_alloc(int nsymbol, int nterminal) { - acttab *p = (acttab *)calloc(1, sizeof(*p)); - if (p == 0) { - fprintf(stderr, "Unable to allocate memory for a new acttab."); - exit(1); - } - memset(p, 0, sizeof(*p)); - p->nsymbol = nsymbol; - p->nterminal = nterminal; - return p; -} - -/* Add a new action to the current transaction set. -** -** This routine is called once for each lookahead for a particular -** state. -*/ -void acttab_action(acttab *p, int lookahead, int action) { - if (p->nLookahead >= p->nLookaheadAlloc) { - p->nLookaheadAlloc += 25; - p->aLookahead = (struct lookahead_action *)realloc( - p->aLookahead, sizeof(p->aLookahead[0]) * p->nLookaheadAlloc); - if (p->aLookahead == 0) { - fprintf(stderr, "malloc failed\n"); - exit(1); - } - } - if (p->nLookahead == 0) { - p->mxLookahead = lookahead; - p->mnLookahead = lookahead; - p->mnAction = action; - } else { - if (p->mxLookahead < lookahead) p->mxLookahead = lookahead; - if (p->mnLookahead > lookahead) { - p->mnLookahead = lookahead; - p->mnAction = action; - } - } - p->aLookahead[p->nLookahead].lookahead = lookahead; - p->aLookahead[p->nLookahead].action = action; - p->nLookahead++; -} - -/* -** Add the transaction set built up with prior calls to acttab_action() -** into the current action table. Then reset the transaction set back -** to an empty set in preparation for a new round of acttab_action() calls. -** -** Return the offset into the action table of the new transaction. -** -** If the makeItSafe parameter is true, then the offset is chosen so that -** it is impossible to overread the yy_lookaside[] table regardless of -** the lookaside token. This is done for the terminal symbols, as they -** come from external inputs and can contain syntax errors. When makeItSafe -** is false, there is more flexibility in selecting offsets, resulting in -** a smaller table. For non-terminal symbols, which are never syntax errors, -** makeItSafe can be false. -*/ -int acttab_insert(acttab *p, int makeItSafe) { - int i, j, k, n, end; - assert(p->nLookahead > 0); - - /* Make sure we have enough space to hold the expanded action table - ** in the worst case. The worst case occurs if the transaction set - ** must be appended to the current action table - */ - n = p->nsymbol + 1; - if (p->nAction + n >= p->nActionAlloc) { - int oldAlloc = p->nActionAlloc; - p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20; - p->aAction = (struct lookahead_action *)realloc( - p->aAction, sizeof(p->aAction[0]) * p->nActionAlloc); - if (p->aAction == 0) { - fprintf(stderr, "malloc failed\n"); - exit(1); - } - for (i = oldAlloc; i < p->nActionAlloc; i++) { - p->aAction[i].lookahead = -1; - p->aAction[i].action = -1; - } - } - - /* Scan the existing action table looking for an offset that is a - ** duplicate of the current transaction set. Fall out of the loop - ** if and when the duplicate is found. - ** - ** i is the index in p->aAction[] where p->mnLookahead is inserted. - */ - end = makeItSafe ? p->mnLookahead : 0; - for (i = p->nAction - 1; i >= end; i--) { - if (p->aAction[i].lookahead == p->mnLookahead) { - /* All lookaheads and actions in the aLookahead[] transaction - ** must match against the candidate aAction[i] entry. */ - if (p->aAction[i].action != p->mnAction) continue; - for (j = 0; j < p->nLookahead; j++) { - k = p->aLookahead[j].lookahead - p->mnLookahead + i; - if (k < 0 || k >= p->nAction) break; - if (p->aLookahead[j].lookahead != p->aAction[k].lookahead) break; - if (p->aLookahead[j].action != p->aAction[k].action) break; - } - if (j < p->nLookahead) continue; - - /* No possible lookahead value that is not in the aLookahead[] - ** transaction is allowed to match aAction[i] */ - n = 0; - for (j = 0; j < p->nAction; j++) { - if (p->aAction[j].lookahead < 0) continue; - if (p->aAction[j].lookahead == j + p->mnLookahead - i) n++; - } - if (n == p->nLookahead) { - break; /* An exact match is found at offset i */ - } - } - } - - /* If no existing offsets exactly match the current transaction, find an - ** an empty offset in the aAction[] table in which we can add the - ** aLookahead[] transaction. - */ - if (i < end) { - /* Look for holes in the aAction[] table that fit the current - ** aLookahead[] transaction. Leave i set to the offset of the hole. - ** If no holes are found, i is left at p->nAction, which means the - ** transaction will be appended. */ - i = makeItSafe ? p->mnLookahead : 0; - for (; i < p->nActionAlloc - p->mxLookahead; i++) { - if (p->aAction[i].lookahead < 0) { - for (j = 0; j < p->nLookahead; j++) { - k = p->aLookahead[j].lookahead - p->mnLookahead + i; - if (k < 0) break; - if (p->aAction[k].lookahead >= 0) break; - } - if (j < p->nLookahead) continue; - for (j = 0; j < p->nAction; j++) { - if (p->aAction[j].lookahead == j + p->mnLookahead - i) break; - } - if (j == p->nAction) { - break; /* Fits in empty slots */ - } - } - } - } - /* Insert transaction set at index i. */ -#if 0 - printf("Acttab:"); - for(j=0; jnLookahead; j++){ - printf(" %d", p->aLookahead[j].lookahead); - } - printf(" inserted at %d\n", i); -#endif - for (j = 0; j < p->nLookahead; j++) { - k = p->aLookahead[j].lookahead - p->mnLookahead + i; - p->aAction[k] = p->aLookahead[j]; - if (k >= p->nAction) p->nAction = k + 1; - } - if (makeItSafe && i + p->nterminal >= p->nAction) - p->nAction = i + p->nterminal + 1; - p->nLookahead = 0; - - /* Return the offset that is added to the lookahead in order to get the - ** index into yy_action of the action */ - return i - p->mnLookahead; -} - -/* -** Return the size of the action table without the trailing syntax error -** entries. -*/ -int acttab_action_size(acttab *p) { - int n = p->nAction; - while (n > 0 && p->aAction[n - 1].lookahead < 0) { - n--; - } - return n; -} - -/********************** From the file "build.c" *****************************/ -/* -** Routines to construction the finite state machine for the LEMON -** parser generator. -*/ - -/* Find a precedence symbol of every rule in the grammar. -** -** Those rules which have a precedence symbol coded in the input -** grammar using the "[symbol]" construct will already have the -** rp->precsym field filled. Other rules take as their precedence -** symbol the first RHS symbol with a defined precedence. If there -** are not RHS symbols with a defined precedence, the precedence -** symbol field is left blank. -*/ -void FindRulePrecedences(struct lemon *xp) { - struct rule *rp; - for (rp = xp->rule; rp; rp = rp->next) { - if (rp->precsym == 0) { - int i, j; - for (i = 0; i < rp->nrhs && rp->precsym == 0; i++) { - struct symbol *sp = rp->rhs[i]; - if (sp->type == MULTITERMINAL) { - for (j = 0; j < sp->nsubsym; j++) { - if (sp->subsym[j]->prec >= 0) { - rp->precsym = sp->subsym[j]; - break; - } - } - } else if (sp->prec >= 0) { - rp->precsym = rp->rhs[i]; - } - } - } - } - return; -} - -/* Find all nonterminals which will generate the empty string. -** Then go back and compute the first sets of every nonterminal. -** The first set is the set of all terminal symbols which can begin -** a string generated by that nonterminal. -*/ -void FindFirstSets(struct lemon *lemp) { - int i, j; - struct rule *rp; - int progress; - - for (i = 0; i < lemp->nsymbol; i++) { - lemp->symbols[i]->lambda = LEMON_FALSE; - } - for (i = lemp->nterminal; i < lemp->nsymbol; i++) { - lemp->symbols[i]->firstset = SetNew(); - } - - /* First compute all lambdas */ - do { - progress = 0; - for (rp = lemp->rule; rp; rp = rp->next) { - if (rp->lhs->lambda) continue; - for (i = 0; i < rp->nrhs; i++) { - struct symbol *sp = rp->rhs[i]; - assert(sp->type == NONTERMINAL || sp->lambda == LEMON_FALSE); - if (sp->lambda == LEMON_FALSE) break; - } - if (i == rp->nrhs) { - rp->lhs->lambda = LEMON_TRUE; - progress = 1; - } - } - } while (progress); - - /* Now compute all first sets */ - do { - struct symbol *s1, *s2; - progress = 0; - for (rp = lemp->rule; rp; rp = rp->next) { - s1 = rp->lhs; - for (i = 0; i < rp->nrhs; i++) { - s2 = rp->rhs[i]; - if (s2->type == TERMINAL) { - progress += SetAdd(s1->firstset, s2->index); - break; - } else if (s2->type == MULTITERMINAL) { - for (j = 0; j < s2->nsubsym; j++) { - progress += SetAdd(s1->firstset, s2->subsym[j]->index); - } - break; - } else if (s1 == s2) { - if (s1->lambda == LEMON_FALSE) break; - } else { - progress += SetUnion(s1->firstset, s2->firstset); - if (s2->lambda == LEMON_FALSE) break; - } - } - } - } while (progress); - return; -} - -/* Compute all LR(0) states for the grammar. Links -** are added to between some states so that the LR(1) follow sets -** can be computed later. -*/ -PRIVATE struct state *getstate(struct lemon *); /* forward reference */ -void FindStates(struct lemon *lemp) { - struct symbol *sp; - struct rule *rp; - - Configlist_init(); - - /* Find the start symbol */ - if (lemp->start) { - sp = Symbol_find(lemp->start); - if (sp == 0) { - ErrorMsg( - lemp->filename, 0, - "The specified start symbol \"%s\" is not " - "in a nonterminal of the grammar. \"%s\" will be used as the start " - "symbol instead.", - lemp->start, lemp->startRule->lhs->name); - lemp->errorcnt++; - sp = lemp->startRule->lhs; - } - } else { - sp = lemp->startRule->lhs; - } - - /* Make sure the start symbol doesn't occur on the right-hand side of - ** any rule. Report an error if it does. (YACC would generate a new - ** start symbol in this case.) */ - for (rp = lemp->rule; rp; rp = rp->next) { - int i; - for (i = 0; i < rp->nrhs; i++) { - if (rp->rhs[i] == sp) { /* FIX ME: Deal with multiterminals */ - ErrorMsg( - lemp->filename, 0, - "The start symbol \"%s\" occurs on the " - "right-hand side of a rule. This will result in a parser which " - "does not work properly.", - sp->name); - lemp->errorcnt++; - } - } - } - - /* The basis configuration set for the first state - ** is all rules which have the start symbol as their - ** left-hand side */ - for (rp = sp->rule; rp; rp = rp->nextlhs) { - struct config *newcfp; - rp->lhsStart = 1; - newcfp = Configlist_addbasis(rp, 0); - SetAdd(newcfp->fws, 0); - } - - /* Compute the first state. All other states will be - ** computed automatically during the computation of the first one. - ** The returned pointer to the first state is not used. */ - (void)getstate(lemp); - return; -} - -/* Return a pointer to a state which is described by the configuration -** list which has been built from calls to Configlist_add. -*/ -PRIVATE void buildshifts(struct lemon *, struct state *); /* Forwd ref */ -PRIVATE struct state *getstate(struct lemon *lemp) { - struct config *cfp, *bp; - struct state *stp; - - /* Extract the sorted basis of the new state. The basis was constructed - ** by prior calls to "Configlist_addbasis()". */ - Configlist_sortbasis(); - bp = Configlist_basis(); - - /* Get a state with the same basis */ - stp = State_find(bp); - if (stp) { - /* A state with the same basis already exists! Copy all the follow-set - ** propagation links from the state under construction into the - ** preexisting state, then return a pointer to the preexisting state */ - struct config *x, *y; - for (x = bp, y = stp->bp; x && y; x = x->bp, y = y->bp) { - Plink_copy(&y->bplp, x->bplp); - Plink_delete(x->fplp); - x->fplp = x->bplp = 0; - } - cfp = Configlist_return(); - Configlist_eat(cfp); - } else { - /* This really is a new state. Construct all the details */ - Configlist_closure(lemp); /* Compute the configuration closure */ - Configlist_sort(); /* Sort the configuration closure */ - cfp = Configlist_return(); /* Get a pointer to the config list */ - stp = State_new(); /* A new state structure */ - MemoryCheck(stp); - stp->bp = bp; /* Remember the configuration basis */ - stp->cfp = cfp; /* Remember the configuration closure */ - stp->statenum = lemp->nstate++; /* Every state gets a sequence number */ - stp->ap = 0; /* No actions, yet. */ - State_insert(stp, stp->bp); /* Add to the state table */ - buildshifts(lemp, stp); /* Recursively compute successor states */ - } - return stp; -} - -/* -** Return true if two symbols are the same. -*/ -int same_symbol(struct symbol *a, struct symbol *b) { - int i; - if (a == b) return 1; - if (a->type != MULTITERMINAL) return 0; - if (b->type != MULTITERMINAL) return 0; - if (a->nsubsym != b->nsubsym) return 0; - for (i = 0; i < a->nsubsym; i++) { - if (a->subsym[i] != b->subsym[i]) return 0; - } - return 1; -} - -/* Construct all successor states to the given state. A "successor" -** state is any state which can be reached by a shift action. -*/ -PRIVATE void buildshifts(struct lemon *lemp, struct state *stp) { - struct config *cfp; /* For looping thru the config closure of "stp" */ - struct config *bcfp; /* For the inner loop on config closure of "stp" */ - struct config *newcfg; /* */ - struct symbol *sp; /* Symbol following the dot in configuration "cfp" */ - struct symbol *bsp; /* Symbol following the dot in configuration "bcfp" */ - struct state *newstp; /* A pointer to a successor state */ - - /* Each configuration becomes complete after it contibutes to a successor - ** state. Initially, all configurations are incomplete */ - for (cfp = stp->cfp; cfp; cfp = cfp->next) cfp->status = INCOMPLETE; - - /* Loop through all configurations of the state "stp" */ - for (cfp = stp->cfp; cfp; cfp = cfp->next) { - if (cfp->status == COMPLETE) continue; /* Already used by inner loop */ - if (cfp->dot >= cfp->rp->nrhs) continue; /* Can't shift this config */ - Configlist_reset(); /* Reset the new config set */ - sp = cfp->rp->rhs[cfp->dot]; /* Symbol after the dot */ - - /* For every configuration in the state "stp" which has the symbol "sp" - ** following its dot, add the same configuration to the basis set under - ** construction but with the dot shifted one symbol to the right. */ - for (bcfp = cfp; bcfp; bcfp = bcfp->next) { - if (bcfp->status == COMPLETE) continue; /* Already used */ - if (bcfp->dot >= bcfp->rp->nrhs) continue; /* Can't shift this one */ - bsp = bcfp->rp->rhs[bcfp->dot]; /* Get symbol after dot */ - if (!same_symbol(bsp, sp)) continue; /* Must be same as for "cfp" */ - bcfp->status = COMPLETE; /* Mark this config as used */ - newcfg = Configlist_addbasis(bcfp->rp, bcfp->dot + 1); - Plink_add(&newcfg->bplp, bcfp); - } - - /* Get a pointer to the state described by the basis configuration set - ** constructed in the preceding loop */ - newstp = getstate(lemp); - - /* The state "newstp" is reached from the state "stp" by a shift action - ** on the symbol "sp" */ - if (sp->type == MULTITERMINAL) { - int i; - for (i = 0; i < sp->nsubsym; i++) { - Action_add(&stp->ap, SHIFT, sp->subsym[i], (char *)newstp); - } - } else { - Action_add(&stp->ap, SHIFT, sp, (char *)newstp); - } - } -} - -/* -** Construct the propagation links -*/ -void FindLinks(struct lemon *lemp) { - int i; - struct config *cfp, *other; - struct state *stp; - struct plink *plp; - - /* Housekeeping detail: - ** Add to every propagate link a pointer back to the state to - ** which the link is attached. */ - for (i = 0; i < lemp->nstate; i++) { - stp = lemp->sorted[i]; - for (cfp = stp->cfp; cfp; cfp = cfp->next) { - cfp->stp = stp; - } - } - - /* Convert all backlinks into forward links. Only the forward - ** links are used in the follow-set computation. */ - for (i = 0; i < lemp->nstate; i++) { - stp = lemp->sorted[i]; - for (cfp = stp->cfp; cfp; cfp = cfp->next) { - for (plp = cfp->bplp; plp; plp = plp->next) { - other = plp->cfp; - Plink_add(&other->fplp, cfp); - } - } - } -} - -/* Compute all followsets. -** -** A followset is the set of all symbols which can come immediately -** after a configuration. -*/ -void FindFollowSets(struct lemon *lemp) { - int i; - struct config *cfp; - struct plink *plp; - int progress; - int change; - - for (i = 0; i < lemp->nstate; i++) { - for (cfp = lemp->sorted[i]->cfp; cfp; cfp = cfp->next) { - cfp->status = INCOMPLETE; - } - } - - do { - progress = 0; - for (i = 0; i < lemp->nstate; i++) { - for (cfp = lemp->sorted[i]->cfp; cfp; cfp = cfp->next) { - if (cfp->status == COMPLETE) continue; - for (plp = cfp->fplp; plp; plp = plp->next) { - change = SetUnion(plp->cfp->fws, cfp->fws); - if (change) { - plp->cfp->status = INCOMPLETE; - progress = 1; - } - } - cfp->status = COMPLETE; - } - } - } while (progress); -} - -static int resolve_conflict(struct action *, struct action *); - -/* Compute the reduce actions, and resolve conflicts. - */ -void FindActions(struct lemon *lemp) { - int i, j; - struct config *cfp; - struct state *stp; - struct symbol *sp; - struct rule *rp; - - /* Add all of the reduce actions - ** A reduce action is added for each element of the followset of - ** a configuration which has its dot at the extreme right. - */ - for (i = 0; i < lemp->nstate; i++) { /* Loop over all states */ - stp = lemp->sorted[i]; - for (cfp = stp->cfp; cfp; - cfp = cfp->next) { /* Loop over all configurations */ - if (cfp->rp->nrhs == cfp->dot) { /* Is dot at extreme right? */ - for (j = 0; j < lemp->nterminal; j++) { - if (SetFind(cfp->fws, j)) { - /* Add a reduce action to the state "stp" which will reduce by the - ** rule "cfp->rp" if the lookahead symbol is "lemp->symbols[j]" */ - Action_add(&stp->ap, REDUCE, lemp->symbols[j], (char *)cfp->rp); - } - } - } - } - } - - /* Add the accepting token */ - if (lemp->start) { - sp = Symbol_find(lemp->start); - if (sp == 0) sp = lemp->startRule->lhs; - } else { - sp = lemp->startRule->lhs; - } - /* Add to the first state (which is always the starting state of the - ** finite state machine) an action to ACCEPT if the lookahead is the - ** start nonterminal. */ - Action_add(&lemp->sorted[0]->ap, ACCEPT, sp, 0); - - /* Resolve conflicts */ - for (i = 0; i < lemp->nstate; i++) { - struct action *ap, *nap; - stp = lemp->sorted[i]; - /* assert( stp->ap ); */ - stp->ap = Action_sort(stp->ap); - for (ap = stp->ap; ap && ap->next; ap = ap->next) { - for (nap = ap->next; nap && nap->sp == ap->sp; nap = nap->next) { - /* The two actions "ap" and "nap" have the same lookahead. - ** Figure out which one should be used */ - lemp->nconflict += resolve_conflict(ap, nap); - } - } - } - - /* Report an error for each rule that can never be reduced. */ - for (rp = lemp->rule; rp; rp = rp->next) rp->canReduce = LEMON_FALSE; - for (i = 0; i < lemp->nstate; i++) { - struct action *ap; - for (ap = lemp->sorted[i]->ap; ap; ap = ap->next) { - if (ap->type == REDUCE) ap->x.rp->canReduce = LEMON_TRUE; - } - } - for (rp = lemp->rule; rp; rp = rp->next) { - if (rp->canReduce) continue; - ErrorMsg(lemp->filename, rp->ruleline, "This rule can not be reduced.\n"); - lemp->errorcnt++; - } -} - -/* Resolve a conflict between the two given actions. If the -** conflict can't be resolved, return non-zero. -** -** NO LONGER TRUE: -** To resolve a conflict, first look to see if either action -** is on an error rule. In that case, take the action which -** is not associated with the error rule. If neither or both -** actions are associated with an error rule, then try to -** use precedence to resolve the conflict. -** -** If either action is a SHIFT, then it must be apx. This -** function won't work if apx->type==REDUCE and apy->type==SHIFT. -*/ -static int resolve_conflict(struct action *apx, struct action *apy) { - struct symbol *spx, *spy; - int errcnt = 0; - assert(apx->sp == apy->sp); /* Otherwise there would be no conflict */ - if (apx->type == SHIFT && apy->type == SHIFT) { - apy->type = SSCONFLICT; - errcnt++; - } - if (apx->type == SHIFT && apy->type == REDUCE) { - spx = apx->sp; - spy = apy->x.rp->precsym; - if (spy == 0 || spx->prec < 0 || spy->prec < 0) { - /* Not enough precedence information. */ - apy->type = SRCONFLICT; - errcnt++; - } else if (spx->prec > spy->prec) { /* higher precedence wins */ - apy->type = RD_RESOLVED; - } else if (spx->prec < spy->prec) { - apx->type = SH_RESOLVED; - } else if (spx->prec == spy->prec && - spx->assoc == RIGHT) { /* Use operator */ - apy->type = RD_RESOLVED; /* associativity */ - } else if (spx->prec == spy->prec && - spx->assoc == LEFT) { /* to break tie */ - apx->type = SH_RESOLVED; - } else { - assert(spx->prec == spy->prec && spx->assoc == NONE); - apx->type = ERROR; - } - } else if (apx->type == REDUCE && apy->type == REDUCE) { - spx = apx->x.rp->precsym; - spy = apy->x.rp->precsym; - if (spx == 0 || spy == 0 || spx->prec < 0 || spy->prec < 0 || - spx->prec == spy->prec) { - apy->type = RRCONFLICT; - errcnt++; - } else if (spx->prec > spy->prec) { - apy->type = RD_RESOLVED; - } else if (spx->prec < spy->prec) { - apx->type = RD_RESOLVED; - } - } else { - assert(apx->type == SH_RESOLVED || apx->type == RD_RESOLVED || - apx->type == SSCONFLICT || apx->type == SRCONFLICT || - apx->type == RRCONFLICT || apy->type == SH_RESOLVED || - apy->type == RD_RESOLVED || apy->type == SSCONFLICT || - apy->type == SRCONFLICT || apy->type == RRCONFLICT); - /* The REDUCE/SHIFT case cannot happen because SHIFTs come before - ** REDUCEs on the list. If we reach this point it must be because - ** the parser conflict had already been resolved. */ - } - return errcnt; -} -/********************* From the file "configlist.c" *************************/ -/* -** Routines to processing a configuration list and building a state -** in the LEMON parser generator. -*/ - -static struct config *freelist = 0; /* List of free configurations */ -static struct config *current = 0; /* Top of list of configurations */ -static struct config **currentend = 0; /* Last on list of configs */ -static struct config *basis = 0; /* Top of list of basis configs */ -static struct config **basisend = 0; /* End of list of basis configs */ - -/* Return a pointer to a new configuration */ -PRIVATE struct config *newconfig(void) { - struct config *newcfg; - if (freelist == 0) { - int i; - int amt = 3; - freelist = (struct config *)calloc(amt, sizeof(struct config)); - if (freelist == 0) { - fprintf(stderr, "Unable to allocate memory for a new configuration."); - exit(1); - } - for (i = 0; i < amt - 1; i++) freelist[i].next = &freelist[i + 1]; - freelist[amt - 1].next = 0; - } - newcfg = freelist; - freelist = freelist->next; - return newcfg; -} - -/* The configuration "old" is no longer used */ -PRIVATE void deleteconfig(struct config *old) { - old->next = freelist; - freelist = old; -} - -/* Initialized the configuration list builder */ -void Configlist_init(void) { - current = 0; - currentend = ¤t; - basis = 0; - basisend = &basis; - Configtable_init(); - return; -} - -/* Initialized the configuration list builder */ -void Configlist_reset(void) { - current = 0; - currentend = ¤t; - basis = 0; - basisend = &basis; - Configtable_clear(0); - return; -} - -/* Add another configuration to the configuration list */ -struct config *Configlist_add( - struct rule *rp, /* The rule */ - int dot /* Index into the RHS of the rule where the dot goes */ -) { - struct config *cfp, model; - - assert(currentend != 0); - model.rp = rp; - model.dot = dot; - cfp = Configtable_find(&model); - if (cfp == 0) { - cfp = newconfig(); - cfp->rp = rp; - cfp->dot = dot; - cfp->fws = SetNew(); - cfp->stp = 0; - cfp->fplp = cfp->bplp = 0; - cfp->next = 0; - cfp->bp = 0; - *currentend = cfp; - currentend = &cfp->next; - Configtable_insert(cfp); - } - return cfp; -} - -/* Add a basis configuration to the configuration list */ -struct config *Configlist_addbasis(struct rule *rp, int dot) { - struct config *cfp, model; - - assert(basisend != 0); - assert(currentend != 0); - model.rp = rp; - model.dot = dot; - cfp = Configtable_find(&model); - if (cfp == 0) { - cfp = newconfig(); - cfp->rp = rp; - cfp->dot = dot; - cfp->fws = SetNew(); - cfp->stp = 0; - cfp->fplp = cfp->bplp = 0; - cfp->next = 0; - cfp->bp = 0; - *currentend = cfp; - currentend = &cfp->next; - *basisend = cfp; - basisend = &cfp->bp; - Configtable_insert(cfp); - } - return cfp; -} - -/* Compute the closure of the configuration list */ -void Configlist_closure(struct lemon *lemp) { - struct config *cfp, *newcfp; - struct rule *rp, *newrp; - struct symbol *sp, *xsp; - int i, dot; - - assert(currentend != 0); - for (cfp = current; cfp; cfp = cfp->next) { - rp = cfp->rp; - dot = cfp->dot; - if (dot >= rp->nrhs) continue; - sp = rp->rhs[dot]; - if (sp->type == NONTERMINAL) { - if (sp->rule == 0 && sp != lemp->errsym) { - ErrorMsg(lemp->filename, rp->line, "Nonterminal \"%s\" has no rules.", - sp->name); - lemp->errorcnt++; - } - for (newrp = sp->rule; newrp; newrp = newrp->nextlhs) { - newcfp = Configlist_add(newrp, 0); - for (i = dot + 1; i < rp->nrhs; i++) { - xsp = rp->rhs[i]; - if (xsp->type == TERMINAL) { - SetAdd(newcfp->fws, xsp->index); - break; - } else if (xsp->type == MULTITERMINAL) { - int k; - for (k = 0; k < xsp->nsubsym; k++) { - SetAdd(newcfp->fws, xsp->subsym[k]->index); - } - break; - } else { - SetUnion(newcfp->fws, xsp->firstset); - if (xsp->lambda == LEMON_FALSE) break; - } - } - if (i == rp->nrhs) Plink_add(&cfp->fplp, newcfp); - } - } - } - return; -} - -/* Sort the configuration list */ -void Configlist_sort(void) { - current = (struct config *)msort((char *)current, (char **)&(current->next), - Configcmp); - currentend = 0; - return; -} - -/* Sort the basis configuration list */ -void Configlist_sortbasis(void) { - basis = (struct config *)msort((char *)current, (char **)&(current->bp), - Configcmp); - basisend = 0; - return; -} - -/* Return a pointer to the head of the configuration list and -** reset the list */ -struct config *Configlist_return(void) { - struct config *old; - old = current; - current = 0; - currentend = 0; - return old; -} - -/* Return a pointer to the head of the configuration list and -** reset the list */ -struct config *Configlist_basis(void) { - struct config *old; - old = basis; - basis = 0; - basisend = 0; - return old; -} - -/* Free all elements of the given configuration list */ -void Configlist_eat(struct config *cfp) { - struct config *nextcfp; - for (; cfp; cfp = nextcfp) { - nextcfp = cfp->next; - assert(cfp->fplp == 0); - assert(cfp->bplp == 0); - if (cfp->fws) SetFree(cfp->fws); - deleteconfig(cfp); - } - return; -} -/***************** From the file "error.c" *********************************/ -/* -** Code for printing error message. -*/ - -void ErrorMsg(const char *filename, int lineno, const char *format, ...) { - va_list ap; - fprintf(stderr, "%s:%d: ", filename, lineno); - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - fprintf(stderr, "\n"); -} -/**************** From the file "main.c" ************************************/ -/* -** Main program file for the LEMON parser generator. -*/ - -/* Report an out-of-memory condition and abort. This function -** is used mostly by the "MemoryCheck" macro in struct.h -*/ -void memory_error(void) { - fprintf(stderr, "Out of memory. Aborting...\n"); - exit(1); -} - -static int nDefine = 0; /* Number of -D options on the command line */ -static char **azDefine = 0; /* Name of the -D macros */ - -/* This routine is called with the argument to each -D command-line option. -** Add the macro defined to the azDefine array. -*/ -static void handle_D_option(char *z) { - char **paz; - nDefine++; - azDefine = (char **)realloc(azDefine, sizeof(azDefine[0]) * nDefine); - if (azDefine == 0) { - fprintf(stderr, "out of memory\n"); - exit(1); - } - paz = &azDefine[nDefine - 1]; - *paz = (char *)malloc(lemonStrlen(z) + 1); - if (*paz == 0) { - fprintf(stderr, "out of memory\n"); - exit(1); - } - lemon_strcpy(*paz, z); - for (z = *paz; *z && *z != '='; z++) { - } - *z = 0; -} - -/* Rember the name of the output directory - */ -static char *outputDir = NULL; -static void handle_d_option(char *z) { - outputDir = (char *)malloc(lemonStrlen(z) + 1); - if (outputDir == 0) { - fprintf(stderr, "out of memory\n"); - exit(1); - } - lemon_strcpy(outputDir, z); -} - -static char *user_templatename = NULL; -static void handle_T_option(char *z) { - user_templatename = (char *)malloc(lemonStrlen(z) + 1); - if (user_templatename == 0) { - memory_error(); - } - lemon_strcpy(user_templatename, z); -} - -/* Merge together to lists of rules ordered by rule.iRule */ -static struct rule *Rule_merge(struct rule *pA, struct rule *pB) { - struct rule *pFirst = 0; - struct rule **ppPrev = &pFirst; - while (pA && pB) { - if (pA->iRule < pB->iRule) { - *ppPrev = pA; - ppPrev = &pA->next; - pA = pA->next; - } else { - *ppPrev = pB; - ppPrev = &pB->next; - pB = pB->next; - } - } - if (pA) { - *ppPrev = pA; - } else { - *ppPrev = pB; - } - return pFirst; -} - -/* -** Sort a list of rules in order of increasing iRule value -*/ -static struct rule *Rule_sort(struct rule *rp) { - unsigned int i; - struct rule *pNext; - struct rule *x[32]; - memset(x, 0, sizeof(x)); - while (rp) { - pNext = rp->next; - rp->next = 0; - for (i = 0; i < sizeof(x) / sizeof(x[0]) - 1 && x[i]; i++) { - rp = Rule_merge(x[i], rp); - x[i] = 0; - } - x[i] = rp; - rp = pNext; - } - rp = 0; - for (i = 0; i < sizeof(x) / sizeof(x[0]); i++) { - rp = Rule_merge(x[i], rp); - } - return rp; -} - -/* forward reference */ -static const char *minimum_size_type(int lwr, int upr, int *pnByte); - -/* Print a single line of the "Parser Stats" output - */ -static void stats_line(const char *zLabel, int iValue) { - int nLabel = lemonStrlen(zLabel); - printf(" %s%.*s %5d\n", zLabel, 35 - nLabel, - "................................", iValue); -} - -/* The main program. Parse the command line and do it... */ -int main(int argc, char **argv) { - static int version = 0; - static int rpflag = 0; - static int basisflag = 0; - static int compress = 0; - static int quiet = 0; - static int statistics = 0; - static int mhflag = 0; - static int nolinenosflag = 0; - static int noResort = 0; - static int sqlFlag = 0; - static int printPP = 0; - - static const struct s_options options[] = { - {OPT_FLAG, "b", (char *)&basisflag, "Print only the basis in report."}, - {OPT_FLAG, "c", (char *)&compress, "Don't compress the action table."}, - {OPT_FSTR, "d", (char *)&handle_d_option, - "Output directory. Default '.'"}, - {OPT_FSTR, "D", (char *)handle_D_option, "Define an %ifdef macro."}, - {OPT_FLAG, "E", (char *)&printPP, - "Print input file after preprocessing."}, - {OPT_FSTR, "f", 0, "Ignored. (Placeholder for -f compiler options.)"}, - {OPT_FLAG, "g", (char *)&rpflag, "Print grammar without actions."}, - {OPT_FSTR, "I", 0, "Ignored. (Placeholder for '-I' compiler options.)"}, - {OPT_FLAG, "m", (char *)&mhflag, "Output a makeheaders compatible file."}, - {OPT_FLAG, "l", (char *)&nolinenosflag, "Do not print #line statements."}, - {OPT_FSTR, "O", 0, "Ignored. (Placeholder for '-O' compiler options.)"}, - {OPT_FLAG, "p", (char *)&showPrecedenceConflict, - "Show conflicts resolved by precedence rules"}, - {OPT_FLAG, "q", (char *)&quiet, "(Quiet) Don't print the report file."}, - {OPT_FLAG, "r", (char *)&noResort, "Do not sort or renumber states"}, - {OPT_FLAG, "s", (char *)&statistics, - "Print parser stats to standard output."}, - {OPT_FLAG, "S", (char *)&sqlFlag, - "Generate the *.sql file describing the parser tables."}, - {OPT_FLAG, "x", (char *)&version, "Print the version number."}, - {OPT_FSTR, "T", (char *)handle_T_option, "Specify a template file."}, - {OPT_FSTR, "W", 0, "Ignored. (Placeholder for '-W' compiler options.)"}, - {OPT_FLAG, 0, 0, 0}}; - int i; - int exitcode; - struct lemon lem; - struct rule *rp; - - (void)argc; - OptInit(argv, options, stderr); - if (version) { - printf("Lemon version 1.0\n"); - exit(0); - } - if (OptNArgs() != 1) { - fprintf(stderr, "Exactly one filename argument is required.\n"); - exit(1); - } - memset(&lem, 0, sizeof(lem)); - lem.errorcnt = 0; - - /* Initialize the machine */ - Strsafe_init(); - Symbol_init(); - State_init(); - lem.argv0 = argv[0]; - lem.filename = OptArg(0); - lem.basisflag = basisflag; - lem.nolinenosflag = nolinenosflag; - lem.printPreprocessed = printPP; - Symbol_new("$"); - - /* Parse the input file */ - Parse(&lem); - if (lem.printPreprocessed || lem.errorcnt) exit(lem.errorcnt); - if (lem.nrule == 0) { - fprintf(stderr, "Empty grammar.\n"); - exit(1); - } - lem.errsym = Symbol_find("error"); - - /* Count and index the symbols of the grammar */ - Symbol_new("{default}"); - lem.nsymbol = Symbol_count(); - lem.symbols = Symbol_arrayof(); - for (i = 0; i < lem.nsymbol; i++) lem.symbols[i]->index = i; - qsort(lem.symbols, lem.nsymbol, sizeof(struct symbol *), Symbolcmpp); - for (i = 0; i < lem.nsymbol; i++) lem.symbols[i]->index = i; - while (lem.symbols[i - 1]->type == MULTITERMINAL) { - i--; - } - assert(strcmp(lem.symbols[i - 1]->name, "{default}") == 0); - lem.nsymbol = i - 1; - for (i = 1; ISUPPER(lem.symbols[i]->name[0]); i++) - ; - lem.nterminal = i; - - /* Assign sequential rule numbers. Start with 0. Put rules that have no - ** reduce action C-code associated with them last, so that the switch() - ** statement that selects reduction actions will have a smaller jump table. - */ - for (i = 0, rp = lem.rule; rp; rp = rp->next) { - rp->iRule = rp->code ? i++ : -1; - } - lem.nruleWithAction = i; - for (rp = lem.rule; rp; rp = rp->next) { - if (rp->iRule < 0) rp->iRule = i++; - } - lem.startRule = lem.rule; - lem.rule = Rule_sort(lem.rule); - - /* Generate a reprint of the grammar, if requested on the command line */ - if (rpflag) { - Reprint(&lem); - } else { - /* Initialize the size for all follow and first sets */ - SetSize(lem.nterminal + 1); - - /* Find the precedence for every production rule (that has one) */ - FindRulePrecedences(&lem); - - /* Compute the lambda-nonterminals and the first-sets for every - ** nonterminal */ - FindFirstSets(&lem); - - /* Compute all LR(0) states. Also record follow-set propagation - ** links so that the follow-set can be computed later */ - lem.nstate = 0; - FindStates(&lem); - lem.sorted = State_arrayof(); - - /* Tie up loose ends on the propagation links */ - FindLinks(&lem); - - /* Compute the follow set of every reducible configuration */ - FindFollowSets(&lem); - - /* Compute the action tables */ - FindActions(&lem); - - /* Compress the action tables */ - if (compress == 0) CompressTables(&lem); - - /* Reorder and renumber the states so that states with fewer choices - ** occur at the end. This is an optimization that helps make the - ** generated parser tables smaller. */ - if (noResort == 0) ResortStates(&lem); - - /* Generate a report of the parser generated. (the "y.output" file) */ - if (!quiet) ReportOutput(&lem); - - /* Generate the source code for the parser */ - ReportTable(&lem, mhflag, sqlFlag); - - /* Produce a header file for use by the scanner. (This step is - ** omitted if the "-m" option is used because makeheaders will - ** generate the file for us.) */ - if (!mhflag) ReportHeader(&lem); - } - if (statistics) { - printf("Parser statistics:\n"); - stats_line("terminal symbols", lem.nterminal); - stats_line("non-terminal symbols", lem.nsymbol - lem.nterminal); - stats_line("total symbols", lem.nsymbol); - stats_line("rules", lem.nrule); - stats_line("states", lem.nxstate); - stats_line("conflicts", lem.nconflict); - stats_line("action table entries", lem.nactiontab); - stats_line("lookahead table entries", lem.nlookaheadtab); - stats_line("total table size (bytes)", lem.tablesize); - } - if (lem.nconflict > 0) { - fprintf(stderr, "%d parsing conflicts.\n", lem.nconflict); - } - - /* return 0 on success, 1 on failure. */ - exitcode = ((lem.errorcnt > 0) || (lem.nconflict > 0)) ? 1 : 0; - exit(exitcode); - return (exitcode); -} - -/******************** From the file "msort.c" *******************************/ -/* -** A generic merge-sort program. -** -** USAGE: -** Let "ptr" be a pointer to some structure which is at the head of -** a null-terminated list. Then to sort the list call: -** -** ptr = msort(ptr,&(ptr->next),cmpfnc); -** -** In the above, "cmpfnc" is a pointer to a function which compares -** two instances of the structure and returns an integer, as in -** strcmp. The second argument is a pointer to the pointer to the -** second element of the linked list. This address is used to compute -** the offset to the "next" field within the structure. The offset to -** the "next" field must be constant for all structures in the list. -** -** The function returns a new pointer which is the head of the list -** after sorting. -** -** ALGORITHM: -** Merge-sort. -*/ - -/* -** Return a pointer to the next structure in the linked list. -*/ -#define NEXT(A) (*(char **)(((char *)A) + offset)) - -/* -** Inputs: -** a: A sorted, null-terminated linked list. (May be null). -** b: A sorted, null-terminated linked list. (May be null). -** cmp: A pointer to the comparison function. -** offset: Offset in the structure to the "next" field. -** -** Return Value: -** A pointer to the head of a sorted list containing the elements -** of both a and b. -** -** Side effects: -** The "next" pointers for elements in the lists a and b are -** changed. -*/ -static char *merge(char *a, char *b, int (*cmp)(const char *, const char *), - int offset) { - char *ptr, *head; - if (a == 0) { - head = b; - } else if (b == 0) { - head = a; - } else { - if ((*cmp)(a, b) <= 0) { - ptr = a; - a = NEXT(a); - } else { - ptr = b; - b = NEXT(b); - } - head = ptr; - while (a && b) { - if ((*cmp)(a, b) <= 0) { - NEXT(ptr) = a; - ptr = a; - a = NEXT(a); - } else { - NEXT(ptr) = b; - ptr = b; - b = NEXT(b); - } - } - if (a) - NEXT(ptr) = a; - else - NEXT(ptr) = b; - } - return head; -} - -/* -** Inputs: -** list: Pointer to a singly-linked list of structures. -** next: Pointer to pointer to the second element of the list. -** cmp: A comparison function. -** -** Return Value: -** A pointer to the head of a sorted list containing the elements -** orginally in list. -** -** Side effects: -** The "next" pointers for elements in list are changed. -*/ -#define LISTSIZE 30 -static char *msort(char *list, char **next, - int (*cmp)(const char *, const char *)) { - unsigned long offset; - char *ep; - char *set[LISTSIZE]; - int i; - offset = (unsigned long)((char *)next - (char *)list); - for (i = 0; i < LISTSIZE; i++) set[i] = 0; - while (list) { - ep = list; - list = NEXT(list); - NEXT(ep) = 0; - for (i = 0; i < LISTSIZE - 1 && set[i] != 0; i++) { - ep = merge(ep, set[i], cmp, offset); - set[i] = 0; - } - set[i] = ep; - } - ep = 0; - for (i = 0; i < LISTSIZE; i++) - if (set[i]) ep = merge(set[i], ep, cmp, offset); - return ep; -} - -/************************ From the file "option.c" **************************/ -static char **lemon_argv; -static struct s_options *op; -static FILE *errstream; - -#define ISOPT(X) ((X)[0] == '-' || (X)[0] == '+' || strchr((X), '=') != 0) - -/* -** Print the command line with a carrot pointing to the k-th character -** of the n-th field. -*/ -static void errline(int n, int k, FILE *err) { - int spcnt, i; - if (lemon_argv[0]) fprintf(err, "%s", lemon_argv[0]); - spcnt = lemonStrlen(lemon_argv[0]) + 1; - for (i = 1; i < n && lemon_argv[i]; i++) { - fprintf(err, " %s", lemon_argv[i]); - spcnt += lemonStrlen(lemon_argv[i]) + 1; - } - spcnt += k; - for (; lemon_argv[i]; i++) fprintf(err, " %s", lemon_argv[i]); - if (spcnt < 20) { - fprintf(err, "\n%*s^-- here\n", spcnt, ""); - } else { - fprintf(err, "\n%*shere --^\n", spcnt - 7, ""); - } -} - -/* -** Return the index of the N-th non-switch argument. Return -1 -** if N is out of range. -*/ -static int argindex(int n) { - int i; - int dashdash = 0; - if (lemon_argv != 0 && *lemon_argv != 0) { - for (i = 1; lemon_argv[i]; i++) { - if (dashdash || !ISOPT(lemon_argv[i])) { - if (n == 0) return i; - n--; - } - if (strcmp(lemon_argv[i], "--") == 0) dashdash = 1; - } - } - return -1; -} - -static const char emsg[] = "Command line syntax error: "; - -/* -** Process a flag command line argument. -*/ -static int handleflags(int i, FILE *err) { - int v; - int errcnt = 0; - int j; - for (j = 0; op[j].label; j++) { - if (strncmp(&lemon_argv[i][1], op[j].label, lemonStrlen(op[j].label)) == 0) - break; - } - v = lemon_argv[i][0] == '-' ? 1 : 0; - if (op[j].label == 0) { - if (err) { - fprintf(err, "%sundefined option.\n", emsg); - errline(i, 1, err); - } - errcnt++; - } else if (op[j].arg == 0) { - /* Ignore this option */ - } else if (op[j].type == OPT_FLAG) { - *((int *)op[j].arg) = v; - } else if (op[j].type == OPT_FFLAG) { - (*(void (*)(int))(op[j].arg))(v); - } else if (op[j].type == OPT_FSTR) { - (*(void (*)(char *))(op[j].arg))(&lemon_argv[i][2]); - } else { - if (err) { - fprintf(err, "%smissing argument on switch.\n", emsg); - errline(i, 1, err); - } - errcnt++; - } - return errcnt; -} - -/* -** Process a command line switch which has an argument. -*/ -static int handleswitch(int i, FILE *err) { - int lv = 0; - double dv = 0.0; - char *sv = 0, *end; - char *cp; - int j; - int errcnt = 0; - cp = strchr(lemon_argv[i], '='); - assert(cp != 0); - *cp = 0; - for (j = 0; op[j].label; j++) { - if (strcmp(lemon_argv[i], op[j].label) == 0) break; - } - *cp = '='; - if (op[j].label == 0) { - if (err) { - fprintf(err, "%sundefined option.\n", emsg); - errline(i, 0, err); - } - errcnt++; - } else { - cp++; - switch (op[j].type) { - case OPT_FLAG: - case OPT_FFLAG: - if (err) { - fprintf(err, "%soption requires an argument.\n", emsg); - errline(i, 0, err); - } - errcnt++; - break; - case OPT_DBL: - case OPT_FDBL: - dv = strtod(cp, &end); - if (*end) { - if (err) { - fprintf(err, "%sillegal character in floating-point argument.\n", - emsg); - errline(i, (int)((char *)end - (char *)lemon_argv[i]), err); - } - errcnt++; - } - break; - case OPT_INT: - case OPT_FINT: - lv = strtol(cp, &end, 0); - if (*end) { - if (err) { - fprintf(err, "%sillegal character in integer argument.\n", emsg); - errline(i, (int)((char *)end - (char *)lemon_argv[i]), err); - } - errcnt++; - } - break; - case OPT_STR: - case OPT_FSTR: - sv = cp; - break; - } - switch (op[j].type) { - case OPT_FLAG: - case OPT_FFLAG: - break; - case OPT_DBL: - *(double *)(op[j].arg) = dv; - break; - case OPT_FDBL: - (*(void (*)(double))(op[j].arg))(dv); - break; - case OPT_INT: - *(int *)(op[j].arg) = lv; - break; - case OPT_FINT: - (*(void (*)(int))(op[j].arg))((int)lv); - break; - case OPT_STR: - *(char **)(op[j].arg) = sv; - break; - case OPT_FSTR: - (*(void (*)(char *))(op[j].arg))(sv); - break; - } - } - return errcnt; -} - -int OptInit(char **a, struct s_options *o, FILE *err) { - int errcnt = 0; - lemon_argv = a; - op = o; - errstream = err; - if (lemon_argv && *lemon_argv && op) { - int i; - for (i = 1; lemon_argv[i]; i++) { - if (lemon_argv[i][0] == '+' || lemon_argv[i][0] == '-') { - errcnt += handleflags(i, err); - } else if (strchr(lemon_argv[i], '=')) { - errcnt += handleswitch(i, err); - } - } - } - if (errcnt > 0) { - fprintf(err, "Valid command line options for \"%s\" are:\n", *a); - OptPrint(); - exit(1); - } - return 0; -} - -int OptNArgs(void) { - int cnt = 0; - int dashdash = 0; - int i; - if (lemon_argv != 0 && lemon_argv[0] != 0) { - for (i = 1; lemon_argv[i]; i++) { - if (dashdash || !ISOPT(lemon_argv[i])) cnt++; - if (strcmp(lemon_argv[i], "--") == 0) dashdash = 1; - } - } - return cnt; -} - -char *OptArg(int n) { - int i; - i = argindex(n); - return i >= 0 ? lemon_argv[i] : 0; -} - -void OptErr(int n) { - int i; - i = argindex(n); - if (i >= 0) errline(i, 0, errstream); -} - -void OptPrint(void) { - int i; - int max, len; - max = 0; - for (i = 0; op[i].label; i++) { - len = lemonStrlen(op[i].label) + 1; - switch (op[i].type) { - case OPT_FLAG: - case OPT_FFLAG: - break; - case OPT_INT: - case OPT_FINT: - len += 9; /* length of "" */ - break; - case OPT_DBL: - case OPT_FDBL: - len += 6; /* length of "" */ - break; - case OPT_STR: - case OPT_FSTR: - len += 8; /* length of "" */ - break; - } - if (len > max) max = len; - } - for (i = 0; op[i].label; i++) { - switch (op[i].type) { - case OPT_FLAG: - case OPT_FFLAG: - fprintf(errstream, " -%-*s %s\n", max, op[i].label, op[i].message); - break; - case OPT_INT: - case OPT_FINT: - fprintf(errstream, " -%s%*s %s\n", op[i].label, - (int)(max - lemonStrlen(op[i].label) - 9), "", op[i].message); - break; - case OPT_DBL: - case OPT_FDBL: - fprintf(errstream, " -%s%*s %s\n", op[i].label, - (int)(max - lemonStrlen(op[i].label) - 6), "", op[i].message); - break; - case OPT_STR: - case OPT_FSTR: - fprintf(errstream, " -%s%*s %s\n", op[i].label, - (int)(max - lemonStrlen(op[i].label) - 8), "", op[i].message); - break; - } - } -} - -/*********************** From the file "parse.c" ****************************/ -/* -** Input file parser for the LEMON parser generator. -*/ - -/* The state of the parser */ -enum e_state { - INITIALIZE, - WAITING_FOR_DECL_OR_RULE, - WAITING_FOR_DECL_KEYWORD, - WAITING_FOR_DECL_ARG, - WAITING_FOR_PRECEDENCE_SYMBOL, - WAITING_FOR_ARROW, - IN_RHS, - LHS_ALIAS_1, - LHS_ALIAS_2, - LHS_ALIAS_3, - RHS_ALIAS_1, - RHS_ALIAS_2, - PRECEDENCE_MARK_1, - PRECEDENCE_MARK_2, - RESYNC_AFTER_RULE_ERROR, - RESYNC_AFTER_DECL_ERROR, - WAITING_FOR_DESTRUCTOR_SYMBOL, - WAITING_FOR_DATATYPE_SYMBOL, - WAITING_FOR_FALLBACK_ID, - WAITING_FOR_WILDCARD_ID, - WAITING_FOR_CLASS_ID, - WAITING_FOR_CLASS_TOKEN, - WAITING_FOR_TOKEN_NAME -}; - -struct pstate { - char *filename; /* Name of the input file */ - int tokenlineno; /* Linenumber at which current token starts */ - int errorcnt; /* Number of errors so far */ - char *tokenstart; /* Text of current token */ - struct lemon *gp; /* Global state vector */ - enum e_state state; /* The state of the parser */ - struct symbol *fallback; /* The fallback token */ - struct symbol *tkclass; /* Token class symbol */ - struct symbol *lhs; /* Left-hand side of current rule */ - const char *lhsalias; /* Alias for the LHS */ - int nrhs; /* Number of right-hand side symbols seen */ - struct symbol *rhs[MAXRHS]; /* RHS symbols */ - const char *alias[MAXRHS]; /* Aliases for each RHS symbol (or NULL) */ - struct rule *prevrule; /* Previous rule parsed */ - const char *declkeyword; /* Keyword of a declaration */ - char **declargslot; /* Where the declaration argument should be put */ - int insertLineMacro; /* Add #line before declaration insert */ - int *decllinenoslot; /* Where to write declaration line number */ - enum e_assoc declassoc; /* Assign this association to decl arguments */ - int preccounter; /* Assign this precedence to decl arguments */ - struct rule *firstrule; /* Pointer to first rule in the grammar */ - struct rule *lastrule; /* Pointer to the most recently parsed rule */ -}; - -/* Parse a single token */ -static void parseonetoken(struct pstate *psp) { - const char *x; - x = Strsafe(psp->tokenstart); /* Save the token permanently */ -#if 0 - printf("%s:%d: Token=[%s] state=%d\n",psp->filename,psp->tokenlineno, - x,psp->state); -#endif - switch (psp->state) { - case INITIALIZE: - psp->prevrule = 0; - psp->preccounter = 0; - psp->firstrule = psp->lastrule = 0; - psp->gp->nrule = 0; - /* fall through */ - case WAITING_FOR_DECL_OR_RULE: - if (x[0] == '%') { - psp->state = WAITING_FOR_DECL_KEYWORD; - } else if (ISLOWER(x[0])) { - psp->lhs = Symbol_new(x); - psp->nrhs = 0; - psp->lhsalias = 0; - psp->state = WAITING_FOR_ARROW; - } else if (x[0] == '{') { - if (psp->prevrule == 0) { - ErrorMsg(psp->filename, psp->tokenlineno, - "There is no prior rule upon which to attach the code " - "fragment which begins on this line."); - psp->errorcnt++; - } else if (psp->prevrule->code != 0) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Code fragment beginning on this line is not the first " - "to follow the previous rule."); - psp->errorcnt++; - } else if (strcmp(x, "{NEVER-REDUCE") == 0) { - psp->prevrule->neverReduce = 1; - } else { - psp->prevrule->line = psp->tokenlineno; - psp->prevrule->code = &x[1]; - psp->prevrule->noCode = 0; - } - } else if (x[0] == '[') { - psp->state = PRECEDENCE_MARK_1; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Token \"%s\" should be either \"%%\" or a nonterminal name.", - x); - psp->errorcnt++; - } - break; - case PRECEDENCE_MARK_1: - if (!ISUPPER(x[0])) { - ErrorMsg(psp->filename, psp->tokenlineno, - "The precedence symbol must be a terminal."); - psp->errorcnt++; - } else if (psp->prevrule == 0) { - ErrorMsg(psp->filename, psp->tokenlineno, - "There is no prior rule to assign precedence \"[%s]\".", x); - psp->errorcnt++; - } else if (psp->prevrule->precsym != 0) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Precedence mark on this line is not the first " - "to follow the previous rule."); - psp->errorcnt++; - } else { - psp->prevrule->precsym = Symbol_new(x); - } - psp->state = PRECEDENCE_MARK_2; - break; - case PRECEDENCE_MARK_2: - if (x[0] != ']') { - ErrorMsg(psp->filename, psp->tokenlineno, - "Missing \"]\" on precedence mark."); - psp->errorcnt++; - } - psp->state = WAITING_FOR_DECL_OR_RULE; - break; - case WAITING_FOR_ARROW: - if (x[0] == ':' && x[1] == ':' && x[2] == '=') { - psp->state = IN_RHS; - } else if (x[0] == '(') { - psp->state = LHS_ALIAS_1; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Expected to see a \":\" following the LHS symbol \"%s\".", - psp->lhs->name); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case LHS_ALIAS_1: - if (ISALPHA(x[0])) { - psp->lhsalias = x; - psp->state = LHS_ALIAS_2; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "\"%s\" is not a valid alias for the LHS \"%s\"\n", x, - psp->lhs->name); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case LHS_ALIAS_2: - if (x[0] == ')') { - psp->state = LHS_ALIAS_3; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Missing \")\" following LHS alias name \"%s\".", - psp->lhsalias); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case LHS_ALIAS_3: - if (x[0] == ':' && x[1] == ':' && x[2] == '=') { - psp->state = IN_RHS; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Missing \"->\" following: \"%s(%s)\".", psp->lhs->name, - psp->lhsalias); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case IN_RHS: - if (x[0] == '.') { - struct rule *rp; - rp = (struct rule *)calloc(sizeof(struct rule) + - sizeof(struct symbol *) * psp->nrhs + - sizeof(char *) * psp->nrhs, - 1); - if (rp == 0) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Can't allocate enough memory for this rule."); - psp->errorcnt++; - psp->prevrule = 0; - } else { - int i; - rp->ruleline = psp->tokenlineno; - rp->rhs = (struct symbol **)&rp[1]; - rp->rhsalias = (const char **)&(rp->rhs[psp->nrhs]); - for (i = 0; i < psp->nrhs; i++) { - rp->rhs[i] = psp->rhs[i]; - rp->rhsalias[i] = psp->alias[i]; - if (rp->rhsalias[i] != 0) { - rp->rhs[i]->bContent = 1; - } - } - rp->lhs = psp->lhs; - rp->lhsalias = psp->lhsalias; - rp->nrhs = psp->nrhs; - rp->code = 0; - rp->noCode = 1; - rp->precsym = 0; - rp->index = psp->gp->nrule++; - rp->nextlhs = rp->lhs->rule; - rp->lhs->rule = rp; - rp->next = 0; - if (psp->firstrule == 0) { - psp->firstrule = psp->lastrule = rp; - } else { - psp->lastrule->next = rp; - psp->lastrule = rp; - } - psp->prevrule = rp; - } - psp->state = WAITING_FOR_DECL_OR_RULE; - } else if (ISALPHA(x[0])) { - if (psp->nrhs >= MAXRHS) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Too many symbols on RHS of rule beginning at \"%s\".", x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } else { - psp->rhs[psp->nrhs] = Symbol_new(x); - psp->alias[psp->nrhs] = 0; - psp->nrhs++; - } - } else if ((x[0] == '|' || x[0] == '/') && psp->nrhs > 0 && - ISUPPER(x[1])) { - struct symbol *msp = psp->rhs[psp->nrhs - 1]; - if (msp->type != MULTITERMINAL) { - struct symbol *origsp = msp; - msp = (struct symbol *)calloc(1, sizeof(*msp)); - memset(msp, 0, sizeof(*msp)); - msp->type = MULTITERMINAL; - msp->nsubsym = 1; - msp->subsym = (struct symbol **)calloc(1, sizeof(struct symbol *)); - msp->subsym[0] = origsp; - msp->name = origsp->name; - psp->rhs[psp->nrhs - 1] = msp; - } - msp->nsubsym++; - msp->subsym = (struct symbol **)realloc( - msp->subsym, sizeof(struct symbol *) * msp->nsubsym); - msp->subsym[msp->nsubsym - 1] = Symbol_new(&x[1]); - if (ISLOWER(x[1]) || ISLOWER(msp->subsym[0]->name[0])) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Cannot form a compound containing a non-terminal"); - psp->errorcnt++; - } - } else if (x[0] == '(' && psp->nrhs > 0) { - psp->state = RHS_ALIAS_1; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Illegal character on RHS of rule: \"%s\".", x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case RHS_ALIAS_1: - if (ISALPHA(x[0])) { - psp->alias[psp->nrhs - 1] = x; - psp->state = RHS_ALIAS_2; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "\"%s\" is not a valid alias for the RHS symbol \"%s\"\n", x, - psp->rhs[psp->nrhs - 1]->name); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case RHS_ALIAS_2: - if (x[0] == ')') { - psp->state = IN_RHS; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Missing \")\" following LHS alias name \"%s\".", - psp->lhsalias); - psp->errorcnt++; - psp->state = RESYNC_AFTER_RULE_ERROR; - } - break; - case WAITING_FOR_DECL_KEYWORD: - if (ISALPHA(x[0])) { - psp->declkeyword = x; - psp->declargslot = 0; - psp->decllinenoslot = 0; - psp->insertLineMacro = 1; - psp->state = WAITING_FOR_DECL_ARG; - if (strcmp(x, "name") == 0) { - psp->declargslot = &(psp->gp->name); - psp->insertLineMacro = 0; - } else if (strcmp(x, "include") == 0) { - psp->declargslot = &(psp->gp->include); - } else if (strcmp(x, "code") == 0) { - psp->declargslot = &(psp->gp->extracode); - } else if (strcmp(x, "token_destructor") == 0) { - psp->declargslot = &psp->gp->tokendest; - } else if (strcmp(x, "default_destructor") == 0) { - psp->declargslot = &psp->gp->vardest; - } else if (strcmp(x, "token_prefix") == 0) { - psp->declargslot = &psp->gp->tokenprefix; - psp->insertLineMacro = 0; - } else if (strcmp(x, "syntax_error") == 0) { - psp->declargslot = &(psp->gp->error); - } else if (strcmp(x, "parse_accept") == 0) { - psp->declargslot = &(psp->gp->accept); - } else if (strcmp(x, "parse_failure") == 0) { - psp->declargslot = &(psp->gp->failure); - } else if (strcmp(x, "stack_overflow") == 0) { - psp->declargslot = &(psp->gp->overflow); - } else if (strcmp(x, "extra_argument") == 0) { - psp->declargslot = &(psp->gp->arg); - psp->insertLineMacro = 0; - } else if (strcmp(x, "extra_context") == 0) { - psp->declargslot = &(psp->gp->ctx); - psp->insertLineMacro = 0; - } else if (strcmp(x, "token_type") == 0) { - psp->declargslot = &(psp->gp->tokentype); - psp->insertLineMacro = 0; - } else if (strcmp(x, "default_type") == 0) { - psp->declargslot = &(psp->gp->vartype); - psp->insertLineMacro = 0; - } else if (strcmp(x, "stack_size") == 0) { - psp->declargslot = &(psp->gp->stacksize); - psp->insertLineMacro = 0; - } else if (strcmp(x, "start_symbol") == 0) { - psp->declargslot = &(psp->gp->start); - psp->insertLineMacro = 0; - } else if (strcmp(x, "left") == 0) { - psp->preccounter++; - psp->declassoc = LEFT; - psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; - } else if (strcmp(x, "right") == 0) { - psp->preccounter++; - psp->declassoc = RIGHT; - psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; - } else if (strcmp(x, "nonassoc") == 0) { - psp->preccounter++; - psp->declassoc = NONE; - psp->state = WAITING_FOR_PRECEDENCE_SYMBOL; - } else if (strcmp(x, "destructor") == 0) { - psp->state = WAITING_FOR_DESTRUCTOR_SYMBOL; - } else if (strcmp(x, "type") == 0) { - psp->state = WAITING_FOR_DATATYPE_SYMBOL; - } else if (strcmp(x, "fallback") == 0) { - psp->fallback = 0; - psp->state = WAITING_FOR_FALLBACK_ID; - } else if (strcmp(x, "token") == 0) { - psp->state = WAITING_FOR_TOKEN_NAME; - } else if (strcmp(x, "wildcard") == 0) { - psp->state = WAITING_FOR_WILDCARD_ID; - } else if (strcmp(x, "token_class") == 0) { - psp->state = WAITING_FOR_CLASS_ID; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Unknown declaration keyword: \"%%%s\".", x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Illegal declaration keyword: \"%s\".", x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } - break; - case WAITING_FOR_DESTRUCTOR_SYMBOL: - if (!ISALPHA(x[0])) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Symbol name missing after %%destructor keyword"); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } else { - struct symbol *sp = Symbol_new(x); - psp->declargslot = &sp->destructor; - psp->decllinenoslot = &sp->destLineno; - psp->insertLineMacro = 1; - psp->state = WAITING_FOR_DECL_ARG; - } - break; - case WAITING_FOR_DATATYPE_SYMBOL: - if (!ISALPHA(x[0])) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Symbol name missing after %%type keyword"); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } else { - struct symbol *sp = Symbol_find(x); - if ((sp) && (sp->datatype)) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Symbol %%type \"%s\" already defined", x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } else { - if (!sp) { - sp = Symbol_new(x); - } - psp->declargslot = &sp->datatype; - psp->insertLineMacro = 0; - psp->state = WAITING_FOR_DECL_ARG; - } - } - break; - case WAITING_FOR_PRECEDENCE_SYMBOL: - if (x[0] == '.') { - psp->state = WAITING_FOR_DECL_OR_RULE; - } else if (ISUPPER(x[0])) { - struct symbol *sp; - sp = Symbol_new(x); - if (sp->prec >= 0) { - ErrorMsg(psp->filename, psp->tokenlineno, - "Symbol \"%s\" has already be given a precedence.", x); - psp->errorcnt++; - } else { - sp->prec = psp->preccounter; - sp->assoc = psp->declassoc; - } - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Can't assign a precedence to \"%s\".", x); - psp->errorcnt++; - } - break; - case WAITING_FOR_DECL_ARG: - if (x[0] == '{' || x[0] == '\"' || ISALNUM(x[0])) { - const char *zOld, *zNew; - char *zBuf, *z; - int nOld, n, nLine = 0, nNew, nBack; - int addLineMacro; - char zLine[50]; - zNew = x; - if (zNew[0] == '"' || zNew[0] == '{') zNew++; - nNew = lemonStrlen(zNew); - if (*psp->declargslot) { - zOld = *psp->declargslot; - } else { - zOld = ""; - } - nOld = lemonStrlen(zOld); - n = nOld + nNew + 20; - addLineMacro = - !psp->gp->nolinenosflag && psp->insertLineMacro && - psp->tokenlineno > 1 && - (psp->decllinenoslot == 0 || psp->decllinenoslot[0] != 0); - if (addLineMacro) { - for (z = psp->filename, nBack = 0; *z; z++) { - if (*z == '\\') nBack++; - } - lemon_sprintf(zLine, "#line %d ", psp->tokenlineno); - nLine = lemonStrlen(zLine); - n += nLine + lemonStrlen(psp->filename) + nBack; - } - *psp->declargslot = (char *)realloc(*psp->declargslot, n); - zBuf = *psp->declargslot + nOld; - if (addLineMacro) { - if (nOld && zBuf[-1] != '\n') { - *(zBuf++) = '\n'; - } - memcpy(zBuf, zLine, nLine); - zBuf += nLine; - *(zBuf++) = '"'; - for (z = psp->filename; *z; z++) { - if (*z == '\\') { - *(zBuf++) = '\\'; - } - *(zBuf++) = *z; - } - *(zBuf++) = '"'; - *(zBuf++) = '\n'; - } - if (psp->decllinenoslot && psp->decllinenoslot[0] == 0) { - psp->decllinenoslot[0] = psp->tokenlineno; - } - memcpy(zBuf, zNew, nNew); - zBuf += nNew; - *zBuf = 0; - psp->state = WAITING_FOR_DECL_OR_RULE; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Illegal argument to %%%s: %s", psp->declkeyword, x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } - break; - case WAITING_FOR_FALLBACK_ID: - if (x[0] == '.') { - psp->state = WAITING_FOR_DECL_OR_RULE; - } else if (!ISUPPER(x[0])) { - ErrorMsg(psp->filename, psp->tokenlineno, - "%%fallback argument \"%s\" should be a token", x); - psp->errorcnt++; - } else { - struct symbol *sp = Symbol_new(x); - if (psp->fallback == 0) { - psp->fallback = sp; - } else if (sp->fallback) { - ErrorMsg(psp->filename, psp->tokenlineno, - "More than one fallback assigned to token %s", x); - psp->errorcnt++; - } else { - sp->fallback = psp->fallback; - psp->gp->has_fallback = 1; - } - } - break; - case WAITING_FOR_TOKEN_NAME: - /* Tokens do not have to be declared before use. But they can be - ** in order to control their assigned integer number. The number for - ** each token is assigned when it is first seen. So by including - ** - ** %token ONE TWO THREE - ** - ** early in the grammar file, that assigns small consecutive values - ** to each of the tokens ONE TWO and THREE. - */ - if (x[0] == '.') { - psp->state = WAITING_FOR_DECL_OR_RULE; - } else if (!ISUPPER(x[0])) { - ErrorMsg(psp->filename, psp->tokenlineno, - "%%token argument \"%s\" should be a token", x); - psp->errorcnt++; - } else { - (void)Symbol_new(x); - } - break; - case WAITING_FOR_WILDCARD_ID: - if (x[0] == '.') { - psp->state = WAITING_FOR_DECL_OR_RULE; - } else if (!ISUPPER(x[0])) { - ErrorMsg(psp->filename, psp->tokenlineno, - "%%wildcard argument \"%s\" should be a token", x); - psp->errorcnt++; - } else { - struct symbol *sp = Symbol_new(x); - if (psp->gp->wildcard == 0) { - psp->gp->wildcard = sp; - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "Extra wildcard to token: %s", x); - psp->errorcnt++; - } - } - break; - case WAITING_FOR_CLASS_ID: - if (!ISLOWER(x[0])) { - ErrorMsg(psp->filename, psp->tokenlineno, - "%%token_class must be followed by an identifier: %s", x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } else if (Symbol_find(x)) { - ErrorMsg(psp->filename, psp->tokenlineno, "Symbol \"%s\" already used", - x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } else { - psp->tkclass = Symbol_new(x); - psp->tkclass->type = MULTITERMINAL; - psp->state = WAITING_FOR_CLASS_TOKEN; - } - break; - case WAITING_FOR_CLASS_TOKEN: - if (x[0] == '.') { - psp->state = WAITING_FOR_DECL_OR_RULE; - } else if (ISUPPER(x[0]) || - ((x[0] == '|' || x[0] == '/') && ISUPPER(x[1]))) { - struct symbol *msp = psp->tkclass; - msp->nsubsym++; - msp->subsym = (struct symbol **)realloc( - msp->subsym, sizeof(struct symbol *) * msp->nsubsym); - if (!ISUPPER(x[0])) x++; - msp->subsym[msp->nsubsym - 1] = Symbol_new(x); - } else { - ErrorMsg(psp->filename, psp->tokenlineno, - "%%token_class argument \"%s\" should be a token", x); - psp->errorcnt++; - psp->state = RESYNC_AFTER_DECL_ERROR; - } - break; - case RESYNC_AFTER_RULE_ERROR: - /* if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE; - ** break; */ - case RESYNC_AFTER_DECL_ERROR: - if (x[0] == '.') psp->state = WAITING_FOR_DECL_OR_RULE; - if (x[0] == '%') psp->state = WAITING_FOR_DECL_KEYWORD; - break; - } -} - -/* The text in the input is part of the argument to an %ifdef or %ifndef. -** Evaluate the text as a boolean expression. Return true or false. -*/ -static int eval_preprocessor_boolean(char *z, int lineno) { - int neg = 0; - int res = 0; - int okTerm = 1; - int i; - for (i = 0; z[i] != 0; i++) { - if (ISSPACE(z[i])) continue; - if (z[i] == '!') { - if (!okTerm) goto pp_syntax_error; - neg = !neg; - continue; - } - if (z[i] == '|' && z[i + 1] == '|') { - if (okTerm) goto pp_syntax_error; - if (res) return 1; - i++; - okTerm = 1; - continue; - } - if (z[i] == '&' && z[i + 1] == '&') { - if (okTerm) goto pp_syntax_error; - if (!res) return 0; - i++; - okTerm = 1; - continue; - } - if (z[i] == '(') { - int k; - int n = 1; - if (!okTerm) goto pp_syntax_error; - for (k = i + 1; z[k]; k++) { - if (z[k] == ')') { - n--; - if (n == 0) { - z[k] = 0; - res = eval_preprocessor_boolean(&z[i + 1], -1); - z[k] = ')'; - if (res < 0) { - i = i - res; - goto pp_syntax_error; - } - i = k; - break; - } - } else if (z[k] == '(') { - n++; - } else if (z[k] == 0) { - i = k; - goto pp_syntax_error; - } - } - if (neg) { - res = !res; - neg = 0; - } - okTerm = 0; - continue; - } - if (ISALPHA(z[i])) { - int j, k, n; - if (!okTerm) goto pp_syntax_error; - for (k = i + 1; ISALNUM(z[k]) || z[k] == '_'; k++) { - } - n = k - i; - res = 0; - for (j = 0; j < nDefine; j++) { - if (strncmp(azDefine[j], &z[i], n) == 0 && azDefine[j][n] == 0) { - res = 1; - break; - } - } - i = k - 1; - if (neg) { - res = !res; - neg = 0; - } - okTerm = 0; - continue; - } - goto pp_syntax_error; - } - return res; - -pp_syntax_error: - if (lineno > 0) { - fprintf(stderr, "%%if syntax error on line %d.\n", lineno); - fprintf(stderr, " %.*s <-- syntax error here\n", i + 1, z); - exit(1); - } else { - return -(i + 1); - } -} - -/* Run the preprocessor over the input file text. The global variables -** azDefine[0] through azDefine[nDefine-1] contains the names of all defined -** macros. This routine looks for "%ifdef" and "%ifndef" and "%endif" and -** comments them out. Text in between is also commented out as appropriate. -*/ -static void preprocess_input(char *z) { - int i, j, k; - int exclude = 0; - int start = 0; - int lineno = 1; - int start_lineno = 1; - for (i = 0; z[i]; i++) { - if (z[i] == '\n') lineno++; - if (z[i] != '%' || (i > 0 && z[i - 1] != '\n')) continue; - if (strncmp(&z[i], "%endif", 6) == 0 && ISSPACE(z[i + 6])) { - if (exclude) { - exclude--; - if (exclude == 0) { - for (j = start; j < i; j++) - if (z[j] != '\n') z[j] = ' '; - } - } - for (j = i; z[j] && z[j] != '\n'; j++) z[j] = ' '; - } else if (strncmp(&z[i], "%else", 5) == 0 && ISSPACE(z[i + 5])) { - if (exclude == 1) { - exclude = 0; - for (j = start; j < i; j++) - if (z[j] != '\n') z[j] = ' '; - } else if (exclude == 0) { - exclude = 1; - start = i; - start_lineno = lineno; - } - for (j = i; z[j] && z[j] != '\n'; j++) z[j] = ' '; - } else if (strncmp(&z[i], "%ifdef ", 7) == 0 || - strncmp(&z[i], "%if ", 4) == 0 || - strncmp(&z[i], "%ifndef ", 8) == 0) { - if (exclude) { - exclude++; - } else { - int isNot; - int iBool; - for (j = i; z[j] && !ISSPACE(z[j]); j++) { - } - iBool = j; - isNot = (j == i + 7); - while (z[j] && z[j] != '\n') { - j++; - } - k = z[j]; - z[j] = 0; - exclude = eval_preprocessor_boolean(&z[iBool], lineno); - z[j] = k; - if (!isNot) exclude = !exclude; - if (exclude) { - start = i; - start_lineno = lineno; - } - } - for (j = i; z[j] && z[j] != '\n'; j++) z[j] = ' '; - } - } - if (exclude) { - fprintf(stderr, "unterminated %%ifdef starting on line %d\n", start_lineno); - exit(1); - } -} - -/* In spite of its name, this function is really a scanner. It read -** in the entire input file (all at once) then tokenizes it. Each -** token is passed to the function "parseonetoken" which builds all -** the appropriate data structures in the global state vector "gp". -*/ -void Parse(struct lemon *gp) { - struct pstate *ps; - FILE *fp; - char *filebuf; - unsigned int filesize; - int lineno; - int c; - char *cp, *nextcp; - int startline = 0; - - ps = gc(xcalloc(1, sizeof(struct pstate))); - ps->gp = gp; - ps->filename = gp->filename; - ps->errorcnt = 0; - ps->state = INITIALIZE; - - /* Begin by reading the input file */ - fp = fopen(ps->filename, "rb"); - if (fp == 0) { - ErrorMsg(ps->filename, 0, "Can't open this file for reading."); - gp->errorcnt++; - return; - } - fseek(fp, 0, 2); - filesize = ftell(fp); - rewind(fp); - filebuf = (char *)malloc(filesize + 1); - if (filesize > 100000000 || filebuf == 0) { - ErrorMsg(ps->filename, 0, "Input file too large."); - free(filebuf); - gp->errorcnt++; - fclose(fp); - return; - } - if (fread(filebuf, 1, filesize, fp) != filesize) { - ErrorMsg(ps->filename, 0, "Can't read in all %d bytes of this file.", - filesize); - free(filebuf); - gp->errorcnt++; - fclose(fp); - return; - } - fclose(fp); - filebuf[filesize] = 0; - - /* Make an initial pass through the file to handle %ifdef and %ifndef */ - preprocess_input(filebuf); - if (gp->printPreprocessed) { - printf("%s\n", filebuf); - return; - } - - /* Now scan the text of the input file */ - lineno = 1; - for (cp = filebuf; (c = *cp) != 0;) { - if (c == '\n') lineno++; /* Keep track of the line number */ - if (ISSPACE(c)) { - cp++; - continue; - } /* Skip all white space */ - if (c == '/' && cp[1] == '/') { /* Skip C++ style comments */ - cp += 2; - while ((c = *cp) != 0 && c != '\n') cp++; - continue; - } - if (c == '/' && cp[1] == '*') { /* Skip C style comments */ - cp += 2; - while ((c = *cp) != 0 && (c != '/' || cp[-1] != '*')) { - if (c == '\n') lineno++; - cp++; - } - if (c) cp++; - continue; - } - ps->tokenstart = cp; /* Mark the beginning of the token */ - ps->tokenlineno = lineno; /* Linenumber on which token begins */ - if (c == '\"') { /* String literals */ - cp++; - while ((c = *cp) != 0 && c != '\"') { - if (c == '\n') lineno++; - cp++; - } - if (c == 0) { - ErrorMsg(ps->filename, startline, - "String starting on this line is not terminated before " - "the end of the file."); - ps->errorcnt++; - nextcp = cp; - } else { - nextcp = cp + 1; - } - } else if (c == '{') { /* A block of C code */ - int level; - cp++; - for (level = 1; (c = *cp) != 0 && (level > 1 || c != '}'); cp++) { - if (c == '\n') - lineno++; - else if (c == '{') - level++; - else if (c == '}') - level--; - else if (c == '/' && cp[1] == '*') { /* Skip comments */ - int prevc; - cp = &cp[2]; - prevc = 0; - while ((c = *cp) != 0 && (c != '/' || prevc != '*')) { - if (c == '\n') lineno++; - prevc = c; - cp++; - } - } else if (c == '/' && cp[1] == '/') { /* Skip C++ style comments too */ - cp = &cp[2]; - while ((c = *cp) != 0 && c != '\n') cp++; - if (c) lineno++; - } else if (c == '\'' || c == '\"') { /* String a character literals */ - int startchar, prevc; - startchar = c; - prevc = 0; - for (cp++; (c = *cp) != 0 && (c != startchar || prevc == '\\'); - cp++) { - if (c == '\n') lineno++; - if (prevc == '\\') - prevc = 0; - else - prevc = c; - } - } - } - if (c == 0) { - ErrorMsg(ps->filename, ps->tokenlineno, - "C code starting on this line is not terminated before " - "the end of the file."); - ps->errorcnt++; - nextcp = cp; - } else { - nextcp = cp + 1; - } - } else if (ISALNUM(c)) { /* Identifiers */ - while ((c = *cp) != 0 && (ISALNUM(c) || c == '_')) cp++; - nextcp = cp; - } else if (c == ':' && cp[1] == ':' && - cp[2] == '=') { /* The operator "::=" */ - cp += 3; - nextcp = cp; - } else if ((c == '/' || c == '|') && ISALPHA(cp[1])) { - cp += 2; - while ((c = *cp) != 0 && (ISALNUM(c) || c == '_')) cp++; - nextcp = cp; - } else { /* All other (one character) operators */ - cp++; - nextcp = cp; - } - c = *cp; - *cp = 0; /* Null terminate the token */ - parseonetoken(ps); /* Parse the token */ - *cp = (char)c; /* Restore the buffer */ - cp = nextcp; - } - free(filebuf); /* Release the buffer after parsing */ - gp->rule = ps->firstrule; - gp->errorcnt = ps->errorcnt; -} - -/*************************** From the file "plink.c" *********************/ -/* -** Routines processing configuration follow-set propagation links -** in the LEMON parser generator. -*/ -static struct plink *plink_freelist = 0; - -/* Allocate a new plink */ -struct plink *Plink_new(void) { - struct plink *newlink; - - if (plink_freelist == 0) { - int i; - int amt = 100; - plink_freelist = (struct plink *)calloc(amt, sizeof(struct plink)); - if (plink_freelist == 0) { - fprintf( - stderr, - "Unable to allocate memory for a new follow-set propagation link.\n"); - exit(1); - } - for (i = 0; i < amt - 1; i++) - plink_freelist[i].next = &plink_freelist[i + 1]; - plink_freelist[amt - 1].next = 0; - } - newlink = plink_freelist; - plink_freelist = plink_freelist->next; - return newlink; -} - -/* Add a plink to a plink list */ -void Plink_add(struct plink **plpp, struct config *cfp) { - struct plink *newlink; - newlink = Plink_new(); - newlink->next = *plpp; - *plpp = newlink; - newlink->cfp = cfp; -} - -/* Transfer every plink on the list "from" to the list "to" */ -void Plink_copy(struct plink **to, struct plink *from) { - struct plink *nextpl; - while (from) { - nextpl = from->next; - from->next = *to; - *to = from; - from = nextpl; - } -} - -/* Delete every plink on the list */ -void Plink_delete(struct plink *plp) { - struct plink *nextpl; - - while (plp) { - nextpl = plp->next; - plp->next = plink_freelist; - plink_freelist = plp; - plp = nextpl; - } -} - -/*********************** From the file "report.c" **************************/ -/* -** Procedures for generating reports and tables in the LEMON parser generator. -*/ - -/* Generate a filename with the given suffix. Space to hold the -** name comes from malloc() and must be freed by the calling -** function. -*/ -PRIVATE char *file_makename(struct lemon *lemp, const char *suffix) { - char *name; - char *cp; - char *filename = lemp->filename; - int sz; - - if (outputDir) { - cp = strrchr(filename, '/'); - if (cp) filename = cp + 1; - } - sz = lemonStrlen(filename); - sz += lemonStrlen(suffix); - if (outputDir) sz += lemonStrlen(outputDir) + 1; - sz += 5; - name = (char *)malloc(sz); - if (name == 0) { - fprintf(stderr, "Can't allocate space for a filename.\n"); - exit(1); - } - name[0] = 0; - if (outputDir) { - lemon_strcpy(name, outputDir); - lemon_strcat(name, "/"); - } - lemon_strcat(name, filename); - cp = strrchr(name, '.'); - if (cp) *cp = 0; - lemon_strcat(name, suffix); - return name; -} - -/* Open a file with a name based on the name of the input file, -** but with a different (specified) suffix, and return a pointer -** to the stream */ -PRIVATE FILE *file_open(struct lemon *lemp, const char *suffix, - const char *mode) { - FILE *fp; - - if (lemp->outname) free(lemp->outname); - lemp->outname = file_makename(lemp, suffix); - fp = fopen(lemp->outname, mode); - if (fp == 0 && *mode == 'w') { - fprintf(stderr, "Can't open file \"%s\".\n", lemp->outname); - lemp->errorcnt++; - return 0; - } - return fp; -} - -/* Print the text of a rule - */ -void rule_print(FILE *out, struct rule *rp) { - int i, j; - fprintf(out, "%s", rp->lhs->name); - /* if( rp->lhsalias ) fprintf(out,"(%s)",rp->lhsalias); */ - fprintf(out, " ::="); - for (i = 0; i < rp->nrhs; i++) { - struct symbol *sp = rp->rhs[i]; - if (sp->type == MULTITERMINAL) { - fprintf(out, " %s", sp->subsym[0]->name); - for (j = 1; j < sp->nsubsym; j++) { - fprintf(out, "|%s", sp->subsym[j]->name); - } - } else { - fprintf(out, " %s", sp->name); - } - /* if( rp->rhsalias[i] ) fprintf(out,"(%s)",rp->rhsalias[i]); */ - } -} - -/* Duplicate the input file without comments and without actions -** on rules */ -void Reprint(struct lemon *lemp) { - struct rule *rp; - struct symbol *sp; - int i, j, maxlen, len, ncolumns, skip; - printf("// Reprint of input file \"%s\".\n// Symbols:\n", lemp->filename); - maxlen = 10; - for (i = 0; i < lemp->nsymbol; i++) { - sp = lemp->symbols[i]; - len = lemonStrlen(sp->name); - if (len > maxlen) maxlen = len; - } - ncolumns = 76 / (maxlen + 5); - if (ncolumns < 1) ncolumns = 1; - skip = (lemp->nsymbol + ncolumns - 1) / ncolumns; - for (i = 0; i < skip; i++) { - printf("//"); - for (j = i; j < lemp->nsymbol; j += skip) { - sp = lemp->symbols[j]; - assert(sp->index == j); - printf(" %3d %-*.*s", j, maxlen, maxlen, sp->name); - } - printf("\n"); - } - for (rp = lemp->rule; rp; rp = rp->next) { - rule_print(stdout, rp); - printf("."); - if (rp->precsym) printf(" [%s]", rp->precsym->name); - /* if( rp->code ) printf("\n %s",rp->code); */ - printf("\n"); - } -} - -/* Print a single rule. - */ -void RulePrint(FILE *fp, struct rule *rp, int iCursor) { - struct symbol *sp; - int i, j; - fprintf(fp, "%s ::=", rp->lhs->name); - for (i = 0; i <= rp->nrhs; i++) { - if (i == iCursor) fprintf(fp, " *"); - if (i == rp->nrhs) break; - sp = rp->rhs[i]; - if (sp->type == MULTITERMINAL) { - fprintf(fp, " %s", sp->subsym[0]->name); - for (j = 1; j < sp->nsubsym; j++) { - fprintf(fp, "|%s", sp->subsym[j]->name); - } - } else { - fprintf(fp, " %s", sp->name); - } - } -} - -/* Print the rule for a configuration. - */ -void ConfigPrint(FILE *fp, struct config *cfp) { - RulePrint(fp, cfp->rp, cfp->dot); -} - -/* #define TEST */ -#if 0 -/* Print a set */ -PRIVATE void SetPrint(out,set,lemp) -FILE *out; -char *set; -struct lemon *lemp; -{ - int i; - char *spacer; - spacer = ""; - fprintf(out,"%12s[",""); - for(i=0; interminal; i++){ - if( SetFind(set,i) ){ - fprintf(out,"%s%s",spacer,lemp->symbols[i]->name); - spacer = " "; - } - } - fprintf(out,"]\n"); -} - -/* Print a plink chain */ -PRIVATE void PlinkPrint(out,plp,tag) -FILE *out; -struct plink *plp; -char *tag; -{ - while( plp ){ - fprintf(out,"%12s%s (state %2d) ","",tag,plp->cfp->stp->statenum); - ConfigPrint(out,plp->cfp); - fprintf(out,"\n"); - plp = plp->next; - } -} -#endif - -/* Print an action to the given file descriptor. Return FALSE if -** nothing was actually printed. -*/ -int PrintAction(struct action *ap, /* The action to print */ - FILE *fp, /* Print the action here */ - int indent /* Indent by this amount */ -) { - int result = 1; - switch (ap->type) { - case SHIFT: { - struct state *stp = ap->x.stp; - fprintf(fp, "%*s shift %-7d", indent, ap->sp->name, stp->statenum); - break; - } - case REDUCE: { - struct rule *rp = ap->x.rp; - fprintf(fp, "%*s reduce %-7d", indent, ap->sp->name, rp->iRule); - RulePrint(fp, rp, -1); - break; - } - case SHIFTREDUCE: { - struct rule *rp = ap->x.rp; - fprintf(fp, "%*s shift-reduce %-7d", indent, ap->sp->name, rp->iRule); - RulePrint(fp, rp, -1); - break; - } - case ACCEPT: - fprintf(fp, "%*s accept", indent, ap->sp->name); - break; - case ERROR: - fprintf(fp, "%*s error", indent, ap->sp->name); - break; - case SRCONFLICT: - case RRCONFLICT: - fprintf(fp, "%*s reduce %-7d ** Parsing conflict **", indent, - ap->sp->name, ap->x.rp->iRule); - break; - case SSCONFLICT: - fprintf(fp, "%*s shift %-7d ** Parsing conflict **", indent, - ap->sp->name, ap->x.stp->statenum); - break; - case SH_RESOLVED: - if (showPrecedenceConflict) { - fprintf(fp, "%*s shift %-7d -- dropped by precedence", indent, - ap->sp->name, ap->x.stp->statenum); - } else { - result = 0; - } - break; - case RD_RESOLVED: - if (showPrecedenceConflict) { - fprintf(fp, "%*s reduce %-7d -- dropped by precedence", indent, - ap->sp->name, ap->x.rp->iRule); - } else { - result = 0; - } - break; - case NOT_USED: - result = 0; - break; - } - if (result && ap->spOpt) { - fprintf(fp, " /* because %s==%s */", ap->sp->name, ap->spOpt->name); - } - return result; -} - -/* Generate the "*.out" log file */ -void ReportOutput(struct lemon *lemp) { - int i, n; - struct state *stp; - struct config *cfp; - struct action *ap; - struct rule *rp; - FILE *fp; - - fp = file_open(lemp, ".out", "wb"); - if (fp == 0) return; - for (i = 0; i < lemp->nxstate; i++) { - stp = lemp->sorted[i]; - fprintf(fp, "State %d:\n", stp->statenum); - if (lemp->basisflag) - cfp = stp->bp; - else - cfp = stp->cfp; - while (cfp) { - char buf[20]; - if (cfp->dot == cfp->rp->nrhs) { - lemon_sprintf(buf, "(%d)", cfp->rp->iRule); - fprintf(fp, " %5s ", buf); - } else { - fprintf(fp, " "); - } - ConfigPrint(fp, cfp); - fprintf(fp, "\n"); -#if 0 - SetPrint(fp,cfp->fws,lemp); - PlinkPrint(fp,cfp->fplp,"To "); - PlinkPrint(fp,cfp->bplp,"From"); -#endif - if (lemp->basisflag) - cfp = cfp->bp; - else - cfp = cfp->next; - } - fprintf(fp, "\n"); - for (ap = stp->ap; ap; ap = ap->next) { - if (PrintAction(ap, fp, 30)) fprintf(fp, "\n"); - } - fprintf(fp, "\n"); - } - fprintf(fp, "----------------------------------------------------\n"); - fprintf(fp, "Symbols:\n"); - fprintf(fp, "The first-set of non-terminals is shown after the name.\n\n"); - for (i = 0; i < lemp->nsymbol; i++) { - int j; - struct symbol *sp; - - sp = lemp->symbols[i]; - fprintf(fp, " %3d: %s", i, sp->name); - if (sp->type == NONTERMINAL) { - fprintf(fp, ":"); - if (sp->lambda) { - fprintf(fp, " "); - } - for (j = 0; j < lemp->nterminal; j++) { - if (sp->firstset && SetFind(sp->firstset, j)) { - fprintf(fp, " %s", lemp->symbols[j]->name); - } - } - } - if (sp->prec >= 0) fprintf(fp, " (precedence=%d)", sp->prec); - fprintf(fp, "\n"); - } - fprintf(fp, "----------------------------------------------------\n"); - fprintf(fp, "Syntax-only Symbols:\n"); - fprintf(fp, "The following symbols never carry semantic content.\n\n"); - for (i = n = 0; i < lemp->nsymbol; i++) { - int w; - struct symbol *sp = lemp->symbols[i]; - if (sp->bContent) continue; - w = (int)strlen(sp->name); - if (n > 0 && n + w > 75) { - fprintf(fp, "\n"); - n = 0; - } - if (n > 0) { - fprintf(fp, " "); - n++; - } - fprintf(fp, "%s", sp->name); - n += w; - } - if (n > 0) fprintf(fp, "\n"); - fprintf(fp, "----------------------------------------------------\n"); - fprintf(fp, "Rules:\n"); - for (rp = lemp->rule; rp; rp = rp->next) { - fprintf(fp, "%4d: ", rp->iRule); - rule_print(fp, rp); - fprintf(fp, "."); - if (rp->precsym) { - fprintf(fp, " [%s precedence=%d]", rp->precsym->name, rp->precsym->prec); - } - fprintf(fp, "\n"); - } - fclose(fp); - return; -} - -/* Search for the file "name" which is in the same directory as -** the exacutable */ -PRIVATE char *pathsearch(char *argv0, char *name, int modemask) { - const char *pathlist; - char *pathbufptr = 0; - char *pathbuf = 0; - char *path, *cp; - char c; - -#ifdef __WIN32__ - cp = strrchr(argv0, '\\'); -#else - cp = strrchr(argv0, '/'); -#endif - if (cp) { - c = *cp; - *cp = 0; - path = (char *)malloc(lemonStrlen(argv0) + lemonStrlen(name) + 2); - if (path) lemon_sprintf(path, "%s/%s", argv0, name); - *cp = c; - } else { - pathlist = getenv("PATH"); - if (pathlist == 0) pathlist = ".:/bin:/usr/bin"; - pathbuf = (char *)malloc(lemonStrlen(pathlist) + 1); - path = (char *)malloc(lemonStrlen(pathlist) + lemonStrlen(name) + 2); - if ((pathbuf != 0) && (path != 0)) { - pathbufptr = pathbuf; - lemon_strcpy(pathbuf, pathlist); - while (*pathbuf) { - cp = strchr(pathbuf, ':'); - if (cp == 0) cp = &pathbuf[lemonStrlen(pathbuf)]; - c = *cp; - *cp = 0; - lemon_sprintf(path, "%s/%s", pathbuf, name); - *cp = c; - if (c == 0) - pathbuf[0] = 0; - else - pathbuf = &cp[1]; - if (access(path, modemask) == 0) break; - } - } - free(pathbufptr); - } - return path; -} - -/* Given an action, compute the integer value for that action -** which is to be put in the action table of the generated machine. -** Return negative if no action should be generated. -*/ -PRIVATE int compute_action(struct lemon *lemp, struct action *ap) { - int act; - switch (ap->type) { - case SHIFT: - act = ap->x.stp->statenum; - break; - case SHIFTREDUCE: { - /* Since a SHIFT is inherient after a prior REDUCE, convert any - ** SHIFTREDUCE action with a nonterminal on the LHS into a simple - ** REDUCE action: */ - if (ap->sp->index >= lemp->nterminal) { - act = lemp->minReduce + ap->x.rp->iRule; - } else { - act = lemp->minShiftReduce + ap->x.rp->iRule; - } - break; - } - case REDUCE: - act = lemp->minReduce + ap->x.rp->iRule; - break; - case ERROR: - act = lemp->errAction; - break; - case ACCEPT: - act = lemp->accAction; - break; - default: - act = -1; - break; - } - return act; -} - -#define LINESIZE 1000 -/* The next cluster of routines are for reading the template file -** and writing the results to the generated parser */ -/* The first function transfers data from "in" to "out" until -** a line is seen which begins with "%%". The line number is -** tracked. -** -** if name!=0, then any word that begin with "Parse" is changed to -** begin with *name instead. -*/ -PRIVATE void tplt_xfer(char *name, FILE *in, FILE *out, int *lineno) { - int i, iStart; - char *line = gc(xmalloc(LINESIZE)); - while (fgets(line, LINESIZE, in) && (line[0] != '%' || line[1] != '%')) { - (*lineno)++; - iStart = 0; - if (name) { - for (i = 0; line[i]; i++) { - if (line[i] == 'P' && strncmp(&line[i], "Parse", 5) == 0 && - (i == 0 || !ISALPHA(line[i - 1]))) { - if (i > iStart) fprintf(out, "%.*s", i - iStart, &line[iStart]); - fprintf(out, "%s", name); - i += 4; - iStart = i + 1; - } - } - } - fprintf(out, "%s", &line[iStart]); - } -} - -/* Skip forward past the header of the template file to the first "%%" - */ -PRIVATE void tplt_skip_header(FILE *in, int *lineno) { - char *line = gc(xmalloc(LINESIZE)); - while (fgets(line, LINESIZE, in) && (line[0] != '%' || line[1] != '%')) { - (*lineno)++; - } -} - -/* The next function finds the template file and opens it, returning -** a pointer to the opened file. */ -PRIVATE FILE *tplt_open(struct lemon *lemp) { - static const char templatename[] = "third_party/lemon/lempar.c.txt"; - char *buf; - FILE *in; - char *tpltname; - char *toFree = 0; - char *cp; - - buf = gc(xmalloc(1000)); - - /* first, see if user specified a template filename on the command line. */ - if (user_templatename != 0) { - if (access(user_templatename, 004) == -1) { - fprintf(stderr, "Can't find the parser driver template file \"%s\".\n", - user_templatename); - lemp->errorcnt++; - return 0; - } - in = fopen(user_templatename, "rb"); - if (in == 0) { - fprintf(stderr, "Can't open the template file \"%s\".\n", - user_templatename); - lemp->errorcnt++; - return 0; - } - return in; - } - - cp = strrchr(lemp->filename, '.'); - if (cp) { - lemon_sprintf(buf, "%.*s.lt", (int)(cp - lemp->filename), lemp->filename); - } else { - lemon_sprintf(buf, "%s.lt", lemp->filename); - } - if (access(buf, 004) == 0) { - tpltname = buf; - } else if (access(templatename, 004) == 0) { - tpltname = templatename; - } else { - toFree = tpltname = pathsearch(lemp->argv0, templatename, 0); - } - if (tpltname == 0) { - fprintf(stderr, "Can't find the parser driver template file \"%s\".\n", - templatename); - lemp->errorcnt++; - return 0; - } - in = fopen(tpltname, "rb"); - if (in == 0) { - fprintf(stderr, "Can't open the template file \"%s\".\n", tpltname); - lemp->errorcnt++; - } - free(toFree); - return in; -} - -/* Print a #line directive line to the output file. */ -PRIVATE void tplt_linedir(FILE *out, int lineno, char *filename) { - fprintf(out, "#line %d \"", lineno); - while (*filename) { - if (*filename == '\\') putc('\\', out); - putc(*filename, out); - filename++; - } - fprintf(out, "\"\n"); -} - -/* Print a string to the file and keep the linenumber up to date */ -PRIVATE void tplt_print(FILE *out, struct lemon *lemp, char *str, int *lineno) { - if (str == 0) return; - while (*str) { - putc(*str, out); - if (*str == '\n') (*lineno)++; - str++; - } - if (str[-1] != '\n') { - putc('\n', out); - (*lineno)++; - } - if (!lemp->nolinenosflag) { - (*lineno)++; - tplt_linedir(out, *lineno, lemp->outname); - } - return; -} - -/* -** The following routine emits code for the destructor for the -** symbol sp -*/ -void emit_destructor_code(FILE *out, struct symbol *sp, struct lemon *lemp, - int *lineno) { - char *cp = 0; - - if (sp->type == TERMINAL) { - cp = lemp->tokendest; - if (cp == 0) return; - fprintf(out, "{\n"); - (*lineno)++; - } else if (sp->destructor) { - cp = sp->destructor; - fprintf(out, "{\n"); - (*lineno)++; - if (!lemp->nolinenosflag) { - (*lineno)++; - tplt_linedir(out, sp->destLineno, lemp->filename); - } - } else if (lemp->vardest) { - cp = lemp->vardest; - if (cp == 0) return; - fprintf(out, "{\n"); - (*lineno)++; - } else { - assert(0); /* Cannot happen */ - } - for (; *cp; cp++) { - if (*cp == '$' && cp[1] == '$') { - fprintf(out, "(yypminor->yy%d)", sp->dtnum); - cp++; - continue; - } - if (*cp == '\n') (*lineno)++; - fputc(*cp, out); - } - fprintf(out, "\n"); - (*lineno)++; - if (!lemp->nolinenosflag) { - (*lineno)++; - tplt_linedir(out, *lineno, lemp->outname); - } - fprintf(out, "}\n"); - (*lineno)++; - return; -} - -/* -** Return TRUE (non-zero) if the given symbol has a destructor. -*/ -int has_destructor(struct symbol *sp, struct lemon *lemp) { - int ret; - if (sp->type == TERMINAL) { - ret = lemp->tokendest != 0; - } else { - ret = lemp->vardest != 0 || sp->destructor != 0; - } - return ret; -} - -/* -** Append text to a dynamically allocated string. If zText is 0 then -** reset the string to be empty again. Always return the complete text -** of the string (which is overwritten with each call). -** -** n bytes of zText are stored. If n==0 then all of zText up to the first -** \000 terminator is stored. zText can contain up to two instances of -** %d. The values of p1 and p2 are written into the first and second -** %d. -** -** If n==-1, then the previous character is overwritten. -*/ -PRIVATE char *append_str(const char *zText, int n, int p1, int p2) { - static char empty[1] = {0}; - static char *z = 0; - static int alloced = 0; - static int used = 0; - int c; - char zInt[40]; - if (zText == 0) { - if (used == 0 && z != 0) z[0] = 0; - used = 0; - return z; - } - if (n <= 0) { - if (n < 0) { - used += n; - assert(used >= 0); - } - n = lemonStrlen(zText); - } - if ((int)(n + sizeof(zInt) * 2 + used) >= alloced) { - alloced = n + sizeof(zInt) * 2 + used + 200; - z = (char *)realloc(z, alloced); - } - if (z == 0) return empty; - while (n-- > 0) { - c = *(zText++); - if (c == '%' && n > 0 && zText[0] == 'd') { - lemon_sprintf(zInt, "%d", p1); - p1 = p2; - lemon_strcpy(&z[used], zInt); - used += lemonStrlen(&z[used]); - zText++; - n--; - } else { - z[used++] = (char)c; - } - } - z[used] = 0; - return z; -} - -/* -** Write and transform the rp->code string so that symbols are expanded. -** Populate the rp->codePrefix and rp->codeSuffix strings, as appropriate. -** -** Return 1 if the expanded code requires that "yylhsminor" local variable -** to be defined. -*/ -PRIVATE int translate_code(struct lemon *lemp, struct rule *rp) { - char *cp, *xp; - int i; - int rc = 0; /* True if yylhsminor is used */ - int dontUseRhs0 = 0; /* If true, use of left-most RHS label is illegal */ - const char *zSkip = 0; /* The zOvwrt comment within rp->code, or NULL */ - char lhsused = 0; /* True if the LHS element has been used */ - char lhsdirect; /* True if LHS writes directly into stack */ - char used[MAXRHS]; /* True for each RHS element which is used */ - char zLhs[50]; /* Convert the LHS symbol into this string */ - char zOvwrt[900]; /* Comment that to allow LHS to overwrite RHS */ - - for (i = 0; i < rp->nrhs; i++) used[i] = 0; - lhsused = 0; - - if (rp->code == 0) { - static const char newlinestr[2] = {'\n', '\0'}; - rp->code = newlinestr; - rp->line = rp->ruleline; - rp->noCode = 1; - } else { - rp->noCode = 0; - } - - if (rp->nrhs == 0) { - /* If there are no RHS symbols, then writing directly to the LHS is ok */ - lhsdirect = 1; - } else if (rp->rhsalias[0] == 0) { - /* The left-most RHS symbol has no value. LHS direct is ok. But - ** we have to call the distructor on the RHS symbol first. */ - lhsdirect = 1; - if (has_destructor(rp->rhs[0], lemp)) { - append_str(0, 0, 0, 0); - append_str(" yy_destructor(yypParser,%d,&yymsp[%d].minor);\n", 0, - rp->rhs[0]->index, 1 - rp->nrhs); - rp->codePrefix = Strsafe(append_str(0, 0, 0, 0)); - rp->noCode = 0; - } - } else if (rp->lhsalias == 0) { - /* There is no LHS value symbol. */ - lhsdirect = 1; - } else if (strcmp(rp->lhsalias, rp->rhsalias[0]) == 0) { - /* The LHS symbol and the left-most RHS symbol are the same, so - ** direct writing is allowed */ - lhsdirect = 1; - lhsused = 1; - used[0] = 1; - if (rp->lhs->dtnum != rp->rhs[0]->dtnum) { - ErrorMsg(lemp->filename, rp->ruleline, - "%s(%s) and %s(%s) share the same label but have " - "different datatypes.", - rp->lhs->name, rp->lhsalias, rp->rhs[0]->name, rp->rhsalias[0]); - lemp->errorcnt++; - } - } else { - lemon_sprintf(zOvwrt, "/*%s-overwrites-%s*/", rp->lhsalias, - rp->rhsalias[0]); - zSkip = strstr(rp->code, zOvwrt); - if (zSkip != 0) { - /* The code contains a special comment that indicates that it is safe - ** for the LHS label to overwrite left-most RHS label. */ - lhsdirect = 1; - } else { - lhsdirect = 0; - } - } - if (lhsdirect) { - sprintf(zLhs, "yymsp[%d].minor.yy%d", 1 - rp->nrhs, rp->lhs->dtnum); - } else { - rc = 1; - sprintf(zLhs, "yylhsminor.yy%d", rp->lhs->dtnum); - } - - append_str(0, 0, 0, 0); - - /* This const cast is wrong but harmless, if we're careful. */ - for (cp = (char *)rp->code; *cp; cp++) { - if (cp == zSkip) { - append_str(zOvwrt, 0, 0, 0); - cp += lemonStrlen(zOvwrt) - 1; - dontUseRhs0 = 1; - continue; - } - if (ISALPHA(*cp) && - (cp == rp->code || (!ISALNUM(cp[-1]) && cp[-1] != '_'))) { - char saved; - for (xp = &cp[1]; ISALNUM(*xp) || *xp == '_'; xp++) - ; - saved = *xp; - *xp = 0; - if (rp->lhsalias && strcmp(cp, rp->lhsalias) == 0) { - append_str(zLhs, 0, 0, 0); - cp = xp; - lhsused = 1; - } else { - for (i = 0; i < rp->nrhs; i++) { - if (rp->rhsalias[i] && strcmp(cp, rp->rhsalias[i]) == 0) { - if (i == 0 && dontUseRhs0) { - ErrorMsg(lemp->filename, rp->ruleline, - "Label %s used after '%s'.", rp->rhsalias[0], zOvwrt); - lemp->errorcnt++; - } else if (cp != rp->code && cp[-1] == '@') { - /* If the argument is of the form @X then substituted - ** the token number of X, not the value of X */ - append_str("yymsp[%d].major", -1, i - rp->nrhs + 1, 0); - } else { - struct symbol *sp = rp->rhs[i]; - int dtnum; - if (sp->type == MULTITERMINAL) { - dtnum = sp->subsym[0]->dtnum; - } else { - dtnum = sp->dtnum; - } - append_str("yymsp[%d].minor.yy%d", 0, i - rp->nrhs + 1, dtnum); - } - cp = xp; - used[i] = 1; - break; - } - } - } - *xp = saved; - } - append_str(cp, 1, 0, 0); - } /* End loop */ - - /* Main code generation completed */ - cp = append_str(0, 0, 0, 0); - if (cp && cp[0]) rp->code = Strsafe(cp); - append_str(0, 0, 0, 0); - - /* Check to make sure the LHS has been used */ - if (rp->lhsalias && !lhsused) { - ErrorMsg(lemp->filename, rp->ruleline, - "Label \"%s\" for \"%s(%s)\" is never used.", rp->lhsalias, - rp->lhs->name, rp->lhsalias); - lemp->errorcnt++; - } - - /* Generate destructor code for RHS minor values which are not referenced. - ** Generate error messages for unused labels and duplicate labels. - */ - for (i = 0; i < rp->nrhs; i++) { - if (rp->rhsalias[i]) { - if (i > 0) { - int j; - if (rp->lhsalias && strcmp(rp->lhsalias, rp->rhsalias[i]) == 0) { - ErrorMsg( - lemp->filename, rp->ruleline, - "%s(%s) has the same label as the LHS but is not the left-most " - "symbol on the RHS.", - rp->rhs[i]->name, rp->rhsalias[i]); - lemp->errorcnt++; - } - for (j = 0; j < i; j++) { - if (rp->rhsalias[j] && - strcmp(rp->rhsalias[j], rp->rhsalias[i]) == 0) { - ErrorMsg(lemp->filename, rp->ruleline, - "Label %s used for multiple symbols on the RHS of a rule.", - rp->rhsalias[i]); - lemp->errorcnt++; - break; - } - } - } - if (!used[i]) { - ErrorMsg(lemp->filename, rp->ruleline, - "Label %s for \"%s(%s)\" is never used.", rp->rhsalias[i], - rp->rhs[i]->name, rp->rhsalias[i]); - lemp->errorcnt++; - } - } else if (i > 0 && has_destructor(rp->rhs[i], lemp)) { - append_str(" yy_destructor(yypParser,%d,&yymsp[%d].minor);\n", 0, - rp->rhs[i]->index, i - rp->nrhs + 1); - } - } - - /* If unable to write LHS values directly into the stack, write the - ** saved LHS value now. */ - if (lhsdirect == 0) { - append_str(" yymsp[%d].minor.yy%d = ", 0, 1 - rp->nrhs, rp->lhs->dtnum); - append_str(zLhs, 0, 0, 0); - append_str(";\n", 0, 0, 0); - } - - /* Suffix code generation complete */ - cp = append_str(0, 0, 0, 0); - if (cp && cp[0]) { - rp->codeSuffix = Strsafe(cp); - rp->noCode = 0; - } - - return rc; -} - -/* -** Generate code which executes when the rule "rp" is reduced. Write -** the code to "out". Make sure lineno stays up-to-date. -*/ -PRIVATE void emit_code(FILE *out, struct rule *rp, struct lemon *lemp, - int *lineno) { - const char *cp; - - /* Setup code prior to the #line directive */ - if (rp->codePrefix && rp->codePrefix[0]) { - fprintf(out, "{%s", rp->codePrefix); - for (cp = rp->codePrefix; *cp; cp++) { - if (*cp == '\n') (*lineno)++; - } - } - - /* Generate code to do the reduce action */ - if (rp->code) { - if (!lemp->nolinenosflag) { - (*lineno)++; - tplt_linedir(out, rp->line, lemp->filename); - } - fprintf(out, "{%s", rp->code); - for (cp = rp->code; *cp; cp++) { - if (*cp == '\n') (*lineno)++; - } - fprintf(out, "}\n"); - (*lineno)++; - if (!lemp->nolinenosflag) { - (*lineno)++; - tplt_linedir(out, *lineno, lemp->outname); - } - } - - /* Generate breakdown code that occurs after the #line directive */ - if (rp->codeSuffix && rp->codeSuffix[0]) { - fprintf(out, "%s", rp->codeSuffix); - for (cp = rp->codeSuffix; *cp; cp++) { - if (*cp == '\n') (*lineno)++; - } - } - - if (rp->codePrefix) { - fprintf(out, "}\n"); - (*lineno)++; - } - - return; -} - -/* -** Print the definition of the union used for the parser's data stack. -** This union contains fields for every possible data type for tokens -** and nonterminals. In the process of computing and printing this -** union, also set the ".dtnum" field of every terminal and nonterminal -** symbol. -*/ -void print_stack_union( - FILE *out, /* The output stream */ - struct lemon *lemp, /* The main info structure for this parser */ - int *plineno, /* Pointer to the line number */ - int mhflag /* True if generating makeheaders output */ -) { - int lineno = *plineno; /* The line number of the output */ - char **types; /* A hash table of datatypes */ - int arraysize; /* Size of the "types" array */ - int maxdtlength; /* Maximum length of any ".datatype" field. */ - char *stddt; /* Standardized name for a datatype */ - int i, j; /* Loop counters */ - unsigned hash; /* For hashing the name of a type */ - const char *name; /* Name of the parser */ - - /* Allocate and initialize types[] and allocate stddt[] */ - arraysize = lemp->nsymbol * 2; - types = (char **)calloc(arraysize, sizeof(char *)); - if (types == 0) { - fprintf(stderr, "Out of memory.\n"); - exit(1); - } - for (i = 0; i < arraysize; i++) types[i] = 0; - maxdtlength = 0; - if (lemp->vartype) { - maxdtlength = lemonStrlen(lemp->vartype); - } - for (i = 0; i < lemp->nsymbol; i++) { - int len; - struct symbol *sp = lemp->symbols[i]; - if (sp->datatype == 0) continue; - len = lemonStrlen(sp->datatype); - if (len > maxdtlength) maxdtlength = len; - } - stddt = (char *)malloc(maxdtlength * 2 + 1); - if (stddt == 0) { - fprintf(stderr, "Out of memory.\n"); - exit(1); - } - - /* Build a hash table of datatypes. The ".dtnum" field of each symbol - ** is filled in with the hash index plus 1. A ".dtnum" value of 0 is - ** used for terminal symbols. If there is no %default_type defined then - ** 0 is also used as the .dtnum value for nonterminals which do not specify - ** a datatype using the %type directive. - */ - for (i = 0; i < lemp->nsymbol; i++) { - struct symbol *sp = lemp->symbols[i]; - char *cp; - if (sp == lemp->errsym) { - sp->dtnum = arraysize + 1; - continue; - } - if (sp->type != NONTERMINAL || (sp->datatype == 0 && lemp->vartype == 0)) { - sp->dtnum = 0; - continue; - } - cp = sp->datatype; - if (cp == 0) cp = lemp->vartype; - j = 0; - while (ISSPACE(*cp)) cp++; - while (*cp) stddt[j++] = *cp++; - while (j > 0 && ISSPACE(stddt[j - 1])) j--; - stddt[j] = 0; - if (lemp->tokentype && strcmp(stddt, lemp->tokentype) == 0) { - sp->dtnum = 0; - continue; - } - hash = 0; - for (j = 0; stddt[j]; j++) { - hash = hash * 53 + stddt[j]; - } - hash = (hash & 0x7fffffff) % arraysize; - while (types[hash]) { - if (strcmp(types[hash], stddt) == 0) { - sp->dtnum = hash + 1; - break; - } - hash++; - if (hash >= (unsigned)arraysize) hash = 0; - } - if (types[hash] == 0) { - sp->dtnum = hash + 1; - types[hash] = (char *)malloc(lemonStrlen(stddt) + 1); - if (types[hash] == 0) { - fprintf(stderr, "Out of memory.\n"); - exit(1); - } - lemon_strcpy(types[hash], stddt); - } - } - - /* Print out the definition of YYTOKENTYPE and YYMINORTYPE */ - name = lemp->name ? lemp->name : "Parse"; - lineno = *plineno; - if (mhflag) { - fprintf(out, "#if INTERFACE\n"); - lineno++; - } - fprintf(out, "#define %sTOKENTYPE %s\n", name, - lemp->tokentype ? lemp->tokentype : "void*"); - lineno++; - if (mhflag) { - fprintf(out, "#endif\n"); - lineno++; - } - fprintf(out, "typedef union {\n"); - lineno++; - fprintf(out, " int yyinit;\n"); - lineno++; - fprintf(out, " %sTOKENTYPE yy0;\n", name); - lineno++; - for (i = 0; i < arraysize; i++) { - if (types[i] == 0) continue; - fprintf(out, " %s yy%d;\n", types[i], i + 1); - lineno++; - free(types[i]); - } - if (lemp->errsym && lemp->errsym->useCnt) { - fprintf(out, " int yy%d;\n", lemp->errsym->dtnum); - lineno++; - } - free(stddt); - free(types); - fprintf(out, "} YYMINORTYPE;\n"); - lineno++; - *plineno = lineno; -} - -/* -** Return the name of a C datatype able to represent values between -** lwr and upr, inclusive. If pnByte!=NULL then also write the sizeof -** for that type (1, 2, or 4) into *pnByte. -*/ -static const char *minimum_size_type(int lwr, int upr, int *pnByte) { - const char *zType = "int"; - int nByte = 4; - if (lwr >= 0) { - if (upr <= 255) { - zType = "unsigned char"; - nByte = 1; - } else if (upr < 65535) { - zType = "unsigned short int"; - nByte = 2; - } else { - zType = "unsigned int"; - nByte = 4; - } - } else if (lwr >= -127 && upr <= 127) { - zType = "signed char"; - nByte = 1; - } else if (lwr >= -32767 && upr < 32767) { - zType = "short"; - nByte = 2; - } - if (pnByte) *pnByte = nByte; - return zType; -} - -/* -** Each state contains a set of token transaction and a set of -** nonterminal transactions. Each of these sets makes an instance -** of the following structure. An array of these structures is used -** to order the creation of entries in the yy_action[] table. -*/ -struct axset { - struct state *stp; /* A pointer to a state */ - int isTkn; /* True to use tokens. False for non-terminals */ - int nAction; /* Number of actions */ - int iOrder; /* Original order of action sets */ -}; - -/* -** Compare to axset structures for sorting purposes -*/ -static int axset_compare(const void *a, const void *b) { - struct axset *p1 = (struct axset *)a; - struct axset *p2 = (struct axset *)b; - int c; - c = p2->nAction - p1->nAction; - if (c == 0) { - c = p1->iOrder - p2->iOrder; - } - assert(c != 0 || p1 == p2); - return c; -} - -/* -** Write text on "out" that describes the rule "rp". -*/ -static void writeRuleText(FILE *out, struct rule *rp) { - int j; - fprintf(out, "%s ::=", rp->lhs->name); - for (j = 0; j < rp->nrhs; j++) { - struct symbol *sp = rp->rhs[j]; - if (sp->type != MULTITERMINAL) { - fprintf(out, " %s", sp->name); - } else { - int k; - fprintf(out, " %s", sp->subsym[0]->name); - for (k = 1; k < sp->nsubsym; k++) { - fprintf(out, "|%s", sp->subsym[k]->name); - } - } - } -} - -/* Generate C source code for the parser */ -void ReportTable(struct lemon *lemp, - int mhflag, /* Output in makeheaders format if true */ - int sqlFlag /* Generate the *.sql file too */ -) { - FILE *out, *in, *sql; - char *line = gc(xmalloc(LINESIZE)); - int lineno; - struct state *stp; - struct action *ap; - struct rule *rp; - struct acttab *pActtab; - int i, j, n, sz; - int nLookAhead; - int szActionType; /* sizeof(YYACTIONTYPE) */ - int szCodeType; /* sizeof(YYCODETYPE) */ - const char *name; - int mnTknOfst, mxTknOfst; - int mnNtOfst, mxNtOfst; - struct axset *ax; - char *prefix; - - lemp->minShiftReduce = lemp->nstate; - lemp->errAction = lemp->minShiftReduce + lemp->nrule; - lemp->accAction = lemp->errAction + 1; - lemp->noAction = lemp->accAction + 1; - lemp->minReduce = lemp->noAction + 1; - lemp->maxAction = lemp->minReduce + lemp->nrule; - - in = tplt_open(lemp); - if (in == 0) return; - out = file_open(lemp, ".c.inc", "wb"); - if (out == 0) { - fclose(in); - return; - } - if (sqlFlag == 0) { - sql = 0; - } else { - sql = file_open(lemp, ".sql", "wb"); - if (sql == 0) { - fclose(in); - fclose(out); - return; - } - fprintf(sql, "BEGIN;\n" - "CREATE TABLE symbol(\n" - " id INTEGER PRIMARY KEY,\n" - " name TEXT NOT NULL,\n" - " isTerminal BOOLEAN NOT NULL,\n" - " fallback INTEGER REFERENCES symbol" - " DEFERRABLE INITIALLY DEFERRED\n" - ");\n"); - for (i = 0; i < lemp->nsymbol; i++) { - fprintf(sql, - "INSERT INTO symbol(id,name,isTerminal,fallback)" - "VALUES(%d,'%s',%s", - i, lemp->symbols[i]->name, - i < lemp->nterminal ? "TRUE" : "FALSE"); - if (lemp->symbols[i]->fallback) { - fprintf(sql, ",%d);\n", lemp->symbols[i]->fallback->index); - } else { - fprintf(sql, ",NULL);\n"); - } - } - fprintf(sql, "CREATE TABLE rule(\n" - " ruleid INTEGER PRIMARY KEY,\n" - " lhs INTEGER REFERENCES symbol(id),\n" - " txt TEXT\n" - ");\n" - "CREATE TABLE rulerhs(\n" - " ruleid INTEGER REFERENCES rule(ruleid),\n" - " pos INTEGER,\n" - " sym INTEGER REFERENCES symbol(id)\n" - ");\n"); - for (i = 0, rp = lemp->rule; rp; rp = rp->next, i++) { - assert(i == rp->iRule); - fprintf(sql, "INSERT INTO rule(ruleid,lhs,txt)VALUES(%d,%d,'", rp->iRule, - rp->lhs->index); - writeRuleText(sql, rp); - fprintf(sql, "');\n"); - for (j = 0; j < rp->nrhs; j++) { - struct symbol *sp = rp->rhs[j]; - if (sp->type != MULTITERMINAL) { - fprintf(sql, "INSERT INTO rulerhs(ruleid,pos,sym)VALUES(%d,%d,%d);\n", - i, j, sp->index); - } else { - int k; - for (k = 0; k < sp->nsubsym; k++) { - fprintf(sql, - "INSERT INTO rulerhs(ruleid,pos,sym)VALUES(%d,%d,%d);\n", i, - j, sp->subsym[k]->index); - } - } - } - } - fprintf(sql, "COMMIT;\n"); - } - lineno = 1; - - fprintf( - out, - "/* This file is automatically generated by Lemon from input grammar\n" - "** source file \"%s\". */\n", - lemp->filename); - lineno += 2; - - /* The first %include directive begins with a C-language comment, - ** then skip over the header comment of the template file - */ - if (lemp->include == 0) lemp->include = ""; - for (i = 0; ISSPACE(lemp->include[i]); i++) { - if (lemp->include[i] == '\n') { - lemp->include += i + 1; - i = -1; - } - } - if (lemp->include[0] == '/') { - tplt_skip_header(in, &lineno); - } else { - tplt_xfer(lemp->name, in, out, &lineno); - } - - /* Generate the include code, if any */ - tplt_print(out, lemp, lemp->include, &lineno); - if (mhflag) { - char *incName = file_makename(lemp, ".h.inc"); - fprintf(out, "#include \"%s\"\n", incName); - lineno++; - free(incName); - } - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate #defines for all tokens */ - if (lemp->tokenprefix) - prefix = lemp->tokenprefix; - else - prefix = ""; - if (mhflag) { - fprintf(out, "#if INTERFACE\n"); - lineno++; - } else { - fprintf(out, "#ifndef %s%s\n", prefix, lemp->symbols[1]->name); - } - for (i = 1; i < lemp->nterminal; i++) { - fprintf(out, "#define %s%-30s %2d\n", prefix, lemp->symbols[i]->name, i); - lineno++; - } - fprintf(out, "#endif\n"); - lineno++; - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate the defines */ - fprintf(out, "#define YYCODETYPE %s\n", - minimum_size_type(0, lemp->nsymbol, &szCodeType)); - lineno++; - fprintf(out, "#define YYNOCODE %d\n", lemp->nsymbol); - lineno++; - fprintf(out, "#define YYACTIONTYPE %s\n", - minimum_size_type(0, lemp->maxAction, &szActionType)); - lineno++; - if (lemp->wildcard) { - fprintf(out, "#define YYWILDCARD %d\n", lemp->wildcard->index); - lineno++; - } - print_stack_union(out, lemp, &lineno, mhflag); - fprintf(out, "#ifndef YYSTACKDEPTH\n"); - lineno++; - if (lemp->stacksize) { - fprintf(out, "#define YYSTACKDEPTH %s\n", lemp->stacksize); - lineno++; - } else { - fprintf(out, "#define YYSTACKDEPTH 100\n"); - lineno++; - } - fprintf(out, "#endif\n"); - lineno++; - if (mhflag) { - fprintf(out, "#if INTERFACE\n"); - lineno++; - } - name = lemp->name ? lemp->name : "Parse"; - if (lemp->arg && lemp->arg[0]) { - i = lemonStrlen(lemp->arg); - while (i >= 1 && ISSPACE(lemp->arg[i - 1])) i--; - while (i >= 1 && (ISALNUM(lemp->arg[i - 1]) || lemp->arg[i - 1] == '_')) - i--; - fprintf(out, "#define %sARG_SDECL %s;\n", name, lemp->arg); - lineno++; - fprintf(out, "#define %sARG_PDECL ,%s\n", name, lemp->arg); - lineno++; - fprintf(out, "#define %sARG_PARAM ,%s\n", name, &lemp->arg[i]); - lineno++; - fprintf(out, "#define %sARG_FETCH %s=yypParser->%s;\n", name, lemp->arg, - &lemp->arg[i]); - lineno++; - fprintf(out, "#define %sARG_STORE yypParser->%s=%s;\n", name, &lemp->arg[i], - &lemp->arg[i]); - lineno++; - } else { - fprintf(out, "#define %sARG_SDECL\n", name); - lineno++; - fprintf(out, "#define %sARG_PDECL\n", name); - lineno++; - fprintf(out, "#define %sARG_PARAM\n", name); - lineno++; - fprintf(out, "#define %sARG_FETCH\n", name); - lineno++; - fprintf(out, "#define %sARG_STORE\n", name); - lineno++; - } - if (lemp->ctx && lemp->ctx[0]) { - i = lemonStrlen(lemp->ctx); - while (i >= 1 && ISSPACE(lemp->ctx[i - 1])) i--; - while (i >= 1 && (ISALNUM(lemp->ctx[i - 1]) || lemp->ctx[i - 1] == '_')) - i--; - fprintf(out, "#define %sCTX_SDECL %s;\n", name, lemp->ctx); - lineno++; - fprintf(out, "#define %sCTX_PDECL ,%s\n", name, lemp->ctx); - lineno++; - fprintf(out, "#define %sCTX_PARAM ,%s\n", name, &lemp->ctx[i]); - lineno++; - fprintf(out, "#define %sCTX_FETCH %s=yypParser->%s;\n", name, lemp->ctx, - &lemp->ctx[i]); - lineno++; - fprintf(out, "#define %sCTX_STORE yypParser->%s=%s;\n", name, &lemp->ctx[i], - &lemp->ctx[i]); - lineno++; - } else { - fprintf(out, "#define %sCTX_SDECL\n", name); - lineno++; - fprintf(out, "#define %sCTX_PDECL\n", name); - lineno++; - fprintf(out, "#define %sCTX_PARAM\n", name); - lineno++; - fprintf(out, "#define %sCTX_FETCH\n", name); - lineno++; - fprintf(out, "#define %sCTX_STORE\n", name); - lineno++; - } - if (mhflag) { - fprintf(out, "#endif\n"); - lineno++; - } - if (lemp->errsym && lemp->errsym->useCnt) { - fprintf(out, "#define YYERRORSYMBOL %d\n", lemp->errsym->index); - lineno++; - fprintf(out, "#define YYERRSYMDT yy%d\n", lemp->errsym->dtnum); - lineno++; - } - if (lemp->has_fallback) { - fprintf(out, "#define YYFALLBACK 1\n"); - lineno++; - } - - /* Compute the action table, but do not output it yet. The action - ** table must be computed before generating the YYNSTATE macro because - ** we need to know how many states can be eliminated. - */ - ax = (struct axset *)calloc(lemp->nxstate * 2, sizeof(ax[0])); - if (ax == 0) { - fprintf(stderr, "malloc failed\n"); - exit(1); - } - for (i = 0; i < lemp->nxstate; i++) { - stp = lemp->sorted[i]; - ax[i * 2].stp = stp; - ax[i * 2].isTkn = 1; - ax[i * 2].nAction = stp->nTknAct; - ax[i * 2 + 1].stp = stp; - ax[i * 2 + 1].isTkn = 0; - ax[i * 2 + 1].nAction = stp->nNtAct; - } - mxTknOfst = mnTknOfst = 0; - mxNtOfst = mnNtOfst = 0; - /* In an effort to minimize the action table size, use the heuristic - ** of placing the largest action sets first */ - for (i = 0; i < lemp->nxstate * 2; i++) ax[i].iOrder = i; - qsort(ax, lemp->nxstate * 2, sizeof(ax[0]), axset_compare); - pActtab = acttab_alloc(lemp->nsymbol, lemp->nterminal); - for (i = 0; i < lemp->nxstate * 2 && ax[i].nAction > 0; i++) { - stp = ax[i].stp; - if (ax[i].isTkn) { - for (ap = stp->ap; ap; ap = ap->next) { - int action; - if (ap->sp->index >= lemp->nterminal) continue; - action = compute_action(lemp, ap); - if (action < 0) continue; - acttab_action(pActtab, ap->sp->index, action); - } - stp->iTknOfst = acttab_insert(pActtab, 1); - if (stp->iTknOfst < mnTknOfst) mnTknOfst = stp->iTknOfst; - if (stp->iTknOfst > mxTknOfst) mxTknOfst = stp->iTknOfst; - } else { - for (ap = stp->ap; ap; ap = ap->next) { - int action; - if (ap->sp->index < lemp->nterminal) continue; - if (ap->sp->index == lemp->nsymbol) continue; - action = compute_action(lemp, ap); - if (action < 0) continue; - acttab_action(pActtab, ap->sp->index, action); - } - stp->iNtOfst = acttab_insert(pActtab, 0); - if (stp->iNtOfst < mnNtOfst) mnNtOfst = stp->iNtOfst; - if (stp->iNtOfst > mxNtOfst) mxNtOfst = stp->iNtOfst; - } -#if 0 /* Uncomment for a trace of how the yy_action[] table fills out */ - { int jj, nn; - for(jj=nn=0; jjnAction; jj++){ - if( pActtab->aAction[jj].action<0 ) nn++; - } - printf("%4d: State %3d %s n: %2d size: %5d freespace: %d\n", - i, stp->statenum, ax[i].isTkn ? "Token" : "Var ", - ax[i].nAction, pActtab->nAction, nn); - } -#endif - } - free(ax); - - /* Mark rules that are actually used for reduce actions after all - ** optimizations have been applied - */ - for (rp = lemp->rule; rp; rp = rp->next) rp->doesReduce = LEMON_FALSE; - for (i = 0; i < lemp->nxstate; i++) { - for (ap = lemp->sorted[i]->ap; ap; ap = ap->next) { - if (ap->type == REDUCE || ap->type == SHIFTREDUCE) { - ap->x.rp->doesReduce = 1; - } - } - } - - /* Finish rendering the constants now that the action table has - ** been computed */ - fprintf(out, "#define YYNSTATE %d\n", lemp->nxstate); - lineno++; - fprintf(out, "#define YYNRULE %d\n", lemp->nrule); - lineno++; - fprintf(out, "#define YYNRULE_WITH_ACTION %d\n", lemp->nruleWithAction); - lineno++; - fprintf(out, "#define YYNTOKEN %d\n", lemp->nterminal); - lineno++; - fprintf(out, "#define YY_MAX_SHIFT %d\n", lemp->nxstate - 1); - lineno++; - i = lemp->minShiftReduce; - fprintf(out, "#define YY_MIN_SHIFTREDUCE %d\n", i); - lineno++; - i += lemp->nrule; - fprintf(out, "#define YY_MAX_SHIFTREDUCE %d\n", i - 1); - lineno++; - fprintf(out, "#define YY_ERROR_ACTION %d\n", lemp->errAction); - lineno++; - fprintf(out, "#define YY_ACCEPT_ACTION %d\n", lemp->accAction); - lineno++; - fprintf(out, "#define YY_NO_ACTION %d\n", lemp->noAction); - lineno++; - fprintf(out, "#define YY_MIN_REDUCE %d\n", lemp->minReduce); - lineno++; - i = lemp->minReduce + lemp->nrule; - fprintf(out, "#define YY_MAX_REDUCE %d\n", i - 1); - lineno++; - tplt_xfer(lemp->name, in, out, &lineno); - - /* Now output the action table and its associates: - ** - ** yy_action[] A single table containing all actions. - ** yy_lookahead[] A table containing the lookahead for each entry in - ** yy_action. Used to detect hash collisions. - ** yy_shift_ofst[] For each state, the offset into yy_action for - ** shifting terminals. - ** yy_reduce_ofst[] For each state, the offset into yy_action for - ** shifting non-terminals after a reduce. - ** yy_default[] Default action for each state. - */ - - /* Output the yy_action table */ - lemp->nactiontab = n = acttab_action_size(pActtab); - lemp->tablesize += n * szActionType; - fprintf(out, "#define YY_ACTTAB_COUNT (%d)\n", n); - lineno++; - fprintf(out, "static const YYACTIONTYPE yy_action[] = {\n"); - lineno++; - for (i = j = 0; i < n; i++) { - int action = acttab_yyaction(pActtab, i); - if (action < 0) action = lemp->noAction; - if (j == 0) fprintf(out, " /* %5d */ ", i); - fprintf(out, " %4d,", action); - if (j == 9 || i == n - 1) { - fprintf(out, "\n"); - lineno++; - j = 0; - } else { - j++; - } - } - fprintf(out, "};\n"); - lineno++; - - /* Output the yy_lookahead table */ - lemp->nlookaheadtab = n = acttab_lookahead_size(pActtab); - lemp->tablesize += n * szCodeType; - fprintf(out, "static const YYCODETYPE yy_lookahead[] = {\n"); - lineno++; - for (i = j = 0; i < n; i++) { - int la = acttab_yylookahead(pActtab, i); - if (la < 0) la = lemp->nsymbol; - if (j == 0) fprintf(out, " /* %5d */ ", i); - fprintf(out, " %4d,", la); - if (j == 9) { - fprintf(out, "\n"); - lineno++; - j = 0; - } else { - j++; - } - } - /* Add extra entries to the end of the yy_lookahead[] table so that - ** yy_shift_ofst[]+iToken will always be a valid index into the array, - ** even for the largest possible value of yy_shift_ofst[] and iToken. */ - nLookAhead = lemp->nterminal + lemp->nactiontab; - while (i < nLookAhead) { - if (j == 0) fprintf(out, " /* %5d */ ", i); - fprintf(out, " %4d,", lemp->nterminal); - if (j == 9) { - fprintf(out, "\n"); - lineno++; - j = 0; - } else { - j++; - } - i++; - } - if (j > 0) { - fprintf(out, "\n"); - lineno++; - } - fprintf(out, "};\n"); - lineno++; - - /* Output the yy_shift_ofst[] table */ - n = lemp->nxstate; - while (n > 0 && lemp->sorted[n - 1]->iTknOfst == NO_OFFSET) n--; - fprintf(out, "#define YY_SHIFT_COUNT (%d)\n", n - 1); - lineno++; - fprintf(out, "#define YY_SHIFT_MIN (%d)\n", mnTknOfst); - lineno++; - fprintf(out, "#define YY_SHIFT_MAX (%d)\n", mxTknOfst); - lineno++; - fprintf( - out, "static const %s yy_shift_ofst[] = {\n", - minimum_size_type(mnTknOfst, lemp->nterminal + lemp->nactiontab, &sz)); - lineno++; - lemp->tablesize += n * sz; - for (i = j = 0; i < n; i++) { - int ofst; - stp = lemp->sorted[i]; - ofst = stp->iTknOfst; - if (ofst == NO_OFFSET) ofst = lemp->nactiontab; - if (j == 0) fprintf(out, " /* %5d */ ", i); - fprintf(out, " %4d,", ofst); - if (j == 9 || i == n - 1) { - fprintf(out, "\n"); - lineno++; - j = 0; - } else { - j++; - } - } - fprintf(out, "};\n"); - lineno++; - - /* Output the yy_reduce_ofst[] table */ - n = lemp->nxstate; - while (n > 0 && lemp->sorted[n - 1]->iNtOfst == NO_OFFSET) n--; - fprintf(out, "#define YY_REDUCE_COUNT (%d)\n", n - 1); - lineno++; - fprintf(out, "#define YY_REDUCE_MIN (%d)\n", mnNtOfst); - lineno++; - fprintf(out, "#define YY_REDUCE_MAX (%d)\n", mxNtOfst); - lineno++; - fprintf(out, "static const %s yy_reduce_ofst[] = {\n", - minimum_size_type(mnNtOfst - 1, mxNtOfst, &sz)); - lineno++; - lemp->tablesize += n * sz; - for (i = j = 0; i < n; i++) { - int ofst; - stp = lemp->sorted[i]; - ofst = stp->iNtOfst; - if (ofst == NO_OFFSET) ofst = mnNtOfst - 1; - if (j == 0) fprintf(out, " /* %5d */ ", i); - fprintf(out, " %4d,", ofst); - if (j == 9 || i == n - 1) { - fprintf(out, "\n"); - lineno++; - j = 0; - } else { - j++; - } - } - fprintf(out, "};\n"); - lineno++; - - /* Output the default action table */ - fprintf(out, "static const YYACTIONTYPE yy_default[] = {\n"); - lineno++; - n = lemp->nxstate; - lemp->tablesize += n * szActionType; - for (i = j = 0; i < n; i++) { - stp = lemp->sorted[i]; - if (j == 0) fprintf(out, " /* %5d */ ", i); - if (stp->iDfltReduce < 0) { - fprintf(out, " %4d,", lemp->errAction); - } else { - fprintf(out, " %4d,", stp->iDfltReduce + lemp->minReduce); - } - if (j == 9 || i == n - 1) { - fprintf(out, "\n"); - lineno++; - j = 0; - } else { - j++; - } - } - fprintf(out, "};\n"); - lineno++; - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate the table of fallback tokens. - */ - if (lemp->has_fallback) { - int mx = lemp->nterminal - 1; - /* 2019-08-28: Generate fallback entries for every token to avoid - ** having to do a range check on the index */ - /* while( mx>0 && lemp->symbols[mx]->fallback==0 ){ mx--; } */ - lemp->tablesize += (mx + 1) * szCodeType; - for (i = 0; i <= mx; i++) { - struct symbol *p = lemp->symbols[i]; - if (p->fallback == 0) { - fprintf(out, " 0, /* %10s => nothing */\n", p->name); - } else { - fprintf(out, " %3d, /* %10s => %s */\n", p->fallback->index, p->name, - p->fallback->name); - } - lineno++; - } - } - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate a table containing the symbolic name of every symbol - */ - for (i = 0; i < lemp->nsymbol; i++) { - lemon_sprintf(line, "\"%s\",", lemp->symbols[i]->name); - fprintf(out, " /* %4d */ \"%s\",\n", i, lemp->symbols[i]->name); - lineno++; - } - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate a table containing a text string that describes every - ** rule in the rule set of the grammar. This information is used - ** when tracing REDUCE actions. - */ - for (i = 0, rp = lemp->rule; rp; rp = rp->next, i++) { - assert(rp->iRule == i); - fprintf(out, " /* %3d */ \"", i); - writeRuleText(out, rp); - fprintf(out, "\",\n"); - lineno++; - } - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate code which executes every time a symbol is popped from - ** the stack while processing errors or while destroying the parser. - ** (In other words, generate the %destructor actions) - */ - if (lemp->tokendest) { - int once = 1; - for (i = 0; i < lemp->nsymbol; i++) { - struct symbol *sp = lemp->symbols[i]; - if (sp == 0 || sp->type != TERMINAL) continue; - if (once) { - fprintf(out, " /* TERMINAL Destructor */\n"); - lineno++; - once = 0; - } - fprintf(out, " case %d: /* %s */\n", sp->index, sp->name); - lineno++; - } - for (i = 0; i < lemp->nsymbol && lemp->symbols[i]->type != TERMINAL; i++) - ; - if (i < lemp->nsymbol) { - emit_destructor_code(out, lemp->symbols[i], lemp, &lineno); - fprintf(out, " break;\n"); - lineno++; - } - } - if (lemp->vardest) { - struct symbol *dflt_sp = 0; - int once = 1; - for (i = 0; i < lemp->nsymbol; i++) { - struct symbol *sp = lemp->symbols[i]; - if (sp == 0 || sp->type == TERMINAL || sp->index <= 0 || - sp->destructor != 0) - continue; - if (once) { - fprintf(out, " /* Default NON-TERMINAL Destructor */\n"); - lineno++; - once = 0; - } - fprintf(out, " case %d: /* %s */\n", sp->index, sp->name); - lineno++; - dflt_sp = sp; - } - if (dflt_sp != 0) { - emit_destructor_code(out, dflt_sp, lemp, &lineno); - } - fprintf(out, " break;\n"); - lineno++; - } - for (i = 0; i < lemp->nsymbol; i++) { - struct symbol *sp = lemp->symbols[i]; - if (sp == 0 || sp->type == TERMINAL || sp->destructor == 0) continue; - if (sp->destLineno < 0) continue; /* Already emitted */ - fprintf(out, " case %d: /* %s */\n", sp->index, sp->name); - lineno++; - - /* Combine duplicate destructors into a single case */ - for (j = i + 1; j < lemp->nsymbol; j++) { - struct symbol *sp2 = lemp->symbols[j]; - if (sp2 && sp2->type != TERMINAL && sp2->destructor && - sp2->dtnum == sp->dtnum && - strcmp(sp->destructor, sp2->destructor) == 0) { - fprintf(out, " case %d: /* %s */\n", sp2->index, sp2->name); - lineno++; - sp2->destLineno = -1; /* Avoid emitting this destructor again */ - } - } - - emit_destructor_code(out, lemp->symbols[i], lemp, &lineno); - fprintf(out, " break;\n"); - lineno++; - } - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate code which executes whenever the parser stack overflows */ - tplt_print(out, lemp, lemp->overflow, &lineno); - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate the tables of rule information. yyRuleInfoLhs[] and - ** yyRuleInfoNRhs[]. - ** - ** Note: This code depends on the fact that rules are number - ** sequentually beginning with 0. - */ - for (i = 0, rp = lemp->rule; rp; rp = rp->next, i++) { - fprintf(out, " %4d, /* (%d) ", rp->lhs->index, i); - rule_print(out, rp); - fprintf(out, " */\n"); - lineno++; - } - tplt_xfer(lemp->name, in, out, &lineno); - for (i = 0, rp = lemp->rule; rp; rp = rp->next, i++) { - fprintf(out, " %3d, /* (%d) ", -rp->nrhs, i); - rule_print(out, rp); - fprintf(out, " */\n"); - lineno++; - } - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate code which execution during each REDUCE action */ - i = 0; - for (rp = lemp->rule; rp; rp = rp->next) { - i += translate_code(lemp, rp); - } - if (i) { - fprintf(out, " YYMINORTYPE yylhsminor;\n"); - lineno++; - } - /* First output rules other than the default: rule */ - for (rp = lemp->rule; rp; rp = rp->next) { - struct rule *rp2; /* Other rules with the same action */ - if (rp->codeEmitted) continue; - if (rp->noCode) { - /* No C code actions, so this will be part of the "default:" rule */ - continue; - } - fprintf(out, " case %d: /* ", rp->iRule); - writeRuleText(out, rp); - fprintf(out, " */\n"); - lineno++; - for (rp2 = rp->next; rp2; rp2 = rp2->next) { - if (rp2->code == rp->code && rp2->codePrefix == rp->codePrefix && - rp2->codeSuffix == rp->codeSuffix) { - fprintf(out, " case %d: /* ", rp2->iRule); - writeRuleText(out, rp2); - fprintf(out, " */ yytestcase(yyruleno==%d);\n", rp2->iRule); - lineno++; - rp2->codeEmitted = 1; - } - } - emit_code(out, rp, lemp, &lineno); - fprintf(out, " break;\n"); - lineno++; - rp->codeEmitted = 1; - } - /* Finally, output the default: rule. We choose as the default: all - ** empty actions. */ - fprintf(out, " default:\n"); - lineno++; - for (rp = lemp->rule; rp; rp = rp->next) { - if (rp->codeEmitted) continue; - assert(rp->noCode); - fprintf(out, " /* (%d) ", rp->iRule); - writeRuleText(out, rp); - if (rp->neverReduce) { - fprintf(out, " (NEVER REDUCES) */ assert(yyruleno!=%d);\n", rp->iRule); - lineno++; - } else if (rp->doesReduce) { - fprintf(out, " */ yytestcase(yyruleno==%d);\n", rp->iRule); - lineno++; - } else { - fprintf(out, " (OPTIMIZED OUT) */ assert(yyruleno!=%d);\n", rp->iRule); - lineno++; - } - } - fprintf(out, " break;\n"); - lineno++; - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate code which executes if a parse fails */ - tplt_print(out, lemp, lemp->failure, &lineno); - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate code which executes when a syntax error occurs */ - tplt_print(out, lemp, lemp->error, &lineno); - tplt_xfer(lemp->name, in, out, &lineno); - - /* Generate code which executes when the parser accepts its input */ - tplt_print(out, lemp, lemp->accept, &lineno); - tplt_xfer(lemp->name, in, out, &lineno); - - /* Append any addition code the user desires */ - tplt_print(out, lemp, lemp->extracode, &lineno); - - acttab_free(pActtab); - fclose(in); - fclose(out); - if (sql) fclose(sql); - return; -} - -/* Generate a header file for the parser */ -void ReportHeader(struct lemon *lemp) { - FILE *out, *in; - const char *prefix; - char *line = gc(xmalloc(LINESIZE)); - char *pattern = gc(xmalloc(LINESIZE)); - int i; - - if (lemp->tokenprefix) - prefix = lemp->tokenprefix; - else - prefix = ""; - in = file_open(lemp, ".h.inc", "rb"); - if (in) { - int nextChar; - for (i = 1; i < lemp->nterminal && fgets(line, LINESIZE, in); i++) { - lemon_sprintf(pattern, "#define %s%-30s %3d\n", prefix, - lemp->symbols[i]->name, i); - if (strcmp(line, pattern)) break; - } - nextChar = fgetc(in); - fclose(in); - if (i == lemp->nterminal && nextChar == EOF) { - /* No change in the file. Don't rewrite it. */ - return; - } - } - out = file_open(lemp, ".h.inc", "wb"); - if (out) { - for (i = 1; i < lemp->nterminal; i++) { - fprintf(out, "#define %s%-30s %3d\n", prefix, lemp->symbols[i]->name, i); - } - fclose(out); - } - return; -} - -/* Reduce the size of the action tables, if possible, by making use -** of defaults. -** -** In this version, we take the most frequent REDUCE action and make -** it the default. Except, there is no default if the wildcard token -** is a possible look-ahead. -*/ -void CompressTables(struct lemon *lemp) { - struct state *stp; - struct action *ap, *ap2, *nextap; - struct rule *rp, *rp2, *rbest; - int nbest, n; - int i; - int usesWildcard; - - for (i = 0; i < lemp->nstate; i++) { - stp = lemp->sorted[i]; - nbest = 0; - rbest = 0; - usesWildcard = 0; - - for (ap = stp->ap; ap; ap = ap->next) { - if (ap->type == SHIFT && ap->sp == lemp->wildcard) { - usesWildcard = 1; - } - if (ap->type != REDUCE) continue; - rp = ap->x.rp; - if (rp->lhsStart) continue; - if (rp == rbest) continue; - n = 1; - for (ap2 = ap->next; ap2; ap2 = ap2->next) { - if (ap2->type != REDUCE) continue; - rp2 = ap2->x.rp; - if (rp2 == rbest) continue; - if (rp2 == rp) n++; - } - if (n > nbest) { - nbest = n; - rbest = rp; - } - } - - /* Do not make a default if the number of rules to default - ** is not at least 1 or if the wildcard token is a possible - ** lookahead. - */ - if (nbest < 1 || usesWildcard) continue; - - /* Combine matching REDUCE actions into a single default */ - for (ap = stp->ap; ap; ap = ap->next) { - if (ap->type == REDUCE && ap->x.rp == rbest) break; - } - assert(ap); - ap->sp = Symbol_new("{default}"); - for (ap = ap->next; ap; ap = ap->next) { - if (ap->type == REDUCE && ap->x.rp == rbest) ap->type = NOT_USED; - } - stp->ap = Action_sort(stp->ap); - - for (ap = stp->ap; ap; ap = ap->next) { - if (ap->type == SHIFT) break; - if (ap->type == REDUCE && ap->x.rp != rbest) break; - } - if (ap == 0) { - stp->autoReduce = 1; - stp->pDfltReduce = rbest; - } - } - - /* Make a second pass over all states and actions. Convert - ** every action that is a SHIFT to an autoReduce state into - ** a SHIFTREDUCE action. - */ - for (i = 0; i < lemp->nstate; i++) { - stp = lemp->sorted[i]; - for (ap = stp->ap; ap; ap = ap->next) { - struct state *pNextState; - if (ap->type != SHIFT) continue; - pNextState = ap->x.stp; - if (pNextState->autoReduce && pNextState->pDfltReduce != 0) { - ap->type = SHIFTREDUCE; - ap->x.rp = pNextState->pDfltReduce; - } - } - } - - /* If a SHIFTREDUCE action specifies a rule that has a single RHS term - ** (meaning that the SHIFTREDUCE will land back in the state where it - ** started) and if there is no C-code associated with the reduce action, - ** then we can go ahead and convert the action to be the same as the - ** action for the RHS of the rule. - */ - for (i = 0; i < lemp->nstate; i++) { - stp = lemp->sorted[i]; - for (ap = stp->ap; ap; ap = nextap) { - nextap = ap->next; - if (ap->type != SHIFTREDUCE) continue; - rp = ap->x.rp; - if (rp->noCode == 0) continue; - if (rp->nrhs != 1) continue; -#if 1 - /* Only apply this optimization to non-terminals. It would be OK to - ** apply it to terminal symbols too, but that makes the parser tables - ** larger. */ - if (ap->sp->index < lemp->nterminal) continue; -#endif - /* If we reach this point, it means the optimization can be applied */ - nextap = ap; - for (ap2 = stp->ap; ap2 && (ap2 == ap || ap2->sp != rp->lhs); - ap2 = ap2->next) { - } - assert(ap2 != 0); - ap->spOpt = ap2->sp; - ap->type = ap2->type; - ap->x = ap2->x; - } - } -} - -/* -** Compare two states for sorting purposes. The smaller state is the -** one with the most non-terminal actions. If they have the same number -** of non-terminal actions, then the smaller is the one with the most -** token actions. -*/ -static int stateResortCompare(const void *a, const void *b) { - const struct state *pA = *(const struct state **)a; - const struct state *pB = *(const struct state **)b; - int n; - - n = pB->nNtAct - pA->nNtAct; - if (n == 0) { - n = pB->nTknAct - pA->nTknAct; - if (n == 0) { - n = pB->statenum - pA->statenum; - } - } - assert(n != 0); - return n; -} - -/* -** Renumber and resort states so that states with fewer choices -** occur at the end. Except, keep state 0 as the first state. -*/ -void ResortStates(struct lemon *lemp) { - int i; - struct state *stp; - struct action *ap; - - for (i = 0; i < lemp->nstate; i++) { - stp = lemp->sorted[i]; - stp->nTknAct = stp->nNtAct = 0; - stp->iDfltReduce = -1; /* Init dflt action to "syntax error" */ - stp->iTknOfst = NO_OFFSET; - stp->iNtOfst = NO_OFFSET; - for (ap = stp->ap; ap; ap = ap->next) { - int iAction = compute_action(lemp, ap); - if (iAction >= 0) { - if (ap->sp->index < lemp->nterminal) { - stp->nTknAct++; - } else if (ap->sp->index < lemp->nsymbol) { - stp->nNtAct++; - } else { - assert(stp->autoReduce == 0 || stp->pDfltReduce == ap->x.rp); - stp->iDfltReduce = iAction; - } - } - } - } - qsort(&lemp->sorted[1], lemp->nstate - 1, sizeof(lemp->sorted[0]), - stateResortCompare); - for (i = 0; i < lemp->nstate; i++) { - lemp->sorted[i]->statenum = i; - } - lemp->nxstate = lemp->nstate; - while (lemp->nxstate > 1 && lemp->sorted[lemp->nxstate - 1]->autoReduce) { - lemp->nxstate--; - } -} - -/***************** From the file "set.c" ************************************/ -/* -** Set manipulation routines for the LEMON parser generator. -*/ - -static int size = 0; - -/* Set the set size */ -void SetSize(int n) { - size = n + 1; -} - -/* Allocate a new set */ -char *SetNew(void) { - char *s; - s = (char *)calloc(size, 1); - if (s == 0) { - memory_error(); - } - return s; -} - -/* Deallocate a set */ -void SetFree(char *s) { - free(s); -} - -/* Add a new element to the set. Return TRUE if the element was added -** and FALSE if it was already there. */ -int SetAdd(char *s, int e) { - int rv; - assert(e >= 0 && e < size); - rv = s[e]; - s[e] = 1; - return !rv; -} - -/* Add every element of s2 to s1. Return TRUE if s1 changes. */ -int SetUnion(char *s1, char *s2) { - int i, progress; - progress = 0; - for (i = 0; i < size; i++) { - if (s2[i] == 0) continue; - if (s1[i] == 0) { - progress = 1; - s1[i] = 1; - } - } - return progress; -} - -/********************** From the file "table.c" ****************************/ -/* -** All code in this file has been automatically generated -** from a specification in the file -** "table.q" -** by the associative array code building program "aagen". -** Do not edit this file! Instead, edit the specification -** file, then rerun aagen. -*/ -/* -** Code for processing tables in the LEMON parser generator. -*/ - -PRIVATE unsigned strhash(const char *x) { - unsigned h = 0; - while (*x) h = h * 13 + *(x++); - return h; -} - -/* Works like strdup, sort of. Save a string in malloced memory, but -** keep strings in a table so that the same string is not in more -** than one place. -*/ -const char *Strsafe(const char *y) { - const char *z; - char *cpy; - - if (y == 0) return 0; - z = Strsafe_find(y); - if (z == 0 && (cpy = (char *)malloc(lemonStrlen(y) + 1)) != 0) { - lemon_strcpy(cpy, y); - z = cpy; - Strsafe_insert(z); - } - MemoryCheck(z); - return z; -} - -/* There is one instance of the following structure for each -** associative array of type "x1". -*/ -struct s_x1 { - int size; /* The number of available slots. */ - /* Must be a power of 2 greater than or */ - /* equal to 1 */ - int count; /* Number of currently slots filled */ - struct s_x1node *tbl; /* The data stored here */ - struct s_x1node **ht; /* Hash table for lookups */ -}; - -/* There is one instance of this structure for every data element -** in an associative array of type "x1". -*/ -typedef struct s_x1node { - const char *data; /* The data */ - struct s_x1node *next; /* Next entry with the same hash */ - struct s_x1node **from; /* Previous link */ -} x1node; - -/* There is only one instance of the array, which is the following */ -static struct s_x1 *x1a; - -/* Allocate a new associative array */ -void Strsafe_init(void) { - if (x1a) return; - x1a = (struct s_x1 *)malloc(sizeof(struct s_x1)); - if (x1a) { - x1a->size = 1024; - x1a->count = 0; - x1a->tbl = (x1node *)calloc(1024, sizeof(x1node) + sizeof(x1node *)); - if (x1a->tbl == 0) { - free(x1a); - x1a = 0; - } else { - int i; - x1a->ht = (x1node **)&(x1a->tbl[1024]); - for (i = 0; i < 1024; i++) x1a->ht[i] = 0; - } - } -} -/* Insert a new record into the array. Return TRUE if successful. -** Prior data with the same key is NOT overwritten */ -int Strsafe_insert(const char *data) { - x1node *np; - unsigned h; - unsigned ph; - - if (x1a == 0) return 0; - ph = strhash(data); - h = ph & (x1a->size - 1); - np = x1a->ht[h]; - while (np) { - if (strcmp(np->data, data) == 0) { - /* An existing entry with the same key is found. */ - /* Fail because overwrite is not allows. */ - return 0; - } - np = np->next; - } - if (x1a->count >= x1a->size) { - /* Need to make the hash table bigger */ - int i, arrSize; - struct s_x1 array; - array.size = arrSize = x1a->size * 2; - array.count = x1a->count; - array.tbl = (x1node *)calloc(arrSize, sizeof(x1node) + sizeof(x1node *)); - if (array.tbl == 0) return 0; /* Fail due to malloc failure */ - array.ht = (x1node **)&(array.tbl[arrSize]); - for (i = 0; i < arrSize; i++) array.ht[i] = 0; - for (i = 0; i < x1a->count; i++) { - x1node *oldnp, *newnp; - oldnp = &(x1a->tbl[i]); - h = strhash(oldnp->data) & (arrSize - 1); - newnp = &(array.tbl[i]); - if (array.ht[h]) array.ht[h]->from = &(newnp->next); - newnp->next = array.ht[h]; - newnp->data = oldnp->data; - newnp->from = &(array.ht[h]); - array.ht[h] = newnp; - } - free(x1a->tbl); - *x1a = array; - } - /* Insert the new data */ - h = ph & (x1a->size - 1); - np = &(x1a->tbl[x1a->count++]); - np->data = data; - if (x1a->ht[h]) x1a->ht[h]->from = &(np->next); - np->next = x1a->ht[h]; - x1a->ht[h] = np; - np->from = &(x1a->ht[h]); - return 1; -} - -/* Return a pointer to data assigned to the given key. Return NULL -** if no such key. */ -const char *Strsafe_find(const char *key) { - unsigned h; - x1node *np; - - if (x1a == 0) return 0; - h = strhash(key) & (x1a->size - 1); - np = x1a->ht[h]; - while (np) { - if (strcmp(np->data, key) == 0) break; - np = np->next; - } - return np ? np->data : 0; -} - -/* Return a pointer to the (terminal or nonterminal) symbol "x". -** Create a new symbol if this is the first time "x" has been seen. -*/ -struct symbol *Symbol_new(const char *x) { - struct symbol *sp; - - sp = Symbol_find(x); - if (sp == 0) { - sp = (struct symbol *)calloc(1, sizeof(struct symbol)); - MemoryCheck(sp); - sp->name = Strsafe(x); - sp->type = ISUPPER(*x) ? TERMINAL : NONTERMINAL; - sp->rule = 0; - sp->fallback = 0; - sp->prec = -1; - sp->assoc = UNK; - sp->firstset = 0; - sp->lambda = LEMON_FALSE; - sp->destructor = 0; - sp->destLineno = 0; - sp->datatype = 0; - sp->useCnt = 0; - Symbol_insert(sp, sp->name); - } - sp->useCnt++; - return sp; -} - -/* Compare two symbols for sorting purposes. Return negative, -** zero, or positive if a is less then, equal to, or greater -** than b. -** -** Symbols that begin with upper case letters (terminals or tokens) -** must sort before symbols that begin with lower case letters -** (non-terminals). And MULTITERMINAL symbols (created using the -** %token_class directive) must sort at the very end. Other than -** that, the order does not matter. -** -** We find experimentally that leaving the symbols in their original -** order (the order they appeared in the grammar file) gives the -** smallest parser tables in SQLite. -*/ -int Symbolcmpp(const void *_a, const void *_b) { - const struct symbol *a = *(const struct symbol **)_a; - const struct symbol *b = *(const struct symbol **)_b; - int i1 = a->type == MULTITERMINAL ? 3 : a->name[0] > 'Z' ? 2 : 1; - int i2 = b->type == MULTITERMINAL ? 3 : b->name[0] > 'Z' ? 2 : 1; - return i1 == i2 ? a->index - b->index : i1 - i2; -} - -/* There is one instance of the following structure for each -** associative array of type "x2". -*/ -struct s_x2 { - int size; /* The number of available slots. */ - /* Must be a power of 2 greater than or */ - /* equal to 1 */ - int count; /* Number of currently slots filled */ - struct s_x2node *tbl; /* The data stored here */ - struct s_x2node **ht; /* Hash table for lookups */ -}; - -/* There is one instance of this structure for every data element -** in an associative array of type "x2". -*/ -typedef struct s_x2node { - struct symbol *data; /* The data */ - const char *key; /* The key */ - struct s_x2node *next; /* Next entry with the same hash */ - struct s_x2node **from; /* Previous link */ -} x2node; - -/* There is only one instance of the array, which is the following */ -static struct s_x2 *x2a; - -/* Allocate a new associative array */ -void Symbol_init(void) { - if (x2a) return; - x2a = (struct s_x2 *)malloc(sizeof(struct s_x2)); - if (x2a) { - x2a->size = 128; - x2a->count = 0; - x2a->tbl = (x2node *)calloc(128, sizeof(x2node) + sizeof(x2node *)); - if (x2a->tbl == 0) { - free(x2a); - x2a = 0; - } else { - int i; - x2a->ht = (x2node **)&(x2a->tbl[128]); - for (i = 0; i < 128; i++) x2a->ht[i] = 0; - } - } -} -/* Insert a new record into the array. Return TRUE if successful. -** Prior data with the same key is NOT overwritten */ -int Symbol_insert(struct symbol *data, const char *key) { - x2node *np; - unsigned h; - unsigned ph; - - if (x2a == 0) return 0; - ph = strhash(key); - h = ph & (x2a->size - 1); - np = x2a->ht[h]; - while (np) { - if (strcmp(np->key, key) == 0) { - /* An existing entry with the same key is found. */ - /* Fail because overwrite is not allows. */ - return 0; - } - np = np->next; - } - if (x2a->count >= x2a->size) { - /* Need to make the hash table bigger */ - int i, arrSize; - struct s_x2 array; - array.size = arrSize = x2a->size * 2; - array.count = x2a->count; - array.tbl = (x2node *)calloc(arrSize, sizeof(x2node) + sizeof(x2node *)); - if (array.tbl == 0) return 0; /* Fail due to malloc failure */ - array.ht = (x2node **)&(array.tbl[arrSize]); - for (i = 0; i < arrSize; i++) array.ht[i] = 0; - for (i = 0; i < x2a->count; i++) { - x2node *oldnp, *newnp; - oldnp = &(x2a->tbl[i]); - h = strhash(oldnp->key) & (arrSize - 1); - newnp = &(array.tbl[i]); - if (array.ht[h]) array.ht[h]->from = &(newnp->next); - newnp->next = array.ht[h]; - newnp->key = oldnp->key; - newnp->data = oldnp->data; - newnp->from = &(array.ht[h]); - array.ht[h] = newnp; - } - free(x2a->tbl); - *x2a = array; - } - /* Insert the new data */ - h = ph & (x2a->size - 1); - np = &(x2a->tbl[x2a->count++]); - np->key = key; - np->data = data; - if (x2a->ht[h]) x2a->ht[h]->from = &(np->next); - np->next = x2a->ht[h]; - x2a->ht[h] = np; - np->from = &(x2a->ht[h]); - return 1; -} - -/* Return a pointer to data assigned to the given key. Return NULL -** if no such key. */ -struct symbol *Symbol_find(const char *key) { - unsigned h; - x2node *np; - - if (x2a == 0) return 0; - h = strhash(key) & (x2a->size - 1); - np = x2a->ht[h]; - while (np) { - if (strcmp(np->key, key) == 0) break; - np = np->next; - } - return np ? np->data : 0; -} - -/* Return the n-th data. Return NULL if n is out of range. */ -struct symbol *Symbol_Nth(int n) { - struct symbol *data; - if (x2a && n > 0 && n <= x2a->count) { - data = x2a->tbl[n - 1].data; - } else { - data = 0; - } - return data; -} - -/* Return the size of the array */ -int Symbol_count() { - return x2a ? x2a->count : 0; -} - -/* Return an array of pointers to all data in the table. -** The array is obtained from malloc. Return NULL if memory allocation -** problems, or if the array is empty. */ -struct symbol **Symbol_arrayof() { - struct symbol **array; - int i, arrSize; - if (x2a == 0) return 0; - arrSize = x2a->count; - array = (struct symbol **)calloc(arrSize, sizeof(struct symbol *)); - if (array) { - for (i = 0; i < arrSize; i++) array[i] = x2a->tbl[i].data; - } - return array; -} - -/* Compare two configurations */ -int Configcmp(const char *_a, const char *_b) { - const struct config *a = (struct config *)_a; - const struct config *b = (struct config *)_b; - int x; - x = a->rp->index - b->rp->index; - if (x == 0) x = a->dot - b->dot; - return x; -} - -/* Compare two states */ -PRIVATE int statecmp(struct config *a, struct config *b) { - int rc; - for (rc = 0; rc == 0 && a && b; a = a->bp, b = b->bp) { - rc = a->rp->index - b->rp->index; - if (rc == 0) rc = a->dot - b->dot; - } - if (rc == 0) { - if (a) rc = 1; - if (b) rc = -1; - } - return rc; -} - -/* Hash a state */ -PRIVATE unsigned statehash(struct config *a) { - unsigned h = 0; - while (a) { - h = h * 571 + a->rp->index * 37 + a->dot; - a = a->bp; - } - return h; -} - -/* Allocate a new state structure */ -struct state *State_new() { - struct state *newstate; - newstate = (struct state *)calloc(1, sizeof(struct state)); - MemoryCheck(newstate); - return newstate; -} - -/* There is one instance of the following structure for each -** associative array of type "x3". -*/ -struct s_x3 { - int size; /* The number of available slots. */ - /* Must be a power of 2 greater than or */ - /* equal to 1 */ - int count; /* Number of currently slots filled */ - struct s_x3node *tbl; /* The data stored here */ - struct s_x3node **ht; /* Hash table for lookups */ -}; - -/* There is one instance of this structure for every data element -** in an associative array of type "x3". -*/ -typedef struct s_x3node { - struct state *data; /* The data */ - struct config *key; /* The key */ - struct s_x3node *next; /* Next entry with the same hash */ - struct s_x3node **from; /* Previous link */ -} x3node; - -/* There is only one instance of the array, which is the following */ -static struct s_x3 *x3a; - -/* Allocate a new associative array */ -void State_init(void) { - if (x3a) return; - x3a = (struct s_x3 *)malloc(sizeof(struct s_x3)); - if (x3a) { - x3a->size = 128; - x3a->count = 0; - x3a->tbl = (x3node *)calloc(128, sizeof(x3node) + sizeof(x3node *)); - if (x3a->tbl == 0) { - free(x3a); - x3a = 0; - } else { - int i; - x3a->ht = (x3node **)&(x3a->tbl[128]); - for (i = 0; i < 128; i++) x3a->ht[i] = 0; - } - } -} -/* Insert a new record into the array. Return TRUE if successful. -** Prior data with the same key is NOT overwritten */ -int State_insert(struct state *data, struct config *key) { - x3node *np; - unsigned h; - unsigned ph; - - if (x3a == 0) return 0; - ph = statehash(key); - h = ph & (x3a->size - 1); - np = x3a->ht[h]; - while (np) { - if (statecmp(np->key, key) == 0) { - /* An existing entry with the same key is found. */ - /* Fail because overwrite is not allows. */ - return 0; - } - np = np->next; - } - if (x3a->count >= x3a->size) { - /* Need to make the hash table bigger */ - int i, arrSize; - struct s_x3 array; - array.size = arrSize = x3a->size * 2; - array.count = x3a->count; - array.tbl = (x3node *)calloc(arrSize, sizeof(x3node) + sizeof(x3node *)); - if (array.tbl == 0) return 0; /* Fail due to malloc failure */ - array.ht = (x3node **)&(array.tbl[arrSize]); - for (i = 0; i < arrSize; i++) array.ht[i] = 0; - for (i = 0; i < x3a->count; i++) { - x3node *oldnp, *newnp; - oldnp = &(x3a->tbl[i]); - h = statehash(oldnp->key) & (arrSize - 1); - newnp = &(array.tbl[i]); - if (array.ht[h]) array.ht[h]->from = &(newnp->next); - newnp->next = array.ht[h]; - newnp->key = oldnp->key; - newnp->data = oldnp->data; - newnp->from = &(array.ht[h]); - array.ht[h] = newnp; - } - free(x3a->tbl); - *x3a = array; - } - /* Insert the new data */ - h = ph & (x3a->size - 1); - np = &(x3a->tbl[x3a->count++]); - np->key = key; - np->data = data; - if (x3a->ht[h]) x3a->ht[h]->from = &(np->next); - np->next = x3a->ht[h]; - x3a->ht[h] = np; - np->from = &(x3a->ht[h]); - return 1; -} - -/* Return a pointer to data assigned to the given key. Return NULL -** if no such key. */ -struct state *State_find(struct config *key) { - unsigned h; - x3node *np; - - if (x3a == 0) return 0; - h = statehash(key) & (x3a->size - 1); - np = x3a->ht[h]; - while (np) { - if (statecmp(np->key, key) == 0) break; - np = np->next; - } - return np ? np->data : 0; -} - -/* Return an array of pointers to all data in the table. -** The array is obtained from malloc. Return NULL if memory allocation -** problems, or if the array is empty. */ -struct state **State_arrayof(void) { - struct state **array; - int i, arrSize; - if (x3a == 0) return 0; - arrSize = x3a->count; - array = (struct state **)calloc(arrSize, sizeof(struct state *)); - if (array) { - for (i = 0; i < arrSize; i++) array[i] = x3a->tbl[i].data; - } - return array; -} - -/* Hash a configuration */ -PRIVATE unsigned confighash(struct config *a) { - unsigned h = 0; - h = h * 571 + a->rp->index * 37 + a->dot; - return h; -} - -/* There is one instance of the following structure for each -** associative array of type "x4". -*/ -struct s_x4 { - int size; /* The number of available slots. */ - /* Must be a power of 2 greater than or */ - /* equal to 1 */ - int count; /* Number of currently slots filled */ - struct s_x4node *tbl; /* The data stored here */ - struct s_x4node **ht; /* Hash table for lookups */ -}; - -/* There is one instance of this structure for every data element -** in an associative array of type "x4". -*/ -typedef struct s_x4node { - struct config *data; /* The data */ - struct s_x4node *next; /* Next entry with the same hash */ - struct s_x4node **from; /* Previous link */ -} x4node; - -/* There is only one instance of the array, which is the following */ -static struct s_x4 *x4a; - -/* Allocate a new associative array */ -void Configtable_init(void) { - if (x4a) return; - x4a = (struct s_x4 *)malloc(sizeof(struct s_x4)); - if (x4a) { - x4a->size = 64; - x4a->count = 0; - x4a->tbl = (x4node *)calloc(64, sizeof(x4node) + sizeof(x4node *)); - if (x4a->tbl == 0) { - free(x4a); - x4a = 0; - } else { - int i; - x4a->ht = (x4node **)&(x4a->tbl[64]); - for (i = 0; i < 64; i++) x4a->ht[i] = 0; - } - } -} -/* Insert a new record into the array. Return TRUE if successful. -** Prior data with the same key is NOT overwritten */ -int Configtable_insert(struct config *data) { - x4node *np; - unsigned h; - unsigned ph; - - if (x4a == 0) return 0; - ph = confighash(data); - h = ph & (x4a->size - 1); - np = x4a->ht[h]; - while (np) { - if (Configcmp((const char *)np->data, (const char *)data) == 0) { - /* An existing entry with the same key is found. */ - /* Fail because overwrite is not allows. */ - return 0; - } - np = np->next; - } - if (x4a->count >= x4a->size) { - /* Need to make the hash table bigger */ - int i, arrSize; - struct s_x4 array; - array.size = arrSize = x4a->size * 2; - array.count = x4a->count; - array.tbl = (x4node *)calloc(arrSize, sizeof(x4node) + sizeof(x4node *)); - if (array.tbl == 0) return 0; /* Fail due to malloc failure */ - array.ht = (x4node **)&(array.tbl[arrSize]); - for (i = 0; i < arrSize; i++) array.ht[i] = 0; - for (i = 0; i < x4a->count; i++) { - x4node *oldnp, *newnp; - oldnp = &(x4a->tbl[i]); - h = confighash(oldnp->data) & (arrSize - 1); - newnp = &(array.tbl[i]); - if (array.ht[h]) array.ht[h]->from = &(newnp->next); - newnp->next = array.ht[h]; - newnp->data = oldnp->data; - newnp->from = &(array.ht[h]); - array.ht[h] = newnp; - } - free(x4a->tbl); - *x4a = array; - } - /* Insert the new data */ - h = ph & (x4a->size - 1); - np = &(x4a->tbl[x4a->count++]); - np->data = data; - if (x4a->ht[h]) x4a->ht[h]->from = &(np->next); - np->next = x4a->ht[h]; - x4a->ht[h] = np; - np->from = &(x4a->ht[h]); - return 1; -} - -/* Return a pointer to data assigned to the given key. Return NULL -** if no such key. */ -struct config *Configtable_find(struct config *key) { - int h; - x4node *np; - - if (x4a == 0) return 0; - h = confighash(key) & (x4a->size - 1); - np = x4a->ht[h]; - while (np) { - if (Configcmp((const char *)np->data, (const char *)key) == 0) break; - np = np->next; - } - return np ? np->data : 0; -} - -/* Remove all data from the table. Pass each data to the function "f" -** as it is removed. ("f" may be null to avoid this step.) */ -void Configtable_clear(int (*f)(struct config *)) { - int i; - if (x4a == 0 || x4a->count == 0) return; - if (f) - for (i = 0; i < x4a->count; i++) (*f)(x4a->tbl[i].data); - for (i = 0; i < x4a->size; i++) x4a->ht[i] = 0; - x4a->count = 0; - return; -} diff --git a/third_party/lemon/lemon.mk b/third_party/lemon/lemon.mk deleted file mode 100644 index 3de296d05..000000000 --- a/third_party/lemon/lemon.mk +++ /dev/null @@ -1,61 +0,0 @@ -#-*-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───────────────────────┘ - -PKGS += THIRD_PARTY_LEMON -THIRD_PARTY_LEMON_FILES := $(wildcard third_party/lemon/*) -THIRD_PARTY_LEMON_HDRS = $(filter %.h,$(THIRD_PARTY_LEMON_FILES)) -THIRD_PARTY_LEMON_INCS = $(filter %.inc,$(THIRD_PARTY_LEMON_FILES)) -THIRD_PARTY_LEMON_SRCS = $(filter %.c,$(THIRD_PARTY_LEMON_FILES)) - -LEMON = $(MKDIR) $(@D) && ACTION="LEMON $@" build/do $(THIRD_PARTY_LEMON) - -THIRD_PARTY_LEMON = o/$(MODE)/third_party/lemon/lemon.com.dbg - -THIRD_PARTY_LEMON_OBJS = \ - o/$(MODE)/third_party/lemon/lemon.o \ - o/$(MODE)/third_party/lemon/lempar.c.txt.zip.o - -THIRD_PARTY_LEMON_COMS = \ - o/$(MODE)/third_party/lemon/lemon.com - -THIRD_PARTY_LEMON_LINK = \ - $(THIRD_PARTY_LEMON_DEPS) \ - o/$(MODE)/third_party/lemon/%.o \ - $(CRT) \ - $(APE) - -THIRD_PARTY_LEMON_DIRECTDEPS = \ - LIBC_ALG \ - LIBC_CALLS \ - LIBC_FMT \ - LIBC_INTRIN \ - LIBC_MEM \ - LIBC_NEXGEN32E \ - LIBC_RUNTIME \ - LIBC_STDIO \ - LIBC_STR \ - LIBC_STUBS \ - LIBC_UNICODE \ - LIBC_X \ - LIBC_ZIPOS \ - THIRD_PARTY_GDTOA - -THIRD_PARTY_LEMON_DEPS := \ - $(call uniq,$(foreach x,$(THIRD_PARTY_LEMON_DIRECTDEPS),$($(x)))) - -o/$(MODE)/third_party/lemon/lemon.pkg: \ - $(THIRD_PARTY_LEMON_OBJS) \ - $(foreach x,$(THIRD_PARTY_LEMON_DIRECTDEPS),$($(x)_A).pkg) - -o/$(MODE)/third_party/lemon/lemon.com.dbg: \ - $(THIRD_PARTY_LEMON_DEPS) \ - o/$(MODE)/third_party/lemon/lemon.pkg \ - o/$(MODE)/third_party/lemon/lemon.o \ - o/$(MODE)/third_party/lemon/lempar.c.txt.zip.o \ - $(CRT) \ - $(APE) - -@$(APELINK) - -.PHONY: o/$(MODE)/third_party/lemon -o/$(MODE)/third_party/lemon: \ - o/$(MODE)/third_party/lemon/lemon.com diff --git a/third_party/lemon/lempar.c.txt b/third_party/lemon/lempar.c.txt deleted file mode 100644 index ca46ddc9a..000000000 --- a/third_party/lemon/lempar.c.txt +++ /dev/null @@ -1,1083 +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/stdio/stdio.h" -#include "libc/assert.h" - -/* -** 2000-05-29 -** -** The author disclaims copyright to this source code. In place of -** a legal notice, here is a blessing: -** -** May you do good and not evil. -** May you find forgiveness for yourself and forgive others. -** May you share freely, never taking more than you give. -** -************************************************************************* -** Driver template for the LEMON parser generator. -** -** The "lemon" program processes an LALR(1) input grammar file, then uses -** this template to construct a parser. The "lemon" program inserts text -** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the -** interstitial "-" characters) contained in this template is changed into -** the value of the %name directive from the grammar. Otherwise, the content -** of this template is copied straight through into the generate parser -** source file. -** -** The following is the concatenation of all %include directives from the -** input grammar file: -*/ - -/************ Begin %include sections from the grammar ************************/ -%% -/**************** End of %include directives **********************************/ -/* These constants specify the various numeric values for terminal symbols. -***************** Begin token definitions *************************************/ -%% -/**************** End token definitions ***************************************/ - -/* The next sections is a series of control #defines. -** various aspects of the generated parser. -** YYCODETYPE is the data type used to store the integer codes -** that represent terminal and non-terminal symbols. -** "unsigned char" is used if there are fewer than -** 256 symbols. Larger types otherwise. -** YYNOCODE is a number of type YYCODETYPE that is not used for -** any terminal or nonterminal symbol. -** YYFALLBACK If defined, this indicates that one or more tokens -** (also known as: "terminal symbols") have fall-back -** values which should be used if the original symbol -** would not parse. This permits keywords to sometimes -** be used as identifiers, for example. -** YYACTIONTYPE is the data type used for "action codes" - numbers -** that indicate what to do in response to the next -** token. -** ParseTOKENTYPE is the data type used for minor type for terminal -** symbols. Background: A "minor type" is a semantic -** value associated with a terminal or non-terminal -** symbols. For example, for an "ID" terminal symbol, -** the minor type might be the name of the identifier. -** Each non-terminal can have a different minor type. -** Terminal symbols all have the same minor type, though. -** This macros defines the minor type for terminal -** symbols. -** YYMINORTYPE is the data type used for all minor types. -** This is typically a union of many types, one of -** which is ParseTOKENTYPE. The entry in the union -** for terminal symbols is called "yy0". -** YYSTACKDEPTH is the maximum depth of the parser's stack. If -** zero the stack is dynamically sized using realloc() -** ParseARG_SDECL A static variable declaration for the %extra_argument -** ParseARG_PDECL A parameter declaration for the %extra_argument -** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter -** ParseARG_STORE Code to store %extra_argument into yypParser -** ParseARG_FETCH Code to extract %extra_argument from yypParser -** ParseCTX_* As ParseARG_ except for %extra_context -** YYERRORSYMBOL is the code number of the error symbol. If not -** defined, then do no error processing. -** YYNSTATE the combined number of states. -** YYNRULE the number of rules in the grammar -** YYNTOKEN Number of terminal symbols -** YY_MAX_SHIFT Maximum value for shift actions -** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions -** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions -** YY_ERROR_ACTION The yy_action[] code for syntax error -** YY_ACCEPT_ACTION The yy_action[] code for accept -** YY_NO_ACTION The yy_action[] code for no-op -** YY_MIN_REDUCE Minimum value for reduce actions -** YY_MAX_REDUCE Maximum value for reduce actions -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/************* Begin control #defines *****************************************/ -%% -/************* End control #defines *******************************************/ -#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) - -/* Define the yytestcase() macro to be a no-op if is not already defined -** otherwise. -** -** Applications can choose to define yytestcase() in the %include section -** to a macro that can assist in verifying code coverage. For production -** code the yytestcase() macro should be turned off. But it is useful -** for testing. -*/ -#ifndef yytestcase -# define yytestcase(X) -#endif - - -/* Next are the tables used to determine what action to take based on the -** current state and lookahead token. These tables are used to implement -** functions that take a state number and lookahead value and return an -** action integer. -** -** Suppose the action integer is N. Then the action is determined as -** follows -** -** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead -** token onto the stack and goto state N. -** -** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then -** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. -** -** N == YY_ERROR_ACTION A syntax error has occurred. -** -** N == YY_ACCEPT_ACTION The parser accepts its input. -** -** N == YY_NO_ACTION No such action. Denotes unused -** slots in the yy_action[] table. -** -** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE -** and YY_MAX_REDUCE -** -** The action table is constructed as a single large table named yy_action[]. -** Given state S and lookahead X, the action is computed as either: -** -** (A) N = yy_action[ yy_shift_ofst[S] + X ] -** (B) N = yy_default[S] -** -** The (A) formula is preferred. The B formula is used instead if -** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X. -** -** The formulas above are for computing the action when the lookahead is -** a terminal symbol. If the lookahead is a non-terminal (as occurs after -** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array. -** -** The following are the tables generated in this section: -** -** yy_action[] A single table containing all actions. -** yy_lookahead[] A table containing the lookahead for each entry in -** yy_action. Used to detect hash collisions. -** yy_shift_ofst[] For each state, the offset into yy_action for -** shifting terminals. -** yy_reduce_ofst[] For each state, the offset into yy_action for -** shifting non-terminals after a reduce. -** yy_default[] Default action for each state. -** -*********** Begin parsing tables **********************************************/ -%% -/********** End of lemon-generated parsing tables *****************************/ - -/* The next table maps tokens (terminal symbols) into fallback tokens. -** If a construct like the following: -** -** %fallback ID X Y Z. -** -** appears in the grammar, then ID becomes a fallback token for X, Y, -** and Z. Whenever one of the tokens X, Y, or Z is input to the parser -** but it does not parse, the type of the token is changed to ID and -** the parse is retried before an error is thrown. -** -** This feature can be used, for example, to cause some keywords in a language -** to revert to identifiers if they keyword does not apply in the context where -** it appears. -*/ -#ifdef YYFALLBACK -static const YYCODETYPE yyFallback[] = { -%% -}; -#endif /* YYFALLBACK */ - -/* The following structure represents a single element of the -** parser's stack. Information stored includes: -** -** + The state number for the parser at this level of the stack. -** -** + The value of the token stored at this level of the stack. -** (In other words, the "major" token.) -** -** + The semantic value stored at this level of the stack. This is -** the information used by the action routines in the grammar. -** It is sometimes called the "minor" token. -** -** After the "shift" half of a SHIFTREDUCE action, the stateno field -** actually contains the reduce action for the second half of the -** SHIFTREDUCE. -*/ -struct yyStackEntry { - YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */ - YYCODETYPE major; /* The major token value. This is the code - ** number for the token at this stack level */ - YYMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; -typedef struct yyStackEntry yyStackEntry; - -/* The state of the parser is completely contained in an instance of -** the following structure */ -struct yyParser { - yyStackEntry *yytos; /* Pointer to top element of the stack */ -#ifdef YYTRACKMAXSTACKDEPTH - int yyhwm; /* High-water mark of the stack */ -#endif -#ifndef YYNOERRORRECOVERY - int yyerrcnt; /* Shifts left before out of the error */ -#endif - ParseARG_SDECL /* A place to hold %extra_argument */ - ParseCTX_SDECL /* A place to hold %extra_context */ -#if YYSTACKDEPTH<=0 - int yystksz; /* Current side of the stack */ - yyStackEntry *yystack; /* The parser's stack */ - yyStackEntry yystk0; /* First stack entry */ -#else - yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ - yyStackEntry *yystackEnd; /* Last entry in the stack */ -#endif -}; -typedef struct yyParser yyParser; - -#ifndef NDEBUG -static FILE *yyTraceFILE; -static char *yyTracePrompt; -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* -** Turn parser tracing on by giving a stream to which to write the trace -** and a prompt to preface each trace message. Tracing is turned off -** by making either argument NULL -** -** Inputs: -**
    -**
  • A FILE* to which trace output should be written. -** If NULL, then tracing is turned off. -**
  • A prefix string written at the beginning of every -** line of trace output. If NULL, then tracing is -** turned off. -**
-** -** Outputs: -** None. -*/ -void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ - yyTraceFILE = TraceFILE; - yyTracePrompt = zTracePrompt; - if( yyTraceFILE==0 ) yyTracePrompt = 0; - else if( yyTracePrompt==0 ) yyTraceFILE = 0; -} -#endif /* NDEBUG */ - -#if defined(YYCOVERAGE) || !defined(NDEBUG) -/* For tracing shifts, the names of all terminals and nonterminals -** are required. The following table supplies these names */ -static const char *const yyTokenName[] = { -%% -}; -#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ - -#ifndef NDEBUG -/* For tracing reduce actions, the names of all rules are required. -*/ -static const char *const yyRuleName[] = { -%% -}; -#endif /* NDEBUG */ - -#if YYSTACKDEPTH<=0 -/* -** Try to increase the size of the parser stack. Return the number -** of errors. Return 0 on success. -*/ -static int yyGrowStack(yyParser *p){ - int newSize; - int idx; - yyStackEntry *pNew; - newSize = p->yystksz*2 + 100; - idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; - if( p->yystack==&p->yystk0 ){ - pNew = malloc(newSize*sizeof(pNew[0])); - if( pNew ) pNew[0] = p->yystk0; - }else{ - pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); - } - if( pNew ){ - p->yystack = pNew; - p->yytos = &p->yystack[idx]; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", - yyTracePrompt, p->yystksz, newSize); - } -#endif - p->yystksz = newSize; - } - return pNew==0; -} -#endif - -/* Datatype of the argument to the memory allocated passed as the -** second argument to ParseAlloc() below. This can be changed by -** putting an appropriate #define in the %include section of the input -** grammar. -*/ -#ifndef YYMALLOCARGTYPE -# define YYMALLOCARGTYPE size_t -#endif - -/* Initialize a new parser that has already been allocated. -*/ -static void ParseInit(void *yypRawParser ParseCTX_PDECL){ - yyParser *yypParser = (yyParser*)yypRawParser; - ParseCTX_STORE -#ifdef YYTRACKMAXSTACKDEPTH - yypParser->yyhwm = 0; -#endif -#if YYSTACKDEPTH<=0 - yypParser->yytos = NULL; - yypParser->yystack = NULL; - yypParser->yystksz = 0; - if( yyGrowStack(yypParser) ){ - yypParser->yystack = &yypParser->yystk0; - yypParser->yystksz = 1; - } -#endif -#ifndef YYNOERRORRECOVERY - yypParser->yyerrcnt = -1; -#endif - yypParser->yytos = yypParser->yystack; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; -#if YYSTACKDEPTH>0 - yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; -#endif -} - -#ifndef Parse_ENGINEALWAYSONSTACK -/* -** This function allocates a new parser. -** The only argument is a pointer to a function which works like -** malloc. -** -** Inputs: -** A pointer to the function used to allocate memory. -** -** Outputs: -** A pointer to a parser. This pointer is used in subsequent calls -** to Parse and ParseFree. -*/ -static void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){ - yyParser *yypParser; - yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); - if( yypParser ){ - ParseCTX_STORE - ParseInit(yypParser ParseCTX_PARAM); - } - return (void*)yypParser; -} -#endif /* Parse_ENGINEALWAYSONSTACK */ - - -/* The following function deletes the "minor type" or semantic value -** associated with a symbol. The symbol can be either a terminal -** or nonterminal. "yymajor" is the symbol code, and "yypminor" is -** a pointer to the value to be deleted. The code used to do the -** deletions is derived from the %destructor and/or %token_destructor -** directives of the input grammar. -*/ -static void yy_destructor( - yyParser *yypParser, /* The parser */ - YYCODETYPE yymajor, /* Type code for object to destroy */ - YYMINORTYPE *yypminor /* The object to be destroyed */ -){ - ParseARG_FETCH - ParseCTX_FETCH - switch( yymajor ){ - /* Here is inserted the actions which take place when a - ** terminal or non-terminal is destroyed. This can happen - ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is - ** being destroyed before it is finished parsing. - ** - ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are *not* used - ** inside the C code. - */ -/********* Begin destructor definitions ***************************************/ -%% -/********* End destructor definitions *****************************************/ - default: break; /* If no destructor action specified: do nothing */ - } -} - -/* -** Pop the parser's stack once. -** -** If there is a destructor routine associated with the token which -** is popped from the stack, then call it. -*/ -static void yy_pop_parser_stack(yyParser *pParser){ - yyStackEntry *yytos; - assert( pParser->yytos!=0 ); - assert( pParser->yytos > pParser->yystack ); - yytos = pParser->yytos--; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sPopping %s\n", - yyTracePrompt, - yyTokenName[yytos->major]); - } -#endif - yy_destructor(pParser, yytos->major, &yytos->minor); -} - -/* -** Clear all secondary memory allocations from the parser -*/ -static void ParseFinalize(void *p){ - yyParser *pParser = (yyParser*)p; - while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); -#if YYSTACKDEPTH<=0 - if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); -#endif -} - -#ifndef Parse_ENGINEALWAYSONSTACK -/* -** Deallocate and destroy a parser. Destructors are called for -** all stack elements before shutting the parser down. -** -** If the YYPARSEFREENEVERNULL macro exists (for example because it -** is defined in a %include section of the input grammar) then it is -** assumed that the input pointer is never NULL. -*/ -static void ParseFree( - void *p, /* The parser to be deleted */ - void (*freeProc)(void*) /* Function used to reclaim memory */ -){ -#ifndef YYPARSEFREENEVERNULL - if( p==0 ) return; -#endif - ParseFinalize(p); - (*freeProc)(p); -} -#endif /* Parse_ENGINEALWAYSONSTACK */ - -/* -** Return the peak depth of the stack for a parser. -*/ -#ifdef YYTRACKMAXSTACKDEPTH -int ParseStackPeak(void *p){ - yyParser *pParser = (yyParser*)p; - return pParser->yyhwm; -} -#endif - -/* This array of booleans keeps track of the parser statement -** coverage. The element yycoverage[X][Y] is set when the parser -** is in state X and has a lookahead token Y. In a well-tested -** systems, every element of this matrix should end up being set. -*/ -#if defined(YYCOVERAGE) -static unsigned char yycoverage[YYNSTATE][YYNTOKEN]; -#endif - -/* -** Write into out a description of every state/lookahead combination that -** -** (1) has not been used by the parser, and -** (2) is not a syntax error. -** -** Return the number of missed state/lookahead combinations. -*/ -#if defined(YYCOVERAGE) -static int ParseCoverage(FILE *out){ - int stateno, iLookAhead, i; - int nMissed = 0; - for(stateno=0; statenoYY_MAX_SHIFT ) return stateno; - assert( stateno <= YY_SHIFT_COUNT ); -#if defined(YYCOVERAGE) - yycoverage[stateno][iLookAhead] = 1; -#endif - do{ - i = yy_shift_ofst[stateno]; - assert( i>=0 ); - assert( i<=YY_ACTTAB_COUNT ); - assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); - assert( iLookAhead!=YYNOCODE ); - assert( iLookAhead < YYNTOKEN ); - i += iLookAhead; - assert( i<(int)YY_NLOOKAHEAD ); - if( yy_lookahead[i]!=iLookAhead ){ -#ifdef YYFALLBACK - YYCODETYPE iFallback; /* Fallback token */ - assert( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ - iLookAhead = iFallback; - continue; - } -#endif -#ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); - if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", - yyTracePrompt, yyTokenName[iLookAhead], - yyTokenName[YYWILDCARD]); - } -#endif /* NDEBUG */ - return yy_action[j]; - } - } -#endif /* YYWILDCARD */ - return yy_default[stateno]; - }else{ - assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) ); - return yy_action[i]; - } - }while(1); -} - -/* -** Find the appropriate action for a parser given the non-terminal -** look-ahead token iLookAhead. -*/ -static YYACTIONTYPE yy_find_reduce_action( - YYACTIONTYPE stateno, /* Current state number */ - YYCODETYPE iLookAhead /* The look-ahead token */ -){ - int i; -#ifdef YYERRORSYMBOL - if( stateno>YY_REDUCE_COUNT ){ - return yy_default[stateno]; - } -#else - assert( stateno<=YY_REDUCE_COUNT ); -#endif - i = yy_reduce_ofst[stateno]; - assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; -#ifdef YYERRORSYMBOL - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ - return yy_default[stateno]; - } -#else - assert( i>=0 && iyytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will execute if the parser - ** stack every overflows */ -/******** Begin %stack_overflow code ******************************************/ -%% -/******** End %stack_overflow code ********************************************/ - ParseARG_STORE /* Suppress warning about unused %extra_argument var */ - ParseCTX_STORE -} - -/* -** Print tracing information for a SHIFT action -*/ -#ifndef NDEBUG -static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){ - if( yyTraceFILE ){ - if( yyNewStateyytos->major], - yyNewState); - }else{ - fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n", - yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], - yyNewState - YY_MIN_REDUCE); - } - } -} -#else -# define yyTraceShift(X,Y,Z) -#endif - -/* -** Perform a shift action. -*/ -static void yy_shift( - yyParser *yypParser, /* The parser to be shifted */ - YYACTIONTYPE yyNewState, /* The new state to shift in */ - YYCODETYPE yyMajor, /* The major token to shift in */ - ParseTOKENTYPE yyMinor /* The minor token to shift in */ -){ - yyStackEntry *yytos; - yypParser->yytos++; -#ifdef YYTRACKMAXSTACKDEPTH - if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ - yypParser->yyhwm++; - assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); - } -#endif -#if YYSTACKDEPTH>0 - if( yypParser->yytos>yypParser->yystackEnd ){ - yypParser->yytos--; - yyStackOverflow(yypParser); - return; - } -#else - if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){ - if( yyGrowStack(yypParser) ){ - yypParser->yytos--; - yyStackOverflow(yypParser); - return; - } - } -#endif - if( yyNewState > YY_MAX_SHIFT ){ - yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; - } - yytos = yypParser->yytos; - yytos->stateno = yyNewState; - yytos->major = yyMajor; - yytos->minor.yy0 = yyMinor; - yyTraceShift(yypParser, yyNewState, "Shift"); -} - -/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side -** of that rule */ -static const YYCODETYPE yyRuleInfoLhs[] = { -%% -}; - -/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number -** of symbols on the right-hand side of that rule. */ -static const signed char yyRuleInfoNRhs[] = { -%% -}; - -static void yy_accept(yyParser*); /* Forward Declaration */ - -/* -** Perform a reduce action and the shift that must immediately -** follow the reduce. -** -** The yyLookahead and yyLookaheadToken parameters provide reduce actions -** access to the lookahead token (if any). The yyLookahead will be YYNOCODE -** if the lookahead token has already been consumed. As this procedure is -** only called from one place, optimizing compilers will in-line it, which -** means that the extra parameters have no performance impact. -*/ -static YYACTIONTYPE yy_reduce( - yyParser *yypParser, /* The parser */ - unsigned int yyruleno, /* Number of the rule by which to reduce */ - int yyLookahead, /* Lookahead token, or YYNOCODE if none */ - ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ - ParseCTX_PDECL /* %extra_context */ -){ - int yygoto; /* The next state */ - YYACTIONTYPE yyact; /* The next action */ - yyStackEntry *yymsp; /* The top of the parser's stack */ - int yysize; /* Amount to pop the stack */ - ParseARG_FETCH - (void)yyLookahead; - (void)yyLookaheadToken; - yymsp = yypParser->yytos; -#ifndef NDEBUG - assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); - if( yyTraceFILE ){ - yysize = yyRuleInfoNRhs[yyruleno]; - if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", - yyTracePrompt, - yyruleno, yyRuleName[yyruleno], - yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ - yypParser->yyhwm++; - assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); - } -#endif -#if YYSTACKDEPTH>0 - if( yypParser->yytos>=yypParser->yystackEnd ){ - yyStackOverflow(yypParser); - /* The call to yyStackOverflow() above pops the stack until it is - ** empty, causing the main parser loop to exit. So the return value - ** is never used and does not matter. */ - return 0; - } -#else - if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ - if( yyGrowStack(yypParser) ){ - yyStackOverflow(yypParser); - /* The call to yyStackOverflow() above pops the stack until it is - ** empty, causing the main parser loop to exit. So the return value - ** is never used and does not matter. */ - return 0; - } - yymsp = yypParser->yytos; - } -#endif - } - - switch( yyruleno ){ - /* Beginning here are the reduction cases. A typical example - ** follows: - ** case 0: - ** #line - ** { ... } // User supplied code - ** #line - ** break; - */ -/********** Begin reduce actions **********************************************/ -%% -/********** End reduce actions ************************************************/ - }; - assert( yyrulenoYY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) ); - - /* It is not possible for a REDUCE to be followed by an error */ - assert( yyact!=YY_ERROR_ACTION ); - - yymsp += yysize+1; - yypParser->yytos = yymsp; - yymsp->stateno = (YYACTIONTYPE)yyact; - yymsp->major = (YYCODETYPE)yygoto; - yyTraceShift(yypParser, yyact, "... then shift"); - return yyact; -} - -/* -** The following code executes when the parse fails -*/ -#ifndef YYNOERRORRECOVERY -static void yy_parse_failed( - yyParser *yypParser /* The parser */ -){ - ParseARG_FETCH - ParseCTX_FETCH -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); - } -#endif - while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser fails */ -/************ Begin %parse_failure code ***************************************/ -%% -/************ End %parse_failure code *****************************************/ - ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ - ParseCTX_STORE -} -#endif /* YYNOERRORRECOVERY */ - -/* -** The following code executes when a syntax error first occurs. -*/ -static void yy_syntax_error( - yyParser *yypParser, /* The parser */ - int yymajor, /* The major type of the error token */ - ParseTOKENTYPE yyminor /* The minor type of the error token */ -){ - ParseARG_FETCH - ParseCTX_FETCH -#define TOKEN yyminor -/************ Begin %syntax_error code ****************************************/ -%% -/************ End %syntax_error code ******************************************/ - ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ - ParseCTX_STORE -} - -/* -** The following is executed when the parser accepts -*/ -static void yy_accept( - yyParser *yypParser /* The parser */ -){ - ParseARG_FETCH - ParseCTX_FETCH -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); - } -#endif -#ifndef YYNOERRORRECOVERY - yypParser->yyerrcnt = -1; -#endif - assert( yypParser->yytos==yypParser->yystack ); - /* Here code is inserted which will be executed whenever the - ** parser accepts */ -/*********** Begin %parse_accept code *****************************************/ -%% -/*********** End %parse_accept code *******************************************/ - ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ - ParseCTX_STORE -} - -/* The main parser program. -** The first argument is a pointer to a structure obtained from -** "ParseAlloc" which describes the current state of the parser. -** The second argument is the major token number. The third is -** the minor token. The fourth optional argument is whatever the -** user wants (and specified in the grammar) and is available for -** use by the action routines. -** -** Inputs: -**
    -**
  • A pointer to the parser (an opaque structure.) -**
  • The major token number. -**
  • The minor token number. -**
  • An option argument of a grammar-specified type. -**
-** -** Outputs: -** None. -*/ -static void Parse( - void *yyp, /* The parser */ - int yymajor, /* The major token code number */ - ParseTOKENTYPE yyminor /* The value for the token */ - ParseARG_PDECL /* Optional %extra_argument parameter */ -){ - YYMINORTYPE yyminorunion; - YYACTIONTYPE yyact; /* The parser action. */ -#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) - int yyendofinput; /* True if we are at the end of input */ -#endif -#ifdef YYERRORSYMBOL - int yyerrorhit = 0; /* True if yymajor has invoked an error */ -#endif - yyParser *yypParser = (yyParser*)yyp; /* The parser */ - ParseCTX_FETCH - ParseARG_STORE - - assert( yypParser->yytos!=0 ); -#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) - yyendofinput = (yymajor==0); -#endif - - yyact = yypParser->yytos->stateno; -#ifndef NDEBUG - if( yyTraceFILE ){ - if( yyact < YY_MIN_REDUCE ){ - fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", - yyTracePrompt,yyTokenName[yymajor],yyact); - }else{ - fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", - yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE); - } - } -#endif - - do{ - assert( yyact==yypParser->yytos->stateno ); - yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); - if( yyact >= YY_MIN_REDUCE ){ - yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor, - yyminor ParseCTX_PARAM); - }else if( yyact <= YY_MAX_SHIFTREDUCE ){ - yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor); -#ifndef YYNOERRORRECOVERY - yypParser->yyerrcnt--; -#endif - break; - }else if( yyact==YY_ACCEPT_ACTION ){ - yypParser->yytos--; - yy_accept(yypParser); - return; - }else{ - assert( yyact == YY_ERROR_ACTION ); - yyminorunion.yy0 = yyminor; -#ifdef YYERRORSYMBOL - int yymx; -#endif -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); - } -#endif -#ifdef YYERRORSYMBOL - /* A syntax error has occurred. - ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". - ** - ** This is what we do if the grammar does define ERROR: - ** - ** * Call the %syntax_error function. - ** - ** * Begin popping the stack until we enter a state where - ** it is legal to shift the error symbol, then shift - ** the error symbol. - ** - ** * Set the error count to three. - ** - ** * Begin accepting and shifting new tokens. No new error - ** processing will occur until three tokens have been - ** shifted successfully. - ** - */ - if( yypParser->yyerrcnt<0 ){ - yy_syntax_error(yypParser,yymajor,yyminor); - } - yymx = yypParser->yytos->major; - if( yymx==YYERRORSYMBOL || yyerrorhit ){ -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sDiscard input token %s\n", - yyTracePrompt,yyTokenName[yymajor]); - } -#endif - yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); - yymajor = YYNOCODE; - }else{ - while( yypParser->yytos >= yypParser->yystack - && (yyact = yy_find_reduce_action( - yypParser->yytos->stateno, - YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE - ){ - yy_pop_parser_stack(yypParser); - } - if( yypParser->yytos < yypParser->yystack || yymajor==0 ){ - yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - yy_parse_failed(yypParser); -#ifndef YYNOERRORRECOVERY - yypParser->yyerrcnt = -1; -#endif - yymajor = YYNOCODE; - }else if( yymx!=YYERRORSYMBOL ){ - yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor); - } - } - yypParser->yyerrcnt = 3; - yyerrorhit = 1; - if( yymajor==YYNOCODE ) break; - yyact = yypParser->yytos->stateno; -#elif defined(YYNOERRORRECOVERY) - /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to - ** do any kind of error recovery. Instead, simply invoke the syntax - ** error routine and continue going as if nothing had happened. - ** - ** Applications can set this macro (for example inside %include) if - ** they intend to abandon the parse upon the first syntax error seen. - */ - yy_syntax_error(yypParser,yymajor, yyminor); - yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - break; -#else /* YYERRORSYMBOL is not defined */ - /* This is what we do if the grammar does not define ERROR: - ** - ** * Report an error message, and throw away the input token. - ** - ** * If the input token is $, then fail the parse. - ** - ** As before, subsequent error messages are suppressed until - ** three input tokens have been successfully shifted. - */ - if( yypParser->yyerrcnt<=0 ){ - yy_syntax_error(yypParser,yymajor, yyminor); - } - yypParser->yyerrcnt = 3; - yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - if( yyendofinput ){ - yy_parse_failed(yypParser); -#ifndef YYNOERRORRECOVERY - yypParser->yyerrcnt = -1; -#endif - } - break; -#endif - } - }while( yypParser->yytos>yypParser->yystack ); -#ifndef NDEBUG - if( yyTraceFILE ){ - yyStackEntry *i; - char cDiv = '['; - fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); - for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){ - fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]); - cDiv = ' '; - } - fprintf(yyTraceFILE,"]\n"); - } -#endif - return; -} - -/* -** Return the fallback token corresponding to canonical token iToken, or -** 0 if iToken has no fallback. -*/ -static int ParseFallback(int iToken){ -#ifdef YYFALLBACK - assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) ); - return yyFallback[iToken]; -#else - (void)iToken; - return 0; -#endif -} diff --git a/third_party/third_party.mk b/third_party/third_party.mk index 63217935b..0496e07f5 100644 --- a/third_party/third_party.mk +++ b/third_party/third_party.mk @@ -11,7 +11,6 @@ o/$(MODE)/third_party: \ o/$(MODE)/third_party/duktape \ o/$(MODE)/third_party/f2c \ o/$(MODE)/third_party/getopt \ - o/$(MODE)/third_party/lemon \ o/$(MODE)/third_party/lz4cli \ o/$(MODE)/third_party/musl \ o/$(MODE)/third_party/regex \ diff --git a/tool/build/blinkenlights.c b/tool/build/blinkenlights.c index 0e14cd992..82be8de2f 100644 --- a/tool/build/blinkenlights.c +++ b/tool/build/blinkenlights.c @@ -50,6 +50,7 @@ #include "libc/str/str.h" #include "libc/str/thompike.h" #include "libc/str/tpdecode.internal.h" +#include "libc/str/tpenc.h" #include "libc/str/tpencode.internal.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/ex.h" @@ -1957,12 +1958,16 @@ static int GetVidyaByte(unsigned char b) { } static void OnVidyaServiceWriteCharacter(void) { + uint64_t w; int i, n, y, x; char *p, buf[32]; p = buf; p += FormatCga(m->bx[0], p); p = stpcpy(p, "\e7"); - p += tpencode(p, 8, GetVidyaByte(m->ax[0]), false); + w = tpenc(GetVidyaByte(m->ax[0])); + do { + *p++ = w; + } while ((w >>= 8)); p = stpcpy(p, "\e8"); for (i = Read16(m->cx); i--;) { PtyWrite(pty, buf, p - buf); @@ -1984,9 +1989,13 @@ static char16_t VidyaServiceXlatTeletype(uint8_t c) { static void OnVidyaServiceTeletypeOutput(void) { int n; + uint64_t w; char buf[12]; n = FormatCga(m->bx[0], buf); - n += tpencode(buf + n, 6, VidyaServiceXlatTeletype(m->ax[0]), false); + w = tpenc(VidyaServiceXlatTeletype(m->ax[0])); + do { + buf[n++] = w; + } while ((w >>= 8)); PtyWrite(pty, buf, n); } diff --git a/tool/build/lib/buffer.c b/tool/build/lib/buffer.c index 2a8ebe9f0..1202b2c41 100644 --- a/tool/build/lib/buffer.c +++ b/tool/build/lib/buffer.c @@ -21,6 +21,7 @@ #include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/macros.h" +#include "libc/mem/fmt.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "libc/str/tpenc.h" diff --git a/tool/build/lib/dis.c b/tool/build/lib/dis.c index 91c01244b..24b008cbb 100644 --- a/tool/build/lib/dis.c +++ b/tool/build/lib/dis.c @@ -28,7 +28,7 @@ #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" -#include "libc/str/tpencode.internal.h" +#include "libc/str/tpenc.h" #include "third_party/xed/x86.h" #include "tool/build/lib/case.h" #include "tool/build/lib/demangle.h" @@ -134,12 +134,18 @@ static char *DisLineCode(struct Dis *d, char *p) { static char *DisLineData(struct Dis *d, char *p, const uint8_t *b, size_t n) { size_t i; + uint64_t w; p = DisColumn(DisAddr(d, p), p, ADDRLEN); p = DisColumn(DisByte(p, b, n), p, 64); p = HighStart(p, g_high.comment); *p++ = '#'; *p++ = ' '; - for (i = 0; i < n; ++i) p += tpencode(p, 8, bing(b[i], 0), false); + for (i = 0; i < n; ++i) { + w = tpenc(bing(b[i], 0)); + do { + *p++ = w; + } while ((w >>= 8)); + } p = HighEnd(p); *p = '\0'; return p; diff --git a/tool/build/lib/elfwriter.c b/tool/build/lib/elfwriter.c index 5e46fd37a..74521170e 100644 --- a/tool/build/lib/elfwriter.c +++ b/tool/build/lib/elfwriter.c @@ -21,6 +21,7 @@ #include "libc/calls/calls.h" #include "libc/log/check.h" #include "libc/macros.h" +#include "libc/mem/fmt.h" #include "libc/mem/mem.h" #include "libc/runtime/gc.h" #include "libc/runtime/memtrack.h" diff --git a/tool/build/lib/loader.c b/tool/build/lib/loader.c index e1d5ddce7..ed3313bdb 100644 --- a/tool/build/lib/loader.c +++ b/tool/build/lib/loader.c @@ -140,7 +140,7 @@ void LoadProgram(struct Machine *m, const char *prog, char **args, char **vars, size_t i, mappedsize; DCHECK_NOTNULL(prog); elf->prog = prog; - if ((fd = open(prog, O_RDONLY)) == -1 || + if ((fd = open(prog, O_RDWR)) == -1 || (fstat(fd, &st) == -1 || !st.st_size)) { fputs(prog, stderr); fputs(": not found\n", stderr); diff --git a/tool/build/lib/syscall.c b/tool/build/lib/syscall.c index a51ca8514..bb6d9d1a2 100644 --- a/tool/build/lib/syscall.c +++ b/tool/build/lib/syscall.c @@ -466,7 +466,7 @@ static int AppendIovsGuest(struct Machine *m, struct Iovs *iv, int64_t iovaddr, } static struct sigaction *CoerceSigactionToCosmo( - struct sigaction *dst, const struct sigaction$linux *src) { + struct sigaction *dst, const struct sigaction_linux *src) { if (!src) return NULL; memset(dst, 0, sizeof(*dst)); ASSIGN(dst->sa_handler, src->sa_handler); @@ -476,8 +476,8 @@ static struct sigaction *CoerceSigactionToCosmo( return dst; } -static struct sigaction$linux *CoerceSigactionToLinux( - struct sigaction$linux *dst, const struct sigaction *src) { +static struct sigaction_linux *CoerceSigactionToLinux( + struct sigaction_linux *dst, const struct sigaction *src) { if (!dst) return NULL; memset(dst, 0, sizeof(*dst)); ASSIGN(dst->sa_handler, src->sa_handler); @@ -1145,14 +1145,14 @@ static int OpSigaction(struct Machine *m, int sig, int64_t act, int64_t old) { int rc; struct OpSigactionMemory { struct sigaction act, old; - uint8_t b[sizeof(struct sigaction$linux)]; + uint8_t b[sizeof(struct sigaction_linux)]; void *p[2]; } * mem; if (!(mem = malloc(sizeof(*mem)))) return enomem(); if ((rc = sigaction( XlatSignal(sig), CoerceSigactionToCosmo( - &mem->act, LoadBuf(m, act, sizeof(struct sigaction$linux))), + &mem->act, LoadBuf(m, act, sizeof(struct sigaction_linux))), &mem->old)) != -1) { CoerceSigactionToLinux(BeginStoreNp(m, old, sizeof(mem->b), mem->p, mem->b), &mem->old); diff --git a/tool/build/runit.c b/tool/build/runit.c index 6cd5fcffc..84094b926 100644 --- a/tool/build/runit.c +++ b/tool/build/runit.c @@ -367,7 +367,7 @@ int ReadResponse(void) { goto drop; case kRunitStderr: CHECK_GE(n, 4); - size = read32be(p), p += 4, n -= 4; + size = READ32BE(p), p += 4, n -= 4; while (size) { if (n) { CHECK_NE(-1, (rc = write(STDERR_FILENO, p, min(n, size)))); diff --git a/tool/build/runitd.c b/tool/build/runitd.c index 09bf86d6b..221278a1c 100644 --- a/tool/build/runitd.c +++ b/tool/build/runitd.c @@ -263,12 +263,12 @@ void HandleClient(void) { got = recv(g_clifd, (p = &g_buf[0]), sizeof(g_buf), 0); CHECK_GE(got, kMinMsgSize); CHECK_LE(got, sizeof(g_buf)); - CHECK_EQ(RUNITD_MAGIC, read32be(p)); + CHECK_EQ(RUNITD_MAGIC, READ32BE(p)); p += 4, got -= 4; CHECK_EQ(kRunitExecute, *p++); got--; - namesize = read32be(p), p += 4, got -= 4; - filesize = read32be(p), p += 4, got -= 4; + namesize = READ32BE(p), p += 4, got -= 4; + filesize = READ32BE(p), p += 4, got -= 4; CHECK_GE(got, namesize); CHECK_LE(namesize, kMaxNameSize); CHECK_LE(filesize, kMaxFileSize); diff --git a/tool/calc/calc.c b/tool/calc/calc.c deleted file mode 100644 index 27fa62645..000000000 --- a/tool/calc/calc.c +++ /dev/null @@ -1,961 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/bits.h" -#include "libc/bits/bswap.h" -#include "libc/bits/safemacros.h" -#include "libc/calls/calls.h" -#include "libc/errno.h" -#include "libc/fmt/conv.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" -#include "libc/x/x.h" -#include "o/tool/calc/calc.c.inc" -#include "o/tool/calc/calc.h.inc" -#include "third_party/gdtoa/gdtoa.h" -#include "tool/calc/calc.h" - -/** - * make -j8 o//tool/calc - * rlwrap -A -H ~/.calc -f tool/calc/calc.lst -e\( o//tool/calc/calc.com - * @see https://github.com/hanslub42/rlwrap - */ - -static jmp_buf jb; -static int g_line; -static int g_column; -static const char *g_file; -static yyParser g_parser[1]; - -wontreturn static void Error(const char *msg) { - fprintf(stderr, "%s:%d:%d: %s\n", g_file, g_line, g_column, msg); - longjmp(jb, 1); -} - -wontreturn static void SyntaxError(void) { - Error("SYNTAX ERROR"); -} - -wontreturn static void LexError(void) { - Error("LEX ERROR"); -} - -wontreturn static void MissingArgumentError(void) { - Error("MISSING ARGUMENT"); -} - -wontreturn static void MissingFunctionError(void) { - Error("MISSING FUNCTION"); -} - -wontreturn static void SyscallError(const char *name) { - fprintf(stderr, "ERROR: %s[%s]: %d\n", name, g_file, errno); - exit(1); -} - -static void NumbersFree(struct Numbers *n) { - if (n) { - NumbersFree(n->n); - free(n); - } -} - -static struct Numbers *NumbersAppend(struct Numbers *n, long double x) { - struct Numbers *a; - a = malloc(sizeof(struct Numbers)); - a->n = n; - a->x = x; - return a; -} - -static long double ParseNumber(struct Token t) { - char *ep; - ep = t.s + t.n; - if (t.s[0] == '0') { - return strtoumax(t.s, &ep, 0); - } else { - return strtod(t.s, &ep); - } -} - -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); -} - -static long double FnLdexp(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return ldexpl(a->n->x, a->x); -} - -static long double FnCopysign(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return copysignl(a->n->x, a->x); -} - -static long double FnFmax(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return fmaxl(a->n->x, a->x); -} - -static long double FnFmin(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return fminl(a->n->x, a->x); -} - -static long double FnFmod(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return fmodl(a->n->x, a->x); -} - -static long double FnHypot(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return hypotl(a->n->x, a->x); -} - -static long double FnPowi(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return powil(a->n->x, a->x); -} - -static long double FnPow(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return powl(a->n->x, a->x); -} - -static long double FnScalb(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return scalbl(a->n->x, a->x); -} - -static long double FnIsgreater(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return isgreater(a->n->x, a->x); -} - -static long double FnRemainder(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return remainderl(a->n->x, a->x); -} - -static long double FnIsgreaterequal(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return isgreaterequal(a->n->x, a->x); -} - -static long double FnIsless(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return isless(a->n->x, a->x); -} - -static long double FnIslessequal(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return islessequal(a->n->x, a->x); -} - -static long double FnIslessgreater(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return islessgreater(a->n->x, a->x); -} - -static long double FnIsunordered(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return isunordered(a->n->x, a->x); -} - -static long double FnRounddown(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return ROUNDDOWN((int128_t)a->n->x, (int128_t)a->x); -} - -static long double FnRoundup(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return ROUNDUP((int128_t)a->n->x, (int128_t)a->x); -} - -static long double FnAcos(struct Numbers *a) { - if (!a) MissingArgumentError(); - return acosl(a->x); -} - -static long double FnAsin(struct Numbers *a) { - if (!a) MissingArgumentError(); - return asinl(a->x); -} - -static long double FnAtan(struct Numbers *a) { - if (!a) MissingArgumentError(); - return atanl(a->x); -} - -static long double FnCbrt(struct Numbers *a) { - if (!a) MissingArgumentError(); - return cbrtl(a->x); -} - -static long double FnCeil(struct Numbers *a) { - if (!a) MissingArgumentError(); - return ceill(a->x); -} - -static long double FnCos(struct Numbers *a) { - if (!a) MissingArgumentError(); - return cosl(a->x); -} - -static long double FnExp10(struct Numbers *a) { - if (!a) MissingArgumentError(); - return exp10l(a->x); -} - -static long double FnExp2(struct Numbers *a) { - if (!a) MissingArgumentError(); - return exp2l(a->x); -} - -static long double FnExp(struct Numbers *a) { - if (!a) MissingArgumentError(); - return expl(a->x); -} - -static long double FnExpm1(struct Numbers *a) { - if (!a) MissingArgumentError(); - return expm1l(a->x); -} - -static long double FnFabs(struct Numbers *a) { - if (!a) MissingArgumentError(); - return fabsl(a->x); -} - -static long double FnFloor(struct Numbers *a) { - if (!a) MissingArgumentError(); - return floorl(a->x); -} - -static long double FnIlogb(struct Numbers *a) { - if (!a) MissingArgumentError(); - return ilogbl(a->x); -} - -static long double FnLog10(struct Numbers *a) { - if (!a) MissingArgumentError(); - return log10l(a->x); -} - -static long double FnLog1p(struct Numbers *a) { - if (!a) MissingArgumentError(); - return log1pl(a->x); -} - -static long double FnLog2(struct Numbers *a) { - if (!a) MissingArgumentError(); - return log2l(a->x); -} - -static long double FnLogb(struct Numbers *a) { - if (!a) MissingArgumentError(); - return logbl(a->x); -} - -static long double FnLog(struct Numbers *a) { - if (!a) MissingArgumentError(); - return logl(a->x); -} - -static long double FnLrint(struct Numbers *a) { - if (!a) MissingArgumentError(); - return lrintl(a->x); -} - -static long double FnLround(struct Numbers *a) { - if (!a) MissingArgumentError(); - return lroundl(a->x); -} - -static long double FnNearbyint(struct Numbers *a) { - if (!a) MissingArgumentError(); - return nearbyintl(a->x); -} - -static long double FnRint(struct Numbers *a) { - if (!a) MissingArgumentError(); - return rintl(a->x); -} - -static long double FnRound(struct Numbers *a) { - if (!a) MissingArgumentError(); - return roundl(a->x); -} - -static long double FnSignificand(struct Numbers *a) { - if (!a) MissingArgumentError(); - return significandl(a->x); -} - -static long double FnSin(struct Numbers *a) { - if (!a) MissingArgumentError(); - return sinl(a->x); -} - -static long double FnSqrt(struct Numbers *a) { - if (!a) MissingArgumentError(); - return sqrtl(a->x); -} - -static long double FnTan(struct Numbers *a) { - if (!a) MissingArgumentError(); - return tanl(a->x); -} - -static long double FnTrunc(struct Numbers *a) { - if (!a) MissingArgumentError(); - return truncl(a->x); -} - -static long double FnIsinf(struct Numbers *a) { - if (!a) MissingArgumentError(); - return isinf(a->x); -} - -static long double FnIsnan(struct Numbers *a) { - if (!a) MissingArgumentError(); - return isnan(a->x); -} - -static long double FnIsfinite(struct Numbers *a) { - if (!a) MissingArgumentError(); - return isfinite(a->x); -} - -static long double FnIsnormal(struct Numbers *a) { - if (!a) MissingArgumentError(); - return isnormal(a->x); -} - -static long double FnSignbit(struct Numbers *a) { - if (!a) MissingArgumentError(); - return signbit(a->x); -} - -static long double FnFpclassify(struct Numbers *a) { - if (!a) MissingArgumentError(); - return fpclassify(a->x); -} - -static long double FnBswap16(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bswap_16((uint16_t)a->x); -} - -static long double FnBswap32(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bswap_32((uint32_t)a->x); -} - -static long double FnBswap64(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bswap_64((uint64_t)a->x); -} - -static long double FnBsr(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bsr(a->x); -} - -static long double FnBsrl(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bsrl(a->x); -} - -static long double FnBsfl(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bsfl(a->x); -} - -static long double FnFfs(struct Numbers *a) { - if (!a) MissingArgumentError(); - return ffs(a->x); -} - -static long double FnFfsl(struct Numbers *a) { - if (!a) MissingArgumentError(); - return ffsl(a->x); -} - -static long double FnGray(struct Numbers *a) { - if (!a) MissingArgumentError(); - return gray(a->x); -} - -static long double FnUngray(struct Numbers *a) { - if (!a) MissingArgumentError(); - return ungray(a->x); -} - -static long double FnRounddown2pow(struct Numbers *a) { - if (!a) MissingArgumentError(); - return rounddown2pow(a->x); -} - -static long double FnRoundup2pow(struct Numbers *a) { - if (!a) MissingArgumentError(); - return roundup2pow(a->x); -} - -static long double FnRoundup2log(struct Numbers *a) { - if (!a) MissingArgumentError(); - return roundup2log(a->x); -} - -static long double FnBitreverse8(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bitreverse8(a->x); -} - -static long double FnBitreverse16(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bitreverse16(a->x); -} - -static long double FnBitreverse32(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bitreverse32(a->x); -} - -static long double FnBitreverse64(struct Numbers *a) { - if (!a) MissingArgumentError(); - return bitreverse64(a->x); -} - -static int8_t sarb(int8_t x, uint8_t y) { - return x >> (y & 7); -} - -static int16_t sarw(int16_t x, uint8_t y) { - return x >> (y & 15); -} - -static int32_t sarl(int32_t x, uint8_t y) { - return x >> (y & 31); -} - -static int64_t sarq(int64_t x, uint8_t y) { - return x >> (y & 63); -} - -static long double FnSarb(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return sarb(a->n->x, a->x); -} - -static long double FnSarw(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return sarw(a->n->x, a->x); -} - -static long double FnSarl(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return sarl(a->n->x, a->x); -} - -static long double FnSarq(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return sarq(a->n->x, a->x); -} - -static long double FnSar(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return sarq(a->n->x, a->x); -} - -static uint8_t rorb(uint8_t x, uint8_t y) { - return x >> (y & 7) | x << (8 - (y & 7)); -} - -static uint16_t rorw(uint16_t x, uint8_t y) { - return x >> (y & 15) | x << (16 - (y & 15)); -} - -static uint32_t rorl(uint32_t x, uint8_t y) { - return x >> (y & 31) | x << (32 - (y & 31)); -} - -static uint64_t rorq(uint64_t x, uint8_t y) { - return x >> (y & 63) | x << (64 - (y & 63)); -} - -static long double FnRorb(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rorb(a->n->x, a->x); -} - -static long double FnRorw(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rorw(a->n->x, a->x); -} - -static long double FnRorl(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rorl(a->n->x, a->x); -} - -static long double FnRorq(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rorq(a->n->x, a->x); -} - -static long double FnRor(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rorq(a->n->x, a->x); -} - -static uint8_t rolb(uint8_t x, uint8_t y) { - return x << (y & 7) | x >> (8 - (y & 7)); -} - -static uint16_t rolw(uint16_t x, uint8_t y) { - return x << (y & 15) | x >> (16 - (y & 15)); -} - -static uint32_t roll(uint32_t x, uint8_t y) { - return x << (y & 31) | x >> (32 - (y & 31)); -} - -static uint64_t rolq(uint64_t x, uint8_t y) { - return x << (y & 63) | x >> (64 - (y & 63)); -} - -static long double FnRolb(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rolb(a->n->x, a->x); -} - -static long double FnRolw(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rolw(a->n->x, a->x); -} - -static long double FnRoll(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return roll(a->n->x, a->x); -} - -static long double FnRolq(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rolq(a->n->x, a->x); -} - -static long double FnRol(struct Numbers *a) { - if (!a || !a->n) MissingArgumentError(); - return rolq(a->n->x, a->x); -} - -static long double FnTime(struct Numbers *a) { - return nowl(); -} - -static long double FnBin(struct Numbers *a) { - if (!a) MissingArgumentError(); - printf("0b%jb\n", (uint128_t)a->x); - return 0; -} - -static long double FnOct(struct Numbers *a) { - if (!a) MissingArgumentError(); - printf("0%jo\n", (uint128_t)a->x); - return 0; -} - -static long double FnHex(struct Numbers *a) { - if (!a) MissingArgumentError(); - printf("0x%jx\n", (uint128_t)a->x); - return 0; -} - -static void PrintNumber(long double x) { - char buf[32]; - g_xfmt_p(buf, &x, 15, sizeof(buf), 0); - fputs(buf, stdout); -} - -static void Print(struct Numbers *a) { - if (a) { - Print(a->n); - if (a->n) fputc(' ', stdout); - PrintNumber(a->x); - } -} - -static long double FnPrint(struct Numbers *a) { - Print(a); - fputc('\n', stdout); - return 0; -} - -static const struct Fn { - const char *s; - long double (*f)(struct Numbers *); -} kFunctions[] = { - {"abs", FnFabs}, - {"acos", FnAcos}, - {"asin", FnAsin}, - {"atan", FnAtan}, - {"atan2", FnAtan2}, - {"bin", FnBin}, - {"bitreverse16", FnBitreverse16}, - {"bitreverse32", FnBitreverse32}, - {"bitreverse64", FnBitreverse64}, - {"bitreverse8", FnBitreverse8}, - {"bsfl", FnBsfl}, - {"bsfl", FnBsfl}, - {"bsr", FnBsr}, - {"bsrl", FnBsrl}, - {"bswap16", FnBswap16}, - {"bswap32", FnBswap32}, - {"bswap64", FnBswap64}, - {"cbrt", FnCbrt}, - {"ceil", FnCeil}, - {"copysign", FnCopysign}, - {"cos", FnCos}, - {"exp", FnExp}, - {"exp10", FnExp10}, - {"exp2", FnExp2}, - {"expm1", FnExpm1}, - {"fabs", FnFabs}, - {"ffs", FnFfs}, - {"ffsl", FnFfsl}, - {"floor", FnFloor}, - {"fmax", FnFmax}, - {"fmin", FnFmin}, - {"fmod", FnFmod}, - {"fpclassify", FnFpclassify}, - {"gray", FnGray}, - {"hex", FnHex}, - {"hypot", FnHypot}, - {"ilogb", FnIlogb}, - {"isfinite", FnIsfinite}, - {"isgreater", FnIsgreater}, - {"isgreaterequal", FnIsgreaterequal}, - {"isinf", FnIsinf}, - {"isless", FnIsless}, - {"islessequal", FnIslessequal}, - {"islessgreater", FnIslessgreater}, - {"isnan", FnIsnan}, - {"isnormal", FnIsnormal}, - {"isunordered", FnIsunordered}, - {"ldexp", FnLdexp}, - {"ldexp", FnLdexp}, - {"log", FnLog}, - {"log10", FnLog10}, - {"log1p", FnLog1p}, - {"log2", FnLog2}, - {"logb", FnLogb}, - {"lrint", FnLrint}, - {"lround", FnLround}, - {"max", FnFmax}, - {"min", FnFmin}, - {"nearbyint", FnNearbyint}, - {"oct", FnOct}, - {"pow", FnPow}, - {"powi", FnPowi}, - {"print", FnPrint}, - {"rand", FnRand}, - {"rand32", FnRand32}, - {"rand64", FnRand64}, - {"rdrand", FnRdrand}, - {"rdseed", FnRdseed}, - {"remainder", FnRemainder}, - {"rint", FnRint}, - {"rol", FnRol}, - {"rolb", FnRolb}, - {"roll", FnRoll}, - {"rolq", FnRolq}, - {"rolw", FnRolw}, - {"ror", FnRor}, - {"rorb", FnRorb}, - {"rorl", FnRorl}, - {"rorq", FnRorq}, - {"rorw", FnRorw}, - {"round", FnRound}, - {"rounddown", FnRounddown}, - {"rounddown2pow", FnRounddown2pow}, - {"roundup", FnRoundup}, - {"roundup2log", FnRoundup2log}, - {"roundup2pow", FnRoundup2pow}, - {"sar", FnSar}, - {"sarb", FnSarb}, - {"sarl", FnSarl}, - {"sarq", FnSarq}, - {"sarw", FnSarw}, - {"scalb", FnScalb}, - {"signbit", FnSignbit}, - {"signbit", FnSignbit}, - {"significand", FnSignificand}, - {"sin", FnSin}, - {"sqrt", FnSqrt}, - {"tan", FnTan}, - {"time", FnTime}, - {"trunc", FnTrunc}, - {"ungray", FnUngray}, -}; - -static long double CallFunction(struct Token fn, struct Numbers *args) { - int l, r, m, p; - l = 0; - r = ARRAYLEN(kFunctions) - 1; - while (l <= r) { - m = (l + r) >> 1; - p = strncmp(kFunctions[m].s, fn.s, fn.n); - if (p < 0) { - l = m + 1; - } else if (p > 0) { - r = m - 1; - } else { - return kFunctions[m].f(args); - } - } - MissingFunctionError(); -} - -static void Tokenize(const char *s, size_t size) { - size_t n; - char *se; - for (se = s + size; s < se; s += n, ++g_column) { - n = 1; - switch (*s & 0xff) { - case ' ': - case '\t': - case '\v': - case '\r': - break; - case '\n': - ++g_line; - g_column = 0; - break; - case 'A' ... 'Z': - case 'a' ... 'z': - n = strspn(s, "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"); - Parse(g_parser, SYMBOL, (struct Token){s, n}); - break; - case '0': - n = strspn(s, "xXbB0123456789abcdefABCDEF"); - Parse(g_parser, NUMBER, (struct Token){s, n}); - n += strspn(s + n, "LUlu"); - break; - case '1' ... '9': - n = strspn(s, "0123456789."); - if (s[n] == 'e' || s[n] == 'E') { - ++n; - if (s[n] == '+' || s[n] == '-') ++n; - n += strspn(s + n, "0123456789"); - } - Parse(g_parser, NUMBER, (struct Token){s, n}); - n += strspn(s + n, "LUlu"); - break; - case '(': - Parse(g_parser, LP, (struct Token){0, 0}); - break; - case ')': - Parse(g_parser, RP, (struct Token){0, 0}); - break; - case ',': - Parse(g_parser, COMMA, (struct Token){0, 0}); - break; - case '^': - Parse(g_parser, XOR, (struct Token){0, 0}); - break; - case '%': - Parse(g_parser, REM, (struct Token){0, 0}); - break; - case '+': - Parse(g_parser, PLUS, (struct Token){0, 0}); - break; - case '-': - Parse(g_parser, MINUS, (struct Token){0, 0}); - break; - case '~': - Parse(g_parser, NOT, (struct Token){0, 0}); - break; - case '/': - if (s[1] == '/') { - Parse(g_parser, DDIV, (struct Token){0, 0}); - ++n; - } else { - Parse(g_parser, DIV, (struct Token){0, 0}); - } - break; - case '*': - if (s[1] == '*') { - Parse(g_parser, EXP, (struct Token){0, 0}); - ++n; - } else { - Parse(g_parser, MUL, (struct Token){0, 0}); - } - break; - case '|': - if (s[1] == '|') { - Parse(g_parser, LOR, (struct Token){0, 0}); - ++n; - } else { - Parse(g_parser, OR, (struct Token){0, 0}); - } - break; - case '&': - if (s[1] == '&') { - Parse(g_parser, LAND, (struct Token){0, 0}); - ++n; - } else { - Parse(g_parser, AND, (struct Token){0, 0}); - } - break; - case '!': - if (s[1] == '=') { - Parse(g_parser, NE, (struct Token){0, 0}); - ++n; - } else { - Parse(g_parser, LNOT, (struct Token){0, 0}); - } - break; - case '=': - if (s[1] == '=') { - Parse(g_parser, EQ, (struct Token){0, 0}); - ++n; - } else { - LexError(); - } - break; - case '>': - if (s[1] == '=') { - Parse(g_parser, GE, (struct Token){0, 0}); - ++n; - } else if (s[1] == '>') { - Parse(g_parser, SHR, (struct Token){0, 0}); - ++n; - } else { - Parse(g_parser, GT, (struct Token){0, 0}); - } - break; - case '<': - if (s[1] == '=') { - Parse(g_parser, LE, (struct Token){0, 0}); - ++n; - } else if (s[1] == '<') { - Parse(g_parser, SHL, (struct Token){0, 0}); - ++n; - } else { - Parse(g_parser, LT, (struct Token){0, 0}); - } - break; - default: - LexError(); - } - } -} - -int main(int argc, char *argv[]) { - int i; - int ec; - int fd; - size_t n; - char *buf; - ssize_t rc; - size_t bufcap; - if (!(ec = setjmp(jb))) { - if (argc > 1) { - ParseInit(g_parser); - bufcap = BIGPAGESIZE; - buf = malloc(bufcap); - for (i = 1; i < argc; ++i) { - g_file = argv[i]; - g_line = 0; - g_column = 0; - n = 0; /* wut */ - if ((fd = open(g_file, O_RDONLY)) == -1) SyscallError("open"); - for (;;) { - if ((rc = read(fd, buf, bufcap)) == -1) SyscallError("read"); - if (!(n = rc)) break; - Tokenize(buf, n); - } - close(fd); - Parse(g_parser, 0, (struct Token){0, 0}); - } - ParseFinalize(g_parser); - } else { - g_file = "/dev/stdin"; - g_line = 0; - g_column = 0; - buf = NULL; - bufcap = 0; - while (getline(&buf, &bufcap, stdin) != -1) { - if ((n = strlen(buf))) { - ParseInit(g_parser); - if (!setjmp(jb)) { - Tokenize("print(", 6); - Tokenize(buf, n); - Tokenize(")", 1); - Parse(g_parser, 0, (struct Token){0, 0}); - } - ParseFinalize(g_parser); - } - } - } - } - free(buf); - return ec; -} diff --git a/tool/calc/calc.h b/tool/calc/calc.h deleted file mode 100644 index bb00407ae..000000000 --- a/tool/calc/calc.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef COSMOPOLITAN_TOOL_CALC_CALC_H_ -#define COSMOPOLITAN_TOOL_CALC_CALC_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct Token { - const char *s; - size_t n; -}; - -struct Numbers { - struct Numbers *n; - long double x; -}; - -static void SyntaxError(void) wontreturn; -static long double ParseNumber(struct Token); -static void NumbersFree(struct Numbers *); -static struct Numbers *NumbersAppend(struct Numbers *, long double); -static long double CallFunction(struct Token, struct Numbers *); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_TOOL_CALC_CALC_H_ */ diff --git a/tool/calc/calc.lst b/tool/calc/calc.lst deleted file mode 100644 index 1b7fccd7a..000000000 --- a/tool/calc/calc.lst +++ /dev/null @@ -1,93 +0,0 @@ -abs -acos -asin -atan -atan2 -bin -bitreverse16 -bitreverse32 -bitreverse64 -bitreverse8 -bsfl -bsfl -bsr -bsr -cbrt -ceil -copysign -cos -exp -exp10 -exp2 -expm1 -fabs -ffs -ffsl -floor -fmax -fmin -fmod -fpclassify -gray -hex -hypot -ilogb -isfinite -isgreater -isgreaterequal -isinf -isless -islessequal -islessgreater -isnan -isnormal -isunordered -ldexp -ldexp -log -log10 -log1p -log2 -logb -lrint -lround -max -min -nearbyint -oct -pow -powi -print -remainder -rint -rol -rolb -roll -rolq -rolw -ror -rorb -rorl -rorq -rorw -round -rounddown -rounddown2pow -roundup -roundup2log -roundup2pow -sar -sarb -sarl -sarq -sarw -scalb -signbit -signbit -significand -sin -sqrt -tan -time -trunc -ungray diff --git a/tool/calc/calc.mk b/tool/calc/calc.mk deleted file mode 100644 index 192ba6548..000000000 --- a/tool/calc/calc.mk +++ /dev/null @@ -1,79 +0,0 @@ -#-*-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───────────────────────┘ - -PKGS += TOOL_CALC - -TOOL_CALC = $(TOOL_LIB_A_DEPS) $(TOOL_LIB_A) -TOOL_CALC_A = o/$(MODE)/tool/calc/calc.a -TOOL_CALC_FILES := $(wildcard tool/calc/*) -TOOL_CALC_COMS = $(TOOL_CALC_OBJS:%.o=%.com) -TOOL_CALC_SRCS = $(filter %.c,$(TOOL_CALC_FILES)) -TOOL_CALC_HDRS = $(filter %.h,$(TOOL_CALC_FILES)) - -TOOL_CALC_OBJS = \ - $(TOOL_CALC_SRCS:%.c=o/$(MODE)/%.o) - -TOOL_CALC_COMS = \ - $(TOOL_CALC_SRCS:%.c=o/$(MODE)/%.com) - -TOOL_CALC_BINS = \ - $(TOOL_CALC_COMS) \ - $(TOOL_CALC_COMS:%=%.dbg) - -TOOL_CALC_CHECKS = \ - $(TOOL_CALC_HDRS:%=o/$(MODE)/%.ok) - -TOOL_CALC_DIRECTDEPS = \ - LIBC_BITS \ - LIBC_CALLS \ - LIBC_FMT \ - LIBC_INTRIN \ - LIBC_LOG \ - LIBC_MEM \ - LIBC_NEXGEN32E \ - LIBC_RAND \ - LIBC_RUNTIME \ - LIBC_STDIO \ - LIBC_STR \ - LIBC_STUBS \ - LIBC_SYSV \ - LIBC_TINYMATH \ - LIBC_X \ - THIRD_PARTY_COMPILER_RT \ - THIRD_PARTY_GDTOA - -TOOL_CALC_DEPS := \ - $(call uniq,$(foreach x,$(TOOL_CALC_DIRECTDEPS),$($(x)))) - -$(TOOL_CALC_A): \ - tool/calc/ \ - $(TOOL_CALC_A).pkg \ - $(TOOL_CALC_OBJS) - -$(TOOL_CALC_A).pkg: \ - $(TOOL_CALC_OBJS) \ - $(foreach x,$(TOOL_CALC_DIRECTDEPS),$($(x)_A).pkg) - -o/tool/calc/calc.h.inc: o/tool/calc/calc.c.inc -o/tool/calc/calc.c.inc: \ - tool/calc/calc.y \ - $(THIRD_PARTY_LEMON) - @$(LEMON) -l -d$(@D) $< - -o/$(MODE)/tool/calc/%.com.dbg: \ - $(TOOL_CALC_DEPS) \ - $(TOOL_CALC_A) \ - o/$(MODE)/tool/calc/%.o \ - $(TOOL_CALC_A).pkg \ - $(CRT) \ - $(APE) - @$(APELINK) - -tool/calc/calc.c: \ - o/tool/calc/calc.c.inc \ - o/tool/calc/calc.h.inc - -.PHONY: o/$(MODE)/tool/calc -o/$(MODE)/tool/calc: \ - $(TOOL_CALC_BINS) \ - $(TOOL_CALC_CHECKS) diff --git a/tool/calc/calc.y b/tool/calc/calc.y deleted file mode 100644 index ca06fdbe6..000000000 --- a/tool/calc/calc.y +++ /dev/null @@ -1,79 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -%include { -#include "libc/stdio/stdio.h" -#include "tool/calc/calc.h" -#include "libc/calls/calls.h" -#include "libc/str/str.h" -#include "libc/x/x.h" -#include "libc/runtime/gc.h" -#include "libc/math.h" -} - -%token_type {struct Token} -%type number {long double} -%syntax_error { SyntaxError(); } - -%left LOR. -%left LAND. -%left OR. -%left XOR. -%left AND. -%left EQ NE. -%left LT LE GT GE. -%left SHL SHR. -%left PLUS MINUS. -%left MUL DIV DDIV REM. -%right NOT LNOT. -%right EXP. - -program ::= number. -number(A) ::= NUMBER(B). { A = ParseNumber(B); } -number(A) ::= LP number(B) RP. { A = B; } -number(A) ::= LNOT number(B). { A = !B; } -number(A) ::= NOT number(B). { A = ~(long)B; } -number(A) ::= PLUS number(B). { A = +B; } [NOT] -number(A) ::= MINUS number(B). { A = -B; } [NOT] -number(A) ::= SYMBOL(F) LP numbers(N) RP. { A = CallFunction(F, N); } -number(A) ::= number(B) EQ number(C). { A = B == C; } -number(A) ::= number(B) NE number(C). { A = B != C; } -number(A) ::= number(B) LT number(C). { A = B < C; } -number(A) ::= number(B) LE number(C). { A = B <= C; } -number(A) ::= number(B) GT number(C). { A = B > C; } -number(A) ::= number(B) GE number(C). { A = B >= C; } -number(A) ::= number(B) LOR number(C). { A = B || C; } -number(A) ::= number(B) LAND number(C). { A = B && C; } -number(A) ::= number(B) PLUS number(C). { A = B + C; } -number(A) ::= number(B) MINUS number(C). { A = B - C; } -number(A) ::= number(B) MUL number(C). { A = B * C; } -number(A) ::= number(B) DIV number(C). { A = B / C; } -number(A) ::= number(B) REM number(C). { A = remainderl(B, C); } -number(A) ::= number(B) EXP number(C). { A = powl(B, C); } -number(A) ::= number(B) DDIV number(C). { A = truncl(B / C); } -number(A) ::= number(B) OR number(C). { A = (long)B | (long)C; } -number(A) ::= number(B) XOR number(C). { A = (long)B ^ (long)C; } -number(A) ::= number(B) AND number(C). { A = (long)B & (long)C; } -number(A) ::= number(B) SHL number(C). { A = (long)B << (long)C; } -number(A) ::= number(B) SHR number(C). { A = (long)B >> (long)C; } - -%type numbers {struct Numbers *} -%destructor numbers { NumbersFree($$); } -numbers(A) ::= . { A = 0; } -numbers(A) ::= number(B). { A = NumbersAppend(0, B); } -numbers(A) ::= numbers(A) COMMA number(B). { A = NumbersAppend(A, B); } diff --git a/tool/decode/ar.c b/tool/decode/ar.c index fcde6d427..f27f3b983 100644 --- a/tool/decode/ar.c +++ b/tool/decode/ar.c @@ -100,7 +100,7 @@ static void Print(void) { arsize = atoi((char *)(data + 8 + 48)); CHECK_LE(4, arsize); CHECK_LE(8 + 60 + arsize, size); - entries = read32be(data + 8 + 60); + entries = READ32BE(data + 8 + 60); CHECK_LE(4 + entries * 4 + 1, arsize); printf("\t# %'s\n", path); PrintString(data, 8, "file signature"); @@ -110,7 +110,7 @@ static void Print(void) { printf("\t.long\t%u\t\t\t# %s\n", entries, "symbol table entries"); table = 8 + 60 + 4; for (i = 0; i < entries; ++i) { - printf("\t.long\t%#x\t\t\t\t# %u\n", read32be(data + table + i * 4), i); + printf("\t.long\t%#x\t\t\t\t# %u\n", READ32BE(data + table + i * 4), i); } symbols = table + entries * 4; symbolslen = arsize - (4 + entries * 4); diff --git a/tool/decode/zip.c b/tool/decode/zip.c index 582ac76a9..011076b65 100644 --- a/tool/decode/zip.c +++ b/tool/decode/zip.c @@ -94,22 +94,22 @@ void showcompressmethod(uint16_t compressmethod) { void showextrantfs(uint8_t *ntfs) { struct timespec mtime, atime, ctime; mtime = FileTimeToTimeSpec( - (struct NtFileTime){read32le(ntfs + 8), read32le(ntfs + 12)}); + (struct NtFileTime){READ32LE(ntfs + 8), READ32LE(ntfs + 12)}); atime = FileTimeToTimeSpec( - (struct NtFileTime){read32le(ntfs + 16), read32le(ntfs + 20)}); + (struct NtFileTime){READ32LE(ntfs + 16), READ32LE(ntfs + 20)}); ctime = FileTimeToTimeSpec( - (struct NtFileTime){read32le(ntfs + 24), read32le(ntfs + 28)}); - show(".long", gc(xasprintf("%d", read32le(ntfs))), "ntfs reserved"); - show(".short", gc(xasprintf("0x%04x", read16le(ntfs + 4))), + (struct NtFileTime){READ32LE(ntfs + 24), READ32LE(ntfs + 28)}); + show(".long", gc(xasprintf("%d", READ32LE(ntfs))), "ntfs reserved"); + show(".short", gc(xasprintf("0x%04x", READ16LE(ntfs + 4))), "ntfs attribute tag value #1"); - show(".short", gc(xasprintf("%hu", read16le(ntfs + 6))), + show(".short", gc(xasprintf("%hu", READ16LE(ntfs + 6))), "ntfs attribute tag size"); - show(".quad", gc(xasprintf("%lu", read64le(ntfs + 8))), + show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 8))), gc(xasprintf("%s (%s)", "ntfs last modified time", gc(xiso8601(&mtime))))); - show(".quad", gc(xasprintf("%lu", read64le(ntfs + 16))), + show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 16))), gc(xasprintf("%s (%s)", "ntfs last access time", gc(xiso8601(&atime))))); - show(".quad", gc(xasprintf("%lu", read64le(ntfs + 24))), + show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 24))), gc(xasprintf("%s (%s)", "ntfs creation time", gc(xiso8601(&ctime))))); } diff --git a/tool/tool.mk b/tool/tool.mk index 317215e33..8c2b58948 100644 --- a/tool/tool.mk +++ b/tool/tool.mk @@ -4,7 +4,6 @@ .PHONY: o/$(MODE)/tool o/$(MODE)/tool: \ o/$(MODE)/tool/build \ - o/$(MODE)/tool/calc \ o/$(MODE)/tool/decode \ o/$(MODE)/tool/hash \ o/$(MODE)/tool/net \ diff --git a/tool/viz/printpeb.c b/tool/viz/printpeb.c index aee83de7a..42bc96214 100644 --- a/tool/viz/printpeb.c +++ b/tool/viz/printpeb.c @@ -87,7 +87,7 @@ noasan void PrintStartupInfo(void) { ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); #define X(D, F) \ - printf("%s.%-22s= " D "\n", "g_ntstartupinfo", #F, g_ntstartupinfo.F); + printf("%s.%-22s= " D "\n", "__nt_startupinfo", #F, __nt_startupinfo.F); X("%u", cb); X("%p", lpReserved); X("%hs", lpDesktop); @@ -99,8 +99,8 @@ noasan void PrintStartupInfo(void) { X("%u", dwXCountChars); X("%u", dwYCountChars); X("%u", dwFillAttribute); - printf("%s.%-22s: %s\n", "g_ntstartupinfo", "dwFlags", - RecreateFlags(kNtStartfFlagNames, g_ntstartupinfo.dwFlags)); + printf("%s.%-22s: %s\n", "__nt_startupinfo", "dwFlags", + RecreateFlags(kNtStartfFlagNames, __nt_startupinfo.dwFlags)); X("%hu", wShowWindow); X("%hu", cbReserved2); X("%s", lpReserved2); @@ -117,7 +117,7 @@ void PrintSystemInfo(void) { ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); #define X(D, F) \ - printf("%s.%-28s= " D "\n", "g_ntsysteminfo", #F, g_ntsysteminfo.F); + printf("%s.%-28s= " D "\n", "__nt_systeminfo", #F, __nt_systeminfo.F); X("%08x", dwOemId); X("%04hx", wProcessorArchitecture); X("%d", dwPageSize); diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index a6f39aa47..25aef47b0 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -127,12 +127,17 @@ Flags & Keyboard Shortcuts:\n\ CTRL+L redraw [keyboard]\n\ CTRL+Z suspend [keyboard]\n\ CTRL+C exit [keyboard]\n\ + q quit [keyboard]\n\ \n\ Effects Shortcuts:\n\ \n\ - H +Hue ALT+H -Hue\n\ - S +Saturation ALT+S -Saturation\n\ - L +Lightness ALT+L -Lightness\n\ + S Toggle Swing (TV, PC)\n\ + Y Toggle Black/White Mode\n\ + p Toggle Primaries (BT.601, BT.709)\n\ + g +Gamma G -Gamma\n\ + l +Illumination L -Illumination\n\ + k +LumaKernel K -LumaKernel\n\ + j +ChromaKernel J -ChromaKernel\n\ CTRL-G {Unsharp,Sharp}\n\ \n\ Environment Variables:\n\ @@ -1018,6 +1023,7 @@ static optimizesize void ReadKeyboard(void) { chromakernel_ = MOD(sgn + chromakernel_, ARRAYLEN(kMagkern)); memcpy(g_magkern, kMagkern[chromakernel_], sizeof(kMagkern[0])); break; + case 'q': case CTRL('C'): longjmp(jb_, 1); break; diff --git a/usr/share/img/honeybadger.png b/usr/share/img/honeybadger.png new file mode 100644 index 000000000..6f9d154fa Binary files /dev/null and b/usr/share/img/honeybadger.png differ