VirtualBox

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

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

more cleanup, 32-bit mode still doesn't work.
Very hard to tell why.

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