Debugging sys_exec :(
This commit is contained in:
parent
6d88ef9d99
commit
ad0a7bcaa1
14 changed files with 371 additions and 182 deletions
|
@ -13,14 +13,16 @@ use alloc::sync::Arc;
|
|||
use manager::fetch_task;
|
||||
use lazy_static::*;
|
||||
use process::ProcessControlBlock;
|
||||
use id::RecycleAllocator;
|
||||
|
||||
pub use context::TaskContext;
|
||||
pub use processor::{
|
||||
run_tasks,
|
||||
current_task,
|
||||
current_process,
|
||||
current_user_token,
|
||||
current_trap_cx_user_va,
|
||||
current_trap_cx,
|
||||
current_kstack_top,
|
||||
take_current_task,
|
||||
schedule,
|
||||
};
|
||||
|
@ -42,7 +44,7 @@ pub fn suspend_current_and_run_next() {
|
|||
// Change status to Ready
|
||||
task_inner.task_status = TaskStatus::Ready;
|
||||
drop(task_inner);
|
||||
// ---- release current PCB
|
||||
// ---- release current TCB
|
||||
|
||||
// push back to ready queue.
|
||||
add_task(task);
|
||||
|
@ -53,30 +55,35 @@ pub fn suspend_current_and_run_next() {
|
|||
pub fn exit_current_and_run_next(exit_code: i32) {
|
||||
// take from Processor
|
||||
let task = take_current_task().unwrap();
|
||||
// **** access current TCB exclusively
|
||||
let mut inner = task.inner_exclusive_access();
|
||||
// Change status to Zombie
|
||||
inner.task_status = TaskStatus::Zombie;
|
||||
// Record exit code
|
||||
inner.exit_code = exit_code;
|
||||
// do not move to its parent but under initproc
|
||||
let task_exit_code = task.inner_exclusive_access().exit_code;
|
||||
let tid = task.inner_exclusive_access().res.tid;
|
||||
// remove thread
|
||||
let process = task.process.upgrade().unwrap();
|
||||
let mut process_inner = process.inner_exclusive_access();
|
||||
process_inner.tasks.drain(tid..tid + 1);
|
||||
// if this is the main thread of the process, then we need terminate this process
|
||||
if tid == 0 {
|
||||
// mark this process as a zombie process
|
||||
process_inner.is_zombie = true;
|
||||
// record exit code of main process
|
||||
process_inner.exit_code = task_exit_code;
|
||||
|
||||
// ++++++ access initproc TCB exclusively
|
||||
{
|
||||
let mut initproc_inner = INITPROC.inner_exclusive_access();
|
||||
for child in inner.children.iter() {
|
||||
child.inner_exclusive_access().parent = Some(Arc::downgrade(&INITPROC));
|
||||
initproc_inner.children.push(child.clone());
|
||||
{
|
||||
// move all child processes under init process
|
||||
let mut initproc_inner = INITPROC.inner_exclusive_access();
|
||||
for child in process_inner.children.iter() {
|
||||
child.inner_exclusive_access().parent = Some(Arc::downgrade(&INITPROC));
|
||||
initproc_inner.children.push(child.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
// ++++++ release parent PCB
|
||||
|
||||
inner.children.clear();
|
||||
// deallocate user space
|
||||
inner.memory_set.recycle_data_pages();
|
||||
drop(inner);
|
||||
// **** release current PCB
|
||||
// drop task manually to maintain rc correctly
|
||||
process_inner.children.clear();
|
||||
// deallocate user space as soon as possible
|
||||
process_inner.memory_set.recycle_data_pages();
|
||||
}
|
||||
// maintain rc of process manually since we will break this context soon
|
||||
drop(process_inner);
|
||||
drop(process);
|
||||
drop(task);
|
||||
// we do not have to save task context
|
||||
let mut _unused = TaskContext::zero_init();
|
||||
|
@ -84,13 +91,13 @@ pub fn exit_current_and_run_next(exit_code: i32) {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref INITPROC: Arc<TaskControlBlock> = Arc::new({
|
||||
pub static ref INITPROC: Arc<ProcessControlBlock> = {
|
||||
let inode = open_file("initproc", OpenFlags::RDONLY).unwrap();
|
||||
let v = inode.read_all();
|
||||
TaskControlBlock::new(v.as_slice())
|
||||
});
|
||||
ProcessControlBlock::new(v.as_slice())
|
||||
};
|
||||
}
|
||||
|
||||
pub fn add_initproc() {
|
||||
add_task(INITPROC.clone());
|
||||
let initproc = INITPROC.clone();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue