blob: dbc281f3bc0f7d3c2d5099233a6782ce5ea9612b [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
j_mayerdf2542c2007-11-19 00:38:33 +000010#ifndef glue
11#define xglue(x, y) x ## y
12#define glue(x, y) xglue(x, y)
13#define stringify(s) tostring(s)
14#define tostring(s) #s
15#endif
16
17#ifndef likely
18#if __GNUC__ < 3
19#define __builtin_expect(x, n) (x)
20#endif
21
22#define likely(x) __builtin_expect(!!(x), 1)
23#define unlikely(x) __builtin_expect(!!(x), 0)
24#endif
25
balrogac509d82008-09-16 13:36:57 +000026#ifndef offsetof
27#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
28#endif
29#ifndef container_of
aliguori62a6e3e2008-08-21 20:11:11 +000030#define container_of(ptr, type, member) ({ \
balrogac509d82008-09-16 13:36:57 +000031 const typeof(((type *) 0)->member) *__mptr = (ptr); \
32 (type *) ((char *) __mptr - offsetof(type, member));})
33#endif
aliguori62a6e3e2008-08-21 20:11:11 +000034
j_mayerdf2542c2007-11-19 00:38:33 +000035#ifndef MIN
36#define MIN(a, b) (((a) < (b)) ? (a) : (b))
37#endif
38#ifndef MAX
39#define MAX(a, b) (((a) > (b)) ? (a) : (b))
40#endif
41
blueswir10954d0d2008-03-11 21:01:02 +000042#ifndef ARRAY_SIZE
43#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
44#endif
45
j_mayerdf2542c2007-11-19 00:38:33 +000046#ifndef always_inline
47#if (__GNUC__ < 3) || defined(__APPLE__)
48#define always_inline inline
49#else
50#define always_inline __attribute__ (( always_inline )) __inline__
pbrook3dec6ec2008-11-19 01:31:52 +000051#ifdef __OPTIMIZE__
j_mayerdf2542c2007-11-19 00:38:33 +000052#define inline always_inline
thscebdff72008-06-05 22:55:54 +000053#endif
pbrook3dec6ec2008-11-19 01:31:52 +000054#endif
thscebdff72008-06-05 22:55:54 +000055#else
56#define inline always_inline
57#endif
j_mayerdf2542c2007-11-19 00:38:33 +000058
59#ifdef __i386__
bellardd6564692008-01-31 09:22:27 +000060#define REGPARM __attribute((regparm(3)))
j_mayerdf2542c2007-11-19 00:38:33 +000061#else
bellardd6564692008-01-31 09:22:27 +000062#define REGPARM
j_mayerdf2542c2007-11-19 00:38:33 +000063#endif
64
bellardd62ca2b2006-08-01 15:50:14 +000065#define qemu_printf printf
bellardea888122004-02-16 22:12:40 +000066
balrog80fe30e2008-12-01 01:53:55 +000067#if defined (__GNUC__) && defined (__GNUC_MINOR__)
aurel32bad5b1e2008-10-12 16:15:04 +000068# define QEMU_GNUC_PREREQ(maj, min) \
69 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
70#else
71# define QEMU_GNUC_PREREQ(maj, min) 0
72#endif
73
balrog33f00272007-12-24 14:33:24 +000074void *qemu_memalign(size_t alignment, size_t size);
bellard49b470e2005-02-10 21:59:25 +000075void *qemu_vmalloc(size_t size);
76void qemu_vfree(void *ptr);
77
thsaa26bb22007-03-25 21:33:06 +000078int qemu_create_pidfile(const char *filename);
79
pbrook29b3a662007-06-07 23:09:47 +000080#ifdef _WIN32
balrogc6d29ad2007-12-16 12:55:24 +000081int ffs(int i);
82
pbrook29b3a662007-06-07 23:09:47 +000083typedef struct {
84 long tv_sec;
85 long tv_usec;
86} qemu_timeval;
87int qemu_gettimeofday(qemu_timeval *tp);
88#else
89typedef struct timeval qemu_timeval;
90#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
91#endif /* !_WIN32 */
92
bellardea888122004-02-16 22:12:40 +000093#endif