I hate failed merges
authorAndrew Waterman <waterman@parcad.millennium.berkeley.edu>
Wed, 27 Jan 2010 21:37:57 +0000 (13:37 -0800)
committerAndrew Waterman <waterman@parcad.millennium.berkeley.edu>
Wed, 27 Jan 2010 21:37:57 +0000 (13:37 -0800)
1  2 
kern/src/syscall.c

@@@ -117,21 -335,53 +336,53 @@@ static ssize_t sys_fork(env_t* e
                        assert(upage_alloc(env,&pp,0) == 0);
                        assert(page_insert(env->env_pgdir,pp,va,perms) == 0);
  
-                       pte_t* pte = pgdir_walk(e->env_pgdir,va,0);
-                       assert(pte);
-                       pagecopy(page2kva(pp),ppn2kva(PTE2PPN(*pte)));
-               }
+                       pte_t* pte = pgdir_walk(e->env_pgdir,va,0);
+                       assert(pte);
+                       pagecopy(page2kva(pp),ppn2kva(PTE2PPN(*pte)));
+               }
+       }
+       __proc_set_state(env, PROC_RUNNABLE_S);
+       schedule_proc(env);
+       // don't decref the new process.
+       // that will happen when the parent waits for it.
+       printd("[PID %d] fork PID %d\n",e->pid,env->pid);
+       return env->pid;
+ }
+ static ssize_t sys_exec(env_t* e, void *DANGEROUS binary_buf, size_t len,
 -                        void*DANGEROUS arg, void*DANGEROUS env)
++                        procinfo_t*DANGEROUS procinfo)
+ {
+       // TODO: right now we only support exec for single-core processes
+       if(e->state != PROC_RUNNING_S)
+               return -1;
 -      if(memcpy_from_user(e,e->env_procinfo->argv_buf,arg,PROCINFO_MAX_ARGV_SIZE))
 -              return -1;
 -      if(memcpy_from_user(e,e->env_procinfo->env_buf,env,PROCINFO_MAX_ENV_SIZE))
++      if(memcpy_from_user(e,e->env_procinfo,procinfo,sizeof(*procinfo)))
+               return -1;
+       void* binary = kmalloc(len,0);
+       if(binary == NULL)
+               return -1;
+       if(memcpy_from_user(e,binary,binary_buf,len))
+       {
+               kfree(binary);
+               return -1;
        }
  
-       __proc_set_state(env, PROC_RUNNABLE_S);
-       schedule_proc(env);
-       // don't decref the new process.
-       // that will happen when the parent waits for it.
 -      // TODO: this breaks with mmap
 -      env_segment_free(e,0,(intptr_t)e->heap_top);
 -      env_segment_free(e,(void*)USTACKBOT,USTACKTOP-USTACKBOT);
++      // TODO: this is slow but correct.
++      // don't skip any va's so exec behaves right
++      env_segment_free(e,0,USTACKTOP);
++      //env_segment_free(e,0,ROUNDUP((intptr_t)e->heap_top,PGSIZE));
++      //env_segment_free(e,(void*)USTACKBOT,USTACKTOP-USTACKBOT);
  
-       printd("[PID %d] fork PID %d\n",e->pid,env->pid);
+       proc_init_trapframe(current_tf,0);
+       env_load_icode(e,NULL,binary,len);
  
-       return env->pid;
+       kfree(binary);
+       return 0;
  }
  
  static ssize_t sys_trywait(env_t* e, pid_t pid, int* status)