Fix fork() regression on Windows

Recent optimizations to fork() introduced a regression, that could cause
the subprocess to fail unexpectedly, when TlsAlloc() returns a different
index. This is because we were burning the indexes into the displacement
of x86 opcodes. So when fork() happened and the executable memory copied
it would use the old index. Right now the way this is being solved is to
not copy the executable on fork() and then re-apply code changes. If you
need to be able to preserve self-modified code on fork, reach out and we
can implement a better solution for you. This gets us unblocked quickly.
This commit is contained in:
Justine Tunney 2025-01-05 09:24:17 -08:00
parent f71f61cd40
commit 29eb7e67bb
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
11 changed files with 66 additions and 34 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/fmt/conv.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
void GenBuf(char buf[8], int x) {
@ -40,5 +41,15 @@ int main(int argc, char *argv[]) {
tinyprint(2, "error: buf check failed\n", NULL);
return 10;
}
const char *prog = "./execve_test_prog2";
if (!fork()) {
execl(prog, prog, NULL);
_Exit(127);
}
int ws;
if (wait(&ws) == -1)
return 30;
if (ws)
return 31;
return 0;
}