VirtualBox

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

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

rem: Merged in changes from the branches/stable_0_10 (r7249).

  • 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 _WIN32
76#include <sys/time.h>
77#endif
78
79#ifndef glue
80#define xglue(x, y) x ## y
81#define glue(x, y) xglue(x, y)
82#define stringify(s) tostring(s)
83#define tostring(s) #s
84#endif
85
86#ifndef likely
87#if __GNUC__ < 3
88#define __builtin_expect(x, n) (x)
89#endif
90
91#define likely(x) __builtin_expect(!!(x), 1)
92#define unlikely(x) __builtin_expect(!!(x), 0)
93#endif
94
95#ifndef offsetof
96#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
97#endif
98#ifndef container_of
99#define container_of(ptr, type, member) ({ \
100 const typeof(((type *) 0)->member) *__mptr = (ptr); \
101 (type *) ((char *) __mptr - offsetof(type, member));})
102#endif
103
104#ifndef MIN
105#define MIN(a, b) (((a) < (b)) ? (a) : (b))
106#endif
107#ifndef MAX
108#define MAX(a, b) (((a) > (b)) ? (a) : (b))
109#endif
110
111#ifndef ARRAY_SIZE
112#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
113#endif
114
115#ifndef always_inline
116#if (__GNUC__ < 3) || defined(__APPLE__)
117#define always_inline inline
118#else
119#define always_inline __attribute__ (( always_inline )) __inline__
120#ifdef __OPTIMIZE__
121#define inline always_inline
122#endif
123#endif
124#else
125#define inline always_inline
126#endif
127
128#ifdef __i386__
129#define REGPARM __attribute((regparm(3)))
130#else
131#define REGPARM
132#endif
133
134#ifndef VBOX
135#define qemu_printf printf
136#endif
137
138#if defined (__GNUC__) && defined (__GNUC_MINOR__)
139# define QEMU_GNUC_PREREQ(maj, min) \
140 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
141#else
142# define QEMU_GNUC_PREREQ(maj, min) 0
143#endif
144
145#ifndef VBOX
146void *qemu_memalign(size_t alignment, size_t size);
147void *qemu_vmalloc(size_t size);
148void qemu_vfree(void *ptr);
149
150int qemu_create_pidfile(const char *filename);
151
152#ifdef _WIN32
153int ffs(int i);
154
155typedef struct {
156 long tv_sec;
157 long tv_usec;
158} qemu_timeval;
159int qemu_gettimeofday(qemu_timeval *tp);
160#else
161typedef struct timeval qemu_timeval;
162#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
163#endif /* !_WIN32 */
164#else /* VBOX */
165# define qemu_memalign(alignment, size) ( (alignment) <= PAGE_SIZE ? RTMemPageAlloc((size)) : NULL )
166#endif /* VBOX */
167
168#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette