proc.h revision 1.233
1/*	$NetBSD: proc.h,v 1.233 2007/02/09 21:55:37 ad Exp $	*/
2
3/*-
4 * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *        This product includes software developed by the NetBSD
21 *        Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39/*-
40 * Copyright (c) 1986, 1989, 1991, 1993
41 *	The Regents of the University of California.  All rights reserved.
42 * (c) UNIX System Laboratories, Inc.
43 * All or some portions of this file are derived from material licensed
44 * to the University of California by American Telephone and Telegraph
45 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
46 * the permission of UNIX System Laboratories, Inc.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 *    notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 *    notice, this list of conditions and the following disclaimer in the
55 *    documentation and/or other materials provided with the distribution.
56 * 3. Neither the name of the University nor the names of its contributors
57 *    may be used to endorse or promote products derived from this software
58 *    without specific prior written permission.
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * SUCH DAMAGE.
71 *
72 *	@(#)proc.h	8.15 (Berkeley) 5/19/95
73 */
74
75#ifndef _SYS_PROC_H_
76#define	_SYS_PROC_H_
77
78#if defined(_KERNEL_OPT)
79#include "opt_multiprocessor.h"
80#include "opt_kstack.h"
81#include "opt_lockdebug.h"
82#endif
83
84#include <machine/proc.h>		/* Machine-dependent proc substruct */
85#include <sys/lock.h>
86#include <sys/rwlock.h>
87#include <sys/mutex.h>
88#include <sys/condvar.h>
89#include <sys/lwp.h>
90#include <sys/queue.h>
91#include <sys/callout.h>
92#include <sys/signalvar.h>
93#include <sys/siginfo.h>
94#include <sys/event.h>
95#include <sys/specificdata.h>
96
97#ifndef _KERNEL
98#include <sys/time.h>
99#include <sys/resource.h>
100#endif
101
102/*
103 * One structure allocated per session.
104 */
105struct session {
106	int		s_count;	/* Ref cnt; pgrps in session */
107	u_int		s_flags;
108#define	S_LOGIN_SET	1		/* s_login set in this session */
109	struct proc	*s_leader;	/* Session leader */
110	struct vnode	*s_ttyvp;	/* Vnode of controlling terminal */
111	struct tty	*s_ttyp;	/* Controlling terminal */
112	char		s_login[MAXLOGNAME]; /* Setlogin() name */
113	pid_t		s_sid;		/* Session ID (pid of leader) */
114};
115
116/*
117 * One structure allocated per process group.
118 */
119struct pgrp {
120	LIST_HEAD(, proc) pg_members;	/* Pointer to pgrp members */
121	struct session	*pg_session;	/* Pointer to session */
122	pid_t		pg_id;		/* Pgrp id */
123	int		pg_jobc;	/*
124					 * Number of processes qualifying
125					 * pgrp for job control
126					 */
127};
128
129/*
130 * One structure allocated per emulation.
131 */
132struct exec_package;
133struct ps_strings;
134struct ras;
135struct sa_emul;
136struct kauth_cred;
137
138struct emul {
139	const char	*e_name;	/* Symbolic name */
140	const char	*e_path;	/* Extra emulation path (NULL if none)*/
141#ifndef __HAVE_MINIMAL_EMUL
142	int		e_flags;	/* Miscellaneous flags, see above */
143					/* Syscall handling function */
144	const int	*e_errno;	/* Errno array */
145	int		e_nosys;	/* Offset of the nosys() syscall */
146	int		e_nsysent;	/* Number of system call entries */
147#endif
148	const struct sysent *e_sysent;	/* System call array */
149	const char * const *e_syscallnames; /* System call name array */
150					/* Signal sending function */
151	void		(*e_sendsig)(const struct ksiginfo *,
152					  const sigset_t *);
153	void		(*e_trapsignal)(struct lwp *, struct ksiginfo *);
154	int		(*e_tracesig)(struct proc *, int);
155	char		*e_sigcode;	/* Start of sigcode */
156	char		*e_esigcode;	/* End of sigcode */
157					/* Set registers before execution */
158	struct uvm_object **e_sigobject;/* shared sigcode object */
159	void		(*e_setregs)(struct lwp *, struct exec_package *,
160					  u_long);
161
162					/* Per-process hooks */
163	void		(*e_proc_exec)(struct proc *, struct exec_package *);
164	void		(*e_proc_fork)(struct proc *, struct proc *, int);
165	void		(*e_proc_exit)(struct proc *);
166	void		(*e_lwp_fork)(struct lwp *, struct lwp *);
167	void		(*e_lwp_exit)(struct lwp *);
168
169#ifdef __HAVE_SYSCALL_INTERN
170	void		(*e_syscall_intern)(struct proc *);
171#else
172	void		(*e_syscall)(void);
173#endif
174					/* Emulation specific sysctl data */
175	struct sysctlnode *e_sysctlovly;
176	int		(*e_fault)(struct proc *, vaddr_t, int);
177
178	vaddr_t		(*e_vm_default_addr)(struct proc *, vaddr_t, vsize_t);
179
180	/* Emulation-specific hook for userspace page faults */
181	int		(*e_usertrap)(struct lwp *, vaddr_t, void *);
182
183	size_t		e_ucsize;	/* size of ucontext_t */
184};
185
186/*
187 * Emulation miscelaneous flags
188 */
189#define	EMUL_HAS_SYS___syscall	0x001	/* Has SYS___syscall */
190
191/*
192 * Description of a process.
193 *
194 * This structure contains the information needed to manage a thread of
195 * control, known in UN*X as a process; it has references to substructures
196 * containing descriptions of things that the process uses, but may share
197 * with related processes.  The process structure and the substructures
198 * are always addressible except for those marked "(PROC ONLY)" below,
199 * which might be addressible only on a processor on which the process
200 * is running.
201 *
202 * Field markings and the corresponding locks (not yet fully implemented,
203 * more a statement of intent):
204 *
205 * k:	ktrace_mutex
206 * m:	proclist_mutex
207 * l:	proclist_lock
208 * s:	p_smutex
209 * t:	p_stmutex
210 * p:	p_mutex
211 * r:	p_rasmutex
212 * (:	unlocked, stable
213 */
214struct proc {
215	LIST_ENTRY(proc) p_list;	/* l, m: List of all processes */
216
217	kmutex_t	p_rasmutex;	/* :: RAS mutex */
218	kmutex_t	p_mutex;	/* :: general mutex */
219	kmutex_t	p_smutex;	/* :: mutex on scheduling state */
220	kmutex_t	p_stmutex;	/* :: mutex on profiling state */
221	kcondvar_t	p_refcv;	/* p: reference count CV */
222	kcondvar_t	p_waitcv;	/* s: wait, stop CV on children */
223	kcondvar_t	p_lwpcv;	/* s: wait, stop CV on LWPs */
224	int		p_refcnt;	/* p: ref count for procfs etc */
225
226	/* Substructures: */
227	struct kauth_cred *p_cred;	/* p: Master copy of credentials */
228	struct filedesc	*p_fd;		/*    Ptr to open files structure */
229	struct cwdinfo	*p_cwdi;	/*    cdir/rdir/cmask info */
230	struct pstats	*p_stats;	/*    Accounting/stats (PROC ONLY) */
231	struct plimit	*p_limit;	/*    Process limits */
232	struct vmspace	*p_vmspace;	/*    Address space */
233	struct sigacts	*p_sigacts;	/*    Process sigactions */
234
235	specificdata_reference
236			p_specdataref;	/* subsystem proc-specific data */
237
238	int		p_exitsig;	/* l: signal to send to parent on exit */
239	int		p_flag;		/* p: P_* flags */
240	int		p_sflag;	/* s: PS_* flags */
241	int		p_slflag;	/* s, l: PSL_* flags */
242	int		p_lflag;	/* l: PL_* flags */
243	int		p_stflag;	/* t: PST_* flags */
244	char		p_stat;		/* s: S* process status. */
245	char		p_pad1[3];
246
247	pid_t		p_pid;		/* (: Process identifier. */
248	LIST_ENTRY(proc) p_pglist;	/* l: List of processes in pgrp. */
249	struct proc 	*p_pptr;	/* l: Pointer to parent process. */
250	LIST_ENTRY(proc) p_sibling;	/* l: List of sibling processes. */
251	LIST_HEAD(, proc) p_children;	/* l: List of children. */
252	LIST_HEAD(, lwp) p_lwps;	/* s: List of LWPs. */
253	LIST_HEAD(, ras) p_raslist;	/* r: List of RAS entries */
254
255/* The following fields are all zeroed upon creation in fork. */
256#define	p_startzero	p_nlwps
257
258	int 		p_nlwps;	/* s: Number of LWPs */
259	int 		p_nzlwps;	/* s: Number of zombie LWPs */
260	int		p_nrlwps;	/* s: Number running/sleeping LWPs */
261	int		p_nlwpwait;	/* s: Number of LWPs in lwp_wait1() */
262	int		p_ndlwps;	/* s: Number of detached LWPs */
263	int 		p_nlwpid;	/* s: Next LWP ID */
264	u_int		p_nstopchild;	/* m: Count of stopped/dead children */
265	u_int		p_waited;	/* m: parent has waited on child */
266	struct lwp	*p_zomblwp;	/* s: detached LWP to be reaped */
267
268	/* scheduling */
269	fixpt_t		p_estcpu;	/* t: Time averaged value of p_cpticks XXX belongs in p_startcopy section */
270	fixpt_t		p_estcpu_inherited;
271	unsigned int	p_forktime;
272	int		p_cpticks;	/* t: Ticks of CPU time */
273	fixpt_t		p_pctcpu;	/* t: %cpu for this process during p_swtime */
274
275	struct proc	*p_opptr;	/* l: save parent during ptrace. */
276	struct ptimers	*p_timers;	/*    Timers: real, virtual, profiling */
277	struct timeval 	p_rtime;	/* s: real time */
278	u_quad_t 	p_uticks;	/* t: Statclock hits in user mode */
279	u_quad_t 	p_sticks;	/* t: Statclock hits in system mode */
280	u_quad_t 	p_iticks;	/* t: Statclock hits processing intr */
281
282	int		p_traceflag;	/* k: Kernel trace points */
283	void		*p_tracep;	/* k: Trace private data */
284	void		*p_systrace;	/*    Back pointer to systrace */
285
286	struct vnode 	*p_textvp;	/*    Vnode of executable */
287
288	const struct emul *p_emul;	/*    Emulation information */
289	void		*p_emuldata;	/*    Per-process emulation data, or NULL.
290					 *    Malloc type M_EMULDATA */
291	const struct execsw *p_execsw;	/*    Exec package information */
292	struct klist	p_klist;	/*    Knotes attached to this process */
293
294	LIST_HEAD(, lwp) p_sigwaiters;	/* s: LWPs waiting for signals */
295	sigpend_t	p_sigpend;	/* s: pending signals */
296
297/*
298 * End area that is zeroed on creation
299 */
300#define	p_endzero	p_startcopy
301
302/*
303 * The following fields are all copied upon creation in fork.
304 */
305#define	p_startcopy	p_sigctx
306
307	struct sigctx 	p_sigctx;	/* s: Shared signal state */
308
309	u_char		p_nice;		/* s: Process "nice" value */
310	char		p_comm[MAXCOMLEN+1];
311					/* p: basename of last exec file */
312	struct pgrp 	*p_pgrp;	/* l: Pointer to process group */
313
314	struct ps_strings *p_psstr;	/* (: address of process's ps_strings */
315	size_t 		p_psargv;	/* (: offset of ps_argvstr in above */
316	size_t 		p_psnargv;	/* (: offset of ps_nargvstr in above */
317	size_t 		p_psenv;	/* (: offset of ps_envstr in above */
318	size_t 		p_psnenv;	/* (: offset of ps_nenvstr in above */
319
320/*
321 * End area that is copied on creation
322 */
323#define	p_endcopy	p_xstat
324
325	u_short		p_xstat;	/* s: Exit status for wait; also stop signal */
326	u_short		p_acflag;	/* p: Acc. flags; see struct lwp also */
327	struct rusage 	*p_ru;		/*    Exit information. XXX */
328
329	struct mdproc	p_md;		/*    Any machine-dependent fields */
330};
331
332#define	p_rlimit	p_limit->pl_rlimit
333#define	p_session	p_pgrp->pg_session
334#define	p_pgid		p_pgrp->pg_id
335
336/*
337 * Status values.
338 */
339#define	SIDL		1		/* Process being created by fork */
340#define	SACTIVE		2		/* Process is not stopped */
341#define	SDYING		3		/* About to die */
342#define	SSTOP		4		/* Process debugging or suspension */
343#define	SZOMB		5		/* Awaiting collection by parent */
344#define	SDEAD	 	6		/* Almost a zombie */
345
346#define	P_ZOMBIE(p)	\
347    ((p)->p_stat == SZOMB || (p)->p_stat == SDYING || (p)->p_stat == SDEAD)
348
349/*
350 * These flags are kept in p_flag and are protected by p_mutex.  Access from
351 * process context only.
352 */
353#define	P_ADVLOCK	0x00000001 /* Process may hold a POSIX advisory lock */
354#define	P_SYSTEM	0x00000002 /* System process (kthread) */
355#define	P_SUGID		0x00000100 /* Had set id privileges since last exec */
356#define	P_EXEC		0x00004000 /* Process called exec */
357#define	P_NOCLDWAIT	0x00020000 /* No zombies if child dies */
358#define	P_32		0x00040000 /* 32-bit process (used on 64-bit kernels) */
359#define	P_CLDSIGIGN	0x00080000 /* Process is ignoring SIGCHLD */
360#define	P_SYSTRACE	0x00200000 /* Process system call tracing active */
361#define	P_PAXMPROTECT  	0x08000000 /* Explicitly enable PaX MPROTECT */
362#define	P_PAXMPROTECT  	0x08000000 /* Explicitly enable PaX MPROTECT */
363#define	P_PAXNOMPROTECT	0x10000000 /* Explicitly disable PaX MPROTECT */
364#define	P_MARKER	0x80000000 /* Is a dummy marker process */
365
366/*
367 * These flags are kept in p_sflag and are protected by p_smutex.  Access from
368 * process context or interrupt context.
369 */
370#define	PS_NOCLDSTOP	0x00000008 /* No SIGCHLD when children stop */
371#define	PS_PPWAIT	0x00000010 /* Parent is waiting for child exec/exit */
372#define	PS_WCORE	0x00001000 /* Process needs to dump core */
373#define	PS_WEXIT	0x00002000 /* Working on exiting */
374#define	PS_STOPFORK	0x00800000 /* Child will be stopped on fork(2) */
375#define	PS_STOPEXEC	0x01000000 /* Will be stopped on exec(2) */
376#define	PS_STOPEXIT	0x02000000 /* Will be stopped at process exit */
377#define	PS_NOTIFYSTOP	0x10000000 /* Notify parent of successful STOP */
378#define	PS_ORPHANPG	0x20000000 /* Member of an orphaned pgrp */
379#define	PS_STOPPING	0x80000000 /* Transitioning SACTIVE -> SSTOP */
380
381/*
382 * These flags are kept in p_sflag and are protected by the proclist_lock
383 * and p_smutex.  Access from process context or interrupt context.
384 */
385#define	PSL_TRACED	0x00000800 /* Debugged process being traced */
386#define	PSL_FSTRACE	0x00010000 /* Debugger process being traced by procfs */
387#define	PSL_CHTRACED	0x00400000 /* Child has been traced & reparented */
388#define	PSL_SYSCALL	0x04000000 /* process has PT_SYSCALL enabled */
389
390/*
391 * Kept in p_stflag and protected by p_stmutex.
392 */
393#define	PST_PROFIL	0x00000020 /* Has started profiling */
394
395/*
396 * The final set are protected by the proclist_lock.  Access
397 * from process context only.
398 */
399#define	PL_CONTROLT	0x00000002 /* Has a controlling terminal */
400
401/*
402 * Macro to compute the exit signal to be delivered.
403 */
404#define	P_EXITSIG(p)	\
405    (((p)->p_slflag & (PSL_TRACED|PSL_FSTRACE)) ? SIGCHLD : p->p_exitsig)
406
407/*
408 * MOVE TO ucred.h?
409 *
410 * Shareable process credentials (always resident).  This includes a reference
411 * to the current user credentials as well as real and saved ids that may be
412 * used to change ids.
413 */
414struct pcred {
415	struct ucred	*pc_ucred;	/* Current credentials */
416	uid_t		p_ruid;		/* Real user id */
417	uid_t		p_svuid;	/* Saved effective user id */
418	gid_t		p_rgid;		/* Real group id */
419	gid_t		p_svgid;	/* Saved effective group id */
420	int		p_refcnt;	/* Number of references */
421};
422
423LIST_HEAD(proclist, proc);		/* A list of processes */
424
425/*
426 * This structure associates a proclist with its lock.
427 */
428struct proclist_desc {
429	struct proclist	*pd_list;	/* The list */
430	/*
431	 * XXX Add a pointer to the proclist's lock eventually.
432	 */
433};
434
435#ifdef _KERNEL
436#include <sys/mallocvar.h>
437MALLOC_DECLARE(M_EMULDATA);
438MALLOC_DECLARE(M_PROC);
439MALLOC_DECLARE(M_SESSION);
440MALLOC_DECLARE(M_SUBPROC);	/* XXX - only used by sparc/sparc64 */
441
442/*
443 * We use process IDs <= PID_MAX until there are > 16k processes.
444 * NO_PGID is used to represent "no process group" for a tty.
445 */
446#define	PID_MAX		30000
447#define	NO_PGID		((pid_t)-1)
448
449#define	SESS_LEADER(p)	((p)->p_session->s_leader == (p))
450#define	SESSHOLD(s)	((s)->s_count++)
451#define	SESSRELE(s)							\
452do {									\
453	if (--(s)->s_count == 0)					\
454		sessdelete(s);						\
455} while (/* CONSTCOND */ 0)
456
457
458/*
459 * Flags passed to fork1().
460 */
461#define	FORK_PPWAIT	0x01		/* Block parent until child exit */
462#define	FORK_SHAREVM	0x02		/* Share vmspace with parent */
463#define	FORK_SHARECWD	0x04		/* Share cdir/rdir/cmask */
464#define	FORK_SHAREFILES	0x08		/* Share file descriptors */
465#define	FORK_SHARESIGS	0x10		/* Share signal actions */
466#define	FORK_NOWAIT	0x20		/* Make init the parent of the child */
467#define	FORK_CLEANFILES	0x40		/* Start with a clean descriptor set */
468#define	FORK_SYSTEM	0x80		/* Fork a kernel thread */
469
470/*
471 * Allow machine-dependent code to override curproc in <machine/cpu.h> for
472 * its own convenience.  Otherwise, we declare it as appropriate.
473 */
474#if !defined(curlwp)
475#if defined(MULTIPROCESSOR)
476#define	curlwp		curcpu()->ci_curlwp	/* Current running LWP */
477#else
478extern struct lwp	*curlwp;		/* Current running LWP */
479#endif /* MULTIPROCESSOR */
480#endif /* ! curproc */
481
482static struct proc *__curproc(void);
483
484static __inline struct proc *
485__curproc()
486{
487	struct lwp *l = curlwp;
488
489	if (l == NULL)
490		return NULL;
491	return l->l_proc;
492}
493#define	curproc	__curproc()
494
495extern struct proc	proc0;		/* Process slot for swapper */
496extern int		nprocs, maxproc; /* Current and max number of procs */
497#define	vmspace_kernel()	(proc0.p_vmspace)
498
499/* Process list locks; see kern_proc.c for locking protocol details */
500extern krwlock_t	proclist_lock;
501extern kmutex_t		proclist_mutex;
502
503extern struct proclist	allproc;	/* List of all processes */
504extern struct proclist	zombproc;	/* List of zombie processes */
505
506extern SLIST_HEAD(deadprocs, proc) deadprocs;	/* List of dead processes */
507extern struct simplelock deadproc_slock;
508
509extern struct proc	*initproc;	/* Process slots for init, pager */
510
511extern const struct proclist_desc proclists[];
512
513extern struct pool	pcred_pool;	/* Memory pool for pcreds */
514extern struct pool	plimit_pool;	/* Memory pool for plimits */
515extern struct pool 	pstats_pool;	/* memory pool for pstats */
516extern struct pool	rusage_pool;	/* Memory pool for rusages */
517extern struct pool	ptimer_pool;	/* Memory pool for ptimers */
518
519struct proc *p_find(pid_t, uint);	/* Find process by id */
520struct pgrp *pg_find(pid_t, uint);	/* Find process group by id */
521/* Flags values for p_find() and pg_find(). */
522#define PFIND_ZOMBIE		1	/* look for zombies as well */
523#define PFIND_LOCKED		2	/* proclist locked on entry */
524#define PFIND_UNLOCK_FAIL	4	/* unlock proclist on failure */
525#define PFIND_UNLOCK_OK		8	/* unlock proclist on success */
526#define PFIND_UNLOCK		(PFIND_UNLOCK_OK | PFIND_UNLOCK_FAIL)
527/* For source compatibility. but UNLOCK_OK gives a stale answer... */
528#define pfind(pid) p_find((pid), PFIND_UNLOCK)
529#define pgfind(pgid) pg_find((pgid), PFIND_UNLOCK)
530
531struct simplelock;
532int	enterpgrp(struct proc *, pid_t, pid_t, int);
533void	leavepgrp(struct proc *);
534void	fixjobc(struct proc *, struct pgrp *, int);
535int	inferior(struct proc *, struct proc *);
536void	sessdelete(struct session *);
537void	yield(void);
538void	pgdelete(struct pgrp *);
539void	procinit(void);
540void	resetprocpriority(struct proc *);
541void	suspendsched(void);
542int	ltsleep(wchan_t, int, const char *, int,
543	    volatile struct simplelock *);
544void	wakeup(wchan_t);
545void	wakeup_one(wchan_t);
546int	kpause(const char *, boolean_t, int, kmutex_t *);
547void	exit1(struct lwp *, int);
548int	find_stopped_child(struct proc *, pid_t, int, struct proc **, int *);
549struct proc *proc_alloc(void);
550void	proc0_init(void);
551void	proc_free(struct proc *, struct rusage **);
552void	proc_free_mem(struct proc *);
553void	exit_lwps(struct lwp *l);
554int	fork1(struct lwp *, int, int, void *, size_t,
555	    void (*)(void *), void *, register_t *, struct proc **);
556void	rqinit(void);
557int	pgid_in_session(struct proc *, pid_t);
558#ifndef cpu_idle
559void	cpu_idle(void);
560#endif
561void	cpu_exit(struct lwp *);
562void	cpu_lwp_fork(struct lwp *, struct lwp *, void *, size_t,
563	    void (*)(void *), void *);
564#ifndef cpu_lwp_free
565void	cpu_lwp_free(struct lwp *, int);
566void	cpu_lwp_free2(struct lwp *);
567#endif
568
569#ifdef __HAVE_SYSCALL_INTERN
570void	syscall_intern(struct proc *);
571#endif
572
573void	child_return(void *);
574
575int	proc_isunder(struct proc *, struct lwp *);
576void	proc_stop(struct proc *, int, int);
577
578void	p_sugid(struct proc *);
579
580int	proc_vmspace_getref(struct proc *, struct vmspace **);
581void	proc_crmod_leave(kauth_cred_t, kauth_cred_t, boolean_t);
582void	proc_crmod_enter(void);
583int	proc_addref(struct proc *);
584void	proc_delref(struct proc *);
585void	proc_drainrefs(struct proc *);
586
587int	proc_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
588void	proc_specific_key_delete(specificdata_key_t);
589void 	proc_initspecific(struct proc *);
590void 	proc_finispecific(struct proc *);
591void *	proc_getspecific(struct proc *, specificdata_key_t);
592void	proc_setspecific(struct proc *, specificdata_key_t, void *);
593
594int	proclist_foreach_call(struct proclist *,
595    int (*)(struct proc *, void *arg), void *);
596static __inline struct proc *_proclist_skipmarker(struct proc *);
597
598static __inline struct proc *
599_proclist_skipmarker(struct proc *p0)
600{
601	struct proc *p = p0;
602
603	while (p != NULL && p->p_flag & P_MARKER)
604		p = LIST_NEXT(p, p_list);
605
606	return p;
607}
608#define	PROCLIST_FOREACH(var, head)					\
609	for ((var) = LIST_FIRST(head);					\
610		((var) = _proclist_skipmarker(var)) != NULL;		\
611		(var) = LIST_NEXT(var, p_list))
612
613#if defined(LOCKDEBUG)
614void assert_sleepable(struct simplelock *, const char *);
615#define	ASSERT_SLEEPABLE(lk, msg)	assert_sleepable((lk), (msg))
616#else /* defined(LOCKDEBUG) */
617#define	ASSERT_SLEEPABLE(lk, msg)	/* nothing */
618#endif /* defined(LOCKDEBUG) */
619
620/* Compatibility with old, non-interlocked tsleep call */
621#define	tsleep(chan, pri, wmesg, timo)					\
622	ltsleep(chan, pri, wmesg, timo, NULL)
623
624#if defined(MULTIPROCESSOR)
625void	proc_trampoline_mp(void);	/* XXX */
626#endif
627
628#ifdef KSTACK_CHECK_MAGIC
629void kstack_setup_magic(const struct lwp *);
630void kstack_check_magic(const struct lwp *);
631#endif
632
633/*
634 * kernel stack paramaters
635 * XXX require sizeof(struct user)
636 */
637/* the lowest address of kernel stack */
638#ifndef KSTACK_LOWEST_ADDR
639#define	KSTACK_LOWEST_ADDR(l)	((caddr_t)ALIGN((l)->l_addr + 1))
640#endif
641/* size of kernel stack */
642#ifndef KSTACK_SIZE
643#define	KSTACK_SIZE	(USPACE - ALIGN(sizeof(struct user)))
644#endif
645
646#endif	/* _KERNEL */
647#endif	/* !_SYS_PROC_H_ */
648