@@ -1668,53 +1668,51 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1668
1668
fn chmod ( & mut self , path_op : & OpTy < ' tcx > , perm_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
1669
1669
let this = self . eval_context_mut ( ) ;
1670
1670
1671
- // Permissions::from_mode is Unix-specific.
1672
- this. assert_target_os_is_unix ( "chmod" ) ;
1671
+ let pathname = this. read_path_from_c_str ( this. read_pointer ( path_op) ?) ?;
1672
+ let perm = this. read_scalar ( perm_op) ?. to_uint ( this. libc_ty_layout ( "mode_t" ) . size ) ?;
1673
+
1674
+ // Reject if isolation is enabled.
1675
+ if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1676
+ this. reject_in_isolation ( "`chmod`" , reject_with) ?;
1677
+ return this. set_last_error_and_return_i32 ( LibcError ( "EACCES" ) ) ;
1678
+ }
1673
1679
1680
+ // Permissions::from_mode is Unix-specific.
1674
1681
#[ cfg( unix) ]
1675
1682
{
1676
1683
use std:: os:: unix:: fs:: PermissionsExt ;
1677
1684
1678
- let pathname = this. read_path_from_c_str ( this. read_pointer ( path_op) ?) ?;
1679
- let perm = this. read_scalar ( perm_op) ?. to_u32 ( ) ?;
1680
-
1681
- // Reject if isolation is enabled.
1682
- if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1683
- this. reject_in_isolation ( "`chmod`" , reject_with) ?;
1684
- return this. set_last_error_and_return_i32 ( LibcError ( "EACCES" ) ) ;
1685
- }
1686
-
1687
- let result = std:: fs:: set_permissions ( pathname, Permissions :: from_mode ( perm) ) ;
1685
+ let result = std:: fs:: set_permissions (
1686
+ pathname,
1687
+ Permissions :: from_mode ( perm. try_into ( ) . unwrap ( ) ) ,
1688
+ ) ;
1688
1689
let result = this. try_unwrap_io_result ( result. map ( |_| 0i32 ) ) ?;
1689
1690
1690
1691
interp_ok ( Scalar :: from_i32 ( result) )
1691
1692
}
1692
1693
#[ cfg( not( unix) ) ]
1693
1694
{
1694
- unreachable ! ( )
1695
+ throw_unsup_format ! ( "`chmod` is not supported on this platform" )
1695
1696
}
1696
1697
}
1697
1698
1698
1699
fn fchmod ( & mut self , fd_op : & OpTy < ' tcx > , perm_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
1699
1700
let this = self . eval_context_mut ( ) ;
1700
1701
1701
- // `Permissions::from_mode` is Unix-specific.
1702
- this. assert_target_os_is_unix ( "fchmod" ) ;
1702
+ let fd = this . read_scalar ( fd_op ) ? . to_i32 ( ) ? ;
1703
+ let perm = this. read_scalar ( perm_op ) ? . to_uint ( this . libc_ty_layout ( "mode_t" ) . size ) ? ;
1703
1704
1705
+ // Reject if isolation is enabled.
1706
+ if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1707
+ this. reject_in_isolation ( "`fchmod`" , reject_with) ?;
1708
+ // Set error code as "EBADF" (bad fd)
1709
+ return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
1710
+ }
1711
+ // `Permissions::from_mode` is Unix-specific.
1704
1712
#[ cfg( unix) ]
1705
1713
{
1706
1714
use std:: os:: unix:: fs:: PermissionsExt ;
1707
1715
1708
- let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
1709
- let perm = this. read_scalar ( perm_op) ?. to_u32 ( ) ?;
1710
-
1711
- // Reject if isolation is enabled.
1712
- if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1713
- this. reject_in_isolation ( "`fchmod`" , reject_with) ?;
1714
- // Set error code as "EBADF" (bad fd)
1715
- return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
1716
- }
1717
-
1718
1716
let Some ( fd) = this. machine . fds . get ( fd) else {
1719
1717
return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
1720
1718
} ;
@@ -1723,14 +1721,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1723
1721
err_unsup_format ! ( "`fchmod` is only supported on file-backed file descriptors" )
1724
1722
} ) ?;
1725
1723
1726
- let result = file. file . set_permissions ( Permissions :: from_mode ( perm) ) ;
1724
+ let result =
1725
+ file. file . set_permissions ( Permissions :: from_mode ( perm. try_into ( ) . unwrap ( ) ) ) ;
1727
1726
let result = this. try_unwrap_io_result ( result. map ( |_| 0i32 ) ) ?;
1728
1727
1729
1728
interp_ok ( Scalar :: from_i32 ( result) )
1730
1729
}
1731
1730
#[ cfg( not( unix) ) ]
1732
1731
{
1733
- unreachable ! ( )
1732
+ throw_unsup_format ! ( "`fchmod` is not supported on this platform" )
1734
1733
}
1735
1734
}
1736
1735
}
0 commit comments