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