VirtualBox

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

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

intermediate

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