even more fabulous exec
This commit is contained in:
parent
06feabecee
commit
2ea6c764c3
1 changed files with 8 additions and 19 deletions
27
exec.c
27
exec.c
|
@ -81,30 +81,19 @@ exec(char *path, char **argv)
|
||||||
copyout(pgdir, sp, argv[i], strlen(argv[i]) + 1);
|
copyout(pgdir, sp, argv[i], strlen(argv[i]) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// push 0 for argv[argc]
|
#define PUSH(x) { int xx = (int)(x); sp -= 4; copyout(pgdir, sp, &xx, 4); }
|
||||||
sp -= 4;
|
|
||||||
int zero = 0;
|
PUSH(0); // argv[argc] is zero
|
||||||
copyout(pgdir, sp, &zero, 4);
|
|
||||||
|
|
||||||
// push argv[] elements
|
// push argv[] elements
|
||||||
for(i = argc - 1; i >= 0; --i){
|
for(i = argc - 1; i >= 0; --i)
|
||||||
sp -= 4;
|
PUSH(strings[i]);
|
||||||
copyout(pgdir, sp, &strings[i], 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// push argv
|
PUSH(sp); // argv
|
||||||
uint argvaddr = sp;
|
|
||||||
sp -= 4;
|
|
||||||
copyout(pgdir, sp, &argvaddr, 4);
|
|
||||||
|
|
||||||
// push argc
|
PUSH(argc);
|
||||||
sp -= 4;
|
|
||||||
copyout(pgdir, sp, &argc, 4);
|
|
||||||
|
|
||||||
// push 0 in case main returns
|
PUSH(0xffffffff); // in case main tries to return
|
||||||
sp -= 4;
|
|
||||||
uint ffffffff = 0xffffffff;
|
|
||||||
copyout(pgdir, sp, &ffffffff, 4);
|
|
||||||
|
|
||||||
if(sp < sz - PGSIZE)
|
if(sp < sz - PGSIZE)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
Loading…
Reference in a new issue