@@ -15,6 +15,7 @@ use shims::time::system_time_to_duration;
15
15
#[ derive( Debug ) ]
16
16
pub struct FileHandle {
17
17
file : File ,
18
+ read_only : bool ,
18
19
}
19
20
20
21
pub struct FileHandler {
@@ -56,10 +57,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
56
57
if ( o_rdonly | o_wronly | o_rdwr) & !0b11 != 0 {
57
58
throw_unsup_format ! ( "Access mode flags on this platform are unsupported" ) ;
58
59
}
60
+ let mut read_only = false ;
61
+
59
62
// Now we check the access mode
60
63
let access_mode = flag & 0b11 ;
61
64
62
65
if access_mode == o_rdonly {
66
+ read_only = true ;
63
67
options. read ( true ) ;
64
68
} else if access_mode == o_wronly {
65
69
options. write ( true ) ;
@@ -105,7 +109,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
105
109
let fd = options. open ( & path) . map ( |file| {
106
110
let mut fh = & mut this. machine . file_handler ;
107
111
fh. low += 1 ;
108
- fh. handles . insert ( fh. low , FileHandle { file } ) . unwrap_none ( ) ;
112
+ fh. handles . insert ( fh. low , FileHandle { file, read_only } ) . unwrap_none ( ) ;
109
113
fh. low
110
114
} ) ;
111
115
@@ -148,6 +152,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
148
152
let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
149
153
150
154
if let Some ( handle) = this. machine . file_handler . handles . remove ( & fd) {
155
+ if handle. read_only {
156
+ return Ok ( 0 ) ;
157
+ }
151
158
// `File::sync_all` does the checks that are done when closing a file. We do this to
152
159
// to handle possible errors correctly.
153
160
let result = this. try_unwrap_io_result ( handle. file . sync_all ( ) . map ( |_| 0i32 ) ) ;
0 commit comments