@@ -267,18 +267,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
267
267
let handle = if is_dir && exists {
268
268
let fh = & mut this. machine . fds ;
269
269
let fd = fh. insert_new ( DirHandle { path : file_name. into ( ) } ) ;
270
- Ok ( Handle :: File ( fd as u32 ) )
270
+ Ok ( Handle :: File ( fd) )
271
271
} else if creation_disposition == open_existing && desired_access == 0 {
272
272
// Windows supports handles with no permissions. These allow things such as reading
273
273
// metadata, but not file content.
274
274
let fh = & mut this. machine . fds ;
275
275
let fd = fh. insert_new ( MetadataHandle { path : file_name. into ( ) } ) ;
276
- Ok ( Handle :: File ( fd as u32 ) )
276
+ Ok ( Handle :: File ( fd) )
277
277
} else {
278
278
options. open ( file_name) . map ( |file| {
279
279
let fh = & mut this. machine . fds ;
280
280
let fd = fh. insert_new ( FileHandle { file, writable : desired_write } ) ;
281
- Handle :: File ( fd as u32 )
281
+ Handle :: File ( fd)
282
282
} )
283
283
} ;
284
284
@@ -313,7 +313,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
313
313
this. invalid_handle ( "GetFileInformationByHandle" ) ?
314
314
} ;
315
315
316
- let Some ( desc) = this. machine . fds . get ( fd as i32 ) else {
316
+ let Some ( desc) = this. machine . fds . get ( fd) else {
317
317
this. invalid_handle ( "GetFileInformationByHandle" ) ?
318
318
} ;
319
319
@@ -340,18 +340,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
340
340
let accessed = extract_windows_epoch ( metadata. accessed ( ) ) ?. unwrap_or ( ( 0 , 0 ) ) ;
341
341
let written = extract_windows_epoch ( metadata. modified ( ) ) ?. unwrap_or ( ( 0 , 0 ) ) ;
342
342
343
- this. write_int_fields_named (
344
- & [ ( "dwFileAttributes" , attributes as i128 ) ] ,
345
- & file_information,
346
- ) ?;
343
+ this. write_int_fields_named ( & [ ( "dwFileAttributes" , attributes. into ( ) ) ] , & file_information) ?;
347
344
write_filetime_field ( this, & file_information, "ftCreationTime" , created) ?;
348
345
write_filetime_field ( this, & file_information, "ftLastAccessTime" , accessed) ?;
349
346
write_filetime_field ( this, & file_information, "ftLastWriteTime" , written) ?;
350
347
this. write_int_fields_named (
351
348
& [
352
349
( "dwVolumeSerialNumber" , 0 ) ,
353
- ( "nFileSizeHigh" , ( size >> 32 ) as i128 ) ,
354
- ( "nFileSizeLow" , size as u32 as i128 ) ,
350
+ ( "nFileSizeHigh" , ( size >> 32 ) . into ( ) ) ,
351
+ ( "nFileSizeLow" , ( size & 0xFFFFFFFF ) . into ( ) ) ,
355
352
( "nNumberOfLinks" , 1 ) ,
356
353
( "nFileIndexHigh" , 0 ) ,
357
354
( "nFileIndexLow" , 0 ) ,
@@ -451,7 +448,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
451
448
res. ok ( ) . map ( |n| u32:: try_from ( n) . unwrap ( ) )
452
449
}
453
450
Handle :: File ( fd) => {
454
- let Some ( desc) = this. machine . fds . get ( fd as i32 ) else {
451
+ let Some ( desc) = this. machine . fds . get ( fd) else {
455
452
this. invalid_handle ( "NtWriteFile" ) ?
456
453
} ;
457
454
@@ -540,7 +537,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
540
537
res. ok ( ) . map ( |n| u32:: try_from ( n) . unwrap ( ) )
541
538
}
542
539
Handle :: File ( fd) => {
543
- let Some ( desc) = this. machine . fds . get ( fd as i32 ) else {
540
+ let Some ( desc) = this. machine . fds . get ( fd) else {
544
541
this. invalid_handle ( "NtReadFile" ) ?
545
542
} ;
546
543
@@ -584,7 +581,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
584
581
_ => this. invalid_handle ( "SetFilePointerEx" ) ?,
585
582
} ;
586
583
587
- let Some ( desc) = this. machine . fds . get ( fd as i32 ) else {
584
+ let Some ( desc) = this. machine . fds . get ( fd) else {
588
585
throw_unsup_format ! ( "`SetFilePointerEx` is only supported on file backed handles" ) ;
589
586
} ;
590
587
@@ -604,7 +601,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
604
601
605
602
match desc. seek ( this. machine . communicate ( ) , seek) ? {
606
603
Ok ( n) => {
607
- this. write_scalar ( Scalar :: from_i64 ( n as i64 ) , & this. deref_pointer ( new_fp) ?) ?;
604
+ this. write_scalar (
605
+ Scalar :: from_i64 ( n. try_into ( ) . unwrap ( ) ) ,
606
+ & this. deref_pointer ( new_fp) ?,
607
+ ) ?;
608
608
interp_ok ( this. eval_windows ( "c" , "TRUE" ) )
609
609
}
610
610
Err ( e) => {
@@ -619,14 +619,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
619
619
fn extract_windows_epoch < ' tcx > (
620
620
time : io:: Result < SystemTime > ,
621
621
) -> InterpResult < ' tcx , Option < ( u32 , u32 ) > > {
622
- // seconds in a year * 10 million (nanoseconds/second / 100)
623
- const TIME_TO_EPOCH : u64 = 31_536_000 * 10_000_000 ;
622
+ // ( seconds in a year) * (369 years between 1970 and 1601) * 10 million (nanoseconds/second / 100)
623
+ const TIME_TO_EPOCH : u64 = 31_556_926 * 369 * 10_000_000 ;
624
624
match time. ok ( ) {
625
625
Some ( time) => {
626
626
let duration = system_time_to_duration ( & time) ?;
627
- let secs = duration. as_secs ( ) * 10_000_000 ;
628
- let nanos_hundred = ( duration. subsec_nanos ( ) / 100 ) as u64 ;
629
- let total = secs + nanos_hundred + TIME_TO_EPOCH ;
627
+ let secs = duration. as_secs ( ) . saturating_mul ( 10_000_000 ) ;
628
+ let nanos_hundred: u64 = ( duration. subsec_nanos ( ) / 100 ) . into ( ) ;
629
+ let total = secs. saturating_add ( nanos_hundred) . saturating_add ( TIME_TO_EPOCH ) ;
630
+ #[ allow( clippy:: cast_possible_truncation) ]
630
631
interp_ok ( Some ( ( total as u32 , ( total >> 32 ) as u32 ) ) )
631
632
}
632
633
None => interp_ok ( None ) ,
@@ -640,7 +641,7 @@ fn write_filetime_field<'tcx>(
640
641
( low, high) : ( u32 , u32 ) ,
641
642
) -> InterpResult < ' tcx > {
642
643
cx. write_int_fields_named (
643
- & [ ( "dwLowDateTime" , low as i128 ) , ( "dwHighDateTime" , high as i128 ) ] ,
644
+ & [ ( "dwLowDateTime" , low. into ( ) ) , ( "dwHighDateTime" , high. into ( ) ) ] ,
644
645
& cx. project_field_named ( val, name) ?,
645
646
)
646
647
}
0 commit comments