1use std::sync::atomic::{AtomicU32, Ordering};
4
5mod alloc;
6mod core;
7mod debug;
8mod file;
9mod object;
10mod process;
11mod slot;
12mod thread;
13mod time;
14pub(crate) mod upcall;
15
16use twizzler_abi::simple_mutex::Mutex;
17pub use upcall::set_upcall_handler;
18
19use self::object::ObjectHandleManager;
20
21pub struct ReferenceRuntime {
23 pub(crate) state: AtomicU32,
24 pub(crate) object_manager: Mutex<ObjectHandleManager>,
25}
26
27impl std::fmt::Debug for ReferenceRuntime {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 write!(
30 f,
31 "RefRun({})",
32 if self.state().contains(RuntimeState::READY) {
33 "ready"
34 } else {
35 "not-ready"
36 }
37 )
38 }
39}
40
41bitflags::bitflags! {
42 pub struct RuntimeState : u32 {
44 const READY = 1;
45 const IS_MONITOR = 2;
46 }
47}
48
49impl ReferenceRuntime {
50 pub fn state(&self) -> RuntimeState {
52 RuntimeState::from_bits_truncate(self.state.load(Ordering::SeqCst))
53 }
54
55 pub unsafe fn set_runtime_ready(&self) {
58 self.state
59 .fetch_or(RuntimeState::READY.bits(), Ordering::SeqCst);
60 }
61
62 fn set_is_monitor(&self) {
63 self.state
64 .fetch_or(RuntimeState::IS_MONITOR.bits(), Ordering::SeqCst);
65 }
66}
67
68pub static OUR_RUNTIME: ReferenceRuntime = ReferenceRuntime {
69 state: AtomicU32::new(0),
70 object_manager: Mutex::new(ObjectHandleManager::new()),
71};
72
73#[no_mangle]
77#[linkage = "weak"]
78pub extern "C" fn __register_frame_info() {}
79#[no_mangle]
80#[linkage = "weak"]
81pub extern "C" fn __deregister_frame_info() {}
82#[no_mangle]
83#[linkage = "weak"]
84pub extern "C" fn __cxa_finalize() {}