Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
The Miri Conjob Bot committed Oct 17, 2023
1 parent 3b9432d commit b8d95e2
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 49 deletions.
6 changes: 1 addition & 5 deletions src/borrow_tracker/tree_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,7 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
// Make sure the new permission makes sense as the initial permission of a fresh tag.
assert!(new_perm.initial_state.is_initial());
// Ensure we bail out if the pointer goes out-of-bounds (see miri#1050).
this.check_ptr_access(
place.ptr(),
ptr_size,
CheckInAllocMsg::InboundsTest,
)?;
this.check_ptr_access(place.ptr(), ptr_size, CheckInAllocMsg::InboundsTest)?;

// It is crucial that this gets called on all code paths, to ensure we track tag creation.
let log_creation = |this: &MiriInterpCx<'mir, 'tcx>,
Expand Down
5 changes: 1 addition & 4 deletions src/concurrency/data_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
// even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must
// be 8-aligned).
let align = Align::from_bytes(place.layout.size.bytes()).unwrap();
this.check_ptr_align(
place.ptr(),
align,
)?;
this.check_ptr_align(place.ptr(), align)?;
// Ensure the allocation is mutable. Even failing (read-only) compare_exchange need mutable
// memory on many targets (i.e., they segfault if taht memory is mapped read-only), and
// atomic loads can be implemented via compare_exchange on some targets. There could
Expand Down
4 changes: 1 addition & 3 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let size2 = Size::from_bytes(2);
let this = self.eval_context_mut();
this.check_ptr_align(ptr, Align::from_bytes(2).unwrap())?;
let mut alloc = this
.get_ptr_alloc_mut(ptr, size2 * string_length)?
.unwrap(); // not a ZST, so we will get a result
let mut alloc = this.get_ptr_alloc_mut(ptr, size2 * string_length)?.unwrap(); // not a ZST, so we will get a result
for (offset, wchar) in wide_str.iter().copied().chain(iter::once(0x0000)).enumerate() {
let offset = u64::try_from(offset).unwrap();
alloc.write_scalar(alloc_range(size2 * offset, size2), Scalar::from_u16(wchar))?;
Expand Down
14 changes: 2 additions & 12 deletions src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.ptr_get_alloc_id(ptr_dest)?;
this.ptr_get_alloc_id(ptr_src)?;

this.mem_copy(
ptr_src,
ptr_dest,
Size::from_bytes(n),
true,
)?;
this.mem_copy(ptr_src, ptr_dest, Size::from_bytes(n), true)?;
this.write_pointer(ptr_dest, dest)?;
}
"strcpy" => {
Expand All @@ -826,12 +821,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// reason to have `strcpy` destroy pointer provenance.
// This reads at least 1 byte, so we are already enforcing that this is a valid pointer.
let n = this.read_c_str(ptr_src)?.len().checked_add(1).unwrap();
this.mem_copy(
ptr_src,
ptr_dest,
Size::from_bytes(n),
true,
)?;
this.mem_copy(ptr_src, ptr_dest, Size::from_bytes(n), true)?;
this.write_pointer(ptr_dest, dest)?;
}

Expand Down
12 changes: 2 additions & 10 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,11 +756,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
trace!("Reading from FD {}, size {}", fd, count);

// Check that the *entire* buffer is actually valid memory.
this.check_ptr_access(
buf,
Size::from_bytes(count),
CheckInAllocMsg::MemoryAccessTest,
)?;
this.check_ptr_access(buf, Size::from_bytes(count), CheckInAllocMsg::MemoryAccessTest)?;

// We cap the number of read bytes to the largest value that we are able to fit in both the
// host's and target's `isize`. This saves us from having to handle overflows later.
Expand Down Expand Up @@ -809,11 +805,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// Isolation check is done via `FileDescriptor` trait.

// Check that the *entire* buffer is actually valid memory.
this.check_ptr_access(
buf,
Size::from_bytes(count),
CheckInAllocMsg::MemoryAccessTest,
)?;
this.check_ptr_access(buf, Size::from_bytes(count), CheckInAllocMsg::MemoryAccessTest)?;

// We cap the number of written bytes to the largest value that we are able to fit in both the
// host's and target's `isize`. This saves us from having to handle overflows later.
Expand Down
5 changes: 1 addition & 4 deletions src/shims/unix/linux/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ pub fn futex<'tcx>(
return Ok(());
}

let timeout = this.deref_pointer_as(
&args[3],
this.libc_ty_layout("timespec"),
)?;
let timeout = this.deref_pointer_as(&args[3], this.libc_ty_layout("timespec"))?;
let timeout_time = if this.ptr_is_null(timeout.ptr())? {
None
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/shims/windows/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.atomic_fence(AtomicFenceOrd::SeqCst)?;

let layout = this.machine.layouts.uint(size).unwrap();
let futex_val = this
.read_scalar_atomic(&this.ptr_to_mplace(ptr, layout), AtomicReadOrd::Relaxed)?;
let futex_val =
this.read_scalar_atomic(&this.ptr_to_mplace(ptr, layout), AtomicReadOrd::Relaxed)?;
let compare_val = this.read_scalar(&this.ptr_to_mplace(compare, layout))?;

if futex_val == compare_val {
Expand Down
7 changes: 1 addition & 6 deletions src/shims/x86/sse3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
let src_ptr = this.read_pointer(src_ptr)?;
let dest = dest.force_mplace(this)?;

this.mem_copy(
src_ptr,
dest.ptr(),
dest.layout.size,
/*nonoverlapping*/ true,
)?;
this.mem_copy(src_ptr, dest.ptr(), dest.layout.size, /*nonoverlapping*/ true)?;
}
_ => return Ok(EmulateForeignItemResult::NotSupported),
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/dangling_pointers/deref_dangling_box.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Should be caught even without retagging
//@compile-flags: -Zmiri-disable-stacked-borrows
#![feature(strict_provenance)]
use std::ptr::{addr_of_mut, self};
use std::ptr::{self, addr_of_mut};

// Deref'ing a dangling raw pointer is fine, but for a dangling box it is not.
// We do this behind a pointer indirection to potentially fool validity checking.
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/dangling_pointers/deref_dangling_ref.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Should be caught even without retagging
//@compile-flags: -Zmiri-disable-stacked-borrows
#![feature(strict_provenance)]
use std::ptr::{addr_of_mut, self};
use std::ptr::{self, addr_of_mut};

// Deref'ing a dangling raw pointer is fine, but for a dangling reference it is not.
// We do this behind a pointer indirection to potentially fool validity checking.
Expand Down
2 changes: 1 addition & 1 deletion tests/pass/ptr_raw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(strict_provenance)]
use std::ptr::{self, addr_of};
use std::mem;
use std::ptr::{self, addr_of};

fn basic_raw() {
let mut x = 12;
Expand Down

0 comments on commit b8d95e2

Please sign in to comment.