From c83edbb696d6833728808990c69944fecb4b44d6 Mon Sep 17 00:00:00 2001 From: Aurel Feer Date: Tue, 22 Mar 2022 22:36:38 +0100 Subject: [PATCH] setup child vspace --- include/spawn/spawn.h | 4 +++- lib/spawn/spawn.c | 37 ++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/spawn/spawn.h b/include/spawn/spawn.h index f5767a8..b6b7754 100644 --- a/include/spawn/spawn.h +++ b/include/spawn/spawn.h @@ -48,7 +48,9 @@ struct spawninfo { struct capref cspace_cap_dispatcher; // < Contains the dispatcher capability.The dispatcher is the equivalent of a “Process Control Block” in other operating systems. You can create one using dispatcher_create(...); struct capref cspace_cap_rootcn; // < Contains a capability for the root (L1) CNode. struct capref cspace_cap_dispframe; // < A capability to the dispatcher frame, used to communicate between a process and the CPU driver. - struct capref cspace_cap_argspage; // < A page containing a list of command line ar- guments. + struct capref cspace_cap_argspage; // < A page containing a list of command line arguments. + + struct capref vspace_cap_l0_pagetable; }; // Start a child process using the multiboot command line. Fills in si. diff --git a/lib/spawn/spawn.c b/lib/spawn/spawn.c index 9c0e940..f78255f 100644 --- a/lib/spawn/spawn.c +++ b/lib/spawn/spawn.c @@ -148,9 +148,10 @@ errval_t spawn_load_argv(int argc, char *argv[], struct spawninfo *si, // - Setup the child's cspace // afeer: script page 84/85 - cnode_create_l1(&si->cspace_l1_cnode_cap, &si->cspace_l1_cnode_info); - - cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_TASKCN, &si->cspace_l2_cnode_taskcn); + err = cnode_create_l1(&si->cspace_l1_cnode_cap, &si->cspace_l1_cnode_info); + if (err_is_fail(err)) return err; + err = cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_TASKCN, &si->cspace_l2_cnode_taskcn); + if (err_is_fail(err)) return err; // afeer: (script page 84) is this correct? si->cspace_cap_selfep.cnode = si->cspace_l2_cnode_taskcn; @@ -168,18 +169,32 @@ errval_t spawn_load_argv(int argc, char *argv[], struct spawninfo *si, si->cspace_cap_argspage.cnode = si->cspace_l2_cnode_taskcn; si->cspace_cap_argspage.slot = TASKCN_SLOT_ARGSPAGE; - cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_SLOT_ALLOC0, &si->cspace_l2_cnode_slot_alloc_0); - cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_SLOT_ALLOC1, &si->cspace_l2_cnode_slot_alloc_1); - cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_SLOT_ALLOC2, &si->cspace_l2_cnode_slot_alloc_2); - cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_BASE_PAGE_CN, &si->cspace_l2_cnode_base_pagecn); - cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_PAGECN, &si->cspace_l2_cnode_pagecn); // < afeer: TODO: script page 85: fill this with pagetable capabilities + err = cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_SLOT_ALLOC0, &si->cspace_l2_cnode_slot_alloc_0); + if (err_is_fail(err)) return err; + err = cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_SLOT_ALLOC1, &si->cspace_l2_cnode_slot_alloc_1); + if (err_is_fail(err)) return err; + err = cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_SLOT_ALLOC2, &si->cspace_l2_cnode_slot_alloc_2); + if (err_is_fail(err)) return err; + err = cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_BASE_PAGE_CN, &si->cspace_l2_cnode_base_pagecn); + if (err_is_fail(err)) return err; + err = cnode_create_foreign_l2(si->cspace_l1_cnode_cap, ROOTCN_SLOT_PAGECN, &si->cspace_l2_cnode_pagecn); + if (err_is_fail(err)) return err; // afeer: populate some capabilities - dispatcher_create(si->cspace_cap_dispatcher); - cap_retype(si->cspace_cap_selfep, si->cspace_cap_dispatcher, 0, ObjType_EndPointLMP, 0, 1); + err = dispatcher_create(si->cspace_cap_dispatcher); + if (err_is_fail(err)) return err; + err = cap_retype(si->cspace_cap_selfep, si->cspace_cap_dispatcher, 0, ObjType_EndPointLMP, 0, 1); + if (err_is_fail(err)) return err; // - Setup the child's vspace - // TODO + // afeer: create level 0 page table + // the l0 page table is in the first slot of the pagecn cnode. + // lower-level pagetables and mappings are stored on different slots of the pagecn cnode. + si->vspace_cap_l0_pagetable.cnode = si->cspace_l2_cnode_pagecn; + si->vspace_cap_l0_pagetable.slot = PAGECN_SLOT_VROOT; + + err = vnode_create(si->vspace_cap_l0_pagetable, ObjType_VNode_AARCH64_l0); + if (err_is_fail(err)) return err; // - Load the ELF binary struct allocate_state st = {};