From e8d742b5ab816182d520771c6c5330c3f4ca6b66 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 4 May 2024 20:46:30 +0100 Subject: [PATCH] further fixes attempts --- src/shims/unix/solarish/foreign_items.rs | 1 + src/shims/unix/sync.rs | 17 ++++++++++++----- tests/pass-dep/shims/libc-misc.rs | 2 -- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/shims/unix/solarish/foreign_items.rs b/src/shims/unix/solarish/foreign_items.rs index f3b3f35df7..ea67e072ef 100644 --- a/src/shims/unix/solarish/foreign_items.rs +++ b/src/shims/unix/solarish/foreign_items.rs @@ -26,6 +26,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let errno_place = this.last_error_place()?; this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?; } + // Threading "pthread_condattr_setclock" => { let [attr, clock_id] = diff --git a/src/shims/unix/sync.rs b/src/shims/unix/sync.rs index 9acac60209..e7a2d4e01a 100644 --- a/src/shims/unix/sync.rs +++ b/src/shims/unix/sync.rs @@ -133,13 +133,16 @@ fn mutex_set_kind<'mir, 'tcx: 'mir>( // (need to avoid this because it is set by static initializer macros) // bytes 4-7: rwlock id as u32 or 0 if id is not assigned yet. -const RWLOCK_ID_OFFSET: u64 = 4; +#[inline] +fn rwlock_id_offset<'mir, 'tcx: 'mir>(ecx: &MiriInterpCx<'mir, 'tcx>) -> u64 { + if matches!(&*ecx.tcx.sess.target.os, "macos") { 4 } else { 0 } +} fn rwlock_get_id<'mir, 'tcx: 'mir>( ecx: &mut MiriInterpCx<'mir, 'tcx>, rwlock_op: &OpTy<'tcx, Provenance>, ) -> InterpResult<'tcx, RwLockId> { - ecx.rwlock_get_or_create_id(rwlock_op, ecx.libc_ty_layout("pthread_rwlock_t"), RWLOCK_ID_OFFSET) + ecx.rwlock_get_or_create_id(rwlock_op, ecx.libc_ty_layout("pthread_rwlock_t"), rwlock_id_offset(ecx)) } // pthread_condattr_t @@ -186,14 +189,18 @@ fn condattr_set_clock_id<'mir, 'tcx: 'mir>( // bytes 4-7: the conditional variable id as u32 or 0 if id is not assigned yet. // bytes 8-11: the clock id constant as i32 -const CONDVAR_ID_OFFSET: u64 = 4; const CONDVAR_CLOCK_OFFSET: u64 = 8; +#[inline] +fn cond_id_offset<'mir, 'tcx: 'mir>(ecx: &MiriInterpCx<'mir, 'tcx>) -> u64 { + if matches!(&*ecx.tcx.sess.target.os, "macos") { 4 } else { 0 } +} + fn cond_get_id<'mir, 'tcx: 'mir>( ecx: &mut MiriInterpCx<'mir, 'tcx>, cond_op: &OpTy<'tcx, Provenance>, ) -> InterpResult<'tcx, CondvarId> { - ecx.condvar_get_or_create_id(cond_op, ecx.libc_ty_layout("pthread_cond_t"), CONDVAR_ID_OFFSET) + ecx.condvar_get_or_create_id(cond_op, ecx.libc_ty_layout("pthread_cond_t"), cond_id_offset(ecx)) } fn cond_reset_id<'mir, 'tcx: 'mir>( @@ -202,7 +209,7 @@ fn cond_reset_id<'mir, 'tcx: 'mir>( ) -> InterpResult<'tcx, ()> { ecx.deref_pointer_and_write( cond_op, - CONDVAR_ID_OFFSET, + cond_id_offset(ecx), Scalar::from_i32(0), ecx.libc_ty_layout("pthread_cond_t"), ecx.machine.layouts.u32, diff --git a/tests/pass-dep/shims/libc-misc.rs b/tests/pass-dep/shims/libc-misc.rs index c320480928..f710daf527 100644 --- a/tests/pass-dep/shims/libc-misc.rs +++ b/tests/pass-dep/shims/libc-misc.rs @@ -153,8 +153,6 @@ fn test_sync_file_range() { /// Tests whether each thread has its own `__errno_location`. fn test_thread_local_errno() { - #[cfg(any(target_os = "solaris", target_os = "illumos"))] - use libc::__errno as __errno_location; #[cfg(target_os = "linux")] use libc::__errno_location; #[cfg(any(target_os = "macos", target_os = "freebsd"))]