Skip to content

Commit 19933b9

Browse files
committed
better error when calling pthread shims on unsupported unixes
1 parent e0fef82 commit 19933b9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/shims/unix/sync.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
277277
) -> InterpResult<'tcx, i32> {
278278
let this = self.eval_context_mut();
279279

280+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
281+
throw_unsup_format!(
282+
"`pthread_mutexattr_init` is not supported on {}",
283+
this.tcx.sess.target.os
284+
);
285+
}
286+
280287
let default_kind = this.eval_libc_i32("PTHREAD_MUTEX_DEFAULT");
281288
mutexattr_set_kind(this, attr_op, default_kind)?;
282289

@@ -359,6 +366,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
359366
) -> InterpResult<'tcx, i32> {
360367
let this = self.eval_context_mut();
361368

369+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
370+
throw_unsup_format!(
371+
"`pthread_mutex_init` is not supported on {}",
372+
this.tcx.sess.target.os
373+
);
374+
}
375+
362376
let attr = this.read_pointer(attr_op)?;
363377
let kind = if this.ptr_is_null(attr)? {
364378
this.eval_libc_i32("PTHREAD_MUTEX_DEFAULT")
@@ -513,6 +527,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
513527
) -> InterpResult<'tcx, i32> {
514528
let this = self.eval_context_mut();
515529

530+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
531+
throw_unsup_format!(
532+
"`pthread_rwlock_rdlock` is not supported on {}",
533+
this.tcx.sess.target.os
534+
);
535+
}
536+
516537
let id = rwlock_get_id(this, rwlock_op)?;
517538
let active_thread = this.get_active_thread();
518539

@@ -548,6 +569,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
548569
) -> InterpResult<'tcx, i32> {
549570
let this = self.eval_context_mut();
550571

572+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
573+
throw_unsup_format!(
574+
"`pthread_rwlock_wrlock` is not supported on {}",
575+
this.tcx.sess.target.os
576+
);
577+
}
578+
551579
let id = rwlock_get_id(this, rwlock_op)?;
552580
let active_thread = this.get_active_thread();
553581

@@ -638,6 +666,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
638666
) -> InterpResult<'tcx, i32> {
639667
let this = self.eval_context_mut();
640668

669+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
670+
throw_unsup_format!(
671+
"`pthread_condattr_init` is not supported on {}",
672+
this.tcx.sess.target.os
673+
);
674+
}
675+
641676
// The default value of the clock attribute shall refer to the system
642677
// clock.
643678
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_condattr_setclock.html
@@ -704,6 +739,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
704739
) -> InterpResult<'tcx, i32> {
705740
let this = self.eval_context_mut();
706741

742+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
743+
throw_unsup_format!(
744+
"`pthread_cond_init` is not supported on {}",
745+
this.tcx.sess.target.os
746+
);
747+
}
748+
707749
let attr = this.read_pointer(attr_op)?;
708750
let clock_id = if this.ptr_is_null(attr)? {
709751
this.eval_libc_i32("CLOCK_REALTIME")

0 commit comments

Comments
 (0)