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