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