root / osdep.h @ 333c574d
History | View | Annotate | Download (3.7 kB)
1 | ea88812f | bellard | #ifndef QEMU_OSDEP_H
|
---|---|---|---|
2 | ea88812f | bellard | #define QEMU_OSDEP_H
|
3 | ea88812f | bellard | |
4 | ea88812f | bellard | #include <stdarg.h> |
5 | de5071c5 | Blue Swirl | #include <stddef.h> |
6 | 128ab2ff | blueswir1 | #ifdef __OpenBSD__
|
7 | 128ab2ff | blueswir1 | #include <sys/types.h> |
8 | 128ab2ff | blueswir1 | #include <sys/signal.h> |
9 | 128ab2ff | blueswir1 | #endif
|
10 | ea88812f | bellard | |
11 | f7b4a940 | aliguori | #include <sys/time.h> |
12 | f7b4a940 | aliguori | |
13 | df2542c7 | j_mayer | #ifndef glue
|
14 | df2542c7 | j_mayer | #define xglue(x, y) x ## y |
15 | df2542c7 | j_mayer | #define glue(x, y) xglue(x, y)
|
16 | df2542c7 | j_mayer | #define stringify(s) tostring(s)
|
17 | df2542c7 | j_mayer | #define tostring(s) #s |
18 | df2542c7 | j_mayer | #endif
|
19 | df2542c7 | j_mayer | |
20 | df2542c7 | j_mayer | #ifndef likely
|
21 | df2542c7 | j_mayer | #if __GNUC__ < 3 |
22 | df2542c7 | j_mayer | #define __builtin_expect(x, n) (x)
|
23 | df2542c7 | j_mayer | #endif
|
24 | df2542c7 | j_mayer | |
25 | df2542c7 | j_mayer | #define likely(x) __builtin_expect(!!(x), 1) |
26 | df2542c7 | j_mayer | #define unlikely(x) __builtin_expect(!!(x), 0) |
27 | df2542c7 | j_mayer | #endif
|
28 | df2542c7 | j_mayer | |
29 | de5071c5 | Blue Swirl | #ifdef CONFIG_NEED_OFFSETOF
|
30 | ac509d88 | balrog | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) |
31 | ac509d88 | balrog | #endif
|
32 | ac509d88 | balrog | #ifndef container_of
|
33 | 62a6e3e1 | aliguori | #define container_of(ptr, type, member) ({ \
|
34 | ac509d88 | balrog | const typeof(((type *) 0)->member) *__mptr = (ptr); \ |
35 | ac509d88 | balrog | (type *) ((char *) __mptr - offsetof(type, member));})
|
36 | ac509d88 | balrog | #endif
|
37 | 62a6e3e1 | aliguori | |
38 | 5096fae3 | Mark McLoughlin | /* Convert from a base type to a parent type, with compile time checking. */
|
39 | 5096fae3 | Mark McLoughlin | #ifdef __GNUC__
|
40 | 5096fae3 | Mark McLoughlin | #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
|
41 | 5096fae3 | Mark McLoughlin | char __attribute__((unused)) offset_must_be_zero[ \
|
42 | 5096fae3 | Mark McLoughlin | -offsetof(type, field)]; \ |
43 | 5096fae3 | Mark McLoughlin | container_of(dev, type, field);})) |
44 | 5096fae3 | Mark McLoughlin | #else
|
45 | 5096fae3 | Mark McLoughlin | #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
|
46 | 5096fae3 | Mark McLoughlin | #endif
|
47 | 5096fae3 | Mark McLoughlin | |
48 | f0d99ad7 | Juan Quintela | #define typeof_field(type, field) typeof(((type *)0)->field) |
49 | f0d99ad7 | Juan Quintela | #define type_check(t1,t2) ((t1*)0 - (t2*)0) |
50 | f0d99ad7 | Juan Quintela | |
51 | df2542c7 | j_mayer | #ifndef MIN
|
52 | df2542c7 | j_mayer | #define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
53 | df2542c7 | j_mayer | #endif
|
54 | df2542c7 | j_mayer | #ifndef MAX
|
55 | df2542c7 | j_mayer | #define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
56 | df2542c7 | j_mayer | #endif
|
57 | df2542c7 | j_mayer | |
58 | e0e53b2f | Corentin Chary | #ifndef DIV_ROUND_UP
|
59 | e0e53b2f | Corentin Chary | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
60 | e0e53b2f | Corentin Chary | #endif
|
61 | e0e53b2f | Corentin Chary | |
62 | 0954d0d9 | blueswir1 | #ifndef ARRAY_SIZE
|
63 | 0954d0d9 | blueswir1 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
64 | 0954d0d9 | blueswir1 | #endif
|
65 | 0954d0d9 | blueswir1 | |
66 | df2542c7 | j_mayer | #ifndef always_inline
|
67 | 636aa200 | Blue Swirl | #if !((__GNUC__ < 3) || defined(__APPLE__)) |
68 | 3dec6ecd | pbrook | #ifdef __OPTIMIZE__
|
69 | 636aa200 | Blue Swirl | #define inline __attribute__ (( always_inline )) __inline__ |
70 | df2542c7 | j_mayer | #endif
|
71 | 3dec6ecd | pbrook | #endif
|
72 | cebdff77 | ths | #else
|
73 | df2542c7 | j_mayer | #define inline always_inline |
74 | cebdff77 | ths | #endif
|
75 | df2542c7 | j_mayer | |
76 | df2542c7 | j_mayer | #ifdef __i386__
|
77 | d656469f | bellard | #define REGPARM __attribute((regparm(3))) |
78 | df2542c7 | j_mayer | #else
|
79 | d656469f | bellard | #define REGPARM
|
80 | df2542c7 | j_mayer | #endif
|
81 | df2542c7 | j_mayer | |
82 | d62ca2bb | bellard | #define qemu_printf printf
|
83 | ea88812f | bellard | |
84 | 80fe30ed | balrog | #if defined (__GNUC__) && defined (__GNUC_MINOR__)
|
85 | bad5b1ec | aurel32 | # define QEMU_GNUC_PREREQ(maj, min) \
|
86 | bad5b1ec | aurel32 | ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) |
87 | bad5b1ec | aurel32 | #else
|
88 | bad5b1ec | aurel32 | # define QEMU_GNUC_PREREQ(maj, min) 0 |
89 | bad5b1ec | aurel32 | #endif
|
90 | bad5b1ec | aurel32 | |
91 | f97742d0 | Alexandre Raymond | int qemu_daemon(int nochdir, int noclose); |
92 | 33f00271 | balrog | void *qemu_memalign(size_t alignment, size_t size);
|
93 | 49b470eb | bellard | void *qemu_vmalloc(size_t size);
|
94 | 49b470eb | bellard | void qemu_vfree(void *ptr); |
95 | ea88812f | bellard | |
96 | e78815a5 | Andreas Färber | #define QEMU_MADV_INVALID -1 |
97 | e78815a5 | Andreas Färber | |
98 | e78815a5 | Andreas Färber | #if defined(CONFIG_MADVISE)
|
99 | e78815a5 | Andreas Färber | |
100 | e78815a5 | Andreas Färber | #define QEMU_MADV_WILLNEED MADV_WILLNEED
|
101 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTNEED MADV_DONTNEED
|
102 | e78815a5 | Andreas Färber | #ifdef MADV_DONTFORK
|
103 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTFORK MADV_DONTFORK
|
104 | e78815a5 | Andreas Färber | #else
|
105 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
|
106 | e78815a5 | Andreas Färber | #endif
|
107 | e78815a5 | Andreas Färber | #ifdef MADV_MERGEABLE
|
108 | e78815a5 | Andreas Färber | #define QEMU_MADV_MERGEABLE MADV_MERGEABLE
|
109 | e78815a5 | Andreas Färber | #else
|
110 | e78815a5 | Andreas Färber | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
|
111 | e78815a5 | Andreas Färber | #endif
|
112 | e78815a5 | Andreas Färber | |
113 | e78815a5 | Andreas Färber | #elif defined(CONFIG_POSIX_MADVISE)
|
114 | e78815a5 | Andreas Färber | |
115 | e78815a5 | Andreas Färber | #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED
|
116 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED
|
117 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
|
118 | e78815a5 | Andreas Färber | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
|
119 | e78815a5 | Andreas Färber | |
120 | e78815a5 | Andreas Färber | #else /* no-op */ |
121 | e78815a5 | Andreas Färber | |
122 | e78815a5 | Andreas Färber | #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID
|
123 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID
|
124 | e78815a5 | Andreas Färber | #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
|
125 | e78815a5 | Andreas Färber | #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
|
126 | e78815a5 | Andreas Färber | |
127 | e78815a5 | Andreas Färber | #endif
|
128 | e78815a5 | Andreas Färber | |
129 | e78815a5 | Andreas Färber | int qemu_madvise(void *addr, size_t len, int advice); |
130 | e78815a5 | Andreas Färber | |
131 | 953ffe0f | Andreas Färber | #if defined(__HAIKU__) && defined(__i386__)
|
132 | 953ffe0f | Andreas Färber | #define FMT_pid "%ld" |
133 | 953ffe0f | Andreas Färber | #else
|
134 | 953ffe0f | Andreas Färber | #define FMT_pid "%d" |
135 | 953ffe0f | Andreas Färber | #endif
|
136 | 953ffe0f | Andreas Färber | |
137 | aa26bb2d | ths | int qemu_create_pidfile(const char *filename); |
138 | dc7a09cf | Jan Kiszka | int qemu_get_thread_id(void); |
139 | aa26bb2d | ths | |
140 | ad620c29 | Blue Swirl | #ifdef _WIN32
|
141 | ad620c29 | Blue Swirl | static inline void qemu_timersub(const struct timeval *val1, |
142 | ad620c29 | Blue Swirl | const struct timeval *val2, |
143 | ad620c29 | Blue Swirl | struct timeval *res)
|
144 | ad620c29 | Blue Swirl | { |
145 | ad620c29 | Blue Swirl | res->tv_sec = val1->tv_sec - val2->tv_sec; |
146 | ad620c29 | Blue Swirl | if (val1->tv_usec < val2->tv_usec) {
|
147 | ad620c29 | Blue Swirl | res->tv_sec--; |
148 | ad620c29 | Blue Swirl | res->tv_usec = val1->tv_usec - val2->tv_usec + 1000 * 1000; |
149 | ad620c29 | Blue Swirl | } else {
|
150 | ad620c29 | Blue Swirl | res->tv_usec = val1->tv_usec - val2->tv_usec; |
151 | ad620c29 | Blue Swirl | } |
152 | ad620c29 | Blue Swirl | } |
153 | ad620c29 | Blue Swirl | #else
|
154 | ad620c29 | Blue Swirl | #define qemu_timersub timersub
|
155 | ad620c29 | Blue Swirl | #endif
|
156 | ad620c29 | Blue Swirl | |
157 | ea88812f | bellard | #endif |