.memory
.allocate(Size::from_bytes(size), align, kind.into());
if zero_init {
- // We just allocated this, the access cannot fail
+ // We just allocated this, the access is definitely in-bounds.
this.memory
.get_mut(ptr.alloc_id)
.unwrap()
Align::from_bytes(align).unwrap(),
MiriMemoryKind::Rust.into(),
);
- // We just allocated this, the access cannot fail
+ // We just allocated this, the access is definitely in-bounds.
this.memory
.get_mut(ptr.alloc_id)
.unwrap()
let arg_dest = this.local_place(arg_local)?;
this.write_scalar(data, arg_dest)?;
- assert!(
- args.next().is_none(),
- "__rust_maybe_catch_panic argument has more arguments than expected"
- );
+ args.next().expect_none("__rust_maybe_catch_panic argument has more arguments than expected");
// We ourselves will return `0`, eventually (because we will not return if we paniced).
this.write_null(dest)?;
}
"__errno_location" | "__error" => {
- let errno_scalar: Scalar<Tag> = this.machine.last_error.unwrap().into();
- this.write_scalar(errno_scalar, dest)?;
+ let errno_place = this.machine.last_error.unwrap();
+ this.write_scalar(errno_place.to_ref().to_scalar()?, dest)?;
}
"getenv" => {
// Hook pthread calls that go to the thread-local storage memory subsystem.
"pthread_key_create" => {
- let key_ptr = this.read_scalar(args[0])?.not_undef()?;
+ let key_place = this.deref_operand(args[0])?;
// Extract the function type out of the signature (that seems easier than constructing it ourselves).
let dtor = match this.test_null(this.read_scalar(args[1])?.not_undef()?)? {
throw_unsup!(OutOfTls);
}
- let key_ptr = this
- .memory
- .check_ptr_access(key_ptr, key_layout.size, key_layout.align.abi)?
- .expect("cannot be a ZST");
- this.memory.get_mut(key_ptr.alloc_id)?.write_scalar(
- tcx,
- key_ptr,
- Scalar::from_uint(key, key_layout.size).into(),
- key_layout.size,
- )?;
+ this.write_scalar(Scalar::from_uint(key, key_layout.size), key_place.into())?;
// Return success (`0`).
this.write_null(dest)?;
let system_info_ptr = this
.check_mplace_access(system_info, None)?
.expect("cannot be a ZST");
+ // We rely on `deref_operand` doing bounds checks for us.
// Initialize with `0`.
this.memory
.get_mut(system_info_ptr.alloc_id)?
}
return Ok(None);
}
-
- fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
- let this = self.eval_context_mut();
- let errno_ptr = this.machine.last_error.unwrap();
- this.memory.get_mut(errno_ptr.alloc_id)?.write_scalar(
- &*this.tcx,
- errno_ptr,
- scalar.into(),
- Size::from_bits(32),
- )
- }
-
- fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
- let this = self.eval_context_mut();
- let errno_ptr = this.machine.last_error.unwrap();
- this.memory
- .get(errno_ptr.alloc_id)?
- .read_scalar(&*this.tcx, errno_ptr, Size::from_bits(32))?
- .not_undef()
- }
-
- fn consume_io_error(&mut self, e: std::io::Error) -> InterpResult<'tcx> {
- self.eval_context_mut().set_last_error(Scalar::from_int(
- e.raw_os_error().unwrap(),
- Size::from_bits(32),
- ))
- }
}
// Shims the linux 'getrandom()' syscall.