dhil opened PR #14398 from dhil:stack-switching-asan to bytecodealliance:main:
This patch adds facilities for instrumenting continuation stack switches with ASan's fiber switch hooks. The implementation is nearly zero-cost for non-ASan builds save for two new
VMCommonStackInformationfields used to track stack bounds and fake-stack state. I will consider wasy to eliminate this overheads once I start working on optimising stack switching.prtest:full
dhil requested cfallin for a review on PR #14398.
dhil requested wasmtime-core-reviewers for a review on PR #14398.
dhil requested wasmtime-compiler-reviewers for a review on PR #14398.
dhil edited PR #14398:
This patch adds facilities for instrumenting continuation stack switches with ASan's fiber switch hooks. The implementation is nearly zero-cost for non-ASan builds save for two new
VMCommonStackInformationfields used to track stack bounds and fake-stack state. I will consider wasy to eliminate this overheads once I start working on optimising stack switching.prtest:full
Resolves #14222
dhil updated PR #14398.
dhil updated PR #14398.
fitzgen added the label wasm-proposal:stack-switching on PR #14398.
dhil updated PR #14398.
dhil edited PR #14398:
This patch adds facilities for instrumenting continuation stack switches with ASan's fiber switch hooks. The implementation is nearly zero-cost for non-ASan builds save for two new
VMCommonStackInformationfields used to track stack bounds and fake-stack state. I will consider ways to eliminate this overheads once I start working on optimising stack switching.prtest:full
Resolves #14222
github-actions[bot] added the label wasmtime:api on PR #14398.
github-actions[bot] added the label wasmtime:config on PR #14398.
:thumbs_up: cfallin submitted PR review:
This looks reasonable overall -- thanks! A few comments below but nothing major.
:speech_balloon: cfallin created PR review comment:
Do we want to try to share one (lazily-created) stack slot for all stack switch ops in a function, if there is more than one? As-is this will create a stackframe size linear in the number of switch ops, which might be suboptimal for some kinds of continuation usage (e.g. frequent async yield points or ...). We could stash an
Option<StackSlot>on theenvfor example.
:speech_balloon: cfallin created PR review comment:
Can we add a comment here about this arithmetic (that, I think, we are excluding the guard page from the stack region that we tell ASan about, because that doesn't work / we aren't supposed to be accessing it / ...)?
:speech_balloon: cfallin created PR review comment:
We should probably note why this is a dynamic config option rather than a static
cfg!(asan)-- this is to support cross-compilation (compiler build doesn't have asan but runtime does), right?
:speech_balloon: cfallin created PR review comment:
Rather than fine-grained
cfg(asan)here, perhaps two submodules,asan::enabledandasan::disabled, each conditionally gated, and withpub usere-exports here? (Follows the pattern we have elsewhere and makes code a little easier to read)Or if the defs aren't needed in the disabled-case, then let's just cfg-gate the whole
asanmodule.
:speech_balloon: cfallin created PR review comment:
Rather than inline cfg'd blocks, perhaps a helper function with two cfg-gated functions? A little easier to read at least.
github-actions[bot] commented on PR #14398:
Label Messager: wasmtime:config
It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:
[ ] If you added a new
Configmethod, you wrote extensive documentation for
it.<details>
Our documentation should be of the following form:
```text
Short, simple summary sentence.More details. These details can be multiple paragraphs. There should be
information about not just the method, but its parameters and results as
well.Is this method fallible? If so, when can it return an error?
Can this method panic? If so, when does it panic?
Example
Optional example here.
```</details>
[ ] If you added a new
Configmethod, or modified an existing one, you
ensured that this configuration is exercised by the fuzz targets.<details>
For example, if you expose a new strategy for allocating the next instance
slot inside the pooling allocator, you should ensure that at least one of our
fuzz targets exercises that new strategy.Often, all that is required of you is to ensure that there is a knob for this
configuration option in [wasmtime_fuzzing::Config][fuzzing-config] (or one
of its nestedstructs).Rarely, this may require authoring a new fuzz target to specifically test this
configuration. See [our docs on fuzzing][fuzzing-docs] for more details.</details>
[ ] If you are enabling a configuration option by default, make sure that it
has been fuzzed for at least two weeks before turning it on by default.[fuzzing-config]: https://github.com/bytecodealliance/wasmtime/blob/ca0e8d0a1d8cefc0496dba2f77a670571d8fdcab/crates/fuzzing/src/generators.rs#L182-L194
[fuzzing-docs]: https://docs.wasmtime.dev/contributing-fuzzing.html
<details>
To modify this label's message, edit the <code>.github/label-messager/wasmtime-config.md</code> file.
To add new label messages or remove existing label messages, edit the
<code>.github/label-messager.json</code> configuration file.</details>
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
I keep making this mistake -- yes! I think I will do a slightly more general thing here and package up the various
stack_switching_support fields into a coherent structure, rather than keep appending inline onFuncEnvironment.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
Yes, to ensure that the compiled artifact is compatible with the runtime. I will reword it.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
Yes correct, ASan fiber switch needs the bounds of the readable and writeable stack region, which excludes the guard page. I will add a comment.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
Good idea, thanks! I've added a
enabledanddisablednow (I'll commit it in a moment).
dhil updated PR #14398.
dhil updated PR #14398.
dhil updated PR #14398.
dhil updated PR #14398.
dhil updated PR #14398.
:speech_balloon: cfallin created PR review comment:
We can probably fold these parameters into
env.get_or_create_asan_fake_stack_slot()(pointer_bytesalso comes fromenv)?
:thumbs_up: cfallin submitted PR review:
Thanks! Just one little nit but otherwise happy to merge.
dhil updated PR #14398.
dhil updated PR #14398.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
Yes good point, thanks!
cfallin added PR #14398 [stack-switching] Interop with ASan to the merge queue.
:check: cfallin merged PR #14398.
cfallin removed PR #14398 [stack-switching] Interop with ASan from the merge queue.
Last updated: Oct 11 2026 at 02:20 UTC