Skip to content

Commit

Permalink
exec tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Jul 13, 2009
1 parent fd8e368 commit b3bebfc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ exec(char *path, char **argv)
struct inode *ip;
struct proghdr ph;

mem = 0;
sz = 0;

if((ip = namei(path)) == 0)
return -1;
ilock(ip);

// Compute memory size of new process.
mem = 0;
sz = 0;

// Program segments.
// Check ELF header
if(readi(ip, (char*)&elf, 0, sizeof(elf)) < sizeof(elf))
goto bad;
if(elf.magic != ELF_MAGIC)
goto bad;

// Compute memory size of new process.
// Program segments.
for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
if(readi(ip, (char*)&ph, off, sizeof(ph)) != sizeof(ph))
goto bad;
Expand All @@ -44,7 +46,10 @@ exec(char *path, char **argv)
for(argc=0; argv[argc]; argc++)
arglen += strlen(argv[argc]) + 1;
arglen = (arglen+3) & ~3;
sz += arglen + 4*(argc+1);
sz += arglen;
sz += 4*(argc+1); // argv data
sz += 4; // argv
sz += 4; // argc

// Stack.
sz += PAGE;
Expand Down

0 comments on commit b3bebfc

Please sign in to comment.