Skip to content

Commit a93a671

Browse files
committed
fix handling of scalars in futex code
1 parent 8de4747 commit a93a671

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(unqualified_local_imports)]
1616
#![feature(derive_coerce_pointee)]
1717
#![feature(arbitrary_self_types)]
18+
#![feature(unsigned_is_multiple_of)]
1819
// Configure clippy and other lints
1920
#![allow(
2021
clippy::collapsible_else_if,

src/shims/unix/linux_like/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn futex<'tcx>(
167167
}
168168
|ecx, unblock: UnblockKind| match unblock {
169169
UnblockKind::Ready => {
170-
ecx.write_scalar(Scalar::from_target_isize(0, ecx), &dest)
170+
ecx.write_int(0, &dest)
171171
}
172172
UnblockKind::TimedOut => {
173173
ecx.set_last_error_and_return(LibcError("ETIMEDOUT"), &dest)

src/shims/unix/macos/sync.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
120120
// Perform validation of the arguments.
121121
let addr = ptr.addr().bytes();
122122
if addr == 0
123-
|| addr % size != 0
124123
|| !matches!(size, 4 | 8)
124+
|| !addr.is_multiple_of(size)
125125
|| (flags != none && flags != shared)
126126
|| clock_timeout
127127
.is_some_and(|(clock, _, timeout)| clock != absolute_clock || timeout == 0)
@@ -164,7 +164,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
164164
return interp_ok(());
165165
}
166166

167-
if futex_val == value as u128 {
167+
if futex_val == value.into() {
168168
// If the values are the same, we have to block.
169169
let futex_ref = futex.futex.clone();
170170
let dest = dest.clone();
@@ -180,8 +180,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
180180
|this, unblock: UnblockKind| {
181181
match unblock {
182182
UnblockKind::Ready => {
183-
let remaining = futex_ref.waiters();
184-
this.write_scalar(Scalar::from_i32(remaining as i32), &dest)
183+
let remaining = futex_ref.waiters().try_into().unwrap();
184+
this.write_scalar(Scalar::from_i32(remaining), &dest)
185185
}
186186
UnblockKind::TimedOut => {
187187
this.set_last_error_and_return(LibcError("ETIMEDOUT"), &dest)
@@ -192,7 +192,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
192192
);
193193
} else {
194194
// else retrieve the current number of waiters.
195-
let waiters = futex.futex.waiters() as i32;
195+
let waiters = futex.futex.waiters().try_into().unwrap();
196196
this.write_scalar(Scalar::from_i32(waiters), dest)?;
197197
}
198198

src/shims/windows/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
222222
|this, unblock: UnblockKind| {
223223
match unblock {
224224
UnblockKind::Ready => {
225-
this.write_scalar(Scalar::from_i32(1), &dest)
225+
this.write_int(1, &dest)
226226
}
227227
UnblockKind::TimedOut => {
228228
this.set_last_error(IoError::WindowsError("ERROR_TIMEOUT"))?;
229-
this.write_scalar(Scalar::from_i32(0), &dest)
229+
this.write_int(0, &dest)
230230
}
231231
}
232232
}

0 commit comments

Comments
 (0)