diff options
| author | Michael Goulet <michael@errs.io> | 2025-03-06 12:22:18 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-06 12:22:18 -0500 |
| commit | b7b2179b5e526f3a84da2e5f3667b512bd6339bc (patch) | |
| tree | 8a7ad0316683cb22d0405d334247d4a2bc34cfb8 /compiler/rustc_const_eval/src | |
| parent | 59cd96770b1ed1d16b4be338fff83052ee7db854 (diff) | |
| parent | 88f988cf139797edd56aea011998d5c9f07b5685 (diff) | |
| download | rust-b7b2179b5e526f3a84da2e5f3667b512bd6339bc.tar.gz rust-b7b2179b5e526f3a84da2e5f3667b512bd6339bc.zip | |
Rollup merge of #137802 - RalfJung:miri-native-call-exposed, r=oli-obk
miri native-call support: all previously exposed provenance is accessible to the callee When Miri invokes a native C function, the memory C can access needs to be "prepared": to avoid false positives, we need to consider all that memory initialized, and we need to consider it to have arbitrary provenance. So far we did this for all pointers passed to C, but not for pointers that were exposed already before the native call. This PR adjusts the logic so that we now "prepare" all memory that has ever been exposed. This fixes cases such as: - cast a pointer to integer, send that integer to C, and access the memory there (`test_pass_ptr_as_int`) - send a pointer to some memory to C, which stores it somewhere; then in Rust store another pointer in that memory, and access that via C (`test_pass_ptr_via_previously_shared_mem`) r? `````@oli-obk`````
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/memory.rs | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 4f4b6785844..ce0b5a350e0 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -955,18 +955,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { /// Handle the effect an FFI call might have on the state of allocations. /// This overapproximates the modifications which external code might make to memory: - /// We set all reachable allocations as initialized, mark all provenances as exposed + /// We set all reachable allocations as initialized, mark all reachable provenances as exposed /// and overwrite them with `Provenance::WILDCARD`. - pub fn prepare_for_native_call( - &mut self, - id: AllocId, - initial_prov: M::Provenance, - ) -> InterpResult<'tcx> { - // Expose provenance of the root allocation. - M::expose_provenance(self, initial_prov)?; - + /// + /// The allocations in `ids` are assumed to be already exposed. + pub fn prepare_for_native_call(&mut self, ids: Vec<AllocId>) -> InterpResult<'tcx> { let mut done = FxHashSet::default(); - let mut todo = vec![id]; + let mut todo = ids; while let Some(id) = todo.pop() { if !done.insert(id) { // We already saw this allocation before, don't process it again. |
