bellard | ea88812 | 2004-02-16 22:12:40 +0000 | [diff] [blame] | 1 | #ifndef QEMU_OSDEP_H |
| 2 | #define QEMU_OSDEP_H |
| 3 | |
| 4 | #include <stdarg.h> |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 5 | #ifdef __OpenBSD__ |
| 6 | #include <sys/types.h> |
| 7 | #include <sys/signal.h> |
| 8 | #endif |
bellard | ea88812 | 2004-02-16 22:12:40 +0000 | [diff] [blame] | 9 | |
j_mayer | df2542c | 2007-11-19 00:38:33 +0000 | [diff] [blame] | 10 | #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 | |
balrog | ac509d8 | 2008-09-16 13:36:57 +0000 | [diff] [blame] | 26 | #ifndef offsetof |
| 27 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) |
| 28 | #endif |
| 29 | #ifndef container_of |
aliguori | 62a6e3e | 2008-08-21 20:11:11 +0000 | [diff] [blame] | 30 | #define container_of(ptr, type, member) ({ \ |
balrog | ac509d8 | 2008-09-16 13:36:57 +0000 | [diff] [blame] | 31 | const typeof(((type *) 0)->member) *__mptr = (ptr); \ |
| 32 | (type *) ((char *) __mptr - offsetof(type, member));}) |
| 33 | #endif |
aliguori | 62a6e3e | 2008-08-21 20:11:11 +0000 | [diff] [blame] | 34 | |
j_mayer | df2542c | 2007-11-19 00:38:33 +0000 | [diff] [blame] | 35 | #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 | |
blueswir1 | 0954d0d | 2008-03-11 21:01:02 +0000 | [diff] [blame] | 42 | #ifndef ARRAY_SIZE |
| 43 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 44 | #endif |
| 45 | |
j_mayer | df2542c | 2007-11-19 00:38:33 +0000 | [diff] [blame] | 46 | #ifndef always_inline |
| 47 | #if (__GNUC__ < 3) || defined(__APPLE__) |
| 48 | #define always_inline inline |
| 49 | #else |
| 50 | #define always_inline __attribute__ (( always_inline )) __inline__ |
pbrook | 3dec6ec | 2008-11-19 01:31:52 +0000 | [diff] [blame] | 51 | #ifdef __OPTIMIZE__ |
j_mayer | df2542c | 2007-11-19 00:38:33 +0000 | [diff] [blame] | 52 | #define inline always_inline |
ths | cebdff7 | 2008-06-05 22:55:54 +0000 | [diff] [blame] | 53 | #endif |
pbrook | 3dec6ec | 2008-11-19 01:31:52 +0000 | [diff] [blame] | 54 | #endif |
ths | cebdff7 | 2008-06-05 22:55:54 +0000 | [diff] [blame] | 55 | #else |
| 56 | #define inline always_inline |
| 57 | #endif |
j_mayer | df2542c | 2007-11-19 00:38:33 +0000 | [diff] [blame] | 58 | |
| 59 | #ifdef __i386__ |
bellard | d656469 | 2008-01-31 09:22:27 +0000 | [diff] [blame] | 60 | #define REGPARM __attribute((regparm(3))) |
j_mayer | df2542c | 2007-11-19 00:38:33 +0000 | [diff] [blame] | 61 | #else |
bellard | d656469 | 2008-01-31 09:22:27 +0000 | [diff] [blame] | 62 | #define REGPARM |
j_mayer | df2542c | 2007-11-19 00:38:33 +0000 | [diff] [blame] | 63 | #endif |
| 64 | |
bellard | d62ca2b | 2006-08-01 15:50:14 +0000 | [diff] [blame] | 65 | #define qemu_printf printf |
bellard | ea88812 | 2004-02-16 22:12:40 +0000 | [diff] [blame] | 66 | |
balrog | 80fe30e | 2008-12-01 01:53:55 +0000 | [diff] [blame] | 67 | #if defined (__GNUC__) && defined (__GNUC_MINOR__) |
aurel32 | bad5b1e | 2008-10-12 16:15:04 +0000 | [diff] [blame] | 68 | # 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 | |
balrog | 33f0027 | 2007-12-24 14:33:24 +0000 | [diff] [blame] | 74 | void *qemu_memalign(size_t alignment, size_t size); |
bellard | 49b470e | 2005-02-10 21:59:25 +0000 | [diff] [blame] | 75 | void *qemu_vmalloc(size_t size); |
| 76 | void qemu_vfree(void *ptr); |
| 77 | |
ths | aa26bb2 | 2007-03-25 21:33:06 +0000 | [diff] [blame] | 78 | int qemu_create_pidfile(const char *filename); |
| 79 | |
pbrook | 29b3a66 | 2007-06-07 23:09:47 +0000 | [diff] [blame] | 80 | #ifdef _WIN32 |
balrog | c6d29ad | 2007-12-16 12:55:24 +0000 | [diff] [blame] | 81 | int ffs(int i); |
| 82 | |
pbrook | 29b3a66 | 2007-06-07 23:09:47 +0000 | [diff] [blame] | 83 | typedef struct { |
| 84 | long tv_sec; |
| 85 | long tv_usec; |
| 86 | } qemu_timeval; |
| 87 | int qemu_gettimeofday(qemu_timeval *tp); |
| 88 | #else |
| 89 | typedef struct timeval qemu_timeval; |
| 90 | #define qemu_gettimeofday(tp) gettimeofday(tp, NULL); |
| 91 | #endif /* !_WIN32 */ |
| 92 | |
bellard | ea88812 | 2004-02-16 22:12:40 +0000 | [diff] [blame] | 93 | #endif |