Forráskód Böngészése

cannot compile, error with passing a function pointer in fork

tarfeef101 6 éve
szülő
commit
7d97cb9768

+ 0 - 0
build/kern


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

@@ -1,4 +1,4 @@
-http://git.tareef.tech/tarfeef101/cs350/src/master/kern/include/syscall.h/*
+/*
  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  *	The President and Fellows of Harvard College.
  *
@@ -179,8 +179,12 @@ syscall(struct trapframe * tf)
  *
  * Thus, you can trash it and do things another way if you prefer.
  */
-void
-enter_forked_process(struct trapframe * tf)
+void enter_forked_process(void * trap)
 {
-	(void)tf;
+	struct trapframe * tf = (struct trapframe *)trap;
+	struct trapframe childframe = *tf;
+	childframe.tf_v0 = 0;
+	childframe.tf_epc += 4;
+	childframe.tf_a3 = 0;
+	mips_usermode(&childTf);
 }

+ 4 - 4
kern/compile/ASST2/.depend

@@ -302,7 +302,7 @@ proc.o: ../../proc/proc.c ../../include/types.h \
   ../../include/current.h includelinks/machine/current.h \
   ../../include/addrspace.h ../../include/vm.h includelinks/machine/vm.h \
   ../../include/vnode.h ../../include/vfs.h ../../include/synch.h \
-  ../../include/kern/fcntl.h
+  ../../include/kern/fcntl.h ../../include/kern/errno.h
 main.o: ../../startup/main.c ../../include/types.h \
   ../../include/kern/types.h includelinks/kern/machine/types.h \
   includelinks/machine/types.h ../../include/kern/errno.h \
@@ -364,8 +364,8 @@ proc_syscalls.o: ../../syscall/proc_syscalls.c ../../include/types.h \
   ../../include/kern/types.h includelinks/kern/machine/types.h \
   includelinks/machine/types.h ../../include/kern/errno.h \
   ../../include/kern/unistd.h ../../include/kern/wait.h \
-  ../../include/lib.h ../../include/cdefs.h opt-noasserts.h \
-  ../../include/syscall.h ../../include/current.h \
+  includelinks/mips/trapframe.h ../../include/lib.h ../../include/cdefs.h \
+  opt-noasserts.h ../../include/syscall.h ../../include/current.h \
   includelinks/machine/current.h ../../include/thread.h \
   ../../include/array.h ../../include/spinlock.h \
   includelinks/machine/spinlock.h ../../include/threadlist.h \
@@ -373,7 +373,7 @@ proc_syscalls.o: ../../syscall/proc_syscalls.c ../../include/types.h \
   includelinks/kern/machine/setjmp.h ../../include/proc.h \
   ../../include/limits.h ../../include/kern/limits.h ../../include/list.h \
   ../../include/addrspace.h ../../include/vm.h includelinks/machine/vm.h \
-  ../../include/copyinout.h
+  ../../include/copyinout.h ../../include/synch.h
 runprogram.o: ../../syscall/runprogram.c ../../include/types.h \
   ../../include/kern/types.h includelinks/kern/machine/types.h \
   includelinks/machine/types.h ../../include/kern/errno.h \

+ 5 - 5
kern/include/addrspace.h

@@ -1,4 +1,4 @@
-justify the means construct/*
+/*
  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  *	The President and Fellows of Harvard College.
  *
@@ -40,7 +40,7 @@ justify the means construct/*
 struct vnode;
 
 
-/* 
+/*
  * Address space - data structure associated with the virtual memory
  * space of a process.
  *
@@ -61,7 +61,7 @@ struct addrspace
 /*
  * Functions in addrspace.c:
  *
- *    as_create - create a new empty address space. You need to make 
+ *    as_create - create a new empty address space. You need to make
  *                sure this gets called in justify the means constructall the right places. You
  *                may find you want to change the argument list. May
  *                return NULL on out-of-memory error.
@@ -100,9 +100,9 @@ void              as_activate(void);
 void              as_deactivate(void);
 void              as_destroy(struct addrspace *);
 
-int               as_define_region(struct addrspace *as, 
+int               as_define_region(struct addrspace *as,
                                    vaddr_t vaddr, size_t sz,
-                                   int readable, 
+                                   int readable,
                                    int writeable,
                                    int executable);
 int               as_prepare_load(struct addrspace *as);

+ 1 - 7
kern/include/proc.h

@@ -89,7 +89,7 @@ struct procs
 extern struct proc * kproc;
 
 // The process array
-extern struct procs * procs;
+extern struct procs * processes;
 
 // The lock for the above array
 extern struct lock * proclock;
@@ -105,9 +105,6 @@ void proc_bootstrap(void);
 /* Create a fresh process for use by runprogram(). */
 struct proc *proc_create_runprogram(const char * name);// get and return a pid for the process
 
-// de-allocates procs' contents (i.e. lock)
-void delete_procs(struct procs * procs);
-
 /* Destroy a process. */
 void proc_destroy(struct proc * proc);
 
@@ -129,8 +126,5 @@ int assignpid(struct proc * proc);
 // returns the child process if it is a child, otherwise null
 struct proc * getChild(struct proc * p, int pid);
 
-// de-allocates procs' contents (i.e. lock)
-void delete_procs(struct procs * procs);
-
 
 #endif /* _PROC_H_ */

+ 25 - 14
kern/proc/proc.c

@@ -52,6 +52,8 @@
 #include <kern/fcntl.h>
 #include <list.h>
 #include <limits.h>
+#include <kern/errno.h>
+
 typedef struct list list;
 typedef struct procs procs;
 
@@ -59,7 +61,7 @@ typedef struct procs procs;
 struct proc * kproc;
 
 // The process array
-procs * procs;
+procs * processes;
 
 // The lock for the above array
 struct lock * proclock;
@@ -127,32 +129,32 @@ static struct proc * proc_create(const char * name)
 	return proc;
 }
 
-static procs * create_procs(void)
+/*static procs * create_procs(void)
 {
   procs * temp = kmalloc(sizeof procs);
   if (!(temp)) panic("Could not create process list!\n");
   temp->lastpid = PID_MIN - 1;
   return temp;
-}
+}*/
 
-proc * getChild(struct proc * p, int pid)
+struct proc * getChild(struct proc * p, int pid)
 {
   int result = listearch(p->kids, pid);
   
   if (!(result)) return NULL;
-  return procs->pids[pid];
+  return processes->pids[pid];
 }
 
 int assignpid(struct proc * proc)
 {
   lock_acquire(proclock);
   
-  for (int i = procs->lastpid + 1; i <= PID_MAX; i++)
+  for (int i = processes->lastpid + 1; i <= PID_MAX; i++)
   {
-    if (procs->pids[i] == 0)
+    if (processes->pids[i] == 0)
     {
       proc->pid = i;
-      procs->lastpid = i;
+      processes->lastpid = i;
       lock_release(proclock);
       return i;
     }
@@ -163,19 +165,22 @@ int assignpid(struct proc * proc)
       continue;
     }
     
-    if (i == procs->lastpid)
+    if (i == processes->lastpid)
     {
       lock_release(proclock);
       return ENPROC;
     }
   }
+  
+  return ENPROC;
 }
 
-void delete_procs(procs * procs)
+/*
+static void delete_procs()
 {
-  kfree(procs->pids);
+  kfree(processes->pids);
   lock_destroy(proclock);
-}
+}*/
 
 /*
  * Destroy a proc structure.
@@ -240,7 +245,7 @@ void proc_destroy(struct proc * proc)
 	spinlock_cleanup(&proc->p_lock);
 
   lock_acquire(proclock);
-  procs->pids[proc->pid] = 0; // update available PIDs
+  processes->pids[proc->pid] = 0; // update available PIDs
   lock_release(proclock);
 	kfree(proc->p_name);
 	kfree(proc);
@@ -288,6 +293,12 @@ void proc_bootstrap(void)
     panic("could not create no_proc_sem semaphore\n");
   }
 #endif // UW
+  
+  int processesLen = PID_MAX - PID_MIN + 1;
+  for (int i = 0; i < processesLen; i++)
+  {
+    processes->pids[i] = 0;
+  }
 }
 
 /*
@@ -352,7 +363,7 @@ struct proc * proc_create_runprogram(const char * name)
            are created using a call to proc_create_runprogram  */
 	P(proc_count_mutex);
 	proc_count++;
-	assignpid(struct proc * proc);
+	assignpid(proc);
 	V(proc_count_mutex);
 #endif // UW
 

+ 6 - 5
kern/syscall/proc_syscalls.c

@@ -2,6 +2,7 @@
 #include <kern/errno.h>
 #include <kern/unistd.h>
 #include <kern/wait.h>
+#include <mips/trapframe.h>
 #include <lib.h>
 #include <syscall.h>
 #include <current.h>
@@ -9,6 +10,7 @@
 #include <thread.h>
 #include <addrspace.h>
 #include <copyinout.h>
+#include <synch.h>
 
   /* this implementation of sys__exit does not do anything with the exit code */
   /* this needs to be fixed to get exit() and waitpid() working properly */
@@ -39,7 +41,7 @@ void sys__exit(int exitcode)
   /* detach this thread from its process */
   /* note: curproc cannot be used after this call */
   proc_remthread(curthread);
-
+
   /* if this is the last user process in the system, proc_destroy()
      will wake up the kernel menu thread */
   proc_destroy(p);
@@ -68,7 +70,7 @@ int sys_waitpid(pid_t pid, userptr_t status, int options, pid_t * retval)
      exit status of 0, regardless of the actual exit status of
      the specified process.
      In fact, this will return 0 even if the specified process
-     is still running, and even if it never existed in the first place.
+     is still running, and even if #include <kern/wait.h>it never existed in the first place.
 
      Fix this!
   */
@@ -95,8 +97,8 @@ int sys_fork(struct trapframe * tf, int * retval)
   struct addrspace * new_as;
   struct trapframe * new_tf = kmalloc(sizeof(*tf));
   
-  if ((!child) return ENOMEM;
-  as_copy(curproc_getas(), &childAddrspace);
+  if ((!child)) return ENOMEM;
+  as_copy(curproc_getas(), &new_as);
   
   if (!(new_as) || !(new_tf))
   {
@@ -106,7 +108,6 @@ int sys_fork(struct trapframe * tf, int * retval)
     return ENOMEM;
   }
   
-  // might want to handle inserting PID into overall struct here. perhaps a setpid function or something in proc_create_runprogram...
   // set PIDs, etc. copy data in to the new space
   child->p_addrspace = new_as;
   child->parent = curproc;