diff options
author | Ian Moffett <ian@osmora.org> | 2025-09-16 20:50:23 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-09-16 20:50:23 -0400 |
commit | 4b5970408f14c6f27070a9747315759b575f9009 (patch) | |
tree | dc96d7d61a4f40a3f1011612f3a126719ec4e5c8 | |
parent | 98c9d507c932a5d66a2192eae8191fe37f1f03fa (diff) |
kern: elf: Fix frame calcs + style cleanup
Allocate more than one frame that exists and increment by one if zero.
We also did some style fix ups, added an #undef and a break.
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | src/sys/os/os_elf64.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/sys/os/os_elf64.c b/src/sys/os/os_elf64.c index 1127cca..cdb42a7 100644 --- a/src/sys/os/os_elf64.c +++ b/src/sys/os/os_elf64.c @@ -103,8 +103,8 @@ elf64_do_load(Elf64_Ehdr *eh, struct proc *proc) struct mmu_map spec; Elf64_Phdr *phdr, *phdr_base; paddr_t frame; - size_t npges, len, misalign; - uintptr_t tmp; + size_t npgs, len, misalign; + void *tmp; int error, prot; if (eh == NULL || proc == NULL) { @@ -135,8 +135,13 @@ elf64_do_load(Elf64_Ehdr *eh, struct proc *proc) misalign = phdr->p_memsz & (PSIZE - 1); len = phdr->p_memsz; len = ALIGN_UP(len + misalign, PSIZE); + npgs = len / PSIZE; - frame = vm_alloc_frame(1); + if (npgs == 0) { + ++npgs; + } + + frame = vm_alloc_frame(npgs); if (frame == 0) { printf("elf64_do_load: could not alloc frame\n"); return -ENOMEM; @@ -152,7 +157,7 @@ elf64_do_load(Elf64_Ehdr *eh, struct proc *proc) error = vm_map( &pcbp->vas, &spec, - phdr->p_memsz, + len, prot ); @@ -160,7 +165,9 @@ elf64_do_load(Elf64_Ehdr *eh, struct proc *proc) printf("elf64_do_load: failed to map segment\n"); return error; } + break; } +#undef _PHDR_I } return 0; |