Skip to content

Commit 17f0aed

Browse files
committed
pthread_cond: also store ID outside addressable memory
1 parent 1389bb9 commit 17f0aed

5 files changed

Lines changed: 109 additions & 172 deletions

File tree

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

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::any::Any;
21
use std::collections::VecDeque;
32
use std::collections::hash_map::Entry;
43
use std::ops::Not;
@@ -129,9 +128,6 @@ struct Condvar {
129128
/// Contains the clock of the last thread to
130129
/// perform a condvar-signal.
131130
clock:VClock,
132-
133-
/// Additional data that can be set by shim implementations.
134-
data:Option<Box<dynAny>>,
135131
}
136132

137133
/// The futex state.
@@ -220,32 +216,6 @@ pub(super) trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
220216
})
221217
}
222218

223-
/// Eagerly creates a Miri sync structure.
224-
///
225-
/// `create_id` will store the index of the sync_structure in the memory pointed to by
226-
/// `lock_op`, so that future calls to `get_or_create_id` will see it as initialized.
227-
/// - `lock_op` must hold a pointer to the sync structure.
228-
/// - `lock_layout` must be the memory layout of the sync structure.
229-
/// - `offset` must be the offset inside the sync structure where its miri id will be stored.
230-
/// - `get_objs` is described in `get_or_create_id`.
231-
/// - `obj` must be the new sync object.
232-
fncreate_id<Id:SyncId + Idx,T>(
233-
&mutself,
234-
lock:&MPlaceTy<'tcx>,
235-
offset:u64,
236-
get_objs:implfor<'a>Fn(&'amutMiriInterpCx<'tcx>) -> &'amutIndexVec<Id,T>,
237-
obj:T,
238-
) -> InterpResult<'tcx,Id>{
239-
let this = self.eval_context_mut();
240-
let offset = Size::from_bytes(offset);
241-
assert!(lock.layout.size >= offset + this.machine.layouts.u32.size);
242-
let id_place = lock.offset(offset, this.machine.layouts.u32, this)?;
243-
244-
let new_index = get_objs(this).push(obj);
245-
this.write_scalar(Scalar::from_u32(new_index.to_u32()),&id_place)?;
246-
interp_ok(new_index)
247-
}
248-
249219
fncondvar_reacquire_mutex(
250220
&mutself,
251221
mutex:MutexId,
@@ -303,45 +273,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
303273
}
304274

305275
/// Eagerly create and initialize a new condvar.
306-
fncondvar_create(
307-
&mutself,
308-
condvar:&MPlaceTy<'tcx>,
309-
offset:u64,
310-
data:Option<Box<dynAny>>,
311-
) -> InterpResult<'tcx,CondvarId>{
276+
fncondvar_create(&mutself) -> CondvarId{
312277
let this = self.eval_context_mut();
313-
this.create_id(condvar, offset, |ecx| &mut ecx.machine.sync.condvars,Condvar{
314-
data,
315-
..Default::default()
316-
})
317-
}
318-
319-
fncondvar_get_or_create_id(
320-
&mutself,
321-
lock:&MPlaceTy<'tcx>,
322-
offset:u64,
323-
initialize_data:implfor<'a>FnOnce(
324-
&'amutMiriInterpCx<'tcx>,
325-
) -> InterpResult<'tcx,Option<Box<dynAny>>>,
326-
) -> InterpResult<'tcx,CondvarId>{
327-
let this = self.eval_context_mut();
328-
this.get_or_create_id(
329-
lock,
330-
offset,
331-
|ecx| &mut ecx.machine.sync.condvars,
332-
|ecx| initialize_data(ecx).map(|data| Condvar{ data, ..Default::default()}),
333-
)?
334-
.ok_or_else(|| err_ub_format!("condvar has invalid ID"))
335-
.into()
336-
}
337-
338-
/// Retrieve the additional data stored for a condvar.
339-
fncondvar_get_data<'a,T:'static>(&'amutself,id:CondvarId) -> Option<&'aT>
340-
where
341-
'tcx:'a,
342-
{
343-
let this = self.eval_context_ref();
344-
this.machine.sync.condvars[id].data.as_deref().and_then(|p| p.downcast_ref::<T>())
278+
this.machine.sync.condvars.push(Default::default())
345279
}
346280

347281
#[inline]

0 commit comments

Comments
 (0)