@@ -263,7 +263,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
263263 None => this. eval_libc_i32 ( "EAGAIN" ) ,
264264 }
265265 } else {
266- this . eval_libc_i32 ( "EINVAL" )
266+ throw_ub_format ! ( "called pthread_mutex_lock on an unsupported type of mutex" ) ;
267267 }
268268 }
269269
@@ -291,7 +291,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
291291 None => this. eval_libc_i32 ( "EAGAIN" ) ,
292292 }
293293 } else {
294- this . eval_libc_i32 ( "EINVAL" )
294+ throw_ub_format ! ( "called pthread_mutex_trylock on an unsupported type of mutex" ) ;
295295 }
296296 }
297297
@@ -306,9 +306,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
306306 mutex_set_locked_count ( this, mutex_op, Scalar :: from_u32 ( 0 ) ) ?;
307307 Ok ( 0 )
308308 } else {
309- throw_ub_format ! (
310- "Attempted to unlock a PTHREAD_MUTEX_NORMAL mutex that was not locked"
311- ) ;
309+ throw_ub_format ! ( "unlocked a PTHREAD_MUTEX_NORMAL mutex that was not locked" ) ;
312310 }
313311 } else if kind == this. eval_libc ( "PTHREAD_MUTEX_ERRORCHECK" ) ? {
314312 if locked_count != 0 {
@@ -329,15 +327,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
329327 }
330328 }
331329 } else {
332- this . eval_libc_i32 ( "EINVAL" )
330+ throw_ub_format ! ( "called pthread_mutex_unlock on an unsupported type of mutex" ) ;
333331 }
334332 }
335333
336334 fn pthread_mutex_destroy ( & mut self , mutex_op : OpTy < ' tcx , Tag > ) -> InterpResult < ' tcx , i32 > {
337335 let this = self . eval_context_mut ( ) ;
338336
339337 if mutex_get_locked_count ( this, mutex_op) ?. to_u32 ( ) ? != 0 {
340- return this . eval_libc_i32 ( "EBUSY ") ;
338+ throw_ub_format ! ( "destroyed a locked mutex ") ;
341339 }
342340
343341 mutex_set_kind ( this, mutex_op, ScalarMaybeUndef :: Undef ) ?;
@@ -422,18 +420,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
422420 rwlock_set_writers ( this, rwlock_op, Scalar :: from_u32 ( 0 ) ) ?;
423421 Ok ( 0 )
424422 } else {
425- this . eval_libc_i32 ( "EPERM" )
423+ throw_ub_format ! ( "unlocked an rwlock that was not locked" ) ;
426424 }
427425 }
428426
429427 fn pthread_rwlock_destroy ( & mut self , rwlock_op : OpTy < ' tcx , Tag > ) -> InterpResult < ' tcx , i32 > {
430428 let this = self . eval_context_mut ( ) ;
431429
432- if rwlock_get_readers ( this, rwlock_op) ?. to_u32 ( ) ? != 0 {
433- return this. eval_libc_i32 ( "EBUSY" ) ;
434- }
435- if rwlock_get_writers ( this, rwlock_op) ?. to_u32 ( ) ? != 0 {
436- return this. eval_libc_i32 ( "EBUSY" ) ;
430+ if rwlock_get_readers ( this, rwlock_op) ?. to_u32 ( ) ? != 0
431+ || rwlock_get_writers ( this, rwlock_op) ?. to_u32 ( ) ? != 0
432+ {
433+ throw_ub_format ! ( "destroyed a locked rwlock" ) ;
437434 }
438435
439436 rwlock_set_readers ( this, rwlock_op, ScalarMaybeUndef :: Undef ) ?;
0 commit comments