use deref_pointer_as instead of deref_pointer
This commit is contained in:
parent
5460fbe610
commit
562b282fcc
14 changed files with 39 additions and 34 deletions
|
|
@ -102,7 +102,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
size: &OpTy<'tcx>,
|
||||
) -> InterpResult<'tcx, Scalar> {
|
||||
let this = self.eval_context_mut();
|
||||
let memptr = this.deref_pointer(memptr)?;
|
||||
let memptr = this.deref_pointer_as(memptr, this.machine.layouts.mut_raw_ptr)?;
|
||||
let align = this.read_target_usize(align)?;
|
||||
let size = this.read_target_usize(size)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -89,9 +89,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
1 => {
|
||||
let [_flags, buf] = this.check_shim(abi, Conv::Rust, link_name, args)?;
|
||||
|
||||
let buf_place = this.deref_pointer(buf)?;
|
||||
|
||||
let ptr_layout = this.layout_of(ptr_ty)?;
|
||||
let buf_place = this.deref_pointer_as(buf, ptr_layout)?;
|
||||
|
||||
for (i, ptr) in ptrs.into_iter().enumerate() {
|
||||
let offset = ptr_layout.size.checked_mul(i.try_into().unwrap(), this).unwrap();
|
||||
|
|
|
|||
|
|
@ -865,7 +865,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
"lgammaf_r" => {
|
||||
let [x, signp] = this.check_shim(abi, Conv::C, link_name, args)?;
|
||||
let x = this.read_scalar(x)?.to_f32()?;
|
||||
let signp = this.deref_pointer(signp)?;
|
||||
let signp = this.deref_pointer_as(signp, this.machine.layouts.i32)?;
|
||||
|
||||
// Using host floats (but it's fine, these operations do not have guaranteed precision).
|
||||
let (res, sign) = x.to_host().ln_gamma();
|
||||
|
|
@ -876,7 +876,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
"lgamma_r" => {
|
||||
let [x, signp] = this.check_shim(abi, Conv::C, link_name, args)?;
|
||||
let x = this.read_scalar(x)?.to_f64()?;
|
||||
let signp = this.deref_pointer(signp)?;
|
||||
let signp = this.deref_pointer_as(signp, this.machine.layouts.i32)?;
|
||||
|
||||
// Using host floats (but it's fine, these operations do not have guaranteed precision).
|
||||
let (res, sign) = x.to_host().ln_gamma();
|
||||
|
|
|
|||
|
|
@ -132,16 +132,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
this.assert_target_os_is_unix("localtime_r");
|
||||
this.check_no_isolation("`localtime_r`")?;
|
||||
|
||||
let timep = this.deref_pointer(timep)?;
|
||||
let time_layout = this.libc_ty_layout("time_t");
|
||||
let timep = this.deref_pointer_as(timep, time_layout)?;
|
||||
let result = this.deref_pointer_as(result_op, this.libc_ty_layout("tm"))?;
|
||||
|
||||
// The input "represents the number of seconds elapsed since the Epoch,
|
||||
// 1970-01-01 00:00:00 +0000 (UTC)".
|
||||
let sec_since_epoch: i64 = this
|
||||
.read_scalar(&timep)?
|
||||
.to_int(this.libc_ty_layout("time_t").size)?
|
||||
.try_into()
|
||||
.unwrap();
|
||||
let sec_since_epoch: i64 =
|
||||
this.read_scalar(&timep)?.to_int(time_layout.size)?.try_into().unwrap();
|
||||
let dt_utc: DateTime<Utc> =
|
||||
DateTime::from_timestamp(sec_since_epoch, 0).expect("Invalid timestamp");
|
||||
|
||||
|
|
@ -254,7 +252,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
let qpc = i64::try_from(duration.as_nanos()).map_err(|_| {
|
||||
err_unsup_format!("programs running longer than 2^63 nanoseconds are not supported")
|
||||
})?;
|
||||
this.write_scalar(Scalar::from_i64(qpc), &this.deref_pointer(lpPerformanceCount_op)?)?;
|
||||
this.write_scalar(
|
||||
Scalar::from_i64(qpc),
|
||||
&this.deref_pointer_as(lpPerformanceCount_op, this.machine.layouts.i64)?,
|
||||
)?;
|
||||
interp_ok(Scalar::from_i32(-1)) // return non-zero on success
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -866,8 +866,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
// These shims are enabled only when the caller is in the standard library.
|
||||
"pthread_attr_getguardsize" if this.frame_in_std() => {
|
||||
let [_attr, guard_size] = this.check_shim(abi, Conv::C, link_name, args)?;
|
||||
let guard_size = this.deref_pointer(guard_size)?;
|
||||
let guard_size_layout = this.libc_ty_layout("size_t");
|
||||
let guard_size = this.deref_pointer_as(guard_size, guard_size_layout)?;
|
||||
this.write_scalar(
|
||||
Scalar::from_uint(this.machine.page_size, guard_size_layout.size),
|
||||
&guard_size,
|
||||
|
|
@ -893,8 +893,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
this.check_shim(abi, Conv::C, link_name, args)?;
|
||||
let _attr_place =
|
||||
this.deref_pointer_as(attr_place, this.libc_ty_layout("pthread_attr_t"))?;
|
||||
let addr_place = this.deref_pointer(addr_place)?;
|
||||
let size_place = this.deref_pointer(size_place)?;
|
||||
let addr_place = this.deref_pointer_as(addr_place, this.machine.layouts.usize)?;
|
||||
let size_place = this.deref_pointer_as(size_place, this.machine.layouts.usize)?;
|
||||
|
||||
this.write_scalar(
|
||||
Scalar::from_uint(this.machine.stack_addr, this.pointer_size()),
|
||||
|
|
@ -928,7 +928,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
let pwd = this.deref_pointer_as(pwd, this.libc_ty_layout("passwd"))?;
|
||||
let buf = this.read_pointer(buf)?;
|
||||
let buflen = this.read_target_usize(buflen)?;
|
||||
let result = this.deref_pointer(result)?;
|
||||
let result = this.deref_pointer_as(result, this.machine.layouts.mut_raw_ptr)?;
|
||||
|
||||
// Must be for "us".
|
||||
if uid != UID {
|
||||
|
|
|
|||
|
|
@ -1168,6 +1168,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
}
|
||||
|
||||
let dirp = this.read_target_usize(dirp_op)?;
|
||||
let result_place = this.deref_pointer_as(result_op, this.machine.layouts.mut_raw_ptr)?;
|
||||
|
||||
// Reject if isolation is enabled.
|
||||
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
|
||||
|
|
@ -1253,15 +1254,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let result_place = this.deref_pointer(result_op)?;
|
||||
this.write_scalar(this.read_scalar(entry_op)?, &result_place)?;
|
||||
|
||||
Scalar::from_i32(0)
|
||||
}
|
||||
None => {
|
||||
// end of stream: return 0, assign *result=NULL
|
||||
this.write_null(&this.deref_pointer(result_op)?)?;
|
||||
this.write_null(&result_place)?;
|
||||
Scalar::from_i32(0)
|
||||
}
|
||||
Some(Err(e)) => {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
'tcx: 'a,
|
||||
{
|
||||
let this = self.eval_context_mut();
|
||||
let lock = this.deref_pointer(lock_ptr)?;
|
||||
let lock = this.deref_pointer_as(lock_ptr, this.libc_ty_layout("os_unfair_lock_s"))?;
|
||||
this.lazy_sync_get_data(
|
||||
&lock,
|
||||
Size::ZERO, // offset for init tracking
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
throw_unsup_format!("pset_info is only supported with list==NULL");
|
||||
}
|
||||
|
||||
let cpus = this.deref_pointer(cpus)?;
|
||||
let cpus = this.deref_pointer_as(cpus, this.machine.layouts.u32)?;
|
||||
this.write_scalar(Scalar::from_u32(this.machine.num_cpus), &cpus)?;
|
||||
this.write_null(dest)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ fn mutex_create<'tcx>(
|
|||
mutex_ptr: &OpTy<'tcx>,
|
||||
kind: MutexKind,
|
||||
) -> InterpResult<'tcx, PthreadMutex> {
|
||||
let mutex = ecx.deref_pointer(mutex_ptr)?;
|
||||
let mutex = ecx.deref_pointer_as(mutex_ptr, ecx.libc_ty_layout("pthread_mutex_t"))?;
|
||||
let id = ecx.machine.sync.mutex_create();
|
||||
let data = PthreadMutex { mutex_ref: id, kind };
|
||||
ecx.lazy_sync_init(&mutex, mutex_init_offset(ecx)?, data.clone())?;
|
||||
|
|
@ -186,7 +186,7 @@ fn mutex_get_data<'tcx, 'a>(
|
|||
where
|
||||
'tcx: 'a,
|
||||
{
|
||||
let mutex = ecx.deref_pointer(mutex_ptr)?;
|
||||
let mutex = ecx.deref_pointer_as(mutex_ptr, ecx.libc_ty_layout("pthread_mutex_t"))?;
|
||||
ecx.lazy_sync_get_data(
|
||||
&mutex,
|
||||
mutex_init_offset(ecx)?,
|
||||
|
|
@ -265,7 +265,7 @@ fn rwlock_get_data<'tcx, 'a>(
|
|||
where
|
||||
'tcx: 'a,
|
||||
{
|
||||
let rwlock = ecx.deref_pointer(rwlock_ptr)?;
|
||||
let rwlock = ecx.deref_pointer_as(rwlock_ptr, ecx.libc_ty_layout("pthread_rwlock_t"))?;
|
||||
ecx.lazy_sync_get_data(
|
||||
&rwlock,
|
||||
rwlock_init_offset(ecx)?,
|
||||
|
|
@ -383,7 +383,7 @@ fn cond_create<'tcx>(
|
|||
cond_ptr: &OpTy<'tcx>,
|
||||
clock: ClockId,
|
||||
) -> InterpResult<'tcx, PthreadCondvar> {
|
||||
let cond = ecx.deref_pointer(cond_ptr)?;
|
||||
let cond = ecx.deref_pointer_as(cond_ptr, ecx.libc_ty_layout("pthread_cond_t"))?;
|
||||
let id = ecx.machine.sync.condvar_create();
|
||||
let data = PthreadCondvar { id, clock };
|
||||
ecx.lazy_sync_init(&cond, cond_init_offset(ecx)?, data)?;
|
||||
|
|
@ -397,7 +397,7 @@ fn cond_get_data<'tcx, 'a>(
|
|||
where
|
||||
'tcx: 'a,
|
||||
{
|
||||
let cond = ecx.deref_pointer(cond_ptr)?;
|
||||
let cond = ecx.deref_pointer_as(cond_ptr, ecx.libc_ty_layout("pthread_cond_t"))?;
|
||||
ecx.lazy_sync_get_data(
|
||||
&cond,
|
||||
cond_init_offset(ecx)?,
|
||||
|
|
@ -760,7 +760,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
let this = self.eval_context_mut();
|
||||
|
||||
let clock_id = condattr_get_clock_id(this, attr_op)?;
|
||||
this.write_scalar(Scalar::from_i32(clock_id), &this.deref_pointer(clk_id_op)?)?;
|
||||
this.write_scalar(
|
||||
Scalar::from_i32(clock_id),
|
||||
&this.deref_pointer_as(clk_id_op, this.libc_ty_layout("clockid_t"))?,
|
||||
)?;
|
||||
|
||||
interp_ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,7 +362,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
let domain = this.read_scalar(domain)?.to_i32()?;
|
||||
let mut flags = this.read_scalar(type_)?.to_i32()?;
|
||||
let protocol = this.read_scalar(protocol)?.to_i32()?;
|
||||
let sv = this.deref_pointer(sv)?;
|
||||
// This is really a pointer to `[i32; 2]` but we use a ptr-to-first-element representation.
|
||||
let sv = this.deref_pointer_as(sv, this.machine.layouts.i32)?;
|
||||
|
||||
let mut is_sock_nonblock = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
|
||||
let token = this.read_target_isize(token)?;
|
||||
let buf = this.read_pointer(buf)?;
|
||||
let size = this.deref_pointer(size)?;
|
||||
let size = this.deref_pointer_as(size, this.machine.layouts.u32)?;
|
||||
|
||||
if token != -4 {
|
||||
throw_unsup_format!(
|
||||
|
|
|
|||
|
|
@ -523,7 +523,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
let [handle, name_ptr] = this.check_shim(abi, sys_conv, link_name, args)?;
|
||||
|
||||
let handle = this.read_scalar(handle)?;
|
||||
let name_ptr = this.deref_pointer(name_ptr)?; // the pointer where we should store the ptr to the name
|
||||
let name_ptr = this.deref_pointer_as(name_ptr, this.machine.layouts.mut_raw_ptr)?; // the pointer where we should store the ptr to the name
|
||||
|
||||
let thread = match Handle::try_from_scalar(handle, this)? {
|
||||
Ok(Handle::Thread(thread)) => Ok(thread),
|
||||
|
|
@ -725,7 +725,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
"GetConsoleMode" if this.frame_in_std() => {
|
||||
let [console, mode] = this.check_shim(abi, sys_conv, link_name, args)?;
|
||||
this.read_target_isize(console)?;
|
||||
this.deref_pointer(mode)?;
|
||||
this.deref_pointer_as(mode, this.machine.layouts.u32)?;
|
||||
// Indicate an error.
|
||||
this.write_null(dest)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
{
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let init_once = this.deref_pointer(init_once_ptr)?;
|
||||
let init_once =
|
||||
this.deref_pointer_as(init_once_ptr, this.windows_ty_layout("INIT_ONCE"))?;
|
||||
let init_offset = Size::ZERO;
|
||||
|
||||
this.lazy_sync_get_data(
|
||||
|
|
@ -85,7 +86,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
|
||||
let id = this.init_once_get_data(init_once_op)?.id;
|
||||
let flags = this.read_scalar(flags_op)?.to_u32()?;
|
||||
let pending_place = this.deref_pointer(pending_op)?;
|
||||
// PBOOL is int*
|
||||
let pending_place = this.deref_pointer_as(pending_op, this.machine.layouts.i32)?;
|
||||
let context = this.read_pointer(context_op)?;
|
||||
|
||||
if flags != 0 {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
let thread = if this.ptr_is_null(this.read_pointer(thread_op)?)? {
|
||||
None
|
||||
} else {
|
||||
let thread_info_place = this.deref_pointer(thread_op)?;
|
||||
let thread_info_place = this.deref_pointer_as(thread_op, this.machine.layouts.u32)?;
|
||||
Some(thread_info_place)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue