88#![ feature( core_intrinsics) ]
99#![ feature( thread_local) ]
1010#![ feature( strict_provenance) ]
11- #![ feature( const_mut_refs) ]
1211
1312extern crate alloc;
1413extern crate compiler_builtins;
1514
1615use alloc:: boxed:: Box ;
1716use atomic_dbg:: dbg;
17+ use core:: cell:: UnsafeCell ;
1818use core:: arch:: asm;
1919use core:: ptr:: { addr_of_mut, without_provenance_mut} ;
2020use origin:: { program, thread} ;
@@ -37,7 +37,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
3737 check_eq ( TEST_DATA . 0 ) ;
3838
3939 // Mutate one of the TLS fields.
40- THREAD_LOCAL [ 1 ] = without_provenance_mut ( 77 ) ;
40+ ( * THREAD_LOCAL . get ( ) ) [ 1 ] = without_provenance_mut ( 77 ) ;
4141
4242 // Assert that the mutation happened properly.
4343 check_eq ( [ TEST_DATA . 0 [ 0 ] , without_provenance_mut ( 77 ) , TEST_DATA . 0 [ 2 ] ] ) ;
@@ -48,14 +48,14 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
4848 check_eq ( [ TEST_DATA . 0 [ 0 ] , without_provenance_mut ( 79 ) , TEST_DATA . 0 [ 2 ] ] ) ;
4949
5050 // Mutate one of the TLS fields.
51- THREAD_LOCAL [ 1 ] = without_provenance_mut ( 80 ) ;
51+ ( * THREAD_LOCAL . get ( ) ) [ 1 ] = without_provenance_mut ( 80 ) ;
5252 } ) ) ;
5353 thread:: at_exit ( Box :: new ( || {
5454 // Assert that we see the value stored at the end of `main`.
5555 check_eq ( [ TEST_DATA . 0 [ 0 ] , without_provenance_mut ( 78 ) , TEST_DATA . 0 [ 2 ] ] ) ;
5656
5757 // Mutate one of the TLS fields.
58- THREAD_LOCAL [ 1 ] = without_provenance_mut ( 79 ) ;
58+ ( * THREAD_LOCAL . get ( ) ) [ 1 ] = without_provenance_mut ( 79 ) ;
5959 } ) ) ;
6060
6161 let thread = thread:: create (
@@ -64,7 +64,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
6464 check_eq ( TEST_DATA . 0 ) ;
6565
6666 // Mutate one of the TLS fields.
67- THREAD_LOCAL [ 1 ] = without_provenance_mut ( 175 ) ;
67+ ( * THREAD_LOCAL . get ( ) ) [ 1 ] = without_provenance_mut ( 175 ) ;
6868
6969 // Assert that the mutation happened properly.
7070 check_eq ( [ TEST_DATA . 0 [ 0 ] , without_provenance_mut ( 175 ) , TEST_DATA . 0 [ 2 ] ] ) ;
@@ -88,7 +88,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
8888 check_eq ( [ TEST_DATA . 0 [ 0 ] , without_provenance_mut ( 77 ) , TEST_DATA . 0 [ 2 ] ] ) ;
8989
9090 // Mutate one of the TLS fields.
91- THREAD_LOCAL [ 1 ] = without_provenance_mut ( 78 ) ;
91+ ( * THREAD_LOCAL . get ( ) ) [ 1 ] = without_provenance_mut ( 78 ) ;
9292
9393 // Assert that the mutation happened properly.
9494 check_eq ( [ TEST_DATA . 0 [ 0 ] , without_provenance_mut ( 78 ) , TEST_DATA . 0 [ 2 ] ] ) ;
@@ -107,7 +107,7 @@ static TEST_DATA: SyncTestData = {
107107} ;
108108
109109#[ thread_local]
110- static mut THREAD_LOCAL : [ * const u32 ; 3 ] = TEST_DATA . 0 ;
110+ static THREAD_LOCAL : UnsafeCell < [ * const u32 ; 3 ] > = UnsafeCell :: new ( TEST_DATA . 0 ) ;
111111
112112// Some variables to point to.
113113static mut SOME_REGULAR_DATA : u32 = 909 ;
@@ -116,11 +116,11 @@ static mut SOME_ZERO_DATA: u32 = 0;
116116fn check_eq ( data : [ * const u32 ; 3 ] ) {
117117 unsafe {
118118 // Check `THREAD_LOCAL` using a static address.
119- asm ! ( "# {}" , in( reg) THREAD_LOCAL . as_mut_ptr( ) , options( nostack, preserves_flags) ) ;
120- assert_eq ! ( THREAD_LOCAL , data) ;
119+ asm ! ( "# {}" , in( reg) ( * THREAD_LOCAL . get ( ) ) . as_mut_ptr( ) , options( nostack, preserves_flags) ) ;
120+ assert_eq ! ( * THREAD_LOCAL . get ( ) , data) ;
121121
122122 // Check `THREAD_LOCAL` using a dynamic address.
123- let mut thread_local_addr: * mut [ * const u32 ; 3 ] = addr_of_mut ! ( THREAD_LOCAL ) ;
123+ let mut thread_local_addr: * mut [ * const u32 ; 3 ] = THREAD_LOCAL . get ( ) ;
124124 asm ! ( "# {}" , inout( reg) thread_local_addr, options( pure, nomem, nostack, preserves_flags) ) ;
125125 assert_eq ! ( * thread_local_addr, data) ;
126126 }
0 commit comments