Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement futex_wait and futex_wake. #1568

Merged
merged 23 commits into from
Oct 3, 2020
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1ffc5bb
Implement futex_wait and futex_wake.
m-ou-se Oct 1, 2020
281a538
Move futex syscall to its own file.
m-ou-se Oct 1, 2020
6c2f36e
Erase tag from futex pointers.
m-ou-se Oct 1, 2020
69cea1d
Only check futex pointer in futex_wait and not in futex_wake.
m-ou-se Oct 1, 2020
1c582e7
Return correct value from futex_wait.
m-ou-se Oct 1, 2020
c2fa27c
Check maximum amount of arguments to SYS_futex.
m-ou-se Oct 2, 2020
712e800
Improve handling of the `addr` argument in SYS_futex.
m-ou-se Oct 2, 2020
ee3eb4b
Add comments that document SYS_futex better.
m-ou-se Oct 2, 2020
dabd980
Update note about number of arguments to SYS_futex.
m-ou-se Oct 2, 2020
422b505
Add note about arguments in futex implementation.
m-ou-se Oct 2, 2020
d5b3f54
Use force_ptr in futex implementation.
m-ou-se Oct 2, 2020
e64ead2
Implement timeouts for FUTEX_WAIT.
m-ou-se Oct 2, 2020
8113882
Add park/park_timeout/unpark test.
m-ou-se Oct 2, 2020
c9627b2
Use correct return type for syscall(SYS_futex).
m-ou-se Oct 2, 2020
924fd56
Only allow FUTEX_WAIT with timeout when isoloation is disabled.
m-ou-se Oct 3, 2020
6628275
Remove backtics from isolation error.
m-ou-se Oct 3, 2020
5880e7d
Update expected error messages in tests.
m-ou-se Oct 3, 2020
6df54c4
Use read_scalar_at_offset in futex_wait instead of memory.get_raw.
m-ou-se Oct 3, 2020
9d764c5
Add FIXME note about variadic syscall().
m-ou-se Oct 3, 2020
dc36988
Add test for futex syscall.
m-ou-se Oct 3, 2020
dfcb46a
Update syscall FIXME to include note about 'wrong' types.
m-ou-se Oct 3, 2020
c268ee2
Add note about use of force_ptr in futex implementation.
m-ou-se Oct 3, 2020
68776d2
Add FIXME about type of `addr` in futex implementation.
m-ou-se Oct 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/shims/posix/linux/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ pub fn futex<'tcx>(
if args.len() < 4 {
throw_ub_format!("incorrect number of arguments for futex syscall: got {}, expected at least 4", args.len());
}
let addr = this.read_scalar(args[1])?.check_init()?;
let addr = args[1];
let addr_scalar = this.read_scalar(addr)?.check_init()?;
m-ou-se marked this conversation as resolved.
Show resolved Hide resolved
let futex_ptr = this.force_ptr(addr_scalar)?.erase_tag();
let op = this.read_scalar(args[2])?.to_i32()?;
let val = this.read_scalar(args[3])?.to_i32()?;

this.memory.check_ptr_access(addr, Size::from_bytes(4), Align::from_bytes(4).unwrap())?;

let addr = addr.assert_ptr().erase_tag();

let thread = this.get_active_thread();

let futex_private = this.eval_libc_i32("FUTEX_PRIVATE_FLAG")?;
Expand All @@ -33,10 +31,11 @@ pub fn futex<'tcx>(
if !this.is_null(timeout)? {
throw_ub_format!("miri does not support timeouts for futex operations");
}
this.memory.check_ptr_access(addr_scalar, Size::from_bytes(4), Align::from_bytes(4).unwrap())?;
m-ou-se marked this conversation as resolved.
Show resolved Hide resolved
let futex_val = this.read_scalar_at_offset(args[1], 0, this.machine.layouts.i32)?.to_i32()?;
if val == futex_val {
this.block_thread(thread);
this.futex_wait(addr, thread);
this.futex_wait(futex_ptr, thread);
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
} else {
let eagain = this.eval_libc("EAGAIN")?;
this.set_last_error(eagain)?;
Expand All @@ -45,7 +44,7 @@ pub fn futex<'tcx>(
op if op == futex_wake => {
let mut n = 0;
for _ in 0..val {
if let Some(thread) = this.futex_wake(addr) {
if let Some(thread) = this.futex_wake(futex_ptr) {
this.unblock_thread(thread);
n += 1;
} else {
Expand Down