From 8905742a7e027f07b062034dad23ace052810773 Mon Sep 17 00:00:00 2001 From: geetanshjuneja Date: Fri, 17 Jan 2025 13:15:42 +0530 Subject: [PATCH 1/5] Use deref_pointer_as instead of deref_pointer --- src/shims/alloc.rs | 2 +- src/shims/foreign_items.rs | 4 ++-- src/shims/time.rs | 4 ++-- src/shims/unix/foreign_items.rs | 6 +++--- src/shims/unix/fs.rs | 6 +++--- src/shims/unix/macos/sync.rs | 2 +- src/shims/unix/solarish/foreign_items.rs | 2 +- src/shims/unix/unnamed_socket.rs | 2 +- src/shims/windows/thread.rs | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/shims/alloc.rs b/src/shims/alloc.rs index 25c0b52d06..82ad8fd80c 100644 --- a/src/shims/alloc.rs +++ b/src/shims/alloc.rs @@ -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)?; diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 6c8ccc8398..3f5d95d36f 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -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(); diff --git a/src/shims/time.rs b/src/shims/time.rs index d6c77d9c4d..dc8b4c5596 100644 --- a/src/shims/time.rs +++ b/src/shims/time.rs @@ -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"))?; let result = this.deref_pointer_as(result_op, this.libc_ty_layout("tm"))?; // The input "represents the number of seconds elapsed since the Epoch, @@ -254,7 +254,7 @@ 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 } diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index 3353cf2cc5..cec8b989b5 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -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, @@ -894,7 +894,7 @@ 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"))?; 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 { diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index 25594b7803..6749e5a764 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -1253,15 +1253,15 @@ 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)?; + this.write_null(&result_place)?; Scalar::from_i32(0) } Some(Err(e)) => { diff --git a/src/shims/unix/macos/sync.rs b/src/shims/unix/macos/sync.rs index 330c64f06a..5442d38d52 100644 --- a/src/shims/unix/macos/sync.rs +++ b/src/shims/unix/macos/sync.rs @@ -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 diff --git a/src/shims/unix/solarish/foreign_items.rs b/src/shims/unix/solarish/foreign_items.rs index f94783a390..ccdf3b868a 100644 --- a/src/shims/unix/solarish/foreign_items.rs +++ b/src/shims/unix/solarish/foreign_items.rs @@ -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)?; } diff --git a/src/shims/unix/unnamed_socket.rs b/src/shims/unix/unnamed_socket.rs index 08515b815a..87b551fe44 100644 --- a/src/shims/unix/unnamed_socket.rs +++ b/src/shims/unix/unnamed_socket.rs @@ -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)?; let mut is_sock_nonblock = false; diff --git a/src/shims/windows/thread.rs b/src/shims/windows/thread.rs index efc1c2286b..5db5540442 100644 --- a/src/shims/windows/thread.rs +++ b/src/shims/windows/thread.rs @@ -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) }; From 09ad165d0ffdcdb8dc93f9bd6693c786ffb95da7 Mon Sep 17 00:00:00 2001 From: geetanshjuneja Date: Fri, 17 Jan 2025 13:18:30 +0530 Subject: [PATCH 2/5] fmt --- src/shims/time.rs | 5 ++++- src/shims/unix/foreign_items.rs | 3 ++- src/shims/unix/fs.rs | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/shims/time.rs b/src/shims/time.rs index dc8b4c5596..c1e45a41aa 100644 --- a/src/shims/time.rs +++ b/src/shims/time.rs @@ -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_as(lpPerformanceCount_op, this.machine.layouts.i64)?)?; + 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 } diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index cec8b989b5..75a01ae2c2 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -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_as(size_place, this.libc_ty_layout("size_t"))?; + let size_place = + this.deref_pointer_as(size_place, this.libc_ty_layout("size_t"))?; this.write_scalar( Scalar::from_uint(this.machine.stack_addr, this.pointer_size()), diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index 6749e5a764..a8f778d8e6 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -1253,14 +1253,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } _ => unreachable!(), } - let result_place = this.deref_pointer_as(result_op, this.machine.layouts.mut_raw_ptr)?; + 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 - let result_place = this.deref_pointer_as(result_op, this.machine.layouts.mut_raw_ptr)?; + let result_place = + this.deref_pointer_as(result_op, this.machine.layouts.mut_raw_ptr)?; this.write_null(&result_place)?; Scalar::from_i32(0) } From 668c107270fa2365108ada826e222461e3a4cdde Mon Sep 17 00:00:00 2001 From: geetanshjuneja Date: Sat, 18 Jan 2025 10:29:47 +0530 Subject: [PATCH 3/5] changed all deref_pointer to deref_pointer_as --- src/shims/backtrace.rs | 3 +-- src/shims/time.rs | 10 ++++------ src/shims/unix/foreign_items.rs | 5 ++--- src/shims/unix/fs.rs | 5 +---- src/shims/unix/sync.rs | 15 +++++++++------ src/shims/unix/unnamed_socket.rs | 1 + src/shims/windows/env.rs | 2 +- src/shims/windows/foreign_items.rs | 9 ++++++--- src/shims/windows/sync.rs | 5 +++-- 9 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/shims/backtrace.rs b/src/shims/backtrace.rs index 1622ef280d..137666160d 100644 --- a/src/shims/backtrace.rs +++ b/src/shims/backtrace.rs @@ -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(); diff --git a/src/shims/time.rs b/src/shims/time.rs index c1e45a41aa..46fcc6985c 100644 --- a/src/shims/time.rs +++ b/src/shims/time.rs @@ -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_as(timep, this.libc_ty_layout("time_t"))?; + let timep_layout = this.libc_ty_layout("time_t"); + let timep = this.deref_pointer_as(timep, timep_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(timep_layout.size)?.try_into().unwrap(); let dt_utc: DateTime = DateTime::from_timestamp(sec_since_epoch, 0).expect("Invalid timestamp"); diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index 75a01ae2c2..075cc2710a 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -893,9 +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_as(size_place, this.libc_ty_layout("size_t"))?; + 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()), diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index a8f778d8e6..79fed97b67 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -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,16 +1254,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } _ => unreachable!(), } - 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 - let result_place = - this.deref_pointer_as(result_op, this.machine.layouts.mut_raw_ptr)?; this.write_null(&result_place)?; Scalar::from_i32(0) } diff --git a/src/shims/unix/sync.rs b/src/shims/unix/sync.rs index 5b0a9398b4..9f1fabfbf6 100644 --- a/src/shims/unix/sync.rs +++ b/src/shims/unix/sync.rs @@ -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(()) } diff --git a/src/shims/unix/unnamed_socket.rs b/src/shims/unix/unnamed_socket.rs index 87b551fe44..4396ff4b1a 100644 --- a/src/shims/unix/unnamed_socket.rs +++ b/src/shims/unix/unnamed_socket.rs @@ -362,6 +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()?; + // 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; diff --git a/src/shims/windows/env.rs b/src/shims/windows/env.rs index 72c1fb5802..1b2ccd99ef 100644 --- a/src/shims/windows/env.rs +++ b/src/shims/windows/env.rs @@ -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!( diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index 0bf56c3d00..fc8c4b7460 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -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.libc_ty_layout("wchar_t"))?; // 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), @@ -613,7 +613,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let [console, buffer_info] = this.check_shim(abi, sys_conv, link_name, args)?; this.read_target_isize(console)?; // FIXME: this should use deref_pointer_as, but CONSOLE_SCREEN_BUFFER_INFO is not in std - this.deref_pointer(buffer_info)?; + this.deref_pointer_as( + buffer_info, + this.libc_ty_layout("CONSOLE_SCREEN_BUFFER_INFO"), + )?; // Indicate an error. // FIXME: we should set last_error, but to what? this.write_null(dest)?; @@ -725,7 +728,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)?; } diff --git a/src/shims/windows/sync.rs b/src/shims/windows/sync.rs index 4001201bf6..f60a219456 100644 --- a/src/shims/windows/sync.rs +++ b/src/shims/windows/sync.rs @@ -29,7 +29,7 @@ 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.libc_ty_layout("INIT_ONCE"))?; let init_offset = Size::ZERO; this.lazy_sync_get_data( @@ -85,7 +85,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 a typedef of int + let pending_place = this.deref_pointer_as(pending_op, this.machine.layouts.i32)?; let context = this.read_pointer(context_op)?; if flags != 0 { From 9c84da863b16abc52d175780890088b022ce087a Mon Sep 17 00:00:00 2001 From: geetanshjuneja Date: Sat, 18 Jan 2025 20:43:14 +0530 Subject: [PATCH 4/5] removed windows specific layouts --- src/shims/windows/foreign_items.rs | 5 +---- src/shims/windows/sync.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index fc8c4b7460..2278988da3 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -613,10 +613,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let [console, buffer_info] = this.check_shim(abi, sys_conv, link_name, args)?; this.read_target_isize(console)?; // FIXME: this should use deref_pointer_as, but CONSOLE_SCREEN_BUFFER_INFO is not in std - this.deref_pointer_as( - buffer_info, - this.libc_ty_layout("CONSOLE_SCREEN_BUFFER_INFO"), - )?; + this.deref_pointer(buffer_info)?; // Indicate an error. // FIXME: we should set last_error, but to what? this.write_null(dest)?; diff --git a/src/shims/windows/sync.rs b/src/shims/windows/sync.rs index f60a219456..008262fab0 100644 --- a/src/shims/windows/sync.rs +++ b/src/shims/windows/sync.rs @@ -29,7 +29,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { { let this = self.eval_context_mut(); - let init_once = this.deref_pointer_as(init_once_ptr, this.libc_ty_layout("INIT_ONCE"))?; + let init_once = this.deref_pointer(init_once_ptr)?; let init_offset = Size::ZERO; this.lazy_sync_get_data( From b68b9761213ff71dfa2a4122ea58cef167e487ee Mon Sep 17 00:00:00 2001 From: geetanshjuneja Date: Sat, 18 Jan 2025 20:54:16 +0530 Subject: [PATCH 5/5] fix --- src/shims/windows/foreign_items.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index 2278988da3..35fced66f0 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -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_as(name_ptr, this.libc_ty_layout("wchar_t"))?; // the pointer where we should store the ptr to the name + let name_ptr = this.deref_pointer(name_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),