commit
8355437d5d
@ -1 +1 @@
|
||||
c34472b77084c9f76f872871aeab121daf81fb99
|
||||
9e346646e93cc243567e27bb0f4e8716d56ad1f1
|
||||
|
@ -63,7 +63,7 @@ impl<'mir, 'tcx> GlobalState {
|
||||
// This never overflows because `int >= glb`
|
||||
let offset = int - glb;
|
||||
// If the offset exceeds the size of the allocation, this access is illegal
|
||||
if offset <= memory.get(alloc_id)?.size.bytes() {
|
||||
if offset <= memory.get_size_and_align(alloc_id, AllocCheck::MaybeDead)?.0.bytes() {
|
||||
// This pointer is untagged because it was created from a cast
|
||||
Pointer::new_with_tag(alloc_id, Size::from_bytes(offset), Tag::Untagged)
|
||||
} else {
|
||||
|
@ -75,7 +75,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
|
||||
let ptr = self.pointer_offset_inbounds(
|
||||
left.to_scalar()?,
|
||||
pointee_ty,
|
||||
right.to_scalar()?.to_isize(self)?,
|
||||
right.to_scalar()?.to_machine_isize(self)?,
|
||||
)?;
|
||||
(ptr, false, left.layout.ty)
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
match dlsym {
|
||||
GetEntropy => {
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let len = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
this.gen_random(ptr, len as usize)?;
|
||||
this.write_null(dest)?;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
this.check_no_isolation("getcwd")?;
|
||||
|
||||
let buf = this.read_scalar(buf_op)?.not_undef()?;
|
||||
let size = this.read_scalar(size_op)?.to_usize(&*this.tcx)?;
|
||||
let size = this.read_scalar(size_op)?.to_machine_usize(&*this.tcx)?;
|
||||
// If we cannot get the current directory, we return null
|
||||
match env::current_dir() {
|
||||
Ok(cwd) => {
|
||||
|
@ -144,13 +144,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let ret = ret.expect("dest is `Some` but ret is `None`");
|
||||
match link_name {
|
||||
"malloc" => {
|
||||
let size = this.read_scalar(args[0])?.to_usize(this)?;
|
||||
let size = this.read_scalar(args[0])?.to_machine_usize(this)?;
|
||||
let res = this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::C);
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
"calloc" => {
|
||||
let items = this.read_scalar(args[0])?.to_usize(this)?;
|
||||
let len = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let items = this.read_scalar(args[0])?.to_machine_usize(this)?;
|
||||
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
let size = items
|
||||
.checked_mul(len)
|
||||
.ok_or_else(|| err_panic!(Overflow(mir::BinOp::Mul)))?;
|
||||
@ -159,8 +159,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
}
|
||||
"posix_memalign" => {
|
||||
let ret = this.deref_operand(args[0])?;
|
||||
let align = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let size = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let align = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
let size = this.read_scalar(args[2])?.to_machine_usize(this)?;
|
||||
// Align must be power of 2, and also at least ptr-sized (POSIX rules).
|
||||
if !align.is_power_of_two() {
|
||||
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
|
||||
@ -190,14 +190,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
}
|
||||
"realloc" => {
|
||||
let old_ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let new_size = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let new_size = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
let res = this.realloc(old_ptr, new_size, MiriMemoryKind::C)?;
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
|
||||
"__rust_alloc" => {
|
||||
let size = this.read_scalar(args[0])?.to_usize(this)?;
|
||||
let align = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let size = this.read_scalar(args[0])?.to_machine_usize(this)?;
|
||||
let align = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
if size == 0 {
|
||||
throw_unsup!(HeapAllocZeroBytes);
|
||||
}
|
||||
@ -212,8 +212,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
this.write_scalar(Scalar::Ptr(ptr), dest)?;
|
||||
}
|
||||
"__rust_alloc_zeroed" => {
|
||||
let size = this.read_scalar(args[0])?.to_usize(this)?;
|
||||
let align = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let size = this.read_scalar(args[0])?.to_machine_usize(this)?;
|
||||
let align = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
if size == 0 {
|
||||
throw_unsup!(HeapAllocZeroBytes);
|
||||
}
|
||||
@ -233,8 +233,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
}
|
||||
"__rust_dealloc" => {
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let old_size = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let align = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let old_size = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
let align = this.read_scalar(args[2])?.to_machine_usize(this)?;
|
||||
if old_size == 0 {
|
||||
throw_unsup!(HeapAllocZeroBytes);
|
||||
}
|
||||
@ -253,9 +253,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
}
|
||||
"__rust_realloc" => {
|
||||
let ptr = this.read_scalar(args[0])?.to_ptr()?;
|
||||
let old_size = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let align = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let new_size = this.read_scalar(args[3])?.to_usize(this)?;
|
||||
let old_size = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
let align = this.read_scalar(args[2])?.to_machine_usize(this)?;
|
||||
let new_size = this.read_scalar(args[3])?.to_machine_usize(this)?;
|
||||
if old_size == 0 || new_size == 0 {
|
||||
throw_unsup!(HeapAllocZeroBytes);
|
||||
}
|
||||
@ -277,11 +277,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let sys_getrandom = this
|
||||
.eval_path_scalar(&["libc", "SYS_getrandom"])?
|
||||
.expect("Failed to get libc::SYS_getrandom")
|
||||
.to_usize(this)?;
|
||||
.to_machine_usize(this)?;
|
||||
|
||||
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
|
||||
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
|
||||
match this.read_scalar(args[0])?.to_usize(this)? {
|
||||
match this.read_scalar(args[0])?.to_machine_usize(this)? {
|
||||
id if id == sys_getrandom => {
|
||||
// The first argument is the syscall id,
|
||||
// so skip over it.
|
||||
@ -357,7 +357,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
"memcmp" => {
|
||||
let left = this.read_scalar(args[0])?.not_undef()?;
|
||||
let right = this.read_scalar(args[1])?.not_undef()?;
|
||||
let n = Size::from_bytes(this.read_scalar(args[2])?.to_usize(this)?);
|
||||
let n = Size::from_bytes(this.read_scalar(args[2])?.to_machine_usize(this)?);
|
||||
|
||||
let result = {
|
||||
let left_bytes = this.memory.read_bytes(left, n)?;
|
||||
@ -377,7 +377,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
"memrchr" => {
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let val = this.read_scalar(args[1])?.to_i32()? as u8;
|
||||
let num = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let num = this.read_scalar(args[2])?.to_machine_usize(this)?;
|
||||
if let Some(idx) = this
|
||||
.memory
|
||||
.read_bytes(ptr, Size::from_bytes(num))?
|
||||
@ -395,7 +395,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
"memchr" => {
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let val = this.read_scalar(args[1])?.to_i32()? as u8;
|
||||
let num = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let num = this.read_scalar(args[2])?.to_machine_usize(this)?;
|
||||
let idx = this
|
||||
.memory
|
||||
.read_bytes(ptr, Size::from_bytes(num))?
|
||||
@ -462,7 +462,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
"write" => {
|
||||
let fd = this.read_scalar(args[0])?.to_i32()?;
|
||||
let buf = this.read_scalar(args[1])?.not_undef()?;
|
||||
let n = this.read_scalar(args[2])?.to_usize(tcx)?;
|
||||
let n = this.read_scalar(args[2])?.to_machine_usize(tcx)?;
|
||||
trace!("Called write({:?}, {:?}, {:?})", fd, buf, n);
|
||||
let result = if fd == 1 || fd == 2 {
|
||||
// stdout/stderr
|
||||
@ -771,7 +771,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
this.write_scalar(this.machine.argv.expect("machine must be initialized"), dest)?;
|
||||
}
|
||||
"SecRandomCopyBytes" => {
|
||||
let len = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
let ptr = this.read_scalar(args[2])?.not_undef()?;
|
||||
this.gen_random(ptr, len as usize)?;
|
||||
this.write_null(dest)?;
|
||||
@ -786,25 +786,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
this.write_scalar(Scalar::from_int(1, this.pointer_size()), dest)?;
|
||||
}
|
||||
"HeapAlloc" => {
|
||||
let _handle = this.read_scalar(args[0])?.to_isize(this)?;
|
||||
let _handle = this.read_scalar(args[0])?.to_machine_isize(this)?;
|
||||
let flags = this.read_scalar(args[1])?.to_u32()?;
|
||||
let size = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let size = this.read_scalar(args[2])?.to_machine_usize(this)?;
|
||||
let zero_init = (flags & 0x00000008) != 0; // HEAP_ZERO_MEMORY
|
||||
let res = this.malloc(size, zero_init, MiriMemoryKind::WinHeap);
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
"HeapFree" => {
|
||||
let _handle = this.read_scalar(args[0])?.to_isize(this)?;
|
||||
let _handle = this.read_scalar(args[0])?.to_machine_isize(this)?;
|
||||
let _flags = this.read_scalar(args[1])?.to_u32()?;
|
||||
let ptr = this.read_scalar(args[2])?.not_undef()?;
|
||||
this.free(ptr, MiriMemoryKind::WinHeap)?;
|
||||
this.write_scalar(Scalar::from_int(1, Size::from_bytes(4)), dest)?;
|
||||
}
|
||||
"HeapReAlloc" => {
|
||||
let _handle = this.read_scalar(args[0])?.to_isize(this)?;
|
||||
let _handle = this.read_scalar(args[0])?.to_machine_isize(this)?;
|
||||
let _flags = this.read_scalar(args[1])?.to_u32()?;
|
||||
let ptr = this.read_scalar(args[2])?.not_undef()?;
|
||||
let size = this.read_scalar(args[3])?.to_usize(this)?;
|
||||
let size = this.read_scalar(args[3])?.to_machine_usize(this)?;
|
||||
let res = this.realloc(ptr, size, MiriMemoryKind::WinHeap)?;
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
@ -883,7 +883,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
this.write_scalar(Scalar::from_int(which, this.pointer_size()), dest)?;
|
||||
}
|
||||
"WriteFile" => {
|
||||
let handle = this.read_scalar(args[0])?.to_isize(this)?;
|
||||
let handle = this.read_scalar(args[0])?.to_machine_isize(this)?;
|
||||
let buf = this.read_scalar(args[1])?.not_undef()?;
|
||||
let n = this.read_scalar(args[2])?.to_u32()?;
|
||||
let written_place = this.deref_operand(args[3])?;
|
||||
@ -973,7 +973,7 @@ fn linux_getrandom<'tcx>(
|
||||
dest: PlaceTy<'tcx, Tag>,
|
||||
) -> InterpResult<'tcx> {
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let len = this.read_scalar(args[1])?.to_usize(this)?;
|
||||
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
|
||||
|
||||
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
|
||||
// neither of which have any effect on our current PRNG.
|
||||
|
@ -154,7 +154,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
|
||||
this.check_no_isolation("read")?;
|
||||
|
||||
let count = this.read_scalar(count_op)?.to_usize(&*this.tcx)?;
|
||||
let count = this.read_scalar(count_op)?.to_machine_usize(&*this.tcx)?;
|
||||
// Reading zero bytes should not change `buf`.
|
||||
if count == 0 {
|
||||
return Ok(0);
|
||||
@ -166,8 +166,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
this.remove_handle_and(fd, |mut handle, this| {
|
||||
// Don't use `?` to avoid returning before reinserting the handle.
|
||||
let bytes = this.force_ptr(buf_scalar).and_then(|buf| {
|
||||
// FIXME: Don't use raw methods
|
||||
this.memory
|
||||
.get_mut(buf.alloc_id)?
|
||||
.get_raw_mut(buf.alloc_id)?
|
||||
.get_bytes_mut(&*this.tcx, buf, Size::from_bytes(count))
|
||||
.map(|buffer| handle.file.read(buffer))
|
||||
});
|
||||
@ -186,7 +187,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
|
||||
this.check_no_isolation("write")?;
|
||||
|
||||
let count = this.read_scalar(count_op)?.to_usize(&*this.tcx)?;
|
||||
let count = this.read_scalar(count_op)?.to_machine_usize(&*this.tcx)?;
|
||||
// Writing zero bytes should not change `buf`.
|
||||
if count == 0 {
|
||||
return Ok(0);
|
||||
@ -195,7 +196,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?;
|
||||
|
||||
this.remove_handle_and(fd, |mut handle, this| {
|
||||
let bytes = this.memory.get(buf.alloc_id).and_then(|alloc| {
|
||||
// FIXME: Don't use raw methods
|
||||
let bytes = this.memory.get_raw(buf.alloc_id).and_then(|alloc| {
|
||||
alloc
|
||||
.get_bytes(&*this.tcx, buf, Size::from_bytes(count))
|
||||
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
|
||||
|
@ -35,7 +35,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let intrinsic_name = &*tcx.item_name(instance.def_id()).as_str();
|
||||
match intrinsic_name {
|
||||
"arith_offset" => {
|
||||
let offset = this.read_scalar(args[1])?.to_isize(this)?;
|
||||
let offset = this.read_scalar(args[1])?.to_machine_isize(this)?;
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
|
||||
let pointee_ty = substs.type_at(0);
|
||||
@ -206,7 +206,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let elem_ty = substs.type_at(0);
|
||||
let elem_layout = this.layout_of(elem_ty)?;
|
||||
let elem_size = elem_layout.size.bytes();
|
||||
let count = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let count = this.read_scalar(args[2])?.to_machine_usize(this)?;
|
||||
let elem_align = elem_layout.align.abi;
|
||||
|
||||
let size = Size::from_bytes(count * elem_size);
|
||||
@ -371,7 +371,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
}
|
||||
|
||||
"offset" => {
|
||||
let offset = this.read_scalar(args[1])?.to_isize(this)?;
|
||||
let offset = this.read_scalar(args[1])?.to_machine_isize(this)?;
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let result_ptr = this.pointer_offset_inbounds(ptr, substs.type_at(0), offset)?;
|
||||
this.write_scalar(result_ptr, dest)?;
|
||||
@ -542,7 +542,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let ptr = mplace.ptr.to_ptr()?;
|
||||
// We know the return place is in-bounds
|
||||
this.memory
|
||||
.get_mut(ptr.alloc_id)?
|
||||
.get_raw_mut(ptr.alloc_id)?
|
||||
.mark_definedness(ptr, dest.layout.size, false);
|
||||
}
|
||||
}
|
||||
@ -554,7 +554,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let ty_layout = this.layout_of(ty)?;
|
||||
let val_byte = this.read_scalar(args[1])?.to_u8()?;
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let count = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let count = this.read_scalar(args[2])?.to_machine_usize(this)?;
|
||||
let byte_count = ty_layout.size * count;
|
||||
this.memory.write_bytes(ptr, iter::repeat(val_byte).take(byte_count.bytes() as usize))?;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let ptr_scalar = this.read_scalar(ptr_op)?.not_undef()?;
|
||||
|
||||
if let Ok(ptr) = this.force_ptr(ptr_scalar) {
|
||||
let cur_align = this.memory.get(ptr.alloc_id)?.align.bytes() as usize;
|
||||
let cur_align = this.memory.get_size_and_align(ptr.alloc_id, AllocCheck::MaybeDead)?.1.bytes() as usize;
|
||||
if cur_align >= req_align {
|
||||
// if the allocation alignment is at least the required alignment we use the
|
||||
// libcore implementation
|
||||
|
@ -540,8 +540,8 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
kind, new_tag, ptr.tag, place.layout.ty, ptr.erase_tag(), size.bytes());
|
||||
|
||||
// Get the allocation. It might not be mutable, so we cannot use `get_mut`.
|
||||
let alloc = this.memory.get(ptr.alloc_id)?;
|
||||
let stacked_borrows = alloc.extra.stacked_borrows.as_ref().expect("we should have Stacked Borrows data");
|
||||
let extra = &this.memory.get_raw(ptr.alloc_id)?.extra;
|
||||
let stacked_borrows = extra.stacked_borrows.as_ref().expect("we should have Stacked Borrows data");
|
||||
// Update the stacks.
|
||||
// Make sure that raw pointers and mutable shared references are reborrowed "weak":
|
||||
// There could be existing unique pointers reborrowed from them that should remain valid!
|
||||
|
Loading…
x
Reference in New Issue
Block a user