Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use deref_pointer_as instead of deref_pointer #4140

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/shims/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
4 changes: 2 additions & 2 deletions src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions src/shims/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ 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 timep = this.deref_pointer_as(timep, this.libc_ty_layout("time_t"))?;
geetanshjuneja marked this conversation as resolved.
Show resolved Hide resolved
let result = this.deref_pointer_as(result_op, this.libc_ty_layout("tm"))?;

// The input "represents the number of seconds elapsed since the Epoch,
Expand Down Expand Up @@ -254,7 +254,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
}

Expand Down
7 changes: 4 additions & 3 deletions src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -894,7 +894,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
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 size_place =
this.deref_pointer_as(size_place, this.libc_ty_layout("size_t"))?;
geetanshjuneja marked this conversation as resolved.
Show resolved Hide resolved

this.write_scalar(
Scalar::from_uint(this.machine.stack_addr, this.pointer_size()),
Expand Down Expand Up @@ -928,7 +929,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 {
Expand Down
8 changes: 5 additions & 3 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,15 +1253,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
}
_ => unreachable!(),
}

let result_place = this.deref_pointer(result_op)?;
let result_place =
this.deref_pointer_as(result_op, this.machine.layouts.mut_raw_ptr)?;
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)?)?;
let result_place =
this.deref_pointer_as(result_op, this.machine.layouts.mut_raw_ptr)?;
geetanshjuneja marked this conversation as resolved.
Show resolved Hide resolved
this.write_null(&result_place)?;
Scalar::from_i32(0)
}
Some(Err(e)) => {
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/macos/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/solarish/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/unnamed_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ 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)?;
let sv = this.deref_pointer_as(sv, this.machine.layouts.i32)?;
geetanshjuneja marked this conversation as resolved.
Show resolved Hide resolved

let mut is_sock_nonblock = false;

Expand Down
2 changes: 1 addition & 1 deletion src/shims/windows/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand Down
Loading