about summary refs log tree commit diff
path: root/library/std/src/sys/thread_local
diff options
context:
space:
mode:
authorNicole LeGare <legare@google.com>2025-02-04 21:59:22 +0000
committerNicole L <dlegare.1001@gmail.com>2025-03-10 10:00:24 -0700
commit87ca2dbb0054256a675e18ddb7098406db4e42ed (patch)
treeb6d8bc32c649b5dfce3d0a764397cb1121d2b902 /library/std/src/sys/thread_local
parent2b285cd5f0877e30ad1d83e04f8cc46254e43391 (diff)
Apply rustc-0023-Add-Trusty-OS-support-to-Rust-std.patch
Diffstat (limited to 'library/std/src/sys/thread_local')
-rw-r--r--library/std/src/sys/thread_local/key/trusty.rs30
-rw-r--r--library/std/src/sys/thread_local/mod.rs9
2 files changed, 39 insertions, 0 deletions
diff --git a/library/std/src/sys/thread_local/key/trusty.rs b/library/std/src/sys/thread_local/key/trusty.rs
new file mode 100644
index 00000000000..894091d2d81
--- /dev/null
+++ b/library/std/src/sys/thread_local/key/trusty.rs
@@ -0,0 +1,30 @@
+use crate::ptr;
+
+pub type Key = usize;
+type Dtor = unsafe extern "C" fn(*mut u8);
+
+static mut STORAGE: crate::vec::Vec<(*mut u8, Option<Dtor>)> = Vec::new();
+
+#[inline]
+pub fn create(dtor: Option<Dtor>) -> Key {
+    unsafe {
+        #[allow(static_mut_refs)]
+        let key = STORAGE.len();
+        #[allow(static_mut_refs)]
+        STORAGE.push((ptr::null_mut(), dtor));
+        key
+    }
+}
+
+#[inline]
+pub unsafe fn set(key: Key, value: *mut u8) {
+    unsafe { STORAGE[key].0 = value };
+}
+
+#[inline]
+pub unsafe fn get(key: Key) -> *mut u8 {
+    unsafe { STORAGE[key].0 }
+}
+
+#[inline]
+pub fn destroy(_key: Key) {}
diff --git a/library/std/src/sys/thread_local/mod.rs b/library/std/src/sys/thread_local/mod.rs
index f0a13323ec9..827f464e860 100644
--- a/library/std/src/sys/thread_local/mod.rs
+++ b/library/std/src/sys/thread_local/mod.rs
@@ -170,6 +170,15 @@ pub(crate) mod key {
             pub(crate) use xous::destroy_tls;
             pub(super) use xous::{Key, get, set};
             use xous::{create, destroy};
+        } else if #[cfg(target_os = "trusty")] {
+            #[allow(unused_unsafe)]
+            mod racy;
+            #[cfg(test)]
+            mod tests;
+            mod trusty;
+            pub(super) use racy::LazyKey;
+            pub(super) use trusty::{Key, get, set};
+            use trusty::{create, destroy};
         }
     }
 }