root / osdep.h @ 6a90e308
History | View | Annotate | Download (2.1 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 | f0d99ad7 | Juan Quintela | #define typeof_field(type, field) typeof(((type *)0)->field) |
41 | f0d99ad7 | Juan Quintela | #define type_check(t1,t2) ((t1*)0 - (t2*)0) |
42 | f0d99ad7 | Juan Quintela | |
43 | df2542c7 | j_mayer | #ifndef MIN
|
44 | df2542c7 | j_mayer | #define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
45 | df2542c7 | j_mayer | #endif
|
46 | df2542c7 | j_mayer | #ifndef MAX
|
47 | df2542c7 | j_mayer | #define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
48 | df2542c7 | j_mayer | #endif
|
49 | df2542c7 | j_mayer | |
50 | 0954d0d9 | blueswir1 | #ifndef ARRAY_SIZE
|
51 | 0954d0d9 | blueswir1 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
52 | 0954d0d9 | blueswir1 | #endif
|
53 | 0954d0d9 | blueswir1 | |
54 | df2542c7 | j_mayer | #ifndef always_inline
|
55 | 636aa200 | Blue Swirl | #if !((__GNUC__ < 3) || defined(__APPLE__)) |
56 | 3dec6ecd | pbrook | #ifdef __OPTIMIZE__
|
57 | 636aa200 | Blue Swirl | #define inline __attribute__ (( always_inline )) __inline__ |
58 | df2542c7 | j_mayer | #endif
|
59 | 3dec6ecd | pbrook | #endif
|
60 | cebdff77 | ths | #else
|
61 | df2542c7 | j_mayer | #define inline always_inline |
62 | cebdff77 | ths | #endif
|
63 | df2542c7 | j_mayer | |
64 | df2542c7 | j_mayer | #ifdef __i386__
|
65 | d656469f | bellard | #define REGPARM __attribute((regparm(3))) |
66 | df2542c7 | j_mayer | #else
|
67 | d656469f | bellard | #define REGPARM
|
68 | df2542c7 | j_mayer | #endif
|
69 | df2542c7 | j_mayer | |
70 | d62ca2bb | bellard | #define qemu_printf printf
|
71 | ea88812f | bellard | |
72 | 80fe30ed | balrog | #if defined (__GNUC__) && defined (__GNUC_MINOR__)
|
73 | bad5b1ec | aurel32 | # define QEMU_GNUC_PREREQ(maj, min) \
|
74 | bad5b1ec | aurel32 | ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) |
75 | bad5b1ec | aurel32 | #else
|
76 | bad5b1ec | aurel32 | # define QEMU_GNUC_PREREQ(maj, min) 0 |
77 | bad5b1ec | aurel32 | #endif
|
78 | bad5b1ec | aurel32 | |
79 | 33f00271 | balrog | void *qemu_memalign(size_t alignment, size_t size);
|
80 | 49b470eb | bellard | void *qemu_vmalloc(size_t size);
|
81 | 49b470eb | bellard | void qemu_vfree(void *ptr); |
82 | ea88812f | bellard | |
83 | aa26bb2d | ths | int qemu_create_pidfile(const char *filename); |
84 | aa26bb2d | ths | |
85 | 29b3a662 | pbrook | #ifdef _WIN32
|
86 | c6d29ad6 | balrog | int ffs(int i); |
87 | c6d29ad6 | balrog | |
88 | 29b3a662 | pbrook | typedef struct { |
89 | 29b3a662 | pbrook | long tv_sec;
|
90 | 29b3a662 | pbrook | long tv_usec;
|
91 | 29b3a662 | pbrook | } qemu_timeval; |
92 | 29b3a662 | pbrook | int qemu_gettimeofday(qemu_timeval *tp);
|
93 | 29b3a662 | pbrook | #else
|
94 | 29b3a662 | pbrook | typedef struct timeval qemu_timeval; |
95 | 29b3a662 | pbrook | #define qemu_gettimeofday(tp) gettimeofday(tp, NULL); |
96 | 29b3a662 | pbrook | #endif /* !_WIN32 */ |
97 | 29b3a662 | pbrook | |
98 | ea88812f | bellard | #endif |