Skip to content

Commit 4ab2ee5

Browse files
extra comments and cleanup
1 parent bcf1681 commit 4ab2ee5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/shims/unix/freebsd/sync.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
6666
if op == wait { this.machine.layouts.isize } else { this.machine.layouts.u32 };
6767
let obj = this.ptr_to_mplace(obj, obj_layout);
6868

69-
// Read the Linux futex implementation in Miri to understand why this fence is needed.
69+
// Read the Linux futex wait implementation in Miri to understand why this fence is needed.
7070
this.atomic_fence(AtomicFenceOrd::SeqCst)?;
7171
let obj_val = this
7272
.read_scalar_atomic(&obj, AtomicReadOrd::Acquire)?
7373
.to_bits(obj_layout.size)?; // isize and u32 can have different sizes
7474

7575
if obj_val == u128::from(val) {
76+
// This cannot fail since we already did an atomic acquire read on that pointer.
77+
// Acquire reads are only allowed on mutable memory.
7678
let futex_ref = this
7779
.get_sync_or_init(obj.ptr(), |_| FreeBsdFutex { futex: Default::default() })
7880
.unwrap()
@@ -122,7 +124,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
122124
};
123125

124126
// From the FreeBSD source code:
125-
// In the function `umtx_copyin_umtx_time` in kern_umtx.c, _clock_id is set to CLOCK_REALTIME when using `timespec`
127+
// In the function `umtx_copyin_umtx_time` in kern_umtx.c,
128+
// _clock_id is set to CLOCK_REALTIME when using a `timespec` timeout.
126129
Some((TimeoutClock::RealTime, TimeoutAnchor::Relative, duration))
127130
} else {
128131
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
@@ -177,7 +180,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
177180
// Saturating cast for when usize is smaller than u64.
178181
let count = usize::try_from(val).unwrap_or(usize::MAX);
179182

180-
// Read the Linux futex implementation in Miri to understand why this fence is needed.
183+
// Read the Linux futex wake implementation in Miri to understand why this fence is needed.
181184
this.atomic_fence(AtomicFenceOrd::SeqCst)?;
182185

183186
// `_umtx_op` doesn't return the amount of woken threads.

0 commit comments

Comments
 (0)