Skip to content

Commit ba523be

Browse files
committed
better error when calling pthread shims on unsupported unixes
1 parent 887ffc6 commit ba523be

File tree

1 file changed

+70
-0
lines changed
  • src/tools/miri/src/shims/unix

1 file changed

+70
-0
lines changed

src/tools/miri/src/shims/unix/sync.rs

Lines changed: 70 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

@@ -531,6 +552,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
531552
) -> InterpResult<'tcx, i32> {
532553
let this = self.eval_context_mut();
533554

555+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
556+
throw_unsup_format!(
557+
"`pthread_rwlock_tryrdlock` is not supported on {}",
558+
this.tcx.sess.target.os
559+
);
560+
}
561+
534562
let id = rwlock_get_id(this, rwlock_op)?;
535563
let active_thread = this.get_active_thread();
536564

@@ -548,6 +576,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
548576
) -> InterpResult<'tcx, i32> {
549577
let this = self.eval_context_mut();
550578

579+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
580+
throw_unsup_format!(
581+
"`pthread_rwlock_wrlock` is not supported on {}",
582+
this.tcx.sess.target.os
583+
);
584+
}
585+
551586
let id = rwlock_get_id(this, rwlock_op)?;
552587
let active_thread = this.get_active_thread();
553588

@@ -578,6 +613,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
578613
) -> InterpResult<'tcx, i32> {
579614
let this = self.eval_context_mut();
580615

616+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
617+
throw_unsup_format!(
618+
"`pthread_rwlock_trywrlock` is not supported on {}",
619+
this.tcx.sess.target.os
620+
);
621+
}
622+
581623
let id = rwlock_get_id(this, rwlock_op)?;
582624
let active_thread = this.get_active_thread();
583625

@@ -595,6 +637,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
595637
) -> InterpResult<'tcx, i32> {
596638
let this = self.eval_context_mut();
597639

640+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
641+
throw_unsup_format!(
642+
"`pthread_rwlock_unlock` is not supported on {}",
643+
this.tcx.sess.target.os
644+
);
645+
}
646+
598647
let id = rwlock_get_id(this, rwlock_op)?;
599648
let active_thread = this.get_active_thread();
600649

@@ -614,6 +663,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
614663
) -> InterpResult<'tcx, i32> {
615664
let this = self.eval_context_mut();
616665

666+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
667+
throw_unsup_format!(
668+
"`pthread_rwlock_destroy` is not supported on {}",
669+
this.tcx.sess.target.os
670+
);
671+
}
672+
617673
let id = rwlock_get_id(this, rwlock_op)?;
618674

619675
if this.rwlock_is_locked(id) {
@@ -638,6 +694,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
638694
) -> InterpResult<'tcx, i32> {
639695
let this = self.eval_context_mut();
640696

697+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
698+
throw_unsup_format!(
699+
"`pthread_condattr_init` is not supported on {}",
700+
this.tcx.sess.target.os
701+
);
702+
}
703+
641704
// The default value of the clock attribute shall refer to the system
642705
// clock.
643706
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_condattr_setclock.html
@@ -704,6 +767,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
704767
) -> InterpResult<'tcx, i32> {
705768
let this = self.eval_context_mut();
706769

770+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
771+
throw_unsup_format!(
772+
"`pthread_cond_init` is not supported on {}",
773+
this.tcx.sess.target.os
774+
);
775+
}
776+
707777
let attr = this.read_pointer(attr_op)?;
708778
let clock_id = if this.ptr_is_null(attr)? {
709779
this.eval_libc_i32("CLOCK_REALTIME")

0 commit comments

Comments
 (0)