VirtualBox

source: vbox/trunk/src/recompiler/osdep.h@ 25722

最後變更 在這個檔案從25722是 17274,由 vboxsync 提交於 16 年 前

REM: fixed #3525 - avoid using HVA -> GPA PGM function, store GPA in REM TLB instead

  • 屬性 svn:eol-style 設為 native
檔案大小: 4.9 KB
 
1#ifndef QEMU_OSDEP_H
2#define QEMU_OSDEP_H
3
4#ifdef VBOX
5
6#include <iprt/alloc.h>
7#ifndef RT_OS_WINDOWS
8# include <iprt/alloca.h>
9#endif
10#include <iprt/stdarg.h>
11#include <iprt/string.h>
12
13#include "config.h"
14
15#define VBOX_ONLY(x) x
16
17#ifndef _MSC_VER
18#define qemu_snprintf(pszBuf, cbBuf, ...) RTStrPrintf((pszBuf), (cbBuf), __VA_ARGS__)
19#else
20#define qemu_snprintf RTStrPrintf
21#endif
22#define qemu_vsnprintf(pszBuf, cbBuf, pszFormat, args) \
23 RTStrPrintfV((pszBuf), (cbBuf), (pszFormat), (args))
24#define qemu_vprintf(pszFormat, args) \
25 RTLogPrintfV((pszFormat), (args))
26#define qemu_printf RTLogPrintf
27#define qemu_malloc(cb) RTMemAlloc(cb)
28#define qemu_mallocz(cb) RTMemAllocZ(cb)
29#define qemu_realloc(ptr, cb) RTMemRealloc(ptr, cb)
30
31#define qemu_free(pv) RTMemFree(pv)
32#define qemu_strdup(psz) RTStrDup(psz)
33
34#define qemu_vmalloc(cb) RTMemPageAlloc(cb)
35#define qemu_vfree(pv) RTMemPageFree(pv)
36
37#ifndef NULL
38# define NULL 0
39#endif
40
41#define fflush(file) RTLogFlush(NULL)
42#define printf(...) LogIt(LOG_INSTANCE, 0, LOG_GROUP_REM_PRINTF, (__VA_ARGS__))
43/* If DEBUG_TMP_LOGGING - goes to QEMU log file */
44#ifndef DEBUG_TMP_LOGGING
45# define fprintf(logfile, ...) LogIt(LOG_INSTANCE, 0, LOG_GROUP_REM_PRINTF, (__VA_ARGS__))
46#endif
47
48#define assert(cond) Assert(cond)
49
50#else /* !VBOX */
51
52#include <stdarg.h>
53
54#define VBOX_ONLY(x)
55
56#define qemu_snprintf snprintf /* bird */
57#define qemu_vsnprintf vsnprintf /* bird */
58#define qemu_vprintf vprintf /* bird */
59
60#define qemu_printf printf
61
62void *qemu_malloc(size_t size);
63void *qemu_mallocz(size_t size);
64void qemu_free(void *ptr);
65char *qemu_strdup(const char *str);
66
67void *qemu_vmalloc(size_t size);
68void qemu_vfree(void *ptr);
69
70void *get_mmap_addr(unsigned long size);
71
72#endif /* !VBOX */
73
74#ifdef __OpenBSD__
75#include <sys/types.h>
76#include <sys/signal.h>
77#endif
78
79#ifndef glue
80#define xglue(x, y) x ## y
81#define glue(x, y) xglue(x, y)
82#define stringify(s) tostring(s)
83#define tostring(s) #s
84#endif
85
86#ifndef likely
87#ifndef VBOX
88#if __GNUC__ < 3
89#define __builtin_expect(x, n) (x)
90#endif
91
92#define likely(x) __builtin_expect(!!(x), 1)
93#define unlikely(x) __builtin_expect(!!(x), 0)
94#else /* VBOX */
95#define likely(cond) RT_LIKELY(cond)
96#define unlikely(cond) RT_UNLIKELY(cond)
97#endif
98#endif /* !likely */
99
100#ifndef offsetof
101#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
102#endif
103#ifndef container_of
104#define container_of(ptr, type, member) ({ \
105 const typeof(((type *) 0)->member) *__mptr = (ptr); \
106 (type *) ((char *) __mptr - offsetof(type, member));})
107#endif
108
109#ifndef MIN
110#define MIN(a, b) (((a) < (b)) ? (a) : (b))
111#endif
112#ifndef MAX
113#define MAX(a, b) (((a) > (b)) ? (a) : (b))
114#endif
115
116#ifndef ARRAY_SIZE
117#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
118#endif
119
120#ifndef always_inline
121#if (__GNUC__ < 3) || defined(__APPLE__)
122#define always_inline inline
123#else
124#define always_inline __attribute__ (( always_inline )) __inline__
125#define inline always_inline
126#endif
127#else
128#define inline always_inline
129#endif
130
131#ifdef __i386__
132#ifdef _MSC_VER
133/** @todo: maybe wrong, or slow */
134#define REGPARM
135#else
136#define REGPARM __attribute((regparm(3)))
137#endif
138#else
139#define REGPARM
140#endif
141
142#if defined (__GNUC__) && defined (__GNUC_MINOR_)
143# define QEMU_GNUC_PREREQ(maj, min) \
144 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
145#else
146# define QEMU_GNUC_PREREQ(maj, min) 0
147#endif
148
149#ifndef VBOX
150void *qemu_memalign(size_t alignment, size_t size);
151void *qemu_vmalloc(size_t size);
152void qemu_vfree(void *ptr);
153
154int qemu_create_pidfile(const char *filename);
155
156#ifdef _WIN32
157int ffs(int i);
158
159typedef struct {
160 long tv_sec;
161 long tv_usec;
162} qemu_timeval;
163int qemu_gettimeofday(qemu_timeval *tp);
164#else
165typedef struct timeval qemu_timeval;
166#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
167#endif /* !_WIN32 */
168#endif /* !VBOX */
169
170#ifdef VBOX
171#ifdef _MSC_VER
172#define ALIGNED_MEMBER(type, name, bytes) type name
173#define ALIGNED_MEMBER_DEF(type, name) type name
174#define PACKED_STRUCT(name) struct name
175#define REGISTER_BOUND_GLOBAL(type, var, reg) type var
176#define SAVE_GLOBAL_REGISTER(reg, var)
177#define RESTORE_GLOBAL_REGISTER(reg, var)
178#define DECLALWAYSINLINE(type) DECLINLINE(type)
179#define FORCE_RET() ;
180#else /* ! _MSC_VER */
181#define ALIGNED_MEMBER(type, name, bytes) type name __attribute__((aligned(bytes)))
182#define ALIGNED_MEMBER_DEF(type, name) type name __attribute__((aligned()))
183#define PACKED_STRUCT(name) struct __attribute__ ((__packed__)) name
184#define REGISTER_BOUND_GLOBAL(type, var, reg) register type var asm(reg)
185#define SAVE_GLOBAL_REGISTER(reg, var) __asm__ __volatile__ ("" : "=r" (var))
186#define RESTORE_GLOBAL_REGISTER(reg, var) __asm__ __volatile__ ("" : : "r" (var))
187#define DECLALWAYSINLINE(type) static always_inline type
188#define FORCE_RET() ;
189#endif /* !_MSC_VER */
190#endif /* VBOX */
191
192#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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