@@ -310,20 +310,20 @@ impl FdTable {
310310
311311impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
312312pub trait EvalContextExt < ' tcx > : crate :: MiriInterpCxExt < ' tcx > {
313- fn dup ( & mut self , old_fd : i32 ) -> InterpResult < ' tcx , i32 > {
313+ fn dup ( & mut self , old_fd : i32 ) -> InterpResult < ' tcx , Scalar > {
314314 let this = self . eval_context_mut ( ) ;
315315
316316 let Some ( dup_fd) = this. machine . fds . dup ( old_fd) else {
317- return this. fd_not_found ( ) ;
317+ return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ? ) ) ;
318318 } ;
319- Ok ( this. machine . fds . insert_fd_with_min_fd ( dup_fd, 0 ) )
319+ Ok ( Scalar :: from_i32 ( this. machine . fds . insert_fd_with_min_fd ( dup_fd, 0 ) ) )
320320 }
321321
322- fn dup2 ( & mut self , old_fd : i32 , new_fd : i32 ) -> InterpResult < ' tcx , i32 > {
322+ fn dup2 ( & mut self , old_fd : i32 , new_fd : i32 ) -> InterpResult < ' tcx , Scalar > {
323323 let this = self . eval_context_mut ( ) ;
324324
325325 let Some ( dup_fd) = this. machine . fds . dup ( old_fd) else {
326- return this. fd_not_found ( ) ;
326+ return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ? ) ) ;
327327 } ;
328328 if new_fd != old_fd {
329329 // Close new_fd if it is previously opened.
@@ -333,7 +333,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
333333 file_description. close ( this. machine . communicate ( ) ) ?. ok ( ) ;
334334 }
335335 }
336- Ok ( new_fd)
336+ Ok ( Scalar :: from_i32 ( new_fd) )
337337 }
338338
339339 fn flock ( & mut self , fd : i32 , op : i32 ) -> InterpResult < ' tcx , Scalar > {
@@ -370,7 +370,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
370370 Ok ( Scalar :: from_i32 ( this. try_unwrap_io_result ( result) ?) )
371371 }
372372
373- fn fcntl ( & mut self , args : & [ OpTy < ' tcx > ] ) -> InterpResult < ' tcx , i32 > {
373+ fn fcntl ( & mut self , args : & [ OpTy < ' tcx > ] ) -> InterpResult < ' tcx , Scalar > {
374374 let this = self . eval_context_mut ( ) ;
375375
376376 if args. len ( ) < 2 {
@@ -388,11 +388,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
388388 // `FD_CLOEXEC` value without checking if the flag is set for the file because `std`
389389 // always sets this flag when opening a file. However we still need to check that the
390390 // file itself is open.
391- if this. machine . fds . is_fd ( fd) {
392- Ok ( this. eval_libc_i32 ( "FD_CLOEXEC" ) )
391+ Ok ( Scalar :: from_i32 ( if this. machine . fds . is_fd ( fd) {
392+ this. eval_libc_i32 ( "FD_CLOEXEC" )
393393 } else {
394- this. fd_not_found ( )
395- }
394+ this. fd_not_found ( ) ?
395+ } ) )
396396 } else if cmd == this. eval_libc_i32 ( "F_DUPFD" )
397397 || cmd == this. eval_libc_i32 ( "F_DUPFD_CLOEXEC" )
398398 {
@@ -409,15 +409,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
409409 let start = this. read_scalar ( & args[ 2 ] ) ?. to_i32 ( ) ?;
410410
411411 match this. machine . fds . dup ( fd) {
412- Some ( dup_fd) => Ok ( this. machine . fds . insert_fd_with_min_fd ( dup_fd, start) ) ,
413- None => this. fd_not_found ( ) ,
412+ Some ( dup_fd) =>
413+ Ok ( Scalar :: from_i32 ( this. machine . fds . insert_fd_with_min_fd ( dup_fd, start) ) ) ,
414+ None => Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ,
414415 }
415416 } else if this. tcx . sess . target . os == "macos" && cmd == this. eval_libc_i32 ( "F_FULLFSYNC" ) {
416417 // Reject if isolation is enabled.
417418 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
418419 this. reject_in_isolation ( "`fcntl`" , reject_with) ?;
419420 this. set_last_error_from_io_error ( ErrorKind :: PermissionDenied . into ( ) ) ?;
420- return Ok ( - 1 ) ;
421+ return Ok ( Scalar :: from_i32 ( - 1 ) ) ;
421422 }
422423
423424 this. ffullsync_fd ( fd)
@@ -462,7 +463,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
462463 buf : Pointer ,
463464 count : u64 ,
464465 offset : Option < i128 > ,
465- ) -> InterpResult < ' tcx , i64 > {
466+ ) -> InterpResult < ' tcx , Scalar > {
466467 let this = self . eval_context_mut ( ) ;
467468
468469 // Isolation check is done via `FileDescriptor` trait.
@@ -482,7 +483,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
482483 // We temporarily dup the FD to be able to retain mutable access to `this`.
483484 let Some ( fd) = this. machine . fds . dup ( fd) else {
484485 trace ! ( "read: FD not found" ) ;
485- return this. fd_not_found ( ) ;
486+ return Ok ( Scalar :: from_target_isize ( this. fd_not_found ( ) ? , this ) ) ;
486487 } ;
487488
488489 trace ! ( "read: FD mapped to {fd:?}" ) ;
@@ -496,7 +497,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
496497 let Ok ( offset) = u64:: try_from ( offset) else {
497498 let einval = this. eval_libc ( "EINVAL" ) ;
498499 this. set_last_error ( einval) ?;
499- return Ok ( - 1 ) ;
500+ return Ok ( Scalar :: from_target_isize ( - 1 , this ) ) ;
500501 } ;
501502 fd. borrow_mut ( ) . pread ( communicate, & mut bytes, offset, this)
502503 }
@@ -513,11 +514,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
513514 buf,
514515 bytes[ ..usize:: try_from ( read_bytes) . unwrap ( ) ] . iter ( ) . copied ( ) ,
515516 ) ?;
516- Ok ( read_bytes)
517+ Ok ( Scalar :: from_target_isize ( read_bytes, this ) )
517518 }
518519 Err ( e) => {
519520 this. set_last_error_from_io_error ( e) ?;
520- Ok ( - 1 )
521+ Ok ( Scalar :: from_target_isize ( - 1 , this ) )
521522 }
522523 }
523524 }
@@ -528,7 +529,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
528529 buf : Pointer ,
529530 count : u64 ,
530531 offset : Option < i128 > ,
531- ) -> InterpResult < ' tcx , i64 > {
532+ ) -> InterpResult < ' tcx , Scalar > {
532533 let this = self . eval_context_mut ( ) ;
533534
534535 // Isolation check is done via `FileDescriptor` trait.
@@ -546,7 +547,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
546547 let bytes = this. read_bytes_ptr_strip_provenance ( buf, Size :: from_bytes ( count) ) ?. to_owned ( ) ;
547548 // We temporarily dup the FD to be able to retain mutable access to `this`.
548549 let Some ( fd) = this. machine . fds . dup ( fd) else {
549- return this. fd_not_found ( ) ;
550+ return Ok ( Scalar :: from_target_isize ( this. fd_not_found ( ) ? , this ) ) ;
550551 } ;
551552
552553 let result = match offset {
@@ -555,15 +556,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
555556 let Ok ( offset) = u64:: try_from ( offset) else {
556557 let einval = this. eval_libc ( "EINVAL" ) ;
557558 this. set_last_error ( einval) ?;
558- return Ok ( - 1 ) ;
559+ return Ok ( Scalar :: from_target_isize ( - 1 , this ) ) ;
559560 } ;
560561 fd. borrow_mut ( ) . pwrite ( communicate, & bytes, offset, this)
561562 }
562563 } ;
563564 drop ( fd) ;
564565
565566 let result = result?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
566- this. try_unwrap_io_result ( result)
567+ Ok ( Scalar :: from_target_isize ( this. try_unwrap_io_result ( result) ? , this ) )
567568 }
568569}
569570
0 commit comments