9 #include <sys/signal.h>
14 #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10
15 /* [u]int_fast*_t not in <sys/int_types.h> */
16 typedef unsigned char uint_fast8_t;
17 typedef unsigned int uint_fast16_t;
18 typedef signed int int_fast16_t;
22 #define xglue(x, y) x ## y
23 #define glue(x, y) xglue(x, y)
24 #define stringify(s) tostring(s)
25 #define tostring(s) #s
30 #define __builtin_expect(x, n) (x)
33 #define likely(x) __builtin_expect(!!(x), 1)
34 #define unlikely(x) __builtin_expect(!!(x), 0)
38 #define container_of(ptr, type, member) ({ \
39 const typeof(((type *) 0)->member) *__mptr = (ptr); \
40 (type *) ((char *) __mptr - offsetof(type, member));})
43 /* Convert from a base type to a parent type, with compile time checking. */
45 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
46 char __attribute__((unused)) offset_must_be_zero[ \
47 -offsetof(type, field)]; \
48 container_of(dev, type, field);}))
50 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
53 #define typeof_field(type, field) typeof(((type *)0)->field)
54 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
57 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
60 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
64 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
68 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
72 #if !((__GNUC__ < 3) || defined(__APPLE__))
75 #define inline __attribute__ (( always_inline )) __inline__
80 #define inline always_inline
83 #define qemu_printf printf
85 int qemu_daemon(int nochdir
, int noclose
);
86 void *qemu_memalign(size_t alignment
, size_t size
);
87 void *qemu_vmalloc(size_t size
);
88 void qemu_vfree(void *ptr
);
90 #define QEMU_MADV_INVALID -1
92 #if defined(CONFIG_MADVISE)
94 #define QEMU_MADV_WILLNEED MADV_WILLNEED
95 #define QEMU_MADV_DONTNEED MADV_DONTNEED
97 #define QEMU_MADV_DONTFORK MADV_DONTFORK
99 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
101 #ifdef MADV_MERGEABLE
102 #define QEMU_MADV_MERGEABLE MADV_MERGEABLE
104 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
107 #define QEMU_MADV_DONTDUMP MADV_DONTDUMP
109 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
112 #define QEMU_MADV_HUGEPAGE MADV_HUGEPAGE
114 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
117 #elif defined(CONFIG_POSIX_MADVISE)
119 #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED
120 #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED
121 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
122 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
123 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
124 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
128 #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID
129 #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID
130 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
131 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
132 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
133 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
137 int qemu_madvise(void *addr
, size_t len
, int advice
);
139 int qemu_open(const char *name
, int flags
, ...);
140 int qemu_close(int fd
);
142 #if defined(__HAIKU__) && defined(__i386__)
143 #define FMT_pid "%ld"
145 #define FMT_pid "%" PRId64
150 int qemu_create_pidfile(const char *filename
);
151 int qemu_get_thread_id(void);
154 static inline void qemu_timersub(const struct timeval
*val1
,
155 const struct timeval
*val2
,
158 res
->tv_sec
= val1
->tv_sec
- val2
->tv_sec
;
159 if (val1
->tv_usec
< val2
->tv_usec
) {
161 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
+ 1000 * 1000;
163 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
;
167 #define qemu_timersub timersub
170 void qemu_set_cloexec(int fd
);
172 void qemu_set_version(const char *);
173 const char *qemu_get_version(void);
175 void fips_set_state(bool requested
);
176 bool fips_get_state(void);