VirtualBox

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

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