Improve lock hierarchy

- NetBSD no longer needs a spin lock to create semaphores
- Windows fork() now locks process manager in correct order
This commit is contained in:
Justine Tunney 2024-07-24 15:55:57 -07:00
parent 7ba9a73840
commit d3a13e8d70
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
14 changed files with 73 additions and 71 deletions

View file

@ -18,11 +18,11 @@
*/
#include "libc/assert.h"
#include "libc/calls/internal.h"
#include "libc/intrin/fds.h"
#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/fds.h"
#include "libc/intrin/kprintf.h"
#include "libc/mem/mem.h"
#include "libc/nt/enum/processaccess.h"
@ -109,10 +109,14 @@ textwindows int sys_execve_nt(const char *program, char *const argv[],
// give child to libc/proc/proc.c worker thread in parent
int64_t handle;
unassert(DuplicateHandle(GetCurrentProcess(), pi.hProcess, hParentProcess,
&handle, 0, false, kNtDuplicateSameAccess));
unassert(!(handle & 0xFFFFFFFFFF000000));
TerminateThisProcess(0x23000000u | handle);
if (DuplicateHandle(GetCurrentProcess(), pi.hProcess, hParentProcess, &handle,
0, false, kNtDuplicateSameAccess)) {
unassert(!(handle & 0xFFFFFFFFFF000000));
TerminateThisProcess(0x23000000u | handle);
} else {
kprintf("DuplicateHandle failed w/ %d\n", GetLastError());
TerminateThisProcess(ECHILD);
}
}
#endif /* __x86_64__ */