Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor testing framework, part 1 #222

Merged
merged 8 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ members = [
"src/runtime/secgate",
"src/runtime/monitor",
"src/runtime/monitor-api",
"src/runtime/monitor/tests/montest",
"src/runtime/monitor/tests/montest-lib",
"src/runtime/rt",
"src/runtime/rt-impl",
"src/runtime/minruntime",
"src/abi/rt-abi",
"src/abi/types",
Expand All @@ -43,7 +46,9 @@ initrd = [
"crate:nettest",
"crate:pager",
"lib:twz-rt",
"lib:monitor",
"crate:monitor",
"crate:montest",
"lib:montest-lib",
"crate:mnemosyne",
"crate:stdfs_demo",
#"third-party:hello-world-rs"
Expand Down
2 changes: 1 addition & 1 deletion src/abi
13 changes: 4 additions & 9 deletions src/bin/bootstrap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ fn name_resolver(mut name: &str) -> Result<ObjID, DynlinkError> {
fn start_runtime(_runtime_monitor: ObjID, _runtime_library: ObjID) -> ! {
let engine = Engine;
let mut ctx = dynlink::context::Context::new(Box::new(engine));
let unlib = UnloadedLibrary::new("libmonitor.so");
let unlib = UnloadedLibrary::new("monitor");
let monitor_comp_id = ctx
.add_compartment("monitor", NewCompartmentFlags::EXPORT_GATES)
.unwrap();

info!("==> {}", monitor_comp_id);
let monitor_id = ctx
.load_library_in_compartment(monitor_comp_id, unlib, true)
.unwrap()[0]
Expand All @@ -90,11 +89,7 @@ fn start_runtime(_runtime_monitor: ObjID, _runtime_library: ObjID) -> ! {

debug!("context loaded, prepping jump to monitor");
let entry = ctx
.lookup_symbol(
monitor_id,
"monitor_entry_from_bootstrap",
LookupFlags::empty(),
)
.lookup_symbol(monitor_id, "_start", LookupFlags::empty())
.unwrap();

let value = entry.reloc_value() as usize;
Expand Down Expand Up @@ -136,13 +131,13 @@ fn start_runtime(_runtime_monitor: ObjID, _runtime_library: ObjID) -> ! {
extern crate twizzler_minruntime;
fn main() {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::DEBUG)
.with_max_level(Level::INFO)
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let runtime_lib = find_init_name("libtwz_rt.so").unwrap();
let monitor = find_init_name("libmonitor.so").unwrap();
let monitor = find_init_name("monitor").unwrap();

info!("bootstrapping runtime monitor");
start_runtime(monitor, runtime_lib);
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/initrd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn init(modules: &[BootModule]) {
}
let obj = Arc::new(obj);
obj::register_object(obj.clone());
if e.filename().as_str() == "init" {
if e.filename().as_str() == "bootstrap" {
boot_objects.init = Some(obj.clone());
}
boot_objects
Expand Down
6 changes: 4 additions & 2 deletions src/lib/twizzler-abi/src/upcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ pub struct UpcallTarget {
impl UpcallTarget {
/// Construct a new upcall target.
pub fn new(
self_address: Option<unsafe extern "C-unwind" fn(*mut UpcallFrame, *const UpcallData) -> !>,
self_address: Option<
unsafe extern "C-unwind" fn(*mut core::ffi::c_void, *const core::ffi::c_void) -> !,
>,
super_address: Option<
unsafe extern "C-unwind" fn(*mut UpcallFrame, *const UpcallData) -> !,
unsafe extern "C-unwind" fn(*mut core::ffi::c_void, *const core::ffi::c_void) -> !,
>,
super_stack: usize,
super_stack_size: usize,
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# runtime subdirectory

This subdirectory contains all the crates for the core runtime:

- dynlink: the dynamic linker code
- minruntime: the minimal (no_std, static linking available) runtime
- monitor: the monitor implementation
- monitor-api: the API crate for interaction with the monitor from runtime or user programs
- rt: reference runtime wrapper crate
- rt-impl: the reference runtime implementation. Users should link against the wrapper crate (rt), not this one.
- secgate: secure gate types and utility functions
8 changes: 4 additions & 4 deletions src/runtime/dynlink/src/arch/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::tls::{Tcb, TlsRegion};
pub(crate) const MINIMUM_TLS_ALIGNMENT: usize = 32;

pub use elf::abi::{
R_X86_64_64 as REL_SYMBOLIC, R_X86_64_COPY as REL_COPY, R_X86_64_DTPMOD64 as REL_DTPMOD,
R_X86_64_DTPOFF64 as REL_DTPOFF, R_X86_64_GLOB_DAT as REL_GOT, R_X86_64_JUMP_SLOT as REL_PLT,
R_X86_64_RELATIVE as REL_RELATIVE, R_X86_64_TPOFF64 as REL_TPOFF,
R_X86_64_64 as REL_SYMBOLIC, R_X86_64_DTPMOD64 as REL_DTPMOD, R_X86_64_DTPOFF64 as REL_DTPOFF,
R_X86_64_GLOB_DAT as REL_GOT, R_X86_64_JUMP_SLOT as REL_PLT, R_X86_64_RELATIVE as REL_RELATIVE,
R_X86_64_TPOFF64 as REL_TPOFF,
};

/// Get a pointer to the current thread control block, using the thread pointer.
Expand All @@ -22,7 +22,7 @@ impl TlsRegion {
/// Get a pointer to the thread control block for this TLS region.
///
/// # Safety
/// The TCB must actually contain runtime data of type T, and be initialized.
/// The TCB must actually contain runtime data of type T, and be initialized.
pub unsafe fn get_thread_control_block<T>(&self) -> *mut Tcb<T> {
self.get_thread_pointer_value() as *mut _
}
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/dynlink/src/compartment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{

use petgraph::stable_graph::NodeIndex;
use talc::{ErrOnOom, Talc};
use tracing::info;

use crate::{context::NewCompartmentFlags, engines::Backing, library::LibraryId, tls::TlsInfo};

Expand Down Expand Up @@ -87,6 +86,6 @@ impl Debug for Compartment {

impl Drop for Compartment {
fn drop(&mut self) {
info!("dynlink: drop compartment {:?}", self);
tracing::debug!("dynlink: drop compartment {:?}", self);
}
}
2 changes: 1 addition & 1 deletion src/runtime/dynlink/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Management of global context.

use std::{collections::HashMap, fmt::Display, ops::Index};
use std::{collections::HashMap, fmt::Display};

use petgraph::stable_graph::{NodeIndex, StableDiGraph};
use stable_vec::StableVec;
Expand Down
13 changes: 9 additions & 4 deletions src/runtime/dynlink/src/context/relocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl Context {
} else {
None
};
let sn = symbol.as_ref().map(|s| s.0.to_string()).unwrap_or_default();

// Helper for logging errors.
let open_sym = || {
Expand Down Expand Up @@ -150,15 +151,19 @@ impl Context {
unsafe { *target = val.wrapping_add_signed(addend) }
}
REL_TPOFF => {
if let Some(tls) = lib.tls_id {
let val = open_sym().map(|sym| sym.raw_value()).unwrap_or(0);
let sym = open_sym()?;
if let Some(tls) = sym.lib.tls_id {
unsafe {
*target = val
*target = sym
.raw_value()
.wrapping_sub(tls.offset() as u64)
.wrapping_add_signed(addend)
}
} else {
error!("{}: TPOFF relocations require a PT_TLS segment", lib);
error!(
"{}: TPOFF relocations require a PT_TLS segment (sym {})",
lib, sn
);
Err(DynlinkErrorKind::NoTLSInfo {
library: lib.name.clone(),
})?
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/dynlink/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::fmt::{Debug, Display};

use elf::{
abi::{DT_FLAGS_1, PT_PHDR, PT_TLS, STB_WEAK},
dynamic::Dyn,
endian::NativeEndian,
segment::{Elf64_Phdr, ProgramHeader},
ParseError,
Expand Down Expand Up @@ -351,7 +350,7 @@ impl Debug for Library {

impl Drop for Library {
fn drop(&mut self) {
tracing::info!("dynlink: drop library: {:?}", self);
tracing::debug!("dynlink: drop library: {:?}", self);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/minruntime/src/arch/aarch64/upcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub(crate) unsafe extern "C" fn upcall_entry2(

#[no_mangle]
pub(crate) unsafe extern "C-unwind" fn upcall_entry(
frame: *mut UpcallFrame,
data: *const UpcallData,
frame: *mut core::ffi::c_void,
data: *const core::ffi::c_void,
) -> ! {
core::arch::asm!(
"b upcall_entry2",
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/minruntime/src/arch/x86_64/upcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ pub(crate) unsafe extern "C" fn upcall_entry2(

#[no_mangle]
pub(crate) unsafe extern "C-unwind" fn upcall_entry(
rdi: *mut UpcallFrame,
rsi: *const UpcallData,
rdi: *mut core::ffi::c_void,
rsi: *const core::ffi::c_void,
) -> ! {
let rdi: *const UpcallFrame = rdi.cast();
core::arch::asm!(
".cfi_signal_frame",
"mov rbp, rdx",
Expand Down
Loading
Loading