1 | /* Common header file that is included by all of qemu. */
|
---|
2 | #ifndef QEMU_COMMON_H
|
---|
3 | #define QEMU_COMMON_H
|
---|
4 |
|
---|
5 | #ifdef VBOX
|
---|
6 |
|
---|
7 | # include <string.h>
|
---|
8 | # include <inttypes.h>
|
---|
9 | # include <iprt/ctype.h>
|
---|
10 |
|
---|
11 | #define QEMU_NORETURN __attribute__ ((__noreturn__))
|
---|
12 |
|
---|
13 | void pstrcpy(char *buf, int buf_size, const char *str);
|
---|
14 | char *pstrcat(char *buf, int buf_size, const char *s);
|
---|
15 | # define snprintf RTStrPrintf
|
---|
16 |
|
---|
17 | #define qemu_isalnum(c) RT_C_IS_ALNUM((unsigned char)(c))
|
---|
18 | #define qemu_isalpha(c) RT_C_IS_ALPHA((unsigned char)(c))
|
---|
19 | #define qemu_iscntrl(c) RT_C_IS_CNTRL((unsigned char)(c))
|
---|
20 | #define qemu_isdigit(c) RT_C_IS_DIGIT((unsigned char)(c))
|
---|
21 | #define qemu_isgraph(c) RT_C_IS_GRAPH((unsigned char)(c))
|
---|
22 | #define qemu_islower(c) RT_C_IS_LOWER((unsigned char)(c))
|
---|
23 | #define qemu_isprint(c) RT_C_IS_PRINT((unsigned char)(c))
|
---|
24 | #define qemu_ispunct(c) RT_C_IS_PUNCT((unsigned char)(c))
|
---|
25 | #define qemu_isspace(c) RT_C_IS_SPACE((unsigned char)(c))
|
---|
26 | #define qemu_isupper(c) RT_C_IS_UPPER((unsigned char)(c))
|
---|
27 | #define qemu_isxdigit(c) RT_C_IS_XDIGIT((unsigned char)(c))
|
---|
28 | #define qemu_tolower(c) RT_C_TO_LOWER((unsigned char)(c))
|
---|
29 | #define qemu_toupper(c) RT_C_TO_UPPER((unsigned char)(c))
|
---|
30 | #define qemu_isascii(c) RT_C_IS_ASCII((unsigned char)(c))
|
---|
31 | #define qemu_toascii(c) RT_C_TO_ASCII((unsigned char)(c))
|
---|
32 |
|
---|
33 | #define qemu_init_vcpu(env) do { } while (0) /* we don't need this :-) */
|
---|
34 |
|
---|
35 |
|
---|
36 | #else /* !VBOX */
|
---|
37 | #ifdef _WIN32
|
---|
38 | #define WIN32_LEAN_AND_MEAN
|
---|
39 | #define WINVER 0x0501 /* needed for ipv6 bits */
|
---|
40 | #include <windows.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #define QEMU_NORETURN __attribute__ ((__noreturn__))
|
---|
44 |
|
---|
45 | /* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
|
---|
46 | cannot include the following headers without conflicts. This condition has
|
---|
47 | to be removed once dyngen is gone. */
|
---|
48 | #ifndef __DYNGEN_EXEC_H__
|
---|
49 |
|
---|
50 | /* we put basic includes here to avoid repeating them in device drivers */
|
---|
51 | #include <stdlib.h>
|
---|
52 | #include <stdio.h>
|
---|
53 | #include <stdarg.h>
|
---|
54 | #include <string.h>
|
---|
55 | #include <strings.h>
|
---|
56 | #include <inttypes.h>
|
---|
57 | #include <limits.h>
|
---|
58 | #include <time.h>
|
---|
59 | #include <ctype.h>
|
---|
60 | #include <errno.h>
|
---|
61 | #include <unistd.h>
|
---|
62 | #include <fcntl.h>
|
---|
63 | #include <sys/stat.h>
|
---|
64 | #include <assert.h>
|
---|
65 | #include "config-host.h"
|
---|
66 |
|
---|
67 | #ifndef O_LARGEFILE
|
---|
68 | #define O_LARGEFILE 0
|
---|
69 | #endif
|
---|
70 | #ifndef O_BINARY
|
---|
71 | #define O_BINARY 0
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | #ifndef ENOMEDIUM
|
---|
75 | #define ENOMEDIUM ENODEV
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | #ifndef HAVE_IOVEC
|
---|
79 | #define HAVE_IOVEC
|
---|
80 | struct iovec {
|
---|
81 | void *iov_base;
|
---|
82 | size_t iov_len;
|
---|
83 | };
|
---|
84 | #else
|
---|
85 | #include <sys/uio.h>
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | #ifdef _WIN32
|
---|
89 | #define fsync _commit
|
---|
90 | #define lseek _lseeki64
|
---|
91 | #define ENOTSUP 4096
|
---|
92 | extern int qemu_ftruncate64(int, int64_t);
|
---|
93 | #define ftruncate qemu_ftruncate64
|
---|
94 |
|
---|
95 |
|
---|
96 | static inline char *realpath(const char *path, char *resolved_path)
|
---|
97 | {
|
---|
98 | _fullpath(resolved_path, path, _MAX_PATH);
|
---|
99 | return resolved_path;
|
---|
100 | }
|
---|
101 |
|
---|
102 | #define PRId64 "I64d"
|
---|
103 | #define PRIx64 "I64x"
|
---|
104 | #define PRIu64 "I64u"
|
---|
105 | #define PRIo64 "I64o"
|
---|
106 | #endif
|
---|
107 |
|
---|
108 | /* FIXME: Remove NEED_CPU_H. */
|
---|
109 | #ifndef NEED_CPU_H
|
---|
110 |
|
---|
111 | #include <setjmp.h>
|
---|
112 | #include "osdep.h"
|
---|
113 | #include "bswap.h"
|
---|
114 |
|
---|
115 | #else
|
---|
116 |
|
---|
117 | #include "cpu.h"
|
---|
118 |
|
---|
119 | #endif /* !defined(NEED_CPU_H) */
|
---|
120 |
|
---|
121 | /* bottom halves */
|
---|
122 | typedef struct QEMUBH QEMUBH;
|
---|
123 |
|
---|
124 | typedef void QEMUBHFunc(void *opaque);
|
---|
125 |
|
---|
126 | QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
|
---|
127 | void qemu_bh_schedule(QEMUBH *bh);
|
---|
128 | /* Bottom halfs that are scheduled from a bottom half handler are instantly
|
---|
129 | * invoked. This can create an infinite loop if a bottom half handler
|
---|
130 | * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by
|
---|
131 | * ensuring that the bottom half isn't executed until the next main loop
|
---|
132 | * iteration.
|
---|
133 | */
|
---|
134 | void qemu_bh_schedule_idle(QEMUBH *bh);
|
---|
135 | void qemu_bh_cancel(QEMUBH *bh);
|
---|
136 | void qemu_bh_delete(QEMUBH *bh);
|
---|
137 | int qemu_bh_poll(void);
|
---|
138 |
|
---|
139 | uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
|
---|
140 |
|
---|
141 | void qemu_get_timedate(struct tm *tm, int offset);
|
---|
142 | int qemu_timedate_diff(struct tm *tm);
|
---|
143 |
|
---|
144 | /* cutils.c */
|
---|
145 | void pstrcpy(char *buf, int buf_size, const char *str);
|
---|
146 | char *pstrcat(char *buf, int buf_size, const char *s);
|
---|
147 | int strstart(const char *str, const char *val, const char **ptr);
|
---|
148 | int stristart(const char *str, const char *val, const char **ptr);
|
---|
149 | int qemu_strnlen(const char *s, int max_len);
|
---|
150 | time_t mktimegm(struct tm *tm);
|
---|
151 | int qemu_fls(int i);
|
---|
152 |
|
---|
153 | #define qemu_isalnum(c) isalnum((unsigned char)(c))
|
---|
154 | #define qemu_isalpha(c) isalpha((unsigned char)(c))
|
---|
155 | #define qemu_iscntrl(c) iscntrl((unsigned char)(c))
|
---|
156 | #define qemu_isdigit(c) isdigit((unsigned char)(c))
|
---|
157 | #define qemu_isgraph(c) isgraph((unsigned char)(c))
|
---|
158 | #define qemu_islower(c) islower((unsigned char)(c))
|
---|
159 | #define qemu_isprint(c) isprint((unsigned char)(c))
|
---|
160 | #define qemu_ispunct(c) ispunct((unsigned char)(c))
|
---|
161 | #define qemu_isspace(c) isspace((unsigned char)(c))
|
---|
162 | #define qemu_isupper(c) isupper((unsigned char)(c))
|
---|
163 | #define qemu_isxdigit(c) isxdigit((unsigned char)(c))
|
---|
164 | #define qemu_tolower(c) tolower((unsigned char)(c))
|
---|
165 | #define qemu_toupper(c) toupper((unsigned char)(c))
|
---|
166 | #define qemu_isascii(c) isascii((unsigned char)(c))
|
---|
167 | #define qemu_toascii(c) toascii((unsigned char)(c))
|
---|
168 |
|
---|
169 | void *qemu_malloc(size_t size);
|
---|
170 | void *qemu_realloc(void *ptr, size_t size);
|
---|
171 | void *qemu_mallocz(size_t size);
|
---|
172 | void qemu_free(void *ptr);
|
---|
173 | char *qemu_strdup(const char *str);
|
---|
174 | char *qemu_strndup(const char *str, size_t size);
|
---|
175 |
|
---|
176 | void *get_mmap_addr(unsigned long size);
|
---|
177 |
|
---|
178 |
|
---|
179 | /* Error handling. */
|
---|
180 |
|
---|
181 | void QEMU_NORETURN hw_error(const char *fmt, ...)
|
---|
182 | __attribute__ ((__format__ (__printf__, 1, 2)));
|
---|
183 |
|
---|
184 | /* IO callbacks. */
|
---|
185 | typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
|
---|
186 | typedef int IOCanRWHandler(void *opaque);
|
---|
187 | typedef void IOHandler(void *opaque);
|
---|
188 |
|
---|
189 | struct ParallelIOArg {
|
---|
190 | void *buffer;
|
---|
191 | int count;
|
---|
192 | };
|
---|
193 |
|
---|
194 | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
|
---|
195 |
|
---|
196 | /* A load of opaque types so that device init declarations don't have to
|
---|
197 | pull in all the real definitions. */
|
---|
198 | typedef struct NICInfo NICInfo;
|
---|
199 | typedef struct HCIInfo HCIInfo;
|
---|
200 | typedef struct AudioState AudioState;
|
---|
201 | typedef struct BlockDriverState BlockDriverState;
|
---|
202 | typedef struct DisplayState DisplayState;
|
---|
203 | typedef struct DisplayChangeListener DisplayChangeListener;
|
---|
204 | typedef struct DisplaySurface DisplaySurface;
|
---|
205 | typedef struct DisplayAllocator DisplayAllocator;
|
---|
206 | typedef struct PixelFormat PixelFormat;
|
---|
207 | typedef struct TextConsole TextConsole;
|
---|
208 | typedef TextConsole QEMUConsole;
|
---|
209 | typedef struct CharDriverState CharDriverState;
|
---|
210 | typedef struct VLANState VLANState;
|
---|
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 PCIBus PCIBus;
|
---|
217 | typedef struct PCIDevice PCIDevice;
|
---|
218 | typedef struct SerialState SerialState;
|
---|
219 | typedef struct IRQState *qemu_irq;
|
---|
220 | typedef struct PCMCIACardState PCMCIACardState;
|
---|
221 | typedef struct MouseTransformInfo MouseTransformInfo;
|
---|
222 | typedef struct uWireSlave uWireSlave;
|
---|
223 | typedef struct I2SCodec I2SCodec;
|
---|
224 | typedef struct DeviceState DeviceState;
|
---|
225 | typedef struct SSIBus SSIBus;
|
---|
226 |
|
---|
227 | /* CPU save/load. */
|
---|
228 | void cpu_save(QEMUFile *f, void *opaque);
|
---|
229 | int cpu_load(QEMUFile *f, void *opaque, int version_id);
|
---|
230 |
|
---|
231 | /* Force QEMU to stop what it's doing and service IO */
|
---|
232 | void qemu_service_io(void);
|
---|
233 |
|
---|
234 | /* Force QEMU to process pending events */
|
---|
235 | void qemu_notify_event(void);
|
---|
236 |
|
---|
237 | /* Unblock cpu */
|
---|
238 | void qemu_cpu_kick(void *env);
|
---|
239 | int qemu_cpu_self(void *env);
|
---|
240 |
|
---|
241 | #ifdef CONFIG_USER_ONLY
|
---|
242 | #define qemu_init_vcpu(env) do { } while (0)
|
---|
243 | #else
|
---|
244 | void qemu_init_vcpu(void *env);
|
---|
245 | #endif
|
---|
246 |
|
---|
247 | typedef struct QEMUIOVector {
|
---|
248 | struct iovec *iov;
|
---|
249 | int niov;
|
---|
250 | int nalloc;
|
---|
251 | size_t size;
|
---|
252 | } QEMUIOVector;
|
---|
253 |
|
---|
254 | void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
|
---|
255 | void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
|
---|
256 | void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
|
---|
257 | void qemu_iovec_destroy(QEMUIOVector *qiov);
|
---|
258 | void qemu_iovec_reset(QEMUIOVector *qiov);
|
---|
259 | void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
|
---|
260 | void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
|
---|
261 |
|
---|
262 | struct Monitor;
|
---|
263 | typedef struct Monitor Monitor;
|
---|
264 |
|
---|
265 | #include "module.h"
|
---|
266 |
|
---|
267 | #endif /* dyngen-exec.h hack */
|
---|
268 |
|
---|
269 | #endif /* !VBOX */
|
---|
270 |
|
---|
271 | #endif
|
---|