| @@ -1,547 +1,544 @@ | | | @@ -1,547 +1,544 @@ |
1 | /* $NetBSD: libkern.h,v 1.139 2020/04/07 08:07:58 skrll Exp $ */ | | 1 | /* $NetBSD: libkern.h,v 1.140 2020/04/17 17:24:46 maxv Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1992, 1993 | | 4 | * Copyright (c) 1992, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the University nor the names of its contributors | | 15 | * 3. Neither the name of the University nor the names of its contributors |
16 | * may be used to endorse or promote products derived from this software | | 16 | * may be used to endorse or promote products derived from this software |
17 | * without specific prior written permission. | | 17 | * without specific prior written permission. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | * | | 30 | * |
31 | * @(#)libkern.h 8.2 (Berkeley) 8/5/94 | | 31 | * @(#)libkern.h 8.2 (Berkeley) 8/5/94 |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #ifndef _LIB_LIBKERN_LIBKERN_H_ | | 34 | #ifndef _LIB_LIBKERN_LIBKERN_H_ |
35 | #define _LIB_LIBKERN_LIBKERN_H_ | | 35 | #define _LIB_LIBKERN_LIBKERN_H_ |
36 | | | 36 | |
37 | #ifdef _KERNEL_OPT | | 37 | #ifdef _KERNEL_OPT |
38 | #include "opt_diagnostic.h" | | 38 | #include "opt_diagnostic.h" |
39 | #include "opt_kasan.h" | | 39 | #include "opt_kasan.h" |
40 | #include "opt_kcsan.h" | | 40 | #include "opt_kcsan.h" |
| | | 41 | #include "opt_kmsan.h" |
41 | #endif | | 42 | #endif |
42 | | | 43 | |
43 | #include <sys/types.h> | | 44 | #include <sys/types.h> |
44 | #include <sys/inttypes.h> | | 45 | #include <sys/inttypes.h> |
45 | #include <sys/null.h> | | 46 | #include <sys/null.h> |
46 | | | 47 | |
47 | #ifndef LIBKERN_INLINE | | 48 | #ifndef LIBKERN_INLINE |
48 | #define LIBKERN_INLINE static __inline | | 49 | #define LIBKERN_INLINE static __inline |
49 | #define LIBKERN_BODY | | 50 | #define LIBKERN_BODY |
50 | #endif | | 51 | #endif |
51 | | | 52 | |
52 | LIBKERN_INLINE int imax(int, int) __unused; | | 53 | LIBKERN_INLINE int imax(int, int) __unused; |
53 | LIBKERN_INLINE int imin(int, int) __unused; | | 54 | LIBKERN_INLINE int imin(int, int) __unused; |
54 | LIBKERN_INLINE u_int uimax(u_int, u_int) __unused; | | 55 | LIBKERN_INLINE u_int uimax(u_int, u_int) __unused; |
55 | LIBKERN_INLINE u_int uimin(u_int, u_int) __unused; | | 56 | LIBKERN_INLINE u_int uimin(u_int, u_int) __unused; |
56 | LIBKERN_INLINE long lmax(long, long) __unused; | | 57 | LIBKERN_INLINE long lmax(long, long) __unused; |
57 | LIBKERN_INLINE long lmin(long, long) __unused; | | 58 | LIBKERN_INLINE long lmin(long, long) __unused; |
58 | LIBKERN_INLINE u_long ulmax(u_long, u_long) __unused; | | 59 | LIBKERN_INLINE u_long ulmax(u_long, u_long) __unused; |
59 | LIBKERN_INLINE u_long ulmin(u_long, u_long) __unused; | | 60 | LIBKERN_INLINE u_long ulmin(u_long, u_long) __unused; |
60 | LIBKERN_INLINE int abs(int) __unused; | | 61 | LIBKERN_INLINE int abs(int) __unused; |
61 | LIBKERN_INLINE long labs(long) __unused; | | 62 | LIBKERN_INLINE long labs(long) __unused; |
62 | LIBKERN_INLINE long long llabs(long long) __unused; | | 63 | LIBKERN_INLINE long long llabs(long long) __unused; |
63 | LIBKERN_INLINE intmax_t imaxabs(intmax_t) __unused; | | 64 | LIBKERN_INLINE intmax_t imaxabs(intmax_t) __unused; |
64 | | | 65 | |
65 | LIBKERN_INLINE int isspace(int) __unused; | | 66 | LIBKERN_INLINE int isspace(int) __unused; |
66 | LIBKERN_INLINE int isascii(int) __unused; | | 67 | LIBKERN_INLINE int isascii(int) __unused; |
67 | LIBKERN_INLINE int isupper(int) __unused; | | 68 | LIBKERN_INLINE int isupper(int) __unused; |
68 | LIBKERN_INLINE int islower(int) __unused; | | 69 | LIBKERN_INLINE int islower(int) __unused; |
69 | LIBKERN_INLINE int isalpha(int) __unused; | | 70 | LIBKERN_INLINE int isalpha(int) __unused; |
70 | LIBKERN_INLINE int isalnum(int) __unused; | | 71 | LIBKERN_INLINE int isalnum(int) __unused; |
71 | LIBKERN_INLINE int isdigit(int) __unused; | | 72 | LIBKERN_INLINE int isdigit(int) __unused; |
72 | LIBKERN_INLINE int isxdigit(int) __unused; | | 73 | LIBKERN_INLINE int isxdigit(int) __unused; |
73 | LIBKERN_INLINE int iscntrl(int) __unused; | | 74 | LIBKERN_INLINE int iscntrl(int) __unused; |
74 | LIBKERN_INLINE int isgraph(int) __unused; | | 75 | LIBKERN_INLINE int isgraph(int) __unused; |
75 | LIBKERN_INLINE int isprint(int) __unused; | | 76 | LIBKERN_INLINE int isprint(int) __unused; |
76 | LIBKERN_INLINE int ispunct(int) __unused; | | 77 | LIBKERN_INLINE int ispunct(int) __unused; |
77 | LIBKERN_INLINE int toupper(int) __unused; | | 78 | LIBKERN_INLINE int toupper(int) __unused; |
78 | LIBKERN_INLINE int tolower(int) __unused; | | 79 | LIBKERN_INLINE int tolower(int) __unused; |
79 | | | 80 | |
80 | #ifdef LIBKERN_BODY | | 81 | #ifdef LIBKERN_BODY |
81 | LIBKERN_INLINE int | | 82 | LIBKERN_INLINE int |
82 | imax(int a, int b) | | 83 | imax(int a, int b) |
83 | { | | 84 | { |
84 | return (a > b ? a : b); | | 85 | return (a > b ? a : b); |
85 | } | | 86 | } |
86 | LIBKERN_INLINE int | | 87 | LIBKERN_INLINE int |
87 | imin(int a, int b) | | 88 | imin(int a, int b) |
88 | { | | 89 | { |
89 | return (a < b ? a : b); | | 90 | return (a < b ? a : b); |
90 | } | | 91 | } |
91 | LIBKERN_INLINE long | | 92 | LIBKERN_INLINE long |
92 | lmax(long a, long b) | | 93 | lmax(long a, long b) |
93 | { | | 94 | { |
94 | return (a > b ? a : b); | | 95 | return (a > b ? a : b); |
95 | } | | 96 | } |
96 | LIBKERN_INLINE long | | 97 | LIBKERN_INLINE long |
97 | lmin(long a, long b) | | 98 | lmin(long a, long b) |
98 | { | | 99 | { |
99 | return (a < b ? a : b); | | 100 | return (a < b ? a : b); |
100 | } | | 101 | } |
101 | LIBKERN_INLINE u_int | | 102 | LIBKERN_INLINE u_int |
102 | uimax(u_int a, u_int b) | | 103 | uimax(u_int a, u_int b) |
103 | { | | 104 | { |
104 | return (a > b ? a : b); | | 105 | return (a > b ? a : b); |
105 | } | | 106 | } |
106 | LIBKERN_INLINE u_int | | 107 | LIBKERN_INLINE u_int |
107 | uimin(u_int a, u_int b) | | 108 | uimin(u_int a, u_int b) |
108 | { | | 109 | { |
109 | return (a < b ? a : b); | | 110 | return (a < b ? a : b); |
110 | } | | 111 | } |
111 | LIBKERN_INLINE u_long | | 112 | LIBKERN_INLINE u_long |
112 | ulmax(u_long a, u_long b) | | 113 | ulmax(u_long a, u_long b) |
113 | { | | 114 | { |
114 | return (a > b ? a : b); | | 115 | return (a > b ? a : b); |
115 | } | | 116 | } |
116 | LIBKERN_INLINE u_long | | 117 | LIBKERN_INLINE u_long |
117 | ulmin(u_long a, u_long b) | | 118 | ulmin(u_long a, u_long b) |
118 | { | | 119 | { |
119 | return (a < b ? a : b); | | 120 | return (a < b ? a : b); |
120 | } | | 121 | } |
121 | | | 122 | |
122 | LIBKERN_INLINE int | | 123 | LIBKERN_INLINE int |
123 | abs(int j) | | 124 | abs(int j) |
124 | { | | 125 | { |
125 | return(j < 0 ? -j : j); | | 126 | return(j < 0 ? -j : j); |
126 | } | | 127 | } |
127 | | | 128 | |
128 | LIBKERN_INLINE long | | 129 | LIBKERN_INLINE long |
129 | labs(long j) | | 130 | labs(long j) |
130 | { | | 131 | { |
131 | return(j < 0 ? -j : j); | | 132 | return(j < 0 ? -j : j); |
132 | } | | 133 | } |
133 | | | 134 | |
134 | LIBKERN_INLINE long long | | 135 | LIBKERN_INLINE long long |
135 | llabs(long long j) | | 136 | llabs(long long j) |
136 | { | | 137 | { |
137 | return(j < 0 ? -j : j); | | 138 | return(j < 0 ? -j : j); |
138 | } | | 139 | } |
139 | | | 140 | |
140 | LIBKERN_INLINE intmax_t | | 141 | LIBKERN_INLINE intmax_t |
141 | imaxabs(intmax_t j) | | 142 | imaxabs(intmax_t j) |
142 | { | | 143 | { |
143 | return(j < 0 ? -j : j); | | 144 | return(j < 0 ? -j : j); |
144 | } | | 145 | } |
145 | | | 146 | |
146 | LIBKERN_INLINE int | | 147 | LIBKERN_INLINE int |
147 | isspace(int ch) | | 148 | isspace(int ch) |
148 | { | | 149 | { |
149 | return (ch == ' ' || (ch >= '\t' && ch <= '\r')); | | 150 | return (ch == ' ' || (ch >= '\t' && ch <= '\r')); |
150 | } | | 151 | } |
151 | | | 152 | |
152 | LIBKERN_INLINE int | | 153 | LIBKERN_INLINE int |
153 | isascii(int ch) | | 154 | isascii(int ch) |
154 | { | | 155 | { |
155 | return ((ch & ~0x7f) == 0); | | 156 | return ((ch & ~0x7f) == 0); |
156 | } | | 157 | } |
157 | | | 158 | |
158 | LIBKERN_INLINE int | | 159 | LIBKERN_INLINE int |
159 | isupper(int ch) | | 160 | isupper(int ch) |
160 | { | | 161 | { |
161 | return (ch >= 'A' && ch <= 'Z'); | | 162 | return (ch >= 'A' && ch <= 'Z'); |
162 | } | | 163 | } |
163 | | | 164 | |
164 | LIBKERN_INLINE int | | 165 | LIBKERN_INLINE int |
165 | islower(int ch) | | 166 | islower(int ch) |
166 | { | | 167 | { |
167 | return (ch >= 'a' && ch <= 'z'); | | 168 | return (ch >= 'a' && ch <= 'z'); |
168 | } | | 169 | } |
169 | | | 170 | |
170 | LIBKERN_INLINE int | | 171 | LIBKERN_INLINE int |
171 | isalpha(int ch) | | 172 | isalpha(int ch) |
172 | { | | 173 | { |
173 | return (isupper(ch) || islower(ch)); | | 174 | return (isupper(ch) || islower(ch)); |
174 | } | | 175 | } |
175 | | | 176 | |
176 | LIBKERN_INLINE int | | 177 | LIBKERN_INLINE int |
177 | isalnum(int ch) | | 178 | isalnum(int ch) |
178 | { | | 179 | { |
179 | return (isalpha(ch) || isdigit(ch)); | | 180 | return (isalpha(ch) || isdigit(ch)); |
180 | } | | 181 | } |
181 | | | 182 | |
182 | LIBKERN_INLINE int | | 183 | LIBKERN_INLINE int |
183 | isdigit(int ch) | | 184 | isdigit(int ch) |
184 | { | | 185 | { |
185 | return (ch >= '0' && ch <= '9'); | | 186 | return (ch >= '0' && ch <= '9'); |
186 | } | | 187 | } |
187 | | | 188 | |
188 | LIBKERN_INLINE int | | 189 | LIBKERN_INLINE int |
189 | isxdigit(int ch) | | 190 | isxdigit(int ch) |
190 | { | | 191 | { |
191 | return (isdigit(ch) || | | 192 | return (isdigit(ch) || |
192 | (ch >= 'A' && ch <= 'F') || | | 193 | (ch >= 'A' && ch <= 'F') || |
193 | (ch >= 'a' && ch <= 'f')); | | 194 | (ch >= 'a' && ch <= 'f')); |
194 | } | | 195 | } |
195 | | | 196 | |
196 | LIBKERN_INLINE int | | 197 | LIBKERN_INLINE int |
197 | iscntrl(int ch) | | 198 | iscntrl(int ch) |
198 | { | | 199 | { |
199 | return ((ch >= 0x00 && ch <= 0x1F) || ch == 0x7F); | | 200 | return ((ch >= 0x00 && ch <= 0x1F) || ch == 0x7F); |
200 | } | | 201 | } |
201 | | | 202 | |
202 | LIBKERN_INLINE int | | 203 | LIBKERN_INLINE int |
203 | isgraph(int ch) | | 204 | isgraph(int ch) |
204 | { | | 205 | { |
205 | return (ch != ' ' && isprint(ch)); | | 206 | return (ch != ' ' && isprint(ch)); |
206 | } | | 207 | } |
207 | | | 208 | |
208 | LIBKERN_INLINE int | | 209 | LIBKERN_INLINE int |
209 | isprint(int ch) | | 210 | isprint(int ch) |
210 | { | | 211 | { |
211 | return (ch >= 0x20 && ch <= 0x7E); | | 212 | return (ch >= 0x20 && ch <= 0x7E); |
212 | } | | 213 | } |
213 | | | 214 | |
214 | LIBKERN_INLINE int | | 215 | LIBKERN_INLINE int |
215 | ispunct(int ch) | | 216 | ispunct(int ch) |
216 | { | | 217 | { |
217 | return (isprint(ch) && ch != ' ' && !isalnum(ch)); | | 218 | return (isprint(ch) && ch != ' ' && !isalnum(ch)); |
218 | } | | 219 | } |
219 | | | 220 | |
220 | LIBKERN_INLINE int | | 221 | LIBKERN_INLINE int |
221 | toupper(int ch) | | 222 | toupper(int ch) |
222 | { | | 223 | { |
223 | if (islower(ch)) | | 224 | if (islower(ch)) |
224 | return (ch - 0x20); | | 225 | return (ch - 0x20); |
225 | return (ch); | | 226 | return (ch); |
226 | } | | 227 | } |
227 | | | 228 | |
228 | LIBKERN_INLINE int | | 229 | LIBKERN_INLINE int |
229 | tolower(int ch) | | 230 | tolower(int ch) |
230 | { | | 231 | { |
231 | if (isupper(ch)) | | 232 | if (isupper(ch)) |
232 | return (ch + 0x20); | | 233 | return (ch + 0x20); |
233 | return (ch); | | 234 | return (ch); |
234 | } | | 235 | } |
235 | #endif | | 236 | #endif |
236 | | | 237 | |
237 | #define __NULL_STMT do { } while (/* CONSTCOND */ 0) | | 238 | #define __NULL_STMT do { } while (/* CONSTCOND */ 0) |
238 | | | 239 | |
239 | #define __KASSERTSTR "kernel %sassertion \"%s\" failed: file \"%s\", line %d " | | 240 | #define __KASSERTSTR "kernel %sassertion \"%s\" failed: file \"%s\", line %d " |
240 | | | 241 | |
241 | #ifdef NDEBUG /* tradition! */ | | 242 | #ifdef NDEBUG /* tradition! */ |
242 | #define assert(e) ((void)0) | | 243 | #define assert(e) ((void)0) |
243 | #else | | 244 | #else |
244 | #define assert(e) (__predict_true((e)) ? (void)0 : \ | | 245 | #define assert(e) (__predict_true((e)) ? (void)0 : \ |
245 | kern_assert(__KASSERTSTR, "", #e, __FILE__, __LINE__)) | | 246 | kern_assert(__KASSERTSTR, "", #e, __FILE__, __LINE__)) |
246 | #endif | | 247 | #endif |
247 | | | 248 | |
248 | #ifdef __COVERITY__ | | 249 | #ifdef __COVERITY__ |
249 | #ifndef DIAGNOSTIC | | 250 | #ifndef DIAGNOSTIC |
250 | #define DIAGNOSTIC | | 251 | #define DIAGNOSTIC |
251 | #endif | | 252 | #endif |
252 | #endif | | 253 | #endif |
253 | | | 254 | |
254 | #ifndef CTASSERT | | 255 | #ifndef CTASSERT |
255 | #define CTASSERT(x) __CTASSERT(x) | | 256 | #define CTASSERT(x) __CTASSERT(x) |
256 | #endif | | 257 | #endif |
257 | #ifndef CTASSERT_SIGNED | | 258 | #ifndef CTASSERT_SIGNED |
258 | #define CTASSERT_SIGNED(x) __CTASSERT(((typeof(x))-1) < 0) | | 259 | #define CTASSERT_SIGNED(x) __CTASSERT(((typeof(x))-1) < 0) |
259 | #endif | | 260 | #endif |
260 | #ifndef CTASSERT_UNSIGNED | | 261 | #ifndef CTASSERT_UNSIGNED |
261 | #define CTASSERT_UNSIGNED(x) __CTASSERT(((typeof(x))-1) >= 0) | | 262 | #define CTASSERT_UNSIGNED(x) __CTASSERT(((typeof(x))-1) >= 0) |
262 | #endif | | 263 | #endif |
263 | | | 264 | |
264 | #ifndef DIAGNOSTIC | | 265 | #ifndef DIAGNOSTIC |
265 | #define _DIAGASSERT(a) (void)0 | | 266 | #define _DIAGASSERT(a) (void)0 |
266 | #ifdef lint | | 267 | #ifdef lint |
267 | #define KASSERTMSG(e, msg, ...) /* NOTHING */ | | 268 | #define KASSERTMSG(e, msg, ...) /* NOTHING */ |
268 | #define KASSERT(e) /* NOTHING */ | | 269 | #define KASSERT(e) /* NOTHING */ |
269 | #else /* !lint */ | | 270 | #else /* !lint */ |
270 | #define KASSERTMSG(e, msg, ...) ((void)0) | | 271 | #define KASSERTMSG(e, msg, ...) ((void)0) |
271 | #define KASSERT(e) ((void)0) | | 272 | #define KASSERT(e) ((void)0) |
272 | #endif /* !lint */ | | 273 | #endif /* !lint */ |
273 | #else /* DIAGNOSTIC */ | | 274 | #else /* DIAGNOSTIC */ |
274 | #define _DIAGASSERT(a) assert(a) | | 275 | #define _DIAGASSERT(a) assert(a) |
275 | #define KASSERTMSG(e, msg, ...) \ | | 276 | #define KASSERTMSG(e, msg, ...) \ |
276 | (__predict_true((e)) ? (void)0 : \ | | 277 | (__predict_true((e)) ? (void)0 : \ |
277 | kern_assert(__KASSERTSTR msg, "diagnostic ", #e, \ | | 278 | kern_assert(__KASSERTSTR msg, "diagnostic ", #e, \ |
278 | __FILE__, __LINE__, ## __VA_ARGS__)) | | 279 | __FILE__, __LINE__, ## __VA_ARGS__)) |
279 | | | 280 | |
280 | #define KASSERT(e) (__predict_true((e)) ? (void)0 : \ | | 281 | #define KASSERT(e) (__predict_true((e)) ? (void)0 : \ |
281 | kern_assert(__KASSERTSTR, "diagnostic ", #e, \ | | 282 | kern_assert(__KASSERTSTR, "diagnostic ", #e, \ |
282 | __FILE__, __LINE__)) | | 283 | __FILE__, __LINE__)) |
283 | #endif | | 284 | #endif |
284 | | | 285 | |
285 | #ifndef DEBUG | | 286 | #ifndef DEBUG |
286 | #ifdef lint | | 287 | #ifdef lint |
287 | #define KDASSERTMSG(e,msg, ...) /* NOTHING */ | | 288 | #define KDASSERTMSG(e,msg, ...) /* NOTHING */ |
288 | #define KDASSERT(e) /* NOTHING */ | | 289 | #define KDASSERT(e) /* NOTHING */ |
289 | #else /* lint */ | | 290 | #else /* lint */ |
290 | #define KDASSERTMSG(e,msg, ...) ((void)0) | | 291 | #define KDASSERTMSG(e,msg, ...) ((void)0) |
291 | #define KDASSERT(e) ((void)0) | | 292 | #define KDASSERT(e) ((void)0) |
292 | #endif /* lint */ | | 293 | #endif /* lint */ |
293 | #else | | 294 | #else |
294 | #define KDASSERTMSG(e, msg, ...) \ | | 295 | #define KDASSERTMSG(e, msg, ...) \ |
295 | (__predict_true((e)) ? (void)0 : \ | | 296 | (__predict_true((e)) ? (void)0 : \ |
296 | kern_assert(__KASSERTSTR msg, "debugging ", #e, \ | | 297 | kern_assert(__KASSERTSTR msg, "debugging ", #e, \ |
297 | __FILE__, __LINE__, ## __VA_ARGS__)) | | 298 | __FILE__, __LINE__, ## __VA_ARGS__)) |
298 | | | 299 | |
299 | #define KDASSERT(e) (__predict_true((e)) ? (void)0 : \ | | 300 | #define KDASSERT(e) (__predict_true((e)) ? (void)0 : \ |
300 | kern_assert(__KASSERTSTR, "debugging ", #e, \ | | 301 | kern_assert(__KASSERTSTR, "debugging ", #e, \ |
301 | __FILE__, __LINE__)) | | 302 | __FILE__, __LINE__)) |
302 | #endif | | 303 | #endif |
303 | | | 304 | |
304 | /* | | 305 | /* |
305 | * XXX: For compatibility we use SMALL_RANDOM by default. | | 306 | * XXX: For compatibility we use SMALL_RANDOM by default. |
306 | */ | | 307 | */ |
307 | #define SMALL_RANDOM | | 308 | #define SMALL_RANDOM |
308 | | | 309 | |
309 | #ifndef offsetof | | 310 | #ifndef offsetof |
310 | #if __GNUC_PREREQ__(4, 0) | | 311 | #if __GNUC_PREREQ__(4, 0) |
311 | #define offsetof(type, member) __builtin_offsetof(type, member) | | 312 | #define offsetof(type, member) __builtin_offsetof(type, member) |
312 | #else | | 313 | #else |
313 | #define offsetof(type, member) \ | | 314 | #define offsetof(type, member) \ |
314 | ((size_t)(unsigned long)(&(((type *)0)->member))) | | 315 | ((size_t)(unsigned long)(&(((type *)0)->member))) |
315 | #endif | | 316 | #endif |
316 | #endif | | 317 | #endif |
317 | | | 318 | |
318 | /* | | 319 | /* |
319 | * Return the container of an embedded struct. Given x = &c->f, | | 320 | * Return the container of an embedded struct. Given x = &c->f, |
320 | * container_of(x, T, f) yields c, where T is the type of c. Example: | | 321 | * container_of(x, T, f) yields c, where T is the type of c. Example: |
321 | * | | 322 | * |
322 | * struct foo { ... }; | | 323 | * struct foo { ... }; |
323 | * struct bar { | | 324 | * struct bar { |
324 | * int b_x; | | 325 | * int b_x; |
325 | * struct foo b_foo; | | 326 | * struct foo b_foo; |
326 | * ... | | 327 | * ... |
327 | * }; | | 328 | * }; |
328 | * | | 329 | * |
329 | * struct bar b; | | 330 | * struct bar b; |
330 | * struct foo *fp = b.b_foo; | | 331 | * struct foo *fp = b.b_foo; |
331 | * | | 332 | * |
332 | * Now we can get at b from fp by: | | 333 | * Now we can get at b from fp by: |
333 | * | | 334 | * |
334 | * struct bar *bp = container_of(fp, struct bar, b_foo); | | 335 | * struct bar *bp = container_of(fp, struct bar, b_foo); |
335 | * | | 336 | * |
336 | * The 0*sizeof((PTR) - ...) causes the compiler to warn if the type of | | 337 | * The 0*sizeof((PTR) - ...) causes the compiler to warn if the type of |
337 | * *fp does not match the type of struct bar::b_foo. | | 338 | * *fp does not match the type of struct bar::b_foo. |
338 | * We skip the validation for coverity runs to avoid warnings. | | 339 | * We skip the validation for coverity runs to avoid warnings. |
339 | */ | | 340 | */ |
340 | #if defined(__COVERITY__) || defined(__LGTM_BOT__) | | 341 | #if defined(__COVERITY__) || defined(__LGTM_BOT__) |
341 | #define __validate_container_of(PTR, TYPE, FIELD) 0 | | 342 | #define __validate_container_of(PTR, TYPE, FIELD) 0 |
342 | #define __validate_const_container_of(PTR, TYPE, FIELD) 0 | | 343 | #define __validate_const_container_of(PTR, TYPE, FIELD) 0 |
343 | #else | | 344 | #else |
344 | #define __validate_container_of(PTR, TYPE, FIELD) \ | | 345 | #define __validate_container_of(PTR, TYPE, FIELD) \ |
345 | (0 * sizeof((PTR) - &((TYPE *)(((char *)(PTR)) - \ | | 346 | (0 * sizeof((PTR) - &((TYPE *)(((char *)(PTR)) - \ |
346 | offsetof(TYPE, FIELD)))->FIELD)) | | 347 | offsetof(TYPE, FIELD)))->FIELD)) |
347 | #define __validate_const_container_of(PTR, TYPE, FIELD) \ | | 348 | #define __validate_const_container_of(PTR, TYPE, FIELD) \ |
348 | (0 * sizeof((PTR) - &((const TYPE *)(((const char *)(PTR)) - \ | | 349 | (0 * sizeof((PTR) - &((const TYPE *)(((const char *)(PTR)) - \ |
349 | offsetof(TYPE, FIELD)))->FIELD)) | | 350 | offsetof(TYPE, FIELD)))->FIELD)) |
350 | #endif | | 351 | #endif |
351 | | | 352 | |
352 | #define container_of(PTR, TYPE, FIELD) \ | | 353 | #define container_of(PTR, TYPE, FIELD) \ |
353 | ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD)) \ | | 354 | ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD)) \ |
354 | + __validate_container_of(PTR, TYPE, FIELD)) | | 355 | + __validate_container_of(PTR, TYPE, FIELD)) |
355 | #define const_container_of(PTR, TYPE, FIELD) \ | | 356 | #define const_container_of(PTR, TYPE, FIELD) \ |
356 | ((const TYPE *)(((const char *)(PTR)) - offsetof(TYPE, FIELD)) \ | | 357 | ((const TYPE *)(((const char *)(PTR)) - offsetof(TYPE, FIELD)) \ |
357 | + __validate_const_container_of(PTR, TYPE, FIELD)) | | 358 | + __validate_const_container_of(PTR, TYPE, FIELD)) |
358 | | | 359 | |
359 | /* Prototypes for which GCC built-ins exist. */ | | 360 | /* Prototypes for which GCC built-ins exist. */ |
360 | void *memcpy(void *, const void *, size_t); | | 361 | void *memcpy(void *, const void *, size_t); |
361 | int memcmp(const void *, const void *, size_t); | | 362 | int memcmp(const void *, const void *, size_t); |
362 | void *memset(void *, int, size_t); | | 363 | void *memset(void *, int, size_t); |
363 | void *memmem(const void *, size_t, const void *, size_t); | | | |
364 | #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) | | 364 | #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) |
365 | #if defined(_KERNEL) && defined(KASAN) | | 365 | #if defined(_KERNEL) && defined(KASAN) |
366 | void *kasan_memcpy(void *, const void *, size_t); | | 366 | void *kasan_memcpy(void *, const void *, size_t); |
367 | int kasan_memcmp(const void *, const void *, size_t); | | 367 | int kasan_memcmp(const void *, const void *, size_t); |
368 | void *kasan_memset(void *, int, size_t); | | 368 | void *kasan_memset(void *, int, size_t); |
369 | #define memcpy(d, s, l) kasan_memcpy(d, s, l) | | 369 | #define memcpy(d, s, l) kasan_memcpy(d, s, l) |
370 | #define memcmp(a, b, l) kasan_memcmp(a, b, l) | | 370 | #define memcmp(a, b, l) kasan_memcmp(a, b, l) |
371 | #define memset(d, v, l) kasan_memset(d, v, l) | | 371 | #define memset(d, v, l) kasan_memset(d, v, l) |
372 | #elif defined(_KERNEL) && defined(KCSAN) | | 372 | #elif defined(_KERNEL) && defined(KCSAN) |
373 | void *kcsan_memcpy(void *, const void *, size_t); | | 373 | void *kcsan_memcpy(void *, const void *, size_t); |
374 | int kcsan_memcmp(const void *, const void *, size_t); | | 374 | int kcsan_memcmp(const void *, const void *, size_t); |
375 | void *kcsan_memset(void *, int, size_t); | | 375 | void *kcsan_memset(void *, int, size_t); |
376 | #define memcpy(d, s, l) kcsan_memcpy(d, s, l) | | 376 | #define memcpy(d, s, l) kcsan_memcpy(d, s, l) |
377 | #define memcmp(a, b, l) kcsan_memcmp(a, b, l) | | 377 | #define memcmp(a, b, l) kcsan_memcmp(a, b, l) |
378 | #define memset(d, v, l) kcsan_memset(d, v, l) | | 378 | #define memset(d, v, l) kcsan_memset(d, v, l) |
379 | #elif defined(_KERNEL) && defined(KMSAN) | | 379 | #elif defined(_KERNEL) && defined(KMSAN) |
380 | void *kmsan_memcpy(void *, const void *, size_t); | | 380 | void *kmsan_memcpy(void *, const void *, size_t); |
381 | int kmsan_memcmp(const void *, const void *, size_t); | | 381 | int kmsan_memcmp(const void *, const void *, size_t); |
382 | void *kmsan_memset(void *, int, size_t); | | 382 | void *kmsan_memset(void *, int, size_t); |
383 | #define memcpy(d, s, l) kmsan_memcpy(d, s, l) | | 383 | #define memcpy(d, s, l) kmsan_memcpy(d, s, l) |
384 | #define memcmp(a, b, l) kmsan_memcmp(a, b, l) | | 384 | #define memcmp(a, b, l) kmsan_memcmp(a, b, l) |
385 | #define memset(d, v, l) kmsan_memset(d, v, l) | | 385 | #define memset(d, v, l) kmsan_memset(d, v, l) |
386 | #else | | 386 | #else |
387 | #define memcpy(d, s, l) __builtin_memcpy(d, s, l) | | 387 | #define memcpy(d, s, l) __builtin_memcpy(d, s, l) |
388 | #define memcmp(a, b, l) __builtin_memcmp(a, b, l) | | 388 | #define memcmp(a, b, l) __builtin_memcmp(a, b, l) |
389 | #define memset(d, v, l) __builtin_memset(d, v, l) | | 389 | #define memset(d, v, l) __builtin_memset(d, v, l) |
390 | #endif | | 390 | #endif |
391 | #endif | | 391 | #endif |
| | | 392 | void *memmem(const void *, size_t, const void *, size_t); |
392 | | | 393 | |
393 | char *strcpy(char *, const char *); | | 394 | char *strcpy(char *, const char *); |
394 | int strcmp(const char *, const char *); | | 395 | int strcmp(const char *, const char *); |
395 | size_t strlen(const char *); | | 396 | size_t strlen(const char *); |
396 | size_t strnlen(const char *, size_t); | | | |
397 | char *strsep(char **, const char *); | | | |
398 | #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) | | 397 | #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) |
399 | #if defined(_KERNEL) && defined(KASAN) | | 398 | #if defined(_KERNEL) && defined(KASAN) |
400 | char *kasan_strcpy(char *, const char *); | | 399 | char *kasan_strcpy(char *, const char *); |
401 | int kasan_strcmp(const char *, const char *); | | 400 | int kasan_strcmp(const char *, const char *); |
402 | size_t kasan_strlen(const char *); | | 401 | size_t kasan_strlen(const char *); |
403 | #define strcpy(d, s) kasan_strcpy(d, s) | | 402 | #define strcpy(d, s) kasan_strcpy(d, s) |
404 | #define strcmp(a, b) kasan_strcmp(a, b) | | 403 | #define strcmp(a, b) kasan_strcmp(a, b) |
405 | #define strlen(a) kasan_strlen(a) | | 404 | #define strlen(a) kasan_strlen(a) |
406 | #elif defined(_KERNEL) && defined(KCSAN) | | 405 | #elif defined(_KERNEL) && defined(KCSAN) |
407 | char *kcsan_strcpy(char *, const char *); | | 406 | char *kcsan_strcpy(char *, const char *); |
408 | int kcsan_strcmp(const char *, const char *); | | 407 | int kcsan_strcmp(const char *, const char *); |
409 | size_t kcsan_strlen(const char *); | | 408 | size_t kcsan_strlen(const char *); |
410 | #define strcpy(d, s) kcsan_strcpy(d, s) | | 409 | #define strcpy(d, s) kcsan_strcpy(d, s) |
411 | #define strcmp(a, b) kcsan_strcmp(a, b) | | 410 | #define strcmp(a, b) kcsan_strcmp(a, b) |
412 | #define strlen(a) kcsan_strlen(a) | | 411 | #define strlen(a) kcsan_strlen(a) |
413 | #elif defined(_KERNEL) && defined(KMSAN) | | 412 | #elif defined(_KERNEL) && defined(KMSAN) |
414 | char *kmsan_strcpy(char *, const char *); | | 413 | char *kmsan_strcpy(char *, const char *); |
415 | int kmsan_strcmp(const char *, const char *); | | 414 | int kmsan_strcmp(const char *, const char *); |
416 | size_t kmsan_strlen(const char *); | | 415 | size_t kmsan_strlen(const char *); |
417 | #define strcpy(d, s) kmsan_strcpy(d, s) | | 416 | #define strcpy(d, s) kmsan_strcpy(d, s) |
418 | #define strcmp(a, b) kmsan_strcmp(a, b) | | 417 | #define strcmp(a, b) kmsan_strcmp(a, b) |
419 | #define strlen(a) kmsan_strlen(a) | | 418 | #define strlen(a) kmsan_strlen(a) |
420 | #else | | 419 | #else |
421 | #define strcpy(d, s) __builtin_strcpy(d, s) | | 420 | #define strcpy(d, s) __builtin_strcpy(d, s) |
422 | #define strcmp(a, b) __builtin_strcmp(a, b) | | 421 | #define strcmp(a, b) __builtin_strcmp(a, b) |
423 | #define strlen(a) __builtin_strlen(a) | | 422 | #define strlen(a) __builtin_strlen(a) |
424 | #endif | | 423 | #endif |
425 | #endif | | 424 | #endif |
| | | 425 | size_t strnlen(const char *, size_t); |
| | | 426 | char *strsep(char **, const char *); |
426 | | | 427 | |
427 | /* Functions for which we always use built-ins. */ | | 428 | /* Functions for which we always use built-ins. */ |
428 | #ifdef __GNUC__ | | 429 | #ifdef __GNUC__ |
429 | #define alloca(s) __builtin_alloca(s) | | 430 | #define alloca(s) __builtin_alloca(s) |
430 | #endif | | 431 | #endif |
431 | | | 432 | |
| | | 433 | /* These exist in GCC 3.x, but we don't bother. */ |
432 | char *strcat(char *, const char *); | | 434 | char *strcat(char *, const char *); |
433 | char *strchr(const char *, int); | | 435 | char *strchr(const char *, int); |
434 | char *strrchr(const char *, int); | | 436 | char *strrchr(const char *, int); |
435 | /* These exist in GCC 3.x, but we don't bother. */ | | | |
436 | #if defined(_KERNEL) && defined(KASAN) | | 437 | #if defined(_KERNEL) && defined(KASAN) |
437 | char *kasan_strcat(char *, const char *); | | 438 | char *kasan_strcat(char *, const char *); |
438 | char *kasan_strchr(const char *, int); | | 439 | char *kasan_strchr(const char *, int); |
439 | char *kasan_strrchr(const char *, int); | | 440 | char *kasan_strrchr(const char *, int); |
440 | #define strcat(d, s) kasan_strcat(d, s) | | 441 | #define strcat(d, s) kasan_strcat(d, s) |
441 | #define strchr(s, c) kasan_strchr(s, c) | | 442 | #define strchr(s, c) kasan_strchr(s, c) |
442 | #define strrchr(s, c) kasan_strrchr(s, c) | | 443 | #define strrchr(s, c) kasan_strrchr(s, c) |
443 | #elif defined(_KERNEL) && defined(KMSAN) | | 444 | #elif defined(_KERNEL) && defined(KMSAN) |
444 | char *kmsan_strcat(char *, const char *); | | 445 | char *kmsan_strcat(char *, const char *); |
445 | char *kmsan_strchr(const char *, int); | | 446 | char *kmsan_strchr(const char *, int); |
446 | char *kmsan_strrchr(const char *, int); | | 447 | char *kmsan_strrchr(const char *, int); |
447 | #define strcat(d, s) kmsan_strcat(d, s) | | 448 | #define strcat(d, s) kmsan_strcat(d, s) |
448 | #define strchr(s, c) kmsan_strchr(s, c) | | 449 | #define strchr(s, c) kmsan_strchr(s, c) |
449 | #define strrchr(s, c) kmsan_strrchr(s, c) | | 450 | #define strrchr(s, c) kmsan_strrchr(s, c) |
450 | #else | | | |
451 | char *strcat(char *, const char *); | | | |
452 | char *strchr(const char *, int); | | | |
453 | char *strrchr(const char *, int); | | | |
454 | #endif | | 451 | #endif |
455 | size_t strcspn(const char *, const char *); | | 452 | size_t strcspn(const char *, const char *); |
456 | char *strncpy(char *, const char *, size_t); | | 453 | char *strncpy(char *, const char *, size_t); |
457 | char *strncat(char *, const char *, size_t); | | 454 | char *strncat(char *, const char *, size_t); |
458 | int strncmp(const char *, const char *, size_t); | | 455 | int strncmp(const char *, const char *, size_t); |
459 | char *strstr(const char *, const char *); | | 456 | char *strstr(const char *, const char *); |
460 | char *strpbrk(const char *, const char *); | | 457 | char *strpbrk(const char *, const char *); |
461 | size_t strspn(const char *, const char *); | | 458 | size_t strspn(const char *, const char *); |
462 | | | 459 | |
463 | /* | | 460 | /* |
464 | * ffs is an instruction on vax. | | 461 | * ffs is an instruction on vax. |
465 | */ | | 462 | */ |
466 | int ffs(int); | | 463 | int ffs(int); |
467 | #if __GNUC_PREREQ__(2, 95) && (!defined(__vax__) || __GNUC_PREREQ__(4,1)) | | 464 | #if __GNUC_PREREQ__(2, 95) && (!defined(__vax__) || __GNUC_PREREQ__(4,1)) |
468 | #define ffs(x) __builtin_ffs(x) | | 465 | #define ffs(x) __builtin_ffs(x) |
469 | #endif | | 466 | #endif |
470 | | | 467 | |
471 | void kern_assert(const char *, ...) | | 468 | void kern_assert(const char *, ...) |
472 | __attribute__((__format__(__printf__, 1, 2))); | | 469 | __attribute__((__format__(__printf__, 1, 2))); |
473 | u_int32_t | | 470 | u_int32_t |
474 | inet_addr(const char *); | | 471 | inet_addr(const char *); |
475 | struct in_addr; | | 472 | struct in_addr; |
476 | int inet_aton(const char *, struct in_addr *); | | 473 | int inet_aton(const char *, struct in_addr *); |
477 | char *intoa(u_int32_t); | | 474 | char *intoa(u_int32_t); |
478 | #define inet_ntoa(a) intoa((a).s_addr) | | 475 | #define inet_ntoa(a) intoa((a).s_addr) |
479 | void *memchr(const void *, int, size_t); | | 476 | void *memchr(const void *, int, size_t); |
480 | | | 477 | |
481 | void *memmove(void *, const void *, size_t); | | 478 | void *memmove(void *, const void *, size_t); |
482 | #if defined(_KERNEL) && defined(KASAN) | | 479 | #if defined(_KERNEL) && defined(KASAN) |
483 | void *kasan_memmove(void *, const void *, size_t); | | 480 | void *kasan_memmove(void *, const void *, size_t); |
484 | #define memmove(d, s, l) kasan_memmove(d, s, l) | | 481 | #define memmove(d, s, l) kasan_memmove(d, s, l) |
485 | #elif defined(_KERNEL) && defined(KCSAN) | | 482 | #elif defined(_KERNEL) && defined(KCSAN) |
486 | void *kcsan_memmove(void *, const void *, size_t); | | 483 | void *kcsan_memmove(void *, const void *, size_t); |
487 | #define memmove(d, s, l) kcsan_memmove(d, s, l) | | 484 | #define memmove(d, s, l) kcsan_memmove(d, s, l) |
488 | #elif defined(_KERNEL) && defined(KMSAN) | | 485 | #elif defined(_KERNEL) && defined(KMSAN) |
489 | void *kmsan_memmove(void *, const void *, size_t); | | 486 | void *kmsan_memmove(void *, const void *, size_t); |
490 | #define memmove(d, s, l) kmsan_memmove(d, s, l) | | 487 | #define memmove(d, s, l) kmsan_memmove(d, s, l) |
491 | #endif | | 488 | #endif |
492 | | | 489 | |
493 | int pmatch(const char *, const char *, const char **); | | 490 | int pmatch(const char *, const char *, const char **); |
494 | #ifndef SMALL_RANDOM | | 491 | #ifndef SMALL_RANDOM |
495 | void srandom(unsigned long); | | 492 | void srandom(unsigned long); |
496 | char *initstate(unsigned long, char *, size_t); | | 493 | char *initstate(unsigned long, char *, size_t); |
497 | char *setstate(char *); | | 494 | char *setstate(char *); |
498 | #endif /* SMALL_RANDOM */ | | 495 | #endif /* SMALL_RANDOM */ |
499 | long random(void); | | 496 | long random(void); |
500 | void mi_vector_hash(const void * __restrict, size_t, uint32_t, | | 497 | void mi_vector_hash(const void * __restrict, size_t, uint32_t, |
501 | uint32_t[3]); | | 498 | uint32_t[3]); |
502 | int scanc(u_int, const u_char *, const u_char *, int); | | 499 | int scanc(u_int, const u_char *, const u_char *, int); |
503 | int skpc(int, size_t, u_char *); | | 500 | int skpc(int, size_t, u_char *); |
504 | int strcasecmp(const char *, const char *); | | 501 | int strcasecmp(const char *, const char *); |
505 | size_t strlcpy(char *, const char *, size_t); | | 502 | size_t strlcpy(char *, const char *, size_t); |
506 | size_t strlcat(char *, const char *, size_t); | | 503 | size_t strlcat(char *, const char *, size_t); |
507 | int strncasecmp(const char *, const char *, size_t); | | 504 | int strncasecmp(const char *, const char *, size_t); |
508 | u_long strtoul(const char *, char **, int); | | 505 | u_long strtoul(const char *, char **, int); |
509 | long long strtoll(const char *, char **, int); | | 506 | long long strtoll(const char *, char **, int); |
510 | unsigned long long strtoull(const char *, char **, int); | | 507 | unsigned long long strtoull(const char *, char **, int); |
511 | intmax_t strtoimax(const char *, char **, int); | | 508 | intmax_t strtoimax(const char *, char **, int); |
512 | uintmax_t strtoumax(const char *, char **, int); | | 509 | uintmax_t strtoumax(const char *, char **, int); |
513 | intmax_t strtoi(const char * __restrict, char ** __restrict, int, intmax_t, | | 510 | intmax_t strtoi(const char * __restrict, char ** __restrict, int, intmax_t, |
514 | intmax_t, int *); | | 511 | intmax_t, int *); |
515 | uintmax_t strtou(const char * __restrict, char ** __restrict, int, uintmax_t, | | 512 | uintmax_t strtou(const char * __restrict, char ** __restrict, int, uintmax_t, |
516 | uintmax_t, int *); | | 513 | uintmax_t, int *); |
517 | void hexdump(void (*)(const char *, ...) __printflike(1, 2), | | 514 | void hexdump(void (*)(const char *, ...) __printflike(1, 2), |
518 | const char *, const void *, size_t); | | 515 | const char *, const void *, size_t); |
519 | | | 516 | |
520 | int snprintb(char *, size_t, const char *, uint64_t); | | 517 | int snprintb(char *, size_t, const char *, uint64_t); |
521 | int snprintb_m(char *, size_t, const char *, uint64_t, size_t); | | 518 | int snprintb_m(char *, size_t, const char *, uint64_t, size_t); |
522 | int kheapsort(void *, size_t, size_t, int (*)(const void *, const void *), | | 519 | int kheapsort(void *, size_t, size_t, int (*)(const void *, const void *), |
523 | void *); | | 520 | void *); |
524 | uint32_t crc32(uint32_t, const uint8_t *, size_t); | | 521 | uint32_t crc32(uint32_t, const uint8_t *, size_t); |
525 | #if __GNUC_PREREQ__(4, 5) \ | | 522 | #if __GNUC_PREREQ__(4, 5) \ |
526 | && (defined(__alpha_cix__) || defined(__mips_popcount)) | | 523 | && (defined(__alpha_cix__) || defined(__mips_popcount)) |
527 | #define popcount __builtin_popcount | | 524 | #define popcount __builtin_popcount |
528 | #define popcountl __builtin_popcountl | | 525 | #define popcountl __builtin_popcountl |
529 | #define popcountll __builtin_popcountll | | 526 | #define popcountll __builtin_popcountll |
530 | #define popcount32 __builtin_popcount | | 527 | #define popcount32 __builtin_popcount |
531 | #define popcount64 __builtin_popcountll | | 528 | #define popcount64 __builtin_popcountll |
532 | #else | | 529 | #else |
533 | unsigned int popcount(unsigned int) __constfunc; | | 530 | unsigned int popcount(unsigned int) __constfunc; |
534 | unsigned int popcountl(unsigned long) __constfunc; | | 531 | unsigned int popcountl(unsigned long) __constfunc; |
535 | unsigned int popcountll(unsigned long long) __constfunc; | | 532 | unsigned int popcountll(unsigned long long) __constfunc; |
536 | unsigned int popcount32(uint32_t) __constfunc; | | 533 | unsigned int popcount32(uint32_t) __constfunc; |
537 | unsigned int popcount64(uint64_t) __constfunc; | | 534 | unsigned int popcount64(uint64_t) __constfunc; |
538 | #endif | | 535 | #endif |
539 | | | 536 | |
540 | void *explicit_memset(void *, int, size_t); | | 537 | void *explicit_memset(void *, int, size_t); |
541 | int consttime_memequal(const void *, const void *, size_t); | | 538 | int consttime_memequal(const void *, const void *, size_t); |
542 | int strnvisx(char *, size_t, const char *, size_t, int); | | 539 | int strnvisx(char *, size_t, const char *, size_t, int); |
543 | #define VIS_OCTAL 0x01 | | 540 | #define VIS_OCTAL 0x01 |
544 | #define VIS_SAFE 0x20 | | 541 | #define VIS_SAFE 0x20 |
545 | #define VIS_TRIM 0x40 | | 542 | #define VIS_TRIM 0x40 |
546 | | | 543 | |
547 | #endif /* !_LIB_LIBKERN_LIBKERN_H_ */ | | 544 | #endif /* !_LIB_LIBKERN_LIBKERN_H_ */ |