1 /*
2 * Copyright 2022, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _OBSD_COMPAT_SYS_SYSTM_H_
6 #define _OBSD_COMPAT_SYS_SYSTM_H_
7
8
9 #include_next <sys/systm.h>
10 #include <sys/kernel.h>
11
12 #include <int.h>
13
14
15 #define INFSLP UINT64_MAX
16
17
18 static inline void
explicit_bzero(void * buf,size_t len)19 explicit_bzero(void *buf, size_t len)
20 {
21 memset(buf, 0, len);
22 }
23
24
25 #define tsleep(identifier, priority, wmesg, timeout) \
26 msleep(identifier, &Giant, priority, wmesg, timeout)
27 #define tsleep_nsec(identifier, priority, wmesg, nsecs) \
28 tsleep(identifier, priority, wmesg, USEC_2_TICKS(nsecs / 1000))
29
30
31 #ifdef INVARIANTS
32 #define DIAGNOSTIC
33 #endif
34
35 #ifdef DIAGNOSTIC
36 #define KASSERT_OPENBSD(x) ASSERT_ALWAYS(x)
37 #define KASSERTMSG(x, format, args...) ASSERT_ALWAYS_PRINT(x, format, args)
38 #else
39 #define KASSERT_OPENBSD(x)
40 #define KASSERTMSG(x, format, args...)
41 #endif
42
43 #undef KASSERT
44 #define KASSERT KASSERT_OPENBSD
45
46
47 #define KERNEL_LOCK() mtx_lock(&Giant)
48 #define KERNEL_UNLOCK() mtx_unlock(&Giant)
49
50
51 /* #pragma mark - interrupts */
52
53 #define IPL_NONE 0
54 #define IPL_HIGH 1
55
56 #define IPL_NET IPL_NONE
57
58 #define IPL_MPSAFE 0x100
59
60 #define splsoft() splraise(IPL_SOFT)
61 #define splsoftclock() splraise(IPL_SOFTCLOCK)
62 #define splsoftnet() splraise(IPL_SOFTNET)
63 #define splsofttty() splraise(IPL_SOFTTTY)
64 #define splbio() splraise(IPL_BIO)
65 #define splnet() splraise(IPL_NET)
66 #define spltty() splraise(IPL_TTY)
67 #define splvm() splraise(IPL_VM)
68 #define splaudio() splraise(IPL_AUDIO)
69 #define splclock() splraise(IPL_CLOCK)
70 #define splsched() splraise(IPL_SCHED)
71 #define splstatclock() splraise(IPL_STATCLOCK)
72 #define splhigh() splraise(IPL_HIGH)
73
74
75 static inline int
splraise(int ipl)76 splraise(int ipl)
77 {
78 if (ipl == IPL_NONE)
79 return 0;
80 return disable_interrupts();
81 }
82
83
84 static inline void
splx(int ipl)85 splx(int ipl)
86 {
87 restore_interrupts(ipl);
88 }
89
90 static void
splassert(int ipl)91 splassert(int ipl)
92 {
93 const int ints = are_interrupts_enabled();
94 if (ints && ipl != IPL_NONE)
95 panic("splassert: interrupts enabled but should be disabled");
96 else if (!ints && ipl == IPL_NONE)
97 panic("splassert: interrupts disabled but should be enabled");
98 }
99
100
101 #endif /* _OBSD_COMPAT_SYS_SYSTM_H_ */
102