Using Self in some methods of mm/task; maintain base_size when exec

This commit is contained in:
Yifan Wu 2022-07-19 23:36:03 +01:00
parent 1cc69229d3
commit 995387bfba
2 changed files with 5 additions and 3 deletions

View File

@ -233,7 +233,7 @@ impl MemorySet {
)
}
///Clone a same `MemorySet`
pub fn from_existed_user(user_space: &MemorySet) -> MemorySet {
pub fn from_existed_user(user_space: &Self) -> Self {
let mut memory_set = Self::new_bare();
// map trampoline
memory_set.map_trampoline();
@ -294,7 +294,7 @@ impl MapArea {
map_perm,
}
}
pub fn from_another(another: &MapArea) -> Self {
pub fn from_another(another: &Self) -> Self {
Self {
vpn_range: VPNRange::new(another.vpn_range.get_start(), another.vpn_range.get_end()),
data_frames: BTreeMap::new(),

View File

@ -105,6 +105,8 @@ impl TaskControlBlock {
inner.memory_set = memory_set;
// update trap_cx ppn
inner.trap_cx_ppn = trap_cx_ppn;
// initialize base_size
inner.base_size = user_sp;
// initialize trap_cx
let trap_cx = inner.get_trap_cx();
*trap_cx = TrapContext::app_init_context(
@ -116,7 +118,7 @@ impl TaskControlBlock {
);
// **** release inner automatically
}
pub fn fork(self: &Arc<TaskControlBlock>) -> Arc<TaskControlBlock> {
pub fn fork(self: &Arc<Self>) -> Arc<Self> {
// ---- access parent PCB exclusively
let mut parent_inner = self.inner_exclusive_access();
// copy user space(include trap context)