Skip to content

Commit 1389bb9

Browse files
committed
pthread_rwlock: also store ID outside addressable memory
1 parent 89323bf commit 1389bb9

5 files changed

Lines changed: 112 additions & 135 deletions

File tree

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

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ struct Mutex {
7979
queue:VecDeque<ThreadId>,
8080
/// Mutex clock. This tracks the moment of the last unlock.
8181
clock:VClock,
82-
83-
/// Additional data that can be set by shim implementations.
84-
data:Option<Box<dynAny>>,
8582
}
8683

8784
declare_id!(RwLockId);
@@ -118,9 +115,6 @@ struct RwLock {
118115
/// locks.
119116
/// This is only relevant when there is an active reader.
120117
clock_current_readers:VClock,
121-
122-
/// Additional data that can be set by shim implementations.
123-
data:Option<Box<dynAny>>,
124118
}
125119

126120
declare_id!(CondvarId);
@@ -290,56 +284,22 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
290284
&mutself,
291285
lock:&MPlaceTy<'tcx>,
292286
offset:u64,
293-
initialize_data:implfor<'a>FnOnce(
294-
&'amutMiriInterpCx<'tcx>,
295-
) -> InterpResult<'tcx,Option<Box<dynAny>>>,
296287
) -> InterpResult<'tcx,MutexId>{
297288
let this = self.eval_context_mut();
298289
this.get_or_create_id(
299290
lock,
300291
offset,
301292
|ecx| &mut ecx.machine.sync.mutexes,
302-
|ecx| initialize_data(ecx).map(|data| Mutex{ data, ..Default::default()}),
293+
|_ecx| interp_ok(Mutex::default()),
303294
)?
304295
.ok_or_else(|| err_ub_format!("mutex has invalid ID"))
305296
.into()
306297
}
307298

308-
/// Retrieve the additional data stored for a mutex.
309-
fnmutex_get_data<'a,T:'static>(&'amutself,id:MutexId) -> Option<&'aT>
310-
where
311-
'tcx:'a,
312-
{
313-
let this = self.eval_context_ref();
314-
this.machine.sync.mutexes[id].data.as_deref().and_then(|p| p.downcast_ref::<T>())
315-
}
316-
317-
fnrwlock_get_or_create_id(
318-
&mutself,
319-
lock:&MPlaceTy<'tcx>,
320-
offset:u64,
321-
initialize_data:implfor<'a>FnOnce(
322-
&'amutMiriInterpCx<'tcx>,
323-
) -> InterpResult<'tcx,Option<Box<dynAny>>>,
324-
) -> InterpResult<'tcx,RwLockId>{
299+
/// Eagerly create and initialize a new rwlock.
300+
fnrwlock_create(&mutself) -> RwLockId{
325301
let this = self.eval_context_mut();
326-
this.get_or_create_id(
327-
lock,
328-
offset,
329-
|ecx| &mut ecx.machine.sync.rwlocks,
330-
|ecx| initialize_data(ecx).map(|data| RwLock{ data, ..Default::default()}),
331-
)?
332-
.ok_or_else(|| err_ub_format!("rwlock has invalid ID"))
333-
.into()
334-
}
335-
336-
/// Retrieve the additional data stored for a rwlock.
337-
fnrwlock_get_data<'a,T:'static>(&'amutself,id:RwLockId) -> Option<&'aT>
338-
where
339-
'tcx:'a,
340-
{
341-
let this = self.eval_context_ref();
342-
this.machine.sync.rwlocks[id].data.as_deref().and_then(|p| p.downcast_ref::<T>())
302+
this.machine.sync.rwlocks.push(Default::default())
343303
}
344304

345305
/// Eagerly create and initialize a new condvar.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
2020
// os_unfair_lock holds a 32-bit value, is initialized with zero and
2121
// must be assumed to be opaque. Therefore, we can just store our
2222
// internal mutex ID in the structure without anyone noticing.
23-
this.mutex_get_or_create_id(&lock,0, |_| interp_ok(None))
23+
this.mutex_get_or_create_id(&lock,/* offset */0)
2424
}
2525
}
2626

0 commit comments

Comments
 (0)