@@ -305,6 +305,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
305
305
let this = self . eval_context_mut ( ) ;
306
306
let next_index = this. machine . threads . sync . mutexes . next_index ( ) ;
307
307
if let Some ( old) = existing ( this, next_index) ? {
308
+ if this. machine . threads . sync . mutexes . get ( old) . is_none ( ) {
309
+ throw_ub_format ! ( "mutex has invalid ID" ) ;
310
+ }
308
311
Ok ( old)
309
312
} else {
310
313
let new_index = this. machine . threads . sync . mutexes . push ( Default :: default ( ) ) ;
@@ -399,6 +402,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
399
402
let this = self . eval_context_mut ( ) ;
400
403
let next_index = this. machine . threads . sync . rwlocks . next_index ( ) ;
401
404
if let Some ( old) = existing ( this, next_index) ? {
405
+ if this. machine . threads . sync . rwlocks . get ( old) . is_none ( ) {
406
+ throw_ub_format ! ( "rwlock has invalid ID" ) ;
407
+ }
402
408
Ok ( old)
403
409
} else {
404
410
let new_index = this. machine . threads . sync . rwlocks . push ( Default :: default ( ) ) ;
@@ -563,6 +569,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
563
569
let this = self . eval_context_mut ( ) ;
564
570
let next_index = this. machine . threads . sync . condvars . next_index ( ) ;
565
571
if let Some ( old) = existing ( this, next_index) ? {
572
+ if this. machine . threads . sync . condvars . get ( old) . is_none ( ) {
573
+ throw_ub_format ! ( "condvar has invalid ID" ) ;
574
+ }
566
575
Ok ( old)
567
576
} else {
568
577
let new_index = this. machine . threads . sync . condvars . push ( Default :: default ( ) ) ;
0 commit comments