0.13.3 --- a detached thread ends and the program goes on - #32
Merged
Conversation
musl's __unmapself moves to a 256-byte stack shared by every exiting thread before the two calls that end a detached one. Here the thread runs on the stack kal_task_start supplied, and those calls pass through the port's dispatcher, context table and openkal: an unoptimized build reached 13,640 bytes below the shared stack. On arm64 macOS the overflow overwrote the thread-specific key table and the context table, and the exit jumped through the bytes it had just written. The port releases the mapping from the stack the thread is on; examples/threads-detached runs on every CI row.
…m they are placed in The version table in README.md names the runtime that carries each release since 0.11.0.
…uments and directory as given
This was referenced Sep 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every program whose detached thread ended stopped with an access violation on arm64 macOS, and on every target the end of a detached thread wrote over memory it did not own.
musl releases a detached thread's mapping from inside the thread. On Linux the thread stands on that mapping, so
src/thread/__unmapself.cfirst moves to a 256-byte stack shared by every exiting thread and makes the two system calls that end the thread from there. Neither premise holds in this port:__clonenever runs a context on the stack musl allocated;kal_task_startsupplies its own. The move protects nothing.Measured with gdb on x86_64 Linux, dev profile, stopped in
kal_task_currentunderSYS_exiton the shared stack:What the overflow lands on depends on the link. On arm64 macOS the bss beneath
shared_stackis musl's thread-specific key table and then this port's context table (g_slots), so the exiting thread read its own record out of the bytes it had just written andlongjmped through them. lldb on macos-14, lsp-mcpp's server after its stdin reader thread ended:On Linux the same bytes land on data that happened not to matter, which is why only macOS showed it.
port/src/okm_thread.c:__unmapselfreleases the mapping from the stack the thread is on and ends the thread the ordinary way. What musl's version guaranteed, that nothing runs upon the mapping once released, holds without the move because nothing here ever ran upon it.mcpp.toml:musl/src/thread/__unmapself.cis excluded, with the reason beside it.musl/PATCHES.md,README.md: twelve replaced sources.examples/threads-detached: eight detached threads end one after another, then a key with a destructor and a joinable thread's error value exercise the two tables beneath the old shared stack. CI runs it on every row.Measured locally: the probe passes on x86_64 Linux and, cross-built, on x86_64-windows-gnu under Wine, and the
shared_stacksymbol is gone from the image. With openkal-llvm-runtime pointed at this tree, all 15 of lsp-mcpp's unit-test programs pass forx86_64-windows-gnuunder Wine. The macOS row of this CI is the one that failed before.Found through lsp-mcpp, whose server crashed on macos-14 as soon as its input reader thread ended.
Also carries openkal-windows 0.7.3 (mcpplibs/openkal-windows#21 and #22; mcpp-index#417 and #418). Its requirement here is exact, so this release is how consumers of openkal-musl reach them:
\\?\prefix that the interpreter refuses.