Skip to content

Commit c0fb1a7

Browse files
committed
Auto merge of #3880 - RalfJung:sync, r=RalfJung
add non-portable linux pthread initializers to layout sanity check Also, turns out we can enable all pthread tests on Solarish.
2 parents 963dadf + 0164fa8 commit c0fb1a7

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

ci/ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ case $HOST_TARGET in
150150
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
151151
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
152152
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
153-
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time tls
154-
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time tls
153+
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread available-parallelism libc-time tls
154+
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread available-parallelism libc-time tls
155155
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX
156156
TEST_TARGET=wasm32-wasip2 run_tests_minimal empty_main wasm heap_alloc libc-mem
157157
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm

src/shims/unix/sync.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,28 @@ fn mutex_id_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> {
9696
// recursive or error checking mutexes. We should also add thme in this sanity check.
9797
static SANITY: AtomicBool = AtomicBool::new(false);
9898
if !SANITY.swap(true, Ordering::Relaxed) {
99-
let static_initializer = ecx.eval_path(&["libc", "PTHREAD_MUTEX_INITIALIZER"]);
100-
let id_field = static_initializer
101-
.offset(Size::from_bytes(offset), ecx.machine.layouts.u32, ecx)
102-
.unwrap();
103-
let id = ecx.read_scalar(&id_field).unwrap().to_u32().unwrap();
104-
assert_eq!(
105-
id, 0,
106-
"PTHREAD_MUTEX_INITIALIZER is incompatible with our pthread_mutex layout: id is not 0"
107-
);
99+
let check_static_initializer = |name| {
100+
let static_initializer = ecx.eval_path(&["libc", name]);
101+
let id_field = static_initializer
102+
.offset(Size::from_bytes(offset), ecx.machine.layouts.u32, ecx)
103+
.unwrap();
104+
let id = ecx.read_scalar(&id_field).unwrap().to_u32().unwrap();
105+
assert_eq!(id, 0, "{name} is incompatible with our pthread_mutex layout: id is not 0");
106+
};
107+
108+
check_static_initializer("PTHREAD_MUTEX_INITIALIZER");
109+
// Check non-standard initializers.
110+
match &*ecx.tcx.sess.target.os {
111+
"linux" => {
112+
check_static_initializer("PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP");
113+
check_static_initializer("PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP");
114+
check_static_initializer("PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP");
115+
}
116+
"illumos" | "solaris" | "macos" => {
117+
// No non-standard initializers.
118+
}
119+
os => throw_unsup_format!("`pthread_mutex` is not supported on {os}"),
120+
}
108121
}
109122

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

0 commit comments

Comments
 (0)