kvm: qemu: ftruncate() is not supported by hugetlbfs on older hosts
[kvm-userspace.git] / qemu / osdep.h
blobeb3198c78fc21e9c996e22f696bbb1d897577678
1 #ifndef QEMU_OSDEP_H
2 #define QEMU_OSDEP_H
4 #include <stdarg.h>
6 #ifndef glue
7 #define xglue(x, y) x ## y
8 #define glue(x, y) xglue(x, y)
9 #define stringify(s) tostring(s)
10 #define tostring(s) #s
11 #endif
13 #ifndef likely
14 #if __GNUC__ < 3
15 #define __builtin_expect(x, n) (x)
16 #endif
18 #define likely(x) __builtin_expect(!!(x), 1)
19 #define unlikely(x) __builtin_expect(!!(x), 0)
20 #endif
22 #ifndef MIN
23 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
24 #endif
25 #ifndef MAX
26 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
27 #endif
29 #ifndef ARRAY_SIZE
30 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31 #endif
33 #ifndef always_inline
34 #if (__GNUC__ < 3) || defined(__APPLE__)
35 #define always_inline inline
36 #else
37 #define always_inline __attribute__ (( always_inline )) __inline__
38 #endif
39 #endif
40 #define inline always_inline
42 #ifdef __i386__
43 #define REGPARM __attribute((regparm(3)))
44 #else
45 #define REGPARM
46 #endif
48 #define qemu_printf printf
50 void *qemu_malloc(size_t size);
51 void *qemu_mallocz(size_t size);
52 void qemu_free(void *ptr);
53 char *qemu_strdup(const char *str);
55 void *qemu_memalign(size_t alignment, size_t size);
56 void *qemu_vmalloc(size_t size);
57 void qemu_vfree(void *ptr);
59 void *get_mmap_addr(unsigned long size);
61 int qemu_create_pidfile(const char *filename);
63 #ifdef _WIN32
64 int ffs(int i);
66 typedef struct {
67 long tv_sec;
68 long tv_usec;
69 } qemu_timeval;
70 int qemu_gettimeofday(qemu_timeval *tp);
71 #else
72 typedef struct timeval qemu_timeval;
73 #define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
74 #endif /* !_WIN32 */
76 #endif