@@ -267,18 +267,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
267267 let handle = if is_dir && exists {
268268 let fh = & mut this. machine . fds ;
269269 let fd = fh. insert_new ( DirHandle { path : file_name. into ( ) } ) ;
270- Ok ( Handle :: File ( fd as u32 ) )
270+ Ok ( Handle :: File ( fd) )
271271 } else if creation_disposition == open_existing && desired_access == 0 {
272272 // Windows supports handles with no permissions. These allow things such as reading
273273 // metadata, but not file content.
274274 let fh = & mut this. machine . fds ;
275275 let fd = fh. insert_new ( MetadataHandle { path : file_name. into ( ) } ) ;
276- Ok ( Handle :: File ( fd as u32 ) )
276+ Ok ( Handle :: File ( fd) )
277277 } else {
278278 options. open ( file_name) . map ( |file| {
279279 let fh = & mut this. machine . fds ;
280280 let fd = fh. insert_new ( FileHandle { file, writable : desired_write } ) ;
281- Handle :: File ( fd as u32 )
281+ Handle :: File ( fd)
282282 } )
283283 } ;
284284
@@ -313,7 +313,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
313313 this. invalid_handle ( "GetFileInformationByHandle" ) ?
314314 } ;
315315
316- let Some ( desc) = this. machine . fds . get ( fd as i32 ) else {
316+ let Some ( desc) = this. machine . fds . get ( fd) else {
317317 this. invalid_handle ( "GetFileInformationByHandle" ) ?
318318 } ;
319319
@@ -340,18 +340,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
340340 let accessed = extract_windows_epoch ( metadata. accessed ( ) ) ?. unwrap_or ( ( 0 , 0 ) ) ;
341341 let written = extract_windows_epoch ( metadata. modified ( ) ) ?. unwrap_or ( ( 0 , 0 ) ) ;
342342
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) ?;
347344 write_filetime_field ( this, & file_information, "ftCreationTime" , created) ?;
348345 write_filetime_field ( this, & file_information, "ftLastAccessTime" , accessed) ?;
349346 write_filetime_field ( this, & file_information, "ftLastWriteTime" , written) ?;
350347 this. write_int_fields_named (
351348 & [
352349 ( "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 ( ) ) ,
355352 ( "nNumberOfLinks" , 1 ) ,
356353 ( "nFileIndexHigh" , 0 ) ,
357354 ( "nFileIndexLow" , 0 ) ,
@@ -451,7 +448,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
451448 res. ok ( ) . map ( |n| u32:: try_from ( n) . unwrap ( ) )
452449 }
453450 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 {
455452 this. invalid_handle ( "NtWriteFile" ) ?
456453 } ;
457454
@@ -540,7 +537,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
540537 res. ok ( ) . map ( |n| u32:: try_from ( n) . unwrap ( ) )
541538 }
542539 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 {
544541 this. invalid_handle ( "NtReadFile" ) ?
545542 } ;
546543
@@ -584,7 +581,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
584581 _ => this. invalid_handle ( "SetFilePointerEx" ) ?,
585582 } ;
586583
587- let Some ( desc) = this. machine . fds . get ( fd as i32 ) else {
584+ let Some ( desc) = this. machine . fds . get ( fd) else {
588585 throw_unsup_format ! ( "`SetFilePointerEx` is only supported on file backed handles" ) ;
589586 } ;
590587
@@ -604,7 +601,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
604601
605602 match desc. seek ( this. machine . communicate ( ) , seek) ? {
606603 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+ ) ?;
608608 interp_ok ( this. eval_windows ( "c" , "TRUE" ) )
609609 }
610610 Err ( e) => {
@@ -619,14 +619,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
619619fn extract_windows_epoch < ' tcx > (
620620 time : io:: Result < SystemTime > ,
621621) -> 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 ;
624624 match time. ok ( ) {
625625 Some ( time) => {
626626 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) ]
630631 interp_ok ( Some ( ( total as u32 , ( total >> 32 ) as u32 ) ) )
631632 }
632633 None => interp_ok ( None ) ,
@@ -640,7 +641,7 @@ fn write_filetime_field<'tcx>(
640641 ( low, high) : ( u32 , u32 ) ,
641642) -> InterpResult < ' tcx > {
642643 cx. write_int_fields_named (
643- & [ ( "dwLowDateTime" , low as i128 ) , ( "dwHighDateTime" , high as i128 ) ] ,
644+ & [ ( "dwLowDateTime" , low. into ( ) ) , ( "dwHighDateTime" , high. into ( ) ) ] ,
644645 & cx. project_field_named ( val, name) ?,
645646 )
646647}
0 commit comments