Repository navigation
Conversation
tombl
force-pushed
the
ryan/wasm-swap-stack
branch
4 times, most recently
from
October 25, 2026 14:05
da8561f to
e44f9f9
Compare
These were hidden along with mmap and its relatives, but they are system calls of their own, which the kernel has and refuses with ENOSYS or EPERM without swap. util-linux's swapon and swapoff need the symbols to link. Ported from ryanrasti/tombl-musl@2e9ff1cc.
The port made the generic pthread_getattr_np crash for the main thread, since there is no mremap to probe its stack with. MariaDB asks for its stack bounds at startup. Restore the generic file and give wasm32 its own. The main thread runs on the stack that wasm-ld places in linear memory, sized by -z stack-size, and the linker defines __stack_low and __stack_high around it. Report __stack_high as the address, since _a_stackaddr is the top of the stack, and the distance between the two as the size. A child cloned from the main thread without CLONE_VM keeps the main thread's descriptor but runs on the stack its parent supplied, so fail with ENOSYS when a thread asking about itself is not running within the bounds. The linker defines the bounds only for static links, which are all this port builds, so a PIC link fails to resolve them. Based on ryanrasti/tombl-musl@cc3a733e by Ryan Rasti, which reported a fixed 1 MiB below a frame address saved by __init_libc. Co-authored-by: Ryan Rasti <ryanrasti@protonmail.com>
tombl
force-pushed
the
ryan/wasm-swap-stack
branch
from
October 25, 2026 15:58
e44f9f9 to
1fab022
Compare
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.
Both changes undo our port's own hacks in generic files.
swaponandswapoff. The#ifndef __wasm__aroundsrc/linux/swap.ccame from our own 19c33f6 ("disable/remove all instances of mmap…"), which swept these up with mmap. They are ordinary syscalls: withARCH_NO_SWAPthe kernel'sswaponis acond_syscallthat returnsENOSYS. This restores the file byte-for-byte to upstream. Nothing in the distro needs it, since util-linux passes--disable-swaponon purpose. It's kept because it removes a needless deviation. The commit is byte-identical to Ryan Rasti's ryanrasti/tombl-musl@2e9ff1cc, so he remains the author.pthread_getattr_npfor the main thread. Our own 40851de ("replace fork calls with clone, and further tidy after mmap/fork removal") turned the generic file's mremap probe into commented-out code plusa_crash(), so asking for the main thread's stack crashed. MariaDB does that at startup. This version restoressrc/thread/pthread_getattr_np.cexactly to upstream, and gives wasm32 its ownsrc/thread/wasm32/pthread_getattr_np.c. musl's build drops the generic object when an arch file of the same name exists, and the build log shows the wasm32 file compiled.__stack_highand the size is__stack_high - __stack_low.ENOSYSwhen the thread asking about itself isn't within those bounds. A child cloned withoutCLONE_VMfrom the main thread keeps the main thread's descriptor but runs on the stack its parent supplied.Test (basic-init
pthread-getattr-main, in distro#206). Before (main's pins): init dies with SIGSEGV (Attempted to kill init! exitcode=0x0000000b). After: pass.The getattr commit is authored by Thomas Stokes with
Co-authored-by: Ryan Rasti. It is based on ryanrasti/tombl-musl@cc3a733e, which reported a fixed 1 MiB below a frame address saved by__init_libc.