]>
git.proxmox.com Git - mirror_qemu.git/blob - include/qemu/osdep.h
eac7172bcb36b5fa4e27af9cf3e7525c1ba741d5
4 #include "config-host.h"
10 #include <sys/signal.h>
16 #define WIFEXITED(x) 1
17 #define WEXITSTATUS(x) (x)
22 #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10
23 /* [u]int_fast*_t not in <sys/int_types.h> */
24 typedef unsigned char uint_fast8_t;
25 typedef unsigned int uint_fast16_t;
26 typedef signed int int_fast16_t;
30 #define xglue(x, y) x ## y
31 #define glue(x, y) xglue(x, y)
32 #define stringify(s) tostring(s)
33 #define tostring(s) #s
38 #define __builtin_expect(x, n) (x)
41 #define likely(x) __builtin_expect(!!(x), 1)
42 #define unlikely(x) __builtin_expect(!!(x), 0)
46 #define container_of(ptr, type, member) ({ \
47 const typeof(((type *) 0)->member) *__mptr = (ptr); \
48 (type *) ((char *) __mptr - offsetof(type, member));})
51 /* Convert from a base type to a parent type, with compile time checking. */
53 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
54 char __attribute__((unused)) offset_must_be_zero[ \
55 -offsetof(type, field)]; \
56 container_of(dev, type, field);}))
58 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
61 #define typeof_field(type, field) typeof(((type *)0)->field)
62 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
65 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
68 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
72 #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
76 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
80 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
84 #if !((__GNUC__ < 3) || defined(__APPLE__))
87 #define inline __attribute__ (( always_inline )) __inline__
92 #define inline always_inline
95 #define qemu_printf printf
97 int qemu_daemon(int nochdir
, int noclose
);
98 void *qemu_memalign(size_t alignment
, size_t size
);
99 void *qemu_anon_ram_alloc(size_t size
);
100 void qemu_vfree(void *ptr
);
101 void qemu_anon_ram_free(void *ptr
, size_t size
);
103 #define QEMU_MADV_INVALID -1
105 #if defined(CONFIG_MADVISE)
107 #define QEMU_MADV_WILLNEED MADV_WILLNEED
108 #define QEMU_MADV_DONTNEED MADV_DONTNEED
110 #define QEMU_MADV_DONTFORK MADV_DONTFORK
112 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
114 #ifdef MADV_MERGEABLE
115 #define QEMU_MADV_MERGEABLE MADV_MERGEABLE
117 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
120 #define QEMU_MADV_DONTDUMP MADV_DONTDUMP
122 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
125 #define QEMU_MADV_HUGEPAGE MADV_HUGEPAGE
127 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
130 #elif defined(CONFIG_POSIX_MADVISE)
132 #define QEMU_MADV_WILLNEED POSIX_MADV_WILLNEED
133 #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED
134 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
135 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
136 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
137 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
141 #define QEMU_MADV_WILLNEED QEMU_MADV_INVALID
142 #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID
143 #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID
144 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
145 #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID
146 #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID
150 int qemu_madvise(void *addr
, size_t len
, int advice
);
152 int qemu_open(const char *name
, int flags
, ...);
153 int qemu_close(int fd
);
155 #if defined(__HAIKU__) && defined(__i386__)
156 #define FMT_pid "%ld"
158 #define FMT_pid "%" PRId64
163 int qemu_create_pidfile(const char *filename
);
164 int qemu_get_thread_id(void);
172 * Use the same value as Linux for now.
176 ssize_t
readv(int fd
, const struct iovec
*iov
, int iov_cnt
);
177 ssize_t
writev(int fd
, const struct iovec
*iov
, int iov_cnt
);
183 static inline void qemu_timersub(const struct timeval
*val1
,
184 const struct timeval
*val2
,
187 res
->tv_sec
= val1
->tv_sec
- val2
->tv_sec
;
188 if (val1
->tv_usec
< val2
->tv_usec
) {
190 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
+ 1000 * 1000;
192 res
->tv_usec
= val1
->tv_usec
- val2
->tv_usec
;
196 #define qemu_timersub timersub
199 void qemu_set_cloexec(int fd
);
201 void qemu_set_version(const char *);
202 const char *qemu_get_version(void);
204 void fips_set_state(bool requested
);
205 bool fips_get_state(void);
207 /* Return a dynamically allocated pathname denoting a file or directory that is
208 * appropriate for storing local state.
210 * @relative_pathname need not start with a directory separator; one will be
211 * added automatically.
213 * The caller is responsible for releasing the value returned with g_free()
216 char *qemu_get_local_state_pathname(const char *relative_pathname
);
220 * @type: the auxiliary vector key to lookup
222 * Search the auxiliary vector for @type, returning the value
223 * or 0 if @type is not present.
225 #if defined(CONFIG_GETAUXVAL) || defined(__linux__)
226 unsigned long qemu_getauxval(unsigned long type
);
228 static inline unsigned long qemu_getauxval(unsigned long type
) { return 0; }
233 * @envp: the third argument to main
235 * If supported and required, locate the auxiliary vector at program startup.
237 #if defined(CONFIG_GETAUXVAL) || !defined(__linux__)
238 static inline void qemu_init_auxval(char **envp
) { }
240 void qemu_init_auxval(char **envp
);
243 void qemu_set_tty_echo(int fd
, bool echo
);