1/*-
  2 * SPDX-License-Identifier: BSD-3-Clause
  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#include <sys/types.h>
 43#include <sys/callout.h>
 44#include <sys/kassert.h>
 45#include <sys/queue.h>
 46#include <sys/stdint.h>		/* for people using printf mainly */
 47#include <machine/atomic.h>
 48#include <machine/cpufunc.h>
 49
 50__NULLABILITY_PRAGMA_PUSH
 51
 52#ifdef _KERNEL
 53extern int cold;		/* nonzero if we are doing a cold boot */
 54extern int suspend_blocked;	/* block suspend due to pending shutdown */
 55extern int rebooting;		/* kern_reboot() has been called. */
 56extern const char version[];	/* system version */
 57extern const char compiler_version[];	/* compiler version */
 58extern const char copyright[];	/* system copyright */
 59extern int kstack_pages;	/* number of kernel stack pages */
 60
 61extern u_long pagesizes[];	/* supported page sizes */
 62extern long physmem;		/* physical memory */
 63extern long realmem;		/* 'real' memory */
 64
 65extern char *rootdevnames[2];	/* names of possible root devices */
 66
 67extern int boothowto;		/* reboot flags, from console subsystem */
 68extern int bootverbose;		/* nonzero to print verbose messages */
 69
 70extern int maxusers;		/* system tune hint */
 71extern int ngroups_max;		/* max # of supplemental groups */
 72extern int vm_guest;		/* Running as virtual machine guest? */
 73
 74extern u_long maxphys;		/* max raw I/O transfer size */
 75
 76/*
 77 * Detected virtual machine guest types. The intention is to expand
 78 * and/or add to the VM_GUEST_VM type if specific VM functionality is
 79 * ever implemented (e.g. vendor-specific paravirtualization features).
 80 * Keep in sync with vm_guest_sysctl_names[].
 81 */
 82enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN, VM_GUEST_HV,
 83		VM_GUEST_VMWARE, VM_GUEST_KVM, VM_GUEST_BHYVE, VM_GUEST_VBOX,
 84		VM_GUEST_PARALLELS, VM_GUEST_NVMM, VM_LAST };
 85
 86#endif /* KERNEL */
 87
 88/*
 89 * Align variables.
 90 */
 91#define	__read_mostly		__section(".data.read_mostly")
 92#define	__read_frequently	__section(".data.read_frequently")
 93#define	__exclusive_cache_line	__aligned(CACHE_LINE_SIZE) \
 94				    __section(".data.exclusive_cache_line")
 95#if defined(_STANDALONE)
 96struct ucred;
 97#endif
 98
 99#ifdef _KERNEL
100#include <sys/param.h>		/* MAXCPU */
101#include <sys/pcpu.h>		/* curthread */
102#include <sys/kpilite.h>
103
104/*
105 * If we have already panic'd and this is the thread that called
106 * panic(), then don't block on any mutexes but silently succeed.
107 * Otherwise, the kernel will deadlock since the scheduler isn't
108 * going to run the thread that holds any lock we need.
109 */
110#define	SCHEDULER_STOPPED_TD(td)  ({					\
111	MPASS((td) == curthread);					\
112	__predict_false((td)->td_stopsched);				\
113})
114#define	SCHEDULER_STOPPED() SCHEDULER_STOPPED_TD(curthread)
115
116extern const int osreldate;
117
118extern const void *zero_region;	/* address space maps to a zeroed page	*/
119
120extern int unmapped_buf_allowed;
121
122#ifdef __LP64__
123#define	IOSIZE_MAX		iosize_max()
124#define	DEVFS_IOSIZE_MAX	devfs_iosize_max()
125#else
126#define	IOSIZE_MAX		SSIZE_MAX
127#define	DEVFS_IOSIZE_MAX	SSIZE_MAX
128#endif
129
130/*
131 * General function declarations.
132 */
133
134struct inpcb;
135struct lock_object;
136struct malloc_type;
137struct mtx;
138struct proc;
139struct socket;
140struct thread;
141struct tty;
142struct ucred;
143struct uio;
144struct _jmp_buf;
145struct trapframe;
146struct eventtimer;
147
148int	setjmp(struct _jmp_buf *) __returns_twice;
149void	longjmp(struct _jmp_buf *, int) __dead2;
150int	dumpstatus(vm_offset_t addr, off_t count);
151int	nullop(void);
152int	eopnotsupp(void);
153int	ureadc(int, struct uio *);
154void	hashdestroy(void *, struct malloc_type *, u_long);
155void	*hashinit(int count, struct malloc_type *type, u_long *hashmask);
156void	*hashinit_flags(int count, struct malloc_type *type,
157    u_long *hashmask, int flags);
158#define	HASH_NOWAIT	0x00000001
159#define	HASH_WAITOK	0x00000002
160
161void	*phashinit(int count, struct malloc_type *type, u_long *nentries);
162void	*phashinit_flags(int count, struct malloc_type *type, u_long *nentries,
163    int flags);
164
165void	cpu_flush_dcache(void *, size_t);
166void	cpu_rootconf(void);
167void	critical_enter_KBI(void);
168void	critical_exit_KBI(void);
169void	critical_exit_preempt(void);
170void	init_param1(void);
171void	init_param2(long physpages);
172void	init_static_kenv(char *, size_t);
173void	tablefull(const char *);
174
175/*
176 * Allocate per-thread "current" state in the linuxkpi
177 */
178extern int (*lkpi_alloc_current)(struct thread *, int);
179int linux_alloc_current_noop(struct thread *, int);
180
181#if (defined(KLD_MODULE) && !defined(KLD_TIED)) || defined(KTR_CRITICAL) || !defined(_KERNEL) || defined(GENOFFSET)
182#define critical_enter() critical_enter_KBI()
183#define critical_exit() critical_exit_KBI()
184#else
185static __inline void
186critical_enter(void)
187{
188	struct thread_lite *td;
189
190	td = (struct thread_lite *)curthread;
191	td->td_critnest++;
192	atomic_interrupt_fence();
193}
194
195static __inline void
196critical_exit(void)
197{
198	struct thread_lite *td;
199
200	td = (struct thread_lite *)curthread;
201	KASSERT(td->td_critnest != 0,
202	    ("critical_exit: td_critnest == 0"));
203	atomic_interrupt_fence();
204	td->td_critnest--;
205	atomic_interrupt_fence();
206	if (__predict_false(td->td_owepreempt))
207		critical_exit_preempt();
208
209}
210#endif
211
212#ifdef  EARLY_PRINTF
213typedef void early_putc_t(int ch);
214extern early_putc_t *early_putc;
215#endif
216int	kvprintf(char const *, void (*)(int, void*), void *, int,
217	    __va_list) __printflike(1, 0);
218void	log(int, const char *, ...) __printflike(2, 3);
219void	log_console(struct uio *);
220void	vlog(int, const char *, __va_list) __printflike(2, 0);
221int	asprintf(char **ret, struct malloc_type *mtp, const char *format, 
222	    ...) __printflike(3, 4);
223int	printf(const char *, ...) __printflike(1, 2);
224int	snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
225int	sprintf(char *buf, const char *, ...) __printflike(2, 3);
226int	uprintf(const char *, ...) __printflike(1, 2);
227int	vprintf(const char *, __va_list) __printflike(1, 0);
228int	vasprintf(char **ret, struct malloc_type *mtp, const char *format,
229	    __va_list ap) __printflike(3, 0);
230int	vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0);
231int	vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0);
232int	vsprintf(char *buf, const char *, __va_list) __printflike(2, 0);
233int	sscanf(const char *, char const * _Nonnull, ...) __scanflike(2, 3);
234int	vsscanf(const char * _Nonnull, char const * _Nonnull, __va_list)  __scanflike(2, 0);
235long	strtol(const char *, char **, int);
236u_long	strtoul(const char *, char **, int);
237quad_t	strtoq(const char *, char **, int);
238u_quad_t strtouq(const char *, char **, int);
239void	tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4);
240void	vtprintf(struct proc *, int, const char *, __va_list) __printflike(3, 0);
241void	hexdump(const void *ptr, int length, const char *hdr, int flags);
242#define	HD_COLUMN_MASK	0xff
243#define	HD_DELIM_MASK	0xff00
244#define	HD_OMIT_COUNT	(1 << 16)
245#define	HD_OMIT_HEX	(1 << 17)
246#define	HD_OMIT_CHARS	(1 << 18)
247
248#define ovbcopy(f, t, l) bcopy((f), (t), (l))
249void	explicit_bzero(void * _Nonnull, size_t);
250
251void	*memset(void * _Nonnull buf, int c, size_t len);
252void	*memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len);
253void	*memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);
254int	memcmp(const void *b1, const void *b2, size_t len);
255
256#ifdef SAN_NEEDS_INTERCEPTORS
257#define	SAN_INTERCEPTOR(func)	\
258	__CONCAT(SAN_INTERCEPTOR_PREFIX, __CONCAT(_, func))
259void	*SAN_INTERCEPTOR(memset)(void *, int, size_t);
260void	*SAN_INTERCEPTOR(memcpy)(void *, const void *, size_t);
261void	*SAN_INTERCEPTOR(memmove)(void *, const void *, size_t);
262int	SAN_INTERCEPTOR(memcmp)(const void *, const void *, size_t);
263#ifndef SAN_RUNTIME
264#define bcopy(from, to, len)	SAN_INTERCEPTOR(memmove)((to), (from), (len))
265#define bzero(buf, len)		SAN_INTERCEPTOR(memset)((buf), 0, (len))
266#define bcmp(b1, b2, len)	SAN_INTERCEPTOR(memcmp)((b1), (b2), (len))
267#define memset(buf, c, len)	SAN_INTERCEPTOR(memset)((buf), (c), (len))
268#define memcpy(to, from, len)	SAN_INTERCEPTOR(memcpy)((to), (from), (len))
269#define memmove(dest, src, n)	SAN_INTERCEPTOR(memmove)((dest), (src), (n))
270#define memcmp(b1, b2, len)	SAN_INTERCEPTOR(memcmp)((b1), (b2), (len))
271#endif /* !SAN_RUNTIME */
272#else /* !SAN_NEEDS_INTERCEPTORS */
273#define bcopy(from, to, len)	__builtin_memmove((to), (from), (len))
274#define bzero(buf, len)		__builtin_memset((buf), 0, (len))
275#define bcmp(b1, b2, len)	__builtin_memcmp((b1), (b2), (len))
276#define memset(buf, c, len)	__builtin_memset((buf), (c), (len))
277#define memcpy(to, from, len)	__builtin_memcpy((to), (from), (len))
278#define memmove(dest, src, n)	__builtin_memmove((dest), (src), (n))
279#define memcmp(b1, b2, len)	__builtin_memcmp((b1), (b2), (len))
280#endif /* SAN_NEEDS_INTERCEPTORS */
281
282void	*memset_early(void * _Nonnull buf, int c, size_t len);
283#define bzero_early(buf, len) memset_early((buf), 0, (len))
284void	*memcpy_early(void * _Nonnull to, const void * _Nonnull from, size_t len);
285void	*memmove_early(void * _Nonnull dest, const void * _Nonnull src, size_t n);
286#define bcopy_early(from, to, len) memmove_early((to), (from), (len))
287
288#define	copystr(src, dst, len, outlen)	({			\
289	size_t __r, __len, *__outlen;				\
290								\
291	__len = (len);						\
292	__outlen = (outlen);					\
293	__r = strlcpy((dst), (src), __len);			\
294	if (__outlen != NULL)					\
295		*__outlen = ((__r >= __len) ? __len : __r + 1);	\
296	((__r >= __len) ? ENAMETOOLONG : 0);			\
297})
298
299int	copyinstr(const void * __restrict udaddr,
300	    void * _Nonnull __restrict kaddr, size_t len,
301	    size_t * __restrict lencopied);
302int	copyin(const void * __restrict udaddr,
303	    void * _Nonnull __restrict kaddr, size_t len);
304int	copyin_nofault(const void * __restrict udaddr,
305	    void * _Nonnull __restrict kaddr, size_t len);
306int	copyout(const void * _Nonnull __restrict kaddr,
307	    void * __restrict udaddr, size_t len);
308int	copyout_nofault(const void * _Nonnull __restrict kaddr,
309	    void * __restrict udaddr, size_t len);
310
311#ifdef SAN_NEEDS_INTERCEPTORS
312int	SAN_INTERCEPTOR(copyin)(const void *, void *, size_t);
313int	SAN_INTERCEPTOR(copyinstr)(const void *, void *, size_t, size_t *);
314int	SAN_INTERCEPTOR(copyout)(const void *, void *, size_t);
315#ifndef SAN_RUNTIME
316#define	copyin(u, k, l)		SAN_INTERCEPTOR(copyin)((u), (k), (l))
317#define	copyinstr(u, k, l, lc)	SAN_INTERCEPTOR(copyinstr)((u), (k), (l), (lc))
318#define	copyout(k, u, l)	SAN_INTERCEPTOR(copyout)((k), (u), (l))
319#endif /* !SAN_RUNTIME */
320#endif /* SAN_NEEDS_INTERCEPTORS */
321
322int	fubyte(volatile const void *base);
323long	fuword(volatile const void *base);
324int	fuword16(volatile const void *base);
325int32_t	fuword32(volatile const void *base);
326int64_t	fuword64(volatile const void *base);
327int	fueword(volatile const void *base, long *val);
328int	fueword32(volatile const void *base, int32_t *val);
329int	fueword64(volatile const void *base, int64_t *val);
330int	subyte(volatile void *base, int byte);
331int	suword(volatile void *base, long word);
332int	suword16(volatile void *base, int word);
333int	suword32(volatile void *base, int32_t word);
334int	suword64(volatile void *base, int64_t word);
335uint32_t casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval);
336u_long	casuword(volatile u_long *p, u_long oldval, u_long newval);
337int	casueword32(volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp,
338	    uint32_t newval);
339int	casueword(volatile u_long *p, u_long oldval, u_long *oldvalp,
340	    u_long newval);
341
342#if defined(SAN_NEEDS_INTERCEPTORS) && !defined(KCSAN)
343int	SAN_INTERCEPTOR(fubyte)(volatile const void *base);
344int	SAN_INTERCEPTOR(fuword16)(volatile const void *base);
345int	SAN_INTERCEPTOR(fueword)(volatile const void *base, long *val);
346int	SAN_INTERCEPTOR(fueword32)(volatile const void *base, int32_t *val);
347int	SAN_INTERCEPTOR(fueword64)(volatile const void *base, int64_t *val);
348int	SAN_INTERCEPTOR(subyte)(volatile void *base, int byte);
349int	SAN_INTERCEPTOR(suword)(volatile void *base, long word);
350int	SAN_INTERCEPTOR(suword16)(volatile void *base, int word);
351int	SAN_INTERCEPTOR(suword32)(volatile void *base, int32_t word);
352int	SAN_INTERCEPTOR(suword64)(volatile void *base, int64_t word);
353int	SAN_INTERCEPTOR(casueword32)(volatile uint32_t *base, uint32_t oldval,
354	    uint32_t *oldvalp, uint32_t newval);
355int	SAN_INTERCEPTOR(casueword)(volatile u_long *p, u_long oldval,
356	    u_long *oldvalp, u_long newval);
357#ifndef SAN_RUNTIME
358#define	fubyte(b)		SAN_INTERCEPTOR(fubyte)((b))
359#define	fuword16(b)		SAN_INTERCEPTOR(fuword16)((b))
360#define	fueword(b, v)		SAN_INTERCEPTOR(fueword)((b), (v))
361#define	fueword32(b, v)		SAN_INTERCEPTOR(fueword32)((b), (v))
362#define	fueword64(b, v)		SAN_INTERCEPTOR(fueword64)((b), (v))
363#define	subyte(b, w)		SAN_INTERCEPTOR(subyte)((b), (w))
364#define	suword(b, w)		SAN_INTERCEPTOR(suword)((b), (w))
365#define	suword16(b, w)		SAN_INTERCEPTOR(suword16)((b), (w))
366#define	suword32(b, w)		SAN_INTERCEPTOR(suword32)((b), (w))
367#define	suword64(b, w)		SAN_INTERCEPTOR(suword64)((b), (w))
368#define	casueword32(b, o, p, n)	SAN_INTERCEPTOR(casueword32)((b), (o), (p), (n))
369#define	casueword(b, o, p, n)	SAN_INTERCEPTOR(casueword)((b), (o), (p), (n))
370#endif /* !SAN_RUNTIME */
371#endif /* SAN_NEEDS_INTERCEPTORS && !KCSAN */
372
373int	sysbeep(int hertz, sbintime_t duration);
374
375void	hardclock(int cnt, int usermode);
376void	hardclock_sync(int cpu);
377void	statclock(int cnt, int usermode);
378void	profclock(int cnt, int usermode, uintfptr_t pc);
379
380int	hardclockintr(void);
381
382void	startprofclock(struct proc *);
383void	stopprofclock(struct proc *);
384void	cpu_startprofclock(void);
385void	cpu_stopprofclock(void);
386void	suspendclock(void);
387void	resumeclock(void);
388sbintime_t 	cpu_idleclock(void);
389void	cpu_activeclock(void);
390void	cpu_new_callout(int cpu, sbintime_t bt, sbintime_t bt_opt);
391void	cpu_et_frequency(struct eventtimer *et, uint64_t newfreq);
392extern int	cpu_disable_c2_sleep;
393extern int	cpu_disable_c3_sleep;
394
395extern void	(*tcp_hpts_softclock)(void);
396extern volatile uint32_t __read_frequently hpts_that_need_softclock;
397
398#define	tcp_hpts_softclock()	do {					\
399		if (hpts_that_need_softclock > 0)			\
400			tcp_hpts_softclock();				\
401} while (0)
402
403char	*kern_getenv(const char *name);
404void	freeenv(char *env);
405int	getenv_int(const char *name, int *data);
406int	getenv_uint(const char *name, unsigned int *data);
407int	getenv_long(const char *name, long *data);
408int	getenv_ulong(const char *name, unsigned long *data);
409int	getenv_string(const char *name, char *data, int size);
410int	getenv_int64(const char *name, int64_t *data);
411int	getenv_uint64(const char *name, uint64_t *data);
412int	getenv_quad(const char *name, quad_t *data);
413int	getenv_bool(const char *name, bool *data);
414bool	getenv_is_true(const char *name);
415bool	getenv_is_false(const char *name);
416int	kern_setenv(const char *name, const char *value);
417int	kern_unsetenv(const char *name);
418int	testenv(const char *name);
419
420int	getenv_array(const char *name, void *data, int size, int *psize,
421    int type_size, bool allow_signed);
422#define	GETENV_UNSIGNED	false	/* negative numbers not allowed */
423#define	GETENV_SIGNED	true	/* negative numbers allowed */
424
425typedef uint64_t (cpu_tick_f)(void);
426void set_cputicker(cpu_tick_f *func, uint64_t freq, bool isvariable);
427extern cpu_tick_f *cpu_ticks;
428uint64_t cpu_tickrate(void);
429uint64_t cputick2usec(uint64_t tick);
430
431#include <sys/libkern.h>
432
433/* Initialize the world */
434void	consinit(void);
435void	cpu_initclocks(void);
436void	cpu_initclocks_bsp(void);
437void	cpu_initclocks_ap(void);
438void	usrinfoinit(void);
439
440/* Finalize the world */
441void	kern_reboot(int) __dead2;
442void	shutdown_nice(int);
443
444/* Stubs for obsolete functions that used to be for interrupt management */
445static __inline intrmask_t	splhigh(void)		{ return 0; }
446static __inline intrmask_t	splimp(void)		{ return 0; }
447static __inline intrmask_t	splnet(void)		{ return 0; }
448static __inline intrmask_t	spltty(void)		{ return 0; }
449static __inline void		splx(intrmask_t ipl __unused)	{ return; }
450
451/*
452 * Common `proc' functions are declared here so that proc.h can be included
453 * less often.
454 */
455int	_sleep(const void * _Nonnull chan, struct lock_object *lock, int pri,
456	   const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags);
457#define	msleep(chan, mtx, pri, wmesg, timo)				\
458	_sleep((chan), &(mtx)->lock_object, (pri), (wmesg),		\
459	    tick_sbt * (timo), 0, C_HARDCLOCK)
460#define	msleep_sbt(chan, mtx, pri, wmesg, bt, pr, flags)		\
461	_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (bt), (pr),	\
462	    (flags))
463int	msleep_spin_sbt(const void * _Nonnull chan, struct mtx *mtx,
464	    const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags);
465#define	msleep_spin(chan, mtx, wmesg, timo)				\
466	msleep_spin_sbt((chan), (mtx), (wmesg), tick_sbt * (timo),	\
467	    0, C_HARDCLOCK)
468int	pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_t pr,
469	    int flags);
470static __inline int
471pause(const char *wmesg, int timo)
472{
473	return (pause_sbt(wmesg, tick_sbt * timo, 0, C_HARDCLOCK));
474}
475#define	pause_sig(wmesg, timo)						\
476	pause_sbt((wmesg), tick_sbt * (timo), 0, C_HARDCLOCK | C_CATCH)
477#define	tsleep(chan, pri, wmesg, timo)					\
478	_sleep((chan), NULL, (pri), (wmesg), tick_sbt * (timo),		\
479	    0, C_HARDCLOCK)
480#define	tsleep_sbt(chan, pri, wmesg, bt, pr, flags)			\
481	_sleep((chan), NULL, (pri), (wmesg), (bt), (pr), (flags))
482void	wakeup(const void *chan);
483void	wakeup_one(const void *chan);
484void	wakeup_any(const void *chan);
485
486/*
487 * Common `struct cdev *' stuff are declared here to avoid #include poisoning
488 */
489
490struct cdev;
491dev_t dev2udev(struct cdev *x);
492const char *devtoname(struct cdev *cdev);
493
494#ifdef __LP64__
495size_t	devfs_iosize_max(void);
496size_t	iosize_max(void);
497#endif
498
499int poll_no_poll(int events);
500
501/* XXX: Should be void nanodelay(u_int nsec); */
502void	DELAY(int usec);
503
504int kcmp_cmp(uintptr_t a, uintptr_t b);
505
506/* Root mount holdback API */
507struct root_hold_token {
508	int				flags;
509	const char			*who;
510	TAILQ_ENTRY(root_hold_token)	list;
511};
512
513struct root_hold_token *root_mount_hold(const char *identifier);
514void root_mount_hold_token(const char *identifier, struct root_hold_token *h);
515void root_mount_rel(struct root_hold_token *h);
516int root_mounted(void);
517
518/*
519 * Unit number allocation API. (kern/subr_unit.c)
520 */
521struct unrhdr;
522#define	UNR_NO_MTX	((void *)(uintptr_t)-1)
523struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex);
524void init_unrhdr(struct unrhdr *uh, int low, int high, struct mtx *mutex);
525void delete_unrhdr(struct unrhdr *uh);
526void clear_unrhdr(struct unrhdr *uh);
527void clean_unrhdr(struct unrhdr *uh);
528void clean_unrhdrl(struct unrhdr *uh);
529int alloc_unr(struct unrhdr *uh);
530int alloc_unr_specific(struct unrhdr *uh, u_int item);
531int alloc_unrl(struct unrhdr *uh);
532void free_unr(struct unrhdr *uh, u_int item);
533void *create_iter_unr(struct unrhdr *uh);
534int next_iter_unr(void *handle);
535void free_iter_unr(void *handle);
536
537struct unrhdr64 {
538        uint64_t	counter;
539};
540
541static __inline void
542new_unrhdr64(struct unrhdr64 *unr64, uint64_t low)
543{
544
545	unr64->counter = low;
546}
547
548static __inline uint64_t
549alloc_unr64(struct unrhdr64 *unr64)
550{
551
552	return (atomic_fetchadd_64(&unr64->counter, 1));
553}
554
555void	intr_prof_stack_use(struct thread *td, struct trapframe *frame);
556
557void counted_warning(unsigned *counter, const char *msg);
558
559/*
560 * APIs to manage deprecation and obsolescence.
561 */
562void _gone_in(int major, const char *msg);
563void _gone_in_dev(device_t dev, int major, const char *msg);
564#ifdef NO_OBSOLETE_CODE
565#define __gone_ok(m, msg)					 \
566	_Static_assert(m < P_OSREL_MAJOR(__FreeBSD_version)),	 \
567	    "Obsolete code: " msg);
568#else
569#define	__gone_ok(m, msg)
570#endif
571#define gone_in(major, msg)		__gone_ok(major, msg) _gone_in(major, msg)
572#define gone_in_dev(dev, major, msg)	__gone_ok(major, msg) _gone_in_dev(dev, major, msg)
573
574#ifdef INVARIANTS
575#define	__diagused
576#else
577#define	__diagused	__unused
578#endif
579
580#ifdef WITNESS
581#define	__witness_used
582#else
583#define	__witness_used	__unused
584#endif
585
586#endif /* _KERNEL */
587
588__NULLABILITY_PRAGMA_POP
589#endif /* !_SYS_SYSTM_H_ */