@@ -304,4 +304,39 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
304
304
fn eval_libc_i32 ( & mut self , name : & str ) -> InterpResult < ' tcx , i32 > {
305
305
self . eval_libc ( name) ?. to_i32 ( )
306
306
}
307
+
308
+ /// Sets the last error variable
309
+ fn set_last_error ( & mut self , scalar : Scalar < Tag > ) -> InterpResult < ' tcx > {
310
+ let this = self . eval_context_mut ( ) ;
311
+ let tcx = & { this. tcx . tcx } ;
312
+ let errno_ptr = this. machine . last_error . unwrap ( ) ;
313
+ this. memory_mut ( ) . get_mut ( errno_ptr. alloc_id ) ?. write_scalar (
314
+ tcx,
315
+ errno_ptr,
316
+ scalar. into ( ) ,
317
+ Size :: from_bits ( 32 ) ,
318
+ )
319
+ }
320
+
321
+ /// Gets the last error variable
322
+ fn get_last_error ( & mut self ) -> InterpResult < ' tcx , Scalar < Tag > > {
323
+ let this = self . eval_context_mut ( ) ;
324
+ let tcx = & { this. tcx . tcx } ;
325
+ let errno_ptr = this. machine . last_error . unwrap ( ) ;
326
+ this. memory ( )
327
+ . get ( errno_ptr. alloc_id ) ?
328
+ . read_scalar ( tcx, errno_ptr, Size :: from_bits ( 32 ) ) ?
329
+ . not_undef ( )
330
+ }
331
+
332
+ /// Sets the last error variable using a `std::io::Error`. It fails if the error cannot be
333
+ /// transformed to a raw os error succesfully
334
+ fn set_last_error_from_io_error ( & mut self , e : std:: io:: Error ) -> InterpResult < ' tcx > {
335
+ self . eval_context_mut ( ) . set_last_error ( Scalar :: from_int (
336
+ e. raw_os_error ( ) . ok_or_else ( || {
337
+ err_unsup_format ! ( "The {} error cannot be transformed into a raw os error" , e)
338
+ } ) ?,
339
+ Size :: from_bits ( 32 ) ,
340
+ ) )
341
+ }
307
342
}
0 commit comments