Skip to content

Commit 5971474

Browse files
committed
Get size of integers using libc
1 parent c933c53 commit 5971474

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/shims/foreign_items.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
522522
} else {
523523
let tp = this.force_ptr(this.read_scalar(args[1])?.not_undef()?)?;
524524

525+
let long = this.resolve_path(&["libc", "c_long"])?.ty(*tcx);
526+
let time_t = this.resolve_path(&["libc", "time_t"])?.ty(*tcx);
527+
528+
let tv_sec_size = this.layout_of(time_t)?.size;
529+
let tv_nsec_size = this.layout_of(long)?.size;
530+
525531
let allocation = this.memory_mut().get_mut(tp.alloc_id)?;
526532

527533
let mut sign = 1;
@@ -533,13 +539,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
533539
e.duration()
534540
});
535541

536-
let tv_sec_size = Size::from_bits(64);
537-
let tv_nsec_size = Size::from_bits(64);
538-
539542
allocation.write_scalar(
540543
tcx,
541544
tp,
542-
Scalar::from_int(sign * (duration.as_secs() as i64), tv_sec_size).into(),
545+
Scalar::from_int(sign * (duration.as_secs() as i64), tv_sec_size)
546+
.into(),
543547
tv_sec_size,
544548
)?;
545549

@@ -555,16 +559,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
555559
}
556560
}
557561

558-
"strlen" => {
559-
let ptr = this.read_scalar(args[0])?.not_undef()?;
560-
let n = this.memory().read_c_str(ptr)?.len();
561-
this.write_scalar(Scalar::from_uint(n as u64, dest.layout.size), dest)?;
562-
}
562+
"strlen" => {
563+
let ptr = this.read_scalar(args[0])?.not_undef()?;
564+
let n = this.memory().read_c_str(ptr)?.len();
565+
this.write_scalar(Scalar::from_uint(n as u64, dest.layout.size), dest)?;
566+
}
563567

564-
// math functions
565-
"cbrtf" | "coshf" | "sinhf" | "tanf" => {
566-
// FIXME: Using host floats.
567-
let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
568+
// math functions
569+
"cbrtf" | "coshf" | "sinhf" | "tanf" => {
570+
// FIXME: Using host floats.
571+
let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
568572
let f = match link_name {
569573
"cbrtf" => f.cbrt(),
570574
"coshf" => f.cosh(),

0 commit comments

Comments
 (0)