root/kern/syscall/proc_syscalls.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys__exit
  2. sys_getpid
  3. sys_waitpid

   1 #include <types.h>
   2 #include <kern/errno.h>
   3 #include <kern/unistd.h>
   4 #include <kern/wait.h>
   5 #include <lib.h>
   6 #include <syscall.h>
   7 #include <current.h>
   8 #include <proc.h>
   9 #include <thread.h>
  10 #include <addrspace.h>
  11 #include <copyinout.h>
  12 
  13   /* this implementation of sys__exit does not do anything with the exit code */
  14   /* this needs to be fixed to get exit() and waitpid() working properly */
  15 
  16 void sys__exit(int exitcode) {
  17 
  18   struct addrspace *as;
  19   struct proc *p = curproc;
  20   /* for now, just include this to keep the compiler from complaining about
  21      an unused variable */
  22   (void)exitcode;
  23 
  24   DEBUG(DB_SYSCALL,"Syscall: _exit(%d)\n",exitcode);
  25 
  26   KASSERT(curproc->p_addrspace != NULL);
  27   as_deactivate();
  28   /*
  29    * clear p_addrspace before calling as_destroy. Otherwise if
  30    * as_destroy sleeps (which is quite possible) when we
  31    * come back we'll be calling as_activate on a
  32    * half-destroyed address space. This tends to be
  33    * messily fatal.
  34    */
  35   as = curproc_setas(NULL);
  36   as_destroy(as);
  37 
  38   /* detach this thread from its process */
  39   /* note: curproc cannot be used after this call */
  40   proc_remthread(curthread);
  41 
  42   /* if this is the last user process in the system, proc_destroy()
  43      will wake up the kernel menu thread */
  44   proc_destroy(p);
  45   
  46   thread_exit();
  47   /* thread_exit() does not return, so we should never get here */
  48   panic("return from thread_exit in sys_exit\n");
  49 }
  50 
  51 
  52 /* stub handler for getpid() system call                */
  53 int
  54 sys_getpid(pid_t *retval)
  55 {
  56   /* for now, this is just a stub that always returns a PID of 1 */
  57   /* you need to fix this to make it work properly */
  58   *retval = 1;
  59   return(0);
  60 }
  61 
  62 /* stub handler for waitpid() system call                */
  63 
  64 int
  65 sys_waitpid(pid_t pid,
  66             userptr_t status,
  67             int options,
  68             pid_t *retval)
  69 {
  70   int exitstatus;
  71   int result;
  72 
  73   /* this is just a stub implementation that always reports an
  74      exit status of 0, regardless of the actual exit status of
  75      the specified process.   
  76      In fact, this will return 0 even if the specified process
  77      is still running, and even if it never existed in the first place.
  78 
  79      Fix this!
  80   */
  81 
  82   if (options != 0) {
  83     return(EINVAL);
  84   }
  85   /* for now, just pretend the exitstatus is 0 */
  86   exitstatus = 0;
  87   result = copyout((void *)&exitstatus,status,sizeof(int));
  88   if (result) {
  89     return(result);
  90   }
  91   *retval = pid;
  92   return(0);
  93 }
  94 

/* [<][>][^][v][top][bottom][index][help] */