]>
Commit | Line | Data |
---|---|---|
ea88812f FB |
1 | #ifndef QEMU_OSDEP_H |
2 | #define QEMU_OSDEP_H | |
3 | ||
4 | #include <stdarg.h> | |
de5071c5 | 5 | #include <stddef.h> |
128ab2ff BS |
6 | #ifdef __OpenBSD__ |
7 | #include <sys/types.h> | |
8 | #include <sys/signal.h> | |
9 | #endif | |
ea88812f | 10 | |
f7b4a940 AL |
11 | #ifndef _WIN32 |
12 | #include <sys/time.h> | |
13 | #endif | |
14 | ||
df2542c7 JM |
15 | #ifndef glue |
16 | #define xglue(x, y) x ## y | |
17 | #define glue(x, y) xglue(x, y) | |
18 | #define stringify(s) tostring(s) | |
19 | #define tostring(s) #s | |
20 | #endif | |
21 | ||
22 | #ifndef likely | |
23 | #if __GNUC__ < 3 | |
24 | #define __builtin_expect(x, n) (x) | |
25 | #endif | |
26 | ||
27 | #define likely(x) __builtin_expect(!!(x), 1) | |
28 | #define unlikely(x) __builtin_expect(!!(x), 0) | |
29 | #endif | |
30 | ||
de5071c5 | 31 | #ifdef CONFIG_NEED_OFFSETOF |
ac509d88 AZ |
32 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) |
33 | #endif | |
34 | #ifndef container_of | |
62a6e3e1 | 35 | #define container_of(ptr, type, member) ({ \ |
ac509d88 AZ |
36 | const typeof(((type *) 0)->member) *__mptr = (ptr); \ |
37 | (type *) ((char *) __mptr - offsetof(type, member));}) | |
38 | #endif | |
62a6e3e1 | 39 | |
5096fae3 MM |
40 | /* Convert from a base type to a parent type, with compile time checking. */ |
41 | #ifdef __GNUC__ | |
42 | #define DO_UPCAST(type, field, dev) ( __extension__ ( { \ | |
43 | char __attribute__((unused)) offset_must_be_zero[ \ | |
44 | -offsetof(type, field)]; \ | |
45 | container_of(dev, type, field);})) | |
46 | #else | |
47 | #define DO_UPCAST(type, field, dev) container_of(dev, type, field) | |
48 | #endif | |
49 | ||
f0d99ad7 JQ |
50 | #define typeof_field(type, field) typeof(((type *)0)->field) |
51 | #define type_check(t1,t2) ((t1*)0 - (t2*)0) | |
52 | ||
df2542c7 JM |
53 | #ifndef MIN |
54 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) | |
55 | #endif | |
56 | #ifndef MAX | |
57 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) | |
58 | #endif | |
59 | ||
e0e53b2f CC |
60 | #ifndef DIV_ROUND_UP |
61 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | |
62 | #endif | |
63 | ||
0954d0d9 BS |
64 | #ifndef ARRAY_SIZE |
65 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | |
66 | #endif | |
67 | ||
df2542c7 | 68 | #ifndef always_inline |
636aa200 | 69 | #if !((__GNUC__ < 3) || defined(__APPLE__)) |
3dec6ecd | 70 | #ifdef __OPTIMIZE__ |
636aa200 | 71 | #define inline __attribute__ (( always_inline )) __inline__ |
df2542c7 | 72 | #endif |
3dec6ecd | 73 | #endif |
cebdff77 | 74 | #else |
df2542c7 | 75 | #define inline always_inline |
cebdff77 | 76 | #endif |
df2542c7 JM |
77 | |
78 | #ifdef __i386__ | |
d656469f | 79 | #define REGPARM __attribute((regparm(3))) |
df2542c7 | 80 | #else |
d656469f | 81 | #define REGPARM |
df2542c7 JM |
82 | #endif |
83 | ||
d62ca2bb | 84 | #define qemu_printf printf |
ea88812f | 85 | |
80fe30ed | 86 | #if defined (__GNUC__) && defined (__GNUC_MINOR__) |
bad5b1ec AJ |
87 | # define QEMU_GNUC_PREREQ(maj, min) \ |
88 | ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) | |
89 | #else | |
90 | # define QEMU_GNUC_PREREQ(maj, min) 0 | |
91 | #endif | |
92 | ||
33f00271 | 93 | void *qemu_memalign(size_t alignment, size_t size); |
49b470eb FB |
94 | void *qemu_vmalloc(size_t size); |
95 | void qemu_vfree(void *ptr); | |
ea88812f | 96 | |
e78815a5 AF |
97 | #define QEMU_MADV_INVALID -1 |
98 | ||
99 | #if defined(CONFIG_MADVISE) | |
100 | ||
101 | #define QEMU_MADV_WILLNEED MADV_WILLNEED | |
102 | #define QEMU_MADV_DONTNEED MADV_DONTNEED | |
103 | #ifdef MADV_DONTFORK | |
104 | #define QEMU_MADV_DONTFORK MADV_DONTFORK | |
105 | #else | |
106 | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID | |
107 | #endif | |
108 | #ifdef MADV_MERGEABLE | |
109 | #define QEMU_MADV_MERGEABLE MADV_MERGEABLE | |
110 | #else | |
111 | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID | |
112 | #endif | |
113 | ||
114 | #elif defined(CONFIG_POSIX_MADVISE) | |
115 | ||
116 | #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED | |
117 | #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED | |
118 | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID | |
119 | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID | |
120 | ||
121 | #else /* no-op */ | |
122 | ||
123 | #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID | |
124 | #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID | |
125 | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID | |
126 | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID | |
127 | ||
128 | #endif | |
129 | ||
130 | int qemu_madvise(void *addr, size_t len, int advice); | |
131 | ||
aa26bb2d TS |
132 | int qemu_create_pidfile(const char *filename); |
133 | ||
ea88812f | 134 | #endif |