Skip to content

Commit 98bb8ac

Browse files
committed
sync: better error in invalid synchronization primitive ID
1 parent 37537d1 commit 98bb8ac

File tree

1 file changed

+9
-0
lines changed
  • src/tools/miri/src/concurrency

1 file changed

+9
-0
lines changed

src/tools/miri/src/concurrency/sync.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
305305
let this = self.eval_context_mut();
306306
let next_index = this.machine.threads.sync.mutexes.next_index();
307307
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+
}
308311
Ok(old)
309312
} else {
310313
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> {
399402
let this = self.eval_context_mut();
400403
let next_index = this.machine.threads.sync.rwlocks.next_index();
401404
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+
}
402408
Ok(old)
403409
} else {
404410
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> {
563569
let this = self.eval_context_mut();
564570
let next_index = this.machine.threads.sync.condvars.next_index();
565571
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+
}
566575
Ok(old)
567576
} else {
568577
let new_index = this.machine.threads.sync.condvars.push(Default::default());

0 commit comments

Comments
 (0)