mirror of
https://github.com/LearningOS/rust-based-os-comp2022.git
synced 2026-05-08 06:41:27 +08:00
23 lines
629 B
Rust
23 lines
629 B
Rust
pub fn get_num_app() -> usize {
|
|
extern "C" {
|
|
fn _num_app();
|
|
}
|
|
unsafe { (_num_app as usize as *const usize).read_volatile() }
|
|
}
|
|
|
|
pub fn get_app_data(app_id: usize) -> &'static [u8] {
|
|
extern "C" {
|
|
fn _num_app();
|
|
}
|
|
let num_app_ptr = _num_app as usize as *const usize;
|
|
let num_app = get_num_app();
|
|
let app_start = unsafe { core::slice::from_raw_parts(num_app_ptr.add(1), num_app + 1) };
|
|
assert!(app_id < num_app);
|
|
unsafe {
|
|
core::slice::from_raw_parts(
|
|
app_start[app_id] as *const u8,
|
|
app_start[app_id + 1] - app_start[app_id],
|
|
)
|
|
}
|
|
}
|