proc.h revision 1.241
1/*	$NetBSD: proc.h,v 1.241 2007/02/27 15:07:28 yamt 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 kauth_cred;
136
137struct emul {
138	const char	*e_name;	/* Symbolic name */
139	const char	*e_path;	/* Extra emulation path (NULL if none)*/
140#ifndef __HAVE_MINIMAL_EMUL
141	int		e_flags;	/* Miscellaneous flags, see above */
142					/* Syscall handling function */
143	const int	*e_errno;	/* Errno array */
144	int		e_nosys;	/* Offset of the nosys() syscall */
145	int		e_nsysent;	/* Number of system call entries */
146#endif
147	const struct sysent *e_sysent;	/* System call array */
148	const char * const *e_syscallnames; /* System call name array */
149					/* Signal sending function */
150	void		(*e_sendsig)(const struct ksiginfo *,
151					  const sigset_t *);
152	void		(*e_trapsignal)(struct lwp *, struct ksiginfo *);
153	int		(*e_tracesig)(struct proc *, int);
154	char		*e_sigcode;	/* Start of sigcode */
155	char		*e_esigcode;	/* End of sigcode */
156					/* Set registers before execution */
157	struct uvm_object **e_sigobject;/* shared sigcode object */
158	void		(*e_setregs)(struct lwp *, struct exec_package *,
159					  u_long);
160
161					/* Per-process hooks */
162	void		(*e_proc_exec)(struct proc *, struct exec_package *);
163	void		(*e_proc_fork)(struct proc *, struct proc *, int);
164	void		(*e_proc_exit)(struct proc *);
165	void		(*e_lwp_fork)(struct lwp *, struct lwp *);
166	void		(*e_lwp_exit)(struct lwp *);
167
168#ifdef __HAVE_SYSCALL_INTERN
169	void		(*e_syscall_intern)(struct proc *);
170#else
171	void		(*e_syscall)(void);
172#endif
173					/* Emulation specific sysctl data */
174	struct sysctlnode *e_sysctlovly;
175	int		(*e_fault)(struct proc *, vaddr_t, int);
176
177	vaddr_t		(*e_vm_default_addr)(struct proc *, vaddr_t, vsize_t);
178
179	/* Emulation-specific hook for userspace page faults */
180	int		(*e_usertrap)(struct lwp *, vaddr_t, void *);
181
182	size_t		e_ucsize;	/* size of ucontext_t */
183	void		(*e_startlwp)(void *);
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	void	     (*p_userret)(void);/* p: return-to-user hook */
289	const struct emul *p_emul;	/*    Emulation information */
290	void		*p_emuldata;	/*    Per-process emulation data, or NULL.
291					 *    Malloc type M_EMULDATA */
292	const struct execsw *p_execsw;	/*    Exec package information */
293	struct klist	p_klist;	/*    Knotes attached to this process */
294
295	LIST_HEAD(, lwp) p_sigwaiters;	/* s: LWPs waiting for signals */
296	sigpend_t	p_sigpend;	/* s: pending signals */
297
298/*
299 * End area that is zeroed on creation
300 */
301#define	p_endzero	p_startcopy
302
303/*
304 * The following fields are all copied upon creation in fork.
305 */
306#define	p_startcopy	p_sigctx
307
308	struct sigctx 	p_sigctx;	/* s: Shared signal state */
309
310	u_char		p_nice;		/* s: Process "nice" value */
311	char		p_comm[MAXCOMLEN+1];
312					/* p: basename of last exec file */
313	struct pgrp 	*p_pgrp;	/* l: Pointer to process group */
314
315	struct ps_strings *p_psstr;	/* (: address of process's ps_strings */
316	size_t 		p_psargv;	/* (: offset of ps_argvstr in above */
317	size_t 		p_psnargv;	/* (: offset of ps_nargvstr in above */
318	size_t 		p_psenv;	/* (: offset of ps_envstr in above */
319	size_t 		p_psnenv;	/* (: offset of ps_nenvstr in above */
320
321/*
322 * End area that is copied on creation
323 */
324#define	p_endcopy	p_xstat
325
326	u_short		p_xstat;	/* s: Exit status for wait; also stop signal */
327	u_short		p_acflag;	/* p: Acc. flags; see struct lwp also */
328	struct rusage 	*p_ru;		/*    Exit information. XXX */
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	PK_ADVLOCK	0x00000001 /* Process may hold a POSIX advisory lock */
354#define	PK_SYSTEM	0x00000002 /* System process (kthread) */
355#define	PK_SUGID	0x00000100 /* Had set id privileges since last exec */
356#define	PK_EXEC		0x00004000 /* Process called exec */
357#define	PK_NOCLDWAIT	0x00020000 /* No zombies if child dies */
358#define	PK_32		0x00040000 /* 32-bit process (used on 64-bit kernels) */
359#define	PK_CLDSIGIGN	0x00080000 /* Process is ignoring SIGCHLD */
360#define	PK_SYSTRACE	0x00200000 /* Process system call tracing active */
361#define	PK_PAXMPROTECT 	0x08000000 /* Explicitly enable PaX MPROTECT */
362#define	PK_PAXNOMPROTECT	0x10000000 /* Explicitly disable PaX MPROTECT */
363#define	PK_MARKER	0x80000000 /* Is a dummy marker process */
364
365/*
366 * These flags are kept in p_sflag and are protected by p_smutex.  Access from
367 * process context or interrupt context.
368 */
369#define	PS_NOCLDSTOP	0x00000008 /* No SIGCHLD when children stop */
370#define	PS_PPWAIT	0x00000010 /* Parent is waiting for child exec/exit */
371#define	PS_WCORE	0x00001000 /* Process needs to dump core */
372#define	PS_WEXIT	0x00002000 /* Working on exiting */
373#define	PS_STOPFORK	0x00800000 /* Child will be stopped on fork(2) */
374#define	PS_STOPEXEC	0x01000000 /* Will be stopped on exec(2) */
375#define	PS_STOPEXIT	0x02000000 /* Will be stopped at process exit */
376#define	PS_NOTIFYSTOP	0x10000000 /* Notify parent of successful STOP */
377#define	PS_ORPHANPG	0x20000000 /* Member of an orphaned pgrp */
378#define	PS_STOPPING	0x80000000 /* Transitioning SACTIVE -> SSTOP */
379
380/*
381 * These flags are kept in p_sflag and are protected by the proclist_lock
382 * and p_smutex.  Access from process context or interrupt context.
383 */
384#define	PSL_TRACED	0x00000800 /* Debugged process being traced */
385#define	PSL_FSTRACE	0x00010000 /* Debugger process being traced by procfs */
386#define	PSL_CHTRACED	0x00400000 /* Child has been traced & reparented */
387#define	PSL_SYSCALL	0x04000000 /* process has PT_SYSCALL enabled */
388
389/*
390 * Kept in p_stflag and protected by p_stmutex.
391 */
392#define	PST_PROFIL	0x00000020 /* Has started profiling */
393
394/*
395 * The final set are protected by the proclist_lock.  Access
396 * from process context only.
397 */
398#define	PL_CONTROLT	0x00000002 /* Has a controlling terminal */
399
400/*
401 * Macro to compute the exit signal to be delivered.
402 */
403#define	P_EXITSIG(p)	\
404    (((p)->p_slflag & (PSL_TRACED|PSL_FSTRACE)) ? SIGCHLD : p->p_exitsig)
405
406LIST_HEAD(proclist, proc);		/* A list of processes */
407
408/*
409 * This structure associates a proclist with its lock.
410 */
411struct proclist_desc {
412	struct proclist	*pd_list;	/* The list */
413	/*
414	 * XXX Add a pointer to the proclist's lock eventually.
415	 */
416};
417
418#ifdef _KERNEL
419#include <sys/mallocvar.h>
420MALLOC_DECLARE(M_EMULDATA);
421MALLOC_DECLARE(M_PROC);
422MALLOC_DECLARE(M_SESSION);
423MALLOC_DECLARE(M_SUBPROC);	/* XXX - only used by sparc/sparc64 */
424
425/*
426 * We use process IDs <= PID_MAX until there are > 16k processes.
427 * NO_PGID is used to represent "no process group" for a tty.
428 */
429#define	PID_MAX		30000
430#define	NO_PGID		((pid_t)-1)
431
432#define	SESS_LEADER(p)	((p)->p_session->s_leader == (p))
433#define	SESSHOLD(s)	((s)->s_count++)
434#define	SESSRELE(s)							\
435do {									\
436	if (--(s)->s_count == 0)					\
437		sessdelete(s);						\
438} while (/* CONSTCOND */ 0)
439
440
441/*
442 * Flags passed to fork1().
443 */
444#define	FORK_PPWAIT	0x01		/* Block parent until child exit */
445#define	FORK_SHAREVM	0x02		/* Share vmspace with parent */
446#define	FORK_SHARECWD	0x04		/* Share cdir/rdir/cmask */
447#define	FORK_SHAREFILES	0x08		/* Share file descriptors */
448#define	FORK_SHARESIGS	0x10		/* Share signal actions */
449#define	FORK_NOWAIT	0x20		/* Make init the parent of the child */
450#define	FORK_CLEANFILES	0x40		/* Start with a clean descriptor set */
451#define	FORK_SYSTEM	0x80		/* Fork a kernel thread */
452
453/*
454 * Allow machine-dependent code to override curproc in <machine/cpu.h> for
455 * its own convenience.  Otherwise, we declare it as appropriate.
456 */
457#if !defined(curlwp)
458#if defined(MULTIPROCESSOR)
459#define	curlwp		curcpu()->ci_curlwp	/* Current running LWP */
460#else
461extern struct lwp	*curlwp;		/* Current running LWP */
462#endif /* MULTIPROCESSOR */
463#endif /* ! curproc */
464
465static struct proc *__curproc(void);
466
467static __inline struct proc *
468__curproc()
469{
470	struct lwp *l = curlwp;
471
472	if (l == NULL)
473		return NULL;
474	return l->l_proc;
475}
476#define	curproc	__curproc()
477
478extern struct proc	proc0;		/* Process slot for swapper */
479extern int		nprocs, maxproc; /* Current and max number of procs */
480#define	vmspace_kernel()	(proc0.p_vmspace)
481
482/* Process list locks; see kern_proc.c for locking protocol details */
483extern krwlock_t	proclist_lock;
484extern kmutex_t		proclist_mutex;
485
486extern struct proclist	allproc;	/* List of all processes */
487extern struct proclist	zombproc;	/* List of zombie processes */
488
489extern SLIST_HEAD(deadprocs, proc) deadprocs;	/* List of dead processes */
490extern struct simplelock deadproc_slock;
491
492extern struct proc	*initproc;	/* Process slots for init, pager */
493
494extern const struct proclist_desc proclists[];
495
496extern struct pool	pcred_pool;	/* Memory pool for pcreds */
497extern struct pool	plimit_pool;	/* Memory pool for plimits */
498extern struct pool 	pstats_pool;	/* memory pool for pstats */
499extern struct pool	rusage_pool;	/* Memory pool for rusages */
500extern struct pool	ptimer_pool;	/* Memory pool for ptimers */
501
502struct proc *p_find(pid_t, uint);	/* Find process by id */
503struct pgrp *pg_find(pid_t, uint);	/* Find process group by id */
504/* Flags values for p_find() and pg_find(). */
505#define PFIND_ZOMBIE		1	/* look for zombies as well */
506#define PFIND_LOCKED		2	/* proclist locked on entry */
507#define PFIND_UNLOCK_FAIL	4	/* unlock proclist on failure */
508#define PFIND_UNLOCK_OK		8	/* unlock proclist on success */
509#define PFIND_UNLOCK		(PFIND_UNLOCK_OK | PFIND_UNLOCK_FAIL)
510/* For source compatibility. but UNLOCK_OK gives a stale answer... */
511#define pfind(pid) p_find((pid), PFIND_UNLOCK)
512#define pgfind(pgid) pg_find((pgid), PFIND_UNLOCK)
513
514struct simplelock;
515int	enterpgrp(struct proc *, pid_t, pid_t, int);
516void	leavepgrp(struct proc *);
517void	fixjobc(struct proc *, struct pgrp *, int);
518int	inferior(struct proc *, struct proc *);
519void	sessdelete(struct session *);
520void	yield(void);
521void	pgdelete(struct pgrp *);
522void	procinit(void);
523void	resetprocpriority(struct proc *);
524void	suspendsched(void);
525int	ltsleep(wchan_t, pri_t, const char *, int,
526	    volatile struct simplelock *);
527void	wakeup(wchan_t);
528void	wakeup_one(wchan_t);
529int	kpause(const char *, bool, int, kmutex_t *);
530void	exit1(struct lwp *, int);
531int	find_stopped_child(struct proc *, pid_t, int, struct proc **, int *);
532struct proc *proc_alloc(void);
533void	proc0_init(void);
534void	proc_free(struct proc *, struct rusage *);
535void	proc_free_mem(struct proc *);
536void	exit_lwps(struct lwp *l);
537int	fork1(struct lwp *, int, int, void *, size_t,
538	    void (*)(void *), void *, register_t *, struct proc **);
539void	rqinit(void);
540int	pgid_in_session(struct proc *, pid_t);
541#ifndef cpu_idle
542void	cpu_idle(void);
543#endif
544void	cpu_exit(struct lwp *);
545void	cpu_lwp_fork(struct lwp *, struct lwp *, void *, size_t,
546	    void (*)(void *), void *);
547#ifndef cpu_lwp_free
548void	cpu_lwp_free(struct lwp *, int);
549void	cpu_lwp_free2(struct lwp *);
550#endif
551
552#ifdef __HAVE_SYSCALL_INTERN
553void	syscall_intern(struct proc *);
554#endif
555
556void	child_return(void *);
557
558int	proc_isunder(struct proc *, struct lwp *);
559void	proc_stop(struct proc *, int, int);
560
561void	p_sugid(struct proc *);
562
563int	proc_vmspace_getref(struct proc *, struct vmspace **);
564void	proc_crmod_leave(kauth_cred_t, kauth_cred_t, bool);
565void	proc_crmod_enter(void);
566int	proc_addref(struct proc *);
567void	proc_delref(struct proc *);
568void	proc_drainrefs(struct proc *);
569
570int	proc_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
571void	proc_specific_key_delete(specificdata_key_t);
572void 	proc_initspecific(struct proc *);
573void 	proc_finispecific(struct proc *);
574void *	proc_getspecific(struct proc *, specificdata_key_t);
575void	proc_setspecific(struct proc *, specificdata_key_t, void *);
576
577int	proclist_foreach_call(struct proclist *,
578    int (*)(struct proc *, void *arg), void *);
579static __inline struct proc *_proclist_skipmarker(struct proc *);
580
581static __inline struct proc *
582_proclist_skipmarker(struct proc *p0)
583{
584	struct proc *p = p0;
585
586	while (p != NULL && p->p_flag & PK_MARKER)
587		p = LIST_NEXT(p, p_list);
588
589	return p;
590}
591#define	PROCLIST_FOREACH(var, head)					\
592	for ((var) = LIST_FIRST(head);					\
593		((var) = _proclist_skipmarker(var)) != NULL;		\
594		(var) = LIST_NEXT(var, p_list))
595
596#if defined(LOCKDEBUG)
597void assert_sleepable(struct simplelock *, const char *);
598#define	ASSERT_SLEEPABLE(lk, msg)	assert_sleepable((lk), (msg))
599#else /* defined(LOCKDEBUG) */
600#define	ASSERT_SLEEPABLE(lk, msg)	/* nothing */
601#endif /* defined(LOCKDEBUG) */
602
603/* Compatibility with old, non-interlocked tsleep call */
604#define	tsleep(chan, pri, wmesg, timo)					\
605	ltsleep(chan, pri, wmesg, timo, NULL)
606
607#if defined(MULTIPROCESSOR)
608void	proc_trampoline_mp(void);	/* XXX */
609#endif
610
611#ifdef KSTACK_CHECK_MAGIC
612void kstack_setup_magic(const struct lwp *);
613void kstack_check_magic(const struct lwp *);
614#endif
615
616/*
617 * kernel stack paramaters
618 * XXX require sizeof(struct user)
619 */
620/* the lowest address of kernel stack */
621#ifndef KSTACK_LOWEST_ADDR
622#define	KSTACK_LOWEST_ADDR(l)	((caddr_t)ALIGN((l)->l_addr + 1))
623#endif
624/* size of kernel stack */
625#ifndef KSTACK_SIZE
626#define	KSTACK_SIZE	(USPACE - ALIGN(sizeof(struct user)))
627#endif
628
629#endif	/* _KERNEL */
630#endif	/* !_SYS_PROC_H_ */
631