use std::sync::{
atomic::{AtomicU32, Ordering},
Mutex,
};
mod alloc;
mod core;
mod debug;
mod file;
mod object;
mod process;
mod slot;
mod stdio;
mod thread;
mod time;
pub(crate) mod upcall;
pub use core::CompartmentInitInfo;
pub use thread::RuntimeThreadControl;
pub use upcall::set_upcall_handler;
use self::object::ObjectHandleManager;
pub struct ReferenceRuntime {
pub(crate) state: AtomicU32,
pub(crate) object_manager: Mutex<ObjectHandleManager>,
}
impl std::fmt::Debug for ReferenceRuntime {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"RefRun({})",
if self.state().contains(RuntimeState::READY) {
"ready"
} else {
"not-ready"
}
)
}
}
bitflags::bitflags! {
pub struct RuntimeState : u32 {
const READY = 1;
const IS_MONITOR = 2;
}
}
impl ReferenceRuntime {
pub fn state(&self) -> RuntimeState {
RuntimeState::from_bits_truncate(self.state.load(Ordering::SeqCst))
}
pub unsafe fn set_runtime_ready(&self) {
self.state
.fetch_or(RuntimeState::READY.bits(), Ordering::SeqCst);
}
fn set_is_monitor(&self) {
self.state
.fetch_or(RuntimeState::IS_MONITOR.bits(), Ordering::SeqCst);
}
}
pub static OUR_RUNTIME: ReferenceRuntime = ReferenceRuntime {
state: AtomicU32::new(0),
object_manager: Mutex::new(ObjectHandleManager::new()),
};
#[cfg(feature = "runtime")]
pub(crate) mod do_impl {
use twizzler_runtime_api::Runtime;
use super::ReferenceRuntime;
use crate::preinit_println;
impl Runtime for ReferenceRuntime {}
#[inline]
#[no_mangle]
pub fn __twz_get_runtime() -> &'static (dyn Runtime + Sync) {
&super::OUR_RUNTIME
}
#[used]
static USE_MARKER: fn() -> &'static (dyn Runtime + Sync) = __twz_get_runtime;
}
#[no_mangle]
pub fn __register_frame_info() {}
#[no_mangle]
pub fn __deregister_frame_info() {}
#[no_mangle]
pub fn __cxa_finalize() {}