diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-17 23:48:03 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-17 23:48:03 -0400 |
commit | c489b2e5f072d73d0cf17d555c6483da55718235 (patch) | |
tree | 88b686a625ef59a0a517cfe67beef38d96a0fc69 /sys/kern/kern_loader.c | |
parent | 3be9e31b6fd78b4a63b13f8a1562be78050774a0 (diff) |
kernel: loader: Keep track of program addr range
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern/kern_loader.c')
-rw-r--r-- | sys/kern/kern_loader.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/sys/kern/kern_loader.c b/sys/kern/kern_loader.c index 23249ea..e62e2b4 100644 --- a/sys/kern/kern_loader.c +++ b/sys/kern/kern_loader.c @@ -54,7 +54,7 @@ __KERNEL_META("$Hyra$: kern_loader.c, Ian Marco Moffett, " (void *)((uintptr_t)hdr + (hdrptr)->e_phoff + (hdrptr->e_phentsize*IDX)) int loader_load(struct vas vas, const void *dataptr, struct auxval *auxv, - size_t load_base, char **ld_path) + size_t load_base, char **ld_path, struct vm_range *prog_range) { const Elf64_Ehdr *hdr = dataptr; Elf64_Phdr *phdr; @@ -64,6 +64,9 @@ int loader_load(struct vas vas, const void *dataptr, struct auxval *auxv, size_t misalign, page_count, map_len; int status; + uintptr_t start_addr = (uintptr_t)-1; + uintptr_t end_addr = 0; + const size_t GRANULE = vm_get_page_size(); void *tmp_ptr; @@ -94,6 +97,16 @@ int loader_load(struct vas vas, const void *dataptr, struct auxval *auxv, physmem = vm_alloc_pageframe(page_count); map_len = page_count * GRANULE; + /* + * Now we want to compute the start address of the + * program and the end address. + */ + if (start_addr == (uintptr_t)-1) { + start_addr = phdr->p_vaddr; + } + + end_addr = __MAX(end_addr, phdr->p_vaddr + page_count*GRANULE); + /* Do we not have enough page frames? */ if (physmem == 0) { DBG("Failed to allocate physical memory\n"); @@ -134,5 +147,7 @@ int loader_load(struct vas vas, const void *dataptr, struct auxval *auxv, auxv->at_entry = hdr->e_entry + load_base; auxv->at_phent = hdr->e_phentsize; auxv->at_phnum = hdr->e_phnum; + prog_range->start = start_addr; + prog_range->end = end_addr; return 0; } |