Skip to content

Commit

Permalink
further fixes attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed May 4, 2024
1 parent 03742ea commit e8d742b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/shims/unix/solarish/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
17 changes: 12 additions & 5 deletions src/shims/unix/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>(
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions tests/pass-dep/shims/libc-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down

0 comments on commit e8d742b

Please sign in to comment.