mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
Make improvements
- We now serialize the file descriptor table when spawning / executing processes on Windows. This means you can now inherit more stuff than just standard i/o. It's needed by bash, which duplicates the console to file descriptor #255. We also now do a better job serializing the environment variables, so you're less likely to encounter E2BIG when using your bash shell. We also no longer coerce environ to uppercase - execve() on Windows now remotely controls its parent process to make them spawn a replacement for itself. Then it'll be able to terminate immediately once the spawn succeeds, without having to linger around for the lifetime as a shell process for proxying the exit code. When process worker thread running in the parent sees the child die, it's given a handle to the new child, to replace it in the process table. - execve() and posix_spawn() on Windows will now provide CreateProcess an explicit handle list. This allows us to remove handle locks which enables better fork/spawn concurrency, with seriously correct thread safety. Other codebases like Go use the same technique. On the other hand fork() still favors the conventional WIN32 inheritence approach which can be a little bit messy, but is *controlled* by guaranteeing perfectly clean slates at both the spawning and execution boundaries - sigset_t is now 64 bits. Having it be 128 bits was a mistake because there's no reason to use that and it's only supported by FreeBSD. By using the system word size, signal mask manipulation on Windows goes very fast. Furthermore @asyncsignalsafe funcs have been rewritten on Windows to take advantage of signal masking, now that it's much more pleasant to use. - All the overlapped i/o code on Windows has been rewritten for pretty good signal and cancelation safety. We're now able to ensure overlap data structures are cleaned up so long as you don't longjmp() out of out of a signal handler that interrupted an i/o operation. Latencies are also improved thanks to the removal of lots of "busy wait" code. Waits should be optimal for everything except poll(), which shall be the last and final demon we slay in the win32 i/o horror show. - getrusage() on Windows is now able to report RUSAGE_CHILDREN as well as RUSAGE_SELF, thanks to aggregation in the process manager thread.
This commit is contained in:
parent
af7cb3c82f
commit
791f79fcb3
382 changed files with 4008 additions and 4511 deletions
56
third_party/lua/lunix.c
vendored
56
third_party/lua/lunix.c
vendored
|
@ -157,8 +157,8 @@ static lua_Integer FixLimit(long x) {
|
|||
}
|
||||
}
|
||||
|
||||
static void LuaPushSigset(lua_State *L, struct sigset set) {
|
||||
struct sigset *sp = lua_newuserdatauv(L, sizeof(*sp), 1);
|
||||
static void LuaPushSigset(lua_State *L, sigset_t set) {
|
||||
sigset_t *sp = lua_newuserdatauv(L, sizeof(*sp), 1);
|
||||
luaL_setmetatable(L, "unix.Sigset");
|
||||
*sp = set;
|
||||
}
|
||||
|
@ -1541,7 +1541,7 @@ static int LuaUnixAccept(lua_State *L) {
|
|||
// └─→ nil, unix.Errno
|
||||
static int LuaUnixPoll(lua_State *L) {
|
||||
size_t nfds;
|
||||
struct sigset *mask;
|
||||
sigset_t *mask;
|
||||
struct timespec ts, *tsp;
|
||||
struct pollfd *fds, *fds2;
|
||||
int i, events, olderr = errno;
|
||||
|
@ -1693,8 +1693,8 @@ static int LuaUnixShutdown(lua_State *L) {
|
|||
// ├─→ oldmask:unix.Sigset
|
||||
// └─→ nil, unix.Errno
|
||||
static int LuaUnixSigprocmask(lua_State *L) {
|
||||
sigset_t oldmask;
|
||||
int olderr = errno;
|
||||
struct sigset oldmask;
|
||||
if (!sigprocmask(luaL_checkinteger(L, 1),
|
||||
luaL_checkudata(L, 2, "unix.Sigset"), &oldmask)) {
|
||||
LuaPushSigset(L, oldmask);
|
||||
|
@ -1726,7 +1726,7 @@ static void LuaUnixOnSignal(int sig, siginfo_t *si, void *ctx) {
|
|||
// ├─→ oldhandler:func|int, flags:int, mask:unix.Sigset
|
||||
// └─→ nil, unix.Errno
|
||||
static int LuaUnixSigaction(lua_State *L) {
|
||||
struct sigset *mask;
|
||||
sigset_t *mask;
|
||||
int i, n, sig, olderr = errno;
|
||||
struct sigaction sa, oldsa, *saptr = &sa;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
|
@ -1765,8 +1765,7 @@ static int LuaUnixSigaction(lua_State *L) {
|
|||
}
|
||||
if (!lua_isnoneornil(L, 4)) {
|
||||
mask = luaL_checkudata(L, 4, "unix.Sigset");
|
||||
sa.sa_mask.__bits[0] |= mask->__bits[0];
|
||||
sa.sa_mask.__bits[1] |= mask->__bits[1];
|
||||
sigorset(&sa.sa_mask, &sa.sa_mask, mask);
|
||||
lua_remove(L, 4);
|
||||
}
|
||||
if (lua_isnoneornil(L, 3)) {
|
||||
|
@ -1817,8 +1816,8 @@ static int LuaUnixSigsuspend(lua_State *L) {
|
|||
// ├─→ mask:unix.Sigset
|
||||
// └─→ nil, unix.Errno
|
||||
static int LuaUnixSigpending(lua_State *L) {
|
||||
sigset_t mask;
|
||||
int olderr = errno;
|
||||
struct sigset mask;
|
||||
if (!sigpending(&mask)) {
|
||||
LuaPushSigset(L, mask);
|
||||
return 1;
|
||||
|
@ -2850,10 +2849,10 @@ static int LuaUnixMemoryWait(lua_State *L) {
|
|||
ts.tv_nsec = luaL_optinteger(L, 5, 0);
|
||||
deadline = &ts;
|
||||
}
|
||||
BEGIN_CANCELLATION_POINT;
|
||||
BEGIN_CANCELATION_POINT;
|
||||
rc = nsync_futex_wait_((atomic_int *)GetWord(L), expect,
|
||||
PTHREAD_PROCESS_SHARED, deadline);
|
||||
END_CANCELLATION_POINT;
|
||||
END_CANCELATION_POINT;
|
||||
if (rc < 0) errno = -rc, rc = -1;
|
||||
return SysretInteger(L, "futex_wait", olderr, rc);
|
||||
}
|
||||
|
@ -2968,15 +2967,11 @@ static int LuaUnixMapshared(lua_State *L) {
|
|||
// └─→ unix.Sigset
|
||||
static int LuaUnixSigset(lua_State *L) {
|
||||
int i, n;
|
||||
lua_Integer sig;
|
||||
struct sigset set;
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
n = lua_gettop(L);
|
||||
for (i = 1; i <= n; ++i) {
|
||||
sig = luaL_checkinteger(L, i);
|
||||
if (1 <= sig && sig <= NSIG) {
|
||||
set.__bits[(sig - 1) >> 6] |= 1ull << ((sig - 1) & 63);
|
||||
}
|
||||
sigaddset(&set, luaL_checkinteger(L, i));
|
||||
}
|
||||
LuaPushSigset(L, set);
|
||||
return 1;
|
||||
|
@ -2984,61 +2979,54 @@ static int LuaUnixSigset(lua_State *L) {
|
|||
|
||||
// unix.Sigset:add(sig:int)
|
||||
static int LuaUnixSigsetAdd(lua_State *L) {
|
||||
sigset_t *set;
|
||||
lua_Integer sig;
|
||||
struct sigset *set;
|
||||
set = luaL_checkudata(L, 1, "unix.Sigset");
|
||||
sig = luaL_checkinteger(L, 2);
|
||||
if (1 <= sig && sig <= NSIG) {
|
||||
set->__bits[(sig - 1) >> 6] |= 1ull << ((sig - 1) & 63);
|
||||
}
|
||||
sigaddset(set, sig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// unix.Sigset:remove(sig:int)
|
||||
static int LuaUnixSigsetRemove(lua_State *L) {
|
||||
sigset_t *set;
|
||||
lua_Integer sig;
|
||||
struct sigset *set;
|
||||
set = luaL_checkudata(L, 1, "unix.Sigset");
|
||||
sig = luaL_checkinteger(L, 2);
|
||||
if (1 <= sig && sig <= NSIG) {
|
||||
set->__bits[(sig - 1) >> 6] &= ~(1ull << ((sig - 1) & 63));
|
||||
}
|
||||
sigdelset(set, sig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// unix.Sigset:fill()
|
||||
static int LuaUnixSigsetFill(lua_State *L) {
|
||||
struct sigset *set;
|
||||
sigset_t *set;
|
||||
set = luaL_checkudata(L, 1, "unix.Sigset");
|
||||
memset(set, -1, sizeof(*set));
|
||||
sigfillset(set);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// unix.Sigset:clear()
|
||||
static int LuaUnixSigsetClear(lua_State *L) {
|
||||
struct sigset *set;
|
||||
sigset_t *set;
|
||||
set = luaL_checkudata(L, 1, "unix.Sigset");
|
||||
bzero(set, sizeof(*set));
|
||||
sigemptyset(set);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// unix.Sigset:contains(sig:int)
|
||||
// └─→ bool
|
||||
static int LuaUnixSigsetContains(lua_State *L) {
|
||||
sigset_t *set;
|
||||
lua_Integer sig;
|
||||
struct sigset *set;
|
||||
set = luaL_checkudata(L, 1, "unix.Sigset");
|
||||
sig = luaL_checkinteger(L, 2);
|
||||
return ReturnBoolean(
|
||||
L, (1 <= sig && sig <= NSIG)
|
||||
? !!(set->__bits[(sig - 1) >> 6] & (1ull << ((sig - 1) & 63)))
|
||||
: false);
|
||||
return ReturnBoolean(L, sigismember(set, sig));
|
||||
}
|
||||
|
||||
static int LuaUnixSigsetTostring(lua_State *L) {
|
||||
char *b = 0;
|
||||
sigset_t *ss;
|
||||
int sig, first;
|
||||
struct sigset *ss;
|
||||
ss = luaL_checkudata(L, 1, "unix.Sigset");
|
||||
appends(&b, "unix.Sigset");
|
||||
appendw(&b, '(');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue