std/sys/pal/sgx/abi/thread.rs
1use fortanix_sgx_abi::Tcs;
2
3/// Gets the ID for the current thread. The ID is guaranteed to be unique among
4/// all currently running threads in the enclave, and it is guaranteed to be
5/// constant for the lifetime of the thread. More specifically for SGX, there
6/// is a one-to-one correspondence of the ID to the address of the TCS.
7#[unstable(feature = "sgx_platform", issue = "56975")]
8pub fn current() -> Tcs {
9 unsafe extern "C" {
10 fn get_tcs_addr() -> *mut u8;
11 }
12 let addr = unsafe { get_tcs_addr() };
13 match Tcs::new(addr) {
14 Some(tcs) => tcs,
15 None => rtabort!("TCS must not be placed at address zero (this is a linker error)"),
16 }
17}