@@ -379,9 +379,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
379
379
&& cmd == this. eval_libc_i32 ( "F_FULLFSYNC" ) ?
380
380
{
381
381
let & [ _, _] = check_arg_count ( args) ?;
382
- if let Some ( FileHandle { file, writable : _ } ) = this. machine . file_handler . handles . get_mut ( & fd) {
383
- let result = file. sync_all ( ) ;
384
- this. try_unwrap_io_result ( result. map ( |_| 0i32 ) )
382
+ if let Some ( FileHandle { file, writable } ) = this. machine . file_handler . handles . get_mut ( & fd) {
383
+ if !* writable && cfg ! ( windows) {
384
+ // sync_all() will return an error on Windows hosts if the file is not opened
385
+ // for writing. (FlushFileBuffers requires that the file handle have the
386
+ // GENERIC_WRITE right)
387
+ Ok ( 0i32 )
388
+ } else {
389
+ let result = file. sync_all ( ) ;
390
+ this. try_unwrap_io_result ( result. map ( |_| 0i32 ) )
391
+ }
385
392
} else {
386
393
this. handle_not_found ( )
387
394
}
@@ -1128,6 +1135,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1128
1135
if let Some ( FileHandle { file, writable } ) = this. machine . file_handler . handles . get_mut ( & fd) {
1129
1136
if !* writable && cfg ! ( windows) {
1130
1137
// sync_all() will return an error on Windows hosts if the file is not opened for writing.
1138
+ // (FlushFileBuffers requires that the file handle have the GENERIC_WRITE right)
1131
1139
Ok ( 0i32 )
1132
1140
} else {
1133
1141
let result = file. sync_all ( ) ;
@@ -1147,6 +1155,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1147
1155
if let Some ( FileHandle { file, writable } ) = this. machine . file_handler . handles . get_mut ( & fd) {
1148
1156
if !* writable && cfg ! ( windows) {
1149
1157
// sync_data() will return an error on Windows hosts if the file is not opened for writing.
1158
+ // (FlushFileBuffers requires that the file handle have the GENERIC_WRITE right)
1150
1159
Ok ( 0i32 )
1151
1160
} else {
1152
1161
let result = file. sync_data ( ) ;
@@ -1187,11 +1196,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1187
1196
return Ok ( -1 ) ;
1188
1197
}
1189
1198
1190
- if let Some ( FileHandle { file, writable : _ } ) = this. machine . file_handler . handles . get_mut ( & fd) {
1191
- // In the interest of host compatibility, we conservatively ignore
1192
- // offset, nbytes, and flags, and sync the entire file.
1193
- let result = file. sync_data ( ) ;
1194
- this. try_unwrap_io_result ( result. map ( |_| 0i32 ) )
1199
+ if let Some ( FileHandle { file, writable } ) = this. machine . file_handler . handles . get_mut ( & fd) {
1200
+ if !* writable && cfg ! ( windows) {
1201
+ // sync_data() will return an error on Windows hosts if the file is not opened for
1202
+ // writing. (FlushFileBuffers requires that the file handle have the GENERIC_WRITE
1203
+ // right)
1204
+ Ok ( 0i32 )
1205
+ } else {
1206
+ // In the interest of host compatibility, we conservatively ignore
1207
+ // offset, nbytes, and flags, and sync the entire file.
1208
+ let result = file. sync_data ( ) ;
1209
+ this. try_unwrap_io_result ( result. map ( |_| 0i32 ) )
1210
+ }
1195
1211
} else {
1196
1212
this. handle_not_found ( )
1197
1213
}
0 commit comments