Skip to content

Commit c96804d

Browse files
nia-eRalfJung
andauthored
Apply suggestions from code review
Co-authored-by: Ralf Jung <[email protected]>
1 parent 6454be8 commit c96804d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/shims/native_lib/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
349349

350350
if !tracing {
351351
// Expose all provenances in this allocation, since the native code can do $whatever.
352+
// Can be skipped when tracing; in that case we'll expose just the actually-read parts later.
352353
for prov in alloc.provenance().provenances() {
353354
this.expose_provenance(prov)?;
354355
}
@@ -357,6 +358,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
357358
// Prepare for possible write from native code if mutable.
358359
if info.mutbl.is_mut() {
359360
let (alloc, cx) = this.get_alloc_raw_mut(alloc_id)?;
361+
// These writes could initialize everything and wreck havoc with the pointers.
362+
// We can skip that when tracing; in that case we'll later do that only for the memory that got actually written.
360363
if !tracing {
361364
alloc.process_native_write(&cx.tcx, None);
362365
}

tests/native-lib/fail/trace_write.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ fn partial_init() {
1616
let mut slice = std::mem::MaybeUninit::<[u8; 3]>::uninit();
1717
let slice_ptr = slice.as_mut_ptr().cast::<u8>();
1818
unsafe {
19+
// Initialize the first two elements.
1920
init_n(2, slice_ptr);
2021
assert!(*slice_ptr == 0);
2122
assert!(*slice_ptr.offset(1) == 0);
23+
// Reading the third is UB!
2224
let _val = *slice_ptr.offset(2); //~ ERROR: Undefined Behavior: using uninitialized data
2325
}
2426
}

0 commit comments

Comments
 (0)