Attempt to fix MODE=dbg Windows execve() flake

This commit is contained in:
Justine Tunney 2025-01-05 13:46:47 -08:00
parent 7b67b20dae
commit 035b0e2a62
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
5 changed files with 68 additions and 84 deletions

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/atomic.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/sig.internal.h"
@ -57,11 +58,10 @@
__msabi extern typeof(CloseHandle) *const __imp_CloseHandle;
__msabi extern typeof(TerminateProcess) *const __imp_TerminateProcess;
extern pthread_mutex_t __sig_worker_lock;
extern atomic_int __sig_worker_state;
static void sys_execve_nt_abort(sigset_t sigmask) {
_pthread_unlock();
_pthread_mutex_unlock(&__sig_worker_lock);
__sig_worker_state &= ~2;
__sig_unblock(sigmask);
}
@ -70,8 +70,10 @@ textwindows int sys_execve_nt(const char *program, char *const argv[],
// execve() needs to be @asyncsignalsafe
sigset_t sigmask = __sig_block();
_pthread_mutex_lock(&__sig_worker_lock); // order matters
_pthread_lock(); // order matters
__sig_worker_state |= 2;
for (;;)
if (__sig_worker_state & 1)
break;
// new process should be a child of our parent
int64_t hParentProcess =
@ -176,6 +178,7 @@ textwindows int sys_execve_nt(const char *program, char *const argv[],
STRACE("warning: execve() lingering due to non-cosmo parent process");
// terminate other threads
_pthread_lock();
struct Dll *e;
struct PosixThread *me = _pthread_self();
for (e = dll_first(_pthread_list); e; e = dll_next(_pthread_list, e)) {