mirror of
https://github.com/Noratrieb/portability.git
synced 2026-01-14 15:55:04 +01:00
static TLS works for the main exe!!
This commit is contained in:
parent
5c284548bd
commit
a6de0298f2
7 changed files with 214 additions and 30 deletions
26
test/example_exe_tls_crt.rs
Normal file
26
test/example_exe_tls_crt.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#![feature(thread_local)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[panic_handler]
|
||||
fn handle_panic(_: &core::panic::PanicInfo<'_>) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[thread_local]
|
||||
static mut A_THREAD_LOCAL: u32 = 50;
|
||||
#[thread_local]
|
||||
static mut ANOTHER_THREAD_LOCAL: u32 = 55;
|
||||
|
||||
#[inline(never)]
|
||||
fn set_tls(value: u32) {
|
||||
unsafe { A_THREAD_LOCAL = value; }
|
||||
unsafe { ANOTHER_THREAD_LOCAL = value; }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "stdcall" fn main() -> u32 {
|
||||
// Use some indirection to actually force TLS to happen
|
||||
set_tls(14);
|
||||
unsafe { A_THREAD_LOCAL + ANOTHER_THREAD_LOCAL }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue