VirtualBox

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

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

REM: segment forced sync, cleanups

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

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