@@ -50,7 +50,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5050 . memory
5151 . allocate ( Size :: from_bytes ( size) , align, kind. into ( ) ) ;
5252 if zero_init {
53- // We just allocated this, the access cannot fail
53+ // We just allocated this, the access is definitely in-bounds.
5454 this. memory
5555 . get_mut ( ptr. alloc_id )
5656 . unwrap ( )
@@ -227,7 +227,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
227227 Align :: from_bytes ( align) . unwrap ( ) ,
228228 MiriMemoryKind :: Rust . into ( ) ,
229229 ) ;
230- // We just allocated this, the access cannot fail
230+ // We just allocated this, the access is definitely in-bounds.
231231 this. memory
232232 . get_mut ( ptr. alloc_id )
233233 . unwrap ( )
@@ -349,10 +349,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
349349 let arg_dest = this. local_place ( arg_local) ?;
350350 this. write_scalar ( data, arg_dest) ?;
351351
352- assert ! (
353- args. next( ) . is_none( ) ,
354- "__rust_maybe_catch_panic argument has more arguments than expected"
355- ) ;
352+ args. next ( ) . expect_none ( "__rust_maybe_catch_panic argument has more arguments than expected" ) ;
356353
357354 // We ourselves will return `0`, eventually (because we will not return if we paniced).
358355 this. write_null ( dest) ?;
@@ -417,8 +414,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
417414 }
418415
419416 "__errno_location" | "__error" => {
420- let errno_scalar : Scalar < Tag > = this. machine . last_error . unwrap ( ) . into ( ) ;
421- this. write_scalar ( errno_scalar , dest) ?;
417+ let errno_place = this. machine . last_error . unwrap ( ) ;
418+ this. write_scalar ( errno_place . to_ref ( ) . to_scalar ( ) ? , dest) ?;
422419 }
423420
424421 "getenv" => {
@@ -643,7 +640,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
643640
644641 // Hook pthread calls that go to the thread-local storage memory subsystem.
645642 "pthread_key_create" => {
646- let key_ptr = this. read_scalar ( args[ 0 ] ) ? . not_undef ( ) ?;
643+ let key_place = this. deref_operand ( args[ 0 ] ) ?;
647644
648645 // Extract the function type out of the signature (that seems easier than constructing it ourselves).
649646 let dtor = match this. test_null ( this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?) ? {
@@ -668,16 +665,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
668665 throw_unsup ! ( OutOfTls ) ;
669666 }
670667
671- let key_ptr = this
672- . memory
673- . check_ptr_access ( key_ptr, key_layout. size , key_layout. align . abi ) ?
674- . expect ( "cannot be a ZST" ) ;
675- this. memory . get_mut ( key_ptr. alloc_id ) ?. write_scalar (
676- tcx,
677- key_ptr,
678- Scalar :: from_uint ( key, key_layout. size ) . into ( ) ,
679- key_layout. size ,
680- ) ?;
668+ this. write_scalar ( Scalar :: from_uint ( key, key_layout. size ) , key_place. into ( ) ) ?;
681669
682670 // Return success (`0`).
683671 this. write_null ( dest) ?;
@@ -856,6 +844,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
856844 let system_info_ptr = this
857845 . check_mplace_access ( system_info, None ) ?
858846 . expect ( "cannot be a ZST" ) ;
847+ // We rely on `deref_operand` doing bounds checks for us.
859848 // Initialize with `0`.
860849 this. memory
861850 . get_mut ( system_info_ptr. alloc_id ) ?
@@ -988,33 +977,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
988977 }
989978 return Ok ( None ) ;
990979 }
991-
992- fn set_last_error ( & mut self , scalar : Scalar < Tag > ) -> InterpResult < ' tcx > {
993- let this = self . eval_context_mut ( ) ;
994- let errno_ptr = this. machine . last_error . unwrap ( ) ;
995- this. memory . get_mut ( errno_ptr. alloc_id ) ?. write_scalar (
996- & * this. tcx ,
997- errno_ptr,
998- scalar. into ( ) ,
999- Size :: from_bits ( 32 ) ,
1000- )
1001- }
1002-
1003- fn get_last_error ( & mut self ) -> InterpResult < ' tcx , Scalar < Tag > > {
1004- let this = self . eval_context_mut ( ) ;
1005- let errno_ptr = this. machine . last_error . unwrap ( ) ;
1006- this. memory
1007- . get ( errno_ptr. alloc_id ) ?
1008- . read_scalar ( & * this. tcx , errno_ptr, Size :: from_bits ( 32 ) ) ?
1009- . not_undef ( )
1010- }
1011-
1012- fn consume_io_error ( & mut self , e : std:: io:: Error ) -> InterpResult < ' tcx > {
1013- self . eval_context_mut ( ) . set_last_error ( Scalar :: from_int (
1014- e. raw_os_error ( ) . unwrap ( ) ,
1015- Size :: from_bits ( 32 ) ,
1016- ) )
1017- }
1018980}
1019981
1020982// Shims the linux 'getrandom()' syscall.
0 commit comments