mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-12 22:19:10 +00:00
Fix _Thread_local with fork() on Windows
This commit is contained in:
parent
99a92048b4
commit
bf757c4646
5 changed files with 51 additions and 2 deletions
|
@ -29,11 +29,11 @@
|
|||
#include "libc/sysv/consts/sicode.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
|
||||
privileged unsigned __wincrash(struct NtExceptionPointers *ep) {
|
||||
unsigned __wincrash(struct NtExceptionPointers *ep) {
|
||||
int64_t rip;
|
||||
int sig, code;
|
||||
ucontext_t ctx;
|
||||
STRACE("__wincrash");
|
||||
STRACE("__wincrash rip=%lx", ep->ContextRecord->Rip);
|
||||
|
||||
switch (ep->ExceptionRecord->ExceptionCode) {
|
||||
case kNtSignalBreakpoint:
|
||||
|
|
|
@ -88,6 +88,7 @@ static inline textwindows ssize_t ForkIo(int64_t h, char *p, size_t n,
|
|||
static dontinline textwindows bool ForkIo2(int64_t h, void *buf, size_t n,
|
||||
bool32 (*fn)(), const char *sf) {
|
||||
ssize_t rc = ForkIo(h, buf, n, fn);
|
||||
__tls_enabled = false; // prevent tls crash in kprintf
|
||||
NTTRACE("%s(%ld, %p, %'zu) → %'zd% m", sf, h, buf, n, rc);
|
||||
return rc != -1;
|
||||
}
|
||||
|
@ -218,6 +219,9 @@ textwindows void WinMainForked(void) {
|
|||
AbortFork("CloseHandle");
|
||||
}
|
||||
|
||||
// turn tls back on
|
||||
__enable_tls();
|
||||
|
||||
// rewrap the stdin named pipe hack
|
||||
// since the handles closed on fork
|
||||
struct Fds *fds = VEIL("r", &g_fds);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue