mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Make forking off threads reliable on Windows
This change makes posix_spawn_test no longer flaky on Windows, by (1) fixing a race condition in wait(), and (2) removing a misguided vfork implementation which was letting Windows bypass pthread_atfork().
This commit is contained in:
parent
2ebc5781a1
commit
58352df0a4
30 changed files with 230 additions and 187 deletions
|
@ -56,8 +56,18 @@
|
|||
vfork:
|
||||
.ftrace2
|
||||
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
jmp fork
|
||||
#endif
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
#if SupportsWindows()
|
||||
// these platforms disagree with vfork
|
||||
testb $_HOSTXNU|_HOSTOPENBSD|_HOSTWINDOWS,__hostos(%rip)
|
||||
jnz fork
|
||||
#endif
|
||||
|
||||
#if !IsTiny()
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
|
@ -69,21 +79,6 @@ vfork:
|
|||
pop %rbp
|
||||
#endif
|
||||
mov %fs:0,%r9 // get thread information block
|
||||
#if SupportsWindows()
|
||||
testb IsWindows()
|
||||
jnz 6f // and we're lucky to have that
|
||||
#endif
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
jmp 5f // TODO: asan and vfork don't mix?
|
||||
#endif
|
||||
#if SupportsXnu()
|
||||
testb IsXnu()
|
||||
jnz 5f
|
||||
#endif
|
||||
#if SupportsOpenbsd()
|
||||
testb IsOpenbsd()
|
||||
jnz 5f // fake vfork plus msyscall issues
|
||||
#endif
|
||||
mov 0x3c(%r9),%r8d // avoid question of @vforksafe errno
|
||||
pop %rsi // saves return address in a register
|
||||
mov __NR_vfork(%rip),%eax
|
||||
|
@ -106,29 +101,6 @@ vfork:
|
|||
ret
|
||||
.Lpar: andb $~TIB_FLAG_VFORKED,0x40(%r9)
|
||||
ret
|
||||
#if SupportsXnu() || SupportsOpenbsd() || defined(__SANITIZE_ADDRESS__)
|
||||
5: push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %r9
|
||||
push %r9
|
||||
call sys_fork
|
||||
pop %r9
|
||||
pop %r9
|
||||
pop %rbp
|
||||
jmp 1b
|
||||
#endif
|
||||
#if SupportsWindows()
|
||||
6: push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %r9
|
||||
push %r9
|
||||
xor %edi,%edi // dwCreationFlags
|
||||
call sys_fork_nt
|
||||
pop %r9
|
||||
pop %r9
|
||||
pop %rbp
|
||||
jmp 1b
|
||||
#endif
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue