cfallin requested wasmtime-core-reviewers for a review on PR #15183.
cfallin requested fitzgen for a review on PR #15183.
cfallin opened PR #15183 from cfallin:memory-range-api to bytecodealliance:main:
In order to support record/replay, we need precise information about when memory is mutated (so we can capture memory side-effects properly). Wasmtime's current APIs provide slices (immutable or mutable) over an entire memory, and the canonical idiom is then to subslice them further; something like
memory.data_mut(&mut store)[start..end]. We can support R/R with this but it ain't gonna be efficient: we'd have to capture the whole memory because we don't know about the subsequent sub-slice.This PR adds
Memory::data_rangeandMemory::data_range_mutto borrow only one range of a memory (and an API alongsideMemory::data_and_store_mutas well, with a bit more fiddly detail involving aMemoryRangesstruct that represents the memory capability without requiring a full reborrow/rederivation of the borrowedTas well).This PR also updates both the component-model canonical ABI implementation, and Wiggle, to use this more precise API, so when we eventually implement R/R, we will have precise/small/efficient traces for all of WASIp{1,2,3} programs.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
:thumbs_up: fitzgen submitted PR review:
r=me w/ comments below addressed
:speech_balloon: fitzgen created PR review comment:
Do we really not already have a method to go from
&mut Store[Inner]<T>to(&mut T, &mut StoreOpaque)?? That's surprising. Seems worth pulling out into its own method if we really don't.
:speech_balloon: fitzgen created PR review comment:
And similar here
:speech_balloon: fitzgen created PR review comment:
And similar here
:speech_balloon: fitzgen created PR review comment:
I think this method is a little misnamed, maybe
ranges_and_data_mutordata_ranges_and_store_data_mut? Because we aren't giving back a whole store, just the store'sTdata. Unfortunate name clobber with "data" being both "memory data" and the "store data" :-/
:speech_balloon: fitzgen created PR review comment:
And then similar regarding
SliceIndexhere
:speech_balloon: fitzgen created PR review comment:
Could this instead take a
SliceIndex<u8>so thatstart..,..end,start..=end, etc... all work with it?
:speech_balloon: fitzgen created PR review comment:
Can you also add a
#[should_panic]test for using a memory from the wrong store? Just because we've had CVEs in the past for forgotten same-store/engine checks, which I don't think this could actually lead to in this case, but best to make sure it is covered.
github-actions[bot] added the label wasi on PR #15183.
github-actions[bot] added the label wasmtime:api on PR #15183.
:memo: cfallin submitted PR review.
:speech_balloon: cfallin created PR review comment:
Unfortunately this would mean that we don't have the range for later dirty-memory tracking / record-replay -- the
SliceIndextrait only lets us apply that abstract index to a slice, not get the start/end indices. (We could derive it by getting raw addresses and doing arithmetic but that seems kind of suboptimal)I'll leave this as-is on that basis, but happy to refine in followup if you have ideas here!
:speech_balloon: cfallin created PR review comment:
(see above)
:memo: cfallin submitted PR review.
:memo: cfallin submitted PR review.
:speech_balloon: cfallin created PR review comment:
Renamed! (re: the range vs
SliceIndex, see above)
cfallin updated PR #15183.
:memo: cfallin submitted PR review.
:speech_balloon: cfallin created PR review comment:
Added!
:memo: cfallin submitted PR review.
:speech_balloon: cfallin created PR review comment:
(see above)
cfallin updated PR #15183.
:memo: cfallin submitted PR review.
:speech_balloon: cfallin created PR review comment:
Done!
cfallin has enabled auto merge for PR #15183.
cfallin added PR #15183 Add memory range APIs, and borrow guest memory by range when possible. to the merge queue
:check: cfallin merged PR #15183.
cfallin removed PR #15183 Add memory range APIs, and borrow guest memory by range when possible. from the merge queue
Last updated: Nov 19 2026 at 20:05 UTC