@@ -16,6 +16,7 @@ fn get_time() -> (Duration, i128) {
16
16
17
17
impl < ' mir , ' tcx > EvalContextExt < ' mir , ' tcx > for crate :: MiriEvalContext < ' mir , ' tcx > { }
18
18
pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
19
+ // Foreign function used by linux
19
20
fn clock_gettime (
20
21
& mut self ,
21
22
clk_id_op : OpTy < ' tcx , Tag > ,
@@ -38,12 +39,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
38
39
39
40
let ( duration, sign) = get_time ( ) ;
40
41
let tv_sec = sign * ( duration. as_secs ( ) as i128 ) ;
41
- let tv_nsec = duration. subsec_nanos ( ) as i128 ;
42
+ let mut tv_nsec = duration. subsec_nanos ( ) as i128 ;
43
+ // If the number of seconds is zero, we need to put the sign into the second's fraction.
44
+ if tv_sec == 0 && sign < 0 {
45
+ tv_nsec *= sign;
46
+ }
47
+
42
48
this. write_c_ints ( & tp, & [ tv_sec, tv_nsec] , & [ "time_t" , "c_long" ] ) ?;
43
49
44
50
Ok ( 0 )
45
51
}
46
-
52
+ // Foreign function used by generic unix
47
53
fn gettimeofday (
48
54
& mut self ,
49
55
tv_op : OpTy < ' tcx , Tag > ,
@@ -66,7 +72,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
66
72
67
73
let ( duration, sign) = get_time ( ) ;
68
74
let tv_sec = sign * ( duration. as_secs ( ) as i128 ) ;
69
- let tv_usec = duration. subsec_micros ( ) as i128 ;
75
+ let mut tv_usec = duration. subsec_micros ( ) as i128 ;
76
+ // If the number of seconds is zero, we need to put the sign into the second's fraction.
77
+ if tv_sec == 0 && sign < 0 {
78
+ tv_usec *= sign;
79
+ }
70
80
71
81
this. write_c_ints ( & tv, & [ tv_sec, tv_usec] , & [ "time_t" , "suseconds_t" ] ) ?;
72
82
0 commit comments