better error when calling pthread shims on unsupported unixes

This commit is contained in:
Ralf Jung 2023-11-12 14:18:36 +01:00
parent 887ffc68ee
commit ba523be7a8

View File

@ -277,6 +277,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_mutexattr_init` is not supported on {}",
this.tcx.sess.target.os
);
}
let default_kind = this.eval_libc_i32("PTHREAD_MUTEX_DEFAULT");
mutexattr_set_kind(this, attr_op, default_kind)?;
@ -359,6 +366,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_mutex_init` is not supported on {}",
this.tcx.sess.target.os
);
}
let attr = this.read_pointer(attr_op)?;
let kind = if this.ptr_is_null(attr)? {
this.eval_libc_i32("PTHREAD_MUTEX_DEFAULT")
@ -513,6 +527,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_rwlock_rdlock` is not supported on {}",
this.tcx.sess.target.os
);
}
let id = rwlock_get_id(this, rwlock_op)?;
let active_thread = this.get_active_thread();
@ -531,6 +552,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_rwlock_tryrdlock` is not supported on {}",
this.tcx.sess.target.os
);
}
let id = rwlock_get_id(this, rwlock_op)?;
let active_thread = this.get_active_thread();
@ -548,6 +576,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_rwlock_wrlock` is not supported on {}",
this.tcx.sess.target.os
);
}
let id = rwlock_get_id(this, rwlock_op)?;
let active_thread = this.get_active_thread();
@ -578,6 +613,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_rwlock_trywrlock` is not supported on {}",
this.tcx.sess.target.os
);
}
let id = rwlock_get_id(this, rwlock_op)?;
let active_thread = this.get_active_thread();
@ -595,6 +637,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_rwlock_unlock` is not supported on {}",
this.tcx.sess.target.os
);
}
let id = rwlock_get_id(this, rwlock_op)?;
let active_thread = this.get_active_thread();
@ -614,6 +663,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_rwlock_destroy` is not supported on {}",
this.tcx.sess.target.os
);
}
let id = rwlock_get_id(this, rwlock_op)?;
if this.rwlock_is_locked(id) {
@ -638,6 +694,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_condattr_init` is not supported on {}",
this.tcx.sess.target.os
);
}
// The default value of the clock attribute shall refer to the system
// clock.
// 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> {
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos") {
throw_unsup_format!(
"`pthread_cond_init` is not supported on {}",
this.tcx.sess.target.os
);
}
let attr = this.read_pointer(attr_op)?;
let clock_id = if this.ptr_is_null(attr)? {
this.eval_libc_i32("CLOCK_REALTIME")