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