Map ELF into child address space

This commit is contained in:
Sparchatus 2022-03-23 09:02:07 +00:00
parent fdf72890f1
commit 3493884ecc
2 changed files with 17 additions and 7 deletions

View File

@ -613,8 +613,7 @@ errval_t paging_map_fixed_attr(struct paging_state *st, lvaddr_t vaddr,
// preconditions
assert(bytes % BASE_PAGE_SIZE == 0);
lvaddr_t end_vaddr = vaddr + bytes;
assert(VADDR_OFFSET <= vaddr && vaddr < end_vaddr &&
end_vaddr <= VADDR_OFFSET + PTABLE_ENTRIES * PTABLE_ENTRIES *PTABLE_ENTRIES * PTABLE_ENTRIES * BASE_PAGE_SIZE);
assert(end_vaddr <= VADDR_OFFSET + PTABLE_ENTRIES * PTABLE_ENTRIES *PTABLE_ENTRIES * PTABLE_ENTRIES * BASE_PAGE_SIZE);
assert(st != NULL);
assert(st->slot_alloc != NULL);
@ -666,9 +665,6 @@ errval_t paging_map_fixed_attr(struct paging_state *st, lvaddr_t vaddr,
capaddr_t l2_index = VMSAv8_64_L2_INDEX(current_vaddr);
capaddr_t l3_index = VMSAv8_64_L3_INDEX(current_vaddr);
// Cannot map anything with l0_index = 0 since this part of the page table was created by the kernel for us
assert(l0_index != 0);
// get the size of the mapping
mapping_size = MIN(PTABLE_ENTRIES - l3_index, (vaddr + bytes - current_vaddr) / BASE_PAGE_SIZE);

View File

@ -52,6 +52,7 @@ static void armv8_set_registers(void *arch_load_info,
struct allocate_state {
// TODO: add fields
struct paging_state *paging_state;
};
static errval_t elf_allocate(
@ -62,7 +63,7 @@ static errval_t elf_allocate(
void **ret
) {
errval_t err;
// struct allocate_state *st = state;
struct allocate_state *st = state;
// Allocate a frame
struct capref frame;
@ -84,6 +85,12 @@ static errval_t elf_allocate(
if (err_is_fail(err)) return err;
// TODO: Map into child address space
err = paging_map_fixed_attr(
st->paging_state, base, frame,
alloc_bytes, VREGION_FLAGS_READ_WRITE
);
if (err_is_fail(err)) return err;
// TODO: Keep track of the mapped regions, so you can unmap them later.
@ -196,8 +203,15 @@ errval_t spawn_load_argv(int argc, char *argv[], struct spawninfo *si,
err = vnode_create(si->vspace_cap_l0_pagetable, ObjType_VNode_AARCH64_l0);
if (err_is_fail(err)) return err;
// rueegges: initialize the foreign paging state
struct paging_state child_paging_state;
// 64 * 1024 is enough to catch null pointers and also enough to not conflict with child starting paging_alloc at VADDR_OFFSET
paging_init_state_foreign(&child_paging_state, 64 * 1024, si->vspace_cap_l0_pagetable, get_default_slot_allocator());
// - Load the ELF binary
struct allocate_state st = {};
struct allocate_state st = {
.paging_state = &child_paging_state,
};
genvaddr_t entry;
err = elf_load(EM_AARCH64, elf_allocate, &st, (lvaddr_t)elf_base, elf_bytes, &entry);
if (err_is_fail(err)) return err_push(err, SPAWN_ERR_ELF_LOAD);