osdep.h 2.0 KB
Newer Older
1 2 3 4
#ifndef QEMU_OSDEP_H
#define QEMU_OSDEP_H

#include <stdarg.h>
5 6 7 8
#ifdef __OpenBSD__
#include <sys/types.h>
#include <sys/signal.h>
#endif
9

10 11 12 13
#ifndef _WIN32
#include <sys/time.h>
#endif

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#ifndef glue
#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
#define stringify(s)	tostring(s)
#define tostring(s)	#s
#endif

#ifndef likely
#if __GNUC__ < 3
#define __builtin_expect(x, n) (x)
#endif

#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x)   __builtin_expect(!!(x), 0)
#endif

30 31 32 33
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
#endif
#ifndef container_of
34
#define container_of(ptr, type, member) ({                      \
35 36 37
        const typeof(((type *) 0)->member) *__mptr = (ptr);     \
        (type *) ((char *) __mptr - offsetof(type, member));})
#endif
38

39 40 41
#define typeof_field(type, field) typeof(((type *)0)->field)
#define type_check(t1,t2) ((t1*)0 - (t2*)0)

42 43 44 45 46 47 48
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif

49 50 51 52
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif

53
#ifndef always_inline
B
Blue Swirl 已提交
54
#if !((__GNUC__ < 3) || defined(__APPLE__))
P
pbrook 已提交
55
#ifdef __OPTIMIZE__
B
Blue Swirl 已提交
56
#define inline __attribute__ (( always_inline )) __inline__
57
#endif
P
pbrook 已提交
58
#endif
59
#else
60
#define inline always_inline
61
#endif
62 63

#ifdef __i386__
64
#define REGPARM __attribute((regparm(3)))
65
#else
66
#define REGPARM
67 68
#endif

B
bellard 已提交
69
#define qemu_printf printf
70

71
#if defined (__GNUC__) && defined (__GNUC_MINOR__)
A
aurel32 已提交
72 73 74 75 76 77
# define QEMU_GNUC_PREREQ(maj, min) \
         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define QEMU_GNUC_PREREQ(maj, min) 0
#endif

78
void *qemu_memalign(size_t alignment, size_t size);
B
bellard 已提交
79 80
void *qemu_vmalloc(size_t size);
void qemu_vfree(void *ptr);
81

82 83
int qemu_create_pidfile(const char *filename);

P
pbrook 已提交
84
#ifdef _WIN32
85 86
int ffs(int i);

P
pbrook 已提交
87 88 89 90 91 92 93 94 95 96
typedef struct {
    long tv_sec;
    long tv_usec;
} qemu_timeval;
int qemu_gettimeofday(qemu_timeval *tp);
#else
typedef struct timeval qemu_timeval;
#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
#endif /* !_WIN32 */

97
#endif