kvm: Fix eflags corruption in kvm mode
[qemu.git] / qemu-common.h
blobc9410066e4275898e744e078149eee571c69e8ee
1 /* Common header file that is included by all of qemu. */
2 #ifndef QEMU_COMMON_H
3 #define QEMU_COMMON_H
5 #include "config-host.h"
7 #define QEMU_NORETURN __attribute__ ((__noreturn__))
8 #ifdef CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT
9 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
10 #else
11 #define QEMU_WARN_UNUSED_RESULT
12 #endif
14 /* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
15 cannot include the following headers without conflicts. This condition has
16 to be removed once dyngen is gone. */
17 #ifndef __DYNGEN_EXEC_H__
19 /* we put basic includes here to avoid repeating them in device drivers */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <strings.h>
25 #include <inttypes.h>
26 #include <limits.h>
27 #include <time.h>
28 #include <ctype.h>
29 #include <errno.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <sys/stat.h>
33 #include <assert.h>
35 #ifndef O_LARGEFILE
36 #define O_LARGEFILE 0
37 #endif
38 #ifndef O_BINARY
39 #define O_BINARY 0
40 #endif
41 #ifndef MAP_ANONYMOUS
42 #define MAP_ANONYMOUS MAP_ANON
43 #endif
44 #ifndef ENOMEDIUM
45 #define ENOMEDIUM ENODEV
46 #endif
47 #if !defined(ENOTSUP)
48 #define ENOTSUP 4096
49 #endif
51 #ifndef CONFIG_IOVEC
52 #define CONFIG_IOVEC
53 struct iovec {
54 void *iov_base;
55 size_t iov_len;
58 * Use the same value as Linux for now.
60 #define IOV_MAX 1024
61 #else
62 #include <sys/uio.h>
63 #endif
65 #ifdef _WIN32
66 #define fsync _commit
67 #define lseek _lseeki64
68 extern int qemu_ftruncate64(int, int64_t);
69 #define ftruncate qemu_ftruncate64
71 static inline char *realpath(const char *path, char *resolved_path)
73 _fullpath(resolved_path, path, _MAX_PATH);
74 return resolved_path;
77 #define PRId64 "I64d"
78 #define PRIx64 "I64x"
79 #define PRIu64 "I64u"
80 #define PRIo64 "I64o"
81 #endif
83 /* FIXME: Remove NEED_CPU_H. */
84 #ifndef NEED_CPU_H
86 #include <setjmp.h>
87 #include "osdep.h"
88 #include "bswap.h"
90 #else
92 #include "cpu.h"
94 #endif /* !defined(NEED_CPU_H) */
96 /* bottom halves */
97 typedef struct QEMUBH QEMUBH;
99 typedef void QEMUBHFunc(void *opaque);
101 void async_context_push(void);
102 void async_context_pop(void);
103 int get_async_context_id(void);
105 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
106 void qemu_bh_schedule(QEMUBH *bh);
107 /* Bottom halfs that are scheduled from a bottom half handler are instantly
108 * invoked. This can create an infinite loop if a bottom half handler
109 * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by
110 * ensuring that the bottom half isn't executed until the next main loop
111 * iteration.
113 void qemu_bh_schedule_idle(QEMUBH *bh);
114 void qemu_bh_cancel(QEMUBH *bh);
115 void qemu_bh_delete(QEMUBH *bh);
116 int qemu_bh_poll(void);
117 void qemu_bh_update_timeout(int *timeout);
119 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
121 void qemu_get_timedate(struct tm *tm, int offset);
122 int qemu_timedate_diff(struct tm *tm);
124 /* cutils.c */
125 void pstrcpy(char *buf, int buf_size, const char *str);
126 char *pstrcat(char *buf, int buf_size, const char *s);
127 int strstart(const char *str, const char *val, const char **ptr);
128 int stristart(const char *str, const char *val, const char **ptr);
129 int qemu_strnlen(const char *s, int max_len);
130 time_t mktimegm(struct tm *tm);
131 int qemu_fls(int i);
132 int qemu_fdatasync(int fd);
134 /* path.c */
135 void init_paths(const char *prefix);
136 const char *path(const char *pathname);
138 #define qemu_isalnum(c) isalnum((unsigned char)(c))
139 #define qemu_isalpha(c) isalpha((unsigned char)(c))
140 #define qemu_iscntrl(c) iscntrl((unsigned char)(c))
141 #define qemu_isdigit(c) isdigit((unsigned char)(c))
142 #define qemu_isgraph(c) isgraph((unsigned char)(c))
143 #define qemu_islower(c) islower((unsigned char)(c))
144 #define qemu_isprint(c) isprint((unsigned char)(c))
145 #define qemu_ispunct(c) ispunct((unsigned char)(c))
146 #define qemu_isspace(c) isspace((unsigned char)(c))
147 #define qemu_isupper(c) isupper((unsigned char)(c))
148 #define qemu_isxdigit(c) isxdigit((unsigned char)(c))
149 #define qemu_tolower(c) tolower((unsigned char)(c))
150 #define qemu_toupper(c) toupper((unsigned char)(c))
151 #define qemu_isascii(c) isascii((unsigned char)(c))
152 #define qemu_toascii(c) toascii((unsigned char)(c))
154 void *qemu_malloc(size_t size);
155 void *qemu_realloc(void *ptr, size_t size);
156 void *qemu_mallocz(size_t size);
157 void qemu_free(void *ptr);
158 char *qemu_strdup(const char *str);
159 char *qemu_strndup(const char *str, size_t size);
161 void *get_mmap_addr(unsigned long size);
164 void qemu_mutex_lock_iothread(void);
165 void qemu_mutex_unlock_iothread(void);
167 int qemu_open(const char *name, int flags, ...);
168 ssize_t qemu_write_full(int fd, const void *buf, size_t count)
169 QEMU_WARN_UNUSED_RESULT;
170 void qemu_set_cloexec(int fd);
172 #ifndef _WIN32
173 int qemu_eventfd(int pipefd[2]);
174 int qemu_pipe(int pipefd[2]);
175 #endif
177 /* Error handling. */
179 void QEMU_NORETURN hw_error(const char *fmt, ...)
180 __attribute__ ((__format__ (__printf__, 1, 2)));
182 /* IO callbacks. */
183 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
184 typedef int IOCanRWHandler(void *opaque);
185 typedef void IOHandler(void *opaque);
187 struct ParallelIOArg {
188 void *buffer;
189 int count;
192 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
194 /* A load of opaque types so that device init declarations don't have to
195 pull in all the real definitions. */
196 typedef struct NICInfo NICInfo;
197 typedef struct HCIInfo HCIInfo;
198 typedef struct AudioState AudioState;
199 typedef struct BlockDriverState BlockDriverState;
200 typedef struct DisplayState DisplayState;
201 typedef struct DisplayChangeListener DisplayChangeListener;
202 typedef struct DisplaySurface DisplaySurface;
203 typedef struct DisplayAllocator DisplayAllocator;
204 typedef struct PixelFormat PixelFormat;
205 typedef struct TextConsole TextConsole;
206 typedef TextConsole QEMUConsole;
207 typedef struct CharDriverState CharDriverState;
208 typedef struct MACAddr MACAddr;
209 typedef struct VLANState VLANState;
210 typedef struct VLANClientState VLANClientState;
211 typedef struct QEMUFile QEMUFile;
212 typedef struct i2c_bus i2c_bus;
213 typedef struct i2c_slave i2c_slave;
214 typedef struct SMBusDevice SMBusDevice;
215 typedef struct QEMUTimer QEMUTimer;
216 typedef struct PCIHostState PCIHostState;
217 typedef struct PCIExpressHost PCIExpressHost;
218 typedef struct PCIBus PCIBus;
219 typedef struct PCIDevice PCIDevice;
220 typedef struct SerialState SerialState;
221 typedef struct IRQState *qemu_irq;
222 typedef struct PCMCIACardState PCMCIACardState;
223 typedef struct MouseTransformInfo MouseTransformInfo;
224 typedef struct uWireSlave uWireSlave;
225 typedef struct I2SCodec I2SCodec;
226 typedef struct DeviceState DeviceState;
227 typedef struct SSIBus SSIBus;
229 /* CPU save/load. */
230 void cpu_save(QEMUFile *f, void *opaque);
231 int cpu_load(QEMUFile *f, void *opaque, int version_id);
233 /* Force QEMU to stop what it's doing and service IO */
234 void qemu_service_io(void);
236 /* Force QEMU to process pending events */
237 void qemu_notify_event(void);
239 /* Unblock cpu */
240 void qemu_cpu_kick(void *env);
241 int qemu_cpu_self(void *env);
243 #ifdef CONFIG_USER_ONLY
244 #define qemu_init_vcpu(env) do { } while (0)
245 #else
246 void qemu_init_vcpu(void *env);
247 #endif
249 typedef struct QEMUIOVector {
250 struct iovec *iov;
251 int niov;
252 int nalloc;
253 size_t size;
254 } QEMUIOVector;
256 void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
257 void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
258 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
259 void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
260 void qemu_iovec_destroy(QEMUIOVector *qiov);
261 void qemu_iovec_reset(QEMUIOVector *qiov);
262 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
263 void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
265 struct Monitor;
266 typedef struct Monitor Monitor;
268 /* Convert a byte between binary and BCD. */
269 static inline uint8_t to_bcd(uint8_t val)
271 return ((val / 10) << 4) | (val % 10);
274 static inline uint8_t from_bcd(uint8_t val)
276 return ((val >> 4) * 10) + (val & 0x0f);
279 #include "module.h"
281 #endif /* dyngen-exec.h hack */
283 #endif