proc_syscalls.c 2.3 KB

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