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