|
1
2
3
4
|
#ifndef QEMU_OSDEP_H
#define QEMU_OSDEP_H
#include <stdarg.h>
|
|
5
6
7
8
|
#ifdef __OpenBSD__
#include <sys/types.h>
#include <sys/signal.h>
#endif
|
|
9
|
|
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#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
|
|
26
27
28
29
|
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
#endif
#ifndef container_of
|
|
30
|
#define container_of(ptr, type, member) ({ \
|
|
31
32
33
|
const typeof(((type *) 0)->member) *__mptr = (ptr); \
(type *) ((char *) __mptr - offsetof(type, member));})
#endif
|
|
34
|
|
|
35
36
37
38
39
40
41
|
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
|
|
42
43
44
45
|
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
|
|
46
47
48
49
50
|
#ifndef always_inline
#if (__GNUC__ < 3) || defined(__APPLE__)
#define always_inline inline
#else
#define always_inline __attribute__ (( always_inline )) __inline__
|
|
51
|
#ifdef __OPTIMIZE__
|
ths
authored
|
52
|
#define inline always_inline
|
|
53
|
#endif
|
|
54
|
#endif
|
ths
authored
|
55
|
#else
|
|
56
|
#define inline always_inline
|
ths
authored
|
57
|
#endif
|
|
58
59
|
#ifdef __i386__
|
|
60
|
#define REGPARM __attribute((regparm(3)))
|
|
61
|
#else
|
|
62
|
#define REGPARM
|
|
63
64
|
#endif
|
|
65
|
#define qemu_printf printf
|
|
66
|
|
|
67
|
#if defined (__GNUC__) && defined (__GNUC_MINOR__)
|
|
68
69
70
71
72
73
|
# define QEMU_GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define QEMU_GNUC_PREREQ(maj, min) 0
#endif
|
|
74
|
void *qemu_memalign(size_t alignment, size_t size);
|
|
75
76
|
void *qemu_vmalloc(size_t size);
void qemu_vfree(void *ptr);
|
|
77
|
|
ths
authored
|
78
79
|
int qemu_create_pidfile(const char *filename);
|
|
80
|
#ifdef _WIN32
|
|
81
82
|
int ffs(int i);
|
|
83
84
85
86
87
88
89
90
91
92
|
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 */
|
|
93
|
#endif
|