@@ -528,8 +528,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
528
528
let o_tmpfile = this. eval_libc_i32 ( "O_TMPFILE" ) ;
529
529
if flag & o_tmpfile == o_tmpfile {
530
530
// if the flag contains `O_TMPFILE` then we return a graceful error
531
- this. set_last_error ( LibcError ( "EOPNOTSUPP" ) ) ?;
532
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
531
+ return this. set_last_error_and_return_i32 ( LibcError ( "EOPNOTSUPP" ) ) ;
533
532
}
534
533
}
535
534
@@ -548,9 +547,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
548
547
// O_NOFOLLOW only fails when the trailing component is a symlink;
549
548
// the entire rest of the path can still contain symlinks.
550
549
if path. is_symlink ( ) {
551
- let eloop = this. eval_libc ( "ELOOP" ) ;
552
- this. set_last_error ( eloop) ?;
553
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
550
+ return this. set_last_error_and_return_i32 ( LibcError ( "ELOOP" ) ) ;
554
551
}
555
552
}
556
553
mirror |= o_nofollow;
@@ -565,8 +562,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
565
562
// Reject if isolation is enabled.
566
563
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
567
564
this. reject_in_isolation ( "`open`" , reject_with) ?;
568
- this. set_last_error ( ErrorKind :: PermissionDenied ) ?;
569
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
565
+ return this. set_last_error_and_return_i32 ( ErrorKind :: PermissionDenied ) ;
570
566
}
571
567
572
568
let fd = options
@@ -584,8 +580,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
584
580
let seek_from = if whence == this. eval_libc_i32 ( "SEEK_SET" ) {
585
581
if offset < 0 {
586
582
// Negative offsets return `EINVAL`.
587
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
588
- return interp_ok ( Scalar :: from_i64 ( -1 ) ) ;
583
+ return this. set_last_error_and_return_i64 ( LibcError ( "EINVAL" ) ) ;
589
584
} else {
590
585
SeekFrom :: Start ( u64:: try_from ( offset) . unwrap ( ) )
591
586
}
@@ -594,8 +589,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
594
589
} else if whence == this. eval_libc_i32 ( "SEEK_END" ) {
595
590
SeekFrom :: End ( i64:: try_from ( offset) . unwrap ( ) )
596
591
} else {
597
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
598
- return interp_ok ( Scalar :: from_i64 ( -1 ) ) ;
592
+ return this. set_last_error_and_return_i64 ( LibcError ( "EINVAL" ) ) ;
599
593
} ;
600
594
601
595
let communicate = this. machine . communicate ( ) ;
@@ -618,8 +612,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
618
612
// Reject if isolation is enabled.
619
613
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
620
614
this. reject_in_isolation ( "`unlink`" , reject_with) ?;
621
- this. set_last_error ( ErrorKind :: PermissionDenied ) ?;
622
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
615
+ return this. set_last_error_and_return_i32 ( ErrorKind :: PermissionDenied ) ;
623
616
}
624
617
625
618
let result = remove_file ( path) . map ( |_| 0 ) ;
@@ -649,8 +642,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
649
642
// Reject if isolation is enabled.
650
643
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
651
644
this. reject_in_isolation ( "`symlink`" , reject_with) ?;
652
- this. set_last_error ( ErrorKind :: PermissionDenied ) ?;
653
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
645
+ return this. set_last_error_and_return_i32 ( ErrorKind :: PermissionDenied ) ;
654
646
}
655
647
656
648
let result = create_link ( & target, & linkpath) . map ( |_| 0 ) ;
@@ -674,9 +666,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
674
666
// Reject if isolation is enabled.
675
667
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
676
668
this. reject_in_isolation ( "`stat`" , reject_with) ?;
677
- let eacc = this. eval_libc ( "EACCES" ) ;
678
- this. set_last_error ( eacc) ?;
679
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
669
+ return this. set_last_error_and_return_i32 ( LibcError ( "EACCES" ) ) ;
680
670
}
681
671
682
672
// `stat` always follows symlinks.
@@ -706,9 +696,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
706
696
// Reject if isolation is enabled.
707
697
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
708
698
this. reject_in_isolation ( "`lstat`" , reject_with) ?;
709
- let eacc = this. eval_libc ( "EACCES" ) ;
710
- this. set_last_error ( eacc) ?;
711
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
699
+ return this. set_last_error_and_return_i32 ( LibcError ( "EACCES" ) ) ;
712
700
}
713
701
714
702
let metadata = match FileMetadata :: from_path ( this, & path, false ) ? {
@@ -766,9 +754,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
766
754
767
755
// If the statxbuf or pathname pointers are null, the function fails with `EFAULT`.
768
756
if this. ptr_is_null ( statxbuf_ptr) ? || this. ptr_is_null ( pathname_ptr) ? {
769
- let efault = this. eval_libc ( "EFAULT" ) ;
770
- this. set_last_error ( efault) ?;
771
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
757
+ return this. set_last_error_and_return_i32 ( LibcError ( "EFAULT" ) ) ;
772
758
}
773
759
774
760
let statxbuf = this. deref_pointer_as ( statxbuf_op, this. libc_ty_layout ( "statx" ) ) ?;
@@ -809,8 +795,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
809
795
assert ! ( empty_path_flag) ;
810
796
this. eval_libc ( "EBADF" )
811
797
} ;
812
- this. set_last_error ( ecode) ?;
813
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
798
+ return this. set_last_error_and_return_i32 ( ecode) ;
814
799
}
815
800
816
801
// the `_mask_op` parameter specifies the file information that the caller requested.
@@ -939,9 +924,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
939
924
let newpath_ptr = this. read_pointer ( newpath_op) ?;
940
925
941
926
if this. ptr_is_null ( oldpath_ptr) ? || this. ptr_is_null ( newpath_ptr) ? {
942
- let efault = this. eval_libc ( "EFAULT" ) ;
943
- this. set_last_error ( efault) ?;
944
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
927
+ return this. set_last_error_and_return_i32 ( LibcError ( "EFAULT" ) ) ;
945
928
}
946
929
947
930
let oldpath = this. read_path_from_c_str ( oldpath_ptr) ?;
@@ -950,8 +933,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
950
933
// Reject if isolation is enabled.
951
934
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
952
935
this. reject_in_isolation ( "`rename`" , reject_with) ?;
953
- this. set_last_error ( ErrorKind :: PermissionDenied ) ?;
954
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
936
+ return this. set_last_error_and_return_i32 ( ErrorKind :: PermissionDenied ) ;
955
937
}
956
938
957
939
let result = rename ( oldpath, newpath) . map ( |_| 0 ) ;
@@ -974,8 +956,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
974
956
// Reject if isolation is enabled.
975
957
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
976
958
this. reject_in_isolation ( "`mkdir`" , reject_with) ?;
977
- this. set_last_error ( ErrorKind :: PermissionDenied ) ?;
978
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
959
+ return this. set_last_error_and_return_i32 ( ErrorKind :: PermissionDenied ) ;
979
960
}
980
961
981
962
#[ cfg_attr( not( unix) , allow( unused_mut) ) ]
@@ -1002,8 +983,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1002
983
// Reject if isolation is enabled.
1003
984
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1004
985
this. reject_in_isolation ( "`rmdir`" , reject_with) ?;
1005
- this. set_last_error ( ErrorKind :: PermissionDenied ) ?;
1006
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
986
+ return this. set_last_error_and_return_i32 ( ErrorKind :: PermissionDenied ) ;
1007
987
}
1008
988
1009
989
let result = remove_dir ( path) . map ( |_| 0i32 ) ;
@@ -1019,8 +999,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1019
999
// Reject if isolation is enabled.
1020
1000
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1021
1001
this. reject_in_isolation ( "`opendir`" , reject_with) ?;
1022
- let eacc = this. eval_libc ( "EACCES" ) ;
1023
- this. set_last_error ( eacc) ?;
1002
+ this. set_last_error ( LibcError ( "EACCES" ) ) ?;
1024
1003
return interp_ok ( Scalar :: null_ptr ( this) ) ;
1025
1004
}
1026
1005
@@ -1307,14 +1286,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1307
1286
interp_ok ( Scalar :: from_i32 ( result) )
1308
1287
} else {
1309
1288
drop ( fd) ;
1310
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
1311
- interp_ok ( Scalar :: from_i32 ( -1 ) )
1289
+ this. set_last_error_and_return_i32 ( LibcError ( "EINVAL" ) )
1312
1290
}
1313
1291
} else {
1314
1292
drop ( fd) ;
1315
1293
// The file is not writable
1316
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
1317
- interp_ok ( Scalar :: from_i32 ( -1 ) )
1294
+ this. set_last_error_and_return_i32 ( LibcError ( "EINVAL" ) )
1318
1295
}
1319
1296
}
1320
1297
@@ -1391,15 +1368,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1391
1368
let flags = this. read_scalar ( flags_op) ?. to_i32 ( ) ?;
1392
1369
1393
1370
if offset < 0 || nbytes < 0 {
1394
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
1395
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
1371
+ return this. set_last_error_and_return_i32 ( LibcError ( "EINVAL" ) ) ;
1396
1372
}
1397
1373
let allowed_flags = this. eval_libc_i32 ( "SYNC_FILE_RANGE_WAIT_BEFORE" )
1398
1374
| this. eval_libc_i32 ( "SYNC_FILE_RANGE_WRITE" )
1399
1375
| this. eval_libc_i32 ( "SYNC_FILE_RANGE_WAIT_AFTER" ) ;
1400
1376
if flags & allowed_flags != flags {
1401
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
1402
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
1377
+ return this. set_last_error_and_return_i32 ( LibcError ( "EINVAL" ) ) ;
1403
1378
}
1404
1379
1405
1380
// Reject if isolation is enabled.
@@ -1436,8 +1411,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1436
1411
// Reject if isolation is enabled.
1437
1412
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1438
1413
this. reject_in_isolation ( "`readlink`" , reject_with) ?;
1439
- let eacc = this. eval_libc ( "EACCES" ) ;
1440
- this. set_last_error ( eacc) ?;
1414
+ this. set_last_error ( LibcError ( "EACCES" ) ) ?;
1441
1415
return interp_ok ( -1 ) ;
1442
1416
}
1443
1417
@@ -1574,9 +1548,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1574
1548
// Reject if isolation is enabled.
1575
1549
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1576
1550
this. reject_in_isolation ( "`mkstemp`" , reject_with) ?;
1577
- let eacc = this. eval_libc ( "EACCES" ) ;
1578
- this. set_last_error ( eacc) ?;
1579
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
1551
+ return this. set_last_error_and_return_i32 ( LibcError ( "EACCES" ) ) ;
1580
1552
}
1581
1553
1582
1554
// Get the bytes of the suffix we expect in _target_ encoding.
@@ -1592,8 +1564,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1592
1564
1593
1565
// If we don't find the suffix, it is an error.
1594
1566
if last_six_char_bytes != suffix_bytes {
1595
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
1596
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
1567
+ return this. set_last_error_and_return_i32 ( LibcError ( "EINVAL" ) ) ;
1597
1568
}
1598
1569
1599
1570
// At this point we know we have 6 ASCII 'X' characters as a suffix.
@@ -1658,17 +1629,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1658
1629
_ => {
1659
1630
// "On error, -1 is returned, and errno is set to
1660
1631
// indicate the error"
1661
- this. set_last_error ( e) ?;
1662
- return interp_ok ( Scalar :: from_i32 ( -1 ) ) ;
1632
+ return this. set_last_error_and_return_i32 ( e) ;
1663
1633
}
1664
1634
} ,
1665
1635
}
1666
1636
}
1667
1637
1668
1638
// We ran out of attempts to create the file, return an error.
1669
- let eexist = this. eval_libc ( "EEXIST" ) ;
1670
- this. set_last_error ( eexist) ?;
1671
- interp_ok ( Scalar :: from_i32 ( -1 ) )
1639
+ this. set_last_error_and_return_i32 ( LibcError ( "EEXIST" ) )
1672
1640
}
1673
1641
}
1674
1642
0 commit comments