Put more thought into i/o polyfills

wait4() is now solid enough to run `make -j100` on Windows. You can now
use MSG_DONTWAIT on Windows. There was a handle leak in accept() that's
been fixed. Our WIN32 overlapped i/o code has been simplified. Priority
class now inherits into subprocesses, so the verynice command will work
and the signal mask will now be inherited by execve() and posix_spawn()
This commit is contained in:
Justine Tunney 2023-11-06 16:38:44 -08:00
parent 736fdb757a
commit e961385e55
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
52 changed files with 679 additions and 487 deletions

View file

@ -22,6 +22,7 @@
#include "libc/calls/struct/sigset.internal.h"
#include "libc/calls/syscall-nt.internal.h"
#include "libc/errno.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/kprintf.h"
#include "libc/mem/mem.h"
#include "libc/nt/enum/processaccess.h"
@ -46,7 +47,7 @@ textwindows int sys_execve_nt(const char *program, char *const argv[],
char *const envp[]) {
// execve() needs to be @asyncsignalsafe
sigset_t m = __sig_block();
sigset_t sigmask = __sig_block();
_pthread_lock();
// new process should be a child of our parent
@ -55,10 +56,14 @@ textwindows int sys_execve_nt(const char *program, char *const argv[],
if (!(hParentProcess = OpenProcess(
kNtProcessDupHandle | kNtProcessCreateProcess, false, ppid))) {
_pthread_unlock();
__sig_unblock(m);
__sig_unblock(sigmask);
return -1;
}
// inherit signal mask
char maskvar[6 + 21];
FormatUint64(stpcpy(maskvar, "_MASK="), sigmask);
// define stdio handles for the spawned subprocess
struct NtStartupInfo si = {
.cb = sizeof(struct NtStartupInfo),
@ -80,21 +85,21 @@ textwindows int sys_execve_nt(const char *program, char *const argv[],
&lpExplicitHandles, &dwExplicitHandleCount))) {
CloseHandle(hParentProcess);
_pthread_unlock();
__sig_unblock(m);
__sig_unblock(sigmask);
return -1;
}
// launch the process
struct NtProcessInformation pi;
int rc = ntspawn(AT_FDCWD, program, argv, envp, (char *[]){fdspec, 0}, 0, 0,
hParentProcess, lpExplicitHandles, dwExplicitHandleCount,
&si, &pi);
int rc = ntspawn(AT_FDCWD, program, argv, envp,
(char *[]){fdspec, maskvar, 0}, 0, 0, hParentProcess,
lpExplicitHandles, dwExplicitHandleCount, &si, &pi);
__undescribe_fds(hParentProcess, lpExplicitHandles, dwExplicitHandleCount);
if (rc == -1) {
free(fdspec);
CloseHandle(hParentProcess);
_pthread_unlock();
__sig_unblock(m);
__sig_unblock(sigmask);
if (GetLastError() == kNtErrorSharingViolation) {
return etxtbsy();
} else {