@@ -49,7 +49,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4949 ptr : Scalar < Tag > ,
5050 ) -> InterpResult < ' tcx > {
5151 let this = self . eval_context_mut ( ) ;
52- if !ptr . is_null_ptr ( this ) {
52+ if !this . is_null ( ptr ) ? {
5353 this. memory_mut ( ) . deallocate (
5454 ptr. to_ptr ( ) ?,
5555 None ,
@@ -66,7 +66,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6666 ) -> InterpResult < ' tcx , Scalar < Tag > > {
6767 let this = self . eval_context_mut ( ) ;
6868 let align = this. min_align ( ) ;
69- if old_ptr . is_null_ptr ( this ) {
69+ if this . is_null ( old_ptr ) ? {
7070 if new_size == 0 {
7171 Ok ( Scalar :: from_int ( 0 , this. pointer_size ( ) ) )
7272 } else {
@@ -427,7 +427,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
427427 let mut success = None ;
428428 {
429429 let name_ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
430- if !name_ptr . is_null_ptr ( this ) {
430+ if !this . is_null ( name_ptr ) ? {
431431 let name_ptr = name_ptr. to_ptr ( ) ?;
432432 let name = this
433433 . memory ( )
@@ -455,7 +455,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
455455 let name_ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
456456 let value_ptr = this. read_scalar ( args[ 1 ] ) ?. to_ptr ( ) ?;
457457 let value = this. memory ( ) . get ( value_ptr. alloc_id ) ?. read_c_str ( tcx, value_ptr) ?;
458- if !name_ptr . is_null_ptr ( this ) {
458+ if !this . is_null ( name_ptr ) ? {
459459 let name_ptr = name_ptr. to_ptr ( ) ?;
460460 let name = this. memory ( ) . get ( name_ptr. alloc_id ) ?. read_c_str ( tcx, name_ptr) ?;
461461 if !name. is_empty ( ) && !name. contains ( & b'=' ) {
@@ -638,14 +638,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
638638 let key_ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
639639
640640 // Extract the function type out of the signature (that seems easier than constructing it ourselves).
641- let dtor = match this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ? {
642- Scalar :: Ptr ( dtor_ptr) => Some ( this. memory ( ) . get_fn ( dtor_ptr) ?) ,
643- Scalar :: Raw { data : 0 , size } => {
644- // NULL pointer
645- assert_eq ! ( size as u64 , this. memory( ) . pointer_size( ) . bytes( ) ) ;
646- None
647- } ,
648- Scalar :: Raw { .. } => return err ! ( ReadBytesAsPointer ) ,
641+ let dtor = match this. test_null ( this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?) ? {
642+ Some ( dtor_ptr) => Some ( this. memory ( ) . get_fn ( dtor_ptr. to_ptr ( ) ?) ?) ,
643+ None => None ,
649644 } ;
650645
651646 // Figure out how large a pthread TLS key actually is.
@@ -657,7 +652,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
657652 let key_layout = this. layout_of ( key_type) ?;
658653
659654 // Create key and write it into the memory where `key_ptr` wants it.
660- let key = this. machine . tls . create_tls_key ( dtor, tcx ) as u128 ;
655+ let key = this. machine . tls . create_tls_key ( dtor) as u128 ;
661656 if key_layout. size . bits ( ) < 128 && key >= ( 1u128 << key_layout. size . bits ( ) as u128 ) {
662657 return err ! ( OutOfTls ) ;
663658 }
@@ -682,13 +677,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
682677 }
683678 "pthread_getspecific" => {
684679 let key = this. read_scalar ( args[ 0 ] ) ?. to_bits ( args[ 0 ] . layout . size ) ?;
685- let ptr = this. machine . tls . load_tls ( key) ?;
680+ let ptr = this. machine . tls . load_tls ( key, tcx ) ?;
686681 this. write_scalar ( ptr, dest) ?;
687682 }
688683 "pthread_setspecific" => {
689684 let key = this. read_scalar ( args[ 0 ] ) ?. to_bits ( args[ 0 ] . layout . size ) ?;
690685 let new_ptr = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
691- this. machine . tls . store_tls ( key, new_ptr) ?;
686+ this. machine . tls . store_tls ( key, this . test_null ( new_ptr) ? ) ?;
692687
693688 // Return success (`0`).
694689 this. write_null ( dest) ?;
@@ -842,7 +837,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
842837 // This just creates a key; Windows does not natively support TLS destructors.
843838
844839 // Create key and return it.
845- let key = this. machine . tls . create_tls_key ( None , tcx ) as u128 ;
840+ let key = this. machine . tls . create_tls_key ( None ) as u128 ;
846841
847842 // Figure out how large a TLS key actually is. This is `c::DWORD`.
848843 if dest. layout . size . bits ( ) < 128
@@ -853,13 +848,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
853848 }
854849 "TlsGetValue" => {
855850 let key = this. read_scalar ( args[ 0 ] ) ?. to_u32 ( ) ? as u128 ;
856- let ptr = this. machine . tls . load_tls ( key) ?;
851+ let ptr = this. machine . tls . load_tls ( key, tcx ) ?;
857852 this. write_scalar ( ptr, dest) ?;
858853 }
859854 "TlsSetValue" => {
860855 let key = this. read_scalar ( args[ 0 ] ) ?. to_u32 ( ) ? as u128 ;
861856 let new_ptr = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
862- this. machine . tls . store_tls ( key, new_ptr) ?;
857+ this. machine . tls . store_tls ( key, this . test_null ( new_ptr) ? ) ?;
863858
864859 // Return success (`1`).
865860 this. write_scalar ( Scalar :: from_int ( 1 , dest. layout . size ) , dest) ?;
@@ -936,10 +931,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
936931 Ok ( ( ) )
937932 }
938933
939- fn write_null ( & mut self , dest : PlaceTy < ' tcx , Tag > ) -> InterpResult < ' tcx > {
940- self . eval_context_mut ( ) . write_scalar ( Scalar :: from_int ( 0 , dest. layout . size ) , dest)
941- }
942-
943934 /// Evaluates the scalar at the specified path. Returns Some(val)
944935 /// if the path could be resolved, and None otherwise
945936 fn eval_path_scalar ( & mut self , path : & [ & str ] ) -> InterpResult < ' tcx , Option < ScalarMaybeUndef < Tag > > > {
0 commit comments