Add bounds-checked unsafe intrinsics#13597
Merged
fitzgen merged 5 commits intoJun 10, 2026
Merged
Conversation
cfallin
approved these changes
Jun 9, 2026
cfallin
left a comment
Member
There was a problem hiding this comment.
Great idea; the bounds-checking logic looks right to me. Just a few comments below.
|
|
||
| let [_callee_vmctx, _caller_vmctx, base_address, offset, length] = *self.abi_load_params() | ||
| else { | ||
| unreachable!() |
Member
There was a problem hiding this comment.
More descriptive panic message here? Note that the above corresponds to a signature declared elsewhere such that mismatches will be caught earlier?
| .trapz(addr, ir::TrapCode::HEAP_OUT_OF_BOUNDS); | ||
| addr | ||
| } | ||
| // Otherwise, when Specter mitigations are disabled, just conditionally |
| /// | ||
| /// See [`TrampolineCompiler::checked_native_addr`] for details; this is the | ||
| /// equivalent for the inlined translation path. | ||
| fn checked_native_addr( |
Member
There was a problem hiding this comment.
Deja vu -- is there any way to deduplicate the two implementations here? Especially if we add any other kind of logic to bounds-checking in the future, and especially as it's safety-critical code, it's unfortunate it has to be duplicated...
Member
Author
There was a problem hiding this comment.
Deduped. Will send a follow up to dedupe the rest of the methods as well.
19ed841 to
0b42dba
Compare
These intrinsics are similar to the unchecked versions, but instead of taking a raw address, take a base, offset, and length. They do a bounds check first, and trap on out-of-bounds accesses or perform the actual in-bounds access. When Spectre mitigations are enabled, their bounds check has Spectre mitigations applied.
prtest:full
This means we will correctly call the raise-trap libcall when signals-based traps are disabled. However, it also means that `UnsafeIntrinsicCompiler` needed to be refactored a bit to take a `FuncBuilder` rather than a `FuncCursor`, and additionally take a generic `T: TranslateTrap`. This should fix the s390x errors in CI.
12421a9 to
c78b73b
Compare
Member
Author
Merged
via the queue into
bytecodealliance:main
with commit Jun 10, 2026
01094f4
221 of 237 checks passed
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.
These intrinsics are similar to the unchecked versions, but instead of taking a raw address, take a base, offset, and length. They do a bounds check first, and trap on out-of-bounds accesses or perform the actual in-bounds access. When Spectre mitigations are enabled, their bounds check has Spectre mitigations applied.