fix a bug in the out-of-memory handling code in exec
This commit is contained in:
parent
8dc71a257d
commit
f2ec6777bd
|
@ -14,7 +14,7 @@ exec(char *path, char **argv)
|
|||
{
|
||||
char *s, *last;
|
||||
int i, off;
|
||||
uint64 argc, sz, sp, ustack[MAXARG+1], stackbase;
|
||||
uint64 argc, sz = 0, sp, ustack[MAXARG+1], stackbase;
|
||||
struct elfhdr elf;
|
||||
struct inode *ip;
|
||||
struct proghdr ph;
|
||||
|
@ -39,7 +39,6 @@ exec(char *path, char **argv)
|
|||
goto bad;
|
||||
|
||||
// Load program into memory.
|
||||
sz = 0;
|
||||
for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
|
||||
if(readi(ip, 0, (uint64)&ph, off, sizeof(ph)) != sizeof(ph))
|
||||
goto bad;
|
||||
|
@ -49,8 +48,10 @@ exec(char *path, char **argv)
|
|||
goto bad;
|
||||
if(ph.vaddr + ph.memsz < ph.vaddr)
|
||||
goto bad;
|
||||
if((sz = uvmalloc(pagetable, sz, ph.vaddr + ph.memsz)) == 0)
|
||||
uint64 sz1;
|
||||
if((sz1 = uvmalloc(pagetable, sz, ph.vaddr + ph.memsz)) == 0)
|
||||
goto bad;
|
||||
sz = sz1;
|
||||
if(ph.vaddr % PGSIZE != 0)
|
||||
goto bad;
|
||||
if(loadseg(pagetable, ph.vaddr, ip, ph.off, ph.filesz) < 0)
|
||||
|
|
|
@ -235,8 +235,7 @@ uvmalloc(pagetable_t pagetable, uint64 oldsz, uint64 newsz)
|
|||
return oldsz;
|
||||
|
||||
oldsz = PGROUNDUP(oldsz);
|
||||
a = oldsz;
|
||||
for(; a < newsz; a += PGSIZE){
|
||||
for(a = oldsz; a < newsz; a += PGSIZE){
|
||||
mem = kalloc();
|
||||
if(mem == 0){
|
||||
uvmdealloc(pagetable, a, oldsz);
|
||||
|
|
Loading…
Reference in a new issue