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