1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#ifndef QEMU_OSDEP_H
#define QEMU_OSDEP_H
#ifdef VBOX /** @todo clean up this, it's not fully synched. */
#include <iprt/alloc.h>
#ifndef RT_OS_WINDOWS
# include <iprt/alloca.h>
#endif
#include <iprt/stdarg.h>
#include <iprt/string.h>
#include "config.h"
#define VBOX_ONLY(x) x
#define qemu_snprintf(pszBuf, cbBuf, ...) RTStrPrintf((pszBuf), (cbBuf), __VA_ARGS__)
#define qemu_vsnprintf(pszBuf, cbBuf, pszFormat, args) \
RTStrPrintfV((pszBuf), (cbBuf), (pszFormat), (args))
#define qemu_vprintf(pszFormat, args) \
RTLogPrintfV((pszFormat), (args))
/**@todo the following macros belongs elsewhere */
#define qemu_malloc(cb) RTMemAlloc(cb)
#define qemu_mallocz(cb) RTMemAllocZ(cb)
#define qemu_realloc(ptr, cb) RTMemRealloc(ptr, cb)
#define qemu_free(pv) RTMemFree(pv)
#define qemu_strdup(psz) RTStrDup(psz)
/* Misc wrappers */
#define fflush(file) RTLogFlush(NULL)
#define printf(...) LogIt(0, LOG_GROUP_REM_PRINTF, (__VA_ARGS__))
/* If DEBUG_TMP_LOGGING - goes to QEMU log file */
#ifndef DEBUG_TMP_LOGGING
# define fprintf(logfile, ...) LogIt(0, LOG_GROUP_REM_PRINTF, (__VA_ARGS__))
#endif
#define assert(cond) Assert(cond)
#else /* !VBOX */
#include <stdarg.h>
#include <stddef.h>
#define VBOX_ONLY(x) /* nike */
#define qemu_snprintf snprintf /* bird */
#define qemu_vsnprintf vsnprintf /* bird */
#define qemu_vprintf vprintf /* bird */
#endif /* !VBOX */
#ifdef __OpenBSD__
#include <sys/types.h>
#include <sys/signal.h>
#endif
#ifndef VBOX
#ifndef _WIN32
#include <sys/time.h>
#endif
#endif /* !VBOX */
#ifndef glue
#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
#define stringify(s) tostring(s)
#define tostring(s) #s
#endif
#ifndef likely
#if __GNUC__ < 3
#define __builtin_expect(x, n) (x)
#endif
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
#ifdef CONFIG_NEED_OFFSETOF
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof(((type *) 0)->member) *__mptr = (ptr); \
(type *) ((char *) __mptr - offsetof(type, member));})
#endif
/* Convert from a base type to a parent type, with compile time checking. */
#ifdef __GNUC__
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
char __attribute__((unused)) offset_must_be_zero[ \
-offsetof(type, field)]; \
container_of(dev, type, field);}))
#else
#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
#endif
#define typeof_field(type, field) typeof(((type *)0)->field)
#define type_check(t1,t2) ((t1*)0 - (t2*)0)
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
#ifndef always_inline
#if !((__GNUC__ < 3) || defined(__APPLE__))
#ifdef __OPTIMIZE__
#define inline __attribute__ (( always_inline )) __inline__
#endif
#endif
#else
#define inline always_inline
#endif
#ifdef __i386__
#define REGPARM __attribute((regparm(3)))
#else
#define REGPARM
#endif
#ifndef VBOX
#define qemu_printf printf
#else /*VBOX*/
#define qemu_printf RTLogPrintf
#endif /*VBOX*/
#if defined (__GNUC__) && defined (__GNUC_MINOR__)
# define QEMU_GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define QEMU_GNUC_PREREQ(maj, min) 0
#endif
#ifndef VBOX
void *qemu_memalign(size_t alignment, size_t size);
void *qemu_vmalloc(size_t size);
void qemu_vfree(void *ptr);
int qemu_create_pidfile(const char *filename);
#ifdef _WIN32
int ffs(int i);
typedef struct {
long tv_sec;
long tv_usec;
} qemu_timeval;
int qemu_gettimeofday(qemu_timeval *tp);
#else
typedef struct timeval qemu_timeval;
#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
#endif /* !_WIN32 */
#else /* VBOX */
# define qemu_memalign(alignment, size) ( (alignment) <= PAGE_SIZE ? RTMemPageAlloc((size)) : NULL )
# define qemu_vfree(pv) RTMemPageFree(pv, missing_size_parameter)
# define qemu_vmalloc(cb) RTMemPageAlloc(cb)
#endif /* VBOX */
#endif
|