@@ -522,6 +522,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
522
522
} else {
523
523
let tp = this. force_ptr ( this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?) ?;
524
524
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
+
525
531
let allocation = this. memory_mut ( ) . get_mut ( tp. alloc_id ) ?;
526
532
527
533
let mut sign = 1 ;
@@ -533,13 +539,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
533
539
e. duration ( )
534
540
} ) ;
535
541
536
- let tv_sec_size = Size :: from_bits ( 64 ) ;
537
- let tv_nsec_size = Size :: from_bits ( 64 ) ;
538
-
539
542
allocation. write_scalar (
540
543
tcx,
541
544
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 ( ) ,
543
547
tv_sec_size,
544
548
) ?;
545
549
@@ -555,16 +559,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
555
559
}
556
560
}
557
561
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
+ }
563
567
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 ( ) ?) ;
568
572
let f = match link_name {
569
573
"cbrtf" => f. cbrt ( ) ,
570
574
"coshf" => f. cosh ( ) ,
@@ -1068,6 +1072,42 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1068
1072
Size :: from_bits ( 32 ) ,
1069
1073
) )
1070
1074
}
1075
+ //
1076
+ // fn path_to_res(tcx: &TyCtxt<'tcx>, path: &[&str]) -> Option<(def::Res)> {
1077
+ // let crates = tcx.crates();
1078
+ // let krate = crates
1079
+ // .iter()
1080
+ // .find(|&&krate| cx.tcx.crate_name(krate).as_str() == path[0]);
1081
+ // if let Some(krate) = krate {
1082
+ // let krate = DefId {
1083
+ // krate: *krate,
1084
+ // index: CRATE_DEF_INDEX,
1085
+ // };
1086
+ // let mut items = cx.tcx.item_children(krate);
1087
+ // let mut path_it = path.iter().skip(1).peekable();
1088
+ //
1089
+ // loop {
1090
+ // let segment = match path_it.next() {
1091
+ // Some(segment) => segment,
1092
+ // None => return None,
1093
+ // };
1094
+ //
1095
+ // let result = SmallVec::<[_; 8]>::new();
1096
+ // for item in mem::replace(&mut items, cx.tcx.arena.alloc_slice(&result)).iter() {
1097
+ // if item.ident.name.as_str() == *segment {
1098
+ // if path_it.peek().is_none() {
1099
+ // return Some(item.res);
1100
+ // }
1101
+ //
1102
+ // items = cx.tcx.item_children(item.res.def_id());
1103
+ // break;
1104
+ // }
1105
+ // }
1106
+ // }
1107
+ // } else {
1108
+ // None
1109
+ // }
1110
+ // }
1071
1111
}
1072
1112
1073
1113
// Shims the linux 'getrandom()' syscall.
0 commit comments