Skip to content

Commit 7b35b59

Browse files
committed
interpret/allocation: expose init + write_wildcards on a range
1 parent 2783fc4 commit 7b35b59

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -809,11 +809,17 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
809809
uninit_bytes.fill(0);
810810
}
811811
}
812-
// Mark everything as initialized now.
813-
self.mark_init(full_range, true);
812+
self.mark_foreign_write(full_range);
813+
}
814814

815-
// Set provenance of all bytes to wildcard.
816-
self.provenance.write_wildcards(self.len());
815+
/// Mark all bytes in the given range as initialised, setting provenances
816+
/// to wildcards. This entirely breaks the normal mechanisms for tracking
817+
/// initialisation and is only provided for Miri operating in native-lib
818+
/// mode. Only call this if you're certain the underlying bytes were in
819+
/// fact actually initialised!
820+
pub fn mark_foreign_write(&mut self, range: AllocRange) {
821+
self.mark_init(range, true);
822+
self.provenance.write_wildcards(range);
817823
}
818824

819825
/// Remove all provenance in the given memory range.

compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
212212
Ok(())
213213
}
214214

215-
/// Overwrites all provenance in the allocation with wildcard provenance.
215+
/// Overwrites all provenance in the given range with wildcard provenance.
216216
///
217217
/// Provided for usage in Miri and panics otherwise.
218-
pub fn write_wildcards(&mut self, alloc_size: usize) {
218+
pub fn write_wildcards(&mut self, range: AllocRange) {
219219
assert!(
220220
Prov::OFFSET_IS_ADDR,
221221
"writing wildcard provenance is not supported when `OFFSET_IS_ADDR` is false"
@@ -224,9 +224,8 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
224224

225225
// Remove all pointer provenances, then write wildcards into the whole byte range.
226226
self.ptrs.clear();
227-
let last = Size::from_bytes(alloc_size);
228227
let bytes = self.bytes.get_or_insert_with(Box::default);
229-
for offset in Size::ZERO..last {
228+
for offset in range.start..range.start + range.size {
230229
bytes.insert(offset, wildcard);
231230
}
232231
}

0 commit comments

Comments
 (0)