Tue Jan 28 16:40:27 2020 UTC ()
Put pri_t back to an int.  It looks like there might be a sign extension
issue somewhere but it's not worth the hassle trying to find it.


(ad)
diff -r1.198 -r1.199 src/sys/sys/lwp.h
diff -r1.103 -r1.104 src/sys/sys/types.h

cvs diff -r1.198 -r1.199 src/sys/sys/lwp.h (switch to unified diff)

--- src/sys/sys/lwp.h 2020/01/25 15:41:52 1.198
+++ src/sys/sys/lwp.h 2020/01/28 16:40:27 1.199
@@ -1,574 +1,574 @@ @@ -1,574 +1,574 @@
1/* $NetBSD: lwp.h,v 1.198 2020/01/25 15:41:52 ad Exp $ */ 1/* $NetBSD: lwp.h,v 1.199 2020/01/28 16:40:27 ad Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010, 2019, 2020 4 * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010, 2019, 2020
5 * The NetBSD Foundation, Inc. 5 * The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Nathan J. Williams and Andrew Doran. 9 * by Nathan J. Williams and Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#ifndef _SYS_LWP_H_ 33#ifndef _SYS_LWP_H_
34#define _SYS_LWP_H_ 34#define _SYS_LWP_H_
35 35
36#if defined(_KERNEL) || defined(_KMEMUSER) 36#if defined(_KERNEL) || defined(_KMEMUSER)
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/time.h> 39#include <sys/time.h>
40#include <sys/queue.h> 40#include <sys/queue.h>
41#include <sys/callout.h> 41#include <sys/callout.h>
42#include <sys/kcpuset.h> 42#include <sys/kcpuset.h>
43#include <sys/mutex.h> 43#include <sys/mutex.h>
44#include <sys/condvar.h> 44#include <sys/condvar.h>
45#include <sys/signalvar.h> 45#include <sys/signalvar.h>
46#include <sys/sched.h> 46#include <sys/sched.h>
47#include <sys/specificdata.h> 47#include <sys/specificdata.h>
48#include <sys/syncobj.h> 48#include <sys/syncobj.h>
49#include <sys/resource.h> 49#include <sys/resource.h>
50 50
51#if defined(_KERNEL) 51#if defined(_KERNEL)
52struct lwp; 52struct lwp;
53/* forward declare this for <machine/cpu.h> so it can get l_cpu. */ 53/* forward declare this for <machine/cpu.h> so it can get l_cpu. */
54static __inline struct cpu_info *lwp_getcpu(struct lwp *); 54static __inline struct cpu_info *lwp_getcpu(struct lwp *);
55#include <machine/cpu.h> /* curcpu() and cpu_info */ 55#include <machine/cpu.h> /* curcpu() and cpu_info */
56#ifdef _KERNEL_OPT 56#ifdef _KERNEL_OPT
57#include "opt_kmsan.h" 57#include "opt_kmsan.h"
58#endif 58#endif
59#endif 59#endif
60 60
61#include <machine/proc.h> /* Machine-dependent proc substruct. */ 61#include <machine/proc.h> /* Machine-dependent proc substruct. */
62 62
63/* 63/*
64 * Lightweight process. Field markings and the corresponding locks: 64 * Lightweight process. Field markings and the corresponding locks:
65 * 65 *
66 * a: proc_lock 66 * a: proc_lock
67 * c: condition variable interlock, passed to cv_wait() 67 * c: condition variable interlock, passed to cv_wait()
68 * l: *l_mutex 68 * l: *l_mutex
69 * p: l_proc->p_lock 69 * p: l_proc->p_lock
70 * s: spc_mutex, which may or may not be referenced by l_mutex 70 * s: spc_mutex, which may or may not be referenced by l_mutex
71 * S: l_selcluster->sc_lock 71 * S: l_selcluster->sc_lock
72 * (: unlocked, stable 72 * (: unlocked, stable
73 * !: unlocked, may only be reliably accessed by the LWP itself 73 * !: unlocked, may only be reliably accessed by the LWP itself
74 * 74 *
75 * Fields are clustered together by usage (to increase the likelihood 75 * Fields are clustered together by usage (to increase the likelihood
76 * of cache hits) and by size (to reduce dead space in the structure). 76 * of cache hits) and by size (to reduce dead space in the structure).
77 */ 77 */
78 78
79#include <sys/pcu.h> 79#include <sys/pcu.h>
80 80
81struct lockdebug; 81struct lockdebug;
82struct sysent; 82struct sysent;
83 83
84struct lwp { 84struct lwp {
85 /* Scheduling and overall state. */ 85 /* Scheduling and overall state. */
86 TAILQ_ENTRY(lwp) l_runq; /* s: run queue */ 86 TAILQ_ENTRY(lwp) l_runq; /* s: run queue */
87 union { 87 union {
88 void * info; /* s: scheduler-specific structure */ 88 void * info; /* s: scheduler-specific structure */
89 u_int timeslice; /* l: time-quantum for SCHED_M2 */ 89 u_int timeslice; /* l: time-quantum for SCHED_M2 */
90 } l_sched; 90 } l_sched;
91 struct cpu_info *volatile l_cpu;/* s: CPU we're on if LSONPROC */ 91 struct cpu_info *volatile l_cpu;/* s: CPU we're on if LSONPROC */
92 kmutex_t * volatile l_mutex; /* l: ptr to mutex on sched state */ 92 kmutex_t * volatile l_mutex; /* l: ptr to mutex on sched state */
93 void *l_addr; /* l: PCB address; use lwp_getpcb() */ 93 void *l_addr; /* l: PCB address; use lwp_getpcb() */
94 struct mdlwp l_md; /* l: machine-dependent fields. */ 94 struct mdlwp l_md; /* l: machine-dependent fields. */
95 struct bintime l_rtime; /* l: real time */ 95 struct bintime l_rtime; /* l: real time */
96 struct bintime l_stime; /* l: start time (while ONPROC) */ 96 struct bintime l_stime; /* l: start time (while ONPROC) */
97 int l_flag; /* l: misc flag values */ 97 int l_flag; /* l: misc flag values */
98 u_int l_swtime; /* l: time swapped in or out */ 98 u_int l_swtime; /* l: time swapped in or out */
99 u_int l_rticks; /* l: Saved start time of run */ 99 u_int l_rticks; /* l: Saved start time of run */
100 u_int l_rticksum; /* l: Sum of ticks spent running */ 100 u_int l_rticksum; /* l: Sum of ticks spent running */
101 u_int l_slpticks; /* l: Saved start time of sleep */ 101 u_int l_slpticks; /* l: Saved start time of sleep */
102 u_int l_slpticksum; /* l: Sum of ticks spent sleeping */ 102 u_int l_slpticksum; /* l: Sum of ticks spent sleeping */
103 int l_biglocks; /* l: biglock count before sleep */ 103 int l_biglocks; /* l: biglock count before sleep */
104 short l_stat; /* l: overall LWP status */ 104 short l_stat; /* l: overall LWP status */
105 short l_class; /* l: scheduling class */ 105 short l_class; /* l: scheduling class */
106 short l_kpriority; /* !: has kernel priority boost */ 106 int l_kpriority; /* !: has kernel priority boost */
107 pri_t l_kpribase; /* !: kernel priority base level */ 107 pri_t l_kpribase; /* !: kernel priority base level */
108 pri_t l_priority; /* l: scheduler priority */ 108 pri_t l_priority; /* l: scheduler priority */
109 pri_t l_inheritedprio;/* l: inherited priority */ 109 pri_t l_inheritedprio;/* l: inherited priority */
110 pri_t l_protectprio; /* l: for PTHREAD_PRIO_PROTECT */ 110 pri_t l_protectprio; /* l: for PTHREAD_PRIO_PROTECT */
111 pri_t l_auxprio; /* l: max(inherit,protect) priority */ 111 pri_t l_auxprio; /* l: max(inherit,protect) priority */
112 int l_protectdepth; /* l: for PTHREAD_PRIO_PROTECT */ 112 int l_protectdepth; /* l: for PTHREAD_PRIO_PROTECT */
113 u_int l_cpticks; /* (: Ticks of CPU time */ 113 u_int l_cpticks; /* (: Ticks of CPU time */
114 psetid_t l_psid; /* l: assigned processor-set ID */ 114 psetid_t l_psid; /* l: assigned processor-set ID */
115 fixpt_t l_pctcpu; /* p: %cpu during l_swtime */ 115 fixpt_t l_pctcpu; /* p: %cpu during l_swtime */
116 fixpt_t l_estcpu; /* l: cpu time for SCHED_4BSD */ 116 fixpt_t l_estcpu; /* l: cpu time for SCHED_4BSD */
117 volatile uint64_t l_ncsw; /* l: total context switches */ 117 volatile uint64_t l_ncsw; /* l: total context switches */
118 volatile uint64_t l_nivcsw; /* l: involuntary context switches */ 118 volatile uint64_t l_nivcsw; /* l: involuntary context switches */
119 SLIST_HEAD(, turnstile) l_pi_lenders; /* l: ts lending us priority */ 119 SLIST_HEAD(, turnstile) l_pi_lenders; /* l: ts lending us priority */
120 struct cpu_info *l_target_cpu; /* l: target CPU to migrate */ 120 struct cpu_info *l_target_cpu; /* l: target CPU to migrate */
121 struct lwpctl *l_lwpctl; /* p: lwpctl block kernel address */ 121 struct lwpctl *l_lwpctl; /* p: lwpctl block kernel address */
122 struct lcpage *l_lcpage; /* p: lwpctl containing page */ 122 struct lcpage *l_lcpage; /* p: lwpctl containing page */
123 kcpuset_t *l_affinity; /* l: CPU set for affinity */ 123 kcpuset_t *l_affinity; /* l: CPU set for affinity */
124 124
125 /* Synchronisation. */ 125 /* Synchronisation. */
126 struct turnstile *l_ts; /* l: current turnstile */ 126 struct turnstile *l_ts; /* l: current turnstile */
127 struct syncobj *l_syncobj; /* l: sync object operations set */ 127 struct syncobj *l_syncobj; /* l: sync object operations set */
128 TAILQ_ENTRY(lwp) l_sleepchain; /* l: sleep queue */ 128 TAILQ_ENTRY(lwp) l_sleepchain; /* l: sleep queue */
129 wchan_t l_wchan; /* l: sleep address */ 129 wchan_t l_wchan; /* l: sleep address */
130 const char *l_wmesg; /* l: reason for sleep */ 130 const char *l_wmesg; /* l: reason for sleep */
131 struct sleepq *l_sleepq; /* l: current sleep queue */ 131 struct sleepq *l_sleepq; /* l: current sleep queue */
132 callout_t l_timeout_ch; /* !: callout for tsleep */ 132 callout_t l_timeout_ch; /* !: callout for tsleep */
133 kcondvar_t l_waitcv; /* a: vfork() wait */ 133 kcondvar_t l_waitcv; /* a: vfork() wait */
134 u_int l_slptime; /* l: time since last blocked */ 134 u_int l_slptime; /* l: time since last blocked */
135 bool l_vforkwaiting; /* a: vfork() waiting */ 135 bool l_vforkwaiting; /* a: vfork() waiting */
136 136
137#if PCU_UNIT_COUNT > 0 137#if PCU_UNIT_COUNT > 0
138 struct cpu_info * volatile l_pcu_cpu[PCU_UNIT_COUNT]; 138 struct cpu_info * volatile l_pcu_cpu[PCU_UNIT_COUNT];
139 uint32_t l_pcu_valid; 139 uint32_t l_pcu_valid;
140#endif 140#endif
141 141
142 /* Process level and global state, misc. */ 142 /* Process level and global state, misc. */
143 lwpid_t l_lid; /* (: LWP identifier; local to proc */ 143 lwpid_t l_lid; /* (: LWP identifier; local to proc */
144 LIST_ENTRY(lwp) l_list; /* a: entry on list of all LWPs */ 144 LIST_ENTRY(lwp) l_list; /* a: entry on list of all LWPs */
145 void *l_ctxlink; /* p: uc_link {get,set}context */ 145 void *l_ctxlink; /* p: uc_link {get,set}context */
146 struct proc *l_proc; /* p: parent process */ 146 struct proc *l_proc; /* p: parent process */
147 LIST_ENTRY(lwp) l_sibling; /* p: entry on proc's list of LWPs */ 147 LIST_ENTRY(lwp) l_sibling; /* p: entry on proc's list of LWPs */
148 char *l_name; /* (: name, optional */ 148 char *l_name; /* (: name, optional */
149 lwpid_t l_waiter; /* p: first LWP waiting on us */ 149 lwpid_t l_waiter; /* p: first LWP waiting on us */
150 lwpid_t l_waitingfor; /* p: specific LWP we are waiting on */ 150 lwpid_t l_waitingfor; /* p: specific LWP we are waiting on */
151 int l_prflag; /* p: process level flags */ 151 int l_prflag; /* p: process level flags */
152 u_int l_refcnt; /* p: reference count on this LWP */ 152 u_int l_refcnt; /* p: reference count on this LWP */
153 153
154 /* State of select() or poll(). */ 154 /* State of select() or poll(). */
155 int l_selflag; /* S: polling state flags */ 155 int l_selflag; /* S: polling state flags */
156 int l_selret; /* S: return value of select/poll */ 156 int l_selret; /* S: return value of select/poll */
157 SLIST_HEAD(,selinfo) l_selwait; /* S: descriptors waited on */ 157 SLIST_HEAD(,selinfo) l_selwait; /* S: descriptors waited on */
158 uintptr_t l_selrec; /* !: argument for selrecord() */ 158 uintptr_t l_selrec; /* !: argument for selrecord() */
159 struct selcluster *l_selcluster;/* !: associated cluster data */ 159 struct selcluster *l_selcluster;/* !: associated cluster data */
160 void * l_selbits; /* (: select() bit-field */ 160 void * l_selbits; /* (: select() bit-field */
161 size_t l_selni; /* (: size of a single bit-field */ 161 size_t l_selni; /* (: size of a single bit-field */
162 162
163 /* Signals. */ 163 /* Signals. */
164 int l_sigrestore; /* p: need to restore old sig mask */ 164 int l_sigrestore; /* p: need to restore old sig mask */
165 sigset_t l_sigwaitset; /* p: signals being waited for */ 165 sigset_t l_sigwaitset; /* p: signals being waited for */
166 kcondvar_t l_sigcv; /* p: for sigsuspend() */ 166 kcondvar_t l_sigcv; /* p: for sigsuspend() */
167 struct ksiginfo *l_sigwaited; /* p: delivered signals from set */ 167 struct ksiginfo *l_sigwaited; /* p: delivered signals from set */
168 sigpend_t *l_sigpendset; /* p: XXX issignal()/postsig() baton */ 168 sigpend_t *l_sigpendset; /* p: XXX issignal()/postsig() baton */
169 LIST_ENTRY(lwp) l_sigwaiter; /* p: chain on list of waiting LWPs */ 169 LIST_ENTRY(lwp) l_sigwaiter; /* p: chain on list of waiting LWPs */
170 stack_t l_sigstk; /* p: sp & on stack state variable */ 170 stack_t l_sigstk; /* p: sp & on stack state variable */
171 sigset_t l_sigmask; /* p: signal mask */ 171 sigset_t l_sigmask; /* p: signal mask */
172 sigpend_t l_sigpend; /* p: signals to this LWP */ 172 sigpend_t l_sigpend; /* p: signals to this LWP */
173 sigset_t l_sigoldmask; /* p: mask for sigpause */ 173 sigset_t l_sigoldmask; /* p: mask for sigpause */
174 174
175 /* Private data. */ 175 /* Private data. */
176 specificdata_reference 176 specificdata_reference
177 l_specdataref; /* !: subsystem lwp-specific data */ 177 l_specdataref; /* !: subsystem lwp-specific data */
178 struct timespec l_ktrcsw; /* !: for ktrace CSW trace XXX */ 178 struct timespec l_ktrcsw; /* !: for ktrace CSW trace XXX */
179 void *l_private; /* !: svr4-style lwp-private data */ 179 void *l_private; /* !: svr4-style lwp-private data */
180 struct lwp *l_switchto; /* !: mi_switch: switch to this LWP */ 180 struct lwp *l_switchto; /* !: mi_switch: switch to this LWP */
181 struct kauth_cred *l_cred; /* !: cached credentials */ 181 struct kauth_cred *l_cred; /* !: cached credentials */
182 struct filedesc *l_fd; /* !: cached copy of proc::p_fd */ 182 struct filedesc *l_fd; /* !: cached copy of proc::p_fd */
183 void *l_emuldata; /* !: kernel lwp-private data */ 183 void *l_emuldata; /* !: kernel lwp-private data */
184 struct fstrans_lwp_info *l_fstrans; /* (: fstrans private data */ 184 struct fstrans_lwp_info *l_fstrans; /* (: fstrans private data */
185 u_short l_shlocks; /* !: lockdebug: shared locks held */ 185 u_short l_shlocks; /* !: lockdebug: shared locks held */
186 u_short l_exlocks; /* !: lockdebug: excl. locks held */ 186 u_short l_exlocks; /* !: lockdebug: excl. locks held */
187 u_short l_psrefs; /* !: count of psref held */ 187 u_short l_psrefs; /* !: count of psref held */
188 u_short l_blcnt; /* !: count of kernel_lock held */ 188 u_short l_blcnt; /* !: count of kernel_lock held */
189 volatile int l_nopreempt; /* !: don't preempt me! */ 189 volatile int l_nopreempt; /* !: don't preempt me! */
190 volatile u_int l_dopreempt; /* s: kernel preemption pending */ 190 volatile u_int l_dopreempt; /* s: kernel preemption pending */
191 int l_pflag; /* !: LWP private flags */ 191 int l_pflag; /* !: LWP private flags */
192 int l_dupfd; /* !: side return from cloning devs XXX */ 192 int l_dupfd; /* !: side return from cloning devs XXX */
193 const struct sysent * volatile l_sysent;/* !: currently active syscall */ 193 const struct sysent * volatile l_sysent;/* !: currently active syscall */
194 struct rusage l_ru; /* !: accounting information */ 194 struct rusage l_ru; /* !: accounting information */
195 uint64_t l_pfailtime; /* !: for kernel preemption */ 195 uint64_t l_pfailtime; /* !: for kernel preemption */
196 uintptr_t l_pfailaddr; /* !: for kernel preemption */ 196 uintptr_t l_pfailaddr; /* !: for kernel preemption */
197 uintptr_t l_pfaillock; /* !: for kernel preemption */ 197 uintptr_t l_pfaillock; /* !: for kernel preemption */
198 _TAILQ_HEAD(,struct lockdebug,volatile) l_ld_locks;/* !: locks held by LWP */ 198 _TAILQ_HEAD(,struct lockdebug,volatile) l_ld_locks;/* !: locks held by LWP */
199 volatile void *l_ld_wanted; /* !: lock currently wanted by LWP */ 199 volatile void *l_ld_wanted; /* !: lock currently wanted by LWP */
200 uintptr_t l_rwcallsite; /* !: rwlock actual callsite */ 200 uintptr_t l_rwcallsite; /* !: rwlock actual callsite */
201 int l_tcgen; /* !: for timecounter removal */ 201 int l_tcgen; /* !: for timecounter removal */
202 202
203 /* These are only used by 'options SYSCALL_TIMES'. */ 203 /* These are only used by 'options SYSCALL_TIMES'. */
204 uint32_t l_syscall_time; /* !: time epoch for current syscall */ 204 uint32_t l_syscall_time; /* !: time epoch for current syscall */
205 uint64_t *l_syscall_counter; /* !: counter for current process */ 205 uint64_t *l_syscall_counter; /* !: counter for current process */
206 206
207 struct kdtrace_thread *l_dtrace; /* (: DTrace-specific data. */ 207 struct kdtrace_thread *l_dtrace; /* (: DTrace-specific data. */
208 208
209#ifdef KMSAN 209#ifdef KMSAN
210 void *l_kmsan; /* !: KMSAN private data. */ 210 void *l_kmsan; /* !: KMSAN private data. */
211#endif 211#endif
212}; 212};
213 213
214/* 214/*
215 * UAREA_PCB_OFFSET: an offset of PCB structure in the uarea. MD code may 215 * UAREA_PCB_OFFSET: an offset of PCB structure in the uarea. MD code may
216 * define it in <machine/proc.h>, to indicate a different uarea layout. 216 * define it in <machine/proc.h>, to indicate a different uarea layout.
217 */ 217 */
218#ifndef UAREA_PCB_OFFSET 218#ifndef UAREA_PCB_OFFSET
219#define UAREA_PCB_OFFSET 0 219#define UAREA_PCB_OFFSET 0
220#endif 220#endif
221 221
222LIST_HEAD(lwplist, lwp); /* A list of LWPs. */ 222LIST_HEAD(lwplist, lwp); /* A list of LWPs. */
223 223
224#ifdef _KERNEL 224#ifdef _KERNEL
225extern struct lwplist alllwp; /* List of all LWPs. */ 225extern struct lwplist alllwp; /* List of all LWPs. */
226extern lwp_t lwp0; /* LWP for proc0. */ 226extern lwp_t lwp0; /* LWP for proc0. */
227extern int maxlwp __read_mostly; /* max number of lwps */ 227extern int maxlwp __read_mostly; /* max number of lwps */
228#ifndef MAXLWP 228#ifndef MAXLWP
229#define MAXLWP 2048 229#define MAXLWP 2048
230#endif 230#endif
231#ifndef __HAVE_CPU_MAXLWP 231#ifndef __HAVE_CPU_MAXLWP
232#define cpu_maxlwp() MAXLWP 232#define cpu_maxlwp() MAXLWP
233#endif 233#endif
234#endif 234#endif
235 235
236#endif /* _KERNEL || _KMEMUSER */ 236#endif /* _KERNEL || _KMEMUSER */
237 237
238/* These flags are kept in l_flag. */ 238/* These flags are kept in l_flag. */
239#define LW_IDLE 0x00000001 /* Idle lwp. */ 239#define LW_IDLE 0x00000001 /* Idle lwp. */
240#define LW_LWPCTL 0x00000002 /* Adjust lwpctl in userret */ 240#define LW_LWPCTL 0x00000002 /* Adjust lwpctl in userret */
241#define LW_CVLOCKDEBUG 0x00000004 /* Waker does lockdebug */ 241#define LW_CVLOCKDEBUG 0x00000004 /* Waker does lockdebug */
242#define LW_SINTR 0x00000080 /* Sleep is interruptible. */ 242#define LW_SINTR 0x00000080 /* Sleep is interruptible. */
243#define LW_SYSTEM 0x00000200 /* Kernel thread */ 243#define LW_SYSTEM 0x00000200 /* Kernel thread */
244#define LW_DBGSUSPEND 0x00010000 /* Suspend by debugger */ 244#define LW_DBGSUSPEND 0x00010000 /* Suspend by debugger */
245#define LW_WSUSPEND 0x00020000 /* Suspend before return to user */ 245#define LW_WSUSPEND 0x00020000 /* Suspend before return to user */
246#define LW_BATCH 0x00040000 /* LWP tends to hog CPU */ 246#define LW_BATCH 0x00040000 /* LWP tends to hog CPU */
247#define LW_WCORE 0x00080000 /* Stop for core dump on return to user */ 247#define LW_WCORE 0x00080000 /* Stop for core dump on return to user */
248#define LW_WEXIT 0x00100000 /* Exit before return to user */ 248#define LW_WEXIT 0x00100000 /* Exit before return to user */
249#define LW_PENDSIG 0x01000000 /* Pending signal for us */ 249#define LW_PENDSIG 0x01000000 /* Pending signal for us */
250#define LW_CANCELLED 0x02000000 /* tsleep should not sleep */ 250#define LW_CANCELLED 0x02000000 /* tsleep should not sleep */
251#define LW_WREBOOT 0x08000000 /* System is rebooting, please suspend */ 251#define LW_WREBOOT 0x08000000 /* System is rebooting, please suspend */
252#define LW_UNPARKED 0x10000000 /* Unpark op pending */ 252#define LW_UNPARKED 0x10000000 /* Unpark op pending */
253#define LW_RUNNING 0x20000000 /* Active on a CPU */ 253#define LW_RUNNING 0x20000000 /* Active on a CPU */
254#define LW_RUMP_CLEAR 0x40000000 /* Clear curlwp in RUMP scheduler */ 254#define LW_RUMP_CLEAR 0x40000000 /* Clear curlwp in RUMP scheduler */
255#define LW_RUMP_QEXIT 0x80000000 /* LWP should exit ASAP */ 255#define LW_RUMP_QEXIT 0x80000000 /* LWP should exit ASAP */
256 256
257/* The second set of flags is kept in l_pflag. */ 257/* The second set of flags is kept in l_pflag. */
258#define LP_KTRACTIVE 0x00000001 /* Executing ktrace operation */ 258#define LP_KTRACTIVE 0x00000001 /* Executing ktrace operation */
259#define LP_KTRCSW 0x00000002 /* ktrace context switch marker */ 259#define LP_KTRCSW 0x00000002 /* ktrace context switch marker */
260#define LP_KTRCSWUSER 0x00000004 /* ktrace context switch marker */ 260#define LP_KTRCSWUSER 0x00000004 /* ktrace context switch marker */
261#define LP_PIDLID 0x00000008 /* free LID from PID space on exit */ 261#define LP_PIDLID 0x00000008 /* free LID from PID space on exit */
262#define LP_OWEUPC 0x00000010 /* Owe user profiling tick */ 262#define LP_OWEUPC 0x00000010 /* Owe user profiling tick */
263#define LP_MPSAFE 0x00000020 /* Starts life without kernel_lock */ 263#define LP_MPSAFE 0x00000020 /* Starts life without kernel_lock */
264#define LP_INTR 0x00000040 /* Soft interrupt handler */ 264#define LP_INTR 0x00000040 /* Soft interrupt handler */
265#define LP_SYSCTLWRITE 0x00000080 /* sysctl write lock held */ 265#define LP_SYSCTLWRITE 0x00000080 /* sysctl write lock held */
266#define LP_MUSTJOIN 0x00000100 /* Must join kthread on exit */ 266#define LP_MUSTJOIN 0x00000100 /* Must join kthread on exit */
267#define LP_SINGLESTEP 0x00000400 /* Single step thread in ptrace(2) */ 267#define LP_SINGLESTEP 0x00000400 /* Single step thread in ptrace(2) */
268#define LP_TIMEINTR 0x00010000 /* Time this soft interrupt */ 268#define LP_TIMEINTR 0x00010000 /* Time this soft interrupt */
269#define LP_PREEMPTING 0x00020000 /* mi_switch called involuntarily */ 269#define LP_PREEMPTING 0x00020000 /* mi_switch called involuntarily */
270#define LP_TELEPORT 0x40000000 /* Teleport to new CPU on preempt() */ 270#define LP_TELEPORT 0x40000000 /* Teleport to new CPU on preempt() */
271#define LP_BOUND 0x80000000 /* Bound to a CPU */ 271#define LP_BOUND 0x80000000 /* Bound to a CPU */
272 272
273/* The third set is kept in l_prflag. */ 273/* The third set is kept in l_prflag. */
274#define LPR_DETACHED 0x00800000 /* Won't be waited for. */ 274#define LPR_DETACHED 0x00800000 /* Won't be waited for. */
275#define LPR_CRMOD 0x00000100 /* Credentials modified */ 275#define LPR_CRMOD 0x00000100 /* Credentials modified */
276 276
277/* 277/*
278 * Mask indicating that there is "exceptional" work to be done on return to 278 * Mask indicating that there is "exceptional" work to be done on return to
279 * user. 279 * user.
280 */ 280 */
281#define LW_USERRET \ 281#define LW_USERRET \
282 (LW_WEXIT | LW_PENDSIG | LW_WREBOOT | LW_WSUSPEND | LW_WCORE | LW_LWPCTL) 282 (LW_WEXIT | LW_PENDSIG | LW_WREBOOT | LW_WSUSPEND | LW_WCORE | LW_LWPCTL)
283 283
284/* 284/*
285 * Status values. 285 * Status values.
286 * 286 *
287 * A note about LSRUN and LSONPROC: LSRUN indicates that a process is 287 * A note about LSRUN and LSONPROC: LSRUN indicates that a process is
288 * runnable but *not* yet running, i.e. is on a run queue. LSONPROC 288 * runnable but *not* yet running, i.e. is on a run queue. LSONPROC
289 * indicates that the process is actually executing on a CPU, i.e. 289 * indicates that the process is actually executing on a CPU, i.e.
290 * it is no longer on a run queue. 290 * it is no longer on a run queue.
291 * 291 *
292 * These values are set in stone and must not be reused with future changes. 292 * These values are set in stone and must not be reused with future changes.
293 */ 293 */
294#define LSIDL 1 /* Process being created by fork. */ 294#define LSIDL 1 /* Process being created by fork. */
295#define LSRUN 2 /* Currently runnable. */ 295#define LSRUN 2 /* Currently runnable. */
296#define LSSLEEP 3 /* Sleeping on an address. */ 296#define LSSLEEP 3 /* Sleeping on an address. */
297#define LSSTOP 4 /* Process debugging or suspension. */ 297#define LSSTOP 4 /* Process debugging or suspension. */
298#define LSZOMB 5 /* Awaiting collection by parent. */ 298#define LSZOMB 5 /* Awaiting collection by parent. */
299/* define LSDEAD 6 Process is almost a zombie. (removed in 5.0) */ 299/* define LSDEAD 6 Process is almost a zombie. (removed in 5.0) */
300#define LSONPROC 7 /* Process is currently on a CPU. */ 300#define LSONPROC 7 /* Process is currently on a CPU. */
301#define LSSUSPENDED 8 /* Not running, not signalable. */ 301#define LSSUSPENDED 8 /* Not running, not signalable. */
302 302
303#if defined(_KERNEL) || defined(_KMEMUSER) 303#if defined(_KERNEL) || defined(_KMEMUSER)
304static __inline void * 304static __inline void *
305lwp_getpcb(struct lwp *l) 305lwp_getpcb(struct lwp *l)
306{ 306{
307 307
308 return l->l_addr; 308 return l->l_addr;
309} 309}
310#endif /* _KERNEL || _KMEMUSER */ 310#endif /* _KERNEL || _KMEMUSER */
311 311
312#ifdef _KERNEL 312#ifdef _KERNEL
313#define LWP_CACHE_CREDS(l, p) \ 313#define LWP_CACHE_CREDS(l, p) \
314do { \ 314do { \
315 (void)p; \ 315 (void)p; \
316 if (__predict_false((l)->l_prflag & LPR_CRMOD)) \ 316 if (__predict_false((l)->l_prflag & LPR_CRMOD)) \
317 lwp_update_creds(l); \ 317 lwp_update_creds(l); \
318} while (/* CONSTCOND */ 0) 318} while (/* CONSTCOND */ 0)
319 319
320void lwpinit(void); 320void lwpinit(void);
321void lwp0_init(void); 321void lwp0_init(void);
322void lwp_sys_init(void); 322void lwp_sys_init(void);
323 323
324void lwp_startup(lwp_t *, lwp_t *); 324void lwp_startup(lwp_t *, lwp_t *);
325void startlwp(void *); 325void startlwp(void *);
326 326
327int lwp_locked(lwp_t *, kmutex_t *); 327int lwp_locked(lwp_t *, kmutex_t *);
328kmutex_t *lwp_setlock(lwp_t *, kmutex_t *); 328kmutex_t *lwp_setlock(lwp_t *, kmutex_t *);
329void lwp_unlock_to(lwp_t *, kmutex_t *); 329void lwp_unlock_to(lwp_t *, kmutex_t *);
330int lwp_trylock(lwp_t *); 330int lwp_trylock(lwp_t *);
331void lwp_addref(lwp_t *); 331void lwp_addref(lwp_t *);
332void lwp_delref(lwp_t *); 332void lwp_delref(lwp_t *);
333void lwp_delref2(lwp_t *); 333void lwp_delref2(lwp_t *);
334void lwp_drainrefs(lwp_t *); 334void lwp_drainrefs(lwp_t *);
335bool lwp_alive(lwp_t *); 335bool lwp_alive(lwp_t *);
336lwp_t *lwp_find_first(proc_t *); 336lwp_t *lwp_find_first(proc_t *);
337 337
338int lwp_wait(lwp_t *, lwpid_t, lwpid_t *, bool); 338int lwp_wait(lwp_t *, lwpid_t, lwpid_t *, bool);
339void lwp_continue(lwp_t *); 339void lwp_continue(lwp_t *);
340void lwp_unsleep(lwp_t *, bool); 340void lwp_unsleep(lwp_t *, bool);
341void lwp_unstop(lwp_t *); 341void lwp_unstop(lwp_t *);
342void lwp_exit(lwp_t *); 342void lwp_exit(lwp_t *);
343int lwp_suspend(lwp_t *, lwp_t *); 343int lwp_suspend(lwp_t *, lwp_t *);
344int lwp_create1(lwp_t *, const void *, size_t, u_long, lwpid_t *); 344int lwp_create1(lwp_t *, const void *, size_t, u_long, lwpid_t *);
345void lwp_start(lwp_t *, int); 345void lwp_start(lwp_t *, int);
346void lwp_update_creds(lwp_t *); 346void lwp_update_creds(lwp_t *);
347void lwp_migrate(lwp_t *, struct cpu_info *); 347void lwp_migrate(lwp_t *, struct cpu_info *);
348lwp_t * lwp_find2(pid_t, lwpid_t); 348lwp_t * lwp_find2(pid_t, lwpid_t);
349lwp_t * lwp_find(proc_t *, int); 349lwp_t * lwp_find(proc_t *, int);
350void lwp_userret(lwp_t *); 350void lwp_userret(lwp_t *);
351void lwp_need_userret(lwp_t *); 351void lwp_need_userret(lwp_t *);
352void lwp_free(lwp_t *, bool, bool); 352void lwp_free(lwp_t *, bool, bool);
353uint64_t lwp_pctr(void); 353uint64_t lwp_pctr(void);
354int lwp_setprivate(lwp_t *, void *); 354int lwp_setprivate(lwp_t *, void *);
355int do_lwp_create(lwp_t *, void *, u_long, lwp_t **, const sigset_t *, 355int do_lwp_create(lwp_t *, void *, u_long, lwp_t **, const sigset_t *,
356 const stack_t *); 356 const stack_t *);
357 357
358void lwpinit_specificdata(void); 358void lwpinit_specificdata(void);
359int lwp_specific_key_create(specificdata_key_t *, specificdata_dtor_t); 359int lwp_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
360void lwp_specific_key_delete(specificdata_key_t); 360void lwp_specific_key_delete(specificdata_key_t);
361void lwp_initspecific(lwp_t *); 361void lwp_initspecific(lwp_t *);
362void lwp_finispecific(lwp_t *); 362void lwp_finispecific(lwp_t *);
363void *lwp_getspecific(specificdata_key_t); 363void *lwp_getspecific(specificdata_key_t);
364#if defined(_LWP_API_PRIVATE) 364#if defined(_LWP_API_PRIVATE)
365void *_lwp_getspecific_by_lwp(lwp_t *, specificdata_key_t); 365void *_lwp_getspecific_by_lwp(lwp_t *, specificdata_key_t);
366#endif 366#endif
367void lwp_setspecific(specificdata_key_t, void *); 367void lwp_setspecific(specificdata_key_t, void *);
368void lwp_setspecific_by_lwp(lwp_t *, specificdata_key_t, void *); 368void lwp_setspecific_by_lwp(lwp_t *, specificdata_key_t, void *);
369 369
370/* Syscalls. */ 370/* Syscalls. */
371int lwp_park(clockid_t, int, struct timespec *, const void *); 371int lwp_park(clockid_t, int, struct timespec *, const void *);
372int lwp_unpark(lwpid_t, const void *); 372int lwp_unpark(lwpid_t, const void *);
373 373
374/* DDB. */ 374/* DDB. */
375void lwp_whatis(uintptr_t, void (*)(const char *, ...) __printflike(1, 2)); 375void lwp_whatis(uintptr_t, void (*)(const char *, ...) __printflike(1, 2));
376 376
377/* 377/*
378 * Lock an LWP. XXX _MODULE 378 * Lock an LWP. XXX _MODULE
379 */ 379 */
380static __inline void 380static __inline void
381lwp_lock(lwp_t *l) 381lwp_lock(lwp_t *l)
382{ 382{
383 kmutex_t *old = l->l_mutex; 383 kmutex_t *old = l->l_mutex;
384 384
385 /* 385 /*
386 * Note: mutex_spin_enter() will have posted a read barrier. 386 * Note: mutex_spin_enter() will have posted a read barrier.
387 * Re-test l->l_mutex. If it has changed, we need to try again. 387 * Re-test l->l_mutex. If it has changed, we need to try again.
388 */ 388 */
389 mutex_spin_enter(old); 389 mutex_spin_enter(old);
390 while (__predict_false(l->l_mutex != old)) { 390 while (__predict_false(l->l_mutex != old)) {
391 mutex_spin_exit(old); 391 mutex_spin_exit(old);
392 old = l->l_mutex; 392 old = l->l_mutex;
393 mutex_spin_enter(old); 393 mutex_spin_enter(old);
394 } 394 }
395} 395}
396 396
397/* 397/*
398 * Unlock an LWP. XXX _MODULE 398 * Unlock an LWP. XXX _MODULE
399 */ 399 */
400static __inline void 400static __inline void
401lwp_unlock(lwp_t *l) 401lwp_unlock(lwp_t *l)
402{ 402{
403 mutex_spin_exit(l->l_mutex); 403 mutex_spin_exit(l->l_mutex);
404} 404}
405 405
406static __inline void 406static __inline void
407lwp_changepri(lwp_t *l, pri_t pri) 407lwp_changepri(lwp_t *l, pri_t pri)
408{ 408{
409 KASSERT(mutex_owned(l->l_mutex)); 409 KASSERT(mutex_owned(l->l_mutex));
410 410
411 if (l->l_priority == pri) 411 if (l->l_priority == pri)
412 return; 412 return;
413 413
414 (*l->l_syncobj->sobj_changepri)(l, pri); 414 (*l->l_syncobj->sobj_changepri)(l, pri);
415 KASSERT(l->l_priority == pri); 415 KASSERT(l->l_priority == pri);
416} 416}
417 417
418static __inline void 418static __inline void
419lwp_lendpri(lwp_t *l, pri_t pri) 419lwp_lendpri(lwp_t *l, pri_t pri)
420{ 420{
421 KASSERT(mutex_owned(l->l_mutex)); 421 KASSERT(mutex_owned(l->l_mutex));
422 422
423 (*l->l_syncobj->sobj_lendpri)(l, pri); 423 (*l->l_syncobj->sobj_lendpri)(l, pri);
424 KASSERT(l->l_inheritedprio == pri); 424 KASSERT(l->l_inheritedprio == pri);
425} 425}
426 426
427static __inline pri_t 427static __inline pri_t
428lwp_eprio(lwp_t *l) 428lwp_eprio(lwp_t *l)
429{ 429{
430 pri_t pri; 430 pri_t pri;
431 431
432 pri = l->l_priority; 432 pri = l->l_priority;
433 if ((l->l_flag & LW_SYSTEM) == 0 && l->l_kpriority && pri < PRI_KERNEL) 433 if ((l->l_flag & LW_SYSTEM) == 0 && l->l_kpriority && pri < PRI_KERNEL)
434 pri = (pri >> 1) + l->l_kpribase; 434 pri = (pri >> 1) + l->l_kpribase;
435 return MAX(l->l_auxprio, pri); 435 return MAX(l->l_auxprio, pri);
436} 436}
437 437
438int lwp_create(lwp_t *, struct proc *, vaddr_t, int, void *, size_t, 438int lwp_create(lwp_t *, struct proc *, vaddr_t, int, void *, size_t,
439 void (*)(void *), void *, lwp_t **, int, const sigset_t *, const stack_t *); 439 void (*)(void *), void *, lwp_t **, int, const sigset_t *, const stack_t *);
440 440
441/* 441/*
442 * XXX _MODULE 442 * XXX _MODULE
443 * We should provide real stubs for the below that modules can use. 443 * We should provide real stubs for the below that modules can use.
444 */ 444 */
445 445
446static __inline void 446static __inline void
447spc_lock(struct cpu_info *ci) 447spc_lock(struct cpu_info *ci)
448{ 448{
449 mutex_spin_enter(ci->ci_schedstate.spc_mutex); 449 mutex_spin_enter(ci->ci_schedstate.spc_mutex);
450} 450}
451 451
452static __inline void 452static __inline void
453spc_unlock(struct cpu_info *ci) 453spc_unlock(struct cpu_info *ci)
454{ 454{
455 mutex_spin_exit(ci->ci_schedstate.spc_mutex); 455 mutex_spin_exit(ci->ci_schedstate.spc_mutex);
456} 456}
457 457
458static __inline void 458static __inline void
459spc_dlock(struct cpu_info *ci1, struct cpu_info *ci2) 459spc_dlock(struct cpu_info *ci1, struct cpu_info *ci2)
460{ 460{
461 struct schedstate_percpu *spc1 = &ci1->ci_schedstate; 461 struct schedstate_percpu *spc1 = &ci1->ci_schedstate;
462 struct schedstate_percpu *spc2 = &ci2->ci_schedstate; 462 struct schedstate_percpu *spc2 = &ci2->ci_schedstate;
463 463
464 KASSERT(ci1 != ci2); 464 KASSERT(ci1 != ci2);
465 if (ci1 < ci2) { 465 if (ci1 < ci2) {
466 mutex_spin_enter(spc1->spc_mutex); 466 mutex_spin_enter(spc1->spc_mutex);
467 mutex_spin_enter(spc2->spc_mutex); 467 mutex_spin_enter(spc2->spc_mutex);
468 } else { 468 } else {
469 mutex_spin_enter(spc2->spc_mutex); 469 mutex_spin_enter(spc2->spc_mutex);
470 mutex_spin_enter(spc1->spc_mutex); 470 mutex_spin_enter(spc1->spc_mutex);
471 } 471 }
472} 472}
473 473
474/* 474/*
475 * Allow machine-dependent code to override curlwp in <machine/cpu.h> for 475 * Allow machine-dependent code to override curlwp in <machine/cpu.h> for
476 * its own convenience. Otherwise, we declare it as appropriate. 476 * its own convenience. Otherwise, we declare it as appropriate.
477 */ 477 */
478#if !defined(curlwp) 478#if !defined(curlwp)
479#if defined(MULTIPROCESSOR) 479#if defined(MULTIPROCESSOR)
480#define curlwp curcpu()->ci_curlwp /* Current running LWP */ 480#define curlwp curcpu()->ci_curlwp /* Current running LWP */
481#else 481#else
482extern struct lwp *curlwp; /* Current running LWP */ 482extern struct lwp *curlwp; /* Current running LWP */
483#endif /* MULTIPROCESSOR */ 483#endif /* MULTIPROCESSOR */
484#endif /* ! curlwp */ 484#endif /* ! curlwp */
485#define curproc (curlwp->l_proc) 485#define curproc (curlwp->l_proc)
486 486
487/* 487/*
488 * This provide a way for <machine/cpu.h> to get l_cpu for curlwp before 488 * This provide a way for <machine/cpu.h> to get l_cpu for curlwp before
489 * struct lwp is defined. 489 * struct lwp is defined.
490 */ 490 */
491static __inline struct cpu_info * 491static __inline struct cpu_info *
492lwp_getcpu(struct lwp *l) 492lwp_getcpu(struct lwp *l)
493{ 493{
494 return l->l_cpu; 494 return l->l_cpu;
495} 495}
496 496
497static __inline bool 497static __inline bool
498CURCPU_IDLE_P(void) 498CURCPU_IDLE_P(void)
499{ 499{
500 struct cpu_info *ci = curcpu(); 500 struct cpu_info *ci = curcpu();
501 return ci->ci_onproc == ci->ci_data.cpu_idlelwp; 501 return ci->ci_onproc == ci->ci_data.cpu_idlelwp;
502} 502}
503 503
504/* 504/*
505 * Disable and re-enable preemption. Only for low-level kernel 505 * Disable and re-enable preemption. Only for low-level kernel
506 * use. Device drivers and anything that could potentially be 506 * use. Device drivers and anything that could potentially be
507 * compiled as a module should use kpreempt_disable() and 507 * compiled as a module should use kpreempt_disable() and
508 * kpreempt_enable(). 508 * kpreempt_enable().
509 */ 509 */
510static __inline void 510static __inline void
511KPREEMPT_DISABLE(lwp_t *l) 511KPREEMPT_DISABLE(lwp_t *l)
512{ 512{
513 513
514 KASSERT(l == curlwp); 514 KASSERT(l == curlwp);
515 l->l_nopreempt++; 515 l->l_nopreempt++;
516 __insn_barrier(); 516 __insn_barrier();
517} 517}
518 518
519static __inline void 519static __inline void
520KPREEMPT_ENABLE(lwp_t *l) 520KPREEMPT_ENABLE(lwp_t *l)
521{ 521{
522 522
523 KASSERT(l == curlwp); 523 KASSERT(l == curlwp);
524 KASSERT(l->l_nopreempt > 0); 524 KASSERT(l->l_nopreempt > 0);
525 __insn_barrier(); 525 __insn_barrier();
526 if (--l->l_nopreempt != 0) 526 if (--l->l_nopreempt != 0)
527 return; 527 return;
528 __insn_barrier(); 528 __insn_barrier();
529 if (__predict_false(l->l_dopreempt)) 529 if (__predict_false(l->l_dopreempt))
530 kpreempt(0); 530 kpreempt(0);
531 __insn_barrier(); 531 __insn_barrier();
532} 532}
533 533
534/* For lwp::l_dopreempt */ 534/* For lwp::l_dopreempt */
535#define DOPREEMPT_ACTIVE 0x01 535#define DOPREEMPT_ACTIVE 0x01
536#define DOPREEMPT_COUNTED 0x02 536#define DOPREEMPT_COUNTED 0x02
537 537
538/* 538/*
539 * Prevent curlwp from migrating between CPUs between curlwp_bind and 539 * Prevent curlwp from migrating between CPUs between curlwp_bind and
540 * curlwp_bindx. One use case is psref(9) that has a contract that 540 * curlwp_bindx. One use case is psref(9) that has a contract that
541 * forbids migrations. 541 * forbids migrations.
542 */ 542 */
543static __inline int 543static __inline int
544curlwp_bind(void) 544curlwp_bind(void)
545{ 545{
546 int bound; 546 int bound;
547 547
548 bound = curlwp->l_pflag & LP_BOUND; 548 bound = curlwp->l_pflag & LP_BOUND;
549 curlwp->l_pflag |= LP_BOUND; 549 curlwp->l_pflag |= LP_BOUND;
550 __insn_barrier(); 550 __insn_barrier();
551 551
552 return bound; 552 return bound;
553} 553}
554 554
555static __inline void 555static __inline void
556curlwp_bindx(int bound) 556curlwp_bindx(int bound)
557{ 557{
558 558
559 KASSERT(curlwp->l_pflag & LP_BOUND); 559 KASSERT(curlwp->l_pflag & LP_BOUND);
560 __insn_barrier(); 560 __insn_barrier();
561 curlwp->l_pflag ^= bound ^ LP_BOUND; 561 curlwp->l_pflag ^= bound ^ LP_BOUND;
562} 562}
563 563
564#endif /* _KERNEL */ 564#endif /* _KERNEL */
565 565
566/* Flags for _lwp_create(), as per Solaris. */ 566/* Flags for _lwp_create(), as per Solaris. */
567#define LWP_DETACHED 0x00000040 567#define LWP_DETACHED 0x00000040
568#define LWP_SUSPENDED 0x00000080 568#define LWP_SUSPENDED 0x00000080
569 569
570/* Kernel-internal flags for LWP creation. */ 570/* Kernel-internal flags for LWP creation. */
571#define LWP_PIDLID 0x40000000 571#define LWP_PIDLID 0x40000000
572#define LWP_VFORK 0x80000000 572#define LWP_VFORK 0x80000000
573 573
574#endif /* !_SYS_LWP_H_ */ 574#endif /* !_SYS_LWP_H_ */

cvs diff -r1.103 -r1.104 src/sys/sys/types.h (switch to unified diff)

--- src/sys/sys/types.h 2020/01/12 21:40:44 1.103
+++ src/sys/sys/types.h 2020/01/28 16:40:27 1.104
@@ -1,358 +1,358 @@ @@ -1,358 +1,358 @@
1/* $NetBSD: types.h,v 1.103 2020/01/12 21:40:44 ad Exp $ */ 1/* $NetBSD: types.h,v 1.104 2020/01/28 16:40:27 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1982, 1986, 1991, 1993, 1994 4 * Copyright (c) 1982, 1986, 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc. 6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed 7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph 8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc. 10 * the permission of UNIX System Laboratories, Inc.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
15 * 1. Redistributions of source code must retain the above copyright 15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer. 16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright 17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the 18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution. 19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors 20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software 21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission. 22 * without specific prior written permission.
23 * 23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * @(#)types.h 8.4 (Berkeley) 1/21/94 36 * @(#)types.h 8.4 (Berkeley) 1/21/94
37 */ 37 */
38 38
39#ifndef _SYS_TYPES_H_ 39#ifndef _SYS_TYPES_H_
40#define _SYS_TYPES_H_ 40#define _SYS_TYPES_H_
41 41
42#include <sys/featuretest.h> 42#include <sys/featuretest.h>
43 43
44/* Machine type dependent parameters. */ 44/* Machine type dependent parameters. */
45#include <machine/types.h> 45#include <machine/types.h>
46 46
47#include <machine/ansi.h> 47#include <machine/ansi.h>
48#include <machine/int_types.h> 48#include <machine/int_types.h>
49 49
50 50
51#include <sys/ansi.h> 51#include <sys/ansi.h>
52 52
53#ifndef _BSD_INT8_T_ 53#ifndef _BSD_INT8_T_
54typedef __int8_t int8_t; 54typedef __int8_t int8_t;
55#define _BSD_INT8_T_ 55#define _BSD_INT8_T_
56#endif 56#endif
57 57
58#ifndef _BSD_UINT8_T_ 58#ifndef _BSD_UINT8_T_
59typedef __uint8_t uint8_t; 59typedef __uint8_t uint8_t;
60#define _BSD_UINT8_T_ 60#define _BSD_UINT8_T_
61#endif 61#endif
62 62
63#ifndef _BSD_INT16_T_ 63#ifndef _BSD_INT16_T_
64typedef __int16_t int16_t; 64typedef __int16_t int16_t;
65#define _BSD_INT16_T_ 65#define _BSD_INT16_T_
66#endif 66#endif
67 67
68#ifndef _BSD_UINT16_T_ 68#ifndef _BSD_UINT16_T_
69typedef __uint16_t uint16_t; 69typedef __uint16_t uint16_t;
70#define _BSD_UINT16_T_ 70#define _BSD_UINT16_T_
71#endif 71#endif
72 72
73#ifndef _BSD_INT32_T_ 73#ifndef _BSD_INT32_T_
74typedef __int32_t int32_t; 74typedef __int32_t int32_t;
75#define _BSD_INT32_T_ 75#define _BSD_INT32_T_
76#endif 76#endif
77 77
78#ifndef _BSD_UINT32_T_ 78#ifndef _BSD_UINT32_T_
79typedef __uint32_t uint32_t; 79typedef __uint32_t uint32_t;
80#define _BSD_UINT32_T_ 80#define _BSD_UINT32_T_
81#endif 81#endif
82 82
83#ifndef _BSD_INT64_T_ 83#ifndef _BSD_INT64_T_
84typedef __int64_t int64_t; 84typedef __int64_t int64_t;
85#define _BSD_INT64_T_ 85#define _BSD_INT64_T_
86#endif 86#endif
87 87
88#ifndef _BSD_UINT64_T_ 88#ifndef _BSD_UINT64_T_
89typedef __uint64_t uint64_t; 89typedef __uint64_t uint64_t;
90#define _BSD_UINT64_T_ 90#define _BSD_UINT64_T_
91#endif 91#endif
92 92
93typedef uint8_t u_int8_t; 93typedef uint8_t u_int8_t;
94typedef uint16_t u_int16_t; 94typedef uint16_t u_int16_t;
95typedef uint32_t u_int32_t; 95typedef uint32_t u_int32_t;
96typedef uint64_t u_int64_t; 96typedef uint64_t u_int64_t;
97 97
98#include <machine/endian.h> 98#include <machine/endian.h>
99 99
100#if defined(_NETBSD_SOURCE) 100#if defined(_NETBSD_SOURCE)
101typedef unsigned char u_char; 101typedef unsigned char u_char;
102typedef unsigned short u_short; 102typedef unsigned short u_short;
103typedef unsigned int u_int; 103typedef unsigned int u_int;
104typedef unsigned long u_long; 104typedef unsigned long u_long;
105 105
106typedef unsigned char unchar; /* Sys V compatibility */ 106typedef unsigned char unchar; /* Sys V compatibility */
107typedef unsigned short ushort; /* Sys V compatibility */ 107typedef unsigned short ushort; /* Sys V compatibility */
108typedef unsigned int uint; /* Sys V compatibility */ 108typedef unsigned int uint; /* Sys V compatibility */
109typedef unsigned long ulong; /* Sys V compatibility */ 109typedef unsigned long ulong; /* Sys V compatibility */
110#endif 110#endif
111 111
112typedef uint64_t u_quad_t; /* quads */ 112typedef uint64_t u_quad_t; /* quads */
113typedef int64_t quad_t; 113typedef int64_t quad_t;
114typedef quad_t * qaddr_t; 114typedef quad_t * qaddr_t;
115 115
116/* 116/*
117 * The types longlong_t and u_longlong_t exist for use with the 117 * The types longlong_t and u_longlong_t exist for use with the
118 * Sun-derived XDR routines involving these types, and their usage 118 * Sun-derived XDR routines involving these types, and their usage
119 * in other contexts is discouraged. Further note that these types 119 * in other contexts is discouraged. Further note that these types
120 * may not be equivalent to "long long" and "unsigned long long", 120 * may not be equivalent to "long long" and "unsigned long long",
121 * they are only guaranteed to be signed and unsigned 64-bit types 121 * they are only guaranteed to be signed and unsigned 64-bit types
122 * respectively. Portable programs that need 64-bit types should use 122 * respectively. Portable programs that need 64-bit types should use
123 * the C99 types int64_t and uint64_t instead. 123 * the C99 types int64_t and uint64_t instead.
124 */ 124 */
125 125
126typedef int64_t longlong_t; /* for XDR */ 126typedef int64_t longlong_t; /* for XDR */
127typedef uint64_t u_longlong_t; /* for XDR */ 127typedef uint64_t u_longlong_t; /* for XDR */
128 128
129typedef int64_t blkcnt_t; /* fs block count */ 129typedef int64_t blkcnt_t; /* fs block count */
130typedef int32_t blksize_t; /* fs optimal block size */ 130typedef int32_t blksize_t; /* fs optimal block size */
131 131
132#ifndef fsblkcnt_t 132#ifndef fsblkcnt_t
133typedef __fsblkcnt_t fsblkcnt_t; /* fs block count (statvfs) */ 133typedef __fsblkcnt_t fsblkcnt_t; /* fs block count (statvfs) */
134#define fsblkcnt_t __fsblkcnt_t 134#define fsblkcnt_t __fsblkcnt_t
135#endif 135#endif
136 136
137#ifndef fsfilcnt_t 137#ifndef fsfilcnt_t
138typedef __fsfilcnt_t fsfilcnt_t; /* fs file count */ 138typedef __fsfilcnt_t fsfilcnt_t; /* fs file count */
139#define fsfilcnt_t __fsfilcnt_t 139#define fsfilcnt_t __fsfilcnt_t
140#endif 140#endif
141 141
142#if !defined(_KERNEL) && !defined(_STANDALONE) 142#if !defined(_KERNEL) && !defined(_STANDALONE)
143/* We don't and shouldn't use caddr_t in the kernel anymore */ 143/* We don't and shouldn't use caddr_t in the kernel anymore */
144#ifndef caddr_t 144#ifndef caddr_t
145typedef __caddr_t caddr_t; /* core address */ 145typedef __caddr_t caddr_t; /* core address */
146#define caddr_t __caddr_t 146#define caddr_t __caddr_t
147#endif 147#endif
148#endif 148#endif
149 149
150#ifdef __daddr_t 150#ifdef __daddr_t
151typedef __daddr_t daddr_t; /* disk address */ 151typedef __daddr_t daddr_t; /* disk address */
152#undef __daddr_t 152#undef __daddr_t
153#else 153#else
154typedef int64_t daddr_t; /* disk address */ 154typedef int64_t daddr_t; /* disk address */
155#endif 155#endif
156 156
157typedef uint64_t dev_t; /* device number */ 157typedef uint64_t dev_t; /* device number */
158typedef uint32_t fixpt_t; /* fixed point number */ 158typedef uint32_t fixpt_t; /* fixed point number */
159 159
160#ifndef gid_t 160#ifndef gid_t
161typedef __gid_t gid_t; /* group id */ 161typedef __gid_t gid_t; /* group id */
162#define gid_t __gid_t 162#define gid_t __gid_t
163#endif 163#endif
164 164
165typedef uint32_t id_t; /* group id, process id or user id */ 165typedef uint32_t id_t; /* group id, process id or user id */
166typedef uint64_t ino_t; /* inode number */ 166typedef uint64_t ino_t; /* inode number */
167typedef long key_t; /* IPC key (for Sys V IPC) */ 167typedef long key_t; /* IPC key (for Sys V IPC) */
168 168
169#ifndef mode_t 169#ifndef mode_t
170typedef __mode_t mode_t; /* permissions */ 170typedef __mode_t mode_t; /* permissions */
171#define mode_t __mode_t 171#define mode_t __mode_t
172#endif 172#endif
173 173
174typedef uint32_t nlink_t; /* link count */ 174typedef uint32_t nlink_t; /* link count */
175 175
176#ifndef off_t 176#ifndef off_t
177typedef __off_t off_t; /* file offset */ 177typedef __off_t off_t; /* file offset */
178#define off_t __off_t 178#define off_t __off_t
179#endif 179#endif
180 180
181#ifndef pid_t 181#ifndef pid_t
182typedef __pid_t pid_t; /* process id */ 182typedef __pid_t pid_t; /* process id */
183#define pid_t __pid_t 183#define pid_t __pid_t
184#endif 184#endif
185typedef int32_t lwpid_t; /* LWP id */ 185typedef int32_t lwpid_t; /* LWP id */
186typedef uint64_t rlim_t; /* resource limit */ 186typedef uint64_t rlim_t; /* resource limit */
187typedef int32_t segsz_t; /* segment size */ 187typedef int32_t segsz_t; /* segment size */
188typedef int32_t swblk_t; /* swap offset */ 188typedef int32_t swblk_t; /* swap offset */
189 189
190#ifndef uid_t 190#ifndef uid_t
191typedef __uid_t uid_t; /* user id */ 191typedef __uid_t uid_t; /* user id */
192#define uid_t __uid_t 192#define uid_t __uid_t
193#endif 193#endif
194 194
195typedef int mqd_t; 195typedef int mqd_t;
196 196
197typedef unsigned long cpuid_t; 197typedef unsigned long cpuid_t;
198 198
199typedef int psetid_t; 199typedef int psetid_t;
200 200
201typedef volatile __cpu_simple_lock_nv_t __cpu_simple_lock_t; 201typedef volatile __cpu_simple_lock_nv_t __cpu_simple_lock_t;
202 202
203#if defined(_KERNEL) || defined(_STANDALONE) 203#if defined(_KERNEL) || defined(_STANDALONE)
204 204
205#include <sys/stdbool.h> 205#include <sys/stdbool.h>
206 206
207/* 207/*
208 * Deprecated Mach-style boolean_t type. Should not be used by new code. 208 * Deprecated Mach-style boolean_t type. Should not be used by new code.
209 */ 209 */
210typedef int boolean_t; 210typedef int boolean_t;
211#ifndef TRUE 211#ifndef TRUE
212#define TRUE 1 212#define TRUE 1
213#endif 213#endif
214#ifndef FALSE 214#ifndef FALSE
215#define FALSE 0 215#define FALSE 0
216#endif 216#endif
217 217
218#endif /* _KERNEL || _STANDALONE */ 218#endif /* _KERNEL || _STANDALONE */
219 219
220#if defined(_KERNEL) || defined(_LIBC) || defined(_KMEMUSER) 220#if defined(_KERNEL) || defined(_LIBC) || defined(_KMEMUSER)
221/* 221/*
222 * semctl(2)'s argument structure. This is here for the benefit of 222 * semctl(2)'s argument structure. This is here for the benefit of
223 * <sys/syscallargs.h>. It is not in the user's namespace in SUSv2. 223 * <sys/syscallargs.h>. It is not in the user's namespace in SUSv2.
224 * The SUSv2 semctl(2) takes variable arguments. 224 * The SUSv2 semctl(2) takes variable arguments.
225 */ 225 */
226union __semun { 226union __semun {
227 int val; /* value for SETVAL */ 227 int val; /* value for SETVAL */
228 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 228 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
229 unsigned short *array; /* array for GETALL & SETALL */ 229 unsigned short *array; /* array for GETALL & SETALL */
230}; 230};
231#include <sys/stdint.h> 231#include <sys/stdint.h>
232#endif /* _KERNEL || _LIBC || _KMEMUSER */ 232#endif /* _KERNEL || _LIBC || _KMEMUSER */
233 233
234/* 234/*
235 * These belong in unistd.h, but are placed here too to ensure that 235 * These belong in unistd.h, but are placed here too to ensure that
236 * long arguments will be promoted to off_t if the program fails to 236 * long arguments will be promoted to off_t if the program fails to
237 * include that header or explicitly cast them to off_t. 237 * include that header or explicitly cast them to off_t.
238 */ 238 */
239#if defined(_NETBSD_SOURCE) 239#if defined(_NETBSD_SOURCE)
240#ifndef __OFF_T_SYSCALLS_DECLARED 240#ifndef __OFF_T_SYSCALLS_DECLARED
241#define __OFF_T_SYSCALLS_DECLARED 241#define __OFF_T_SYSCALLS_DECLARED
242#ifndef _KERNEL 242#ifndef _KERNEL
243#include <sys/cdefs.h> 243#include <sys/cdefs.h>
244__BEGIN_DECLS 244__BEGIN_DECLS
245off_t lseek(int, off_t, int); 245off_t lseek(int, off_t, int);
246int ftruncate(int, off_t); 246int ftruncate(int, off_t);
247int truncate(const char *, off_t); 247int truncate(const char *, off_t);
248__END_DECLS 248__END_DECLS
249#endif /* !_KERNEL */ 249#endif /* !_KERNEL */
250#endif /* __OFF_T_SYSCALLS_DECLARED */ 250#endif /* __OFF_T_SYSCALLS_DECLARED */
251#endif /* defined(_NETBSD_SOURCE) */ 251#endif /* defined(_NETBSD_SOURCE) */
252 252
253#if defined(_NETBSD_SOURCE) 253#if defined(_NETBSD_SOURCE)
254/* Major, minor numbers, dev_t's. */ 254/* Major, minor numbers, dev_t's. */
255typedef int32_t __devmajor_t, __devminor_t; 255typedef int32_t __devmajor_t, __devminor_t;
256#define devmajor_t __devmajor_t 256#define devmajor_t __devmajor_t
257#define devminor_t __devminor_t 257#define devminor_t __devminor_t
258#define NODEVMAJOR (-1) 258#define NODEVMAJOR (-1)
259#define major(x) ((devmajor_t)(((uint32_t)(x) & 0x000fff00) >> 8)) 259#define major(x) ((devmajor_t)(((uint32_t)(x) & 0x000fff00) >> 8))
260#define minor(x) ((devminor_t)((((uint32_t)(x) & 0xfff00000) >> 12) | \ 260#define minor(x) ((devminor_t)((((uint32_t)(x) & 0xfff00000) >> 12) | \
261 (((uint32_t)(x) & 0x000000ff) >> 0))) 261 (((uint32_t)(x) & 0x000000ff) >> 0)))
262#define makedev(x,y) ((dev_t)((((dev_t)(x) << 8) & 0x000fff00U) | \ 262#define makedev(x,y) ((dev_t)((((dev_t)(x) << 8) & 0x000fff00U) | \
263 (((dev_t)(y) << 12) & 0xfff00000U) | \ 263 (((dev_t)(y) << 12) & 0xfff00000U) | \
264 (((dev_t)(y) << 0) & 0x000000ffU))) 264 (((dev_t)(y) << 0) & 0x000000ffU)))
265#endif 265#endif
266 266
267#ifdef _BSD_CLOCK_T_ 267#ifdef _BSD_CLOCK_T_
268typedef _BSD_CLOCK_T_ clock_t; 268typedef _BSD_CLOCK_T_ clock_t;
269#undef _BSD_CLOCK_T_ 269#undef _BSD_CLOCK_T_
270#endif 270#endif
271 271
272#ifdef _BSD_PTRDIFF_T_ 272#ifdef _BSD_PTRDIFF_T_
273typedef _BSD_PTRDIFF_T_ ptrdiff_t; 273typedef _BSD_PTRDIFF_T_ ptrdiff_t;
274#undef _BSD_PTRDIFF_T_ 274#undef _BSD_PTRDIFF_T_
275#endif 275#endif
276 276
277#ifdef _BSD_SIZE_T_ 277#ifdef _BSD_SIZE_T_
278typedef _BSD_SIZE_T_ size_t; 278typedef _BSD_SIZE_T_ size_t;
279#define _SIZE_T 279#define _SIZE_T
280#undef _BSD_SIZE_T_ 280#undef _BSD_SIZE_T_
281#endif 281#endif
282 282
283#ifdef _BSD_SSIZE_T_ 283#ifdef _BSD_SSIZE_T_
284typedef _BSD_SSIZE_T_ ssize_t; 284typedef _BSD_SSIZE_T_ ssize_t;
285#undef _BSD_SSIZE_T_ 285#undef _BSD_SSIZE_T_
286#endif 286#endif
287 287
288#ifdef _BSD_TIME_T_ 288#ifdef _BSD_TIME_T_
289typedef _BSD_TIME_T_ time_t; 289typedef _BSD_TIME_T_ time_t;
290#undef _BSD_TIME_T_ 290#undef _BSD_TIME_T_
291#endif 291#endif
292 292
293#ifdef _BSD_CLOCKID_T_ 293#ifdef _BSD_CLOCKID_T_
294typedef _BSD_CLOCKID_T_ clockid_t; 294typedef _BSD_CLOCKID_T_ clockid_t;
295#undef _BSD_CLOCKID_T_ 295#undef _BSD_CLOCKID_T_
296#endif 296#endif
297 297
298#ifdef _BSD_TIMER_T_ 298#ifdef _BSD_TIMER_T_
299typedef _BSD_TIMER_T_ timer_t; 299typedef _BSD_TIMER_T_ timer_t;
300#undef _BSD_TIMER_T_ 300#undef _BSD_TIMER_T_
301#endif 301#endif
302 302
303#ifdef _BSD_SUSECONDS_T_ 303#ifdef _BSD_SUSECONDS_T_
304typedef _BSD_SUSECONDS_T_ suseconds_t; 304typedef _BSD_SUSECONDS_T_ suseconds_t;
305#undef _BSD_SUSECONDS_T_ 305#undef _BSD_SUSECONDS_T_
306#endif 306#endif
307 307
308#ifdef _BSD_USECONDS_T_ 308#ifdef _BSD_USECONDS_T_
309typedef _BSD_USECONDS_T_ useconds_t; 309typedef _BSD_USECONDS_T_ useconds_t;
310#undef _BSD_USECONDS_T_ 310#undef _BSD_USECONDS_T_
311#endif 311#endif
312 312
313#ifdef _NETBSD_SOURCE 313#ifdef _NETBSD_SOURCE
314#include <sys/fd_set.h> 314#include <sys/fd_set.h>
315 315
316#define NBBY 8 316#define NBBY 8
317 317
318typedef struct kauth_cred *kauth_cred_t; 318typedef struct kauth_cred *kauth_cred_t;
319 319
320typedef short pri_t; 320typedef int pri_t;
321 321
322#endif 322#endif
323 323
324#if defined(__STDC__) && (defined(_KERNEL) || defined(_KMEMUSER)) 324#if defined(__STDC__) && (defined(_KERNEL) || defined(_KMEMUSER))
325/* 325/*
326 * Forward structure declarations for function prototypes. We include the 326 * Forward structure declarations for function prototypes. We include the
327 * common structures that cross subsystem boundaries here; others are mostly 327 * common structures that cross subsystem boundaries here; others are mostly
328 * used in the same place that the structure is defined. 328 * used in the same place that the structure is defined.
329 */ 329 */
330struct lwp; 330struct lwp;
331typedef struct lwp lwp_t; 331typedef struct lwp lwp_t;
332struct __ucontext; 332struct __ucontext;
333struct proc; 333struct proc;
334typedef struct proc proc_t; 334typedef struct proc proc_t;
335struct pgrp; 335struct pgrp;
336struct rusage; 336struct rusage;
337struct file; 337struct file;
338typedef struct file file_t; 338typedef struct file file_t;
339struct buf; 339struct buf;
340typedef struct buf buf_t; 340typedef struct buf buf_t;
341struct tty; 341struct tty;
342struct uio; 342struct uio;
343#endif 343#endif
344 344
345#if defined(_KERNEL) || defined(_STANDALONE) 345#if defined(_KERNEL) || defined(_STANDALONE)
346#define SET(t, f) ((t) |= (f)) 346#define SET(t, f) ((t) |= (f))
347#define ISSET(t, f) ((t) & (f)) 347#define ISSET(t, f) ((t) & (f))
348#define CLR(t, f) ((t) &= ~(f)) 348#define CLR(t, f) ((t) &= ~(f))
349#endif 349#endif
350 350
351#if !defined(_KERNEL) && !defined(_STANDALONE) 351#if !defined(_KERNEL) && !defined(_STANDALONE)
352#if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \ 352#if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
353 defined(_NETBSD_SOURCE) 353 defined(_NETBSD_SOURCE)
354#include <pthread_types.h> 354#include <pthread_types.h>
355#endif 355#endif
356#endif 356#endif
357 357
358#endif /* !_SYS_TYPES_H_ */ 358#endif /* !_SYS_TYPES_H_ */