blob: ffbf221d7f540f3aaf2f93a3e77d6032931c77b6 [file] [log] [blame]
bellardea888122004-02-16 22:12:40 +00001#ifndef QEMU_OSDEP_H
2#define QEMU_OSDEP_H
3
4#include <stdarg.h>
blueswir1128ab2f2008-08-15 18:33:42 +00005#ifdef __OpenBSD__
6#include <sys/types.h>
7#include <sys/signal.h>
8#endif
bellardea888122004-02-16 22:12:40 +00009
aliguorif7b4a942009-01-07 17:40:15 +000010#ifndef _WIN32
11#include <sys/time.h>
12#endif
13
j_mayerdf2542c2007-11-19 00:38:33 +000014#ifndef glue
15#define xglue(x, y) x ## y
16#define glue(x, y) xglue(x, y)
17#define stringify(s) tostring(s)
18#define tostring(s) #s
19#endif
20
21#ifndef likely
22#if __GNUC__ < 3
23#define __builtin_expect(x, n) (x)
24#endif
25
26#define likely(x) __builtin_expect(!!(x), 1)
27#define unlikely(x) __builtin_expect(!!(x), 0)
28#endif
29
balrogac509d82008-09-16 13:36:57 +000030#ifndef offsetof
31#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
32#endif
33#ifndef container_of
aliguori62a6e3e2008-08-21 20:11:11 +000034#define container_of(ptr, type, member) ({ \
balrogac509d82008-09-16 13:36:57 +000035 const typeof(((type *) 0)->member) *__mptr = (ptr); \
36 (type *) ((char *) __mptr - offsetof(type, member));})
37#endif
aliguori62a6e3e2008-08-21 20:11:11 +000038
j_mayerdf2542c2007-11-19 00:38:33 +000039#ifndef MIN
40#define MIN(a, b) (((a) < (b)) ? (a) : (b))
41#endif
42#ifndef MAX
43#define MAX(a, b) (((a) > (b)) ? (a) : (b))
44#endif
45
blueswir10954d0d2008-03-11 21:01:02 +000046#ifndef ARRAY_SIZE
47#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
48#endif
49
j_mayerdf2542c2007-11-19 00:38:33 +000050#ifndef always_inline
51#if (__GNUC__ < 3) || defined(__APPLE__)
52#define always_inline inline
53#else
54#define always_inline __attribute__ (( always_inline )) __inline__
pbrook3dec6ec2008-11-19 01:31:52 +000055#ifdef __OPTIMIZE__
j_mayerdf2542c2007-11-19 00:38:33 +000056#define inline always_inline
thscebdff72008-06-05 22:55:54 +000057#endif
pbrook3dec6ec2008-11-19 01:31:52 +000058#endif
thscebdff72008-06-05 22:55:54 +000059#else
60#define inline always_inline
61#endif
j_mayerdf2542c2007-11-19 00:38:33 +000062
63#ifdef __i386__
bellardd6564692008-01-31 09:22:27 +000064#define REGPARM __attribute((regparm(3)))
j_mayerdf2542c2007-11-19 00:38:33 +000065#else
bellardd6564692008-01-31 09:22:27 +000066#define REGPARM
j_mayerdf2542c2007-11-19 00:38:33 +000067#endif
68
bellardd62ca2b2006-08-01 15:50:14 +000069#define qemu_printf printf
bellardea888122004-02-16 22:12:40 +000070
balrog80fe30e2008-12-01 01:53:55 +000071#if defined (__GNUC__) && defined (__GNUC_MINOR__)
aurel32bad5b1e2008-10-12 16:15:04 +000072# define QEMU_GNUC_PREREQ(maj, min) \
73 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
74#else
75# define QEMU_GNUC_PREREQ(maj, min) 0
76#endif
77
balrog33f00272007-12-24 14:33:24 +000078void *qemu_memalign(size_t alignment, size_t size);
bellard49b470e2005-02-10 21:59:25 +000079void *qemu_vmalloc(size_t size);
80void qemu_vfree(void *ptr);
81
thsaa26bb22007-03-25 21:33:06 +000082int qemu_create_pidfile(const char *filename);
83
pbrook29b3a662007-06-07 23:09:47 +000084#ifdef _WIN32
balrogc6d29ad2007-12-16 12:55:24 +000085int ffs(int i);
86
pbrook29b3a662007-06-07 23:09:47 +000087typedef struct {
88 long tv_sec;
89 long tv_usec;
90} qemu_timeval;
91int qemu_gettimeofday(qemu_timeval *tp);
92#else
93typedef struct timeval qemu_timeval;
94#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
95#endif /* !_WIN32 */
96
bellardea888122004-02-16 22:12:40 +000097#endif