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