]> Devi Nivas Git - cs3210-lab1.git/commitdiff
even more fabulous exec
authorRobert Morris <rtm@csail.mit.edu>
Wed, 29 Sep 2010 18:12:26 +0000 (14:12 -0400)
committerRobert Morris <rtm@csail.mit.edu>
Wed, 29 Sep 2010 18:12:26 +0000 (14:12 -0400)
exec.c

diff --git a/exec.c b/exec.c
index c0ea51526f95fe48ce17b07e0354b25afc2b94cd..1673a3813ff955d020736d2736d8771742e2de28 100644 (file)
--- 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;