Skip to content

Commit f07f99c

Browse files
committed
fix read_scalar/read_pointer
1 parent dcb3593 commit f07f99c

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/tools/miri/src/shims/time.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
367367
clock_id: &OpTy<'tcx>,
368368
flags: &OpTy<'tcx>,
369369
req: &OpTy<'tcx>,
370-
rem: &OpTy<'tcx>, // Signal handlers are not supported, so rem will never be written to.
370+
rem: &OpTy<'tcx>,
371371
) -> InterpResult<'tcx, Scalar> {
372372
let this = self.eval_context_mut();
373373

374374
let clockid_t_size = this.libc_ty_layout("clockid_t").size;
375-
let clock_id = this.read_scalar(clock_id_op)?.to_int(clockid_t_size)?;
376-
let req = this.deref_pointer_as(req_op, this.libc_ty_layout("timespec"))?;
377-
// TODO must be a better way to do this, also fix the
378-
// if compare of the flags later
379-
let int_size = this.libc_ty_layout("int").size;
380-
let flags = this.read_scalar(flags)?.to_int(int_size);
381-
let rem = this.read_pointer()?;
375+
let clock_id = this.read_scalar(clock_id)?.to_int(clockid_t_size)?;
376+
let req = this.deref_pointer_as(req, this.libc_ty_layout("timespec"))?;
377+
let flags = this.read_scalar(flags)?.to_i32()?;
378+
let _rem = this.read_pointer(rem)?; // Signal handlers are not supported, so rem will never be written to.
382379

383380
// The standard lib through sleep_until only needs CLOCK_MONOTONIC
384381
if clock_id != this.eval_libc("CLOCK_MONOTONIC").to_int(clockid_t_size)? {
@@ -396,14 +393,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
396393
// No flags set, the timespec should be interperted as a duration
397394
// to sleep for
398395
TimeoutAnchor::Relative
399-
} else if flag == this.eval_libc("TIMER_ABSTIME").to_int(int_size) {
396+
} else if flags == this.eval_libc("TIMER_ABSTIME").to_i32()? {
400397
// Only flag TIMER_ABSTIME set, the timespec should be interperted as
401398
// an absolute time.
402399
TimeoutAnchor::Absolute
403400
} else {
404-
// The standard lib through sleep_until only needs TIMER_ABSTIME
401+
// The standard lib (through `sleep_until`) only needs TIMER_ABSTIME
405402
throw_unsup_format!(
406-
"`clock_nanosleep` unsupported flags {flags}, only no flags or\
403+
"`clock_nanosleep` unsupported flags {flags}, only no flags or \
407404
TIMER_ABSTIME is supported"
408405
);
409406
};

0 commit comments

Comments
 (0)