]>
Commit | Line | Data |
---|---|---|
ea88812f FB |
1 | #ifndef QEMU_OSDEP_H |
2 | #define QEMU_OSDEP_H | |
3 | ||
4 | #include <stdarg.h> | |
de5071c5 | 5 | #include <stddef.h> |
128ab2ff BS |
6 | #ifdef __OpenBSD__ |
7 | #include <sys/types.h> | |
8 | #include <sys/signal.h> | |
9 | #endif | |
ea88812f | 10 | |
f7b4a940 | 11 | #include <sys/time.h> |
f7b4a940 | 12 | |
dda3c2ee AF |
13 | #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10 |
14 | /* [u]int_fast*_t not in <sys/int_types.h> */ | |
15 | typedef unsigned char uint_fast8_t; | |
16 | typedef unsigned int uint_fast16_t; | |
94a49d86 | 17 | typedef signed int int_fast16_t; |
dda3c2ee AF |
18 | #endif |
19 | ||
df2542c7 JM |
20 | #ifndef glue |
21 | #define xglue(x, y) x ## y | |
22 | #define glue(x, y) xglue(x, y) | |
23 | #define stringify(s) tostring(s) | |
24 | #define tostring(s) #s | |
25 | #endif | |
26 | ||
27 | #ifndef likely | |
28 | #if __GNUC__ < 3 | |
29 | #define __builtin_expect(x, n) (x) | |
30 | #endif | |
31 | ||
32 | #define likely(x) __builtin_expect(!!(x), 1) | |
33 | #define unlikely(x) __builtin_expect(!!(x), 0) | |
34 | #endif | |
35 | ||
ac509d88 | 36 | #ifndef container_of |
62a6e3e1 | 37 | #define container_of(ptr, type, member) ({ \ |
ac509d88 AZ |
38 | const typeof(((type *) 0)->member) *__mptr = (ptr); \ |
39 | (type *) ((char *) __mptr - offsetof(type, member));}) | |
40 | #endif | |
62a6e3e1 | 41 | |
5096fae3 MM |
42 | /* Convert from a base type to a parent type, with compile time checking. */ |
43 | #ifdef __GNUC__ | |
44 | #define DO_UPCAST(type, field, dev) ( __extension__ ( { \ | |
45 | char __attribute__((unused)) offset_must_be_zero[ \ | |
46 | -offsetof(type, field)]; \ | |
47 | container_of(dev, type, field);})) | |
48 | #else | |
49 | #define DO_UPCAST(type, field, dev) container_of(dev, type, field) | |
50 | #endif | |
51 | ||
f0d99ad7 JQ |
52 | #define typeof_field(type, field) typeof(((type *)0)->field) |
53 | #define type_check(t1,t2) ((t1*)0 - (t2*)0) | |
54 | ||
df2542c7 JM |
55 | #ifndef MIN |
56 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) | |
57 | #endif | |
58 | #ifndef MAX | |
59 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) | |
60 | #endif | |
61 | ||
e0e53b2f CC |
62 | #ifndef DIV_ROUND_UP |
63 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | |
64 | #endif | |
65 | ||
0954d0d9 BS |
66 | #ifndef ARRAY_SIZE |
67 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | |
68 | #endif | |
69 | ||
df2542c7 | 70 | #ifndef always_inline |
636aa200 | 71 | #if !((__GNUC__ < 3) || defined(__APPLE__)) |
3dec6ecd | 72 | #ifdef __OPTIMIZE__ |
636aa200 | 73 | #define inline __attribute__ (( always_inline )) __inline__ |
df2542c7 | 74 | #endif |
3dec6ecd | 75 | #endif |
cebdff77 | 76 | #else |
df2542c7 | 77 | #define inline always_inline |
cebdff77 | 78 | #endif |
df2542c7 | 79 | |
d62ca2bb | 80 | #define qemu_printf printf |
ea88812f | 81 | |
f97742d0 | 82 | int qemu_daemon(int nochdir, int noclose); |
33f00271 | 83 | void *qemu_memalign(size_t alignment, size_t size); |
49b470eb FB |
84 | void *qemu_vmalloc(size_t size); |
85 | void qemu_vfree(void *ptr); | |
ea88812f | 86 | |
e78815a5 AF |
87 | #define QEMU_MADV_INVALID -1 |
88 | ||
89 | #if defined(CONFIG_MADVISE) | |
90 | ||
91 | #define QEMU_MADV_WILLNEED MADV_WILLNEED | |
92 | #define QEMU_MADV_DONTNEED MADV_DONTNEED | |
93 | #ifdef MADV_DONTFORK | |
94 | #define QEMU_MADV_DONTFORK MADV_DONTFORK | |
95 | #else | |
96 | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID | |
97 | #endif | |
98 | #ifdef MADV_MERGEABLE | |
99 | #define QEMU_MADV_MERGEABLE MADV_MERGEABLE | |
100 | #else | |
101 | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID | |
102 | #endif | |
103 | ||
104 | #elif defined(CONFIG_POSIX_MADVISE) | |
105 | ||
106 | #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED | |
107 | #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED | |
108 | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID | |
109 | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID | |
110 | ||
111 | #else /* no-op */ | |
112 | ||
113 | #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID | |
114 | #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID | |
115 | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID | |
116 | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID | |
117 | ||
118 | #endif | |
119 | ||
120 | int qemu_madvise(void *addr, size_t len, int advice); | |
121 | ||
953ffe0f AF |
122 | #if defined(__HAIKU__) && defined(__i386__) |
123 | #define FMT_pid "%ld" | |
0e0167ba SW |
124 | #elif defined(WIN64) |
125 | #define FMT_pid "%" PRId64 | |
953ffe0f AF |
126 | #else |
127 | #define FMT_pid "%d" | |
128 | #endif | |
129 | ||
aa26bb2d | 130 | int qemu_create_pidfile(const char *filename); |
dc7a09cf | 131 | int qemu_get_thread_id(void); |
aa26bb2d | 132 | |
ad620c29 BS |
133 | #ifdef _WIN32 |
134 | static inline void qemu_timersub(const struct timeval *val1, | |
135 | const struct timeval *val2, | |
136 | struct timeval *res) | |
137 | { | |
138 | res->tv_sec = val1->tv_sec - val2->tv_sec; | |
139 | if (val1->tv_usec < val2->tv_usec) { | |
140 | res->tv_sec--; | |
141 | res->tv_usec = val1->tv_usec - val2->tv_usec + 1000 * 1000; | |
142 | } else { | |
143 | res->tv_usec = val1->tv_usec - val2->tv_usec; | |
144 | } | |
145 | } | |
146 | #else | |
147 | #define qemu_timersub timersub | |
148 | #endif | |
149 | ||
49ee3590 AL |
150 | void qemu_set_cloexec(int fd); |
151 | ||
93bfef4c CV |
152 | void qemu_set_version(const char *); |
153 | const char *qemu_get_version(void); | |
154 | ||
ea88812f | 155 | #endif |