exec tweaks
This commit is contained in:
parent
fd8e368101
commit
b3bebfce8a
1 changed files with 11 additions and 6 deletions
17
exec.c
17
exec.c
|
@ -16,19 +16,21 @@ exec(char *path, char **argv)
|
||||||
struct inode *ip;
|
struct inode *ip;
|
||||||
struct proghdr ph;
|
struct proghdr ph;
|
||||||
|
|
||||||
|
mem = 0;
|
||||||
|
sz = 0;
|
||||||
|
|
||||||
if((ip = namei(path)) == 0)
|
if((ip = namei(path)) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
ilock(ip);
|
ilock(ip);
|
||||||
|
|
||||||
// Compute memory size of new process.
|
// Check ELF header
|
||||||
mem = 0;
|
|
||||||
sz = 0;
|
|
||||||
|
|
||||||
// Program segments.
|
|
||||||
if(readi(ip, (char*)&elf, 0, sizeof(elf)) < sizeof(elf))
|
if(readi(ip, (char*)&elf, 0, sizeof(elf)) < sizeof(elf))
|
||||||
goto bad;
|
goto bad;
|
||||||
if(elf.magic != ELF_MAGIC)
|
if(elf.magic != ELF_MAGIC)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
||||||
|
// Compute memory size of new process.
|
||||||
|
// Program segments.
|
||||||
for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
|
for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
|
||||||
if(readi(ip, (char*)&ph, off, sizeof(ph)) != sizeof(ph))
|
if(readi(ip, (char*)&ph, off, sizeof(ph)) != sizeof(ph))
|
||||||
goto bad;
|
goto bad;
|
||||||
|
@ -44,7 +46,10 @@ exec(char *path, char **argv)
|
||||||
for(argc=0; argv[argc]; argc++)
|
for(argc=0; argv[argc]; argc++)
|
||||||
arglen += strlen(argv[argc]) + 1;
|
arglen += strlen(argv[argc]) + 1;
|
||||||
arglen = (arglen+3) & ~3;
|
arglen = (arglen+3) & ~3;
|
||||||
sz += arglen + 4*(argc+1);
|
sz += arglen;
|
||||||
|
sz += 4*(argc+1); // argv data
|
||||||
|
sz += 4; // argv
|
||||||
|
sz += 4; // argc
|
||||||
|
|
||||||
// Stack.
|
// Stack.
|
||||||
sz += PAGE;
|
sz += PAGE;
|
||||||
|
|
Loading…
Reference in a new issue