VirtualBox

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

Last change on this file since 15310 was 14763, checked in by vboxsync, 16 years ago

does not work with Windows

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