]>
Commit | Line | Data |
---|---|---|
ea88812f FB |
1 | #ifndef QEMU_OSDEP_H |
2 | #define QEMU_OSDEP_H | |
3 | ||
4 | #include <stdarg.h> | |
128ab2ff BS |
5 | #ifdef __OpenBSD__ |
6 | #include <sys/types.h> | |
7 | #include <sys/signal.h> | |
8 | #endif | |
ea88812f | 9 | |
f7b4a940 AL |
10 | #ifndef _WIN32 |
11 | #include <sys/time.h> | |
12 | #endif | |
13 | ||
df2542c7 JM |
14 | #ifndef glue |
15 | #define xglue(x, y) x ## y | |
16 | #define glue(x, y) xglue(x, y) | |
17 | #define stringify(s) tostring(s) | |
18 | #define tostring(s) #s | |
19 | #endif | |
20 | ||
21 | #ifndef likely | |
22 | #if __GNUC__ < 3 | |
23 | #define __builtin_expect(x, n) (x) | |
24 | #endif | |
25 | ||
26 | #define likely(x) __builtin_expect(!!(x), 1) | |
27 | #define unlikely(x) __builtin_expect(!!(x), 0) | |
28 | #endif | |
29 | ||
ac509d88 AZ |
30 | #ifndef offsetof |
31 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) | |
32 | #endif | |
33 | #ifndef container_of | |
62a6e3e1 | 34 | #define container_of(ptr, type, member) ({ \ |
ac509d88 AZ |
35 | const typeof(((type *) 0)->member) *__mptr = (ptr); \ |
36 | (type *) ((char *) __mptr - offsetof(type, member));}) | |
37 | #endif | |
62a6e3e1 | 38 | |
df2542c7 JM |
39 | #ifndef MIN |
40 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) | |
41 | #endif | |
42 | #ifndef MAX | |
43 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) | |
44 | #endif | |
45 | ||
0954d0d9 BS |
46 | #ifndef ARRAY_SIZE |
47 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | |
48 | #endif | |
49 | ||
df2542c7 | 50 | #ifndef always_inline |
636aa200 | 51 | #if !((__GNUC__ < 3) || defined(__APPLE__)) |
3dec6ecd | 52 | #ifdef __OPTIMIZE__ |
636aa200 | 53 | #define inline __attribute__ (( always_inline )) __inline__ |
df2542c7 | 54 | #endif |
3dec6ecd | 55 | #endif |
cebdff77 | 56 | #else |
df2542c7 | 57 | #define inline always_inline |
cebdff77 | 58 | #endif |
df2542c7 JM |
59 | |
60 | #ifdef __i386__ | |
d656469f | 61 | #define REGPARM __attribute((regparm(3))) |
df2542c7 | 62 | #else |
d656469f | 63 | #define REGPARM |
df2542c7 JM |
64 | #endif |
65 | ||
d62ca2bb | 66 | #define qemu_printf printf |
ea88812f | 67 | |
80fe30ed | 68 | #if defined (__GNUC__) && defined (__GNUC_MINOR__) |
bad5b1ec AJ |
69 | # define QEMU_GNUC_PREREQ(maj, min) \ |
70 | ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) | |
71 | #else | |
72 | # define QEMU_GNUC_PREREQ(maj, min) 0 | |
73 | #endif | |
74 | ||
33f00271 | 75 | void *qemu_memalign(size_t alignment, size_t size); |
49b470eb FB |
76 | void *qemu_vmalloc(size_t size); |
77 | void qemu_vfree(void *ptr); | |
ea88812f | 78 | |
aa26bb2d TS |
79 | int qemu_create_pidfile(const char *filename); |
80 | ||
29b3a662 | 81 | #ifdef _WIN32 |
c6d29ad6 AZ |
82 | int ffs(int i); |
83 | ||
29b3a662 PB |
84 | typedef struct { |
85 | long tv_sec; | |
86 | long tv_usec; | |
87 | } qemu_timeval; | |
88 | int qemu_gettimeofday(qemu_timeval *tp); | |
89 | #else | |
90 | typedef struct timeval qemu_timeval; | |
91 | #define qemu_gettimeofday(tp) gettimeofday(tp, NULL); | |
92 | #endif /* !_WIN32 */ | |
93 | ||
ea88812f | 94 | #endif |