Browse Source

added a script for non-complete building. also, fixed sys exit. issue was not deleting children that are zombies when parents die. i do that now

tarfeef101 6 years ago
parent
commit
41d0d447bd

+ 9 - 0
fastscript.sh

@@ -0,0 +1,9 @@
+#!/bin/bash
+set -eu
+topdir=$(pwd)
+cd ./kern/compile/ASST$1
+bmake depend
+bmake
+bmake install
+echo "SUCCESS!!!!!!!!!!"
+echo ""

+ 3 - 4
kern/arch/mips/syscall/syscall.c

@@ -130,12 +130,11 @@ syscall(struct trapframe * tf)
 			    (int)tf->tf_a2,
 			    (pid_t *)&retval);
 	  break;
-	case SYS_fork:
-	  err = sys_fork(tf, (pid_t*)&retval);
-	  break;
 #endif // UW
 
-	    /* Add stuff here */
+	 case SYS_fork:
+	  err = sys_fork(tf, (pid_t*)&retval);
+	  break;
  
 	default:
 	  kprintf("Unknown syscall %d\n", callno);

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 = 72;
+const int buildversion = 122;
 const char buildconfig[] = "ASST2";

+ 1 - 1
kern/compile/ASST2/version

@@ -1 +1 @@
-72
+122

+ 9 - 20
kern/proc/proc.c

@@ -124,7 +124,7 @@ static struct proc * proc_create(const char * name)
 #endif // UW
 
   // My additions
-  proc->pid =0;
+  proc->pid = 0;
   proc->parent = NULL;
   proc->exitcode = -1;
 
@@ -198,15 +198,6 @@ static void delete_procs()
  */
 void proc_destroy(struct proc * proc)
 {
-	/*
-         * note: some parts of the process structure, such as the address space,
-         *  are destroyed in sys_exit, before we get here
-         *
-         * note: depending on where this function is called from, curproc may not
-         * be defined because the calling thread may have already detached itself
-         * from the process.
-	 */
-
 	KASSERT(proc != NULL);
 	KASSERT(proc != kproc);
 
@@ -216,15 +207,15 @@ void proc_destroy(struct proc * proc)
 	 * incorrect to destroy it.)
 	 */
 	/* VFS fields */
-/*	if (proc->p_cwd)
+	if (proc->p_cwd)
 	{
 		VOP_DECREF(proc->p_cwd);
 		proc->p_cwd = NULL;
-	}*/
+	}
 
-/*#ifndef UW  // in the UW version, space destruction occurs in sys_exit, not here
+#ifndef UW  // in the UW version, space destruction occurs in sys_exit, not here
 	if (proc->p_addrspace)
-	{*/
+	{
 		/*
 		 * In case p is the currently running process (which
 		 * it might be in some circumstances, or if this code
@@ -235,27 +226,25 @@ void proc_destroy(struct proc * proc)
 		 * half-destroyed address space. This tends to be
 		 * messily fatal.
 		 */
-/*		struct addrspace * as;
+		struct addrspace * as;
 
 		as_deactivate();
 		as = curproc_setas(NULL);
 		as_destroy(as);
 	}
-#endif  UW */
+#endif // UW
 /*
 #ifdef UW
 	if (proc->console)
 	{
 	  vfs_close(proc->console);
 	}
-#endif // UW*/
+#endif // UW */
 
 	//threadarray_cleanup(&proc->p_threads);
-	//spinlock_cleanup(&proc->p_lock);
   lock_acquire(proclock);
   processes->pids[proc->pid] = NULL; // update available PIDs
   lock_release(proclock);
-  //listelete(proc->kids);
   lock_destroy(proc->waitlock);
   cv_destroy(proc->waiting);
 	kfree(proc->p_name);
@@ -284,6 +273,7 @@ void proc_destroy(struct proc * proc)
  */
 void proc_bootstrap(void)
 {
+  processes = create_procs();
   kproc = proc_create("[kernel]");
   if (kproc == NULL)
   {
@@ -303,7 +293,6 @@ void proc_bootstrap(void)
   }
 #endif // UW
   
-  processes = create_procs();
   int processesLen = PID_MAX;
   for (int i = 0; i < processesLen; i++)
   {

+ 125 - 28
kern/syscall/proc_syscalls.c

@@ -88,7 +88,7 @@ void(exit)
   // thread_exit() does not return, so we should never get here
   panic("return from thread_exit in sys_exit\n");
 }*/
-
+/*
 void sys__exit(int exitcode)
 {
   struct addrspace * as;
@@ -96,7 +96,19 @@ void sys__exit(int exitcode)
   p->exitcode = exitcode;
   DEBUG(DB_SYSCALL,"Syscall: _exit(%d)\n",exitcode);
   KASSERT(curproc->p_addrspace != NULL);
-	/* VFS fields */
+  
+  lock_acquire(proclock);
+  int x = listpop(p->kids);
+  while (x)
+  {
+    processes->pids[x]->parent = NULL;
+    x = listpop(p->kids);
+  }
+  lock_release(proclock);
+  
+  listelete(p->kids);
+  
+	// VFS fields
 	if (p->p_cwd)
 	{
 		VOP_DECREF(p->p_cwd);
@@ -112,42 +124,84 @@ void sys__exit(int exitcode)
 	  vfs_close(p->console);
 	}
 
-  /* detach this thread from its process */
-  /* note: curproc cannot be used after this call */
+  // detach this thread from its process
+  // note: curproc cannot be used after this call
   proc_remthread(curthread);
 
+  threadarray_cleanup(&p->p_threads);
+	spinlock_cleanup(&p->p_lock);
+
+	lock_acquire(p->waitlock);
+  cv_broadcast(p->waiting, p->waitlock);
+  lock_release(p->waitlock);
+
+  
+  //kprintf("parent is %p\n", p->parent);
+  //if (p->parent) kprintf("parent exitcode is %d\n", p->parent->exitcode);
+  //if (p->parent) kprintf("parent pid is %d\n", p->parent->pid);
+  if (!(p->parent) || p->parent->exitcode >= 0 || p->parent == kproc) proc_destroy(p);
+  
+  thread_exit();
+  // thread_exit() does not return, so we should never get here
+  panic("return from thread_exit in sys_exit\n");
+}*/
+
+void sys__exit(int exitcode)
+{
+  struct addrspace * as;
+  struct proc * p = curproc;
+  p->exitcode = exitcode;
+  DEBUG(DB_SYSCALL,"Syscall: _exit(%d)\n",exitcode);
+  KASSERT(curproc->p_addrspace != NULL);
+  
+  lock_acquire(proclock);
   int x = listpop(p->kids);
   while (x)
   {
-    lock_acquire(proclock);
-    processes->pids[x]->parent = NULL;
-    lock_release(proclock);
+    if(processes->pids[x])
+    {
+      processes->pids[x]->parent = NULL;
+      if (processes->pids[x]->exitcode >= 0)
+      {
+        lock_release(proclock);
+        proc_destroy(processes->pids[x]);
+        lock_acquire(proclock);
+      }
+    }
     x = listpop(p->kids);
   }
-  
+  lock_release(proclock);
   listelete(p->kids);
+  
+  // VFS fields
+	if (p->p_cwd)
+	{
+		VOP_DECREF(p->p_cwd);
+		p->p_cwd = NULL;
+	}
+  
+  as_deactivate();
+  as = curproc_setas(NULL);
+  as_destroy(as);
+
+  /* detach this thread from its process */
+  /* note: curproc cannot be used after this call */
+  proc_remthread(curthread);
+
   threadarray_cleanup(&p->p_threads);
 	spinlock_cleanup(&p->p_lock);
-	
-	lock_acquire(p->waitlock);
+
+  lock_acquire(p->waitlock);
   cv_broadcast(p->waiting, p->waitlock);
   lock_release(p->waitlock);
+
+  if (!(p->parent) || p->parent->exitcode >= 0 || p->parent == kproc) proc_destroy(p);
   
-  if (!(p->parent)) proc_destroy(p);
-  else if (p->parent->exitcode >= 0)
-  {
-    proc_destroy(p);
-  }
-  
-  /* if this is the last user process in the system, proc_destroy()
-     will wake up the kernel menu thread */
-  //proc_destroy(p);
   thread_exit();
   /* thread_exit() does not return, so we should never get here */
   panic("return from thread_exit in sys_exit\n");
 }
 
-
 // basically, return an error code, and put the actual result in retval
 int sys_getpid(pid_t * retval)
 {
@@ -157,16 +211,59 @@ int sys_getpid(pid_t * retval)
 }
 
 /*
-void waitpid()
+int sys_waitpid(pid_t pid, userptr_t status, int options, pid_t * retval)
 {
-  cv_wait(kid); // if valid thing to wait on, ofc
-  fullDelete(kid);
+  int exitstatus;
+  int result;
+
+  if (options != 0) {
+    return(EINVAL);
+  }
+  for now, just pretend the exitstatus is 0
+  exitstatus = 0;
+  result = copyout((void *)&exitstatus,status,sizeof(int));
+  if (result) {
+    return(result);
+  }
+  *retval = pid;
+  return(0);
+}
+
+
+int sys_waitpid(pid_t pid, userptr_t status, int options, pid_t * retval)
+{
+  int exitstatus;
+  int result;
+  
+  (void)status;
+  if (options != 0)
+  {
+    return(EINVAL);
+  }
+  
+  if (pid < PID_MIN || pid > PID_MAX) return ESRCH;
+  struct proc * target = getChild(curproc, pid);
+  
+  if (!(target)) return ECHILD;
+  exitstatus = _MKWAIT_EXIT(target->exitcode);
+  result = copyout((void *)&exitstatus, status, sizeof(int));
+  
+  if (exitstatus >= 0)
+  {
+    // *retval = exitstatus;
+    return result;
+  }
+  
+  lock_acquire(target->waitlock);
+  cv_wait(target->waiting, target->waitlock);
+  lock_release(target->waitlock);
+  *retval = exitstatus;
+  proc_destroy(target);
+  return 0;
 }*/
 
-/* stub handler for waitpid() system call                */
 int sys_waitpid(pid_t pid, userptr_t status, int options, pid_t * retval)
 {
-  kprintf("Waiting on: %d\n", pid);
   (void)status;
   if (options != 0)
   {
@@ -195,10 +292,10 @@ int sys_fork(struct trapframe * tf, int * retval)
 {
   // create new process' memory space
   struct proc * child = proc_create_runprogram("childproc");
-  struct addrspace * new_as;
-  struct trapframe * new_tf = kmalloc(sizeof(*tf));
-  
   if ((!child)) return ENOMEM;
+  
+  struct trapframe * new_tf = kmalloc(sizeof(*tf));
+  struct addrspace * new_as;
   as_copy(curproc_getas(), &new_as);
   
   if (!(new_as) || !(new_tf))