@@ -229,6 +229,8 @@ impl FileDescription for FileHandle {
229
229
TRUE => Ok ( ( ) ) ,
230
230
FALSE => {
231
231
let mut err = io:: Error :: last_os_error ( ) ;
232
+ // This only runs on Windows hosts so we can use `raw_os_error`.
233
+ // We have to be careful not to forward that error code to target code.
232
234
let code: u32 = err. raw_os_error ( ) . unwrap ( ) . try_into ( ) . unwrap ( ) ;
233
235
if matches ! ( code, ERROR_IO_PENDING | ERROR_LOCK_VIOLATION ) {
234
236
if lock_nb {
@@ -337,15 +339,7 @@ trait EvalContextExtPrivate<'tcx>: crate::MiriInterpCxExt<'tcx> {
337
339
_ => interp_ok ( this. eval_libc ( "DT_UNKNOWN" ) . to_u8 ( ) ?. into ( ) ) ,
338
340
}
339
341
}
340
- Err ( e) =>
341
- match e. raw_os_error ( ) {
342
- Some ( error) => interp_ok ( error) ,
343
- None =>
344
- throw_unsup_format ! (
345
- "the error {} couldn't be converted to a return value" ,
346
- e
347
- ) ,
348
- } ,
342
+ Err ( e) => this. io_error_to_errnum ( e) ?. to_i32 ( ) ,
349
343
}
350
344
}
351
345
}
@@ -1137,7 +1131,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1137
1131
let open_dir = this. machine . dirs . streams . get_mut ( & dirp) . ok_or_else ( || {
1138
1132
err_unsup_format ! ( "the DIR pointer passed to readdir_r did not come from opendir" )
1139
1133
} ) ?;
1140
- interp_ok ( Scalar :: from_i32 ( match open_dir. read_dir . next ( ) {
1134
+ interp_ok ( match open_dir. read_dir . next ( ) {
1141
1135
Some ( Ok ( dir_entry) ) => {
1142
1136
// Write into entry, write pointer to result, return 0 on success.
1143
1137
// The name is written with write_os_str_to_c_str, while the rest of the
@@ -1215,25 +1209,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1215
1209
let result_place = this. deref_pointer ( result_op) ?;
1216
1210
this. write_scalar ( this. read_scalar ( entry_op) ?, & result_place) ?;
1217
1211
1218
- 0
1212
+ Scalar :: from_i32 ( 0 )
1219
1213
}
1220
1214
None => {
1221
1215
// end of stream: return 0, assign *result=NULL
1222
1216
this. write_null ( & this. deref_pointer ( result_op) ?) ?;
1223
- 0
1217
+ Scalar :: from_i32 ( 0 )
1224
1218
}
1225
- Some ( Err ( e) ) =>
1226
- match e. raw_os_error ( ) {
1227
- // return positive error number on error
1228
- Some ( error) => error,
1229
- None => {
1230
- throw_unsup_format ! (
1231
- "the error {} couldn't be converted to a return value" ,
1232
- e
1233
- )
1234
- }
1235
- } ,
1236
- } ) )
1219
+ Some ( Err ( e) ) => {
1220
+ // return positive error number on error (do *not* set last error)
1221
+ this. io_error_to_errnum ( e) ?
1222
+ }
1223
+ } )
1237
1224
}
1238
1225
1239
1226
fn closedir ( & mut self , dirp_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
0 commit comments