ELF Loader now sets heap_bottom/heap_top correctly
authorKevin Klues <klueska@ros-dev.(none)>
Tue, 23 Mar 2010 02:33:43 +0000 (19:33 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:37 +0000 (17:35 -0700)
kern/src/elf.c

index 1df6994..8fc112a 100644 (file)
@@ -8,6 +8,7 @@
 struct elf_info
 {
        long entry;
+       long highest_addr;
        long phdr;
        int phnum;
        int dynamic;
@@ -19,6 +20,7 @@ int load_one_elf(struct proc* p, int fd, int pgoffset, struct elf_info* ei)
        int ret = -1;
        ei->phdr = -1;
        ei->dynamic = 0;
+       ei->highest_addr = 0;
 
        char* elf = (char*)kmalloc(PGSIZE,0);
        if(!elf || read_page(p,fd,PADDR(elf),0) == -1)
@@ -63,6 +65,8 @@ int load_one_elf(struct proc* p, int fd, int pgoffset, struct elf_info* ei)
                        uintptr_t memstart = ROUNDDOWN(ph->p_va,PGSIZE);
                        uintptr_t memend = ROUNDUP(ph->p_va + ph->p_memsz,PGSIZE);
                        uintptr_t memsz = memend-memstart;
+                       if(memend > ei->highest_addr)
+                               ei->highest_addr = memend;
 
                        // mmap will zero the rest of the page if filesz % PGSIZE != 0
                        if(filesz)
@@ -133,6 +137,11 @@ int load_elf(struct proc* p, const char* fn)
                MAP_FIXED|MAP_ANON,-1,0) == MAP_FAILED)
                return -1;
 
+       // Set the heap bottom and top to just past where the text 
+       // region has been loaded
+       p->heap_bottom = (void*)ei.highest_addr;
+       p->heap_top = p->heap_bottom;
+
        return 0;
 }