Skip to content

Commit

Permalink
Auto merge of #3880 - RalfJung:sync, r=RalfJung
Browse files Browse the repository at this point in the history
add non-portable linux pthread initializers to layout sanity check

Also, turns out we can enable all pthread tests on Solarish.
  • Loading branch information
bors committed Sep 12, 2024
2 parents 963dadf + 0164fa8 commit c0fb1a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ case $HOST_TARGET in
UNIX="panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time tls
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time tls
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread available-parallelism libc-time tls
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread available-parallelism libc-time tls
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX
TEST_TARGET=wasm32-wasip2 run_tests_minimal empty_main wasm heap_alloc libc-mem
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm
Expand Down
33 changes: 23 additions & 10 deletions src/shims/unix/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,28 @@ fn mutex_id_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> {
// recursive or error checking mutexes. We should also add thme in this sanity check.
static SANITY: AtomicBool = AtomicBool::new(false);
if !SANITY.swap(true, Ordering::Relaxed) {
let static_initializer = ecx.eval_path(&["libc", "PTHREAD_MUTEX_INITIALIZER"]);
let id_field = static_initializer
.offset(Size::from_bytes(offset), ecx.machine.layouts.u32, ecx)
.unwrap();
let id = ecx.read_scalar(&id_field).unwrap().to_u32().unwrap();
assert_eq!(
id, 0,
"PTHREAD_MUTEX_INITIALIZER is incompatible with our pthread_mutex layout: id is not 0"
);
let check_static_initializer = |name| {
let static_initializer = ecx.eval_path(&["libc", name]);
let id_field = static_initializer
.offset(Size::from_bytes(offset), ecx.machine.layouts.u32, ecx)
.unwrap();
let id = ecx.read_scalar(&id_field).unwrap().to_u32().unwrap();
assert_eq!(id, 0, "{name} is incompatible with our pthread_mutex layout: id is not 0");
};

check_static_initializer("PTHREAD_MUTEX_INITIALIZER");
// Check non-standard initializers.
match &*ecx.tcx.sess.target.os {
"linux" => {
check_static_initializer("PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP");
check_static_initializer("PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP");
check_static_initializer("PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP");
}
"illumos" | "solaris" | "macos" => {
// No non-standard initializers.
}
os => throw_unsup_format!("`pthread_mutex` is not supported on {os}"),
}
}

Ok(offset)
Expand Down Expand Up @@ -167,7 +180,7 @@ fn kind_from_static_initializer<'tcx>(
mutex.offset(Size::from_bytes(offset), ecx.machine.layouts.i32, ecx)?;
ecx.read_scalar(&kind_place)?.to_i32()?
}
| "illumos" | "solaris" | "macos" => ecx.eval_libc_i32("PTHREAD_MUTEX_DEFAULT"),
"illumos" | "solaris" | "macos" => ecx.eval_libc_i32("PTHREAD_MUTEX_DEFAULT"),
os => throw_unsup_format!("`pthread_mutex` is not supported on {os}"),
};

Expand Down

0 comments on commit c0fb1a7

Please sign in to comment.