Skip to content

Commit 90c3977

Browse files
committed
Add synchronisation for read and write to pass the race test
1 parent dacfe9c commit 90c3977

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/shims/unix/linux/eventfd.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct Event {
2626
/// kernel. This counter is initialized with the value specified in the argument initval.
2727
counter: u64,
2828
is_nonblock: bool,
29-
_clock: VClock,
29+
clock: VClock,
3030
}
3131

3232
impl FileDescription for Event {
@@ -60,6 +60,8 @@ impl FileDescription for Event {
6060
throw_unsup_format!("eventfd: blocking is unsupported");
6161
}
6262
} else {
63+
// Prevent false alarm in data race detection when doing synchronisation via eventfd.
64+
ecx.acquire_clock(&self.clock);
6365
// Return the counter in the host endianness using the buffer provided by caller.
6466
let counter_byte: [u8; 8] = match ecx.tcx.sess.target.endian {
6567
Endian::Little => self.counter.to_le_bytes(),
@@ -117,6 +119,8 @@ impl FileDescription for Event {
117119
throw_unsup_format!("eventfd: blocking is unsupported");
118120
}
119121
} else {
122+
// Prevent false alarm in data race detection when doing synchronisation via eventfd.
123+
self.clock.join(&ecx.release_clock().unwrap());
120124
self.counter = self.counter.checked_add(num).unwrap();
121125
}
122126
Ok(Ok(8))
@@ -174,7 +178,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
174178
let fd = this.machine.fds.insert_fd(FileDescriptor::new(Event {
175179
counter: val.into(),
176180
is_nonblock,
177-
_clock: VClock::default(),
181+
clock: VClock::default(),
178182
}));
179183
Ok(Scalar::from_i32(fd))
180184
}

tests/pass-dep/libc/libc-eventfd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::thread;
44

55
fn main() {
6-
//test_read_write();
6+
test_read_write();
77
test_race();
88
}
99

0 commit comments

Comments
 (0)