Support thread local storage

This commit is contained in:
Justine Tunney 2022-05-16 13:20:08 -07:00
parent 91ee2b19d4
commit 55de4ca6b5
197 changed files with 1483 additions and 874 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
@ -107,8 +108,16 @@ int LoadZipArgsImpl(int *argc, char ***argv, char *data) {
* If the special argument `...` *is* encountered, then it'll be
* replaced with whatever CLI args were specified by the user.
*
* @return 0 on success, or -1 w/ errno
* @return 0 on success, or -1 if not found w/o errno clobber
*/
int LoadZipArgs(int *argc, char ***argv) {
return LoadZipArgsImpl(argc, argv, xslurp("/zip/.args", 0));
int e;
char *p;
e = errno;
if ((p = xslurp("/zip/.args", 0))) {
return LoadZipArgsImpl(argc, argv, p);
} else {
errno = e;
return -1;
}
}

View file

@ -21,6 +21,7 @@ TOOL_ARGS_A_DIRECTDEPS = \
LIBC_NEXGEN32E \
LIBC_STR \
LIBC_STUBS \
LIBC_SYSV \
LIBC_X \
LIBC_ZIPOS

View file

@ -18,7 +18,7 @@
*/
#include "libc/macros.internal.h"
.macro .errno local:req linux:req
.macro .e local:req linux:req
.globl \local
.long \local-kLinuxErrnos
.byte \linux
@ -30,94 +30,94 @@
.rodata
.align 4
kLinuxErrnos:
.errno EPERM,1
.errno ENOENT,2
.errno ESRCH,3
.errno EINTR,4
.errno EIO,5
.errno ENXIO,6
.errno E2BIG,7
.errno ENOEXEC,8
.errno EBADF,9
.errno ECHILD,10
.errno EAGAIN,11
.errno ENOMEM,12
.errno EACCES,13
.errno EFAULT,14
.errno ENOTBLK,15
.errno EBUSY,16
.errno EEXIST,17
.errno EXDEV,18
.errno ENODEV,19
.errno ENOTDIR,20
.errno EISDIR,21
.errno EINVAL,22
.errno ENFILE,23
.errno EMFILE,24
.errno ENOTTY,25
.errno ETXTBSY,26
.errno EFBIG,27
.errno ENOSPC,28
.errno ESPIPE,29
.errno EROFS,30
.errno EMLINK,31
.errno EPIPE,32
.errno EDOM,33
.errno ERANGE,34
.errno EDEADLK,35
.errno ENAMETOOLONG,36
.errno ENOLCK,37
.errno ENOSYS,38
.errno ENOTEMPTY,39
.errno ELOOP,40
.errno ENOMSG,42
.errno EIDRM,43
.errno EUSERS,87
.errno ENOTSOCK,88
.errno EDESTADDRREQ,89
.errno EMSGSIZE,90
.errno EPROTOTYPE,91
.errno ENOPROTOOPT,92
.errno EPROTONOSUPPORT,93
.errno ESOCKTNOSUPPORT,94
.errno EOPNOTSUPP,95
.errno EPFNOSUPPORT,96
.errno EAFNOSUPPORT,97
.errno EADDRINUSE,98
.errno EADDRNOTAVAIL,99
.errno EL2NSYNC,45
.errno EL3HLT,46
.errno EL3RST,47
.errno ELNRNG,48
.errno ETIME,62
.errno ENONET,64
.errno EREMOTE,66
.errno EPROTO,71
.errno EBADMSG,74
.errno EOVERFLOW,75
.errno EILSEQ,84
.errno ERESTART,85
.errno ENETDOWN,100
.errno ENETUNREACH,101
.errno ENETRESET,102
.errno ECONNABORTED,103
.errno ECONNRESET,104
.errno ENOBUFS,105
.errno EISCONN,106
.errno ENOTCONN,107
.errno ESHUTDOWN,108
.errno ETOOMANYREFS,109
.errno ETIMEDOUT,110
.errno ECONNREFUSED,111
.errno EHOSTDOWN,112
.errno EHOSTUNREACH,113
.errno EALREADY,114
.errno EINPROGRESS,115
.errno ESTALE,116
.errno EDQUOT,122
.errno ECANCELED,125
.errno EOWNERDEAD,130
.errno ENOTRECOVERABLE,131
.e EPERM,1
.e ENOENT,2
.e ESRCH,3
.e EINTR,4
.e EIO,5
.e ENXIO,6
.e E2BIG,7
.e ENOEXEC,8
.e EBADF,9
.e ECHILD,10
.e EAGAIN,11
.e ENOMEM,12
.e EACCES,13
.e EFAULT,14
.e ENOTBLK,15
.e EBUSY,16
.e EEXIST,17
.e EXDEV,18
.e ENODEV,19
.e ENOTDIR,20
.e EISDIR,21
.e EINVAL,22
.e ENFILE,23
.e EMFILE,24
.e ENOTTY,25
.e ETXTBSY,26
.e EFBIG,27
.e ENOSPC,28
.e ESPIPE,29
.e EROFS,30
.e EMLINK,31
.e EPIPE,32
.e EDOM,33
.e ERANGE,34
.e EDEADLK,35
.e ENAMETOOLONG,36
.e ENOLCK,37
.e ENOSYS,38
.e ENOTEMPTY,39
.e ELOOP,40
.e ENOMSG,42
.e EIDRM,43
.e EUSERS,87
.e ENOTSOCK,88
.e EDESTADDRREQ,89
.e EMSGSIZE,90
.e EPROTOTYPE,91
.e ENOPROTOOPT,92
.e EPROTONOSUPPORT,93
.e ESOCKTNOSUPPORT,94
.e EOPNOTSUPP,95
.e EPFNOSUPPORT,96
.e EAFNOSUPPORT,97
.e EADDRINUSE,98
.e EADDRNOTAVAIL,99
.e EL2NSYNC,45
.e EL3HLT,46
.e EL3RST,47
.e ELNRNG,48
.e ETIME,62
.e ENONET,64
.e EREMOTE,66
.e EPROTO,71
.e EBADMSG,74
.e EOVERFLOW,75
.e EILSEQ,84
.e ERESTART,85
.e ENETDOWN,100
.e ENETUNREACH,101
.e ENETRESET,102
.e ECONNABORTED,103
.e ECONNRESET,104
.e ENOBUFS,105
.e EISCONN,106
.e ENOTCONN,107
.e ESHUTDOWN,108
.e ETOOMANYREFS,109
.e ETIMEDOUT,110
.e ECONNREFUSED,111
.e EHOSTDOWN,112
.e EHOSTUNREACH,113
.e EALREADY,114
.e EINPROGRESS,115
.e ESTALE,116
.e EDQUOT,122
.e ECANCELED,125
.e EOWNERDEAD,130
.e ENOTRECOVERABLE,131
.long 0
.byte 0
.endobj kLinuxErrnos,globl

View file

@ -213,6 +213,15 @@
"scp $f $f.dbg win10:"
"ssh win10 ./%s.com"))
mode name (file-name-nondirectory name)))
((eq kind 'run-xnu)
(format
(cosmo-join
" && "
`("m=%s; f=o/$m/%s.com"
,(concat "make -j12 -O $f MODE=$m")
"scp $f $f.dbg xnu:"
"ssh xnu ./%s.com"))
mode name (file-name-nondirectory name)))
((and (equal suffix "")
(cosmo-contains "_test." (buffer-file-name)))
(format "m=%s; make -j12 -O MODE=$m %s"

View file

@ -96,7 +96,7 @@
*/
struct UnixErrno {
int errno;
int errno_;
int winerr;
const char *call;
};
@ -185,7 +185,7 @@ static int SysretErrno(lua_State *L, const char *call, int olderr) {
lua_pushnil(L);
ep = lua_newuserdatauv(L, sizeof(*ep), 1);
luaL_setmetatable(L, "unix.Errno");
ep->errno = unixerr;
ep->errno_ = unixerr;
ep->winerr = winerr;
ep->call = call;
errno = olderr;
@ -2047,7 +2047,7 @@ static struct UnixErrno *GetUnixErrno(lua_State *L) {
// unix.Errno:errno()
// └─→ errno:int
static int LuaUnixErrnoErrno(lua_State *L) {
return ReturnInteger(L, GetUnixErrno(L)->errno);
return ReturnInteger(L, GetUnixErrno(L)->errno_);
}
static int LuaUnixErrnoWinerr(lua_State *L) {
@ -2055,11 +2055,11 @@ static int LuaUnixErrnoWinerr(lua_State *L) {
}
static int LuaUnixErrnoName(lua_State *L) {
return ReturnString(L, strerrno(GetUnixErrno(L)->errno));
return ReturnString(L, strerrno(GetUnixErrno(L)->errno_));
}
static int LuaUnixErrnoDoc(lua_State *L) {
return ReturnString(L, strerdoc(GetUnixErrno(L)->errno));
return ReturnString(L, strerdoc(GetUnixErrno(L)->errno_));
}
static int LuaUnixErrnoCall(lua_State *L) {
@ -2071,10 +2071,10 @@ static int LuaUnixErrnoToString(lua_State *L) {
struct UnixErrno *e;
e = GetUnixErrno(L);
if (e->call) {
strerror_wr(e->errno, e->winerr, msg, sizeof(msg));
strerror_wr(e->errno_, e->winerr, msg, sizeof(msg));
lua_pushfstring(L, "%s() failed: %s", e->call, msg);
} else {
lua_pushstring(L, strerrno(e->errno));
lua_pushstring(L, strerrno(e->errno_));
}
return 1;
}

View file

@ -5404,7 +5404,7 @@ static void LogClose(const char *reason) {
INFOF("(stat) %s %s with %,ld unprocessed and %,d handled (%,d workers)",
DescribeClient(), reason, amtread, messageshandled, shared->workers);
} else {
DEBUGF("(stat) %s %s with %,d requests handled", DescribeClient(), reason,
DEBUGF("(stat) %s %s with %,d messages handled", DescribeClient(), reason,
messageshandled);
}
}
@ -6175,8 +6175,6 @@ static bool HandleMessageActual(void) {
p = stpcpy(p, referrerpolicy);
p = stpcpy(p, "\r\n");
}
LockInc(&shared->c.messageshandled);
++messageshandled;
if (loglatency || LOGGABLE(kLogDebug)) {
now = nowl();
LOGF(kLogDebug, "(stat) %`'.*s latency r: %,ldµs c: %,ldµs",