@@ -511,8 +511,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
511511 if !this. machine . communicate {
512512 throw_unsup_format ! ( "`clock_gettime` not available when isolation is enabled" )
513513 } else {
514- let tcx = & { this. tcx . tcx } ;
515-
516514 let clk_id = this. read_scalar ( args[ 0 ] ) ?. to_i32 ( ) ?;
517515
518516 if clk_id != this. eval_libc_i32 ( "CLOCK_REALTIME" ) ? {
@@ -522,14 +520,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
522520 } else {
523521 let tp = this. force_ptr ( this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?) ?;
524522
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-
531- let allocation = this. memory_mut ( ) . get_mut ( tp. alloc_id ) ?;
532-
533523 let mut sign = 1 ;
534524
535525 let duration = std:: time:: SystemTime :: now ( )
@@ -539,20 +529,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
539529 e. duration ( )
540530 } ) ;
541531
542- allocation. write_scalar (
543- tcx,
544- tp,
545- Scalar :: from_int ( sign * ( duration. as_secs ( ) as i64 ) , tv_sec_size)
546- . into ( ) ,
547- tv_sec_size,
548- ) ?;
549-
550- allocation. write_scalar (
551- tcx,
552- tp. offset ( tv_sec_size, tcx) ?,
553- Scalar :: from_int ( duration. subsec_nanos ( ) as i64 , tv_nsec_size) . into ( ) ,
554- tv_nsec_size,
555- ) ?;
532+ let tv_sec = sign * ( duration. as_secs ( ) as i128 ) ;
533+ let tv_nsec = duration. subsec_nanos ( ) as i128 ;
534+
535+ this. write_c_ints ( & tp, & [ tv_sec, tv_nsec] , & [ "time_t" , "c_long" ] ) ?;
556536
557537 this. write_scalar ( Scalar :: from_int ( 0i32 , dest. layout . size ) , dest) ?;
558538 }
@@ -563,8 +543,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
563543 if !this. machine . communicate {
564544 throw_unsup_format ! ( "`gettimeofday` not available when isolation is enabled" )
565545 } else {
566- let tcx = & { this. tcx . tcx } ;
567-
568546 let tz = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
569547 // Using tz is obsolete and should always be null
570548 if !this. is_null ( tz) ? {
@@ -574,14 +552,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
574552 } else {
575553 let tv = this. force_ptr ( this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?) ?;
576554
577- let time_t = this. resolve_path ( & [ "libc" , "time_t" ] ) ?. ty ( * tcx) ;
578- let suseconds_t = this. resolve_path ( & [ "libc" , "suseconds_t" ] ) ?. ty ( * tcx) ;
579-
580- let tv_sec_size = this. layout_of ( time_t) ?. size ;
581- let tv_usec_size = this. layout_of ( suseconds_t) ?. size ;
582-
583- let allocation = this. memory_mut ( ) . get_mut ( tv. alloc_id ) ?;
584-
585555 let mut sign = 1 ;
586556
587557 let duration = std:: time:: SystemTime :: now ( )
@@ -591,20 +561,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
591561 e. duration ( )
592562 } ) ;
593563
594- allocation. write_scalar (
595- tcx,
596- tv,
597- Scalar :: from_int ( sign * ( duration. as_secs ( ) as i64 ) , tv_sec_size)
598- . into ( ) ,
599- tv_sec_size,
600- ) ?;
601-
602- allocation. write_scalar (
603- tcx,
604- tv. offset ( tv_sec_size, tcx) ?,
605- Scalar :: from_int ( duration. subsec_micros ( ) as i64 , tv_usec_size) . into ( ) ,
606- tv_usec_size,
607- ) ?;
564+ let tv_sec = sign * ( duration. as_secs ( ) as i128 ) ;
565+ let tv_usec = duration. subsec_micros ( ) as i128 ;
566+
567+ this. write_c_ints ( & tv, & [ tv_sec, tv_usec] , & [ "time_t" , "suseconds_t" ] ) ?;
608568
609569 this. write_scalar ( Scalar :: from_int ( 0i32 , dest. layout . size ) , dest) ?;
610570 }
0 commit comments