@@ -809,7 +809,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
809
809
810
810
this. check_no_isolation ( "mkdir" ) ?;
811
811
812
- let _mode = if this. tcx . sess . target . target . target_os . to_lowercase ( ) == "macos" {
812
+ let _mode = if this. tcx . sess . target . target . target_os . as_str ( ) == "macos" {
813
813
this. read_scalar ( mode_op) ?. not_undef ( ) ?. to_u16 ( ) ? as u32
814
814
} else {
815
815
this. read_scalar ( mode_op) ?. to_u32 ( ) ?
@@ -863,16 +863,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
863
863
// The libc API for opendir says that this method returns a pointer to an opaque
864
864
// structure, but we are returning an ID number. Thus, pass it as a scalar of
865
865
// pointer width.
866
- Ok ( Scalar :: from_int ( id, this. pointer_size ( ) ) )
866
+ Ok ( Scalar :: from_machine_usize ( id, this) )
867
867
}
868
868
Err ( e) => {
869
869
this. set_last_error_from_io_error ( e) ?;
870
- Ok ( Scalar :: from_int ( 0 , this. memory . pointer_size ( ) ) )
870
+ Ok ( Scalar :: from_machine_usize ( 0 , this) )
871
871
}
872
872
}
873
873
}
874
874
875
- fn readdir64_r (
875
+ fn linux_readdir64_r (
876
876
& mut self ,
877
877
dirp_op : OpTy < ' tcx , Tag > ,
878
878
entry_op : OpTy < ' tcx , Tag > ,
@@ -884,9 +884,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
884
884
885
885
let dirp = this. read_scalar ( dirp_op) ?. to_machine_usize ( this) ?;
886
886
887
- let entry_ptr = this. force_ptr ( this. read_scalar ( entry_op) ?. not_undef ( ) ?) ?;
888
- let dirent64_layout = this. libc_ty_layout ( "dirent64" ) ?;
889
-
890
887
let dir_iter = this. machine . dir_handler . streams . get_mut ( & dirp) . ok_or_else ( || {
891
888
err_unsup_format ! ( "The DIR pointer passed to readdir64_r did not come from opendir" )
892
889
} ) ?;
@@ -896,13 +893,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
896
893
// The name is written with write_os_str_to_c_str, while the rest of the
897
894
// dirent64 struct is written using write_packed_immediates.
898
895
896
+ // For reference:
897
+ // pub struct dirent64 {
898
+ // pub d_ino: ino64_t,
899
+ // pub d_off: off64_t,
900
+ // pub d_reclen: c_ushort,
901
+ // pub d_type: c_uchar,
902
+ // pub d_name: [c_char; 256],
903
+ // }
904
+
905
+ let entry_ptr = this. force_ptr ( this. read_scalar ( entry_op) ?. not_undef ( ) ?) ?;
906
+ let dirent64_layout = this. libc_ty_layout ( "dirent64" ) ?;
899
907
let name_offset = dirent64_layout. details . fields . offset ( 4 ) ;
900
908
let name_ptr = entry_ptr. offset ( name_offset, this) ?;
901
909
902
910
let file_name = dir_entry. file_name ( ) ;
903
911
let name_fits = this. write_os_str_to_c_str ( & file_name, Scalar :: Ptr ( name_ptr) , 256 ) ?;
904
912
if !name_fits {
905
- panic ! ( "A directory entry had a name too large to fit in libc::dirent64" ) ;
913
+ throw_unsup_format ! ( "A directory entry had a name too large to fit in libc::dirent64" ) ;
906
914
}
907
915
908
916
let entry_place = this. deref_operand ( entry_op) ?;
@@ -948,7 +956,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
948
956
}
949
957
}
950
958
951
- fn readdir_r (
959
+ fn macos_readdir_r (
952
960
& mut self ,
953
961
dirp_op : OpTy < ' tcx , Tag > ,
954
962
entry_op : OpTy < ' tcx , Tag > ,
@@ -960,8 +968,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
960
968
961
969
let dirp = this. read_scalar ( dirp_op) ?. to_machine_usize ( this) ?;
962
970
963
- let entry_ptr = this. force_ptr ( this. read_scalar ( entry_op) ?. not_undef ( ) ?) ?;
964
- let dirent_layout = this. libc_ty_layout ( "dirent" ) ?;
965
971
966
972
let dir_iter = this. machine . dir_handler . streams . get_mut ( & dirp) . ok_or_else ( || {
967
973
err_unsup_format ! ( "The DIR pointer passed to readdir_r did not come from opendir" )
@@ -972,13 +978,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
972
978
// The name is written with write_os_str_to_c_str, while the rest of the
973
979
// dirent struct is written using write_packed_Immediates.
974
980
981
+ // For reference:
982
+ // pub struct dirent {
983
+ // pub d_ino: u64,
984
+ // pub d_seekoff: u64,
985
+ // pub d_reclen: u16,
986
+ // pub d_namlen: u16,
987
+ // pub d_type: u8,
988
+ // pub d_name: [c_char; 1024],
989
+ // }
990
+
991
+ let entry_ptr = this. force_ptr ( this. read_scalar ( entry_op) ?. not_undef ( ) ?) ?;
992
+ let dirent_layout = this. libc_ty_layout ( "dirent" ) ?;
975
993
let name_offset = dirent_layout. details . fields . offset ( 5 ) ;
976
994
let name_ptr = entry_ptr. offset ( name_offset, this) ?;
977
995
978
996
let file_name = dir_entry. file_name ( ) ;
979
997
let name_fits = this. write_os_str_to_c_str ( & file_name, Scalar :: Ptr ( name_ptr) , 1024 ) ?;
980
998
if !name_fits {
981
- panic ! ( "A directory entry had a name too large to fit in libc::dirent" ) ;
999
+ throw_unsup_format ! ( "A directory entry had a name too large to fit in libc::dirent" ) ;
982
1000
}
983
1001
984
1002
let entry_place = this. deref_operand ( entry_op) ?;
0 commit comments