sel4_initialize_tls/
on_stack.rs1use sel4_alloca::with_alloca_ptr;
8
9use crate::{SetThreadPointerFn, TlsImage};
10
11impl TlsImage {
12 #[allow(clippy::missing_safety_doc)]
13 pub unsafe fn with_initialize_on_stack<R>(
14 &self,
15 set_thread_pointer_fn: SetThreadPointerFn,
16 f: impl FnOnce() -> R,
17 ) -> R {
18 with_alloca_ptr(
19 self.reservation_layout().footprint(),
20 |tls_reservation_start| {
21 let thread_pointer = tls_reservation_start
22 .wrapping_byte_add(self.reservation_layout().thread_pointer_offset());
23 unsafe {
24 self.initialize_reservation(tls_reservation_start);
25 (set_thread_pointer_fn)(thread_pointer as usize);
26 }
27 f()
28 },
29 )
30 }
31}