Selaa lähdekoodia

got execv mostly working... arg2 and argc are kinda off with argtestest

tarfeef101 6 vuotta sitten
vanhempi
commit
11fc2beeac

BIN
kern/compile/ASST2/kernel


+ 1 - 1
kern/compile/ASST2/vers.c

@@ -1,3 +1,3 @@
 /* This file is automatically generated. Edits will be lost.*/
-const int buildversion = 159;
+const int buildversion = 216;
 const char buildconfig[] = "ASST2";

+ 1 - 1
kern/compile/ASST2/version

@@ -1 +1 @@
-159
+216

+ 15 - 18
kern/syscall/proc_syscalls.c

@@ -197,38 +197,37 @@ int sys_execv(const char * program, userptr_t args)
   userptr_t temp = args;
   int argcount = 0;
   int errcode; // why don't we have errno!!! my beautful one-liners!!!
-
+  
   // see how long args is
   while (1)
   {
-    char * temp2;
-    errcode = copyin(temp, temp2, sizeof(char *));
+    void * temp2 = kmalloc(sizeof(temp));
+    errcode = copyin(temp, temp2, sizeof(temp2));
     if (errcode) return errcode;
-    if (!(temp2)) break;
-    temp += sizeof(char *);
+    if (!(*(char **)temp2)) break;
+    temp += sizeof(temp);
+    kfree(temp2);
     ++argcount;
   }
-  
+
   // allocate space for argv
   char ** argv = kmalloc(argcount * sizeof(char *));
   if (!argv) return ENOMEM;
-  
+
   // get kernel copy of args in argv
   temp = args;
   for (int i = 0; i < argcount; ++i)
   {
-    char * useraddr;
-
+    char * useraddr = kmalloc(sizeof(temp));
     // useraddr is now the address of the string in userland
-    errcode = copyin(temp, useraddr, sizeof(char *));
+    errcode = copyin(temp, useraddr, sizeof(temp));
     if (errcode)
     {
       kfree(argv);
       return errcode;
     }
- 
     // change argv[i] to be a string of length enough
-    int strLen = strlen(useraddr) + 1;
+    int strLen = strlen(*(char **)useraddr) + 1;
     size_t wasteOfSpace;
     argv[i] = kmalloc(strLen * sizeof(char));
     if (!(argv[i]))
@@ -237,16 +236,16 @@ int sys_execv(const char * program, userptr_t args)
       kfree(argv);
       return ENOMEM;
     }
-    errcode = copyinstr(temp, argv[i], strLen, &wasteOfSpace);
+    errcode = copyinstr((userptr_t)*(char **)temp, argv[i], strLen, &wasteOfSpace);
     if (errcode)
     {
       freeArgv(argv, i);
       kfree(argv);
       return errcode;
     }
-    temp += sizeof(char *);
+    temp += sizeof(temp);
   }
-  
+
   // allocate space for filepath
   char * filepath = kmalloc(sizeof(program));
   if (!(filepath))
@@ -324,6 +323,7 @@ int sys_execv(const char * program, userptr_t args)
     return errcode;
   }
 
+  // put args into the stack
   userptr_t userV;
   errcode = copyArgs(argcount, argv, &userV, &newstack);
   if (errcode)
@@ -336,14 +336,11 @@ int sys_execv(const char * program, userptr_t args)
     return errcode;
   }
   
-  // need to copy data over into the new address space, as rn it is all in kernel heap
-
   // delete old addrspace, enter new process
   as_destroy(oldas);
   kfree(filepath);
   freeArgv(argv, argcount - 1);
   kfree(argv);
-  //kprintf("agrc: %d, userv: %p, stack: %p, entry: %p\n", argcount, userV, (void *)newstack, (void *)entrypoint);
   enter_new_process(argcount, userV, newstack, entrypoint);
   panic("Enter new process returned!\n");
   return EINVAL;