root / include / qemu / osdep.h @ 10f5bff6
History | View | Annotate | Download (6.3 kB)
1 | ea88812f | bellard | #ifndef QEMU_OSDEP_H
|
---|---|---|---|
2 | ea88812f | bellard | #define QEMU_OSDEP_H
|
3 | ea88812f | bellard | |
4 | 9adea5f7 | Paolo Bonzini | #include "config-host.h" |
5 | ea88812f | bellard | #include <stdarg.h> |
6 | de5071c5 | Blue Swirl | #include <stddef.h> |
7 | 0f66998f | Paul Moore | #include <stdbool.h> |
8 | 128ab2ff | blueswir1 | #include <sys/types.h> |
9 | 98b2d199 | Igor Mitsyanko | #ifdef __OpenBSD__
|
10 | 128ab2ff | blueswir1 | #include <sys/signal.h> |
11 | 128ab2ff | blueswir1 | #endif
|
12 | ea88812f | bellard | |
13 | 13c7b2da | Paolo Bonzini | #ifndef _WIN32
|
14 | 13c7b2da | Paolo Bonzini | #include <sys/wait.h> |
15 | 13c7b2da | Paolo Bonzini | #else
|
16 | 13c7b2da | Paolo Bonzini | #define WIFEXITED(x) 1 |
17 | 13c7b2da | Paolo Bonzini | #define WEXITSTATUS(x) (x)
|
18 | 13c7b2da | Paolo Bonzini | #endif
|
19 | 13c7b2da | Paolo Bonzini | |
20 | f7b4a940 | aliguori | #include <sys/time.h> |
21 | f7b4a940 | aliguori | |
22 | dda3c2ee | Andreas Färber | #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10 |
23 | dda3c2ee | Andreas Färber | /* [u]int_fast*_t not in <sys/int_types.h> */
|
24 | dda3c2ee | Andreas Färber | typedef unsigned char uint_fast8_t; |
25 | dda3c2ee | Andreas Färber | typedef unsigned int uint_fast16_t; |
26 | 94a49d86 | Andreas Färber | typedef signed int int_fast16_t; |
27 | dda3c2ee | Andreas Färber | #endif
|
28 | dda3c2ee | Andreas Färber | |
29 | df2542c7 | j_mayer | #ifndef glue
|
30 | df2542c7 | j_mayer | #define xglue(x, y) x ## y |
31 | df2542c7 | j_mayer | #define glue(x, y) xglue(x, y)
|
32 | df2542c7 | j_mayer | #define stringify(s) tostring(s)
|
33 | df2542c7 | j_mayer | #define tostring(s) #s |
34 | df2542c7 | j_mayer | #endif
|
35 | df2542c7 | j_mayer | |
36 | df2542c7 | j_mayer | #ifndef likely
|
37 | df2542c7 | j_mayer | #if __GNUC__ < 3 |
38 | df2542c7 | j_mayer | #define __builtin_expect(x, n) (x)
|
39 | df2542c7 | j_mayer | #endif
|
40 | df2542c7 | j_mayer | |
41 | df2542c7 | j_mayer | #define likely(x) __builtin_expect(!!(x), 1) |
42 | df2542c7 | j_mayer | #define unlikely(x) __builtin_expect(!!(x), 0) |
43 | df2542c7 | j_mayer | #endif
|
44 | df2542c7 | j_mayer | |
45 | ac509d88 | balrog | #ifndef container_of
|
46 | 62a6e3e1 | aliguori | #define container_of(ptr, type, member) ({ \
|
47 | ac509d88 | balrog | const typeof(((type *) 0)->member) *__mptr = (ptr); \ |
48 | ac509d88 | balrog | (type *) ((char *) __mptr - offsetof(type, member));})
|
49 | ac509d88 | balrog | #endif
|
50 | 62a6e3e1 | aliguori | |
51 | 5096fae3 | Mark McLoughlin | /* Convert from a base type to a parent type, with compile time checking. */
|
52 | 5096fae3 | Mark McLoughlin | #ifdef __GNUC__
|
53 | 5096fae3 | Mark McLoughlin | #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
|
54 | 5096fae3 | Mark McLoughlin | char __attribute__((unused)) offset_must_be_zero[ \
|
55 | 5096fae3 | Mark McLoughlin | -offsetof(type, field)]; \ |
56 | 5096fae3 | Mark McLoughlin | container_of(dev, type, field);})) |
57 | 5096fae3 | Mark McLoughlin | #else
|
58 | 5096fae3 | Mark McLoughlin | #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
|
59 | 5096fae3 | Mark McLoughlin | #endif
|
60 | 5096fae3 | Mark McLoughlin | |
61 | f0d99ad7 | Juan Quintela | #define typeof_field(type, field) typeof(((type *)0)->field) |
62 | f0d99ad7 | Juan Quintela | #define type_check(t1,t2) ((t1*)0 - (t2*)0) |
63 | f0d99ad7 | Juan Quintela | |
64 | df2542c7 | j_mayer | #ifndef MIN
|
65 | df2542c7 | j_mayer | #define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
66 | df2542c7 | j_mayer | #endif
|
67 | df2542c7 | j_mayer | #ifndef MAX
|
68 | df2542c7 | j_mayer | #define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
69 | df2542c7 | j_mayer | #endif
|
70 | df2542c7 | j_mayer | |
71 | 292c8e50 | Paolo Bonzini | #ifndef ROUND_UP
|
72 | 292c8e50 | Paolo Bonzini | #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d)) |
73 | 292c8e50 | Paolo Bonzini | #endif
|
74 | 292c8e50 | Paolo Bonzini | |
75 | e0e53b2f | Corentin Chary | #ifndef DIV_ROUND_UP
|
76 | e0e53b2f | Corentin Chary | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
77 | e0e53b2f | Corentin Chary | #endif
|
78 | e0e53b2f | Corentin Chary | |
79 | 0954d0d9 | blueswir1 | #ifndef ARRAY_SIZE
|
80 | 0954d0d9 | blueswir1 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
81 | 0954d0d9 | blueswir1 | #endif
|
82 | 0954d0d9 | blueswir1 | |
83 | df2542c7 | j_mayer | #ifndef always_inline
|
84 | 636aa200 | Blue Swirl | #if !((__GNUC__ < 3) || defined(__APPLE__)) |
85 | 3dec6ecd | pbrook | #ifdef __OPTIMIZE__
|
86 | b595c14a | Blue Swirl | #undef inline |
87 | 636aa200 | Blue Swirl | #define inline __attribute__ (( always_inline )) __inline__ |
88 | df2542c7 | j_mayer | #endif
|
89 | 3dec6ecd | pbrook | #endif
|
90 | cebdff77 | ths | #else
|
91 | b595c14a | Blue Swirl | #undef inline |
92 | df2542c7 | j_mayer | #define inline always_inline |
93 | cebdff77 | ths | #endif
|
94 | df2542c7 | j_mayer | |
95 | d62ca2bb | bellard | #define qemu_printf printf
|
96 | ea88812f | bellard | |
97 | f97742d0 | Alexandre Raymond | int qemu_daemon(int nochdir, int noclose); |
98 | 33f00271 | balrog | void *qemu_memalign(size_t alignment, size_t size);
|
99 | 6eebf958 | Paolo Bonzini | void *qemu_anon_ram_alloc(size_t size);
|
100 | 49b470eb | bellard | void qemu_vfree(void *ptr); |
101 | e7a09b92 | Paolo Bonzini | void qemu_anon_ram_free(void *ptr, size_t size); |
102 | ea88812f | bellard | |
103 | e78815a5 | Andreas Färber | #define QEMU_MADV_INVALID -1 |
104 | e78815a5 | Andreas Färber | |
105 | e78815a5 | Andreas Färber | #if defined(CONFIG_MADVISE)
|
106 | e78815a5 | Andreas Färber | |
107 | e78815a5 | Andreas Färber | #define QEMU_MADV_WILLNEED MADV_WILLNEED
|
108 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTNEED MADV_DONTNEED
|
109 | e78815a5 | Andreas Färber | #ifdef MADV_DONTFORK
|
110 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTFORK MADV_DONTFORK
|
111 | e78815a5 | Andreas Färber | #else
|
112 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
|
113 | e78815a5 | Andreas Färber | #endif
|
114 | e78815a5 | Andreas Färber | #ifdef MADV_MERGEABLE
|
115 | e78815a5 | Andreas Färber | #define QEMU_MADV_MERGEABLE MADV_MERGEABLE
|
116 | e78815a5 | Andreas Färber | #else
|
117 | e78815a5 | Andreas Färber | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
|
118 | e78815a5 | Andreas Färber | #endif
|
119 | ddb97f1d | Jason Baron | #ifdef MADV_DONTDUMP
|
120 | ddb97f1d | Jason Baron | #define QEMU_MADV_DONTDUMP MADV_DONTDUMP
|
121 | ddb97f1d | Jason Baron | #else
|
122 | ddb97f1d | Jason Baron | #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
|
123 | ddb97f1d | Jason Baron | #endif
|
124 | ad0b5321 | Luiz Capitulino | #ifdef MADV_HUGEPAGE
|
125 | ad0b5321 | Luiz Capitulino | #define QEMU_MADV_HUGEPAGE MADV_HUGEPAGE
|
126 | ad0b5321 | Luiz Capitulino | #else
|
127 | ad0b5321 | Luiz Capitulino | #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
|
128 | ad0b5321 | Luiz Capitulino | #endif
|
129 | e78815a5 | Andreas Färber | |
130 | e78815a5 | Andreas Färber | #elif defined(CONFIG_POSIX_MADVISE)
|
131 | e78815a5 | Andreas Färber | |
132 | e78815a5 | Andreas Färber | #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED
|
133 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED
|
134 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
|
135 | e78815a5 | Andreas Färber | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
|
136 | ddb97f1d | Jason Baron | #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
|
137 | 8473f377 | Luiz Capitulino | #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
|
138 | e78815a5 | Andreas Färber | |
139 | e78815a5 | Andreas Färber | #else /* no-op */ |
140 | e78815a5 | Andreas Färber | |
141 | e78815a5 | Andreas Färber | #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID
|
142 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID
|
143 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
|
144 | e78815a5 | Andreas Färber | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
|
145 | ddb97f1d | Jason Baron | #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
|
146 | 8473f377 | Luiz Capitulino | #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
|
147 | e78815a5 | Andreas Färber | |
148 | e78815a5 | Andreas Färber | #endif
|
149 | e78815a5 | Andreas Färber | |
150 | e78815a5 | Andreas Färber | int qemu_madvise(void *addr, size_t len, int advice); |
151 | e78815a5 | Andreas Färber | |
152 | 17e0b6ab | Andreas Färber | int qemu_open(const char *name, int flags, ...); |
153 | 17e0b6ab | Andreas Färber | int qemu_close(int fd); |
154 | 17e0b6ab | Andreas Färber | |
155 | 953ffe0f | Andreas Färber | #if defined(__HAIKU__) && defined(__i386__)
|
156 | 953ffe0f | Andreas Färber | #define FMT_pid "%ld" |
157 | 0e0167ba | Stefan Weil | #elif defined(WIN64)
|
158 | 0e0167ba | Stefan Weil | #define FMT_pid "%" PRId64 |
159 | 953ffe0f | Andreas Färber | #else
|
160 | 953ffe0f | Andreas Färber | #define FMT_pid "%d" |
161 | 953ffe0f | Andreas Färber | #endif
|
162 | 953ffe0f | Andreas Färber | |
163 | aa26bb2d | ths | int qemu_create_pidfile(const char *filename); |
164 | dc7a09cf | Jan Kiszka | int qemu_get_thread_id(void); |
165 | aa26bb2d | ths | |
166 | 9adea5f7 | Paolo Bonzini | #ifndef CONFIG_IOVEC
|
167 | 9adea5f7 | Paolo Bonzini | struct iovec {
|
168 | 9adea5f7 | Paolo Bonzini | void *iov_base;
|
169 | 9adea5f7 | Paolo Bonzini | size_t iov_len; |
170 | 9adea5f7 | Paolo Bonzini | }; |
171 | 9adea5f7 | Paolo Bonzini | /*
|
172 | 9adea5f7 | Paolo Bonzini | * Use the same value as Linux for now.
|
173 | 9adea5f7 | Paolo Bonzini | */
|
174 | 9adea5f7 | Paolo Bonzini | #define IOV_MAX 1024 |
175 | 9adea5f7 | Paolo Bonzini | |
176 | 9adea5f7 | Paolo Bonzini | ssize_t readv(int fd, const struct iovec *iov, int iov_cnt); |
177 | 9adea5f7 | Paolo Bonzini | ssize_t writev(int fd, const struct iovec *iov, int iov_cnt); |
178 | 9adea5f7 | Paolo Bonzini | #else
|
179 | 9adea5f7 | Paolo Bonzini | #include <sys/uio.h> |
180 | 9adea5f7 | Paolo Bonzini | #endif
|
181 | 9adea5f7 | Paolo Bonzini | |
182 | ad620c29 | Blue Swirl | #ifdef _WIN32
|
183 | ad620c29 | Blue Swirl | static inline void qemu_timersub(const struct timeval *val1, |
184 | ad620c29 | Blue Swirl | const struct timeval *val2, |
185 | ad620c29 | Blue Swirl | struct timeval *res)
|
186 | ad620c29 | Blue Swirl | { |
187 | ad620c29 | Blue Swirl | res->tv_sec = val1->tv_sec - val2->tv_sec; |
188 | ad620c29 | Blue Swirl | if (val1->tv_usec < val2->tv_usec) {
|
189 | ad620c29 | Blue Swirl | res->tv_sec--; |
190 | ad620c29 | Blue Swirl | res->tv_usec = val1->tv_usec - val2->tv_usec + 1000 * 1000; |
191 | ad620c29 | Blue Swirl | } else {
|
192 | ad620c29 | Blue Swirl | res->tv_usec = val1->tv_usec - val2->tv_usec; |
193 | ad620c29 | Blue Swirl | } |
194 | ad620c29 | Blue Swirl | } |
195 | ad620c29 | Blue Swirl | #else
|
196 | ad620c29 | Blue Swirl | #define qemu_timersub timersub
|
197 | ad620c29 | Blue Swirl | #endif
|
198 | ad620c29 | Blue Swirl | |
199 | 49ee3590 | Anthony Liguori | void qemu_set_cloexec(int fd); |
200 | 49ee3590 | Anthony Liguori | |
201 | 93bfef4c | Crístian Viana | void qemu_set_version(const char *); |
202 | 93bfef4c | Crístian Viana | const char *qemu_get_version(void); |
203 | 93bfef4c | Crístian Viana | |
204 | 0f66998f | Paul Moore | void fips_set_state(bool requested); |
205 | 0f66998f | Paul Moore | bool fips_get_state(void); |
206 | 0f66998f | Paul Moore | |
207 | e2ea3515 | Laszlo Ersek | /* Return a dynamically allocated pathname denoting a file or directory that is
|
208 | e2ea3515 | Laszlo Ersek | * appropriate for storing local state.
|
209 | e2ea3515 | Laszlo Ersek | *
|
210 | e2ea3515 | Laszlo Ersek | * @relative_pathname need not start with a directory separator; one will be
|
211 | e2ea3515 | Laszlo Ersek | * added automatically.
|
212 | e2ea3515 | Laszlo Ersek | *
|
213 | e2ea3515 | Laszlo Ersek | * The caller is responsible for releasing the value returned with g_free()
|
214 | e2ea3515 | Laszlo Ersek | * after use.
|
215 | e2ea3515 | Laszlo Ersek | */
|
216 | e2ea3515 | Laszlo Ersek | char *qemu_get_local_state_pathname(const char *relative_pathname); |
217 | e2ea3515 | Laszlo Ersek | |
218 | 10f5bff6 | Fam Zheng | /* Find program directory, and save it for later usage with
|
219 | 10f5bff6 | Fam Zheng | * qemu_get_exec_dir().
|
220 | 10f5bff6 | Fam Zheng | * Try OS specific API first, if not working, parse from argv0. */
|
221 | 10f5bff6 | Fam Zheng | void qemu_init_exec_dir(const char *argv0); |
222 | 10f5bff6 | Fam Zheng | |
223 | 10f5bff6 | Fam Zheng | /* Get the saved exec dir.
|
224 | 10f5bff6 | Fam Zheng | * Caller needs to release the returned string by g_free() */
|
225 | 10f5bff6 | Fam Zheng | char *qemu_get_exec_dir(void); |
226 | 10f5bff6 | Fam Zheng | |
227 | b6a3e690 | Richard Henderson | /**
|
228 | b6a3e690 | Richard Henderson | * qemu_getauxval:
|
229 | b6a3e690 | Richard Henderson | * @type: the auxiliary vector key to lookup
|
230 | b6a3e690 | Richard Henderson | *
|
231 | b6a3e690 | Richard Henderson | * Search the auxiliary vector for @type, returning the value
|
232 | b6a3e690 | Richard Henderson | * or 0 if @type is not present.
|
233 | b6a3e690 | Richard Henderson | */
|
234 | b6a3e690 | Richard Henderson | #if defined(CONFIG_GETAUXVAL) || defined(__linux__)
|
235 | b6a3e690 | Richard Henderson | unsigned long qemu_getauxval(unsigned long type); |
236 | b6a3e690 | Richard Henderson | #else
|
237 | b6a3e690 | Richard Henderson | static inline unsigned long qemu_getauxval(unsigned long type) { return 0; } |
238 | b6a3e690 | Richard Henderson | #endif
|
239 | b6a3e690 | Richard Henderson | |
240 | b6a3e690 | Richard Henderson | /**
|
241 | b6a3e690 | Richard Henderson | * qemu_init_auxval:
|
242 | b6a3e690 | Richard Henderson | * @envp: the third argument to main
|
243 | b6a3e690 | Richard Henderson | *
|
244 | b6a3e690 | Richard Henderson | * If supported and required, locate the auxiliary vector at program startup.
|
245 | b6a3e690 | Richard Henderson | */
|
246 | b6a3e690 | Richard Henderson | #if defined(CONFIG_GETAUXVAL) || !defined(__linux__)
|
247 | b6a3e690 | Richard Henderson | static inline void qemu_init_auxval(char **envp) { } |
248 | b6a3e690 | Richard Henderson | #else
|
249 | b6a3e690 | Richard Henderson | void qemu_init_auxval(char **envp); |
250 | b6a3e690 | Richard Henderson | #endif
|
251 | b6a3e690 | Richard Henderson | |
252 | 13401ba0 | Stefan Hajnoczi | void qemu_set_tty_echo(int fd, bool echo); |
253 | 13401ba0 | Stefan Hajnoczi | |
254 | ea88812f | bellard | #endif |