Skip to content

Commit 400214b

Browse files
authored
Merge pull request rust-lang#4263 from geetanshjuneja/check_shim_abi
Replace check_shim with check_shim_abi in unix/foreign_items shims
2 parents a19a024 + f3ae022 commit 400214b

File tree

6 files changed

+405
-82
lines changed

6 files changed

+405
-82
lines changed

src/tools/miri/src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10171017
}
10181018

10191019
/// Check that the given `caller_fn_abi` matches the expected ABI described by
1020-
/// `callee_abi`, `callee_input_tys`, `callee_output_ty`, and the return the list of
1020+
/// `callee_abi`, `callee_input_tys`, `callee_output_ty`, and then returns the list of
10211021
/// arguments.
10221022
fn check_shim_abi<'a, const N: usize>(
10231023
&mut self,

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
2121
&mut self,
2222
clk_id_op: &OpTy<'tcx>,
2323
tp_op: &OpTy<'tcx>,
24-
) -> InterpResult<'tcx, Scalar> {
24+
dest: &MPlaceTy<'tcx>,
25+
) -> InterpResult<'tcx> {
2526
// This clock support is deliberately minimal because a lot of clock types have fiddly
2627
// properties (is it possible for Miri to be suspended independently of the host?). If you
2728
// have a use for another clock type, please open an issue.
2829

2930
let this = self.eval_context_mut();
3031

3132
this.assert_target_os_is_unix("clock_gettime");
33+
let clockid_t_size = this.libc_ty_layout("clockid_t").size;
3234

33-
let clk_id = this.read_scalar(clk_id_op)?.to_i32()?;
35+
let clk_id = this.read_scalar(clk_id_op)?.to_int(clockid_t_size)?;
3436
let tp = this.deref_pointer_as(tp_op, this.libc_ty_layout("timespec"))?;
3537

3638
let absolute_clocks;
@@ -43,34 +45,34 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4345
// Linux further distinguishes regular and "coarse" clocks, but the "coarse" version
4446
// is just specified to be "faster and less precise", so we implement both the same way.
4547
absolute_clocks = vec![
46-
this.eval_libc_i32("CLOCK_REALTIME"),
47-
this.eval_libc_i32("CLOCK_REALTIME_COARSE"),
48+
this.eval_libc("CLOCK_REALTIME").to_int(clockid_t_size)?,
49+
this.eval_libc("CLOCK_REALTIME_COARSE").to_int(clockid_t_size)?,
4850
];
4951
// The second kind is MONOTONIC clocks for which 0 is an arbitrary time point, but they are
5052
// never allowed to go backwards. We don't need to do any additional monotonicity
5153
// enforcement because std::time::Instant already guarantees that it is monotonic.
5254
relative_clocks = vec![
53-
this.eval_libc_i32("CLOCK_MONOTONIC"),
54-
this.eval_libc_i32("CLOCK_MONOTONIC_COARSE"),
55+
this.eval_libc("CLOCK_MONOTONIC").to_int(clockid_t_size)?,
56+
this.eval_libc("CLOCK_MONOTONIC_COARSE").to_int(clockid_t_size)?,
5557
];
5658
}
5759
"macos" => {
58-
absolute_clocks = vec![this.eval_libc_i32("CLOCK_REALTIME")];
59-
relative_clocks = vec![this.eval_libc_i32("CLOCK_MONOTONIC")];
60+
absolute_clocks = vec![this.eval_libc("CLOCK_REALTIME").to_int(clockid_t_size)?];
61+
relative_clocks = vec![this.eval_libc("CLOCK_MONOTONIC").to_int(clockid_t_size)?];
6062
// `CLOCK_UPTIME_RAW` supposed to not increment while the system is asleep... but
6163
// that's not really something a program running inside Miri can tell, anyway.
6264
// We need to support it because std uses it.
63-
relative_clocks.push(this.eval_libc_i32("CLOCK_UPTIME_RAW"));
65+
relative_clocks.push(this.eval_libc("CLOCK_UPTIME_RAW").to_int(clockid_t_size)?);
6466
}
6567
"solaris" | "illumos" => {
6668
// The REALTIME clock returns the actual time since the Unix epoch.
67-
absolute_clocks = vec![this.eval_libc_i32("CLOCK_REALTIME")];
69+
absolute_clocks = vec![this.eval_libc("CLOCK_REALTIME").to_int(clockid_t_size)?];
6870
// MONOTONIC, in the other hand, is the high resolution, non-adjustable
6971
// clock from an arbitrary time in the past.
7072
// Note that the man page mentions HIGHRES but it is just
7173
// an alias of MONOTONIC and the libc crate does not expose it anyway.
7274
// https://docs.oracle.com/cd/E23824_01/html/821-1465/clock-gettime-3c.html
73-
relative_clocks = vec![this.eval_libc_i32("CLOCK_MONOTONIC")];
75+
relative_clocks = vec![this.eval_libc("CLOCK_MONOTONIC").to_int(clockid_t_size)?];
7476
}
7577
target => throw_unsup_format!("`clock_gettime` is not supported on target OS {target}"),
7678
}
@@ -81,15 +83,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8183
} else if relative_clocks.contains(&clk_id) {
8284
this.machine.monotonic_clock.now().duration_since(this.machine.monotonic_clock.epoch())
8385
} else {
84-
return this.set_last_error_and_return_i32(LibcError("EINVAL"));
86+
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
8587
};
8688

8789
let tv_sec = duration.as_secs();
8890
let tv_nsec = duration.subsec_nanos();
8991

9092
this.write_int_fields(&[tv_sec.into(), tv_nsec.into()], &tp)?;
93+
this.write_int(0, dest)?;
9194

92-
interp_ok(Scalar::from_i32(0))
95+
interp_ok(())
9396
}
9497

9598
fn gettimeofday(

0 commit comments

Comments
 (0)