about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2022-09-05 11:42:46 +0200
committerjoboet <jonasboettiger@icloud.com>2022-09-11 12:15:32 +0200
commit2fa58080cbcdb42bda0438e2d37bdd8a4436a6f4 (patch)
tree9a8fcb7df60289c6b44a554982328f0707fc99b7 /library
parent9358d09a55307e47bde0276e2390c603c35d5fb6 (diff)
downloadrust-2fa58080cbcdb42bda0438e2d37bdd8a4436a6f4.tar.gz
rust-2fa58080cbcdb42bda0438e2d37bdd8a4436a6f4.zip
std: check if TCS is a null pointer
Diffstat (limited to 'library')
-rw-r--r--library/std/src/sys/sgx/abi/thread.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/std/src/sys/sgx/abi/thread.rs b/library/std/src/sys/sgx/abi/thread.rs
index ef55b821a2b..2b23e368cc3 100644
--- a/library/std/src/sys/sgx/abi/thread.rs
+++ b/library/std/src/sys/sgx/abi/thread.rs
@@ -7,7 +7,11 @@ use fortanix_sgx_abi::Tcs;
 #[unstable(feature = "sgx_platform", issue = "56975")]
 pub fn current() -> Tcs {
     extern "C" {
-        fn get_tcs_addr() -> Tcs;
+        fn get_tcs_addr() -> *mut u8;
+    }
+    let addr = unsafe { get_tcs_addr() };
+    match Tcs::new(addr) {
+        Some(tcs) => tcs,
+        None => rtabort!("TCS must not be placed at address zero (this is a linker error)"),
     }
-    unsafe { get_tcs_addr() }
 }