Skip to content

Commit 96049ef

Browse files
committed
move a bunch of type information into the respective shim
1 parent 38a4953 commit 96049ef

File tree

6 files changed

+106
-97
lines changed

6 files changed

+106
-97
lines changed

src/shims/time.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1515
&mut self,
1616
clk_id_op: &OpTy<'tcx, Provenance>,
1717
tp_op: &OpTy<'tcx, Provenance>,
18-
) -> InterpResult<'tcx, i32> {
18+
) -> InterpResult<'tcx, Scalar<Provenance>> {
1919
// This clock support is deliberately minimal because a lot of clock types have fiddly
2020
// properties (is it possible for Miri to be suspended independently of the host?). If you
2121
// have a use for another clock type, please open an issue.
@@ -46,15 +46,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4646
} else {
4747
let einval = this.eval_libc("EINVAL")?;
4848
this.set_last_error(einval)?;
49-
return Ok(-1);
49+
return Ok(Scalar::from_i32(-1));
5050
};
5151

5252
let tv_sec = duration.as_secs();
5353
let tv_nsec = duration.subsec_nanos();
5454

5555
this.write_int_fields(&[tv_sec.into(), tv_nsec.into()], &this.deref_operand(tp_op)?)?;
5656

57-
Ok(0)
57+
Ok(Scalar::from_i32(0))
5858
}
5959

6060
fn gettimeofday(
@@ -160,7 +160,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
160160
Ok(-1) // Return non-zero on success
161161
}
162162

163-
fn mach_absolute_time(&self) -> InterpResult<'tcx, u64> {
163+
fn mach_absolute_time(&self) -> InterpResult<'tcx, Scalar<Provenance>> {
164164
let this = self.eval_context_ref();
165165

166166
this.assert_target_os("macos", "mach_absolute_time");
@@ -169,13 +169,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
169169
// This returns a u64, with time units determined dynamically by `mach_timebase_info`.
170170
// We return plain nanoseconds.
171171
let duration = Instant::now().duration_since(this.machine.time_anchor);
172-
u64::try_from(duration.as_nanos()).map_err(|_| {
172+
let res = u64::try_from(duration.as_nanos()).map_err(|_| {
173173
err_unsup_format!("programs running longer than 2^64 nanoseconds are not supported")
174-
.into()
175-
})
174+
})?;
175+
Ok(Scalar::from_u64(res))
176176
}
177177

178-
fn mach_timebase_info(&mut self, info_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> {
178+
fn mach_timebase_info(
179+
&mut self,
180+
info_op: &OpTy<'tcx, Provenance>,
181+
) -> InterpResult<'tcx, Scalar<Provenance>> {
179182
let this = self.eval_context_mut();
180183

181184
this.assert_target_os("macos", "mach_timebase_info");
@@ -188,7 +191,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
188191
let (numer, denom) = (1, 1);
189192
this.write_int_fields(&[numer.into(), denom.into()], &info)?;
190193

191-
Ok(0) // KERN_SUCCESS
194+
Ok(Scalar::from_i32(0)) // KERN_SUCCESS
192195
}
193196

194197
fn nanosleep(

src/shims/unix/foreign_items.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6363
"close" => {
6464
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
6565
let result = this.close(fd)?;
66-
this.write_scalar(Scalar::from_i32(result), dest)?;
66+
this.write_scalar(result, dest)?;
6767
}
6868
"fcntl" => {
6969
// `fcntl` is variadic. The argument count is checked based on the first argument
@@ -128,13 +128,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
128128
"lseek64" => {
129129
let [fd, offset, whence] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
130130
let result = this.lseek64(fd, offset, whence)?;
131-
this.write_scalar(Scalar::from_i64(result), dest)?;
131+
this.write_scalar(result, dest)?;
132132
}
133133
"ftruncate64" => {
134134
let [fd, length] =
135135
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
136136
let result = this.ftruncate64(fd, length)?;
137-
this.write_scalar(Scalar::from_i32(result), dest)?;
137+
this.write_scalar(result, dest)?;
138138
}
139139
"fsync" => {
140140
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
@@ -164,7 +164,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
164164
"realpath" => {
165165
let [path, resolved_path] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
166166
let result = this.realpath(path, resolved_path)?;
167-
this.write_pointer(result, dest)?;
167+
this.write_scalar(result, dest)?;
168168
}
169169
"mkstemp" => {
170170
let [template] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;

0 commit comments

Comments
 (0)