commit 2ea6c764c34d3025b5f3121a0919fda7d1eb9b01
parent 06feabeceeccc8dbd2658e9f10dd139c14f01ba6
Author: Robert Morris <rtm@csail.mit.edu>
Date: Wed, 29 Sep 2010 14:12:26 -0400
even more fabulous exec
Diffstat:
M | exec.c | | | 27 | ++++++++------------------- |
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/exec.c b/exec.c
@@ -81,30 +81,19 @@ exec(char *path, char **argv)
copyout(pgdir, sp, argv[i], strlen(argv[i]) + 1);
}
- // push 0 for argv[argc]
- sp -= 4;
- int zero = 0;
- copyout(pgdir, sp, &zero, 4);
+#define PUSH(x) { int xx = (int)(x); sp -= 4; copyout(pgdir, sp, &xx, 4); }
+
+ PUSH(0); // argv[argc] is zero
// push argv[] elements
- for(i = argc - 1; i >= 0; --i){
- sp -= 4;
- copyout(pgdir, sp, &strings[i], 4);
- }
+ for(i = argc - 1; i >= 0; --i)
+ PUSH(strings[i]);
- // push argv
- uint argvaddr = sp;
- sp -= 4;
- copyout(pgdir, sp, &argvaddr, 4);
+ PUSH(sp); // argv
- // push argc
- sp -= 4;
- copyout(pgdir, sp, &argc, 4);
+ PUSH(argc);
- // push 0 in case main returns
- sp -= 4;
- uint ffffffff = 0xffffffff;
- copyout(pgdir, sp, &ffffffff, 4);
+ PUSH(0xffffffff); // in case main tries to return
if(sp < sz - PGSIZE)
goto bad;