]>
git.proxmox.com Git - qemu.git/blob - include/qemu/osdep.h
9 #include <sys/signal.h>
15 #define WIFEXITED(x) 1
16 #define WEXITSTATUS(x) (x)
21 #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10
22 /* [u]int_fast*_t not in <sys/int_types.h> */
23 typedef unsigned char uint_fast8_t;
24 typedef unsigned int uint_fast16_t;
25 typedef signed int int_fast16_t;
29 #define xglue(x, y) x ## y
30 #define glue(x, y) xglue(x, y)
31 #define stringify(s) tostring(s)
32 #define tostring(s) #s
37 #define __builtin_expect(x, n) (x)
40 #define likely(x) __builtin_expect(!!(x), 1)
41 #define unlikely(x) __builtin_expect(!!(x), 0)
45 #define container_of(ptr, type, member) ({ \
46 const typeof(((type *) 0)->member) *__mptr = (ptr); \
47 (type *) ((char *) __mptr - offsetof(type, member));})
50 /* Convert from a base type to a parent type, with compile time checking. */
52 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
53 char __attribute__((unused)) offset_must_be_zero[ \
54 -offsetof(type, field)]; \
55 container_of(dev, type, field);}))
57 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
60 #define typeof_field(type, field) typeof(((type *)0)->field)
61 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
64 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
67 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
71 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
75 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
79 #if !((__GNUC__ < 3) || defined(__APPLE__))
82 #define inline __attribute__ (( always_inline )) __inline__
87 #define inline always_inline
90 #define qemu_printf printf
92 int qemu_daemon(int nochdir
, int noclose
);
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 #define QEMU_MADV_DONTDUMP MADV_DONTDUMP
116 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
119 #define QEMU_MADV_HUGEPAGE MADV_HUGEPAGE
121 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
124 #elif defined(CONFIG_POSIX_MADVISE)
126 #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED
127 #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED
128 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
129 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
130 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
131 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
135 #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID
136 #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID
137 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
138 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
139 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
140 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
144 int qemu_madvise(void *addr
, size_t len
, int advice
);
146 int qemu_open(const char *name
, int flags
, ...);
147 int qemu_close(int fd
);
149 #if defined(__HAIKU__) && defined(__i386__)
150 #define FMT_pid "%ld"
152 #define FMT_pid "%" PRId64
157 int qemu_create_pidfile(const char *filename
);
158 int qemu_get_thread_id(void);
161 static inline void qemu_timersub(const struct timeval
*val1
,
162 const struct timeval
*val2
,
165 res
->tv_sec
= val1
->tv_sec
- val2
->tv_sec
;
166 if (val1
->tv_usec
< val2
->tv_usec
) {
168 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
+ 1000 * 1000;
170 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
;
174 #define qemu_timersub timersub
177 void qemu_set_cloexec(int fd
);
179 void qemu_set_version(const char *);
180 const char *qemu_get_version(void);
182 void fips_set_state(bool requested
);
183 bool fips_get_state(void);