mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-05 04:02:28 +00:00
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:
parent
f71f61cd40
commit
29eb7e67bb
11 changed files with 66 additions and 34 deletions
|
@ -31,6 +31,7 @@ TEST_LIBC_PROC_DIRECTDEPS = \
|
|||
LIBC_NT_KERNEL32 \
|
||||
LIBC_PROC \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_LOG \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
|
@ -90,6 +91,7 @@ o/$(MODE)/test/libc/proc/execve_test.dbg: \
|
|||
o/$(MODE)/test/libc/proc/execve_test.o \
|
||||
o/$(MODE)/test/libc/calls/life-nomod.zip.o \
|
||||
o/$(MODE)/test/libc/proc/execve_test_prog1.zip.o \
|
||||
o/$(MODE)/test/libc/proc/execve_test_prog2.zip.o \
|
||||
o/$(MODE)/test/libc/mem/prog/life.elf.zip.o \
|
||||
o/$(MODE)/test/libc/mem/prog/sock.elf.zip.o \
|
||||
o/$(MODE)/test/libc/proc/proc.pkg \
|
||||
|
@ -119,6 +121,7 @@ o/$(MODE)/test/libc/proc/life.dbg: \
|
|||
|
||||
o/$(MODE)/test/libc/proc/life.zip.o \
|
||||
o/$(MODE)/test/libc/proc/execve_test_prog1.zip.o \
|
||||
o/$(MODE)/test/libc/proc/execve_test_prog2.zip.o \
|
||||
o/$(MODE)/test/libc/proc/life-pe.zip.o: private \
|
||||
ZIPOBJ_FLAGS += \
|
||||
-B
|
||||
|
|
|
@ -53,6 +53,7 @@ TEST(execve, testArgPassing) {
|
|||
char ibuf[12], buf[8];
|
||||
const char *prog = "./execve_test_prog1";
|
||||
testlib_extract("/zip/execve_test_prog1", prog, 0755);
|
||||
testlib_extract("/zip/execve_test_prog2", "execve_test_prog2", 0755);
|
||||
for (i = 0; i < N; ++i) {
|
||||
FormatInt32(ibuf, i);
|
||||
GenBuf(buf, i);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
23
test/libc/proc/execve_test_prog2.c
Normal file
23
test/libc/proc/execve_test_prog2.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/proc/proc.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue