/* [<][>][^][v][top][bottom][index][help] */
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
30 #ifndef _PROC_H_
31 #define _PROC_H_
32
33 /*
34 * Definition of a process.
35 *
36 * Note: curproc is defined by <current.h>.
37 */
38
39 #include <spinlock.h>
40 #include <thread.h> /* required for struct threadarray */
41
42 struct addrspace;
43 struct vnode;
44 #ifdef UW
45 struct semaphore;
46 #endif // UW
47
48 /*
49 * Process structure.
50 */
51 struct proc {
52 char *p_name; /* Name of this process */
53 struct spinlock p_lock; /* Lock for this structure */
54 struct threadarray p_threads; /* Threads in this process */
55
56 /* VM */
57 struct addrspace *p_addrspace; /* virtual address space */
58
59 /* VFS */
60 struct vnode *p_cwd; /* current working directory */
61
62 #ifdef UW
63 /* a vnode to refer to the console device */
64 /* this is a quick-and-dirty way to get console writes working */
65 /* you will probably need to change this when implementing file-related
66 system calls, since each process will need to keep track of all files
67 it has opened, not just the console. */
68 struct vnode *console; /* a vnode for the console device */
69 #endif
70
71 /* add more material here as needed */
72 };
73
74 /* This is the process structure for the kernel and for kernel-only threads. */
75 extern struct proc *kproc;
76
77 /* Semaphore used to signal when there are no more processes */
78 #ifdef UW
79 extern struct semaphore *no_proc_sem;
80 #endif // UW
81
82 /* Call once during system startup to allocate data structures. */
83 void proc_bootstrap(void);
84
85 /* Create a fresh process for use by runprogram(). */
86 struct proc *proc_create_runprogram(const char *name);
87
88 /* Destroy a process. */
89 void proc_destroy(struct proc *proc);
90
91 /* Attach a thread to a process. Must not already have a process. */
92 int proc_addthread(struct proc *proc, struct thread *t);
93
94 /* Detach a thread from its process. */
95 void proc_remthread(struct thread *t);
96
97 /* Fetch the address space of the current process. */
98 struct addrspace *curproc_getas(void);
99
100 /* Change the address space of the current process, and return the old one. */
101 struct addrspace *curproc_setas(struct addrspace *);
102
103
104 #endif /* _PROC_H_ */