|
@@ -50,12 +50,11 @@ void sys__exit(int exitcode)
|
|
|
}
|
|
|
|
|
|
|
|
|
-/* stub handler for getpid() system call */
|
|
|
+// basically, return an error code, and put the actual result in retval
|
|
|
int sys_getpid(pid_t * retval)
|
|
|
{
|
|
|
- /* for now, this is just a stub that always returns a PID of 1 */
|
|
|
- /* you need to fix this to make it work properly */
|
|
|
- *retval = 1;
|
|
|
+ if (!(curproc)) return 1;
|
|
|
+ *retval = curproc->pid;
|
|
|
return(0);
|
|
|
}
|
|
|
|
|
@@ -90,3 +89,35 @@ int sys_waitpid(pid_t pid, userptr_t status, int options, pid_t * retval)
|
|
|
return(0);
|
|
|
}
|
|
|
|
|
|
+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;
|
|
|
+ as_copy(curproc_getas(), &childAddrspace);
|
|
|
+
|
|
|
+ if (!(new_as) || !(new_tf))
|
|
|
+ {
|
|
|
+ proc_destroy(child);
|
|
|
+ kfree(new_as);
|
|
|
+ kfree(new_tf);
|
|
|
+ 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;
|
|
|
+ *new_tf = *tf;
|
|
|
+
|
|
|
+ // start new thread
|
|
|
+ thread_fork("childproc", child, enter_forked_process, new_tf, 0);
|
|
|
+
|
|
|
+ // return correct values
|
|
|
+ if (curproc->pid == child->pid) *retval = 0;
|
|
|
+ else *retval = child->pid;
|
|
|
+ return 0;
|
|
|
+}
|