VirtualBox

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

最後變更 在這個檔案從37675是 37675,由 vboxsync 提交於 13 年 前

rem: Synced with v0.12.5.

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

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