-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial monitor state management overhaul (#196)
* Monitor setup and stubbing. * Add lock_api to Cargo.toml.
- Loading branch information
Showing
17 changed files
with
651 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use twizzler_runtime_api::ObjID; | ||
|
||
/// Reserved instance ID for the security monitor. | ||
pub const MONITOR_INSTANCE_ID: ObjID = ObjID::new(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub struct CompartmentMgr {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::sync::OnceLock; | ||
|
||
use happylock::RwLock; | ||
|
||
use self::space::Unmapper; | ||
|
||
pub(crate) mod compartment; | ||
pub(crate) mod space; | ||
pub(crate) mod thread; | ||
|
||
/// A security monitor instance. All monitor logic is implemented as methods for this type. | ||
/// We split the state into the following components: 'space', managing the virtual memory space and | ||
/// mapping objects, 'thread_mgr', which manages all threads owned by the monitor (typically, all | ||
/// threads started by compartments), 'compartments', which manages compartment state, and | ||
/// 'dynlink', which contains the dynamic linker state. The unmapper allows for background unmapping | ||
/// and cleanup of objects and handles. | ||
pub struct Monitor { | ||
space: RwLock<space::Space>, | ||
thread_mgr: RwLock<thread::ThreadMgr>, | ||
compartments: RwLock<compartment::CompartmentMgr>, | ||
dynlink: RwLock<dynlink::context::Context>, | ||
unmapper: Unmapper, | ||
} | ||
|
||
static MONITOR: OnceLock<Monitor> = OnceLock::new(); | ||
|
||
/// Get the monitor instance. Panics if called before first call to [set_monitor]. | ||
pub fn get_monitor() -> &'static Monitor { | ||
MONITOR.get().unwrap() | ||
} | ||
|
||
/// Set the monitor instance. Can only be called once. Must be called before any call to | ||
/// [get_monitor]. | ||
pub fn set_monitor(monitor: Monitor) { | ||
if MONITOR.set(monitor).is_err() { | ||
panic!("second call to set_monitor"); | ||
} | ||
} |
Oops, something went wrong.