Skip to content

Commit b09ce99

Browse files
fix/add comments for better explanation + some formatting
1 parent 4ab2ee5 commit b09ce99

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/shims/unix/freebsd/sync.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
2424
/// `obj`: a pointer to the futex object (can be a lot of things, mostly *AtomicU32)
2525
/// `op`: the futex operation to run
2626
/// `val`: the current value of the object as a `c_long` (for wait/wake)
27-
/// `uaddr`: pointer to optional parameter (mostly timeouts)
28-
/// `uaddr2`: pointer to optional parameter (mostly timeouts)
27+
/// `uaddr`: `op`-specific optional parameter, pointer-sized integer or pointer to an `op`-specific struct
28+
/// `uaddr2`: `op`-specific optional parameter, pointer-sized integer or pointer to an `op`-specific struct
2929
/// `dest`: the place this syscall returns to, 0 for success, -1 for failure
30+
///
31+
/// # Note
32+
/// Curently only the WAIT and WAKE operations are implemented.
3033
fn _umtx_op(
3134
&mut self,
3235
obj: &OpTy<'tcx>,
@@ -83,7 +86,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8386

8487
// From the manual:
8588
// The timeout is specified by passing either the address of `struct timespec`, or its
86-
// extended variant, `struct _umtx_time`, as the `uaddr2` argument of _umtx_op().
89+
// extended variant, `struct _umtx_time`, as the `uaddr2` argument of _umtx_op().
8790
// They are distinguished by the `uaddr` value, which must be equal
8891
// to the size of the structure pointed to by `uaddr2`, casted to uintptr_t.
8992
let timeout = if this.ptr_is_null(uaddr2)? {
@@ -113,7 +116,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
113116
// RealTime clock can't be used in isolation mode.
114117
this.check_no_isolation("`_umtx_op` with `timespec` timeout")?;
115118

116-
// `uaddr2` points to a `struct timespec`
119+
// `uaddr2` points to a `struct timespec`.
117120
let timespec = this.ptr_to_mplace(uaddr2, timespec_layout);
118121
let duration = match this.read_timespec(&timespec)? {
119122
Some(duration) => duration,
@@ -123,9 +126,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
123126
}
124127
};
125128

126-
// From the FreeBSD source code:
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.
129+
// FreeBSD does not seem to document which clock is used when the timeout
130+
// is passed as a `struct timespec*`. Based on discussions online and the source
131+
// code (umtx_copyin_umtx_time() in kern_umtx.c), it seems to default to CLOCK_REALTIME,
132+
// so that's what we also do.
133+
// Discussion in golang: https://github.com/golang/go/issues/17168#issuecomment-250235271
129134
Some((TimeoutClock::RealTime, TimeoutAnchor::Relative, duration))
130135
} else {
131136
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
@@ -144,7 +149,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
144149
|ecx, unblock: UnblockKind| match unblock {
145150
UnblockKind::Ready => {
146151
// From the manual:
147-
// If successful, all requests, except UMTX_SHM_CREAT and UMTX_SHM_LOOKUP
152+
// If successful, all requests, except UMTX_SHM_CREAT and UMTX_SHM_LOOKUP
148153
// sub-requests of the UMTX_OP_SHM request, will return zero.
149154
ecx.write_int(0, &dest)
150155
}
@@ -191,8 +196,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
191196
)?;
192197

193198
// From the manual:
194-
// If successful, all requests, except UMTX_SHM_CREAT and UMTX_SHM_LOOKUP
195-
// sub-requests of the UMTX_OP_SHM request, will return zero.
199+
// If successful, all requests, except UMTX_SHM_CREAT and UMTX_SHM_LOOKUP
200+
// sub-requests of the UMTX_OP_SHM request, will return zero.
196201
this.write_int(0, dest)?;
197202
interp_ok(())
198203
}

0 commit comments

Comments
 (0)