sel4_runtime_common/
lib.rs
1#![no_std]
8#![feature(cfg_target_thread_local)]
9#![feature(core_intrinsics)]
10#![feature(never_type)]
11#![allow(internal_features)]
12
13use sel4_elf_header::{ElfHeader, ProgramHeader};
14use sel4_panicking_env::abort;
15
16#[cfg(target_thread_local)]
17mod tls;
18
19#[cfg(panic = "unwind")]
20mod unwinding;
21
22#[cfg(feature = "abort")]
23mod abort;
24
25#[cfg(feature = "start")]
26mod start;
27
28#[allow(clippy::missing_safety_doc)]
29pub unsafe fn with_local_initialization(f: impl FnOnce() -> !) -> ! {
30 cfg_if::cfg_if! {
31 if #[cfg(target_thread_local)] {
32 tls::with_tls(f)
33 } else {
34 f()
35 }
36 }
37}
38
39#[allow(clippy::missing_safety_doc)]
40pub unsafe fn global_initialzation() {
41 #[cfg(panic = "unwind")]
42 {
43 crate::unwinding::set_eh_frame_finder().unwrap();
44 }
45
46 sel4_ctors_dtors::run_ctors().unwrap();
47}
48
49#[allow(dead_code)]
50fn locate_phdrs() -> &'static [ProgramHeader] {
51 extern "C" {
52 static __ehdr_start: ElfHeader;
53 }
54 unsafe {
55 if !__ehdr_start.is_magic_valid() {
56 abort!("ELF header magic mismatch")
57 }
58 __ehdr_start.locate_phdrs()
59 }
60}
61
62#[doc(hidden)]
63pub mod _private {
64 #[cfg(feature = "start")]
65 pub use crate::start::_private as start;
66}