]>
Commit | Line | Data |
---|---|---|
9fb26641 | 1 | |
04509ad9 EH |
2 | /* Common header file that is included by all of QEMU. |
3 | * | |
4 | * This file is supposed to be included only by .c files. No header file should | |
5 | * depend on qemu-common.h, as this would easily lead to circular header | |
6 | * dependencies. | |
7 | * | |
8 | * If a header file uses a definition from qemu-common.h, that definition | |
9 | * must be moved to a separate header file, and the header that uses it | |
10 | * must include that header. | |
11 | */ | |
faf07963 PB |
12 | #ifndef QEMU_COMMON_H |
13 | #define QEMU_COMMON_H | |
14 | ||
5c026320 | 15 | #include "compiler.h" |
beb6f0de KW |
16 | #include "config-host.h" |
17 | ||
332ae28d PB |
18 | #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__) |
19 | #define WORDS_ALIGNED | |
20 | #endif | |
21 | ||
082b5557 | 22 | #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) |
24ebf5f3 | 23 | |
29e922b6 BS |
24 | typedef struct QEMUTimer QEMUTimer; |
25 | typedef struct QEMUFile QEMUFile; | |
f627aab1 | 26 | typedef struct QEMUBH QEMUBH; |
92a16d7a | 27 | typedef struct DeviceState DeviceState; |
29e922b6 | 28 | |
316378e4 JK |
29 | struct Monitor; |
30 | typedef struct Monitor Monitor; | |
6607ae23 | 31 | typedef struct MigrationParams MigrationParams; |
316378e4 | 32 | |
faf07963 PB |
33 | /* we put basic includes here to avoid repeating them in device drivers */ |
34 | #include <stdlib.h> | |
35 | #include <stdio.h> | |
36 | #include <stdarg.h> | |
11165820 | 37 | #include <stdbool.h> |
faf07963 | 38 | #include <string.h> |
c8906845 | 39 | #include <strings.h> |
faf07963 PB |
40 | #include <inttypes.h> |
41 | #include <limits.h> | |
42 | #include <time.h> | |
43 | #include <ctype.h> | |
44 | #include <errno.h> | |
45 | #include <unistd.h> | |
46 | #include <fcntl.h> | |
47 | #include <sys/stat.h> | |
dcfd0865 | 48 | #include <sys/time.h> |
55616505 | 49 | #include <assert.h> |
86f69a92 | 50 | #include <signal.h> |
14015304 | 51 | #include <glib.h> |
faf07963 | 52 | |
082b5557 BS |
53 | #ifdef _WIN32 |
54 | #include "qemu-os-win32.h" | |
55 | #endif | |
56 | ||
57 | #ifdef CONFIG_POSIX | |
58 | #include "qemu-os-posix.h" | |
59 | #endif | |
60 | ||
faf07963 PB |
61 | #ifndef O_LARGEFILE |
62 | #define O_LARGEFILE 0 | |
63 | #endif | |
64 | #ifndef O_BINARY | |
65 | #define O_BINARY 0 | |
66 | #endif | |
0e74e66b JQ |
67 | #ifndef MAP_ANONYMOUS |
68 | #define MAP_ANONYMOUS MAP_ANON | |
69 | #endif | |
faf07963 PB |
70 | #ifndef ENOMEDIUM |
71 | #define ENOMEDIUM ENODEV | |
72 | #endif | |
4c955388 | 73 | #if !defined(ENOTSUP) |
2880bc32 JQ |
74 | #define ENOTSUP 4096 |
75 | #endif | |
2084a8e3 PB |
76 | #if !defined(ECANCELED) |
77 | #define ECANCELED 4097 | |
78 | #endif | |
3c9405a0 GH |
79 | #ifndef TIME_MAX |
80 | #define TIME_MAX LONG_MAX | |
81 | #endif | |
faf07963 | 82 | |
c0fd260e SW |
83 | /* HOST_LONG_BITS is the size of a native pointer in bits. */ |
84 | #if UINTPTR_MAX == UINT32_MAX | |
85 | # define HOST_LONG_BITS 32 | |
86 | #elif UINTPTR_MAX == UINT64_MAX | |
87 | # define HOST_LONG_BITS 64 | |
88 | #else | |
89 | # error Unknown pointer size | |
90 | #endif | |
91 | ||
6114fdb0 JQ |
92 | #ifndef CONFIG_IOVEC |
93 | #define CONFIG_IOVEC | |
bf9298b9 AL |
94 | struct iovec { |
95 | void *iov_base; | |
96 | size_t iov_len; | |
97 | }; | |
e2a305fb CH |
98 | /* |
99 | * Use the same value as Linux for now. | |
100 | */ | |
101 | #define IOV_MAX 1024 | |
331dadde BS |
102 | #else |
103 | #include <sys/uio.h> | |
bf9298b9 AL |
104 | #endif |
105 | ||
f868445a SW |
106 | typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) |
107 | GCC_FMT_ATTR(2, 3); | |
108 | ||
faf07963 | 109 | #ifdef _WIN32 |
faf07963 | 110 | #define fsync _commit |
371c6489 SW |
111 | #if !defined(lseek) |
112 | # define lseek _lseeki64 | |
113 | #endif | |
64b85a8f | 114 | int qemu_ftruncate64(int, int64_t); |
371c6489 SW |
115 | #if !defined(ftruncate) |
116 | # define ftruncate qemu_ftruncate64 | |
117 | #endif | |
faf07963 | 118 | |
faf07963 PB |
119 | static inline char *realpath(const char *path, char *resolved_path) |
120 | { | |
121 | _fullpath(resolved_path, path, _MAX_PATH); | |
122 | return resolved_path; | |
123 | } | |
faf07963 PB |
124 | #endif |
125 | ||
946fb27c PB |
126 | /* icount */ |
127 | void configure_icount(const char *option); | |
128 | extern int use_icount; | |
129 | ||
faf07963 PB |
130 | /* FIXME: Remove NEED_CPU_H. */ |
131 | #ifndef NEED_CPU_H | |
132 | ||
faf07963 PB |
133 | #include "osdep.h" |
134 | #include "bswap.h" | |
135 | ||
136 | #else | |
137 | ||
138 | #include "cpu.h" | |
139 | ||
140 | #endif /* !defined(NEED_CPU_H) */ | |
141 | ||
3bbbee18 AF |
142 | /* main function, renamed */ |
143 | #if defined(CONFIG_COCOA) | |
144 | int qemu_main(int argc, char **argv, char **envp); | |
145 | #endif | |
146 | ||
f6503059 AZ |
147 | void qemu_get_timedate(struct tm *tm, int offset); |
148 | int qemu_timedate_diff(struct tm *tm); | |
149 | ||
c8057f95 PM |
150 | /** |
151 | * is_help_option: | |
152 | * @s: string to test | |
153 | * | |
154 | * Check whether @s is one of the standard strings which indicate | |
155 | * that the user is asking for a list of the valid values for a | |
156 | * command option like -cpu or -M. The current accepted strings | |
157 | * are 'help' and '?'. '?' is deprecated (it is a shell wildcard | |
158 | * which makes it annoying to use in a reliable way) but provided | |
159 | * for backwards compatibility. | |
160 | * | |
161 | * Returns: true if @s is a request for a list. | |
162 | */ | |
163 | static inline bool is_help_option(const char *s) | |
164 | { | |
165 | return !strcmp(s, "?") || !strcmp(s, "help"); | |
166 | } | |
167 | ||
faf07963 PB |
168 | /* cutils.c */ |
169 | void pstrcpy(char *buf, int buf_size, const char *str); | |
2a025ae4 | 170 | void strpadcpy(char *buf, int buf_size, const char *str, char pad); |
faf07963 PB |
171 | char *pstrcat(char *buf, int buf_size, const char *s); |
172 | int strstart(const char *str, const char *val, const char **ptr); | |
173 | int stristart(const char *str, const char *val, const char **ptr); | |
d43277c5 | 174 | int qemu_strnlen(const char *s, int max_len); |
faf07963 | 175 | time_t mktimegm(struct tm *tm); |
ad46db9a | 176 | int qemu_fls(int i); |
6f1953c4 | 177 | int qemu_fdatasync(int fd); |
db1a4972 | 178 | int fcntl_setfl(int fd, int flag); |
443916d1 | 179 | int qemu_parse_fd(const char *param); |
d8427002 | 180 | |
d7142456 JS |
181 | /* |
182 | * strtosz() suffixes used to specify the default treatment of an | |
183 | * argument passed to strtosz() without an explicit suffix. | |
184 | * These should be defined using upper case characters in the range | |
185 | * A-Z, as strtosz() will use qemu_toupper() on the given argument | |
186 | * prior to comparison. | |
187 | */ | |
d8427002 JS |
188 | #define STRTOSZ_DEFSUFFIX_TB 'T' |
189 | #define STRTOSZ_DEFSUFFIX_GB 'G' | |
190 | #define STRTOSZ_DEFSUFFIX_MB 'M' | |
191 | #define STRTOSZ_DEFSUFFIX_KB 'K' | |
192 | #define STRTOSZ_DEFSUFFIX_B 'B' | |
70b4f4bb JS |
193 | int64_t strtosz(const char *nptr, char **end); |
194 | int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix); | |
a732e1ba JR |
195 | int64_t strtosz_suffix_unit(const char *nptr, char **end, |
196 | const char default_suffix, int64_t unit); | |
faf07963 | 197 | |
37022086 BS |
198 | /* path.c */ |
199 | void init_paths(const char *prefix); | |
200 | const char *path(const char *pathname); | |
201 | ||
cd390083 BS |
202 | #define qemu_isalnum(c) isalnum((unsigned char)(c)) |
203 | #define qemu_isalpha(c) isalpha((unsigned char)(c)) | |
204 | #define qemu_iscntrl(c) iscntrl((unsigned char)(c)) | |
205 | #define qemu_isdigit(c) isdigit((unsigned char)(c)) | |
206 | #define qemu_isgraph(c) isgraph((unsigned char)(c)) | |
207 | #define qemu_islower(c) islower((unsigned char)(c)) | |
208 | #define qemu_isprint(c) isprint((unsigned char)(c)) | |
209 | #define qemu_ispunct(c) ispunct((unsigned char)(c)) | |
210 | #define qemu_isspace(c) isspace((unsigned char)(c)) | |
211 | #define qemu_isupper(c) isupper((unsigned char)(c)) | |
212 | #define qemu_isxdigit(c) isxdigit((unsigned char)(c)) | |
213 | #define qemu_tolower(c) tolower((unsigned char)(c)) | |
214 | #define qemu_toupper(c) toupper((unsigned char)(c)) | |
215 | #define qemu_isascii(c) isascii((unsigned char)(c)) | |
216 | #define qemu_toascii(c) toascii((unsigned char)(c)) | |
217 | ||
b152aa84 | 218 | void *qemu_oom_check(void *ptr); |
ca10f867 | 219 | |
7c7c0629 JQ |
220 | ssize_t qemu_write_full(int fd, const void *buf, size_t count) |
221 | QEMU_WARN_UNUSED_RESULT; | |
993295fe PB |
222 | ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags) |
223 | QEMU_WARN_UNUSED_RESULT; | |
8c5135f9 | 224 | ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags) |
993295fe | 225 | QEMU_WARN_UNUSED_RESULT; |
40ff6d7e KW |
226 | |
227 | #ifndef _WIN32 | |
228 | int qemu_pipe(int pipefd[2]); | |
229 | #endif | |
230 | ||
00aa0040 | 231 | #ifdef _WIN32 |
58455eb9 SW |
232 | /* MinGW needs type casts for the 'buf' and 'optval' arguments. */ |
233 | #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \ | |
234 | getsockopt(sockfd, level, optname, (void *)optval, optlen) | |
235 | #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \ | |
236 | setsockopt(sockfd, level, optname, (const void *)optval, optlen) | |
00aa0040 | 237 | #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags) |
73062dfe SW |
238 | #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \ |
239 | sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen) | |
00aa0040 | 240 | #else |
58455eb9 SW |
241 | #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \ |
242 | getsockopt(sockfd, level, optname, optval, optlen) | |
243 | #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \ | |
244 | setsockopt(sockfd, level, optname, optval, optlen) | |
00aa0040 | 245 | #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags) |
73062dfe SW |
246 | #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \ |
247 | sendto(sockfd, buf, len, flags, destaddr, addrlen) | |
00aa0040 BS |
248 | #endif |
249 | ||
87ecb68b PB |
250 | /* Error handling. */ |
251 | ||
e5924d89 | 252 | void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2); |
87ecb68b | 253 | |
87ecb68b PB |
254 | struct ParallelIOArg { |
255 | void *buffer; | |
256 | int count; | |
257 | }; | |
258 | ||
259 | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); | |
260 | ||
261 | /* A load of opaque types so that device init declarations don't have to | |
262 | pull in all the real definitions. */ | |
263 | typedef struct NICInfo NICInfo; | |
1ae26a18 | 264 | typedef struct HCIInfo HCIInfo; |
87ecb68b PB |
265 | typedef struct AudioState AudioState; |
266 | typedef struct BlockDriverState BlockDriverState; | |
2446333c | 267 | typedef struct DriveInfo DriveInfo; |
87ecb68b | 268 | typedef struct DisplayState DisplayState; |
7d957bd8 AL |
269 | typedef struct DisplayChangeListener DisplayChangeListener; |
270 | typedef struct DisplaySurface DisplaySurface; | |
271 | typedef struct PixelFormat PixelFormat; | |
76ffb0b4 | 272 | typedef struct QemuConsole QemuConsole; |
87ecb68b | 273 | typedef struct CharDriverState CharDriverState; |
76d32cba | 274 | typedef struct MACAddr MACAddr; |
4e68f7a0 | 275 | typedef struct NetClientState NetClientState; |
87ecb68b | 276 | typedef struct i2c_bus i2c_bus; |
48a18b3c | 277 | typedef struct ISABus ISABus; |
dfc65f1f | 278 | typedef struct ISADevice ISADevice; |
87ecb68b | 279 | typedef struct SMBusDevice SMBusDevice; |
fb47a2e9 IY |
280 | typedef struct PCIHostState PCIHostState; |
281 | typedef struct PCIExpressHost PCIExpressHost; | |
87ecb68b PB |
282 | typedef struct PCIBus PCIBus; |
283 | typedef struct PCIDevice PCIDevice; | |
0428527c | 284 | typedef struct PCIExpressDevice PCIExpressDevice; |
68f79994 | 285 | typedef struct PCIBridge PCIBridge; |
34e65944 IY |
286 | typedef struct PCIEAERMsg PCIEAERMsg; |
287 | typedef struct PCIEAERLog PCIEAERLog; | |
288 | typedef struct PCIEAERErr PCIEAERErr; | |
bc20ba98 IY |
289 | typedef struct PCIEPort PCIEPort; |
290 | typedef struct PCIESlot PCIESlot; | |
14de9bab | 291 | typedef struct MSIMessage MSIMessage; |
87ecb68b | 292 | typedef struct SerialState SerialState; |
bc24a225 PB |
293 | typedef struct PCMCIACardState PCMCIACardState; |
294 | typedef struct MouseTransformInfo MouseTransformInfo; | |
295 | typedef struct uWireSlave uWireSlave; | |
296 | typedef struct I2SCodec I2SCodec; | |
90d37239 | 297 | typedef struct SSIBus SSIBus; |
2292b339 | 298 | typedef struct EventNotifier EventNotifier; |
2be24aaa | 299 | typedef struct VirtIODevice VirtIODevice; |
d35bf9ad | 300 | typedef struct QEMUSGList QEMUSGList; |
1dc324d2 | 301 | typedef struct SHPCDevice SHPCDevice; |
87ecb68b | 302 | |
186993ee MT |
303 | typedef uint64_t pcibus_t; |
304 | ||
4e4fa398 JK |
305 | typedef enum LostTickPolicy { |
306 | LOST_TICK_DISCARD, | |
307 | LOST_TICK_DELAY, | |
308 | LOST_TICK_MERGE, | |
309 | LOST_TICK_SLEW, | |
1ce05125 | 310 | LOST_TICK_MAX |
4e4fa398 JK |
311 | } LostTickPolicy; |
312 | ||
679042f0 AP |
313 | typedef struct PCIHostDeviceAddress { |
314 | unsigned int domain; | |
315 | unsigned int bus; | |
316 | unsigned int slot; | |
317 | unsigned int function; | |
318 | } PCIHostDeviceAddress; | |
319 | ||
d5ab9713 JK |
320 | void tcg_exec_init(unsigned long tb_size); |
321 | bool tcg_enabled(void); | |
322 | ||
323 | void cpu_exec_init_all(void); | |
d2053c3c | 324 | |
b3c7724c PB |
325 | /* CPU save/load. */ |
326 | void cpu_save(QEMUFile *f, void *opaque); | |
327 | int cpu_load(QEMUFile *f, void *opaque, int version_id); | |
328 | ||
8edac960 | 329 | /* Unblock cpu */ |
46d62fac | 330 | void qemu_cpu_kick_self(void); |
8edac960 | 331 | |
e82bcec2 MT |
332 | /* work queue */ |
333 | struct qemu_work_item { | |
334 | struct qemu_work_item *next; | |
335 | void (*func)(void *data); | |
336 | void *data; | |
337 | int done; | |
338 | }; | |
339 | ||
0bf46a40 AL |
340 | #ifdef CONFIG_USER_ONLY |
341 | #define qemu_init_vcpu(env) do { } while (0) | |
342 | #else | |
343 | void qemu_init_vcpu(void *env); | |
344 | #endif | |
345 | ||
8c5135f9 PB |
346 | |
347 | /** | |
2fc8ae1d MT |
348 | * Sends a (part of) iovec down a socket, yielding when the socket is full, or |
349 | * Receives data into a (part of) iovec from a socket, | |
350 | * yielding when there is no data in the socket. | |
351 | * The same interface as qemu_sendv_recvv(), with added yielding. | |
352 | * XXX should mark these as coroutine_fn | |
8c5135f9 | 353 | */ |
2fc8ae1d MT |
354 | ssize_t qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt, |
355 | size_t offset, size_t bytes, bool do_send); | |
356 | #define qemu_co_recvv(sockfd, iov, iov_cnt, offset, bytes) \ | |
357 | qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, false) | |
358 | #define qemu_co_sendv(sockfd, iov, iov_cnt, offset, bytes) \ | |
359 | qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, true) | |
8c5135f9 PB |
360 | |
361 | /** | |
2fc8ae1d | 362 | * The same as above, but with just a single buffer |
8c5135f9 | 363 | */ |
2fc8ae1d MT |
364 | ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send); |
365 | #define qemu_co_recv(sockfd, buf, bytes) \ | |
366 | qemu_co_send_recv(sockfd, buf, bytes, false) | |
367 | #define qemu_co_send(sockfd, buf, bytes) \ | |
368 | qemu_co_send_recv(sockfd, buf, bytes, true) | |
8c5135f9 | 369 | |
44e3ee8a AL |
370 | typedef struct QEMUIOVector { |
371 | struct iovec *iov; | |
372 | int niov; | |
373 | int nalloc; | |
249aa745 | 374 | size_t size; |
44e3ee8a AL |
375 | } QEMUIOVector; |
376 | ||
377 | void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); | |
522584a5 | 378 | void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov); |
44e3ee8a | 379 | void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len); |
1b093c48 MT |
380 | void qemu_iovec_concat(QEMUIOVector *dst, |
381 | QEMUIOVector *src, size_t soffset, size_t sbytes); | |
44e3ee8a | 382 | void qemu_iovec_destroy(QEMUIOVector *qiov); |
be959463 | 383 | void qemu_iovec_reset(QEMUIOVector *qiov); |
d5e6b161 MT |
384 | size_t qemu_iovec_to_buf(QEMUIOVector *qiov, size_t offset, |
385 | void *buf, size_t bytes); | |
03396148 MT |
386 | size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset, |
387 | const void *buf, size_t bytes); | |
3d9b4925 MT |
388 | size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset, |
389 | int fillc, size_t bytes); | |
44e3ee8a | 390 | |
1a6d39fd SH |
391 | bool buffer_is_zero(const void *buf, size_t len); |
392 | ||
6b837bc4 JS |
393 | void qemu_progress_init(int enabled, float min_skip); |
394 | void qemu_progress_end(void); | |
3bfe4dbf | 395 | void qemu_progress_print(float delta, int max); |
31459f46 | 396 | const char *qemu_get_vm_name(void); |
6b837bc4 | 397 | |
082b5557 BS |
398 | #define QEMU_FILE_TYPE_BIOS 0 |
399 | #define QEMU_FILE_TYPE_KEYMAP 1 | |
400 | char *qemu_find_file(int type, const char *name); | |
401 | ||
402 | /* OS specific functions */ | |
403 | void os_setup_early_signal_handling(void); | |
404 | char *os_find_datadir(const char *argv0); | |
405 | void os_parse_cmd_args(int index, const char *optarg); | |
406 | void os_pidfile_error(void); | |
407 | ||
abd0c6bd PB |
408 | /* Convert a byte between binary and BCD. */ |
409 | static inline uint8_t to_bcd(uint8_t val) | |
410 | { | |
411 | return ((val / 10) << 4) | (val % 10); | |
412 | } | |
413 | ||
414 | static inline uint8_t from_bcd(uint8_t val) | |
415 | { | |
416 | return ((val >> 4) * 10) + (val & 0x0f); | |
417 | } | |
418 | ||
338b922e | 419 | /* compute with 96 bit intermediate result: (a*b)/c */ |
420 | static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) | |
421 | { | |
422 | union { | |
423 | uint64_t ll; | |
424 | struct { | |
425 | #ifdef HOST_WORDS_BIGENDIAN | |
426 | uint32_t high, low; | |
427 | #else | |
428 | uint32_t low, high; | |
429 | #endif | |
430 | } l; | |
431 | } u, res; | |
432 | uint64_t rl, rh; | |
433 | ||
434 | u.ll = a; | |
435 | rl = (uint64_t)u.l.low * (uint64_t)b; | |
436 | rh = (uint64_t)u.l.high * (uint64_t)b; | |
437 | rh += (rl >> 32); | |
438 | res.l.high = rh / c; | |
439 | res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; | |
440 | return res.ll; | |
441 | } | |
442 | ||
3951690a SH |
443 | /* Round number down to multiple */ |
444 | #define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m)) | |
445 | ||
446 | /* Round number up to multiple */ | |
447 | #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m)) | |
448 | ||
9fb26641 OW |
449 | static inline bool is_power_of_2(uint64_t value) |
450 | { | |
451 | if (!value) { | |
452 | return 0; | |
453 | } | |
454 | ||
455 | return !(value & (value - 1)); | |
456 | } | |
457 | ||
458 | /* round down to the nearest power of 2*/ | |
459 | int64_t pow2floor(int64_t value); | |
460 | ||
0bfe3ca5 AL |
461 | #include "module.h" |
462 | ||
e6546bb9 OW |
463 | /* |
464 | * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128) | |
465 | * Input is limited to 14-bit numbers | |
466 | */ | |
467 | ||
468 | int uleb128_encode_small(uint8_t *out, uint32_t n); | |
469 | int uleb128_decode_small(const uint8_t *in, uint32_t *n); | |
470 | ||
faf07963 | 471 | #endif |