proc.h revision 1.324
1/*	$NetBSD: proc.h,v 1.324 2015/11/26 13:15:34 martin Exp $	*/
2
3/*-
4 * Copyright (c) 2006, 2007, 2008 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*-
33 * Copyright (c) 1986, 1989, 1991, 1993
34 *	The Regents of the University of California.  All rights reserved.
35 * (c) UNIX System Laboratories, Inc.
36 * All or some portions of this file are derived from material licensed
37 * to the University of California by American Telephone and Telegraph
38 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
39 * the permission of UNIX System Laboratories, Inc.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 *    notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 *    notice, this list of conditions and the following disclaimer in the
48 *    documentation and/or other materials provided with the distribution.
49 * 3. Neither the name of the University nor the names of its contributors
50 *    may be used to endorse or promote products derived from this software
51 *    without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 *	@(#)proc.h	8.15 (Berkeley) 5/19/95
66 */
67
68#ifndef _SYS_PROC_H_
69#define	_SYS_PROC_H_
70
71#include <sys/lwp.h>
72
73#if defined(_KMEMUSER) || defined(_KERNEL)
74
75#if defined(_KERNEL_OPT)
76#include "opt_multiprocessor.h"
77#include "opt_kstack.h"
78#include "opt_lockdebug.h"
79#endif
80
81#include <machine/proc.h>		/* Machine-dependent proc substruct */
82#include <machine/pcb.h>
83#include <sys/aio.h>
84#include <sys/rwlock.h>
85#include <sys/mqueue.h>
86#include <sys/mutex.h>
87#include <sys/condvar.h>
88#include <sys/queue.h>
89#include <sys/signalvar.h>
90#include <sys/siginfo.h>
91#include <sys/event.h>
92#include <sys/specificdata.h>
93
94#ifndef _KERNEL
95#include <sys/time.h>
96#include <sys/resource.h>
97#endif
98
99/*
100 * One structure allocated per session.
101 */
102struct session {
103	int		s_count;	/* Ref cnt; pgrps in session */
104	u_int		s_flags;
105#define	S_LOGIN_SET	1		/* s_login set in this session */
106	struct proc	*s_leader;	/* Session leader */
107	struct vnode	*s_ttyvp;	/* Vnode of controlling terminal */
108	struct tty	*s_ttyp;	/* Controlling terminal */
109	char		s_login[MAXLOGNAME]; /* Setlogin() name */
110	pid_t		s_sid;		/* Session ID (pid of leader) */
111};
112
113/*
114 * One structure allocated per process group.
115 */
116struct pgrp {
117	LIST_HEAD(, proc) pg_members;	/* Pointer to pgrp members */
118	struct session	*pg_session;	/* Pointer to session */
119	pid_t		pg_id;		/* Pgrp id */
120	int		pg_jobc;	/*
121					 * Number of processes qualifying
122					 * pgrp for job control
123					 */
124};
125
126/*
127 * One structure allocated per emulation.
128 */
129struct exec_package;
130struct ras;
131struct kauth_cred;
132
133struct emul {
134	const char	*e_name;	/* Symbolic name */
135	const char	*e_path;	/* Extra emulation path (NULL if none)*/
136#ifndef __HAVE_MINIMAL_EMUL
137	int		e_flags;	/* Miscellaneous flags, see above */
138					/* Syscall handling function */
139	const int	*e_errno;	/* Errno array */
140	int		e_nosys;	/* Offset of the nosys() syscall */
141	int		e_nsysent;	/* Number of system call entries */
142#endif
143	struct sysent	*e_sysent;	/* System call array */
144	const char * const *e_syscallnames; /* System call name array */
145					/* Signal sending function */
146	void		(*e_sendsig)(const struct ksiginfo *,
147					  const sigset_t *);
148	void		(*e_trapsignal)(struct lwp *, struct ksiginfo *);
149	int		(*e_tracesig)(struct proc *, int);
150	char		*e_sigcode;	/* Start of sigcode */
151	char		*e_esigcode;	/* End of sigcode */
152					/* Set registers before execution */
153	struct uvm_object **e_sigobject;/* shared sigcode object */
154	void		(*e_setregs)(struct lwp *, struct exec_package *,
155					  vaddr_t);
156
157					/* Per-process hooks */
158	void		(*e_proc_exec)(struct proc *, struct exec_package *);
159	void		(*e_proc_fork)(struct proc *, struct lwp *, int);
160	void		(*e_proc_exit)(struct proc *);
161	void		(*e_lwp_fork)(struct lwp *, struct lwp *);
162	void		(*e_lwp_exit)(struct lwp *);
163
164#ifdef __HAVE_SYSCALL_INTERN
165	void		(*e_syscall_intern)(struct proc *);
166#else
167	void		(*e_syscall)(void);
168#endif
169					/* Emulation specific sysctl data */
170	struct sysctlnode *e_sysctlovly;
171	int		(*e_fault)(struct proc *, vaddr_t, int);
172
173	vaddr_t		(*e_vm_default_addr)(struct proc *, vaddr_t, vsize_t,
174			     int);
175
176	/* Emulation-specific hook for userspace page faults */
177	int		(*e_usertrap)(struct lwp *, vaddr_t, void *);
178
179	size_t		e_ucsize;	/* size of ucontext_t */
180	void		(*e_startlwp)(void *);
181
182	/* Dtrace syscall probe */
183	void 		(*e_dtrace_syscall)(uint32_t, register_t,
184			    const struct sysent *, const void *,
185			    const register_t *, int);
186};
187
188/*
189 * Emulation miscelaneous flags
190 */
191#define	EMUL_HAS_SYS___syscall	0x001	/* Has SYS___syscall */
192
193/*
194 * Description of a process.
195 *
196 * This structure contains the information needed to manage a thread of
197 * control, known in UN*X as a process; it has references to substructures
198 * containing descriptions of things that the process uses, but may share
199 * with related processes.  The process structure and the substructures
200 * are always addressible except for those marked "(PROC ONLY)" below,
201 * which might be addressible only on a processor on which the process
202 * is running.
203 *
204 * Field markings and the corresponding locks:
205 *
206 * a:	p_auxlock
207 * k:	ktrace_mutex
208 * l:	proc_lock
209 * t:	p_stmutex
210 * p:	p_lock
211 * (:	updated atomically
212 * ::	unlocked, stable
213 */
214struct vmspace;
215
216struct proc {
217	LIST_ENTRY(proc) p_list;	/* l: List of all processes */
218
219	kmutex_t	p_auxlock;	/* :: secondary, longer term lock */
220	kmutex_t	*p_lock;	/* :: general mutex */
221	kmutex_t	p_stmutex;	/* :: mutex on profiling state */
222	krwlock_t	p_reflock;	/* p: lock for debugger, procfs */
223	kcondvar_t	p_waitcv;	/* p: wait, stop CV on children */
224	kcondvar_t	p_lwpcv;	/* p: wait, stop CV on LWPs */
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	struct aioproc	*p_aio;		/* p: Asynchronous I/O data */
235	u_int		p_mqueue_cnt;	/* (: Count of open message queues */
236	specificdata_reference
237			p_specdataref;	/*    subsystem proc-specific data */
238
239	int		p_exitsig;	/* l: signal to send to parent on exit */
240	int		p_flag;		/* p: PK_* flags */
241	int		p_sflag;	/* p: PS_* flags */
242	int		p_slflag;	/* s, l: PSL_* flags */
243	int		p_lflag;	/* l: PL_* flags */
244	int		p_stflag;	/* t: PST_* flags */
245	char		p_stat;		/* p: S* process status. */
246	char		p_trace_enabled;/* p: cached by syscall_intern() */
247	char		p_pad1[2];	/*  unused */
248
249	pid_t		p_pid;		/* :: Process identifier. */
250	LIST_ENTRY(proc) p_pglist;	/* l: List of processes in pgrp. */
251	struct proc 	*p_pptr;	/* l: Pointer to parent process. */
252	LIST_ENTRY(proc) p_sibling;	/* l: List of sibling processes. */
253	LIST_HEAD(, proc) p_children;	/* l: List of children. */
254	LIST_HEAD(, lwp) p_lwps;	/* p: List of LWPs. */
255	struct ras	*p_raslist;	/* a: List of RAS entries */
256
257/* The following fields are all zeroed upon creation in fork. */
258#define	p_startzero	p_nlwps
259
260	int 		p_nlwps;	/* p: Number of LWPs */
261	int 		p_nzlwps;	/* p: Number of zombie LWPs */
262	int		p_nrlwps;	/* p: Number running/sleeping LWPs */
263	int		p_nlwpwait;	/* p: Number of LWPs in lwp_wait1() */
264	int		p_ndlwps;	/* p: Number of detached LWPs */
265	int 		p_nlwpid;	/* p: Next LWP ID */
266	u_int		p_nstopchild;	/* l: Count of stopped/dead children */
267	u_int		p_waited;	/* l: parent has waited on child */
268	struct lwp	*p_zomblwp;	/* p: detached LWP to be reaped */
269	struct lwp	*p_vforklwp;	/* p: parent LWP waiting at vfork() */
270
271	/* scheduling */
272	void		*p_sched_info;	/* p: Scheduler-specific structure */
273	fixpt_t		p_estcpu;	/* p: Time avg. value of p_cpticks */
274	fixpt_t		p_estcpu_inherited; /* p: cpu inherited from children */
275	unsigned int	p_forktime;
276	fixpt_t         p_pctcpu;       /* p: %cpu from dead LWPs */
277
278	struct proc	*p_opptr;	/* l: save parent during ptrace. */
279	struct ptimers	*p_timers;	/*    Timers: real, virtual, profiling */
280	struct bintime 	p_rtime;	/* p: real time */
281	u_quad_t 	p_uticks;	/* t: Statclock hits in user mode */
282	u_quad_t 	p_sticks;	/* t: Statclock hits in system mode */
283	u_quad_t 	p_iticks;	/* t: Statclock hits processing intr */
284
285	int		p_traceflag;	/* k: Kernel trace points */
286	void		*p_tracep;	/* k: Trace private data */
287	struct vnode 	*p_textvp;	/* :: Vnode of executable */
288
289	struct emul	*p_emul;	/* :: emulation information */
290	void		*p_emuldata;	/* :: per-proc emul data, or NULL */
291	const struct execsw *p_execsw;	/* :: exec package information */
292	struct klist	p_klist;	/* p: knotes attached to proc */
293
294	LIST_HEAD(, lwp) p_sigwaiters;	/* p: LWPs waiting for signals */
295	sigpend_t	p_sigpend;	/* p: pending signals */
296	struct lcproc	*p_lwpctl;	/* p, a: _lwp_ctl() information */
297	pid_t		p_ppid;		/* :: cached parent pid */
298	pid_t 		p_fpid;		/* :: forked pid */
299
300/*
301 * End area that is zeroed on creation
302 */
303#define	p_endzero	p_startcopy
304
305/*
306 * The following fields are all copied upon creation in fork.
307 */
308#define	p_startcopy	p_sigctx
309
310	struct sigctx 	p_sigctx;	/* p: Shared signal state */
311
312	u_char		p_nice;		/* p: Process "nice" value */
313	char		p_comm[MAXCOMLEN+1];
314					/* p: basename of last exec file */
315	struct pgrp 	*p_pgrp;	/* l: Pointer to process group */
316
317	vaddr_t		p_psstrp;	/* :: address of process's ps_strings */
318	u_int		p_pax;		/* :: PAX flags */
319
320/*
321 * End area that is copied on creation
322 */
323#define	p_endcopy	p_xstat
324
325	u_short		p_xstat;	/* p: Exit status for wait; also stop signal */
326	u_short		p_acflag;	/* p: Acc. flags; see struct lwp also */
327	struct mdproc	p_md;		/* p: Any machine-dependent fields */
328	vaddr_t		p_stackbase;	/* :: ASLR randomized stack base */
329	struct kdtrace_proc *p_dtrace;	/* :: DTrace-specific data. */
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#endif	/* _KMEMUSER || _KERNEL */
337
338/*
339 * Status values.
340 */
341#define	SIDL		1		/* Process being created by fork */
342#define	SACTIVE		2		/* Process is not stopped */
343#define	SDYING		3		/* About to die */
344#define	SSTOP		4		/* Process debugging or suspension */
345#define	SZOMB		5		/* Awaiting collection by parent */
346#define	SDEAD	 	6		/* Almost a zombie */
347
348#define	P_ZOMBIE(p)	\
349    ((p)->p_stat == SZOMB || (p)->p_stat == SDYING || (p)->p_stat == SDEAD)
350
351/*
352 * These flags are kept in p_flag and are protected by p_lock.  Access from
353 * process context only.
354 */
355#define	PK_ADVLOCK	0x00000001 /* Process may hold a POSIX advisory lock */
356#define	PK_SYSTEM	0x00000002 /* System process (kthread) */
357#define	PK_SYSVSEM	0x00000004 /* Used SysV semaphores */
358#define	PK_SUGID	0x00000100 /* Had set id privileges since last exec */
359#define	PK_EXEC		0x00004000 /* Process called exec */
360#define	PK_NOCLDWAIT	0x00020000 /* No zombies if child dies */
361#define	PK_32		0x00040000 /* 32-bit process (used on 64-bit kernels) */
362#define	PK_CLDSIGIGN	0x00080000 /* Process is ignoring SIGCHLD */
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_lock.  Access from
367 * process context only.
368 */
369#define	PS_NOCLDSTOP	0x00000008 /* No SIGCHLD when children stop */
370#define	PS_RUMP_LWPEXIT	0x00000400 /* LWPs in RUMP kernel should exit for GC */
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_STOPPING	0x80000000 /* Transitioning SACTIVE -> SSTOP */
378
379/*
380 * These flags are kept in p_sflag and are protected by the proc_lock
381 * and p_lock.  Access from process context only.
382 */
383#define	PSL_TRACEFORK	0x00000001 /* traced process wants fork events */
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#define	PSL_SYSCALLEMU	0x08000000 /* cancel in-progress syscall */
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 proc_lock.  Access
397 * from process context only.
398 */
399#define	PL_CONTROLT	0x00000002 /* Has a controlling terminal */
400#define	PL_PPWAIT	0x00000010 /* Parent is waiting for child exec/exit */
401#define	PL_SIGCOMPAT	0x00000200 /* Has used compat signal trampoline */
402#define	PL_ORPHANPG	0x20000000 /* Member of an orphaned pgrp */
403
404#if defined(_KMEMUSER) || defined(_KERNEL)
405
406/*
407 * Macro to compute the exit signal to be delivered.
408 */
409#define	P_EXITSIG(p)	\
410    (((p)->p_slflag & (PSL_TRACED|PSL_FSTRACE)) ? SIGCHLD : p->p_exitsig)
411
412LIST_HEAD(proclist, proc);		/* A list of processes */
413
414/*
415 * This structure associates a proclist with its lock.
416 */
417struct proclist_desc {
418	struct proclist	*pd_list;	/* The list */
419	/*
420	 * XXX Add a pointer to the proclist's lock eventually.
421	 */
422};
423
424#ifdef _KERNEL
425
426/*
427 * We use process IDs <= PID_MAX until there are > 16k processes.
428 * NO_PGID is used to represent "no process group" for a tty.
429 */
430#define	PID_MAX		30000
431#define	NO_PGID		((pid_t)-1)
432
433#define	SESS_LEADER(p)	((p)->p_session->s_leader == (p))
434
435/*
436 * Flags passed to fork1().
437 */
438#define	FORK_PPWAIT	0x0001		/* Block parent until child exit */
439#define	FORK_SHAREVM	0x0002		/* Share vmspace with parent */
440#define	FORK_SHARECWD	0x0004		/* Share cdir/rdir/cmask */
441#define	FORK_SHAREFILES	0x0008		/* Share file descriptors */
442#define	FORK_SHARESIGS	0x0010		/* Share signal actions */
443#define	FORK_NOWAIT	0x0020		/* Make init the parent of the child */
444#define	FORK_CLEANFILES	0x0040		/* Start with a clean descriptor set */
445#define	FORK_SYSTEM	0x0080		/* Fork a kernel thread */
446
447extern struct proc	proc0;		/* Process slot for swapper */
448extern u_int		nprocs;		/* Current number of procs */
449extern int		maxproc;	/* Max number of procs */
450#define	vmspace_kernel()	(proc0.p_vmspace)
451
452extern kmutex_t		*proc_lock;
453extern struct proclist	allproc;	/* List of all processes */
454extern struct proclist	zombproc;	/* List of zombie processes */
455
456extern struct proc	*initproc;	/* Process slots for init, pager */
457
458extern const struct proclist_desc proclists[];
459
460extern struct pool	ptimer_pool;	/* Memory pool for ptimers */
461
462int		proc_find_locked(struct lwp *, struct proc **, pid_t);
463proc_t *	proc_find_raw(pid_t);
464proc_t *	proc_find(pid_t);		/* Find process by ID */
465struct pgrp *	pgrp_find(pid_t);		/* Find process group by ID */
466
467void	procinit(void);
468void	procinit_sysctl(void);
469int	proc_enterpgrp(struct proc *, pid_t, pid_t, bool);
470void	proc_leavepgrp(struct proc *);
471void	proc_sesshold(struct session *);
472void	proc_sessrele(struct session *);
473void	fixjobc(struct proc *, struct pgrp *, int);
474
475int	tsleep(wchan_t, pri_t, const char *, int);
476int	mtsleep(wchan_t, pri_t, const char *, int, kmutex_t *);
477void	wakeup(wchan_t);
478int	kpause(const char *, bool, int, kmutex_t *);
479void	exit1(struct lwp *, int) __dead;
480int	kill1(struct lwp *l, pid_t pid, ksiginfo_t *ksi, register_t *retval);
481int	do_sys_wait(int *, int *, int, struct rusage *);
482struct proc *proc_alloc(void);
483void	proc0_init(void);
484pid_t	proc_alloc_pid(struct proc *);
485void	proc_free_pid(pid_t);
486void	proc_free_mem(struct proc *);
487void	exit_lwps(struct lwp *l);
488int	fork1(struct lwp *, int, int, void *, size_t,
489	    void (*)(void *), void *, register_t *, struct proc **);
490int	pgid_in_session(struct proc *, pid_t);
491void	cpu_lwp_fork(struct lwp *, struct lwp *, void *, size_t,
492	    void (*)(void *), void *);
493void	cpu_lwp_free(struct lwp *, int);
494void	cpu_lwp_free2(struct lwp *);
495void	cpu_spawn_return(struct lwp*);
496
497#ifdef __HAVE_SYSCALL_INTERN
498void	syscall_intern(struct proc *);
499#endif
500
501void	child_return(void *);
502
503int	proc_isunder(struct proc *, struct lwp *);
504void	proc_stop(struct proc *, int, int);
505int	proc_uidmatch(kauth_cred_t, kauth_cred_t);
506
507int	proc_vmspace_getref(struct proc *, struct vmspace **);
508void	proc_crmod_leave(kauth_cred_t, kauth_cred_t, bool);
509void	proc_crmod_enter(void);
510
511int	proc_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
512void	proc_specific_key_delete(specificdata_key_t);
513void	proc_initspecific(struct proc *);
514void	proc_finispecific(struct proc *);
515void *	proc_getspecific(struct proc *, specificdata_key_t);
516void	proc_setspecific(struct proc *, specificdata_key_t, void *);
517int	proc_compare(const struct proc *, const struct lwp *,
518    const struct proc *, const struct lwp *);
519
520int	proclist_foreach_call(struct proclist *,
521    int (*)(struct proc *, void *arg), void *);
522
523static inline struct proc *
524_proclist_skipmarker(struct proc *p0)
525{
526	struct proc *p = p0;
527
528	while (p != NULL && p->p_flag & PK_MARKER)
529		p = LIST_NEXT(p, p_list);
530
531	return p;
532}
533
534/*
535 * PROCLIST_FOREACH: iterate on the given proclist, skipping PK_MARKER ones.
536 */
537#define	PROCLIST_FOREACH(var, head)					\
538	for ((var) = LIST_FIRST(head);					\
539		((var) = _proclist_skipmarker(var)) != NULL;		\
540		(var) = LIST_NEXT(var, p_list))
541
542#ifdef KSTACK_CHECK_MAGIC
543void	kstack_setup_magic(const struct lwp *);
544void	kstack_check_magic(const struct lwp *);
545#else
546#define	kstack_setup_magic(x)
547#define	kstack_check_magic(x)
548#endif
549
550extern struct emul emul_netbsd;
551
552#endif	/* _KERNEL */
553
554/*
555 * Kernel stack parameters.
556 *
557 * KSTACK_LOWEST_ADDR: return the lowest address of the LWP's kernel stack,
558 * excluding red-zone.
559 *
560 * KSTACK_SIZE: the size kernel stack for a LWP, excluding red-zone.
561 *
562 * if <machine/proc.h> provides the MD definition, it will be used.
563 */
564#ifndef KSTACK_LOWEST_ADDR
565#define	KSTACK_LOWEST_ADDR(l)	((void *)ALIGN((struct pcb *)((l)->l_addr) + 1))
566#endif
567#ifndef KSTACK_SIZE
568#define	KSTACK_SIZE		(USPACE - ALIGN(sizeof(struct pcb)))
569#endif
570
571#endif	/* _KMEMUSER || _KERNEL */
572
573#endif	/* !_SYS_PROC_H_ */
574