VirtualBox

source: vbox/trunk/src/recompiler/qemu-common.h@ 80024

Last change on this file since 80024 was 69465, checked in by vboxsync, 7 years ago

recompiler: scm updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 10.0 KB
Line 
1/* Common header file that is included by all of qemu. */
2#ifndef QEMU_COMMON_H
3#define QEMU_COMMON_H
4
5#include "config-host.h"
6
7#ifdef VBOX
8
9# include <iprt/string.h>
10# include <iprt/types.h>
11# include <iprt/ctype.h>
12
13void pstrcpy(char *buf, int buf_size, const char *str);
14char *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# define QEMU_NORETURN __attribute__((__noreturn__))
36# ifdef CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT
37# define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
38# else
39# define QEMU_WARN_UNUSED_RESULT
40# endif
41#define QEMU_BUILD_BUG_ON(x) typedef char __build_bug_on__##__LINE__[(x)?-1:1];
42
43#include <stdio.h>
44#include "cpu.h"
45
46
47#else /* !VBOX */
48#ifdef _WIN32
49#define WIN32_LEAN_AND_MEAN
50#define WINVER 0x0501 /* needed for ipv6 bits */
51#include <windows.h>
52#endif
53
54#define QEMU_NORETURN __attribute__ ((__noreturn__))
55#ifdef CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT
56#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
57#else
58#define QEMU_WARN_UNUSED_RESULT
59#endif
60
61#define QEMU_BUILD_BUG_ON(x) typedef char __build_bug_on__##__LINE__[(x)?-1:1];
62
63typedef struct QEMUTimer QEMUTimer;
64typedef struct QEMUFile QEMUFile;
65typedef struct QEMUBH QEMUBH;
66typedef struct DeviceState DeviceState;
67
68
69/* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
70 cannot include the following headers without conflicts. This condition has
71 to be removed once dyngen is gone. */
72#ifndef __DYNGEN_EXEC_H__
73
74/* we put basic includes here to avoid repeating them in device drivers */
75#include <stdlib.h>
76#include <stdio.h>
77#include <stdarg.h>
78#include <stdbool.h>
79#include <string.h>
80#include <strings.h>
81#include <inttypes.h>
82#include <limits.h>
83#include <time.h>
84#include <ctype.h>
85#include <errno.h>
86#include <unistd.h>
87#include <fcntl.h>
88#include <sys/stat.h>
89#include <assert.h>
90
91#ifndef O_LARGEFILE
92#define O_LARGEFILE 0
93#endif
94#ifndef O_BINARY
95#define O_BINARY 0
96#endif
97#ifndef MAP_ANONYMOUS
98#define MAP_ANONYMOUS MAP_ANON
99#endif
100#ifndef ENOMEDIUM
101#define ENOMEDIUM ENODEV
102#endif
103#if !defined(ENOTSUP)
104#define ENOTSUP 4096
105#endif
106
107#ifndef CONFIG_IOVEC
108#define CONFIG_IOVEC
109struct iovec {
110 void *iov_base;
111 size_t iov_len;
112};
113/*
114 * Use the same value as Linux for now.
115 */
116#define IOV_MAX 1024
117#else
118#include <sys/uio.h>
119#endif
120
121#ifdef _WIN32
122#define fsync _commit
123#define lseek _lseeki64
124extern int qemu_ftruncate64(int, int64_t);
125#define ftruncate qemu_ftruncate64
126
127static inline char *realpath(const char *path, char *resolved_path)
128{
129 _fullpath(resolved_path, path, _MAX_PATH);
130 return resolved_path;
131}
132
133#define PRId64 "I64d"
134#define PRIx64 "I64x"
135#define PRIu64 "I64u"
136#define PRIo64 "I64o"
137#endif
138
139/* FIXME: Remove NEED_CPU_H. */
140#ifndef NEED_CPU_H
141
142#include <setjmp.h>
143#include "osdep.h"
144#include "bswap.h"
145
146#else
147
148#include "cpu.h"
149
150#endif /* !defined(NEED_CPU_H) */
151
152/* bottom halves */
153typedef void QEMUBHFunc(void *opaque);
154
155void async_context_push(void);
156void async_context_pop(void);
157int get_async_context_id(void);
158
159QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
160void qemu_bh_schedule(QEMUBH *bh);
161/* Bottom halfs that are scheduled from a bottom half handler are instantly
162 * invoked. This can create an infinite loop if a bottom half handler
163 * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by
164 * ensuring that the bottom half isn't executed until the next main loop
165 * iteration.
166 */
167void qemu_bh_schedule_idle(QEMUBH *bh);
168void qemu_bh_cancel(QEMUBH *bh);
169void qemu_bh_delete(QEMUBH *bh);
170int qemu_bh_poll(void);
171void qemu_bh_update_timeout(int *timeout);
172
173uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
174
175void qemu_get_timedate(struct tm *tm, int offset);
176int qemu_timedate_diff(struct tm *tm);
177
178/* cutils.c */
179void pstrcpy(char *buf, int buf_size, const char *str);
180char *pstrcat(char *buf, int buf_size, const char *s);
181int strstart(const char *str, const char *val, const char **ptr);
182int stristart(const char *str, const char *val, const char **ptr);
183int qemu_strnlen(const char *s, int max_len);
184time_t mktimegm(struct tm *tm);
185int qemu_fls(int i);
186int qemu_fdatasync(int fd);
187int fcntl_setfl(int fd, int flag);
188
189/* path.c */
190void init_paths(const char *prefix);
191const char *path(const char *pathname);
192
193#define qemu_isalnum(c) isalnum((unsigned char)(c))
194#define qemu_isalpha(c) isalpha((unsigned char)(c))
195#define qemu_iscntrl(c) iscntrl((unsigned char)(c))
196#define qemu_isdigit(c) isdigit((unsigned char)(c))
197#define qemu_isgraph(c) isgraph((unsigned char)(c))
198#define qemu_islower(c) islower((unsigned char)(c))
199#define qemu_isprint(c) isprint((unsigned char)(c))
200#define qemu_ispunct(c) ispunct((unsigned char)(c))
201#define qemu_isspace(c) isspace((unsigned char)(c))
202#define qemu_isupper(c) isupper((unsigned char)(c))
203#define qemu_isxdigit(c) isxdigit((unsigned char)(c))
204#define qemu_tolower(c) tolower((unsigned char)(c))
205#define qemu_toupper(c) toupper((unsigned char)(c))
206#define qemu_isascii(c) isascii((unsigned char)(c))
207#define qemu_toascii(c) toascii((unsigned char)(c))
208
209void *qemu_malloc(size_t size);
210void *qemu_realloc(void *ptr, size_t size);
211void *qemu_mallocz(size_t size);
212void qemu_free(void *ptr);
213char *qemu_strdup(const char *str);
214char *qemu_strndup(const char *str, size_t size);
215
216void qemu_mutex_lock_iothread(void);
217void qemu_mutex_unlock_iothread(void);
218
219int qemu_open(const char *name, int flags, ...);
220ssize_t qemu_write_full(int fd, const void *buf, size_t count)
221 QEMU_WARN_UNUSED_RESULT;
222void qemu_set_cloexec(int fd);
223
224#ifndef _WIN32
225int qemu_eventfd(int pipefd[2]);
226int qemu_pipe(int pipefd[2]);
227#endif
228
229/* Error handling. */
230
231void QEMU_NORETURN hw_error(const char *fmt, ...)
232 __attribute__ ((__format__ (__printf__, 1, 2)));
233
234/* IO callbacks. */
235typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
236typedef int IOCanReadHandler(void *opaque);
237typedef void IOHandler(void *opaque);
238
239struct ParallelIOArg {
240 void *buffer;
241 int count;
242};
243
244typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
245
246/* A load of opaque types so that device init declarations don't have to
247 pull in all the real definitions. */
248typedef struct NICInfo NICInfo;
249typedef struct HCIInfo HCIInfo;
250typedef struct AudioState AudioState;
251typedef struct BlockDriverState BlockDriverState;
252typedef struct DisplayState DisplayState;
253typedef struct DisplayChangeListener DisplayChangeListener;
254typedef struct DisplaySurface DisplaySurface;
255typedef struct DisplayAllocator DisplayAllocator;
256typedef struct PixelFormat PixelFormat;
257typedef struct TextConsole TextConsole;
258typedef TextConsole QEMUConsole;
259typedef struct CharDriverState CharDriverState;
260typedef struct MACAddr MACAddr;
261typedef struct VLANState VLANState;
262typedef struct VLANClientState VLANClientState;
263typedef struct i2c_bus i2c_bus;
264typedef struct i2c_slave i2c_slave;
265typedef struct SMBusDevice SMBusDevice;
266typedef struct PCIHostState PCIHostState;
267typedef struct PCIExpressHost PCIExpressHost;
268typedef struct PCIBus PCIBus;
269typedef struct PCIDevice PCIDevice;
270typedef struct SerialState SerialState;
271typedef struct IRQState *qemu_irq;
272typedef struct PCMCIACardState PCMCIACardState;
273typedef struct MouseTransformInfo MouseTransformInfo;
274typedef struct uWireSlave uWireSlave;
275typedef struct I2SCodec I2SCodec;
276typedef struct SSIBus SSIBus;
277typedef struct EventNotifier EventNotifier;
278typedef struct VirtIODevice VirtIODevice;
279
280typedef uint64_t pcibus_t;
281
282void cpu_exec_init_all(unsigned long tb_size);
283
284/* CPU save/load. */
285void cpu_save(QEMUFile *f, void *opaque);
286int cpu_load(QEMUFile *f, void *opaque, int version_id);
287
288/* Force QEMU to stop what it's doing and service IO */
289void qemu_service_io(void);
290
291/* Force QEMU to process pending events */
292void qemu_notify_event(void);
293
294/* Unblock cpu */
295void qemu_cpu_kick(void *env);
296int qemu_cpu_self(void *env);
297
298/* work queue */
299struct qemu_work_item {
300 struct qemu_work_item *next;
301 void (*func)(void *data);
302 void *data;
303 int done;
304};
305
306#ifdef CONFIG_USER_ONLY
307#define qemu_init_vcpu(env) do { } while (0)
308#else
309void qemu_init_vcpu(void *env);
310#endif
311
312typedef struct QEMUIOVector {
313 struct iovec *iov;
314 int niov;
315 int nalloc;
316 size_t size;
317} QEMUIOVector;
318
319void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
320void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
321void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
322void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
323void qemu_iovec_destroy(QEMUIOVector *qiov);
324void qemu_iovec_reset(QEMUIOVector *qiov);
325void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
326void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
327
328struct Monitor;
329typedef struct Monitor Monitor;
330
331/* Convert a byte between binary and BCD. */
332static inline uint8_t to_bcd(uint8_t val)
333{
334 return ((val / 10) << 4) | (val % 10);
335}
336
337static inline uint8_t from_bcd(uint8_t val)
338{
339 return ((val >> 4) * 10) + (val & 0x0f);
340}
341
342#include "module.h"
343
344#endif /* dyngen-exec.h hack */
345
346#endif /* !VBOX */
347
348#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette