proc.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2013
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _PROC_H_
  30. #define _PROC_H_
  31. /*
  32. * Definition of a process.
  33. *
  34. * Note: curproc is defined by <current.h>.
  35. */
  36. #include <spinlock.h>
  37. #include <thread.h> /* required for struct threadarray */
  38. struct addrspace;
  39. struct vnode;
  40. #ifdef UW
  41. struct semaphore;
  42. #endif // UW
  43. /*
  44. * Process structure.
  45. */
  46. struct proc {
  47. char *p_name; /* Name of this process */
  48. struct spinlock p_lock; /* Lock for this structure */
  49. struct threadarray p_threads; /* Threads in this process */
  50. /* VM */
  51. struct addrspace *p_addrspace; /* virtual address space */
  52. /* VFS */
  53. struct vnode *p_cwd; /* current working directory */
  54. #ifdef UW
  55. /* a vnode to refer to the console device */
  56. /* this is a quick-and-dirty way to get console writes working */
  57. /* you will probably need to change this when implementing file-related
  58. system calls, since each process will need to keep track of all files
  59. it has opened, not just the console. */
  60. struct vnode *console; /* a vnode for the console device */
  61. #endif
  62. /* add more material here as needed */
  63. };
  64. /* This is the process structure for the kernel and for kernel-only threads. */
  65. extern struct proc *kproc;
  66. /* Semaphore used to signal when there are no more processes */
  67. #ifdef UW
  68. extern struct semaphore *no_proc_sem;
  69. #endif // UW
  70. /* Call once during system startup to allocate data structures. */
  71. void proc_bootstrap(void);
  72. /* Create a fresh process for use by runprogram(). */
  73. struct proc *proc_create_runprogram(const char *name);
  74. /* Destroy a process. */
  75. void proc_destroy(struct proc *proc);
  76. /* Attach a thread to a process. Must not already have a process. */
  77. int proc_addthread(struct proc *proc, struct thread *t);
  78. /* Detach a thread from its process. */
  79. void proc_remthread(struct thread *t);
  80. /* Fetch the address space of the current process. */
  81. struct addrspace *curproc_getas(void);
  82. /* Change the address space of the current process, and return the old one. */
  83. struct addrspace *curproc_setas(struct addrspace *);
  84. #endif /* _PROC_H_ */