Fix bugs in cosmocc toolchain

This change integrates e58abc1110b335a3341e8ad5821ad8e3880d9bb2 from
https://github.com/ahgamut/musl-cross-make/ which fixes the issues we
were having with our C language extension for symbolic constants. This
change also performs some code cleanup and bug fixes to getaddrinfo().
It's now possible to compile projects like ncurses, readline and python
without needing to patch anything upstream, except maybe a line or two.
Pretty soon it should be possible to build a Linux distro on Cosmo.
This commit is contained in:
Justine Tunney 2023-06-08 23:44:03 -07:00
parent 22f81a8d50
commit 23e235b7a5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
272 changed files with 3491 additions and 4350 deletions

View file

@ -383,7 +383,7 @@ static int GetXmmTypeCellCount(int r) {
case kXmmDouble:
return 2;
default:
unreachable;
__builtin_unreachable();
}
}
@ -849,7 +849,7 @@ static int GetRegHexWidth(void) {
return 4;
}
default:
unreachable;
__builtin_unreachable();
}
}
@ -866,7 +866,7 @@ static int GetAddrHexWidth(void) {
return 6;
}
default:
unreachable;
__builtin_unreachable();
}
}
@ -1281,7 +1281,7 @@ static void DrawXmm(struct Panel *p, long i, long r) {
}
break;
default:
unreachable;
__builtin_unreachable();
}
buf[cellwidth] = '\0';
AppendPanel(p, i, buf);
@ -1532,7 +1532,7 @@ static int GetPreferredStackAlignmentMask(void) {
case XED_MODE_REAL:
return 3;
default:
unreachable;
__builtin_unreachable();
}
}
@ -1961,7 +1961,7 @@ static int OnPtyFdPoll(struct pollfd *fds, size_t nfds, int ms) {
++t;
break;
default:
unreachable;
__builtin_unreachable();
}
}
}

View file

@ -27,9 +27,6 @@
* strace -vff bash -c '_PLEDGE=4194303,0 LD_PRELOAD=$HOME/sandbox.so ls'
*/
_Hide uint8_t __privileged_start[1];
_Hide uint8_t __privileged_end[1];
__attribute__((__constructor__)) void init(void) {
int c, i, j;
const char *s;

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "third_party/xed/x86.h"
#include "tool/build/lib/address.h"
#include "third_party/xed/x86.h"
#include "tool/build/lib/endian.h"
#include "tool/build/lib/modrm.h"
#include "tool/build/lib/throw.h"
@ -44,7 +44,7 @@ uint8_t *GetSegment(struct Machine *m, uint32_t rde, int s) {
case 7:
OpUd(m, rde);
default:
unreachable;
__builtin_unreachable();
}
}
@ -69,7 +69,7 @@ uint64_t AddressSi(struct Machine *m, uint32_t rde) {
case XED_MODE_LEGACY:
return DataSegment(m, rde, Read32(m->si));
default:
unreachable;
__builtin_unreachable();
}
}
@ -83,6 +83,6 @@ uint64_t AddressDi(struct Machine *m, uint32_t rde) {
case XED_MODE_LEGACY:
return i + Read32(m->di);
default:
unreachable;
__builtin_unreachable();
}
}

View file

@ -146,7 +146,7 @@ struct Asmdown *ParseAsmdown(const char *code, size_t size) {
}
break;
default:
unreachable;
__builtin_unreachable();
}
}
return ad;

View file

@ -280,7 +280,7 @@ static char *DisBis(struct Dis *d, uint32_t rde, char *p) {
base = "bx";
break;
default:
unreachable;
__builtin_unreachable();
}
}
if (base || index) {

View file

@ -862,7 +862,7 @@ const char *DisSpecMap1(struct XedDecodedInst *x, char *p) {
case 3:
return "movsldup %Vq Wq";
default:
unreachable;
__builtin_unreachable();
}
break;
case 0x13:

View file

@ -16,13 +16,13 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/build/lib/modrm.h"
#include "libc/log/check.h"
#include "third_party/xed/x86.h"
#include "tool/build/lib/address.h"
#include "tool/build/lib/endian.h"
#include "tool/build/lib/machine.h"
#include "tool/build/lib/memory.h"
#include "tool/build/lib/modrm.h"
#include "tool/build/lib/throw.h"
/**
@ -106,7 +106,7 @@ struct AddrSeg LoadEffectiveAddress(const struct Machine *m, uint32_t rde) {
i += Read16(m->bx);
break;
default:
unreachable;
__builtin_unreachable();
}
i &= 0xffff;
}

View file

@ -157,7 +157,7 @@ ssize_t PrintPanels(int fd, long pn, struct Panel *p, long tyn, long txn) {
}
break;
default:
unreachable;
__builtin_unreachable();
}
if (x > p[i].right) {
break;

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/build/lib/pty.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h"
@ -28,7 +29,6 @@
#include "libc/str/unicode.h"
#include "libc/sysv/errfuns.h"
#include "libc/x/x.h"
#include "tool/build/lib/pty.h"
/**
* @fileoverview Pseudoteletypewriter
@ -1158,7 +1158,7 @@ ssize_t PtyWrite(struct Pty *pty, const void *data, size_t n) {
}
break;
default:
unreachable;
__builtin_unreachable();
}
}
return n;

View file

@ -16,13 +16,13 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/build/lib/ssemov.h"
#include "libc/intrin/pmovmskb.h"
#include "libc/str/str.h"
#include "tool/build/lib/address.h"
#include "tool/build/lib/endian.h"
#include "tool/build/lib/memory.h"
#include "tool/build/lib/modrm.h"
#include "tool/build/lib/ssemov.h"
#include "tool/build/lib/throw.h"
static void MovdquVdqWdq(struct Machine *m, uint32_t rde) {
@ -314,7 +314,7 @@ void OpMovWpsVps(struct Machine *m, uint32_t rde) {
MovssWpsVps(m, rde);
break;
default:
unreachable;
__builtin_unreachable();
}
}
@ -404,7 +404,7 @@ void OpMov0f10(struct Machine *m, uint32_t rde) {
MovssVpsWps(m, rde);
break;
default:
unreachable;
__builtin_unreachable();
}
}
@ -443,7 +443,7 @@ void OpMov0f12(struct Machine *m, uint32_t rde) {
MovsldupVqWq(m, rde);
break;
default:
unreachable;
__builtin_unreachable();
}
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/build/lib/stack.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/str/str.h"
@ -23,7 +24,6 @@
#include "tool/build/lib/endian.h"
#include "tool/build/lib/memory.h"
#include "tool/build/lib/modrm.h"
#include "tool/build/lib/stack.h"
#include "tool/build/lib/throw.h"
static const uint8_t kStackOsz[2][3] = {
@ -76,7 +76,7 @@ static void PushN(struct Machine *m, uint32_t rde, uint64_t x, unsigned osz) {
Write64(m->sp, v);
break;
default:
unreachable;
__builtin_unreachable();
}
WriteStackWord(AccessRam(m, v, osz, p, b, false), rde, osz, x);
EndStore(m, v, osz, p, b);
@ -113,7 +113,7 @@ static uint64_t PopN(struct Machine *m, uint32_t rde, uint16_t extra,
v += Read64(m->ss);
break;
default:
unreachable;
__builtin_unreachable();
}
return ReadStackWord(AccessRam(m, v, osz, p, b, true), osz);
}
@ -136,7 +136,7 @@ void OpPopZvq(struct Machine *m, uint32_t rde) {
Write16(RegRexbSrm(m, rde), x);
break;
default:
unreachable;
__builtin_unreachable();
}
}
@ -185,7 +185,7 @@ void OpLeave(struct Machine *m, uint32_t rde) {
Write16(m->bp, Pop(m, rde, 0));
break;
default:
unreachable;
__builtin_unreachable();
}
}
@ -276,7 +276,7 @@ relegated void OpPusha(struct Machine *m, uint32_t rde) {
case XED_MODE_LONG:
OpUd(m, rde);
default:
unreachable;
__builtin_unreachable();
}
}
@ -291,7 +291,7 @@ relegated void OpPopa(struct Machine *m, uint32_t rde) {
case XED_MODE_LONG:
OpUd(m, rde);
default:
unreachable;
__builtin_unreachable();
}
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/build/lib/string.h"
#include "libc/assert.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
@ -29,7 +30,6 @@
#include "tool/build/lib/machine.h"
#include "tool/build/lib/memory.h"
#include "tool/build/lib/modrm.h"
#include "tool/build/lib/string.h"
#include "tool/build/lib/throw.h"
static uint64_t ReadInt(uint8_t p[8], unsigned long w) {
@ -43,7 +43,7 @@ static uint64_t ReadInt(uint8_t p[8], unsigned long w) {
case 3:
return Read64(p);
default:
unreachable;
__builtin_unreachable();
}
}
@ -62,7 +62,7 @@ static void WriteInt(uint8_t p[8], uint64_t x, unsigned long w) {
Write64(p, x);
break;
default:
unreachable;
__builtin_unreachable();
}
}
@ -78,7 +78,7 @@ static void AddDi(struct Machine *m, uint32_t rde, uint64_t x) {
Write16(m->di, Read16(m->di) + x);
return;
default:
unreachable;
__builtin_unreachable();
}
}
@ -94,7 +94,7 @@ static void AddSi(struct Machine *m, uint32_t rde, uint64_t x) {
Write16(m->si, Read16(m->si) + x);
return;
default:
unreachable;
__builtin_unreachable();
}
}
@ -107,7 +107,7 @@ static uint64_t ReadCx(struct Machine *m, uint32_t rde) {
case XED_MODE_REAL:
return Read16(m->cx);
default:
unreachable;
__builtin_unreachable();
}
}

View file

@ -128,14 +128,14 @@ wontreturn void ShowUsage(FILE *f, int rc) {
fprintf(f, "Usage: %s RUNITD PROGRAM HOSTNAME[:RUNITDPORT[:SSHPORT]]...\n",
program_invocation_name);
exit(rc);
unreachable;
__builtin_unreachable();
}
void CheckExists(const char *path) {
if (!isregularfile(path)) {
fprintf(stderr, "error: %s: not found or irregular\n", path);
ShowUsage(stderr, EX_USAGE);
unreachable;
__builtin_unreachable();
}
}
@ -147,14 +147,14 @@ void Connect(void) {
if ((rc = getaddrinfo(g_hostname, _gc(xasprintf("%hu", g_runitdport)),
&kResolvHints, &ai)) != 0) {
FATALF("%s:%hu: EAI_%s %m", g_hostname, g_runitdport, gai_strerror(rc));
unreachable;
__builtin_unreachable();
}
ip4 = (const char *)&ai->ai_addr4->sin_addr;
if (ispublicip(ai->ai_family, &ai->ai_addr4->sin_addr)) {
FATALF("%s points to %hhu.%hhu.%hhu.%hhu"
" which isn't part of a local/private/testing subnet",
g_hostname, ip4[0], ip4[1], ip4[2], ip4[3]);
unreachable;
__builtin_unreachable();
}
DEBUGF("connecting to %d.%d.%d.%d port %d", ip4[0], ip4[1], ip4[2], ip4[3],
ntohs(ai->ai_addr4->sin_port));
@ -180,7 +180,7 @@ TryAgain:
if (t2 > t1 + MAX_WAIT_CONNECT_SECONDS) {
FATALF("timeout connecting to %s (%hhu.%hhu.%hhu.%hhu:%d)", g_hostname,
ip4[0], ip4[1], ip4[2], ip4[3], ntohs(ai->ai_addr4->sin_port));
unreachable;
__builtin_unreachable();
}
goto TryAgain;
}
@ -463,11 +463,11 @@ int main(int argc, char *argv[]) {
if (argc > 1 &&
(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
ShowUsage(stdout, 0);
unreachable;
__builtin_unreachable();
}
if (argc < 3) {
ShowUsage(stderr, EX_USAGE);
unreachable;
__builtin_unreachable();
}
CheckExists((g_runitd = argv[1]));
CheckExists((g_prog = argv[2]));

View file

@ -184,10 +184,10 @@ void GetOpts(int argc, char *argv[]) {
break;
case 'h':
ShowUsage(stdout, EXIT_SUCCESS);
unreachable;
__builtin_unreachable();
default:
ShowUsage(stderr, EX_USAGE);
unreachable;
__builtin_unreachable();
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -42,6 +42,7 @@ int main(int argc, char *argv[]) {
uint8_t *m;
CHECK_NE(MAP_FAILED, (m = mmap(0, n, PROT_READ, MAP_PRIVATE, fd, 0)));
int err;
uint8_t *b, *d, *p;
if ((p = FindEmbeddedApe(m, n))) {
b = p;
@ -49,8 +50,9 @@ int main(int argc, char *argv[]) {
} else {
b = m;
}
if (!(d = GetZipCdir(b, n))) {
fprintf(stderr, "%s: couldn't locate central directory\n", argv[1]);
if (!(d = GetZipEocd(b, n, &err))) {
fprintf(stderr, "%s: couldn't locate central directory [zip error %d]\n",
argv[1], err);
exit(1);
}
@ -58,8 +60,8 @@ int main(int argc, char *argv[]) {
uint8_t *zmap = m;
uint8_t *zbase = b;
uint8_t *zcdir = d;
DCHECK(IsZipCdir32(zbase, zsize, zcdir - zbase) ||
IsZipCdir64(zbase, zsize, zcdir - zbase));
DCHECK(IsZipEocd32(zbase, zsize, zcdir - zbase) == kZipOk ||
IsZipEocd64(zbase, zsize, zcdir - zbase) == kZipOk);
uint64_t cf;
uint64_t lf;

View file

@ -402,7 +402,8 @@ uint8_t *GetZipCdir32(const uint8_t *p, size_t n) {
if (n >= kZipCdirHdrMinSize) {
i = n - kZipCdirHdrMinSize;
do {
if (READ32LE(p + i) == kZipCdirHdrMagic && IsZipCdir32(p, n, i)) {
if (READ32LE(p + i) == kZipCdirHdrMagic &&
IsZipEocd32(p, n, i) == kZipOk) {
return (/*unconst*/ uint8_t *)(p + i);
}
} while (i--);

View file

@ -255,7 +255,7 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) {
void DisassembleZip(const char *path, uint8_t *p, size_t n) {
size_t i, records;
uint8_t *eocd, *cdir, *cf, *lf;
CHECK_NOTNULL((eocd = GetZipCdir(p, n)));
CHECK_NOTNULL((eocd = GetZipEocd(p, n, 0)));
records = GetZipCdirRecords(eocd);
cdir = p + GetZipCdirOffset(eocd);
for (i = 0, cf = cdir; i < records; ++i, cf += ZIP_CFILE_HDRSIZE(cf)) {

View file

@ -65,7 +65,6 @@
"noprune"
"reallocesque"
"nullterminated"
"unreachable"
"notpossible"
"_Hide"
"privileged"

View file

@ -4,9 +4,9 @@
#define FetchHeaderEqualCase(H, S) \
SlicesEqualCase(S, strlen(S), FetchHeaderData(H), FetchHeaderLength(H))
#define kaNONE 0
#define kaOPEN 1
#define kaKEEP 2
#define kaNONE 0
#define kaOPEN 1
#define kaKEEP 2
#define kaCLOSE 3
static int LuaFetch(lua_State *L) {
@ -66,7 +66,7 @@ static int LuaFetch(lua_State *L) {
lua_getfield(L, 2, "keepalive");
if (!lua_isnil(L, -1)) {
if (lua_istable(L, -1)) {
keepalive = kaOPEN; // will be updated based on host later
keepalive = kaOPEN; // will be updated based on host later
} else if (lua_isboolean(L, -1)) {
keepalive = lua_toboolean(L, -1) ? kaOPEN : kaNONE;
if (keepalive) {
@ -74,8 +74,9 @@ static int LuaFetch(lua_State *L) {
lua_setfield(L, 2, "keepalive");
}
} else {
return luaL_argerror(L, 2, "invalid keepalive value;"
" boolean or table expected");
return luaL_argerror(L, 2,
"invalid keepalive value;"
" boolean or table expected");
}
}
lua_getfield(L, 2, "headers");
@ -180,18 +181,18 @@ static int LuaFetch(lua_State *L) {
// check if hosthdr is in keepalive table
if (keepalive && lua_istable(L, 2)) {
lua_getfield(L, 2, "keepalive");
lua_getfield(L, -1, "close"); // aft: -2=tbl, -1=close
lua_getfield(L, -2, hosthdr); // aft: -3=tbl, -2=close, -1=hosthdr
lua_getfield(L, -1, "close"); // aft: -2=tbl, -1=close
lua_getfield(L, -2, hosthdr); // aft: -3=tbl, -2=close, -1=hosthdr
if (lua_isinteger(L, -1)) {
sock = lua_tointeger(L, -1);
keepalive = lua_toboolean(L, -2) ? kaCLOSE : kaKEEP;
// remove host mapping, as the socket is ether being closed
// (so needs to be removed) or will be added after the request is done;
// this also helps to keep the mapping clean in case of an error
lua_pushnil(L); // aft: -4=tbl, -3=close, -2=hosthdr, -1=nil
lua_pushnil(L); // aft: -4=tbl, -3=close, -2=hosthdr, -1=nil
lua_setfield(L, -4, hosthdr);
VERBOSEF("(ftch) reuse socket %d for host %s (and %s)",
sock, hosthdr, keepalive == kaCLOSE ? "close" : "keep");
VERBOSEF("(ftch) reuse socket %d for host %s (and %s)", sock, hosthdr,
keepalive == kaCLOSE ? "close" : "keep");
}
lua_settop(L, 2); // drop all added elements to keep the stack balanced
}
@ -221,8 +222,9 @@ static int LuaFetch(lua_State *L) {
"%s%s"
"\r\n",
method, _gc(EncodeUrl(&url, 0)), hosthdr,
(keepalive == kaNONE || keepalive == kaCLOSE) ? "close"
: (connhdr ? connhdr : "keep-alive"),
(keepalive == kaNONE || keepalive == kaCLOSE)
? "close"
: (connhdr ? connhdr : "keep-alive"),
agenthdr, conlenhdr, headers ? headers : "");
appendd(&request, body, bodylen);
requestlen = appendz(request).i;
@ -242,8 +244,9 @@ static int LuaFetch(lua_State *L) {
* Connect to server.
*/
ip = ntohl(((struct sockaddr_in *)addr->ai_addr)->sin_addr.s_addr);
DEBUGF("(ftch) client connecting %hhu.%hhu.%hhu.%hhu:%d", ip >> 24, ip >> 16,
ip >> 8, ip, ntohs(((struct sockaddr_in *)addr->ai_addr)->sin_port));
DEBUGF("(ftch) client connecting %hhu.%hhu.%hhu.%hhu:%d", ip >> 24,
ip >> 16, ip >> 8, ip,
ntohs(((struct sockaddr_in *)addr->ai_addr)->sin_port));
CHECK_NE(-1, (sock = GoodSocket(addr->ai_family, addr->ai_socktype,
addr->ai_protocol, false, &timeout)));
rc = connect(sock, addr->ai_addr, addr->ai_addrlen);
@ -440,7 +443,7 @@ static int LuaFetch(lua_State *L) {
if (rc) goto Finished;
break;
default:
unreachable;
__builtin_unreachable();
}
}
@ -452,9 +455,8 @@ Finished:
// check if the server has requested to close the connection
// https://www.rfc-editor.org/rfc/rfc2616#section-14.10
if (keepalive && keepalive != kaCLOSE
&& FetchHasHeader(kHttpConnection)
&& FetchHeaderEqualCase(kHttpConnection, "close")) {
if (keepalive && keepalive != kaCLOSE && FetchHasHeader(kHttpConnection) &&
FetchHeaderEqualCase(kHttpConnection, "close")) {
VERBOSEF("(ftch) close keepalive on server request");
keepalive = kaCLOSE;
}

View file

@ -298,7 +298,7 @@ int LuaParseParams(lua_State *L) {
return 1;
} else {
luaL_error(L, "out of memory");
unreachable;
__builtin_unreachable();
}
} else {
return lua_gettop(L);
@ -321,7 +321,7 @@ int LuaParseHost(lua_State *L) {
return 1;
} else {
luaL_error(L, "out of memory");
unreachable;
__builtin_unreachable();
}
} else {
return lua_gettop(L);
@ -340,7 +340,7 @@ int LuaBsr(lua_State *L) {
return 1;
} else {
luaL_argerror(L, 1, "zero");
unreachable;
__builtin_unreachable();
}
}
@ -351,7 +351,7 @@ int LuaBsf(lua_State *L) {
return 1;
} else {
luaL_argerror(L, 1, "zero");
unreachable;
__builtin_unreachable();
}
}
@ -381,7 +381,7 @@ int LuaIndentLines(lua_State *L) {
j = luaL_optinteger(L, 2, 1);
if (!(0 <= j && j <= 65535)) {
luaL_argerror(L, 2, "not in range 0..65535");
unreachable;
__builtin_unreachable();
}
p = IndentLines(p, n, &n, j);
lua_pushlstring(L, p, n);
@ -400,7 +400,7 @@ int LuaGetMonospaceWidth(lua_State *L) {
w = strwidth(luaL_checkstring(L, 1), luaL_optinteger(L, 2, 0) & 7);
} else {
luaL_argerror(L, 1, "not integer or string");
unreachable;
__builtin_unreachable();
}
lua_pushinteger(L, w);
return 1;
@ -490,7 +490,7 @@ int LuaBarf(lua_State *L) {
offset = luaL_checkinteger(L, 5);
if (offset < 1) {
luaL_error(L, "offset must be >= 1");
unreachable;
__builtin_unreachable();
}
--offset;
}
@ -498,11 +498,11 @@ int LuaBarf(lua_State *L) {
flags = O_WRONLY | O_SEQUENTIAL | luaL_optinteger(L, 4, O_TRUNC | O_CREAT);
if (flags & O_NONBLOCK) {
luaL_error(L, "O_NONBLOCK not allowed");
unreachable;
__builtin_unreachable();
}
if ((flags & O_APPEND) && offset) {
luaL_error(L, "O_APPEND with offset not possible");
unreachable;
__builtin_unreachable();
}
if ((fd = open(luaL_checkstring(L, 1), flags, mode)) == -1) {
return LuaUnixSysretErrno(L, "open", olderr);
@ -555,7 +555,7 @@ static int LuaCheckControlFlags(lua_State *L, int idx) {
int f = luaL_optinteger(L, idx, 0);
if (f & ~(kControlWs | kControlC0 | kControlC1)) {
luaL_argerror(L, idx, "invalid control flags");
unreachable;
__builtin_unreachable();
}
return f;
}
@ -582,7 +582,7 @@ int LuaEncodeLatin1(lua_State *L) {
return 1;
} else {
luaL_error(L, "out of memory");
unreachable;
__builtin_unreachable();
}
}
@ -592,7 +592,7 @@ int LuaGetRandomBytes(lua_State *L) {
n = luaL_optinteger(L, 1, 16);
if (!(n > 0 && n <= 256)) {
luaL_argerror(L, 1, "not in range 1..256");
unreachable;
__builtin_unreachable();
}
CHECK_EQ(n, getrandom(luaL_buffinitsize(L, &buf, n), n, 0));
luaL_pushresultsize(&buf, n);
@ -664,7 +664,7 @@ static dontinline int LuaCoderImpl(lua_State *L,
free(p);
} else {
luaL_error(L, "out of memory");
unreachable;
__builtin_unreachable();
}
return 1;
} else {
@ -739,7 +739,7 @@ int LuaEscapeLiteral(lua_State *L) {
return 1;
} else {
luaL_error(L, "out of memory");
unreachable;
__builtin_unreachable();
}
}
@ -856,7 +856,7 @@ int LuaBenchmark(lua_State *L) {
break;
} else if (attempts >= maxattempts) {
luaL_error(L, "system is under too much load to run benchmark");
unreachable;
__builtin_unreachable();
}
}
overhead = avgticks;
@ -878,7 +878,7 @@ int LuaBenchmark(lua_State *L) {
break;
} else if (attempts >= maxattempts) {
luaL_error(L, "system is under too much load to run benchmark");
unreachable;
__builtin_unreachable();
}
}
avgticks = MAX(avgticks - overhead, 0);
@ -898,12 +898,12 @@ static void LuaCompress2(lua_State *L, void *dest, size_t *destLen,
break;
case Z_BUF_ERROR:
luaL_error(L, "out of memory");
unreachable;
__builtin_unreachable();
case Z_STREAM_ERROR:
luaL_error(L, "invalid level");
unreachable;
__builtin_unreachable();
default:
unreachable;
__builtin_unreachable();
}
}
@ -948,7 +948,7 @@ int LuaUncompress(lua_State *L) {
if (lua_isnoneornil(L, 2)) {
if ((rc = unuleb64(p, n, &m)) == -1 || n < rc + 4) {
luaL_error(L, "compressed value too short to be valid");
unreachable;
__builtin_unreachable();
}
len = m;
crc = READ32LE(p + rc);
@ -956,14 +956,14 @@ int LuaUncompress(lua_State *L) {
if (uncompress((void *)q, &m, (unsigned char *)p + rc + 4, n) != Z_OK ||
m != len || crc32_z(0, q, m) != crc) {
luaL_error(L, "compressed value is corrupted");
unreachable;
__builtin_unreachable();
}
} else {
len = m = luaL_checkinteger(L, 2);
q = luaL_buffinitsize(L, &buf, m);
if (uncompress((void *)q, &m, (void *)p, n) != Z_OK || m != len) {
luaL_error(L, "compressed value is corrupted");
unreachable;
__builtin_unreachable();
}
}
luaL_pushresultsize(&buf, m);

View file

@ -543,10 +543,10 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p,
goto StringFailureWithReason;
default:
unreachable;
__builtin_unreachable();
}
}
unreachable;
__builtin_unreachable();
StringFailureWithReason:
luaL_pushresultsize(&b, 0);
lua_pop(L, 1);

View file

@ -72,7 +72,7 @@ static int LuaMaxmindOpen(lua_State *L) {
if ((err = MMDB_open(p, 0, &db->mmdb)) != MMDB_SUCCESS) {
free(db);
luaL_error(L, "MMDB_open(%s) → MMDB_%s", p, GetMmdbError(err));
unreachable;
__builtin_unreachable();
}
db->refs = 1;
udb = lua_newuserdatauv(L, sizeof(db), 1);
@ -88,7 +88,7 @@ static wontreturn void LuaThrowMaxmindIpError(lua_State *L,
(ip & 0xff000000) >> 030, (ip & 0x00ff0000) >> 020,
(ip & 0x0000ff00) >> 010, (ip & 0x000000ff) >> 000,
GetMmdbError(err));
unreachable;
__builtin_unreachable();
}
static int LuaMaxmindDbLookup(lua_State *L) {

View file

@ -106,7 +106,7 @@ static int LuaPathJoin(lua_State *L) {
return 1;
} else {
luaL_error(L, "missing argument");
unreachable;
__builtin_unreachable();
}
}

View file

@ -87,7 +87,7 @@ static int LuaReSearch(lua_State *L) {
if (f & ~(REG_EXTENDED | REG_ICASE | REG_NEWLINE | REG_NOSUB |
REG_NOTBOL << 8 | REG_NOTEOL << 8)) {
luaL_argerror(L, 3, "invalid flags");
unreachable;
__builtin_unreachable();
}
if ((r = LuaReCompileImpl(L, p, f))) {
return LuaReSearchImpl(L, r, s, f);
@ -104,7 +104,7 @@ static int LuaReCompile(lua_State *L) {
f = luaL_optinteger(L, 2, 0);
if (f & ~(REG_EXTENDED | REG_ICASE | REG_NEWLINE | REG_NOSUB)) {
luaL_argerror(L, 2, "invalid flags");
unreachable;
__builtin_unreachable();
}
if ((r = LuaReCompileImpl(L, p, f))) {
return 1;
@ -125,7 +125,7 @@ static int LuaReRegexSearch(lua_State *L) {
f = luaL_optinteger(L, 3, 0);
if (f & ~(REG_NOTBOL << 8 | REG_NOTEOL << 8)) {
luaL_argerror(L, 3, "invalid flags");
unreachable;
__builtin_unreachable();
}
return LuaReSearchImpl(L, r, s, f);
}

View file

@ -2188,7 +2188,7 @@ static bool OpenZip(bool force) {
} else {
b = m;
}
if ((d = GetZipCdir(b, n))) {
if ((d = GetZipEocd(b, n, 0))) {
if (zmap) {
LOGIFNEG1(munmap(zmap, zbase + zsize - zmap));
}
@ -2196,8 +2196,8 @@ static bool OpenZip(bool force) {
zbase = b;
zsize = n;
zcdir = d;
DCHECK(IsZipCdir32(zbase, zsize, zcdir - zbase) ||
IsZipCdir64(zbase, zsize, zcdir - zbase));
DCHECK(IsZipEocd32(zbase, zsize, zcdir - zbase) == kZipOk ||
IsZipEocd64(zbase, zsize, zcdir - zbase) == kZipOk);
memcpy(&zst, &st, sizeof(st));
IndexAssets();
return true;
@ -3331,7 +3331,7 @@ static const char *LuaCheckPath(lua_State *L, int idx, size_t *pathlen) {
if (!IsReasonablePath(path, *pathlen)) {
WARNF("(srvr) bad path %`'.*s", *pathlen, path);
luaL_argerror(L, idx, "bad path");
unreachable;
__builtin_unreachable();
}
}
return path;
@ -3347,7 +3347,7 @@ static const char *LuaCheckHost(lua_State *L, int idx, size_t *hostlen) {
if (!IsAcceptableHost(host, *hostlen)) {
WARNF("(srvr) bad host %`'.*s", *hostlen, host);
luaL_argerror(L, idx, "bad host");
unreachable;
__builtin_unreachable();
}
}
return host;
@ -3357,7 +3357,7 @@ static void OnlyCallFromInitLua(lua_State *L, const char *api) {
if (isinitialized) {
luaL_error(L, "%s() should be called %s", api,
"from the global scope of .init.lua");
unreachable;
__builtin_unreachable();
}
}
@ -3365,7 +3365,7 @@ static void OnlyCallFromMainProcess(lua_State *L, const char *api) {
if (__isworker) {
luaL_error(L, "%s() should be called %s", api,
"from .init.lua or the repl");
unreachable;
__builtin_unreachable();
}
}
@ -3373,7 +3373,7 @@ static void OnlyCallDuringConnection(lua_State *L, const char *api) {
if (!ishandlingconnection) {
luaL_error(L, "%s() can only be called %s", api,
"while handling a connection");
unreachable;
__builtin_unreachable();
}
}
@ -3381,7 +3381,7 @@ static void OnlyCallDuringRequest(lua_State *L, const char *api) {
if (!ishandlingrequest) {
luaL_error(L, "%s() can only be called %s", api,
"while handling a request");
unreachable;
__builtin_unreachable();
}
}
@ -3432,7 +3432,7 @@ static int LuaServeRedirect(lua_State *L) {
code = luaL_checkinteger(L, 1);
if (!(300 <= code && code <= 399)) {
luaL_argerror(L, 1, "bad status code");
unreachable;
__builtin_unreachable();
}
location = luaL_checklstring(L, 2, &loclen);
if (cpm.msg.version < 10) {
@ -3441,7 +3441,7 @@ static int LuaServeRedirect(lua_State *L) {
} else {
if (!(eval = EncodeHttpHeaderValue(location, loclen, 0))) {
luaL_argerror(L, 2, "invalid location");
unreachable;
__builtin_unreachable();
}
VERBOSEF("(rsp) %d redirect to %`'s", code, location);
cpm.luaheaderp =
@ -3489,11 +3489,11 @@ static int LuaProgramTrustedIp(lua_State *L) {
cidr = luaL_optinteger(L, 2, 32);
if (!(0 <= ip && ip <= 0xffffffff)) {
luaL_argerror(L, 1, "ip out of range");
unreachable;
__builtin_unreachable();
}
if (!(0 <= cidr && cidr <= 32)) {
luaL_argerror(L, 2, "cidr should be 0 .. 32");
unreachable;
__builtin_unreachable();
}
ip32 = ip;
imask = ~(0xffffffffu << (32 - cidr));
@ -3501,7 +3501,7 @@ static int LuaProgramTrustedIp(lua_State *L) {
luaL_argerror(L, 1,
"ip address isn't the network address; "
"it has bits masked by the cidr");
unreachable;
__builtin_unreachable();
}
ProgramTrustedIp(ip, cidr);
return 0;
@ -3512,7 +3512,7 @@ static int LuaIsTrusted(lua_State *L) {
ip = luaL_checkinteger(L, 1);
if (!(0 <= ip && ip <= 0xffffffff)) {
luaL_argerror(L, 1, "ip out of range");
unreachable;
__builtin_unreachable();
}
lua_pushboolean(L, IsTrustedIp(ip));
return 1;
@ -3527,7 +3527,7 @@ static int LuaRespond(lua_State *L, char *R(unsigned, const char *)) {
code = luaL_checkinteger(L, 1);
if (!(100 <= code && code <= 999)) {
luaL_argerror(L, 1, "bad status code");
unreachable;
__builtin_unreachable();
}
if (lua_isnoneornil(L, 2)) {
cpm.luaheaderp = R(code, GetHttpReason(code));
@ -3538,7 +3538,7 @@ static int LuaRespond(lua_State *L, char *R(unsigned, const char *)) {
free(p);
} else {
luaL_argerror(L, 2, "invalid");
unreachable;
__builtin_unreachable();
}
}
return 0;
@ -4234,12 +4234,12 @@ static int LuaSetHeader(lua_State *L) {
if ((h = GetHttpHeader(key, keylen)) == -1) {
if (!IsValidHttpToken(key, keylen)) {
luaL_argerror(L, 1, "invalid");
unreachable;
__builtin_unreachable();
}
}
if (!(eval = EncodeHttpHeaderValue(val, vallen, &evallen))) {
luaL_argerror(L, 2, "invalid");
unreachable;
__builtin_unreachable();
}
p = GetLuaResponse();
while (p - hdrbuf.p + keylen + 2 + evallen + 2 + 512 > hdrbuf.n) {
@ -4313,11 +4313,11 @@ static int LuaSetCookie(lua_State *L) {
if (!IsValidHttpToken(key, keylen)) {
luaL_argerror(L, 1, "invalid");
unreachable;
__builtin_unreachable();
}
if (!IsValidCookieValue(val, vallen)) {
luaL_argerror(L, 2, "invalid");
unreachable;
__builtin_unreachable();
}
ishostpref = keylen > strlen(hostpref) &&
@ -4329,7 +4329,7 @@ static int LuaSetCookie(lua_State *L) {
luaL_argerror(
L, 1,
_gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref)));
unreachable;
__builtin_unreachable();
}
appends(&buf, key);
@ -4346,7 +4346,7 @@ static int LuaSetCookie(lua_State *L) {
expires = lua_tostring(L, -1);
if (!ParseHttpDateTime(expires, -1)) {
luaL_argerror(L, 3, "invalid data format in Expires");
unreachable;
__builtin_unreachable();
}
}
appends(&buf, "; Expires=");
@ -4587,7 +4587,7 @@ static int LuaProgramSslPresharedKey(lua_State *L) {
p2 = luaL_checklstring(L, 2, &n2);
if (!n1 || n1 > MBEDTLS_PSK_MAX_LEN || !n2) {
luaL_argerror(L, 1, "bad preshared key length");
unreachable;
__builtin_unreachable();
}
psk.key = memcpy(malloc(n1), p1, n1);
psk.key_len = n1;
@ -4613,7 +4613,7 @@ static int LuaProgramSslCiphersuite(lua_State *L) {
OnlyCallFromInitLua(L, "ProgramSslCiphersuite");
if (!(suite = GetCipherSuite(luaL_checkstring(L, 1)))) {
luaL_argerror(L, 1, "unsupported or unknown ciphersuite");
unreachable;
__builtin_unreachable();
}
suites.p = realloc(suites.p, (++suites.n + 1) * sizeof(*suites.p));
suites.p[suites.n - 1] = suite->id;
@ -4813,7 +4813,7 @@ static int LuaBlackhole(lua_State *L) {
ip = luaL_checkinteger(L, 1);
if (!(0 <= ip && ip <= 0xffffffff)) {
luaL_argerror(L, 1, "ip out of range");
unreachable;
__builtin_unreachable();
}
lua_pushboolean(L, Blackhole(ip));
return 1;
@ -4845,7 +4845,7 @@ static int LuaAcquireToken(lua_State *L) {
uint32_t ip;
if (!tokenbucket.cidr) {
luaL_error(L, "ProgramTokenBucket() needs to be called first");
unreachable;
__builtin_unreachable();
}
GetClientAddr(&ip, 0);
lua_pushinteger(L, AcquireToken(tokenbucket.b, luaL_optinteger(L, 1, ip),
@ -4857,7 +4857,7 @@ static int LuaCountTokens(lua_State *L) {
uint32_t ip;
if (!tokenbucket.cidr) {
luaL_error(L, "ProgramTokenBucket() needs to be called first");
unreachable;
__builtin_unreachable();
}
GetClientAddr(&ip, 0);
lua_pushinteger(L, CountTokens(tokenbucket.b, luaL_optinteger(L, 1, ip),
@ -4868,7 +4868,7 @@ static int LuaCountTokens(lua_State *L) {
static int LuaProgramTokenBucket(lua_State *L) {
if (tokenbucket.cidr) {
luaL_error(L, "ProgramTokenBucket() can only be called once");
unreachable;
__builtin_unreachable();
}
lua_Number replenish = luaL_optnumber(L, 1, 1); // per second
lua_Integer cidr = luaL_optinteger(L, 2, 24);
@ -4877,31 +4877,31 @@ static int LuaProgramTokenBucket(lua_State *L) {
lua_Integer ban = luaL_optinteger(L, 5, MIN(ignore / 10, 1));
if (!(1 / 3600. <= replenish && replenish <= 1e6)) {
luaL_argerror(L, 1, "require 1/3600 <= replenish <= 1e6");
unreachable;
__builtin_unreachable();
}
if (!(8 <= cidr && cidr <= 32)) {
luaL_argerror(L, 2, "require 8 <= cidr <= 32");
unreachable;
__builtin_unreachable();
}
if (!(-1 <= reject && reject <= 126)) {
luaL_argerror(L, 3, "require -1 <= reject <= 126");
unreachable;
__builtin_unreachable();
}
if (!(-1 <= ignore && ignore <= 126)) {
luaL_argerror(L, 4, "require -1 <= ignore <= 126");
unreachable;
__builtin_unreachable();
}
if (!(-1 <= ban && ban <= 126)) {
luaL_argerror(L, 5, "require -1 <= ban <= 126");
unreachable;
__builtin_unreachable();
}
if (!(ignore <= reject)) {
luaL_argerror(L, 4, "require ignore <= reject");
unreachable;
__builtin_unreachable();
}
if (!(ban <= ignore)) {
luaL_argerror(L, 5, "require ban <= ignore");
unreachable;
__builtin_unreachable();
}
VERBOSEF("(token) deploying %,ld buckets "
"(one for every %ld ips) "

View file

@ -309,7 +309,7 @@ SendAnother:
if (rc) goto Finished;
break;
default:
unreachable;
__builtin_unreachable();
}
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/printf.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/runtime/runtime.h"
@ -24,7 +25,6 @@
#include "tool/plinko/lib/char.h"
#include "tool/plinko/lib/plinko.h"
#include "tool/plinko/lib/print.h"
#include "tool/plinko/lib/printf.h"
static inline long GetVarInt(va_list va, signed char t) {
if (t <= 0) return va_arg(va, int);
@ -118,7 +118,7 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
}
break;
default:
unreachable;
__builtin_unreachable();
}
EmitFormatByte:
PrintChar(fd, c);

View file

@ -32,11 +32,13 @@ EOF
exit 0
fi
UNDEF="-D__COSMOPOLITAN__"
PREDEF="-include libc/integral/normalize.inc"
CXX="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-g++"
OBJCOPY="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-objcopy"
CCFLAGS="-g -fdata-sections -ffunction-sections -fno-pie -mno-tls-direct-seg-refs -mno-red-zone -fportcosmo -include $COSMO/build/portcosmo.h"
CCFLAGS="-g -fdata-sections -ffunction-sections -fno-pie -mno-tls-direct-seg-refs -mno-red-zone -fportcosmo"
CXXFLAGS="-fno-exceptions -fuse-cxa-atexit -fno-threadsafe-statics"
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem $COSMOS/include -isystem $COSMO/libc/isystem -include libc/integral/normalize.inc"
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem $COSMOS/include -isystem $COSMO/libc/isystem"
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -L$COSMOS/lib -Wl,-T,$COSMO/o/ape/public/ape.lds $COSMO/o/ape/ape-no-modify-self.o $COSMO/o/libc/crt/crt.o"
LDLIBS="$COSMO/o/third_party/libcxx/libcxx.a $COSMO/o/cosmopolitan.a"
@ -115,12 +117,12 @@ fi
LINKING=
if [ "$HAS_E" = "1" ]; then
set -- $CCFLAGS $CPPFLAGS "$@"
set -- $UNDEF $CCFLAGS $CPPFLAGS "$@"
elif [ "$HAS_C" = "1" ]; then
set -- $CCFLAGS $CXXFLAGS $CPPFLAGS "$@" $FRAME
set -- $UNDEF $PREDEF $CCFLAGS $CXXFLAGS $CPPFLAGS "$@" $FRAME
else
LINKING=1
set -- $LDFLAGS $CXXFLAGS $CPPFLAGS "$@" $LDLIBS -Wl,-z,common-page-size=65536 -Wl,-z,max-page-size=65536 $FRAME
set -- $UNDEF $PREDEF $LDFLAGS $CXXFLAGS $CPPFLAGS "$@" $LDLIBS -Wl,-z,common-page-size=65536 -Wl,-z,max-page-size=65536 $FRAME
fi
set -- "$CXX" "$@"

View file

@ -32,11 +32,13 @@ EOF
exit 0
fi
UNDEF="-D__COSMOPOLITAN__"
PREDEF="-include libc/integral/normalize.inc"
CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
OBJCOPY="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-objcopy"
CCFLAGS="-g -fdata-sections -ffunction-sections -fno-pie -mno-tls-direct-seg-refs -mno-red-zone -fportcosmo -include $COSMO/build/portcosmo.h"
CCFLAGS="-g -fdata-sections -ffunction-sections -fno-pie -mno-tls-direct-seg-refs -mno-red-zone -fportcosmo"
CFLAGS=
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem $COSMOS/include -isystem $COSMO/libc/isystem -include libc/integral/normalize.inc"
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem $COSMOS/include -isystem $COSMO/libc/isystem"
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -L$COSMOS/lib -Wl,-T,$COSMO/o/ape/public/ape.lds $COSMO/o/ape/ape-no-modify-self.o $COSMO/o/libc/crt/crt.o"
LDLIBS="$COSMO/o/cosmopolitan.a"
@ -115,12 +117,12 @@ fi
LINKING=
if [ "$HAS_E" = "1" ]; then
set -- $CCFLAGS $CPPFLAGS "$@"
set -- $UNDEF $CCFLAGS $CPPFLAGS "$@"
elif [ "$HAS_C" = "1" ]; then
set -- $CCFLAGS $CFLAGS $CPPFLAGS "$@" $FRAME
set -- $UNDEF $PREDEF $CCFLAGS $CFLAGS $CPPFLAGS "$@" $FRAME
else
LINKING=1
set -- $LDFLAGS $CFLAGS $CPPFLAGS "$@" $LDLIBS -Wl,-z,common-page-size=65536 -Wl,-z,max-page-size=65536 $FRAME
set -- $UNDEF $PREDEF $LDFLAGS $CFLAGS $CPPFLAGS "$@" $LDLIBS -Wl,-z,common-page-size=65536 -Wl,-z,max-page-size=65536 $FRAME
fi
set -- "$CC" "$@"

View file

@ -706,7 +706,7 @@ static void LoadRanges(void) {
}
break;
default:
unreachable;
__builtin_unreachable();
}
}
}