proc: enter into userspace
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
1a8061e3b3
commit
cd916f624b
12 changed files with 138 additions and 29 deletions
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "elf.h"
|
||||
|
||||
int elf_get_headers(const char *file, struct ehdr **out_ehdr, struct phdr **out_phdrs)
|
||||
int elf_get_headers(const char *file, struct ehdr **out_ehdr, struct phdr **out_phdrs, uaddr_t *entry)
|
||||
{
|
||||
struct ehdr *ehdr = kalloc(sizeof(struct ehdr), ALLOC_KERN);
|
||||
if (!ehdr)
|
||||
|
|
@ -36,20 +36,27 @@ int elf_get_headers(const char *file, struct ehdr **out_ehdr, struct phdr **out_
|
|||
|
||||
*out_ehdr = ehdr;
|
||||
*out_phdrs = phdrs;
|
||||
*entry = ehdr->e_entry;
|
||||
|
||||
return ehdr->e_phnum;
|
||||
}
|
||||
|
||||
int proc_load_file(const char *file, struct proc *proc)
|
||||
ssize_t proc_load_file(const char *file, struct proc *proc)
|
||||
{
|
||||
struct ehdr *ehdr;
|
||||
struct phdr *phdrs;
|
||||
|
||||
int res = elf_get_headers(file, &ehdr, &phdrs);
|
||||
uaddr_t entry = 0;
|
||||
int res = elf_get_headers(file, &ehdr, &phdrs, &entry);
|
||||
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
proc->ehdr = ehdr;
|
||||
proc->phdrs = phdrs;
|
||||
proc->n_phdrs = res;
|
||||
proc->entry = entry;
|
||||
|
||||
for (int i = 0; i < res; i++) {
|
||||
struct phdr *cur = phdrs + i;
|
||||
if (cur->p_type != PT_LOAD)
|
||||
|
|
@ -77,5 +84,5 @@ int proc_load_file(const char *file, struct proc *proc)
|
|||
proc_mmap(proc, TO_PHYS(program), page_vaddr, map_size, flags);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return entry;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue