// in Cargo.toml
[dependencies]
xmas-elf = "0.6"
// in process/structs.rs
use xmas_elf::{
header,
program::{ Flags, SegmentData, Type },
ElfFile,
};
// in process/structs.rs
use crate::memory_set::{ MemorySet, handler::ByFrame, attr::MemoryAttr};
use crate::memory::frame_allocator::alloc_frames;
use crate::consts::*;
use crate::process::{ Tid, ExitCode };
use alloc::{ sync::Arc, boxed::Box };
use alloc::alloc::{ alloc, dealloc, Layout };
use riscv::register::satp;
use core::str;
// in process/mod.rs
extern "C" {
fn _user_img_start();
fn _user_img_end();
}
pub fn init() {
println!("+------ now to initialize process ------+");
let scheduler = Scheduler::new(1);
let thread_pool = ThreadPool::new(100, scheduler);
CPU.init(Thread::new_idle(), Box::new(thread_pool));
...
let data = unsafe{
::core::slice::from_raw_parts(
_user_img_start as *const u8,
_user_img_end as usize - _user_img_start as usize,
)
};
let user = unsafe{ Thread::new_user(data) };
CPU.add_thread(user);
CPU.run();
}