monitor/mon/compartment/
compconfig.rs1use monitor_api::SharedCompConfig;
2use talc::Span;
3use twizzler_abi::object::{MAX_SIZE, NULLPAGE_SIZE};
4
5use crate::mon::space::MapHandle;
6
7pub struct CompConfigObject {
9 handle: MapHandle,
10}
11
12impl CompConfigObject {
13 pub fn new(handle: MapHandle, init_val: SharedCompConfig) -> Self {
15 let mut this = Self { handle };
16 this.write_config(init_val);
17 this
18 }
19
20 pub fn write_config(&mut self, val: SharedCompConfig) {
22 unsafe {
25 let base = self.handle.monitor_data_base();
26 (base as *mut SharedCompConfig).write(val);
27 }
28 }
29
30 pub(crate) fn read_comp_config(&self) -> SharedCompConfig {
32 unsafe { self.get_comp_config().read() }
34 }
35
36 pub fn get_comp_config(&self) -> *const SharedCompConfig {
38 self.handle.monitor_data_base() as *const SharedCompConfig
39 }
40
41 pub fn alloc_span(&self) -> Span {
43 let offset_from_base =
44 core::mem::size_of::<SharedCompConfig>().next_multiple_of(NULLPAGE_SIZE);
45 assert!(offset_from_base < MAX_SIZE / 2);
46 unsafe {
48 Span::new(
49 self.handle.monitor_data_base().add(offset_from_base),
50 self.handle.monitor_data_start().add(MAX_SIZE / 2),
51 )
52 }
53 }
54}