Files
RedBear-OS/src/ld_so/library.rs
T

53 lines
1.3 KiB
Rust

use alloc::{
boxed::Box,
collections::{BTreeMap, BTreeSet},
string::String,
vec::Vec,
};
#[derive(Default, Debug)]
pub struct DepTree {
pub name: String,
pub deps: Vec<DepTree>,
}
impl DepTree {
pub fn new(name: String) -> DepTree {
DepTree {
name,
deps: Vec::new(),
}
}
}
/// Use to represnt a library as well as all th symbols that is loaded withen it.
#[derive(Default)]
pub struct Library {
/// Global symbols
pub globals: BTreeMap<String, usize>,
/// Weak symbols
pub weak_syms: BTreeMap<String, usize>,
/// Loaded library raw data
pub objects: BTreeMap<String, Box<[u8]>>,
/// Loaded library in-memory data
pub mmaps: BTreeMap<String, &'static mut [u8]>,
/// Each object will have its children called once with no repetition.
pub dep_tree: DepTree,
/// A set used to detect circular dependencies in the Linker::load function
pub cir_dep: BTreeSet<String>,
}
impl Library {
pub fn new() -> Library {
Default::default()
}
pub fn get_sym(&self, name: &str) -> Option<usize> {
if let Some(value) = self.globals.get(name) {
Some(*value)
} else if let Some(value) = self.weak_syms.get(name) {
Some(*value)
} else {
None
}
}
}