@@ -44,14 +44,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
44
44
45
45
let mut options = OpenOptions :: new ( ) ;
46
46
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
48
58
let access_mode = flag & 0b11 ;
49
59
50
- if access_mode == this . eval_libc_i32 ( "O_RDONLY" ) ? {
60
+ if access_mode == o_rdonly {
51
61
options. read ( true ) ;
52
- } else if access_mode == this . eval_libc_i32 ( "O_WRONLY" ) ? {
62
+ } else if access_mode == o_wronly {
53
63
options. write ( true ) ;
54
- } else if access_mode == this . eval_libc_i32 ( "O_RDWR" ) ? {
64
+ } else if access_mode == o_rdwr {
55
65
options. read ( true ) . write ( true ) ;
56
66
} else {
57
67
throw_unsup_format ! ( "Unsupported access mode {:#x}" , access_mode) ;
0 commit comments