Annotation of prex/usr/server/proc/proc.h, Revision 1.1.1.1
1.1 nbrk 1: /*
2: * Copyright (c) 2005-2007, Kohsuke Ohtani
3: * All rights reserved.
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 author nor the names of any co-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 AUTHOR 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 AUTHOR 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: #include <sys/param.h>
34: #include <sys/types.h>
35: #include <sys/list.h>
36: #include <server/proc.h>
37: #include <server/stdmsg.h>
38: #include <prex/capability.h>
39:
40: #include <unistd.h>
41: #include <stdio.h>
42:
43: /* #define DEBUG_PROC 1 */
44:
45: #ifdef DEBUG_PROC
46: #define DPRINTF(a) dprintf a
47: #else
48: #define DPRINTF(a)
49: #endif
50:
51: #define PRIO_PROC 130 /* priority of process server */
52: #define PID_MAX 0x8000 /* max number for PID */
53:
54: #define ID_MAXBUCKETS 32
55: #define IDHASH(x) ((x) & (ID_MAXBUCKETS - 1))
56:
57: struct proc;
58:
59: /*
60: * Session
61: */
62: struct session {
63: int s_refcnt; /* reference count */
64: struct proc *s_leader; /* session leader */
65: int s_ttyhold; /* true if hold tty */
66: };
67:
68:
69: /*
70: * Process group
71: */
72: struct pgrp {
73: struct list pg_link; /* link for pgid hash */
74: struct list pg_members; /* list head of processes */
75: struct session *pg_session; /* pointer to session */
76: pid_t pg_pgid; /* pgrp id */
77: };
78:
79: /*
80: * Description of a process
81: */
82: struct proc {
83: struct list p_link; /* link for all processes */
84: struct proc *p_parent; /* pointer to parent process */
85: struct list p_children; /* list head of child processes */
86: struct list p_sibling; /* link for sibling processes */
87: struct list p_pid_link; /* link for pid hash */
88: struct list p_task_link; /* link for task hash */
89: struct list p_pgrp_link; /* link for process group */
90: struct pgrp *p_pgrp; /* pointer to process group */
91: int p_stat; /* process status S* */
92: int p_exitcode; /* exit code to send to parrent */
93: int p_vforked; /* true while processing vfork() */
94: pid_t p_pid; /* process id */
95: task_t p_task; /* task id */
96: cap_t p_cap; /* capability of the task */
97: void *p_stackbase; /* pointer to stack */
98: void *p_stacksaved; /* pointer to saved stack */
99: };
100:
101: /*
102: * stat codes
103: */
104: #define SRUN 1 /* running */
105: #define SZOMB 2 /* process terminated but not waited for */
106: #define SSTOP 3 /* proces stopped */
107:
108: /*
109: * Global variables.
110: */
111: extern struct proc initproc; /* process slot for init */
112: extern struct list allproc; /* list of all processes */
113: extern struct proc *curproc; /* current (caller) process */
114:
115: extern struct proc *proc_find(pid_t);
116: extern struct pgrp *pgrp_find(pid_t);
117: extern struct proc *task_to_proc(task_t);
118:
119: extern pid_t pid_assign(void);
120: extern void proc_add(struct proc *);
121: extern void proc_remove(struct proc *);
122: extern void pgrp_add(struct pgrp *);
123: extern void pgrp_remove(struct pgrp *);
124: extern void table_init(void);
125: extern void pid_init(void);
126: extern void proc_cleanup(struct proc *);
127: extern void vfork_end(struct proc *);
128: extern int kill_pg(pid_t, int);
129: extern void tty_init(void);
130:
131: extern int proc_getpid(struct msg *);
132: extern int proc_getppid(struct msg *);
133: extern int proc_getpgid(struct msg *);
134: extern int proc_setpgid(struct msg *);
135: extern int proc_getsid(struct msg *);
136: extern int proc_setsid(struct msg *);
137: extern int proc_fork(struct msg *);
138: extern int proc_exit(struct msg *);
139: extern int proc_stop(struct msg *);
140: extern int proc_waitpid(struct msg *);
141: extern int proc_kill(struct msg *);
142:
143: #endif /* !_PROC_H */
CVSweb