Repository navigation
[WTF] Give WTF threads an alternate signal stack and make the suspend handler work on one - #742
Conversation
|
Status. Ready for review, stacked on #741 (242085d). The branch has four commits: the suspend handler, the tests that hold without an alternate stack on the threads of WTF, the alternate stack, and the tests that need it. #741 can take the first two. How I reproduced the two problems, on Linux x64:
A self-review found two defects in earlier revisions, and a gap in the tests. The current revision has a fix for each:
CI: on the head (f51a066) all lanes of the fork build and both test jobs pass. macOS and musl: oven-sh/bun#44260 (a probe, closed) pinned the preview build of the head. In the CI of Bun all 181 jobs pass, and the Not run: FreeBSD and Android (built only). Open, and not in this PR: oven-sh/bun#40169 with #741 needs the first commit here. #741 can take commits 1 and 2 as they are (a fast-forward to b37f482). When #741 merges, I rebase this branch on main and retarget it. |
2fc6c01 to
ff791a9
Compare
|
Preview build of f51a066: |
…eep SA_ONSTACK off ASan builds jscSignalHandler decided from uc_stack.ss_flags if the code that it interrupted ran on the alternate stack. Since Linux 4.7 that field holds the flags that the thread passed to sigaltstack(), so the test was the same for every signal on a thread. The outermost invocation on a thread publishes its registers, and registersInterruptedBySignalHandler() returns them only when their stack pointer is in the stack of the thread. A fault inside a handler on the alternate stack leaves the suspension to back off, as before. ASan gives every thread an alternate stack of about 58 KB without a guard page, and the VMTraps handler of an ASan build needs more. ASan builds keep SA_SIGINFO alone. The change is the one of #742.
|
A note for the rebase of this PR: #741 moved to 242085d.
The stress test of this PR covers the suspension inside the handler in the CI of the fork, which #741 cannot do: no thread of |
ff791a9 to
a66379d
Compare
…gnal stack Thread::signalHandlerSuspendResume() decides from its own stack pointer whether the signal interrupted the thread's own stack. That is wrong when the handler has SA_ONSTACK and the thread has an alternate signal stack: the handler runs there, backs off, and Thread::suspend() tries again without end. The runtime of Go adds SA_ONSTACK to the handlers that it finds when a process loads it. When the handler is not on the thread's own stack, it reads the stack pointer that the signal interrupted from its context. If that stack pointer is in the thread's own stack, the registers of the context are the ones that it publishes.
a66379d to
2feae76
Compare
testFFI runs itself as a child that registers a crash handler with SA_ONSTACK, creates a VM and overflows the native stack of the main thread. The crash handler runs only when the handler that JSC registers has SA_ONSTACK too. A second child adds SA_ONSTACK to the handler that suspends a thread, as the runtime of Go does, and suspends a thread that has an alternate signal stack.
The kernel can only deliver a stack overflow on an alternate signal stack: the fault is on the guard page of the thread's own stack. An embedder with a crash handler gives one to the threads it creates. The threads of WTF (heap helpers, JIT worklist, collector) had none. wtfThreadEntryPoint() registers 512 KiB with a guard page below it for as long as the entry point runs. It keeps a stack that is registered already: bionic and the sanitizer runtimes give every thread one. When the entry point returns, the stack is disabled and unmapped. The disable passes the size of the stack, which Darwin checks there too, and a stack that could not be disabled stays mapped.
2feae76 to
f6bee26
Compare
…and a profiled thread on an alternate signal stack finishes testFFI overflows the native stack of a thread that WTF creates, in the child that has the crash handler. It also checks that a thread of WTF has an alternate stack, and what is left of it when the thread ends: nothing is registered, a stack that the thread registered itself stays, and a stack that cannot be disabled stays mapped. The last case and the rule of the libc of Darwin need a sigaltstack() that can fail. On Linux with glibc, testFFI defines one: WTF is linked statically into it. The stress test takes Wasm traps and runs into time limits on an agent thread while the sampling profiler samples it. The agent thread has an alternate stack, so the signal handlers of JSC run on it.
f6bee26 to
f51a066
Compare
autobuild-preview-pr-742-f51a066e has one more testFFI test, which runs on macOS too. Not for merge.
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline findings, I also checked the guard mismatch between the new isOnStack declaration in Source/WTF/wtf/threads/Signals.h (!OS(DARWIN)) and its use in ThreadingPOSIX.cpp (HAVE(MACHINE_CONTEXT) only) — the whole signalHandlerSuspendResume body sits inside the file's #if !OS(DARWIN) block, so macOS builds never see the call. The AlternateSignalStack destructor's registered-stack check and the leak-on-disable-failure path also read correctly against the Darwin size rule.
Extended reasoning...
The change adds a per-thread 512 KiB sigaltstack RAII object to wtfThreadEntryPoint and makes the SIGPWR suspend handler read the interrupted stack pointer from the ucontext when it runs on an alternate stack, plus testFFI and a JSTests stress test. It touches signal-handling and thread-suspension code under Source/WTF (CODEOWNER-listed) but no auth, injection or data-exposure surface. Inline findings are posted, so a human look is already signalled; this note only records the Darwin guard question that was examined and ruled out.
| if (isOnStack(interruptedRegisters, thread->m_stack)) | ||
| registersOfOwnStack = &interruptedRegisters; | ||
| else | ||
| registersOfOwnStack = registersInterruptedBySignalHandler(thread->m_stack); |
There was a problem hiding this comment.
🟡 (optional) Anyone building this fork for a Linux or FreeBSD CPU other than x64 or arm64 gets a hang in every suspension of a WTF thread that is inside a JSC signal handler, which the base branch handled. stackPointerOf in Signals.cpp:489-503 returns nullptr there, so isOnStack at ThreadingPOSIX.cpp:219 and registersInterruptedBySignalHandler at line 222 are always false and the handler backs off at line 231. With this change every WTF thread has an alternate stack, so a Wasm trap or JIT fault on a Worker thread while the GC or sampling profiler suspends it spins Thread::suspend forever. Fix: fall back to publishing the ucontext registers, or compile the alternate stack only where stackPointerOf has an accessor.
Why this was flagged
If any consumer builds this fork for Linux on ARM32, RISCV64 or PPC64 (the CI lanes in .github/scripts/lanes.mjs are all x64 or arm64, so this population is outside the fork's own builds), stackPointerOf at Signals.cpp:499-502 returns nullptr. Before this change WTF threads had no alternate stack, so jscSignalHandler ran on the thread's own stack and signalHandlerSuspendResume took the fast path at line 209 and never consulted stackPointerOf. Now ThreadingPOSIX.cpp:362-372 registers an alternate stack on every WTF thread and jscSignalHandler runs there with SA_ONSTACK; a suspend arriving during it reaches line 219, where isOnStack is false, and line 222, where registersInterruptedBySignalHandler is also false, so the thread posts null at line 231-232 and Thread::suspend at line 748-762 retries forever while the JSC handler waits for the suspender's lock (the case the comment at line 215-217 describes). The GC or SamplingProfiler then never completes. Remedy: on architectures without an accessor, skip the alternate stack or publish the ucontext registers rather than back off.
Verification: nit — trigger: the fork built for Linux/FreeBSD on a CPU other than x64/arm64 that still has HAVE(MACHINE_CONTEXT) (CPU(ARM), CPU(RISCV64) per Source/WTF/wtf/PlatformHave.h:235), a target none of the fork's CI lanes (.github/scripts/lanes.mjs: amd64/arm64 only) or Bun itself builds today; when it is built, a WTF thread (jsc agent/Worker thread) that takes a Wasm trap while the sampling profiler samples it hangs the process, which the base does not do.
Mechanism verified.
| const numberOfTraps = 20000; | ||
| const numberOfTimeLimits = 30; |
There was a problem hiding this comment.
🟡 (optional) Maintainers get a new stress test that breaks the JSTests/README.md rules for new tests: it runs well over the 200 ms budget in every configuration and ignores testLoopCount. The agent waits 30 times for a 5 ms time limit (at least 150 ms) and then takes 20000 Wasm traps under a 50 us sampling interval, with both counts hard-coded at JSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js:9-10. Fix: size the two loops from testLoopCount / wasmTestLoopCount (or cut them so the test stays under 200 ms with --report-execution-time in every run-jsc-stress-tests configuration), and since it embeds a Wasm module, consider JSTests/wasm/stress per the same README.
Why this was flagged
JSTests/CLAUDE.md imports JSTests/README.md, whose rules for new tests are: tests must run under 200 ms in all configurations (rule 1), use testLoopCount or wasmTestLoopCount for iteration counts (rule 2), and put wasm-involving tests in JSTests/wasm/stress. The new file JSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js:9-10 hard-codes numberOfTraps = 20000 and numberOfTimeLimits = 30, and JSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js:47 calls $vm.callWithTimeLimit(() => { for (;;) { } }, 5) thirty times, which alone spends at least 150 ms; the 20000 SIGSEGV-driven Wasm traps under --sampleInterval=50 add more. run-jsc-stress-tests runs every stress test in multiple configurations (no-cjit, ftl-eager, etc.), so each run of the CI test job on the Linux x64 and arm64 LTO lanes pays this repeatedly. On the base branch this file does not exist. The PR description reports the test passes 10 of 10 runs but gives no execution time, so the 200 ms rule is not shown to hold.
Verification: nit. Trigger: the new stress test runs whenever run-javascriptcore-tests / run-jsc-stress-tests JSTests/stress executes (the fork's Linux x64/arm64 CI lanes do this), in every default stress configuration.
| if (sigaltstack(nullptr, ¤t) || !(current.ss_flags & SS_DISABLE)) | ||
| return; | ||
|
|
||
| m_mapping = MmapSpan<uint8_t>::tryAlloc(pageSize() + size); |
There was a problem hiding this comment.
🟡 (optional) Every WTF thread in Bun release builds now costs twice the mapped address space and commit charge, and two extra VMAs, so hosts with strict overcommit or a low vm.max_map_count hit ENOMEM sooner. Threading.cpp:161 gives each WTF thread a 512 KiB pthread stack under USE(BUN_JSC_ADDITIONS), and ThreadingPOSIX.cpp:362 maps another 512 KiB plus a page for the alternate stack, so the dismissal's premise that the pthread stack is already the larger mapping is wrong. Fix: size the alternate stack for the handler that actually runs there (MINSIGSTKSZ-scale, or lazily) or reserve it once per process pool rather than per thread.
Why this was flagged
The dismissal assumed each pthread stack is a much larger mapping than the new alternate stack. Under USE(BUN_JSC_ADDITIONS) with !ASSERT_ENABLED, Threading.cpp:159-161 requests a 512 KiB stack for every WTF thread, the same as the alternate stack size at ThreadingPOSIX.cpp:400. Each thread now adds a 516 KiB MAP_PRIVATE|MAP_ANON mapping (line 362) that vm.overcommit_memory=2 counts fully against CommitLimit, and the mprotect at line 367 splits it into two VMAs. Processes that run near max_map_count or under strict overcommit (containers with memory-limited cgroups and overcommit_memory=2) fail thread creation or mmap in JSC earlier than on the base branch, where a WTF thread had only its pthread stack. Remedy: use a smaller alternate stack or reuse a per-process pool.
Verification: nit; acknowledged in diff: the PR description states "Each thread of WTF costs ... 516 KiB of address space", and that bound is accurate. Triggering condition: a Bun process running on a host with vm.overcommit_memory=2 (or a low vm.max_map_count) already close to its limit.
Mechanism verified.
| if (typeof WebAssembly !== "object") | ||
| return ${numberOfTraps}; | ||
|
|
||
| // (module (memory 1) (func (export "load") (param i32) (result i32) (i32.load (local.get 0)))) |
There was a problem hiding this comment.
🟡 nit (optional): The new test builds and runs a WebAssembly module, but JSTests/README.md says tests that involve wasm belong in JSTests/wasm/stress, not JSTests/stress. Fix: move the file under JSTests/wasm/stress (keeping the WebAssembly-absent fallback at line 14 if the runner still lists it for non-wasm builds), or split the Wasm trap half from the time-limit half.
Why this was flagged
JSTests/README.md, imported by JSTests/CLAUDE.md, states "Put tests that only target JS behavior in JSTests/stress and tests that involve wasm in JSTests/wasm/stress." The new file at JSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js:18-26 compiles a hand-encoded Wasm module and calls its export 20000 times at line 31 to take Wasm traps. The test therefore involves wasm but is placed in JSTests/stress, which the guidance reserves for JS-only behaviour. This is a convention slip only; no runtime failure follows from it.
Verification: nit. Triggering condition: any time the file is added as-is. The rule is real: /home/claude/webkit/JSTests/README.md:15 (imported by /home/claude/webkit/JSTests/CLAUDE.md:1 via @ README.md) says under "Adding Tests": "Put tests that only target JS behavior in JSTests/stress and tests that involve wasm in JSTests/wasm/stress."
Stacked on #741. oven-sh/bun#40169 needs commit 1 too.
Problem
wtfThreadEntryPoint(Source/WTF/wtf/posix/ThreadingPOSIX.cpp:331) registers no alternate signal stack.SA_ONSTACKbacks off andThread::suspend()retries without end. Go's runtime adds that flag, andbun --cpu-profhangs on main.Fix
wtfThreadEntryPointregisters a 512 KiB alternate stack with a guard page while the entry point runs, unless one is registered already.testFFIon Linux, musl and macOS, andJSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js.Background
SA_ONSTACKhandler on an alternate stack, one per thread.pthread_createwrapper of Bun (Linux only).Downsides
Notes
Self-review. Concerns that the reviews of this PR raised, and what I did:
SA_ONSTACKnever suspends a thread that has an alternate stack. Fixed in commit 1, with a test.testThreadReleasesAlternateSignalStack.Weighed, and kept as it is:
PageReservation::tryReserveWithGuardPagesin place ofMmapSpanandmprotect. It has no user in WTF or JSC, it adds a second guard page and one more syscall, and it does not release itself.currentStackPointer()test. On an architecture that has no accessor inSignals.cppthe context gives no stack pointer, and that handler would back off without end. The test of the handler's own stack pointer stays first, as upstream has it.Commits. Four, on top of #741 (242085d):
testFFItests that hold without an alternate stack on the threads of WTF. The overflow of the main thread is the test of [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741. The suspension test is the test of commit 1.Commits 1 and 2 do not depend on 3 and 4, so #741 can take them. Checked with the tests of each commit against each state of WTF:
-14)-11)Revisions. "Final" is
f51a066e36, orf6bee26d4band2feae769a5before it: all three have the same code outside of the tests. "Previous" isa66379db22: the same alternate stack, without the commit for the suspend handler. "Earlier" is a revision whose destructor passed no size to the disable call. All three make the same syscalls at the start and the end of a thread on Linux.Platforms. My own builds and runs are Linux x64, Release
jscandtestFFIwith the settings of thebun-webkit-linux-amd64lane, not LTO. The fork's CI runstestFFIand the JavaScriptCore tests on Linux x64 and arm64. The other lanes build. The CI of Bun rantestFFIon macOS and musl (below).Tests, final revision:
testFFI,testNativeStackOverflowIsReported: a child process registers a handler withSA_ONSTACKand an alternate stack for the main thread, creates a VM and overflows the native stack. On the main thread the child fails on main (-11, killed by SIGSEGV) and passes with [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741. On a thread of WTF it fails with [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741 (-11) and passes with this branch.testFFI,testThreadHasAlternateSignalStack: a thread of WTF has an active stack of 512 KiB, and 1000 threads created and joined leave no mappings behind. It fails with [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741.testFFI,testThreadReleasesAlternateSignalStack: a pthread key destructor looks at the alternate stack of a thread of WTF after its entry point returned. Nothing is registered then. A stack that the thread registered itself stays registered. On Linux with glibc,testFFIdefinessigaltstack()itself (WTF is linked statically into it), and two more cases use that. With the rule of the libc of Darwin, nothing is registered at the end. A stack that cannot be disabled stays registered and mapped. With the destructor of the earlier revision two checks fail: the stack is still registered under the rule of Darwin, and it is unmapped when the disable call fails.testFFI,testSuspendOnAlternateSignalStack: a child process addsSA_ONSTACKto the suspend handler and suspends an idle thread that has an alternate stack. The thread registers one of its own when WTF gives it none. Without the first commit the child is killed by its 30 s alarm (-14). With the first commit it passes at once.jscwhile the sampling profiler samples it. An agent thread has an alternate stack with this branch, so the test covers the suspension of a thread inside the signal handler ([WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741) in the fork's CI. 10 of 10 runs pass. On a build with the flag and the alternate stack and without a fix for the suspension, 0 of 10 runs finish in 60 s (earlier revision).SA_ONSTACKadded to the suspend handler by anLD_PRELOADshim: 0 of 5 runs finish in 30 s on the previous revision, 10 of 10 pass on the final one. Thejscof [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741 passes 3 of 3, because its agent threads have no alternate stack.sampling-profilertests and 23 tests with agent threads fromJSTests/stress, run directly withjsc: 40 of 40 pass, and 40 of 40 with the shim.The suspend handler. A self-review of the previous revision found this. The runtime of Go, built as a shared library, adds
SA_ONSTACKto each handler that it finds and does not replace (runtime.setsigstack). I loaded a Go 1.24 library that exports one function (-buildmode=c-shared) withbun:ffi: the SIGPWR handler has noSA_ONSTACKbefore thedlopenand has it after. A debug Bun with the previous revision then hangs in a script that idles for 6 s (1 run, killed at 40 s). With #741 it finishes. The handler then runs on the alternate stack of a thread that has one, sees a stack pointer outside of the thread's own stack and backs off.Thread::suspend()sends the signal again, without end. Measured with a shim that adds the flag, each run with a limit of 30 to 40 s:bun --cpu-profnode:vmtimeout on the main threadnode:vmtimeout in a Workerpas_thread_local_cache_for_all), spins inThread::suspend()and holds the heap lock. This needs a debug build of WebKit, wherefastMallocis libpas: it sent SIGPWR 84 to 296 times in my runs. A release build uses mimalloc there and sent it 0 times.bun --cpu-profon the final revision writes a profile with 163 samples. Without the flag it has 140.The release on Darwin. The destructor passes the stack size to the disable call and keeps a stack mapped that the call did not disable. The libc of Darwin returns
ENOMEMfor asigaltstackcall with a size below itsMINSIGSTKSZ(32768), also when the call disables the stack. I have no macOS machine, so I rantestFFIon Linux with anLD_PRELOADshim that applies this rule and watchesmunmap, 1001 threads of WTF:Measurements, Release builds:
sigaltstack4,mmap1,mprotect1,munmap1jsc -e 1(no thread of WTF)jsc -e 1rw-pwith Rss 0 kB, +4 KiB---psizeof(WTF::Thread)Text, final revision against #741, same flags:
sizeofThreadingPOSIX.cpp.o4117 to 4891 bytes, ofSignals.cpp.o3126 to 3166. By function:wtfThreadEntryPoint13 to 53 bytes,AlternateSignalStack()297,~AlternateSignalStack()184,signalHandlerSuspendResume364 to 380,isOnStack40.The four calls at the start of a thread are the
sigaltstackquery,mmap,mprotectof the guard page andsigaltstack. The three at its end are the query, the disable andmunmap.strace,perf,valgrind,bloatyandpaholeare not installed where I ran this. The syscalls were counted with a ptrace counter and withLD_PRELOADshims, the record layout was read with clang, the text sizes withsizeandnm -S.Deepest use of the alternate stack by the fault handlers of JSC, of 524,288 bytes (earlier revision): release
jsc3,648 bytes (Wasm trap) and 3,928 (VM trap), 11,208 with the profiler suspending the thread inside the handler. Debug Bun 5,000, 5,856 and 12,776.Bun, final revision. Debug builds without ASan of oven-sh/bun#40169 (11f96f512b), one with the preview build of #741 (
autobuild-preview-pr-741-242085de) and one with the preview build of this PR (autobuild-preview-pr-742-2feae769, same code outside of the tests as the head):HeapHelper, 5 runspanic(HeapHelper): Stack overflowJITWorker, 5 runspanic(JITWorker): Stack overflowpanic(ollector Thread): Stack overflowLD_PRELOADhook onprctl(PR_SET_NAME): the thread that takes the given name recurses without end. A test in Bun for a thread of WTF can use the same hook.test/cli/run/run-crash-handler.test.ts: 36 pass, 0 fail in 3 of 3 runs with this PR. That includes the 6 tests of "native stack overflow is reported" and the Wasm trap while the sampling profiler suspends the thread. One more run, at a load average of 704, had 2 tests reach their limit of 5 s. Each of the two passes 5 of 5 times alone.test/cli/run/cpu-prof.test.ts12 pass,test/js/bun/jsc/bun-jsc.test.ts41 pass,test/js/web/workers/message-channel.test.ts17 pass,test/js/node/worker_threads/worker_threads.test.ts142 pass.test/js/web/workers/worker.test.tsandtest/js/node/vm/vm.test.tshave tests with time limits that fail on both builds on this machine (load average 360 to 1480).worker.test.ts, 14 runs of each build in turn: 41 failed tests in total with [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741, 53 with this PR. In the last 6 of those runs, with the order swapped each time: 12 and 8. CPU time of the test file in those 6 runs: median 51.1 s (39.7 to 53.4) with [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741, 50.1 s (46.2 to 58.3) with this PR.vm.test.ts, 3 runs each: 11, 2 and 1 failed tests with [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741, 7, 4 and 2 with this PR.JITWorker), a script that allocates and collects has 10 (7HeapHelper, 2JITWorker, the collector). The process has that number of alternate stacks more with this PR: 1 and 10 mappings, against 0 and 0 with [WTF] The signal handler runs on the alternate signal stack, and a thread that runs it there can be suspended #741. No thread has SIGSEGV or SIGBUS blocked.CI of the fork. On the head (f51a066) all lanes build and both test jobs pass. The same on f6bee26. On 2feae76, which has the same code outside of the tests, the x64 test job failed once in
run-javascriptcore-testsand passed when I ran it again. I cannot read the log of the failed attempt from where I work. That step also needed a second attempt on other branches this week (for example #741 at 5586daa, on arm64). With the LTOjscof that build on my machine: 340 runs of the new stress test (20 times its 17 modes) have 0 failures, and 5,334 runs of tests and modes that use the sampling profiler have 1,Crashing because current footprint: 635207680 exceeds limit: 629145600. The footprint is resident memory, and main has that failure too.macOS and musl. I have no machine for either, so oven-sh/bun#44260 (a probe, closed) pinned the preview build of the head,
autobuild-preview-pr-742-f51a066e. In the CI of Bun, build 121790, all 181 jobs pass. An earlier run with the build of f6bee26, build 121721, passed too.test/js/bun/jsc-stress/testFFI.test.tsruns thetestFFIof the WebKit build. It passed on macOS aarch64 and x64, Alpine 3.23 aarch64 and x64 (musl), Debian 13 x64 and Ubuntu 25.04 aarch64. On macOS that is the overflow of the main thread and of a thread of WTF, the check that a thread of WTF has an alternate stack, and the check that nothing is registered when the thread ends. The last one is the real rule of the libc of Darwin. The suspension test is not built there.sigaltstackinbsd/kern/kern_sig.c) reportsSS_DISABLEfor a thread that has no alternate stack, which is what the constructor tests. The libc wrapper returnsENOMEMfor a size belowMINSIGSTKSZbefore it calls the kernel. In the macOS arm64 build of an earlier preview, the disassembly of~AlternateSignalStackhas the disable call withss_flags4 andss_sizeset to the size of the mapping minus one page, and it clears the mapping (nomunmap) when that call fails.FreeBSD and Android. Built by the CI of the fork and of Bun. Not run.
ASan. ASan gives every thread an alternate stack of 58,112 bytes on my machine, without a guard page. A thread of WTF issues one
sigaltstackquery under ASan and keeps the stack of ASan. #741 keepsSA_ONSTACKoff the handler in ASan builds, because the VM trap handler used 72,000 bytes there.Still silent after this change.
mi-scavenger).Related. #235 makes the same decision from the context of the signal, for the code before #741. The first commit here is that check on top of #741, limited to the builds with the additions of Bun. #235 and #397 change other functions of
ThreadingPOSIX.cpptoo (initializePlatformThreading,initializeTLS). Neither changeswtfThreadEntryPoint.Alternative for Linux.
__wrap_pthread_createin Bun (src/jsc/bindings/c-bindings.cpp) is in front of everypthread_createof the Bun binary, so it can give a stack to every thread, the mimalloc thread too. Bun links it on Linux only (scripts/build/flags.ts,when: c => c.linux), and the crash handler of Bun is a signal handler on macOS too. It can be a later change in Bun for the threads that this PR does not reach.The Bun side is oven-sh/bun#40169. It pins the preview build of #741, so it needs the first commit of this PR in its WebKit too (table above, Worker row). Its branch has no hook that sets the flag again after JSC installs its handler (
CrashHandler__keepSignalHandlersOnAltStack, called once fromBun::tryCreateVM, with the linttest/internal/source-lints/vm-creation.test.ts), so Bun has nothing to delete after the upgrade.Dropofsrc/bun_core/signal_stack.rsthere passes no size to the disable call, so on macOS it has the problem that the destructor here avoids.