source: rtems-libbsd/freebsd/sys/sys/systm.h

6-freebsd-12
Last change on this file was 6514d56, checked in by Chris Johns <chrisj@…>, on 08/02/21 at 05:09:41

sys/kern: Add VFS support

  • Refactor the libio interface
  • Move syscalls into an rtemsbsd location
  • Provide a root directory mount point

Update #4475

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