Skip to content

Commit 0a28dce

Browse files
committed
fix handling of scalars in futex code
1 parent 834de52 commit 0a28dce

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
@@ -169,7 +169,7 @@ pub fn futex<'tcx>(
169169
}
170170
|ecx, unblock: UnblockKind| match unblock {
171171
UnblockKind::Ready => {
172-
ecx.write_scalar(Scalar::from_target_isize(0, ecx), &dest)
172+
ecx.write_int(0, &dest)
173173
}
174174
UnblockKind::TimedOut => {
175175
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
@@ -224,11 +224,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
224224
|this, unblock: UnblockKind| {
225225
match unblock {
226226
UnblockKind::Ready => {
227-
this.write_scalar(Scalar::from_i32(1), &dest)
227+
this.write_int(1, &dest)
228228
}
229229
UnblockKind::TimedOut => {
230230
this.set_last_error(IoError::WindowsError("ERROR_TIMEOUT"))?;
231-
this.write_scalar(Scalar::from_i32(0), &dest)
231+
this.write_int(0, &dest)
232232
}
233233
}
234234
}

0 commit comments

Comments
 (0)