Sun Mar 14 02:53:57 2021 UTC ()
Comment on CTASSERT() in COND_SET_STRUCT(); this is a sanity check to
avoid hashing/assigning large structure. Upper-bound is arbitrary, but
be carefully for performance penalty if bumping.

Thanks christos for discussion.


(rin)
diff -r1.299 -r1.300 src/sys/sys/systm.h

cvs diff -r1.299 -r1.300 src/sys/sys/systm.h (switch to unified diff)

--- src/sys/sys/systm.h 2021/03/10 13:27:51 1.299
+++ src/sys/sys/systm.h 2021/03/14 02:53:57 1.300
@@ -1,761 +1,766 @@ @@ -1,761 +1,766 @@
1/* $NetBSD: systm.h,v 1.299 2021/03/10 13:27:51 simonb Exp $ */ 1/* $NetBSD: systm.h,v 1.300 2021/03/14 02:53:57 rin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1982, 1988, 1991, 1993 4 * Copyright (c) 1982, 1988, 1991, 1993
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 * @(#)systm.h 8.7 (Berkeley) 3/29/95 36 * @(#)systm.h 8.7 (Berkeley) 3/29/95
37 */ 37 */
38 38
39#ifndef _SYS_SYSTM_H_ 39#ifndef _SYS_SYSTM_H_
40#define _SYS_SYSTM_H_ 40#define _SYS_SYSTM_H_
41 41
42#if defined(_KERNEL_OPT) 42#if defined(_KERNEL_OPT)
43#include "opt_ddb.h" 43#include "opt_ddb.h"
44#include "opt_multiprocessor.h" 44#include "opt_multiprocessor.h"
45#include "opt_gprof.h" 45#include "opt_gprof.h"
46#include "opt_kasan.h" 46#include "opt_kasan.h"
47#include "opt_kcsan.h" 47#include "opt_kcsan.h"
48#include "opt_kmsan.h" 48#include "opt_kmsan.h"
49#include "opt_wsdisplay_compat.h" 49#include "opt_wsdisplay_compat.h"
50#endif 50#endif
51#if !defined(_KERNEL) && !defined(_STANDALONE) 51#if !defined(_KERNEL) && !defined(_STANDALONE)
52#include <stdbool.h> 52#include <stdbool.h>
53#endif 53#endif
54 54
55#include <machine/endian.h> 55#include <machine/endian.h>
56 56
57#include <sys/types.h> 57#include <sys/types.h>
58#include <sys/stdarg.h> 58#include <sys/stdarg.h>
59 59
60#include <sys/device_if.h> 60#include <sys/device_if.h>
61 61
62struct clockframe; 62struct clockframe;
63struct lwp; 63struct lwp;
64struct proc; 64struct proc;
65struct sysent; 65struct sysent;
66struct timeval; 66struct timeval;
67struct tty; 67struct tty;
68struct uio; 68struct uio;
69struct vnode; 69struct vnode;
70struct vmspace; 70struct vmspace;
71 71
72extern const char *panicstr; /* panic message */ 72extern const char *panicstr; /* panic message */
73extern int doing_shutdown; /* shutting down */ 73extern int doing_shutdown; /* shutting down */
74 74
75extern const char copyright[]; /* system copyright */ 75extern const char copyright[]; /* system copyright */
76extern char machine[]; /* machine type */ 76extern char machine[]; /* machine type */
77extern char machine_arch[]; /* machine architecture */ 77extern char machine_arch[]; /* machine architecture */
78extern const char osrelease[]; /* short system version */ 78extern const char osrelease[]; /* short system version */
79extern const char ostype[]; /* system type */ 79extern const char ostype[]; /* system type */
80extern const char kernel_ident[];/* kernel configuration ID */ 80extern const char kernel_ident[];/* kernel configuration ID */
81extern const char version[]; /* system version */ 81extern const char version[]; /* system version */
82extern const char buildinfo[]; /* information from build environment */ 82extern const char buildinfo[]; /* information from build environment */
83 83
84extern int autonicetime; /* time (in seconds) before autoniceval */ 84extern int autonicetime; /* time (in seconds) before autoniceval */
85extern int autoniceval; /* proc priority after autonicetime */ 85extern int autoniceval; /* proc priority after autonicetime */
86 86
87extern int selwait; /* select timeout address */ 87extern int selwait; /* select timeout address */
88 88
89extern int maxmem; /* max memory per process */ 89extern int maxmem; /* max memory per process */
90extern psize_t physmem; /* physical memory */ 90extern psize_t physmem; /* physical memory */
91 91
92extern dev_t dumpdev; /* dump device */ 92extern dev_t dumpdev; /* dump device */
93extern dev_t dumpcdev; /* dump device (character equivalent) */ 93extern dev_t dumpcdev; /* dump device (character equivalent) */
94extern long dumplo; /* offset into dumpdev */ 94extern long dumplo; /* offset into dumpdev */
95extern int dumpsize; /* size of dump in pages */ 95extern int dumpsize; /* size of dump in pages */
96extern const char *dumpspec; /* how dump device was specified */ 96extern const char *dumpspec; /* how dump device was specified */
97 97
98extern dev_t rootdev; /* root device */ 98extern dev_t rootdev; /* root device */
99extern struct vnode *rootvp; /* vnode equivalent to above */ 99extern struct vnode *rootvp; /* vnode equivalent to above */
100extern device_t root_device; /* device equivalent to above */ 100extern device_t root_device; /* device equivalent to above */
101extern const char *rootspec; /* how root device was specified */ 101extern const char *rootspec; /* how root device was specified */
102 102
103extern int ncpu; /* number of CPUs configured */ 103extern int ncpu; /* number of CPUs configured */
104extern int ncpuonline; /* number of CPUs online */ 104extern int ncpuonline; /* number of CPUs online */
105#if defined(_KERNEL) 105#if defined(_KERNEL)
106extern bool mp_online; /* secondary processors are started */ 106extern bool mp_online; /* secondary processors are started */
107#endif /* defined(_KERNEL) */ 107#endif /* defined(_KERNEL) */
108 108
109extern const char hexdigits[]; /* "0123456789abcdef" in subr_prf.c */ 109extern const char hexdigits[]; /* "0123456789abcdef" in subr_prf.c */
110extern const char HEXDIGITS[]; /* "0123456789ABCDEF" in subr_prf.c */ 110extern const char HEXDIGITS[]; /* "0123456789ABCDEF" in subr_prf.c */
111 111
112/* 112/*
113 * These represent the swap pseudo-device (`sw'). This device 113 * These represent the swap pseudo-device (`sw'). This device
114 * is used by the swap pager to indirect through the routines 114 * is used by the swap pager to indirect through the routines
115 * in sys/vm/vm_swap.c. 115 * in sys/vm/vm_swap.c.
116 */ 116 */
117extern const dev_t swapdev; /* swapping device */ 117extern const dev_t swapdev; /* swapping device */
118extern struct vnode *swapdev_vp;/* vnode equivalent to above */ 118extern struct vnode *swapdev_vp;/* vnode equivalent to above */
119 119
120extern const dev_t zerodev; /* /dev/zero */ 120extern const dev_t zerodev; /* /dev/zero */
121 121
122#if defined(_KERNEL) 122#if defined(_KERNEL)
123typedef int sy_call_t(struct lwp *, const void *, register_t *); 123typedef int sy_call_t(struct lwp *, const void *, register_t *);
124 124
125extern struct sysent { /* system call table */ 125extern struct sysent { /* system call table */
126 short sy_narg; /* number of args */ 126 short sy_narg; /* number of args */
127 short sy_argsize; /* total size of arguments */ 127 short sy_argsize; /* total size of arguments */
128 int sy_flags; /* flags. see below */ 128 int sy_flags; /* flags. see below */
129 sy_call_t *sy_call; /* implementing function */ 129 sy_call_t *sy_call; /* implementing function */
130 uint32_t sy_entry; /* DTrace entry ID for systrace. */ 130 uint32_t sy_entry; /* DTrace entry ID for systrace. */
131 uint32_t sy_return; /* DTrace return ID for systrace. */ 131 uint32_t sy_return; /* DTrace return ID for systrace. */
132} sysent[]; 132} sysent[];
133extern int nsysent; 133extern int nsysent;
134extern const uint32_t sysent_nomodbits[]; 134extern const uint32_t sysent_nomodbits[];
135#endif 135#endif
136 136
137#if BYTE_ORDER == BIG_ENDIAN 137#if BYTE_ORDER == BIG_ENDIAN
138#define SCARG(p,k) ((p)->k.be.datum) /* get arg from args pointer */ 138#define SCARG(p,k) ((p)->k.be.datum) /* get arg from args pointer */
139#elif BYTE_ORDER == LITTLE_ENDIAN 139#elif BYTE_ORDER == LITTLE_ENDIAN
140#define SCARG(p,k) ((p)->k.le.datum) /* get arg from args pointer */ 140#define SCARG(p,k) ((p)->k.le.datum) /* get arg from args pointer */
141#else 141#else
142#error "what byte order is this machine?" 142#error "what byte order is this machine?"
143#endif 143#endif
144 144
145#define SYCALL_INDIRECT 0x0000002 /* indirect (ie syscall() or __syscall()) */ 145#define SYCALL_INDIRECT 0x0000002 /* indirect (ie syscall() or __syscall()) */
146#define SYCALL_NARGS64_MASK 0x000f000 /* count of 64bit args */ 146#define SYCALL_NARGS64_MASK 0x000f000 /* count of 64bit args */
147#define SYCALL_RET_64 0x0010000 /* retval is a 64bit integer value */ 147#define SYCALL_RET_64 0x0010000 /* retval is a 64bit integer value */
148#define SYCALL_ARG0_64 0x0020000 148#define SYCALL_ARG0_64 0x0020000
149#define SYCALL_ARG1_64 0x0040000 149#define SYCALL_ARG1_64 0x0040000
150#define SYCALL_ARG2_64 0x0080000 150#define SYCALL_ARG2_64 0x0080000
151#define SYCALL_ARG3_64 0x0100000 151#define SYCALL_ARG3_64 0x0100000
152#define SYCALL_ARG4_64 0x0200000 152#define SYCALL_ARG4_64 0x0200000
153#define SYCALL_ARG5_64 0x0400000 153#define SYCALL_ARG5_64 0x0400000
154#define SYCALL_ARG6_64 0x0800000 154#define SYCALL_ARG6_64 0x0800000
155#define SYCALL_ARG7_64 0x1000000 155#define SYCALL_ARG7_64 0x1000000
156#define SYCALL_NOSYS 0x2000000 /* permanent nosys in sysent[] */ 156#define SYCALL_NOSYS 0x2000000 /* permanent nosys in sysent[] */
157#define SYCALL_ARG_PTR 0x4000000 /* at least one argument is a pointer */ 157#define SYCALL_ARG_PTR 0x4000000 /* at least one argument is a pointer */
158#define SYCALL_RET_64_P(sy) ((sy)->sy_flags & SYCALL_RET_64) 158#define SYCALL_RET_64_P(sy) ((sy)->sy_flags & SYCALL_RET_64)
159#define SYCALL_ARG_64_P(sy, n) ((sy)->sy_flags & (SYCALL_ARG0_64 << (n))) 159#define SYCALL_ARG_64_P(sy, n) ((sy)->sy_flags & (SYCALL_ARG0_64 << (n)))
160#define SYCALL_ARG_64_MASK(sy) (((sy)->sy_flags >> 17) & 0xff) 160#define SYCALL_ARG_64_MASK(sy) (((sy)->sy_flags >> 17) & 0xff)
161#define SYCALL_ARG_PTR_P(sy) ((sy)->sy_flags & SYCALL_ARG_PTR) 161#define SYCALL_ARG_PTR_P(sy) ((sy)->sy_flags & SYCALL_ARG_PTR)
162#define SYCALL_NARGS64(sy) (((sy)->sy_flags >> 12) & 0x0f) 162#define SYCALL_NARGS64(sy) (((sy)->sy_flags >> 12) & 0x0f)
163#define SYCALL_NARGS64_VAL(n) ((n) << 12) 163#define SYCALL_NARGS64_VAL(n) ((n) << 12)
164 164
165extern int boothowto; /* reboot flags, from console subsystem */ 165extern int boothowto; /* reboot flags, from console subsystem */
166#define bootverbose (boothowto & AB_VERBOSE) 166#define bootverbose (boothowto & AB_VERBOSE)
167#define bootquiet (boothowto & AB_QUIET) 167#define bootquiet (boothowto & AB_QUIET)
168 168
169extern const char *get_booted_kernel(void); 169extern const char *get_booted_kernel(void);
170 170
171extern void (*v_putc)(int); /* Virtual console putc routine */ 171extern void (*v_putc)(int); /* Virtual console putc routine */
172 172
173/* 173/*
174 * General function declarations. 174 * General function declarations.
175 */ 175 */
176void voidop(void); 176void voidop(void);
177int nullop(void *); 177int nullop(void *);
178void* nullret(void); 178void* nullret(void);
179int enodev(void); 179int enodev(void);
180int enosys(void); 180int enosys(void);
181int enoioctl(void); 181int enoioctl(void);
182int enxio(void); 182int enxio(void);
183int eopnotsupp(void); 183int eopnotsupp(void);
184 184
185enum hashtype { 185enum hashtype {
186 HASH_LIST, 186 HASH_LIST,
187 HASH_SLIST, 187 HASH_SLIST,
188 HASH_TAILQ, 188 HASH_TAILQ,
189 HASH_PSLIST 189 HASH_PSLIST
190}; 190};
191 191
192#ifdef _KERNEL 192#ifdef _KERNEL
193#define COND_SET_STRUCT(dst, src, allow) \ 193#define COND_SET_STRUCT(dst, src, allow) \
194 do { \ 194 do { \
 195 /* \
 196 * Make sure we don't end up hashing/assigning large \
 197 * structure for performance. Upper-bound is arbitrary, \
 198 * but consider before bumping. \
 199 */ \
195 CTASSERT(sizeof(src) < 32); \ 200 CTASSERT(sizeof(src) < 32); \
196 if (allow) \ 201 if (allow) \
197 dst = src; \ 202 dst = src; \
198 else \ 203 else \
199 hash_value(&dst, sizeof(dst), &src, sizeof(src)); \ 204 hash_value(&dst, sizeof(dst), &src, sizeof(src)); \
200 } while (/*CONSTCOND*/0) 205 } while (/*CONSTCOND*/0)
201 206
202#define COND_SET_CPTR(dst, src, allow) \ 207#define COND_SET_CPTR(dst, src, allow) \
203 do { \ 208 do { \
204 if (allow) \ 209 if (allow) \
205 dst = src; \ 210 dst = src; \
206 else { \ 211 else { \
207 void *__v; \ 212 void *__v; \
208 hash_value(&__v, sizeof(__v), &src, sizeof(src)); \ 213 hash_value(&__v, sizeof(__v), &src, sizeof(src)); \
209 dst = __v; \ 214 dst = __v; \
210 } \ 215 } \
211 } while (/*CONSTCOND*/0) 216 } while (/*CONSTCOND*/0)
212 217
213#define COND_SET_PTR(dst, src, allow) \ 218#define COND_SET_PTR(dst, src, allow) \
214 do { \ 219 do { \
215 if (allow) \ 220 if (allow) \
216 dst = src; \ 221 dst = src; \
217 else \ 222 else \
218 hash_value(&dst, sizeof(dst), &src, sizeof(src)); \ 223 hash_value(&dst, sizeof(dst), &src, sizeof(src)); \
219 } while (/*CONSTCOND*/0) 224 } while (/*CONSTCOND*/0)
220 225
221#define COND_SET_VALUE(dst, src, allow) \ 226#define COND_SET_VALUE(dst, src, allow) \
222 do { \ 227 do { \
223 if (allow) \ 228 if (allow) \
224 dst = src; \ 229 dst = src; \
225 else { \ 230 else { \
226 uint64_t __v = src; \ 231 uint64_t __v = src; \
227 hash_value(&dst, sizeof(dst), &__v, sizeof(__v)); \ 232 hash_value(&dst, sizeof(dst), &__v, sizeof(__v)); \
228 } \ 233 } \
229 } while (/*CONSTCOND*/0) 234 } while (/*CONSTCOND*/0)
230 235
231void hash_value(void *, size_t, const void *, size_t); 236void hash_value(void *, size_t, const void *, size_t);
232bool get_expose_address(struct proc *); 237bool get_expose_address(struct proc *);
233void *hashinit(u_int, enum hashtype, bool, u_long *); 238void *hashinit(u_int, enum hashtype, bool, u_long *);
234void hashdone(void *, enum hashtype, u_long); 239void hashdone(void *, enum hashtype, u_long);
235int seltrue(dev_t, int, struct lwp *); 240int seltrue(dev_t, int, struct lwp *);
236int sys_nosys(struct lwp *, const void *, register_t *); 241int sys_nosys(struct lwp *, const void *, register_t *);
237int sys_nomodule(struct lwp *, const void *, register_t *); 242int sys_nomodule(struct lwp *, const void *, register_t *);
238 243
239void aprint_normal(const char *, ...) __printflike(1, 2); 244void aprint_normal(const char *, ...) __printflike(1, 2);
240void aprint_error(const char *, ...) __printflike(1, 2); 245void aprint_error(const char *, ...) __printflike(1, 2);
241void aprint_naive(const char *, ...) __printflike(1, 2); 246void aprint_naive(const char *, ...) __printflike(1, 2);
242void aprint_verbose(const char *, ...) __printflike(1, 2); 247void aprint_verbose(const char *, ...) __printflike(1, 2);
243void aprint_debug(const char *, ...) __printflike(1, 2); 248void aprint_debug(const char *, ...) __printflike(1, 2);
244 249
245void aprint_normal_dev(device_t, const char *, ...) __printflike(2, 3); 250void aprint_normal_dev(device_t, const char *, ...) __printflike(2, 3);
246void aprint_error_dev(device_t, const char *, ...) __printflike(2, 3); 251void aprint_error_dev(device_t, const char *, ...) __printflike(2, 3);
247void aprint_naive_dev(device_t, const char *, ...) __printflike(2, 3); 252void aprint_naive_dev(device_t, const char *, ...) __printflike(2, 3);
248void aprint_verbose_dev(device_t, const char *, ...) __printflike(2, 3); 253void aprint_verbose_dev(device_t, const char *, ...) __printflike(2, 3);
249void aprint_debug_dev(device_t, const char *, ...) __printflike(2, 3); 254void aprint_debug_dev(device_t, const char *, ...) __printflike(2, 3);
250 255
251void device_printf(device_t, const char *fmt, ...) __printflike(2, 3); 256void device_printf(device_t, const char *fmt, ...) __printflike(2, 3);
252 257
253struct ifnet; 258struct ifnet;
254 259
255void aprint_normal_ifnet(struct ifnet *, const char *, ...) 260void aprint_normal_ifnet(struct ifnet *, const char *, ...)
256 __printflike(2, 3); 261 __printflike(2, 3);
257void aprint_error_ifnet(struct ifnet *, const char *, ...) 262void aprint_error_ifnet(struct ifnet *, const char *, ...)
258 __printflike(2, 3); 263 __printflike(2, 3);
259void aprint_naive_ifnet(struct ifnet *, const char *, ...) 264void aprint_naive_ifnet(struct ifnet *, const char *, ...)
260 __printflike(2, 3); 265 __printflike(2, 3);
261void aprint_verbose_ifnet(struct ifnet *, const char *, ...) 266void aprint_verbose_ifnet(struct ifnet *, const char *, ...)
262 __printflike(2, 3); 267 __printflike(2, 3);
263void aprint_debug_ifnet(struct ifnet *, const char *, ...) 268void aprint_debug_ifnet(struct ifnet *, const char *, ...)
264 __printflike(2, 3); 269 __printflike(2, 3);
265 270
266int aprint_get_error_count(void); 271int aprint_get_error_count(void);
267 272
268void printf_tolog(const char *, ...) __printflike(1, 2); 273void printf_tolog(const char *, ...) __printflike(1, 2);
269 274
270void printf_nolog(const char *, ...) __printflike(1, 2); 275void printf_nolog(const char *, ...) __printflike(1, 2);
271 276
272void printf_nostamp(const char *, ...) __printflike(1, 2); 277void printf_nostamp(const char *, ...) __printflike(1, 2);
273 278
274void printf(const char *, ...) __printflike(1, 2); 279void printf(const char *, ...) __printflike(1, 2);
275 280
276int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); 281int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
277 282
278int vasprintf(char **, const char *, va_list) __printflike(2, 0); 283int vasprintf(char **, const char *, va_list) __printflike(2, 0);
279 284
280void vprintf(const char *, va_list) __printflike(1, 0); 285void vprintf(const char *, va_list) __printflike(1, 0);
281 286
282int vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0); 287int vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0);
283 288
284void vprintf_flags(int, const char *, va_list) __printflike(2, 0); 289void vprintf_flags(int, const char *, va_list) __printflike(2, 0);
285 290
286void printf_flags(int, const char *, ...) __printflike(2, 3); 291void printf_flags(int, const char *, ...) __printflike(2, 3);
287 292
288int humanize_number(char *, size_t, uint64_t, const char *, int); 293int humanize_number(char *, size_t, uint64_t, const char *, int);
289 294
290void twiddle(void); 295void twiddle(void);
291void banner(void); 296void banner(void);
292#endif /* _KERNEL */ 297#endif /* _KERNEL */
293 298
294void panic(const char *, ...) __dead __printflike(1, 2); 299void panic(const char *, ...) __dead __printflike(1, 2);
295void vpanic(const char *, va_list) __dead __printflike(1, 0); 300void vpanic(const char *, va_list) __dead __printflike(1, 0);
296void uprintf(const char *, ...) __printflike(1, 2); 301void uprintf(const char *, ...) __printflike(1, 2);
297void uprintf_locked(const char *, ...) __printflike(1, 2); 302void uprintf_locked(const char *, ...) __printflike(1, 2);
298void ttyprintf(struct tty *, const char *, ...) __printflike(2, 3); 303void ttyprintf(struct tty *, const char *, ...) __printflike(2, 3);
299 304
300int format_bytes(char *, size_t, uint64_t); 305int format_bytes(char *, size_t, uint64_t);
301 306
302void tablefull(const char *, const char *); 307void tablefull(const char *, const char *);
303 308
304#if defined(_KERNEL) && defined(KASAN) 309#if defined(_KERNEL) && defined(KASAN)
305int kasan_kcopy(const void *, void *, size_t); 310int kasan_kcopy(const void *, void *, size_t);
306#define kcopy kasan_kcopy 311#define kcopy kasan_kcopy
307#elif defined(_KERNEL) && defined(KCSAN) 312#elif defined(_KERNEL) && defined(KCSAN)
308int kcsan_kcopy(const void *, void *, size_t); 313int kcsan_kcopy(const void *, void *, size_t);
309#define kcopy kcsan_kcopy 314#define kcopy kcsan_kcopy
310#elif defined(_KERNEL) && defined(KMSAN) 315#elif defined(_KERNEL) && defined(KMSAN)
311int kmsan_kcopy(const void *, void *, size_t); 316int kmsan_kcopy(const void *, void *, size_t);
312#define kcopy kmsan_kcopy 317#define kcopy kmsan_kcopy
313#else 318#else
314int kcopy(const void *, void *, size_t); 319int kcopy(const void *, void *, size_t);
315#endif 320#endif
316 321
317#ifdef _KERNEL 322#ifdef _KERNEL
318#define bcopy(src, dst, len) memcpy((dst), (src), (len)) 323#define bcopy(src, dst, len) memcpy((dst), (src), (len))
319#define bzero(src, len) memset((src), 0, (len)) 324#define bzero(src, len) memset((src), 0, (len))
320#define bcmp(a, b, len) memcmp((a), (b), (len)) 325#define bcmp(a, b, len) memcmp((a), (b), (len))
321#endif /* KERNEL */ 326#endif /* KERNEL */
322 327
323int copystr(const void *, void *, size_t, size_t *); 328int copystr(const void *, void *, size_t, size_t *);
324#if defined(_KERNEL) && defined(KASAN) 329#if defined(_KERNEL) && defined(KASAN)
325int kasan_copyinstr(const void *, void *, size_t, size_t *); 330int kasan_copyinstr(const void *, void *, size_t, size_t *);
326int kasan_copyoutstr(const void *, void *, size_t, size_t *); 331int kasan_copyoutstr(const void *, void *, size_t, size_t *);
327int kasan_copyin(const void *, void *, size_t); 332int kasan_copyin(const void *, void *, size_t);
328int copyout(const void *, void *, size_t); 333int copyout(const void *, void *, size_t);
329#define copyinstr kasan_copyinstr 334#define copyinstr kasan_copyinstr
330#define copyoutstr kasan_copyoutstr 335#define copyoutstr kasan_copyoutstr
331#define copyin kasan_copyin 336#define copyin kasan_copyin
332#elif defined(_KERNEL) && defined(KCSAN) 337#elif defined(_KERNEL) && defined(KCSAN)
333int kcsan_copyinstr(const void *, void *, size_t, size_t *); 338int kcsan_copyinstr(const void *, void *, size_t, size_t *);
334int kcsan_copyoutstr(const void *, void *, size_t, size_t *); 339int kcsan_copyoutstr(const void *, void *, size_t, size_t *);
335int kcsan_copyin(const void *, void *, size_t); 340int kcsan_copyin(const void *, void *, size_t);
336int kcsan_copyout(const void *, void *, size_t); 341int kcsan_copyout(const void *, void *, size_t);
337#define copyinstr kcsan_copyinstr 342#define copyinstr kcsan_copyinstr
338#define copyoutstr kcsan_copyoutstr 343#define copyoutstr kcsan_copyoutstr
339#define copyin kcsan_copyin 344#define copyin kcsan_copyin
340#define copyout kcsan_copyout 345#define copyout kcsan_copyout
341#elif defined(_KERNEL) && defined(KMSAN) 346#elif defined(_KERNEL) && defined(KMSAN)
342int kmsan_copyinstr(const void *, void *, size_t, size_t *); 347int kmsan_copyinstr(const void *, void *, size_t, size_t *);
343int kmsan_copyoutstr(const void *, void *, size_t, size_t *); 348int kmsan_copyoutstr(const void *, void *, size_t, size_t *);
344int kmsan_copyin(const void *, void *, size_t); 349int kmsan_copyin(const void *, void *, size_t);
345int kmsan_copyout(const void *, void *, size_t); 350int kmsan_copyout(const void *, void *, size_t);
346#define copyinstr kmsan_copyinstr 351#define copyinstr kmsan_copyinstr
347#define copyoutstr kmsan_copyoutstr 352#define copyoutstr kmsan_copyoutstr
348#define copyin kmsan_copyin 353#define copyin kmsan_copyin
349#define copyout kmsan_copyout 354#define copyout kmsan_copyout
350#else 355#else
351int copyinstr(const void *, void *, size_t, size_t *); 356int copyinstr(const void *, void *, size_t, size_t *);
352int copyoutstr(const void *, void *, size_t, size_t *); 357int copyoutstr(const void *, void *, size_t, size_t *);
353int copyin(const void *, void *, size_t); 358int copyin(const void *, void *, size_t);
354int copyout(const void *, void *, size_t); 359int copyout(const void *, void *, size_t);
355#endif 360#endif
356 361
357#ifdef _KERNEL 362#ifdef _KERNEL
358typedef int (*copyin_t)(const void *, void *, size_t); 363typedef int (*copyin_t)(const void *, void *, size_t);
359typedef int (*copyout_t)(const void *, void *, size_t); 364typedef int (*copyout_t)(const void *, void *, size_t);
360#endif 365#endif
361 366
362int copyin_proc(struct proc *, const void *, void *, size_t); 367int copyin_proc(struct proc *, const void *, void *, size_t);
363int copyout_proc(struct proc *, const void *, void *, size_t); 368int copyout_proc(struct proc *, const void *, void *, size_t);
364int copyin_pid(pid_t, const void *, void *, size_t); 369int copyin_pid(pid_t, const void *, void *, size_t);
365int copyin_vmspace(struct vmspace *, const void *, void *, size_t); 370int copyin_vmspace(struct vmspace *, const void *, void *, size_t);
366int copyout_vmspace(struct vmspace *, const void *, void *, size_t); 371int copyout_vmspace(struct vmspace *, const void *, void *, size_t);
367 372
368int ioctl_copyin(int ioctlflags, const void *src, void *dst, size_t len); 373int ioctl_copyin(int ioctlflags, const void *src, void *dst, size_t len);
369int ioctl_copyout(int ioctlflags, const void *src, void *dst, size_t len); 374int ioctl_copyout(int ioctlflags, const void *src, void *dst, size_t len);
370 375
371int ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 376int ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *);
372#ifdef _LP64 377#ifdef _LP64
373int ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 378int ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *);
374#endif 379#endif
375int ucas_ptr(volatile void *, void *, void *, void *); 380int ucas_ptr(volatile void *, void *, void *, void *);
376int ucas_int(volatile unsigned int *, unsigned int, unsigned int, 381int ucas_int(volatile unsigned int *, unsigned int, unsigned int,
377 unsigned int *); 382 unsigned int *);
378int ufetch_8(const uint8_t *, uint8_t *); 383int ufetch_8(const uint8_t *, uint8_t *);
379int ufetch_16(const uint16_t *, uint16_t *); 384int ufetch_16(const uint16_t *, uint16_t *);
380int ufetch_32(const uint32_t *, uint32_t *); 385int ufetch_32(const uint32_t *, uint32_t *);
381#ifdef _LP64 386#ifdef _LP64
382int ufetch_64(const uint64_t *, uint64_t *); 387int ufetch_64(const uint64_t *, uint64_t *);
383#endif 388#endif
384int ufetch_char(const unsigned char *, unsigned char *); 389int ufetch_char(const unsigned char *, unsigned char *);
385int ufetch_short(const unsigned short *, unsigned short *); 390int ufetch_short(const unsigned short *, unsigned short *);
386int ufetch_int(const unsigned int *, unsigned int *); 391int ufetch_int(const unsigned int *, unsigned int *);
387int ufetch_long(const unsigned long *, unsigned long *); 392int ufetch_long(const unsigned long *, unsigned long *);
388int ufetch_ptr(const void **, void **); 393int ufetch_ptr(const void **, void **);
389int ustore_8(uint8_t *, uint8_t); 394int ustore_8(uint8_t *, uint8_t);
390int ustore_16(uint16_t *, uint16_t); 395int ustore_16(uint16_t *, uint16_t);
391int ustore_32(uint32_t *, uint32_t); 396int ustore_32(uint32_t *, uint32_t);
392#ifdef _LP64 397#ifdef _LP64
393int ustore_64(uint64_t *, uint64_t); 398int ustore_64(uint64_t *, uint64_t);
394#endif 399#endif
395int ustore_char(unsigned char *, unsigned char); 400int ustore_char(unsigned char *, unsigned char);
396int ustore_short(unsigned short *, unsigned short); 401int ustore_short(unsigned short *, unsigned short);
397int ustore_int(unsigned int *, unsigned int); 402int ustore_int(unsigned int *, unsigned int);
398int ustore_long(unsigned long *, unsigned long); 403int ustore_long(unsigned long *, unsigned long);
399int ustore_ptr(void **, void *); 404int ustore_ptr(void **, void *);
400 405
401#ifdef __UCAS_PRIVATE 406#ifdef __UCAS_PRIVATE
402 407
403#if defined(__HAVE_UCAS_FULL) && defined(KASAN) 408#if defined(__HAVE_UCAS_FULL) && defined(KASAN)
404int kasan__ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 409int kasan__ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *);
405#ifdef __HAVE_UCAS_MP 410#ifdef __HAVE_UCAS_MP
406int kasan__ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 411int kasan__ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *);
407#endif /* __HAVE_UCAS_MP */ 412#endif /* __HAVE_UCAS_MP */
408#ifdef _LP64 413#ifdef _LP64
409int kasan__ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 414int kasan__ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *);
410#ifdef __HAVE_UCAS_MP 415#ifdef __HAVE_UCAS_MP
411int kasan__ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 416int kasan__ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *);
412#endif /* __HAVE_UCAS_MP */ 417#endif /* __HAVE_UCAS_MP */
413#endif /* _LP64 */ 418#endif /* _LP64 */
414#define _ucas_32 kasan__ucas_32 419#define _ucas_32 kasan__ucas_32
415#define _ucas_32_mp kasan__ucas_32_mp 420#define _ucas_32_mp kasan__ucas_32_mp
416#define _ucas_64 kasan__ucas_64 421#define _ucas_64 kasan__ucas_64
417#define _ucas_64_mp kasan__ucas_64_mp 422#define _ucas_64_mp kasan__ucas_64_mp
418#elif defined(__HAVE_UCAS_FULL) && defined(KMSAN) 423#elif defined(__HAVE_UCAS_FULL) && defined(KMSAN)
419int kmsan__ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 424int kmsan__ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *);
420#ifdef __HAVE_UCAS_MP 425#ifdef __HAVE_UCAS_MP
421int kmsan__ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 426int kmsan__ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *);
422#endif /* __HAVE_UCAS_MP */ 427#endif /* __HAVE_UCAS_MP */
423#ifdef _LP64 428#ifdef _LP64
424int kmsan__ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 429int kmsan__ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *);
425#ifdef __HAVE_UCAS_MP 430#ifdef __HAVE_UCAS_MP
426int kmsan__ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 431int kmsan__ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *);
427#endif /* __HAVE_UCAS_MP */ 432#endif /* __HAVE_UCAS_MP */
428#endif /* _LP64 */ 433#endif /* _LP64 */
429#define _ucas_32 kmsan__ucas_32 434#define _ucas_32 kmsan__ucas_32
430#define _ucas_32_mp kmsan__ucas_32_mp 435#define _ucas_32_mp kmsan__ucas_32_mp
431#define _ucas_64 kmsan__ucas_64 436#define _ucas_64 kmsan__ucas_64
432#define _ucas_64_mp kmsan__ucas_64_mp 437#define _ucas_64_mp kmsan__ucas_64_mp
433#else 438#else
434int _ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 439int _ucas_32(volatile uint32_t *, uint32_t, uint32_t, uint32_t *);
435#ifdef __HAVE_UCAS_MP 440#ifdef __HAVE_UCAS_MP
436int _ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *); 441int _ucas_32_mp(volatile uint32_t *, uint32_t, uint32_t, uint32_t *);
437#endif /* __HAVE_UCAS_MP */ 442#endif /* __HAVE_UCAS_MP */
438#ifdef _LP64 443#ifdef _LP64
439int _ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 444int _ucas_64(volatile uint64_t *, uint64_t, uint64_t, uint64_t *);
440#ifdef __HAVE_UCAS_MP 445#ifdef __HAVE_UCAS_MP
441int _ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *); 446int _ucas_64_mp(volatile uint64_t *, uint64_t, uint64_t, uint64_t *);
442#endif /* __HAVE_UCAS_MP */ 447#endif /* __HAVE_UCAS_MP */
443#endif /* _LP64 */ 448#endif /* _LP64 */
444#endif 449#endif
445 450
446#endif /* __UCAS_PRIVATE */ 451#endif /* __UCAS_PRIVATE */
447 452
448#ifdef __UFETCHSTORE_PRIVATE 453#ifdef __UFETCHSTORE_PRIVATE
449 454
450#if defined(KASAN) 455#if defined(KASAN)
451int kasan__ufetch_8(const uint8_t *, uint8_t *); 456int kasan__ufetch_8(const uint8_t *, uint8_t *);
452int kasan__ufetch_16(const uint16_t *, uint16_t *); 457int kasan__ufetch_16(const uint16_t *, uint16_t *);
453int kasan__ufetch_32(const uint32_t *, uint32_t *); 458int kasan__ufetch_32(const uint32_t *, uint32_t *);
454#ifdef _LP64 459#ifdef _LP64
455int kasan__ufetch_64(const uint64_t *, uint64_t *); 460int kasan__ufetch_64(const uint64_t *, uint64_t *);
456#endif 461#endif
457int _ustore_8(uint8_t *, uint8_t); 462int _ustore_8(uint8_t *, uint8_t);
458int _ustore_16(uint16_t *, uint16_t); 463int _ustore_16(uint16_t *, uint16_t);
459int _ustore_32(uint32_t *, uint32_t); 464int _ustore_32(uint32_t *, uint32_t);
460#ifdef _LP64 465#ifdef _LP64
461int _ustore_64(uint64_t *, uint64_t); 466int _ustore_64(uint64_t *, uint64_t);
462#endif 467#endif
463#define _ufetch_8 kasan__ufetch_8 468#define _ufetch_8 kasan__ufetch_8
464#define _ufetch_16 kasan__ufetch_16 469#define _ufetch_16 kasan__ufetch_16
465#define _ufetch_32 kasan__ufetch_32 470#define _ufetch_32 kasan__ufetch_32
466#define _ufetch_64 kasan__ufetch_64 471#define _ufetch_64 kasan__ufetch_64
467#elif defined(KMSAN) 472#elif defined(KMSAN)
468int kmsan__ufetch_8(const uint8_t *, uint8_t *); 473int kmsan__ufetch_8(const uint8_t *, uint8_t *);
469int kmsan__ufetch_16(const uint16_t *, uint16_t *); 474int kmsan__ufetch_16(const uint16_t *, uint16_t *);
470int kmsan__ufetch_32(const uint32_t *, uint32_t *); 475int kmsan__ufetch_32(const uint32_t *, uint32_t *);
471#ifdef _LP64 476#ifdef _LP64
472int kmsan__ufetch_64(const uint64_t *, uint64_t *); 477int kmsan__ufetch_64(const uint64_t *, uint64_t *);
473#endif 478#endif
474int kmsan__ustore_8(uint8_t *, uint8_t); 479int kmsan__ustore_8(uint8_t *, uint8_t);
475int kmsan__ustore_16(uint16_t *, uint16_t); 480int kmsan__ustore_16(uint16_t *, uint16_t);
476int kmsan__ustore_32(uint32_t *, uint32_t); 481int kmsan__ustore_32(uint32_t *, uint32_t);
477#ifdef _LP64 482#ifdef _LP64
478int kmsan__ustore_64(uint64_t *, uint64_t); 483int kmsan__ustore_64(uint64_t *, uint64_t);
479#endif 484#endif
480#define _ufetch_8 kmsan__ufetch_8 485#define _ufetch_8 kmsan__ufetch_8
481#define _ufetch_16 kmsan__ufetch_16 486#define _ufetch_16 kmsan__ufetch_16
482#define _ufetch_32 kmsan__ufetch_32 487#define _ufetch_32 kmsan__ufetch_32
483#define _ufetch_64 kmsan__ufetch_64 488#define _ufetch_64 kmsan__ufetch_64
484#define _ustore_8 kmsan__ustore_8 489#define _ustore_8 kmsan__ustore_8
485#define _ustore_16 kmsan__ustore_16 490#define _ustore_16 kmsan__ustore_16
486#define _ustore_32 kmsan__ustore_32 491#define _ustore_32 kmsan__ustore_32
487#define _ustore_64 kmsan__ustore_64 492#define _ustore_64 kmsan__ustore_64
488#else 493#else
489int _ufetch_8(const uint8_t *, uint8_t *); 494int _ufetch_8(const uint8_t *, uint8_t *);
490int _ufetch_16(const uint16_t *, uint16_t *); 495int _ufetch_16(const uint16_t *, uint16_t *);
491int _ufetch_32(const uint32_t *, uint32_t *); 496int _ufetch_32(const uint32_t *, uint32_t *);
492#ifdef _LP64 497#ifdef _LP64
493int _ufetch_64(const uint64_t *, uint64_t *); 498int _ufetch_64(const uint64_t *, uint64_t *);
494#endif 499#endif
495int _ustore_8(uint8_t *, uint8_t); 500int _ustore_8(uint8_t *, uint8_t);
496int _ustore_16(uint16_t *, uint16_t); 501int _ustore_16(uint16_t *, uint16_t);
497int _ustore_32(uint32_t *, uint32_t); 502int _ustore_32(uint32_t *, uint32_t);
498#ifdef _LP64 503#ifdef _LP64
499int _ustore_64(uint64_t *, uint64_t); 504int _ustore_64(uint64_t *, uint64_t);
500#endif 505#endif
501#endif 506#endif
502 507
503#endif /* __UFETCHSTORE_PRIVATE */ 508#endif /* __UFETCHSTORE_PRIVATE */
504 509
505void hardclock(struct clockframe *); 510void hardclock(struct clockframe *);
506void softclock(void *); 511void softclock(void *);
507void statclock(struct clockframe *); 512void statclock(struct clockframe *);
508 513
509#ifdef NTP 514#ifdef NTP
510void ntp_init(void); 515void ntp_init(void);
511#ifdef PPS_SYNC 516#ifdef PPS_SYNC
512struct timespec; 517struct timespec;
513void hardpps(struct timespec *, long); 518void hardpps(struct timespec *, long);
514#endif /* PPS_SYNC */ 519#endif /* PPS_SYNC */
515#else 520#else
516void ntp_init(void); /* also provides adjtime() functionality */ 521void ntp_init(void); /* also provides adjtime() functionality */
517#endif /* NTP */ 522#endif /* NTP */
518 523
519void ssp_init(void); 524void ssp_init(void);
520 525
521void initclocks(void); 526void initclocks(void);
522void inittodr(time_t); 527void inittodr(time_t);
523void resettodr(void); 528void resettodr(void);
524void cpu_initclocks(void); 529void cpu_initclocks(void);
525void setrootfstime(time_t); 530void setrootfstime(time_t);
526 531
527void startprofclock(struct proc *); 532void startprofclock(struct proc *);
528void stopprofclock(struct proc *); 533void stopprofclock(struct proc *);
529void proftick(struct clockframe *); 534void proftick(struct clockframe *);
530void setstatclockrate(int); 535void setstatclockrate(int);
531 536
532/* 537/*
533 * Critical polling hooks. Functions to be run while the kernel stays 538 * Critical polling hooks. Functions to be run while the kernel stays
534 * elevated IPL for a "long" time. (watchdogs). 539 * elevated IPL for a "long" time. (watchdogs).
535 */ 540 */
536void *critpollhook_establish(void (*)(void *), void *); 541void *critpollhook_establish(void (*)(void *), void *);
537void critpollhook_disestablish(void *); 542void critpollhook_disestablish(void *);
538void docritpollhooks(void); 543void docritpollhooks(void);
539 544
540/* 545/*
541 * Shutdown hooks. Functions to be run with all interrupts disabled 546 * Shutdown hooks. Functions to be run with all interrupts disabled
542 * immediately before the system is halted or rebooted. 547 * immediately before the system is halted or rebooted.
543 */ 548 */
544void *shutdownhook_establish(void (*)(void *), void *); 549void *shutdownhook_establish(void (*)(void *), void *);
545void shutdownhook_disestablish(void *); 550void shutdownhook_disestablish(void *);
546void doshutdownhooks(void); 551void doshutdownhooks(void);
547 552
548/* 553/*
549 * Power management hooks. 554 * Power management hooks.
550 */ 555 */
551void *powerhook_establish(const char *, void (*)(int, void *), void *); 556void *powerhook_establish(const char *, void (*)(int, void *), void *);
552void powerhook_disestablish(void *); 557void powerhook_disestablish(void *);
553void dopowerhooks(int); 558void dopowerhooks(int);
554#define PWR_RESUME 0 559#define PWR_RESUME 0
555#define PWR_SUSPEND 1 560#define PWR_SUSPEND 1
556#define PWR_STANDBY 2 561#define PWR_STANDBY 2
557#define PWR_SOFTRESUME 3 562#define PWR_SOFTRESUME 3
558#define PWR_SOFTSUSPEND 4 563#define PWR_SOFTSUSPEND 4
559#define PWR_SOFTSTANDBY 5 564#define PWR_SOFTSTANDBY 5
560#define PWR_NAMES \ 565#define PWR_NAMES \
561 "resume", /* 0 */ \ 566 "resume", /* 0 */ \
562 "suspend", /* 1 */ \ 567 "suspend", /* 1 */ \
563 "standby", /* 2 */ \ 568 "standby", /* 2 */ \
564 "softresume", /* 3 */ \ 569 "softresume", /* 3 */ \
565 "softsuspend", /* 4 */ \ 570 "softsuspend", /* 4 */ \
566 "softstandby" /* 5 */ 571 "softstandby" /* 5 */
567 572
568/* 573/*
569 * Mountroot hooks (and mountroot declaration). Device drivers establish 574 * Mountroot hooks (and mountroot declaration). Device drivers establish
570 * these to be executed just before (*mountroot)() if the passed device is 575 * these to be executed just before (*mountroot)() if the passed device is
571 * selected as the root device. 576 * selected as the root device.
572 */ 577 */
573 578
574#define ROOT_FSTYPE_ANY "?" 579#define ROOT_FSTYPE_ANY "?"
575 580
576extern const char *rootfstype; 581extern const char *rootfstype;
577void *mountroothook_establish(void (*)(device_t), device_t); 582void *mountroothook_establish(void (*)(device_t), device_t);
578void mountroothook_disestablish(void *); 583void mountroothook_disestablish(void *);
579void mountroothook_destroy(void); 584void mountroothook_destroy(void);
580void domountroothook(device_t); 585void domountroothook(device_t);
581 586
582/* 587/*
583 * Exec hooks. Subsystems may want to do cleanup when a process 588 * Exec hooks. Subsystems may want to do cleanup when a process
584 * execs. 589 * execs.
585 */ 590 */
586void *exechook_establish(void (*)(struct proc *, void *), void *); 591void *exechook_establish(void (*)(struct proc *, void *), void *);
587void exechook_disestablish(void *); 592void exechook_disestablish(void *);
588void doexechooks(struct proc *); 593void doexechooks(struct proc *);
589 594
590/* 595/*
591 * Exit hooks. Subsystems may want to do cleanup when a process exits. 596 * Exit hooks. Subsystems may want to do cleanup when a process exits.
592 */ 597 */
593void *exithook_establish(void (*)(struct proc *, void *), void *); 598void *exithook_establish(void (*)(struct proc *, void *), void *);
594void exithook_disestablish(void *); 599void exithook_disestablish(void *);
595void doexithooks(struct proc *); 600void doexithooks(struct proc *);
596 601
597/* 602/*
598 * Fork hooks. Subsystems may want to do special processing when a process 603 * Fork hooks. Subsystems may want to do special processing when a process
599 * forks. 604 * forks.
600 */ 605 */
601void *forkhook_establish(void (*)(struct proc *, struct proc *)); 606void *forkhook_establish(void (*)(struct proc *, struct proc *));
602void forkhook_disestablish(void *); 607void forkhook_disestablish(void *);
603void doforkhooks(struct proc *, struct proc *); 608void doforkhooks(struct proc *, struct proc *);
604 609
605/* 610/*
606 * kernel syscall tracing/debugging hooks. 611 * kernel syscall tracing/debugging hooks.
607 */ 612 */
608#ifdef _KERNEL 613#ifdef _KERNEL
609bool trace_is_enabled(struct proc *); 614bool trace_is_enabled(struct proc *);
610int trace_enter(register_t, const struct sysent *, const void *); 615int trace_enter(register_t, const struct sysent *, const void *);
611void trace_exit(register_t, const struct sysent *, const void *, 616void trace_exit(register_t, const struct sysent *, const void *,
612 register_t [], int); 617 register_t [], int);
613#endif 618#endif
614 619
615int uiomove(void *, size_t, struct uio *); 620int uiomove(void *, size_t, struct uio *);
616int uiomove_frombuf(void *, size_t, struct uio *); 621int uiomove_frombuf(void *, size_t, struct uio *);
617 622
618#ifdef _KERNEL 623#ifdef _KERNEL
619int setjmp(label_t *) __returns_twice; 624int setjmp(label_t *) __returns_twice;
620void longjmp(label_t *) __dead; 625void longjmp(label_t *) __dead;
621#endif 626#endif
622 627
623void consinit(void); 628void consinit(void);
624 629
625void cpu_startup(void); 630void cpu_startup(void);
626void cpu_configure(void); 631void cpu_configure(void);
627void cpu_bootconf(void); 632void cpu_bootconf(void);
628void cpu_rootconf(void); 633void cpu_rootconf(void);
629void cpu_dumpconf(void); 634void cpu_dumpconf(void);
630 635
631#ifdef GPROF 636#ifdef GPROF
632void kmstartup(void); 637void kmstartup(void);
633#endif 638#endif
634 639
635void machdep_init(void); 640void machdep_init(void);
636 641
637#ifdef _KERNEL 642#ifdef _KERNEL
638#include <lib/libkern/libkern.h> 643#include <lib/libkern/libkern.h>
639 644
640/* 645/*
641 * Stuff to handle debugger magic key sequences. 646 * Stuff to handle debugger magic key sequences.
642 */ 647 */
643#define CNS_LEN 128 648#define CNS_LEN 128
644#define CNS_MAGIC_VAL(x) ((x)&0x1ff) 649#define CNS_MAGIC_VAL(x) ((x)&0x1ff)
645#define CNS_MAGIC_NEXT(x) (((x)>>9)&0x7f) 650#define CNS_MAGIC_NEXT(x) (((x)>>9)&0x7f)
646#define CNS_TERM 0x7f /* End of sequence */ 651#define CNS_TERM 0x7f /* End of sequence */
647 652
648typedef struct cnm_state { 653typedef struct cnm_state {
649 int cnm_state; 654 int cnm_state;
650 u_short *cnm_magic; 655 u_short *cnm_magic;
651} cnm_state_t; 656} cnm_state_t;
652 657
653/* Override db_console() in MD headers */ 658/* Override db_console() in MD headers */
654#ifndef cn_trap 659#ifndef cn_trap
655#define cn_trap() console_debugger() 660#define cn_trap() console_debugger()
656#endif 661#endif
657#ifndef cn_isconsole 662#ifndef cn_isconsole
658#ifndef WSDISPLAY_MULTICONS 663#ifndef WSDISPLAY_MULTICONS
659#define cn_isconsole(d) (cn_tab != NULL && (d) == cn_tab->cn_dev) 664#define cn_isconsole(d) (cn_tab != NULL && (d) == cn_tab->cn_dev)
660#else 665#else
661bool wsdisplay_cn_isconsole(dev_t); 666bool wsdisplay_cn_isconsole(dev_t);
662#define cn_isconsole(d) wsdisplay_cn_isconsole(d) 667#define cn_isconsole(d) wsdisplay_cn_isconsole(d)
663#endif 668#endif
664#endif 669#endif
665 670
666void cn_init_magic(cnm_state_t *); 671void cn_init_magic(cnm_state_t *);
667void cn_destroy_magic(cnm_state_t *); 672void cn_destroy_magic(cnm_state_t *);
668int cn_set_magic(const char *); 673int cn_set_magic(const char *);
669int cn_get_magic(char *, size_t); 674int cn_get_magic(char *, size_t);
670/* This should be called for each byte read */ 675/* This should be called for each byte read */
671#ifndef cn_check_magic 676#ifndef cn_check_magic
672#define cn_check_magic(d, k, s) \ 677#define cn_check_magic(d, k, s) \
673 do { \ 678 do { \
674 if (cn_isconsole(d)) { \ 679 if (cn_isconsole(d)) { \
675 int _v = (s).cnm_magic[(s).cnm_state]; \ 680 int _v = (s).cnm_magic[(s).cnm_state]; \
676 if ((k) == CNS_MAGIC_VAL(_v)) { \ 681 if ((k) == CNS_MAGIC_VAL(_v)) { \
677 (s).cnm_state = CNS_MAGIC_NEXT(_v); \ 682 (s).cnm_state = CNS_MAGIC_NEXT(_v); \
678 if ((s).cnm_state == CNS_TERM) { \ 683 if ((s).cnm_state == CNS_TERM) { \
679 cn_trap(); \ 684 cn_trap(); \
680 (s).cnm_state = 0; \ 685 (s).cnm_state = 0; \
681 } \ 686 } \
682 } else { \ 687 } else { \
683 (s).cnm_state = 0; \ 688 (s).cnm_state = 0; \
684 } \ 689 } \
685 } \ 690 } \
686 } while (/* CONSTCOND */ 0) 691 } while (/* CONSTCOND */ 0)
687#endif 692#endif
688 693
689/* Encode out-of-band events this way when passing to cn_check_magic() */ 694/* Encode out-of-band events this way when passing to cn_check_magic() */
690#define CNC_BREAK 0x100 695#define CNC_BREAK 0x100
691 696
692#if defined(DDB) || defined(sun3) || defined(sun2) 697#if defined(DDB) || defined(sun3) || defined(sun2)
693/* note that cpu_Debugger() is always available on sun[23] */ 698/* note that cpu_Debugger() is always available on sun[23] */
694void cpu_Debugger(void); 699void cpu_Debugger(void);
695#define Debugger cpu_Debugger 700#define Debugger cpu_Debugger
696#endif 701#endif
697 702
698#ifdef DDB 703#ifdef DDB
699/* 704/*
700 * Enter debugger(s) from console attention if enabled 705 * Enter debugger(s) from console attention if enabled
701 */ 706 */
702extern int db_fromconsole; /* XXX ddb/ddbvar.h */ 707extern int db_fromconsole; /* XXX ddb/ddbvar.h */
703#define console_debugger() if (db_fromconsole) Debugger() 708#define console_debugger() if (db_fromconsole) Debugger()
704#elif defined(Debugger) 709#elif defined(Debugger)
705#define console_debugger() Debugger() 710#define console_debugger() Debugger()
706#else 711#else
707#define console_debugger() do {} while (/* CONSTCOND */ 0) /* NOP */ 712#define console_debugger() do {} while (/* CONSTCOND */ 0) /* NOP */
708#endif 713#endif
709 714
710/* For SYSCALL_DEBUG */ 715/* For SYSCALL_DEBUG */
711void scdebug_init(void); 716void scdebug_init(void);
712void scdebug_call(register_t, const register_t[]); 717void scdebug_call(register_t, const register_t[]);
713void scdebug_ret(register_t, int, const register_t[]); 718void scdebug_ret(register_t, int, const register_t[]);
714 719
715void kernel_lock_init(void); 720void kernel_lock_init(void);
716void _kernel_lock(int); 721void _kernel_lock(int);
717void _kernel_unlock(int, int *); 722void _kernel_unlock(int, int *);
718bool _kernel_locked_p(void); 723bool _kernel_locked_p(void);
719 724
720void kernconfig_lock_init(void); 725void kernconfig_lock_init(void);
721void kernconfig_lock(void); 726void kernconfig_lock(void);
722void kernconfig_unlock(void); 727void kernconfig_unlock(void);
723bool kernconfig_is_held(void); 728bool kernconfig_is_held(void);
724#endif 729#endif
725 730
726#if defined(MULTIPROCESSOR) || defined(_MODULE) 731#if defined(MULTIPROCESSOR) || defined(_MODULE)
727#define KERNEL_LOCK(count, lwp) \ 732#define KERNEL_LOCK(count, lwp) \
728do { \ 733do { \
729 if ((count) != 0) \ 734 if ((count) != 0) \
730 _kernel_lock((count)); \ 735 _kernel_lock((count)); \
731} while (/* CONSTCOND */ 0) 736} while (/* CONSTCOND */ 0)
732#define KERNEL_UNLOCK(all, lwp, p) _kernel_unlock((all), (p)) 737#define KERNEL_UNLOCK(all, lwp, p) _kernel_unlock((all), (p))
733#define KERNEL_LOCKED_P() _kernel_locked_p() 738#define KERNEL_LOCKED_P() _kernel_locked_p()
734#else 739#else
735#define KERNEL_LOCK(count, lwp) do {(void)(count); (void)(lwp);} while (/* CONSTCOND */ 0) /*NOP*/ 740#define KERNEL_LOCK(count, lwp) do {(void)(count); (void)(lwp);} while (/* CONSTCOND */ 0) /*NOP*/
736#define KERNEL_UNLOCK(all, lwp, ptr) do {(void)(all); (void)(lwp); (void)(ptr);} while (/* CONSTCOND */ 0) /*NOP*/ 741#define KERNEL_UNLOCK(all, lwp, ptr) do {(void)(all); (void)(lwp); (void)(ptr);} while (/* CONSTCOND */ 0) /*NOP*/
737#define KERNEL_LOCKED_P() (true) 742#define KERNEL_LOCKED_P() (true)
738#endif 743#endif
739 744
740#define KERNEL_UNLOCK_LAST(l) KERNEL_UNLOCK(-1, (l), NULL) 745#define KERNEL_UNLOCK_LAST(l) KERNEL_UNLOCK(-1, (l), NULL)
741#define KERNEL_UNLOCK_ALL(l, p) KERNEL_UNLOCK(0, (l), (p)) 746#define KERNEL_UNLOCK_ALL(l, p) KERNEL_UNLOCK(0, (l), (p))
742#define KERNEL_UNLOCK_ONE(l) KERNEL_UNLOCK(1, (l), NULL) 747#define KERNEL_UNLOCK_ONE(l) KERNEL_UNLOCK(1, (l), NULL)
743 748
744#ifdef _KERNEL 749#ifdef _KERNEL
745/* Preemption control. */ 750/* Preemption control. */
746void kpreempt_disable(void); 751void kpreempt_disable(void);
747void kpreempt_enable(void); 752void kpreempt_enable(void);
748bool kpreempt_disabled(void); 753bool kpreempt_disabled(void);
749 754
750vaddr_t calc_cache_size(vsize_t , int, int); 755vaddr_t calc_cache_size(vsize_t , int, int);
751#endif 756#endif
752 757
753void assert_sleepable(void); 758void assert_sleepable(void);
754#if defined(DEBUG) 759#if defined(DEBUG)
755#define ASSERT_SLEEPABLE() assert_sleepable() 760#define ASSERT_SLEEPABLE() assert_sleepable()
756#else /* defined(DEBUG) */ 761#else /* defined(DEBUG) */
757#define ASSERT_SLEEPABLE() do {} while (0) 762#define ASSERT_SLEEPABLE() do {} while (0)
758#endif /* defined(DEBUG) */ 763#endif /* defined(DEBUG) */
759 764
760 765
761#endif /* !_SYS_SYSTM_H_ */ 766#endif /* !_SYS_SYSTM_H_ */