2004-02-17 06:12:40 +08:00
|
|
|
#ifndef QEMU_OSDEP_H
|
|
|
|
#define QEMU_OSDEP_H
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2009-09-12 17:58:46 +08:00
|
|
|
#include <stddef.h>
|
2008-08-16 02:33:42 +08:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#endif
|
2004-02-17 06:12:40 +08:00
|
|
|
|
2009-01-08 01:40:15 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2007-11-19 08:38:33 +08:00
|
|
|
#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
|
|
|
|
|
2009-09-12 17:58:46 +08:00
|
|
|
#ifdef CONFIG_NEED_OFFSETOF
|
2008-09-16 21:36:57 +08:00
|
|
|
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
|
|
|
|
#endif
|
|
|
|
#ifndef container_of
|
2008-08-22 04:11:11 +08:00
|
|
|
#define container_of(ptr, type, member) ({ \
|
2008-09-16 21:36:57 +08:00
|
|
|
const typeof(((type *) 0)->member) *__mptr = (ptr); \
|
|
|
|
(type *) ((char *) __mptr - offsetof(type, member));})
|
|
|
|
#endif
|
2008-08-22 04:11:11 +08:00
|
|
|
|
2009-08-21 01:42:19 +08:00
|
|
|
#define typeof_field(type, field) typeof(((type *)0)->field)
|
|
|
|
#define type_check(t1,t2) ((t1*)0 - (t2*)0)
|
|
|
|
|
2007-11-19 08:38:33 +08:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
2008-03-12 05:01:02 +08:00
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
#endif
|
|
|
|
|
2007-11-19 08:38:33 +08:00
|
|
|
#ifndef always_inline
|
2009-08-16 17:06:54 +08:00
|
|
|
#if !((__GNUC__ < 3) || defined(__APPLE__))
|
2008-11-19 09:31:52 +08:00
|
|
|
#ifdef __OPTIMIZE__
|
2009-08-16 17:06:54 +08:00
|
|
|
#define inline __attribute__ (( always_inline )) __inline__
|
2007-11-19 08:38:33 +08:00
|
|
|
#endif
|
2008-11-19 09:31:52 +08:00
|
|
|
#endif
|
2008-06-06 06:55:54 +08:00
|
|
|
#else
|
2007-11-19 08:38:33 +08:00
|
|
|
#define inline always_inline
|
2008-06-06 06:55:54 +08:00
|
|
|
#endif
|
2007-11-19 08:38:33 +08:00
|
|
|
|
|
|
|
#ifdef __i386__
|
2008-01-31 17:22:27 +08:00
|
|
|
#define REGPARM __attribute((regparm(3)))
|
2007-11-19 08:38:33 +08:00
|
|
|
#else
|
2008-01-31 17:22:27 +08:00
|
|
|
#define REGPARM
|
2007-11-19 08:38:33 +08:00
|
|
|
#endif
|
|
|
|
|
2006-08-01 23:50:14 +08:00
|
|
|
#define qemu_printf printf
|
2004-02-17 06:12:40 +08:00
|
|
|
|
2008-12-01 09:53:55 +08:00
|
|
|
#if defined (__GNUC__) && defined (__GNUC_MINOR__)
|
2008-10-13 00:15:04 +08:00
|
|
|
# define QEMU_GNUC_PREREQ(maj, min) \
|
|
|
|
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
|
|
|
#else
|
|
|
|
# define QEMU_GNUC_PREREQ(maj, min) 0
|
|
|
|
#endif
|
|
|
|
|
2007-12-24 22:33:24 +08:00
|
|
|
void *qemu_memalign(size_t alignment, size_t size);
|
2005-02-11 05:59:25 +08:00
|
|
|
void *qemu_vmalloc(size_t size);
|
|
|
|
void qemu_vfree(void *ptr);
|
2004-02-17 06:12:40 +08:00
|
|
|
|
2007-03-26 05:33:06 +08:00
|
|
|
int qemu_create_pidfile(const char *filename);
|
|
|
|
|
2007-06-08 07:09:47 +08:00
|
|
|
#ifdef _WIN32
|
2007-12-16 20:55:24 +08:00
|
|
|
int ffs(int i);
|
|
|
|
|
2007-06-08 07:09:47 +08:00
|
|
|
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 */
|
|
|
|
|
2004-02-17 06:12:40 +08:00
|
|
|
#endif
|