VirtualBox

source: vbox/trunk/src/recompiler/osdep.h@ 36170

Last change on this file since 36170 was 36170, checked in by vboxsync, 14 years ago

rem: synced up to svn://svn.savannah.nongnu.org/qemu/trunk@6686 (repo UUID c046a42c-6fe2-441c-8c8c-71466251a162).

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1#ifndef QEMU_OSDEP_H
2#define QEMU_OSDEP_H
3
4#ifdef VBOX /** @todo clean up this, it's not fully synched. */
5
6#include <iprt/alloc.h>
7#ifndef RT_OS_WINDOWS
8# include <iprt/alloca.h>
9#endif
10#include <iprt/stdarg.h>
11#include <iprt/string.h>
12
13#include "config.h"
14
15#define VBOX_ONLY(x) x
16
17#define qemu_snprintf(pszBuf, cbBuf, ...) RTStrPrintf((pszBuf), (cbBuf), __VA_ARGS__)
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, missing_size_parameter)
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_TMP_LOGGING - goes to QEMU log file */
40#ifndef DEBUG_TMP_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 VBOX_ONLY(x)
51
52#define qemu_snprintf snprintf /* bird */
53#define qemu_vsnprintf vsnprintf /* bird */
54#define qemu_vprintf vprintf /* bird */
55
56#define qemu_printf printf
57
58void *qemu_malloc(size_t size);
59void *qemu_mallocz(size_t size);
60void qemu_free(void *ptr);
61char *qemu_strdup(const char *str);
62
63void *qemu_vmalloc(size_t size);
64void qemu_vfree(void *ptr);
65
66void *get_mmap_addr(unsigned long size);
67
68#endif /* !VBOX */
69
70#ifdef __OpenBSD__
71#include <sys/types.h>
72#include <sys/signal.h>
73#endif
74
75#ifndef glue
76#define xglue(x, y) x ## y
77#define glue(x, y) xglue(x, y)
78#define stringify(s) tostring(s)
79#define tostring(s) #s
80#endif
81
82#ifndef likely
83#if __GNUC__ < 3
84#define __builtin_expect(x, n) (x)
85#endif
86
87#define likely(x) __builtin_expect(!!(x), 1)
88#define unlikely(x) __builtin_expect(!!(x), 0)
89#endif
90
91#ifndef offsetof
92#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
93#endif
94#ifndef container_of
95#define container_of(ptr, type, member) ({ \
96 const typeof(((type *) 0)->member) *__mptr = (ptr); \
97 (type *) ((char *) __mptr - offsetof(type, member));})
98#endif
99
100#ifndef MIN
101#define MIN(a, b) (((a) < (b)) ? (a) : (b))
102#endif
103#ifndef MAX
104#define MAX(a, b) (((a) > (b)) ? (a) : (b))
105#endif
106
107#ifndef ARRAY_SIZE
108#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
109#endif
110
111#ifndef always_inline
112#if (__GNUC__ < 3) || defined(__APPLE__)
113#define always_inline inline
114#else
115#define always_inline __attribute__ (( always_inline )) __inline__
116#ifdef __OPTIMIZE__
117#define inline always_inline
118#endif
119#endif
120#else
121#define inline always_inline
122#endif
123
124#ifdef __i386__
125#define REGPARM __attribute((regparm(3)))
126#else
127#define REGPARM
128#endif
129
130#ifndef VBOX
131#define qemu_printf printf
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#else /* VBOX */
161# define qemu_memalign(alignment, size) ( (alignment) <= PAGE_SIZE ? RTMemPageAlloc((size)) : NULL )
162#endif /* VBOX */
163
164#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