2
2
3
3
use std:: borrow:: Cow ;
4
4
use std:: fs:: {
5
- DirBuilder , File , FileType , Metadata , OpenOptions , Permissions , ReadDir , read_dir, remove_dir,
6
- remove_file , rename,
5
+ DirBuilder , File , FileType , Metadata , OpenOptions , ReadDir , read_dir, remove_dir, remove_file ,
6
+ rename,
7
7
} ;
8
8
use std:: io:: { self , ErrorKind , IsTerminal , Read , Seek , SeekFrom , Write } ;
9
9
use std:: path:: { Path , PathBuf } ;
@@ -1668,9 +1668,6 @@ 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
- 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
1671
// Reject if isolation is enabled.
1675
1672
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1676
1673
this. reject_in_isolation ( "`chmod`" , reject_with) ?;
@@ -1680,8 +1677,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1680
1677
// Permissions::from_mode is Unix-specific.
1681
1678
#[ cfg( unix) ]
1682
1679
{
1680
+ use std:: fs:: Permissions ;
1683
1681
use std:: os:: unix:: fs:: PermissionsExt ;
1684
1682
1683
+ let pathname = this. read_path_from_c_str ( this. read_pointer ( path_op) ?) ?;
1684
+ let perm = this. read_scalar ( perm_op) ?. to_uint ( this. libc_ty_layout ( "mode_t" ) . size ) ?;
1685
+
1685
1686
let result = std:: fs:: set_permissions (
1686
1687
pathname,
1687
1688
Permissions :: from_mode ( perm. try_into ( ) . unwrap ( ) ) ,
@@ -1692,27 +1693,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1692
1693
}
1693
1694
#[ cfg( not( unix) ) ]
1694
1695
{
1696
+ let ( _, _) = ( path_op, perm_op) ;
1695
1697
throw_unsup_format ! ( "`chmod` is not supported on this platform" )
1696
1698
}
1697
1699
}
1698
1700
1699
1701
fn fchmod ( & mut self , fd_op : & OpTy < ' tcx > , perm_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
1700
1702
let this = self . eval_context_mut ( ) ;
1701
1703
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 ) ?;
1704
-
1705
1704
// Reject if isolation is enabled.
1706
1705
if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
1707
1706
this. reject_in_isolation ( "`fchmod`" , reject_with) ?;
1708
1707
// Set error code as "EBADF" (bad fd)
1709
1708
return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
1710
1709
}
1710
+
1711
1711
// `Permissions::from_mode` is Unix-specific.
1712
1712
#[ cfg( unix) ]
1713
1713
{
1714
+ use std:: fs:: Permissions ;
1714
1715
use std:: os:: unix:: fs:: PermissionsExt ;
1715
1716
1717
+ let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
1718
+ let perm = this. read_scalar ( perm_op) ?. to_uint ( this. libc_ty_layout ( "mode_t" ) . size ) ?;
1719
+
1716
1720
let Some ( fd) = this. machine . fds . get ( fd) else {
1717
1721
return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
1718
1722
} ;
@@ -1729,6 +1733,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1729
1733
}
1730
1734
#[ cfg( not( unix) ) ]
1731
1735
{
1736
+ let ( _, _) = ( fd_op, perm_op) ;
1732
1737
throw_unsup_format ! ( "`fchmod` is not supported on this platform" )
1733
1738
}
1734
1739
}
0 commit comments