@@ -44,14 +44,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4444
4545 let mut options = OpenOptions :: new ( ) ;
4646
47- // The first two bits of the flag correspond to the access mode of the file in linux.
47+ let o_rdonly = this. eval_libc_i32 ( "O_RDONLY" ) ?;
48+ let o_wronly = this. eval_libc_i32 ( "O_WRONLY" ) ?;
49+ let o_rdwr = this. eval_libc_i32 ( "O_RDWR" ) ?;
50+ // The first two bits of the flag correspond to the access mode in linux, macOS and
51+ // windows. We need to check that in fact the access mode flags for the current platform
52+ // only use these two bits, otherwise we are in an unsupported platform and should error.
53+ if o_rdonly | o_wronly | o_rdwr & !0b11 == 0 {
54+ println ! ( "{} {} {}" , o_rdonly, o_wronly, o_rdwr) ;
55+ throw_unsup_format ! ( "Access mode flags on this platform are unsupported" ) ;
56+ }
57+ // Now we check the access mode
4858 let access_mode = flag & 0b11 ;
4959
50- if access_mode == this . eval_libc_i32 ( "O_RDONLY" ) ? {
60+ if access_mode == o_rdonly {
5161 options. read ( true ) ;
52- } else if access_mode == this . eval_libc_i32 ( "O_WRONLY" ) ? {
62+ } else if access_mode == o_wronly {
5363 options. write ( true ) ;
54- } else if access_mode == this . eval_libc_i32 ( "O_RDWR" ) ? {
64+ } else if access_mode == o_rdwr {
5565 options. read ( true ) . write ( true ) ;
5666 } else {
5767 throw_unsup_format ! ( "Unsupported access mode {:#x}" , access_mode) ;
0 commit comments