@@ -310,20 +310,20 @@ impl FdTable {
310
310
311
311
impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
312
312
pub 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 > {
314
314
let this = self . eval_context_mut ( ) ;
315
315
316
316
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 ( ) ? ) ) ;
318
318
} ;
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 ) ) )
320
320
}
321
321
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 > {
323
323
let this = self . eval_context_mut ( ) ;
324
324
325
325
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 ( ) ? ) ) ;
327
327
} ;
328
328
if new_fd != old_fd {
329
329
// Close new_fd if it is previously opened.
@@ -333,7 +333,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
333
333
file_description. close ( this. machine . communicate ( ) ) ?. ok ( ) ;
334
334
}
335
335
}
336
- Ok ( new_fd)
336
+ Ok ( Scalar :: from_i32 ( new_fd) )
337
337
}
338
338
339
339
fn flock ( & mut self , fd : i32 , op : i32 ) -> InterpResult < ' tcx , Scalar > {
@@ -370,7 +370,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
370
370
Ok ( Scalar :: from_i32 ( this. try_unwrap_io_result ( result) ?) )
371
371
}
372
372
373
- fn fcntl ( & mut self , args : & [ OpTy < ' tcx > ] ) -> InterpResult < ' tcx , i32 > {
373
+ fn fcntl ( & mut self , args : & [ OpTy < ' tcx > ] ) -> InterpResult < ' tcx , Scalar > {
374
374
let this = self . eval_context_mut ( ) ;
375
375
376
376
if args. len ( ) < 2 {
@@ -388,11 +388,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
388
388
// `FD_CLOEXEC` value without checking if the flag is set for the file because `std`
389
389
// always sets this flag when opening a file. However we still need to check that the
390
390
// 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" )
393
393
} else {
394
- this. fd_not_found ( )
395
- }
394
+ this. fd_not_found ( ) ?
395
+ } ) )
396
396
} else if cmd == this. eval_libc_i32 ( "F_DUPFD" )
397
397
|| cmd == this. eval_libc_i32 ( "F_DUPFD_CLOEXEC" )
398
398
{
@@ -409,15 +409,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
409
409
let start = this. read_scalar ( & args[ 2 ] ) ?. to_i32 ( ) ?;
410
410
411
411
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 ( ) ?) ) ,
414
415
}
415
416
} else if this. tcx . sess . target . os == "macos" && cmd == this. eval_libc_i32 ( "F_FULLFSYNC" ) {
416
417
// Reject if isolation is enabled.
417
418
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
418
419
this. reject_in_isolation ( "`fcntl`" , reject_with) ?;
419
420
this. set_last_error_from_io_error ( ErrorKind :: PermissionDenied . into ( ) ) ?;
420
- return Ok ( - 1 ) ;
421
+ return Ok ( Scalar :: from_i32 ( - 1 ) ) ;
421
422
}
422
423
423
424
this. ffullsync_fd ( fd)
@@ -462,7 +463,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
462
463
buf : Pointer ,
463
464
count : u64 ,
464
465
offset : Option < i128 > ,
465
- ) -> InterpResult < ' tcx , i64 > {
466
+ ) -> InterpResult < ' tcx , Scalar > {
466
467
let this = self . eval_context_mut ( ) ;
467
468
468
469
// Isolation check is done via `FileDescriptor` trait.
@@ -482,7 +483,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
482
483
// We temporarily dup the FD to be able to retain mutable access to `this`.
483
484
let Some ( fd) = this. machine . fds . dup ( fd) else {
484
485
trace ! ( "read: FD not found" ) ;
485
- return this. fd_not_found ( ) ;
486
+ return Ok ( Scalar :: from_target_isize ( this. fd_not_found ( ) ? , this ) ) ;
486
487
} ;
487
488
488
489
trace ! ( "read: FD mapped to {fd:?}" ) ;
@@ -496,7 +497,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
496
497
let Ok ( offset) = u64:: try_from ( offset) else {
497
498
let einval = this. eval_libc ( "EINVAL" ) ;
498
499
this. set_last_error ( einval) ?;
499
- return Ok ( - 1 ) ;
500
+ return Ok ( Scalar :: from_target_isize ( - 1 , this ) ) ;
500
501
} ;
501
502
fd. borrow_mut ( ) . pread ( communicate, & mut bytes, offset, this)
502
503
}
@@ -513,11 +514,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
513
514
buf,
514
515
bytes[ ..usize:: try_from ( read_bytes) . unwrap ( ) ] . iter ( ) . copied ( ) ,
515
516
) ?;
516
- Ok ( read_bytes)
517
+ Ok ( Scalar :: from_target_isize ( read_bytes, this ) )
517
518
}
518
519
Err ( e) => {
519
520
this. set_last_error_from_io_error ( e) ?;
520
- Ok ( - 1 )
521
+ Ok ( Scalar :: from_target_isize ( - 1 , this ) )
521
522
}
522
523
}
523
524
}
@@ -528,7 +529,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
528
529
buf : Pointer ,
529
530
count : u64 ,
530
531
offset : Option < i128 > ,
531
- ) -> InterpResult < ' tcx , i64 > {
532
+ ) -> InterpResult < ' tcx , Scalar > {
532
533
let this = self . eval_context_mut ( ) ;
533
534
534
535
// Isolation check is done via `FileDescriptor` trait.
@@ -546,7 +547,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
546
547
let bytes = this. read_bytes_ptr_strip_provenance ( buf, Size :: from_bytes ( count) ) ?. to_owned ( ) ;
547
548
// We temporarily dup the FD to be able to retain mutable access to `this`.
548
549
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 ) ) ;
550
551
} ;
551
552
552
553
let result = match offset {
@@ -555,15 +556,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
555
556
let Ok ( offset) = u64:: try_from ( offset) else {
556
557
let einval = this. eval_libc ( "EINVAL" ) ;
557
558
this. set_last_error ( einval) ?;
558
- return Ok ( - 1 ) ;
559
+ return Ok ( Scalar :: from_target_isize ( - 1 , this ) ) ;
559
560
} ;
560
561
fd. borrow_mut ( ) . pwrite ( communicate, & bytes, offset, this)
561
562
}
562
563
} ;
563
564
drop ( fd) ;
564
565
565
566
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 ) )
567
568
}
568
569
}
569
570
0 commit comments