summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-07-18 21:03:08 -0400
committerIan Moffett <ian@osmora.org>2024-07-18 21:03:08 -0400
commit5d0e6ce144629888fbcf4e443e494dc0d7197672 (patch)
tree447417378e88e84c578e74e89b7344c08e254afd
parent24d1080c716098273cea3e40b4bbcde236b222dc (diff)
kernel: elf: Keep track of program start and end
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/include/sys/exec.h2
-rw-r--r--sys/kern/exec_elf64.c14
2 files changed, 16 insertions, 0 deletions
diff --git a/sys/include/sys/exec.h b/sys/include/sys/exec.h
index 2c85010..08ddac6 100644
--- a/sys/include/sys/exec.h
+++ b/sys/include/sys/exec.h
@@ -73,6 +73,8 @@ struct exec_prog {
struct auxval auxval;
char **argp;
char **envp;
+ vaddr_t start;
+ vaddr_t end;
};
struct execve_args {
diff --git a/sys/kern/exec_elf64.c b/sys/kern/exec_elf64.c
index 4dbc3aa..0fafc02 100644
--- a/sys/kern/exec_elf64.c
+++ b/sys/kern/exec_elf64.c
@@ -170,6 +170,7 @@ elf64_load(const char *pathname, struct proc *td, struct exec_prog *prog)
Elf64_Ehdr *hdr;
Elf64_Phdr *phdr;
paddr_t physmem;
+ vaddr_t start, end;
off_t misalign;
void *tmp;
size_t page_count, map_len;
@@ -188,6 +189,8 @@ elf64_load(const char *pathname, struct proc *td, struct exec_prog *prog)
goto done;
pcbp = &td->pcb;
+ start = -1;
+ end = 0;
/* Load program headers */
for (size_t i = 0; i < hdr->e_phnum; ++i) {
@@ -223,10 +226,21 @@ elf64_load(const char *pathname, struct proc *td, struct exec_prog *prog)
loadmap[loadmap_idx].start = physmem;
loadmap[loadmap_idx].end = physmem + map_len;
loadmap[loadmap_idx].vbase = phdr->p_vaddr;
+
+ /* Get start/end addresses */
+ if (start == (vaddr_t)-1)
+ start = loadmap[loadmap_idx].vbase;
+ if (phdr->p_vaddr > end)
+ end = loadmap[loadmap_idx].vbase + phdr->p_memsz;
+
+ ++loadmap_idx;
}
}
memcpy(prog->loadmap, loadmap, sizeof(loadmap));
+ prog->start = start;
+ prog->end = end;
+
auxvalp = &prog->auxval;
auxvalp->at_entry = hdr->e_entry;
auxvalp->at_phent = hdr->e_phentsize;