root / osdep.h @ f4918804
History | View | Annotate | Download (2.4 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 | aa26bb2d | ths | int qemu_create_pidfile(const char *filename); |
94 | aa26bb2d | ths | |
95 | 29b3a662 | pbrook | #ifdef _WIN32
|
96 | c6d29ad6 | balrog | int ffs(int i); |
97 | c6d29ad6 | balrog | |
98 | 29b3a662 | pbrook | typedef struct { |
99 | 29b3a662 | pbrook | long tv_sec;
|
100 | 29b3a662 | pbrook | long tv_usec;
|
101 | 29b3a662 | pbrook | } qemu_timeval; |
102 | 29b3a662 | pbrook | int qemu_gettimeofday(qemu_timeval *tp);
|
103 | 29b3a662 | pbrook | #else
|
104 | 29b3a662 | pbrook | typedef struct timeval qemu_timeval; |
105 | 29b3a662 | pbrook | #define qemu_gettimeofday(tp) gettimeofday(tp, NULL); |
106 | 29b3a662 | pbrook | #endif /* !_WIN32 */ |
107 | 29b3a662 | pbrook | |
108 | ea88812f | bellard | #endif |