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