8 #include <sys/signal.h>
13 #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10
14 /* [u]int_fast*_t not in <sys/int_types.h> */
15 typedef unsigned char uint_fast8_t;
16 typedef unsigned int uint_fast16_t;
17 typedef signed int int_fast16_t;
21 #define xglue(x, y) x ## y
22 #define glue(x, y) xglue(x, y)
23 #define stringify(s) tostring(s)
24 #define tostring(s) #s
29 #define __builtin_expect(x, n) (x)
32 #define likely(x) __builtin_expect(!!(x), 1)
33 #define unlikely(x) __builtin_expect(!!(x), 0)
37 #define container_of(ptr, type, member) ({ \
38 const typeof(((type *) 0)->member) *__mptr = (ptr); \
39 (type *) ((char *) __mptr - offsetof(type, member));})
42 /* Convert from a base type to a parent type, with compile time checking. */
44 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
45 char __attribute__((unused)) offset_must_be_zero[ \
46 -offsetof(type, field)]; \
47 container_of(dev, type, field);}))
49 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
52 #define typeof_field(type, field) typeof(((type *)0)->field)
53 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
56 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
59 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
63 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
67 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
71 #if !((__GNUC__ < 3) || defined(__APPLE__))
74 #define inline __attribute__ (( always_inline )) __inline__
79 #define inline always_inline
82 #define qemu_printf printf
84 int qemu_daemon(int nochdir
, int noclose
);
85 void *qemu_memalign(size_t alignment
, size_t size
);
86 void *qemu_vmalloc(size_t size
);
87 void qemu_vfree(void *ptr
);
89 #define QEMU_MADV_INVALID -1
91 #if defined(CONFIG_MADVISE)
93 #define QEMU_MADV_WILLNEED MADV_WILLNEED
94 #define QEMU_MADV_DONTNEED MADV_DONTNEED
96 #define QEMU_MADV_DONTFORK MADV_DONTFORK
98 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
100 #ifdef MADV_MERGEABLE
101 #define QEMU_MADV_MERGEABLE MADV_MERGEABLE
103 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
106 #elif defined(CONFIG_POSIX_MADVISE)
108 #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED
109 #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED
110 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
111 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
115 #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID
116 #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID
117 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
118 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
122 int qemu_madvise(void *addr
, size_t len
, int advice
);
124 #if defined(__HAIKU__) && defined(__i386__)
125 #define FMT_pid "%ld"
127 #define FMT_pid "%" PRId64
132 int qemu_create_pidfile(const char *filename
);
133 int qemu_get_thread_id(void);
136 static inline void qemu_timersub(const struct timeval
*val1
,
137 const struct timeval
*val2
,
140 res
->tv_sec
= val1
->tv_sec
- val2
->tv_sec
;
141 if (val1
->tv_usec
< val2
->tv_usec
) {
143 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
+ 1000 * 1000;
145 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
;
149 #define qemu_timersub timersub
152 void qemu_set_cloexec(int fd
);
154 void qemu_set_version(const char *);
155 const char *qemu_get_version(void);