Skip to content

Commit 1f25f53

Browse files
committed
Add more comments
1 parent 86edc8f commit 1f25f53

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/shims/unix/linux/eventfd.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use crate::{concurrency::VClock, *};
99

1010
use self::shims::unix::fd::FileDescriptor;
1111

12+
/// Minimum size of u8 array to hold u64 value.
13+
const U64_MIN_ARRAY_SIZE: usize = 8;
14+
1215
/// Maximum value that the eventfd counter can hold.
1316
const MAX_COUNTER: u64 = u64::MAX - 1;
1417

@@ -48,7 +51,7 @@ impl FileDescription for Event {
4851
ecx: &mut MiriInterpCx<'tcx>,
4952
) -> InterpResult<'tcx, io::Result<usize>> {
5053
// Check the size of slice, and return error only if the size of the slice < 8.
51-
let Some(bytes) = bytes.first_chunk_mut::<8>() else {
54+
let Some(bytes) = bytes.first_chunk_mut::<U64_MIN_ARRAY_SIZE>() else {
5255
return Ok(Err(Error::from(ErrorKind::InvalidInput)));
5356
};
5457
// Block when counter == 0.
@@ -68,7 +71,7 @@ impl FileDescription for Event {
6871
Endian::Big => self.counter.to_be_bytes(),
6972
};
7073
self.counter = 0;
71-
return Ok(Ok(8));
74+
return Ok(Ok(U64_MIN_ARRAY_SIZE));
7275
}
7376
}
7477

@@ -91,7 +94,7 @@ impl FileDescription for Event {
9194
ecx: &mut MiriInterpCx<'tcx>,
9295
) -> InterpResult<'tcx, io::Result<usize>> {
9396
// Check the size of slice, and return error only if the size of the slice < 8.
94-
let Some(bytes) = bytes.first_chunk::<8>() else {
97+
let Some(bytes) = bytes.first_chunk::<U64_MIN_ARRAY_SIZE>() else {
9598
return Ok(Err(Error::from(ErrorKind::InvalidInput)));
9699
};
97100
// Convert from bytes to int according to host endianness.
@@ -120,7 +123,7 @@ impl FileDescription for Event {
120123
}
121124
}
122125
};
123-
Ok(Ok(8))
126+
Ok(Ok(U64_MIN_ARRAY_SIZE))
124127
}
125128
}
126129

@@ -161,14 +164,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
161164

162165
let mut is_nonblock = false;
163166
// Unload the flag that we support.
167+
// After unloading, flags != 0 means other flags are used.
164168
if flags & efd_cloexec == efd_cloexec {
165169
flags &= !efd_cloexec;
166170
}
167171
if flags & efd_nonblock == efd_nonblock {
168172
flags &= !efd_nonblock;
169173
is_nonblock = true;
170174
}
171-
// After unloading, flags != 0 means other flags are used.
172175
if flags != 0 {
173176
let einval = this.eval_libc("EINVAL");
174177
this.set_last_error(einval)?;

tests/fail-dep/libc/libc_eventfd_read_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ignore-target-windows: No eventfd on Windows
22
//@ignore-target-apple: No eventfd in macos
33
fn main() {
4-
// eventfd read will block when non-block flag is clear and counter = 0.
4+
// eventfd read will block when EFD_NONBLOCK flag is clear and counter = 0.
55
// This will pass when blocking is implemented.
66
let flags = libc::EFD_CLOEXEC;
77
let fd = unsafe { libc::eventfd(0, flags) };

tests/fail-dep/libc/libc_eventfd_write_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ignore-target-windows: No eventfd on Windows
22
//@ignore-target-apple: No eventfd in macos
33
fn main() {
4-
// eventfd write will block when we try to add until it exceed u64-1.
4+
// eventfd write will block when we try to add until it exceed u64::MAX - 1.
55
// This will pass when blocking is implemented.
66
let flags = libc::EFD_CLOEXEC;
77
let fd = unsafe { libc::eventfd(0, flags) };

0 commit comments

Comments
 (0)