Don't relocate file descriptor memory

This change fixes #496 where ASAN spotted a race condition that could
happen in multithreaded programs, with more than OPEN_MAX descriptors
when using ZipOS or Windows NT, which require tracking open file info
and this change fixes that table so it never relocates, thus allowing
us to continue to enjoy the benefits of avoiding locks while reading.
This commit is contained in:
Justine Tunney 2022-09-09 16:54:28 -07:00
parent c3208eb9d5
commit 3265324e00
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
35 changed files with 297 additions and 152 deletions

View file

@ -26,6 +26,7 @@
#include "libc/intrin/pthread2.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
#include "libc/sysv/consts/prot.h"
@ -37,18 +38,19 @@
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"
void OnTrap(int sig, struct siginfo *si, void *vctx) {
void OnUsr1(int sig, struct siginfo *si, void *vctx) {
struct ucontext *ctx = vctx;
}
void SetUp(void) {
struct sigaction sig = {.sa_sigaction = OnTrap, .sa_flags = SA_SIGINFO};
sigaction(SIGTRAP, &sig, 0);
struct sigaction sig = {.sa_sigaction = OnUsr1, .sa_flags = SA_SIGINFO};
sigaction(SIGUSR1, &sig, 0);
}
void TriggerSignal(void) {
sched_yield();
DebugBreak();
/* kprintf("raising at %p\n", __builtin_frame_address(0)); */
raise(SIGUSR1);
sched_yield();
}
@ -67,6 +69,7 @@ TEST(pthread_create, testCreateReturnJoin) {
}
static void *IncExit(void *arg) {
CheckStackIsAligned();
TriggerSignal();
pthread_exit((void *)((uintptr_t)arg + 1));
}