8 #include <sys/signal.h>
14 #define xglue(x, y) x ## y
15 #define glue(x, y) xglue(x, y)
16 #define stringify(s) tostring(s)
17 #define tostring(s) #s
22 #define __builtin_expect(x, n) (x)
25 #define likely(x) __builtin_expect(!!(x), 1)
26 #define unlikely(x) __builtin_expect(!!(x), 0)
30 #define container_of(ptr, type, member) ({ \
31 const typeof(((type *) 0)->member) *__mptr = (ptr); \
32 (type *) ((char *) __mptr - offsetof(type, member));})
35 /* Convert from a base type to a parent type, with compile time checking. */
37 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
38 char __attribute__((unused)) offset_must_be_zero[ \
39 -offsetof(type, field)]; \
40 container_of(dev, type, field);}))
42 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
45 #define typeof_field(type, field) typeof(((type *)0)->field)
46 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
49 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
52 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
56 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
60 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
64 #if !((__GNUC__ < 3) || defined(__APPLE__))
66 #define inline __attribute__ (( always_inline )) __inline__
70 #define inline always_inline
74 #define REGPARM __attribute((regparm(3)))
79 #define qemu_printf printf
81 int qemu_daemon(int nochdir
, int noclose
);
82 void *qemu_memalign(size_t alignment
, size_t size
);
83 void *qemu_vmalloc(size_t size
);
84 void qemu_vfree(void *ptr
);
86 #define QEMU_MADV_INVALID -1
88 #if defined(CONFIG_MADVISE)
90 #define QEMU_MADV_WILLNEED MADV_WILLNEED
91 #define QEMU_MADV_DONTNEED MADV_DONTNEED
93 #define QEMU_MADV_DONTFORK MADV_DONTFORK
95 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
98 #define QEMU_MADV_MERGEABLE MADV_MERGEABLE
100 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
103 #elif defined(CONFIG_POSIX_MADVISE)
105 #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED
106 #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED
107 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
108 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
112 #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID
113 #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID
114 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
115 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
119 int qemu_madvise(void *addr
, size_t len
, int advice
);
121 #if defined(__HAIKU__) && defined(__i386__)
122 #define FMT_pid "%ld"
124 #define FMT_pid "%" PRId64
129 int qemu_create_pidfile(const char *filename
);
130 int qemu_get_thread_id(void);
133 static inline void qemu_timersub(const struct timeval
*val1
,
134 const struct timeval
*val2
,
137 res
->tv_sec
= val1
->tv_sec
- val2
->tv_sec
;
138 if (val1
->tv_usec
< val2
->tv_usec
) {
140 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
+ 1000 * 1000;
142 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
;
146 #define qemu_timersub timersub