8 #include <sys/signal.h>
16 #define xglue(x, y) x ## y
17 #define glue(x, y) xglue(x, y)
18 #define stringify(s) tostring(s)
19 #define tostring(s) #s
24 #define __builtin_expect(x, n) (x)
27 #define likely(x) __builtin_expect(!!(x), 1)
28 #define unlikely(x) __builtin_expect(!!(x), 0)
31 #ifdef CONFIG_NEED_OFFSETOF
32 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
35 #define container_of(ptr, type, member) ({ \
36 const typeof(((type *) 0)->member) *__mptr = (ptr); \
37 (type *) ((char *) __mptr - offsetof(type, member));})
40 /* Convert from a base type to a parent type, with compile time checking. */
42 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
43 char __attribute__((unused)) offset_must_be_zero[ \
44 -offsetof(type, field)]; \
45 container_of(dev, type, field);}))
47 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
50 #define typeof_field(type, field) typeof(((type *)0)->field)
51 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
54 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
57 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
61 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
69 #if !((__GNUC__ < 3) || defined(__APPLE__))
71 #define inline __attribute__ (( always_inline )) __inline__
75 #define inline always_inline
79 #define REGPARM __attribute((regparm(3)))
84 #define qemu_printf printf
86 #if defined (__GNUC__) && defined (__GNUC_MINOR__)
87 # define QEMU_GNUC_PREREQ(maj, min) \
88 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
90 # define QEMU_GNUC_PREREQ(maj, min) 0
93 void *qemu_memalign(size_t alignment
, size_t size
);
94 void *qemu_vmalloc(size_t size
);
95 void qemu_vfree(void *ptr
);
97 #define QEMU_MADV_INVALID -1
99 #if defined(CONFIG_MADVISE)
101 #define QEMU_MADV_WILLNEED MADV_WILLNEED
102 #define QEMU_MADV_DONTNEED MADV_DONTNEED
104 #define QEMU_MADV_DONTFORK MADV_DONTFORK
106 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
108 #ifdef MADV_MERGEABLE
109 #define QEMU_MADV_MERGEABLE MADV_MERGEABLE
111 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
114 #elif defined(CONFIG_POSIX_MADVISE)
116 #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED
117 #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED
118 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
119 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
123 #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID
124 #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID
125 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
126 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
130 int qemu_madvise(void *addr
, size_t len
, int advice
);
132 int qemu_create_pidfile(const char *filename
);