VirtualBox

source: vbox/trunk/src/recompiler_new/osdep.h@ 14447

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

New REM compiles on Win/AMD64 (using wrapper yet), not tested if runs

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

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