23 |
#include <sys/param.h> |
#include <sys/param.h> |
24 |
#include <rtmk/rtmk.h> |
#include <rtmk/rtmk.h> |
25 |
#include <sys/signal.h> |
#include <sys/signal.h> |
26 |
|
#include <pthread.h> |
27 |
|
|
28 |
|
#include "ihash.h" |
29 |
|
#include "nova-intern.h" |
30 |
|
#include "evq.h" |
31 |
|
|
32 |
|
#define PEV_CHILD_EXITED 0 |
33 |
|
#define PEV_POST_SIGNAL 1 |
34 |
|
|
35 |
|
/* Hash table for all processes. Indexed by process request |
36 |
|
port. The hash table is protected by htable lock. */ |
37 |
|
extern ihash_t proc_hash_table; |
38 |
|
extern pthread_mutex_t proc_hash_lock; |
39 |
|
|
40 |
|
/* Try to find process for request port PROC_PORT. |
41 |
|
If we do not find one, we return NULL. ??? panic? */ |
42 |
|
static inline struct proc * |
43 |
|
proc_lookup (void *arg) |
44 |
|
{ |
45 |
|
rtmk_port_t proc_port = (rtmk_port_t) arg; |
46 |
|
struct proc *p; |
47 |
|
|
48 |
|
pthread_mutex_lock (&proc_hash_lock); |
49 |
|
p = ihash_find (proc_hash_table, proc_port); |
50 |
|
pthread_mutex_unlock (&proc_hash_lock); |
51 |
|
return p; |
52 |
|
} |
53 |
|
|
54 |
struct vnode; /* ??? We do not include vfs.h */ |
struct vnode; /* ??? We do not include vfs.h */ |
55 |
struct proc; |
struct proc; |
91 |
a hash table which holds all available processes. */ |
a hash table which holds all available processes. */ |
92 |
struct proc |
struct proc |
93 |
{ |
{ |
94 |
/* ??? lock */ |
/* Lock for the process structure. */ |
95 |
|
pthread_mutex_t p_lock; |
96 |
|
|
97 |
|
/* State of this process. */ |
98 |
|
int p_state; |
99 |
|
#define PS_UNINIT 0 |
100 |
|
#define PS_ZOMBIE 1 |
101 |
|
#define PS_ACTIVE 2 |
102 |
|
#define PS_STOP 3 |
103 |
|
|
104 |
|
/* Event queue for this process. */ |
105 |
|
struct evq p_evq; |
106 |
|
|
107 |
|
/* Reference counter for process. */ |
108 |
|
int p_refcnt; |
109 |
|
|
110 |
|
/* Some one is waiting for children to exit on this process. */ |
111 |
|
int p_wait_on_child_p: 1; |
112 |
|
|
113 |
|
/* The parent of this process is waiting on us to exit. */ |
114 |
|
int p_parent_waiting_p: 1; |
115 |
|
|
116 |
|
/* Condition variable for waking up this process. */ |
117 |
|
pthread_cond_t p_child_exited_or_signal_cond; |
118 |
|
|
119 |
|
/* Pointer to process that just exited. */ |
120 |
|
struct proc *p_child_exited; |
121 |
|
|
122 |
|
/* Process ID of this process (unique to the system). */ |
123 |
pid_t p_pid; |
pid_t p_pid; |
124 |
|
|
125 |
/* Credentials for this process. */ |
/* Credentials for this process. */ |
170 |
vector (allocated entries -- not valid ones). */ |
vector (allocated entries -- not valid ones). */ |
171 |
struct file **p_fdset; |
struct file **p_fdset; |
172 |
int p_nfds; |
int p_nfds; |
173 |
|
|
174 |
|
/* Exit status -- if the process has exit that is. |
175 |
|
We olso have a condition variable that we signal on when exit. */ |
176 |
|
int p_exitstatus; |
177 |
|
pthread_cond_t p_exitcond; |
178 |
}; |
}; |
179 |
|
|
180 |
/* Create a named (i.e. pre-defined pid) process. TASK_OBJECT is the |
/* Create a named (i.e. pre-defined pid) process. TASK_OBJECT is the |
183 |
extern int proc_create_named (pid_t pid, rtmk_port_t task_object, |
extern int proc_create_named (pid_t pid, rtmk_port_t task_object, |
184 |
rtmk_port_t thread_object, struct proc **pp); |
rtmk_port_t thread_object, struct proc **pp); |
185 |
|
|
|
/* Fork PARENT process and return process structure in PP. */ |
|
|
extern int proc_fork (struct proc *parent, struct proc **pp); |
|
|
|
|
186 |
/* Create a new dummy process. This process can only be used with |
/* Create a new dummy process. This process can only be used with |
187 |
the exec syscall -- since we have no state for the process. */ |
the exec syscall -- since we have no state for the process. */ |
188 |
extern int proc_dummy (struct proc **pp); |
extern int proc_dummy (struct proc **pp); |
192 |
int nargv, char **argv, |
int nargv, char **argv, |
193 |
int nenvp, char **envp); |
int nenvp, char **envp); |
194 |
|
|
195 |
|
/* Executes the program pointed to by FILENAME. FILENAME must be |
196 |
|
of a valid object format. NARGZ is number of null-terminated |
197 |
|
strings in ARGZ. NENVZ is number of null-terminated environment |
198 |
|
strings in ENVZ. In success, this function does not return. */ |
199 |
|
int nova_S_proc_exec (struct proc *p, char *filename, int fn_length, |
200 |
|
void *argz, int argz_size, void *envz, int envz_size); |
201 |
|
|
202 |
|
|
203 |
|
/* Process P killed itself. RC is the return code. |
204 |
|
We inhibit all communication on the process port after |
205 |
|
this call, so no other threads (or the same thread), |
206 |
|
can do spooky stuff after this point. */ |
207 |
|
int nova_S_proc_exit (struct proc *p, void *rc); |
208 |
|
|
209 |
|
/* Change working directory of P to DIR. */ |
210 |
|
int nova_S_proc_chdir (struct proc *p, char *dir, int dir_length); |
211 |
|
|
212 |
|
/* Wait until process has exited. If PID_P is true, we wait until |
213 |
|
process PID has exited, otherwise we wait until any child has |
214 |
|
exited or a signal is raised. */ |
215 |
|
int nova_S_proc_wait (struct proc *p, int pid_p, int pid, int options, |
216 |
|
int *statusp, int *pidp); |
217 |
|
|
218 |
|
/* Get process ID of PROC. Return PID in *PIDP. */ |
219 |
|
int nova_S_proc_getpid (struct proc *p, int *pidp); |
220 |
|
|
221 |
|
/* Spawn new processes. TASK is task of new process, THREAD is |
222 |
|
main thread of new process. We return send rights to new process |
223 |
|
structure in *CHILDP. ??? used by posix_spawn and fork? */ |
224 |
|
int nova_S_proc_spawn (struct proc *parent, rtmk_port_t task, |
225 |
|
rtmk_port_t thread, rtmk_port_t *child_port, |
226 |
|
int *pidp); |
227 |
|
/* Exception raise function. EXC_PORT is the proc port, |
228 |
|
so we can just do a "proc_lookup" on it. THREAD is |
229 |
|
the thread that caused the exception. */ |
230 |
|
kern_return_t proc_exception_raise (rtmk_port_t exc_port, |
231 |
|
rtmk_port_t thread, |
232 |
|
rtmk_port_t task, |
233 |
|
int exception, int code, |
234 |
|
int subcode, char *state, |
235 |
|
int state_length); |
236 |
|
|
237 |
#endif /* _PROC_H */ |
#endif /* _PROC_H */ |