VirtualBox

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

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

new REM works on Win/amd64 hosts

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