Configure a new stack in cabi_realloc - #854
Merged
alexcrichton merged 1 commit intoJul 27, 2026
Merged
Conversation
Collaborator
Author
|
Wrong button... |
Collaborator
Author
|
Oh right, I should also mention that I've updated the implementation of |
This commit is an update to the `cabi_realloc` export configured by wasi-libc, specifically for wasip3 targets. The change here is to change the entrypoint from a C function to a small assembly wrapper which configures the stack pointer and TLS base before calling into C. This is to account for the spec change in WebAssembly/component-model#680 where `realloc` hooks are now going to be invoked with context slots set to 0. This means that `cabi_realloc` runs with no stack, and this would quickly abort in wasi-libc otherwise. The change here is to, when the ABI is using `context` slots for the stack pointer, have an assembly wrapper that configures a known-good stack and TLS block for `cabi_realloc` to use. Once configured the normal C-based `cabi_realloc` routine runs. This is tested against bytecodealliance/wasmtime#13949 to ensure it works on the p3 target with/without coop threading and before/after that Wasmtime change.
alexcrichton
force-pushed
the
configure-stack-poitner-in-cabi-realloc
branch
from
July 24, 2026 23:58
339af6a to
ffedbd4
Compare
dicej
approved these changes
Jul 27, 2026
| @@ -0,0 +1,21 @@ | |||
| // This is a "surgical" augmentation for the generated `wasip{2,3}.c` files in | |||
| // wasi-libc which changes the behavior of the generated `cabi_realloc`. Ideally | |||
| // `wit-bindgen` would have a mode that doesn't generate `cabi_realloc`, but that | |||
Collaborator
There was a problem hiding this comment.
Is there an issue for this? It would be nice to remove the need for this "surgery" sooner rather than later.
Collaborator
Author
There was a problem hiding this comment.
Not currently, no
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.
This commit is an update to the
cabi_reallocexport configured by wasi-libc, specifically for wasip3 targets. The change here is to change the entrypoint from a C function to a small assembly wrapper which configures the stack pointer and TLS base before calling into C. This is to account for the spec change in WebAssembly/component-model#680 wherereallochooks are now going to be invoked with context slots set to 0. This means thatcabi_reallocruns with no stack, and this would quickly abort in wasi-libc otherwise.The change here is to, when the ABI is using
contextslots for the stack pointer, have an assembly wrapper that configures a known-good stack and TLS block forcabi_reallocto use. Once configured the normal C-basedcabi_reallocroutine runs. This is tested against bytecodealliance/wasmtime#13949 to ensure it works on the p3 target with/without coop threading and before/after that Wasmtime change.