mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-22 10:30:29 +00:00
Fix flakes in runitd and popen_test
This commit is contained in:
parent
801224df67
commit
2ebc5781a1
18 changed files with 123 additions and 34 deletions
|
@ -131,10 +131,14 @@ textstartup void cosmo(long *sp, struct Syslib *m1) {
|
|||
__mmi_lock_obj._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
|
||||
// record system provided stack to memory manager
|
||||
// todo: how do we get the real size of the stack
|
||||
// if `y` is too small mmap will destroy it
|
||||
// if `x` is too high, backtraces will fail
|
||||
uintptr_t t = (uintptr_t)__builtin_frame_address(0);
|
||||
uintptr_t s = (uintptr_t)sp;
|
||||
uintptr_t z = GetStackSize() << 1;
|
||||
_mmi.i = 1;
|
||||
_mmi.p->x = (s & -z) >> 16;
|
||||
_mmi.p->x = MIN((s & -z) >> 16, (t & -z) >> 16);
|
||||
_mmi.p->y = MIN(((s & -z) + (z - 1)) >> 16, INT_MAX);
|
||||
_mmi.p->size = z;
|
||||
_mmi.p->prot = PROT_READ | PROT_WRITE;
|
||||
|
|
|
@ -48,12 +48,14 @@
|
|||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/signals.h"
|
||||
#include "libc/nt/struct/ntexceptionpointers.h"
|
||||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/limits.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
@ -108,20 +110,36 @@ static dontinline textwindows bool ForkIo2(int64_t h, void *buf, size_t n,
|
|||
|
||||
static dontinline textwindows bool WriteAll(int64_t h, void *buf, size_t n) {
|
||||
bool ok;
|
||||
// kprintf("WriteAll(%ld, %p, %zu);\n", h, buf, n);
|
||||
ok = ForkIo2(h, buf, n, WriteFile, "WriteFile", false);
|
||||
#ifndef NDEBUG
|
||||
if (ok) ok = ForkIo2(h, &n, sizeof(n), WriteFile, "WriteFile", false);
|
||||
#endif
|
||||
#ifdef SYSDEBUG
|
||||
if (!ok) {
|
||||
kprintf("failed to write %zu bytes to forked child: %d\n", n,
|
||||
GetLastError());
|
||||
}
|
||||
#endif
|
||||
// Sleep(10);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static textwindows dontinline void ReadOrDie(int64_t h, void *buf, size_t n) {
|
||||
// kprintf("ReadOrDie(%ld, %p, %zu);\n", h, buf, n);
|
||||
if (!ForkIo2(h, buf, n, ReadFile, "ReadFile", true)) {
|
||||
AbortFork("ReadFile");
|
||||
AbortFork("ReadFile1");
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
size_t got;
|
||||
if (!ForkIo2(h, &got, sizeof(got), ReadFile, "ReadFile", true)) {
|
||||
AbortFork("ReadFile2");
|
||||
}
|
||||
if (got != n) {
|
||||
AbortFork("ReadFile_SIZE_CHECK");
|
||||
}
|
||||
#endif
|
||||
// Sleep(10);
|
||||
}
|
||||
|
||||
static textwindows int64_t MapOrDie(uint32_t prot, uint64_t size) {
|
||||
|
@ -276,6 +294,7 @@ textwindows void WinMainForked(void) {
|
|||
|
||||
textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
|
||||
jmp_buf jb;
|
||||
uint32_t op;
|
||||
uint32_t oldprot;
|
||||
char ok, threaded;
|
||||
char **args, **args2;
|
||||
|
@ -290,12 +309,10 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
|
|||
tib = __tls_enabled ? __get_tls() : 0;
|
||||
if (!setjmp(jb)) {
|
||||
pid = untrackpid = __reservefd_unlocked(-1);
|
||||
reader = CreateNamedPipe(CreatePipeName(pipename),
|
||||
kNtPipeAccessInbound | kNtFileFlagOverlapped,
|
||||
kNtPipeTypeMessage | kNtPipeReadmodeMessage, 1,
|
||||
65536, 65536, 0, &kNtIsInheritable);
|
||||
writer = CreateFile(pipename, kNtGenericWrite, 0, 0, kNtOpenExisting,
|
||||
kNtFileFlagOverlapped, 0);
|
||||
reader = CreateNamedPipe(CreatePipeName(pipename), kNtPipeAccessInbound,
|
||||
kNtPipeTypeByte | kNtPipeReadmodeByte, 1, PIPE_BUF,
|
||||
PIPE_BUF, 0, &kNtIsInheritable);
|
||||
writer = CreateFile(pipename, kNtGenericWrite, 0, 0, kNtOpenExisting, 0, 0);
|
||||
if (pid != -1 && reader != -1 && writer != -1) {
|
||||
p = stpcpy(forkvar, "_FORK=");
|
||||
p = FormatUint64(p, reader);
|
||||
|
@ -331,7 +348,6 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
|
|||
}
|
||||
for (i = 0; i < _mmi.i && ok; ++i) {
|
||||
if ((_mmi.p[i].flags & MAP_TYPE) != MAP_SHARED) {
|
||||
uint32_t op;
|
||||
char *p = (char *)((uint64_t)_mmi.p[i].x << 16);
|
||||
// XXX: forking destroys thread guard pages currently
|
||||
VirtualProtect(
|
||||
|
|
|
@ -464,6 +464,8 @@ dontasan textstartup void __printargs(const char *prologue) {
|
|||
PRINT(" - stderr");
|
||||
}
|
||||
kprintf(prologue);
|
||||
errno = 0;
|
||||
kprintf(" isatty = %d% m\n", isatty(i));
|
||||
if (!tcgetwinsize(i, &ws)) {
|
||||
kprintf(" ws_row = %d\n", ws.ws_row);
|
||||
kprintf(" ws_col = %d\n", ws.ws_col);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue