VirtualBox

source: vbox/trunk/src/recompiler_new/osdep.h@ 13428

Last change on this file since 13428 was 13384, checked in by vboxsync, 16 years ago

more MSC stuff

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1#ifndef QEMU_OSDEP_H
2#define QEMU_OSDEP_H
3
4#ifdef VBOX
5
6#include <iprt/alloc.h>
7#include <iprt/alloca.h>
8#include <iprt/stdarg.h>
9#include <iprt/string.h>
10
11#ifndef _MSC_VER
12#define qemu_snprintf(pszBuf, cbBuf, ...) RTStrPrintf((pszBuf), (cbBuf), __VA_ARGS__)
13#else
14#define qemu_snprintf RTStrPrintf
15#endif
16#define qemu_vsnprintf(pszBuf, cbBuf, pszFormat, args) \
17 RTStrPrintfV((pszBuf), (cbBuf), (pszFormat), (args))
18#define qemu_vprintf(pszFormat, args) \
19 RTLogPrintfV((pszFormat), (args))
20#define qemu_printf RTLogPrintf
21#define qemu_malloc(cb) RTMemAlloc(cb)
22#define qemu_mallocz(cb) RTMemAllocZ(cb)
23#define qemu_free(pv) RTMemFree(pv)
24#define qemu_strdup(psz) RTStrDup(psz)
25
26#define qemu_vmalloc(cb) RTMemPageAlloc(cb)
27#define qemu_vfree(pv) RTMemPageFree(pv)
28
29#ifndef NULL
30# define NULL 0
31#endif
32
33#else /* !VBOX */
34
35#include <stdarg.h>
36
37#define qemu_snprintf snprintf /* bird */
38#define qemu_vsnprintf vsnprintf /* bird */
39#define qemu_vprintf vprintf /* bird */
40
41#define qemu_printf printf
42
43void *qemu_malloc(size_t size);
44void *qemu_mallocz(size_t size);
45void qemu_free(void *ptr);
46char *qemu_strdup(const char *str);
47
48void *qemu_vmalloc(size_t size);
49void qemu_vfree(void *ptr);
50
51void *get_mmap_addr(unsigned long size);
52
53#endif /* !VBOX */
54
55#ifdef __OpenBSD__
56#include <sys/types.h>
57#include <sys/signal.h>
58#endif
59
60#ifndef glue
61#define xglue(x, y) x ## y
62#define glue(x, y) xglue(x, y)
63#define stringify(s) tostring(s)
64#define tostring(s) #s
65#endif
66
67#ifndef likely
68#ifndef VBOX
69#if __GNUC__ < 3
70#define __builtin_expect(x, n) (x)
71#endif
72
73#define likely(x) __builtin_expect(!!(x), 1)
74#define unlikely(x) __builtin_expect(!!(x), 0)
75#else /* VBOX */
76#define likely(cond) RT_LIKELY(cond)
77#define unlikely(cond) RT_UNLIKELY(cond)
78#endif
79#endif /* !likely */
80
81#ifndef offsetof
82#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
83#endif
84#ifndef container_of
85#define container_of(ptr, type, member) ({ \
86 const typeof(((type *) 0)->member) *__mptr = (ptr); \
87 (type *) ((char *) __mptr - offsetof(type, member));})
88#endif
89
90#ifndef MIN
91#define MIN(a, b) (((a) < (b)) ? (a) : (b))
92#endif
93#ifndef MAX
94#define MAX(a, b) (((a) > (b)) ? (a) : (b))
95#endif
96
97#ifndef ARRAY_SIZE
98#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
99#endif
100
101#ifndef always_inline
102#if (__GNUC__ < 3) || defined(__APPLE__)
103#define always_inline inline
104#else
105#define always_inline __attribute__ (( always_inline )) __inline__
106#define inline always_inline
107#endif
108#else
109#define inline always_inline
110#endif
111
112#ifdef __i386__
113#ifdef _MSC_VER
114/** @todo: maybe wrong, or slow */
115#define REGPARM
116#else
117#define REGPARM __attribute((regparm(3)))
118#endif
119#else
120#define REGPARM
121#endif
122
123#if defined (__GNUC__) && defined (__GNUC_MINOR_)
124# define QEMU_GNUC_PREREQ(maj, min) \
125 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
126#else
127# define QEMU_GNUC_PREREQ(maj, min) 0
128#endif
129
130#ifndef VBOX
131void *qemu_memalign(size_t alignment, size_t size);
132void *qemu_vmalloc(size_t size);
133void qemu_vfree(void *ptr);
134
135int qemu_create_pidfile(const char *filename);
136
137#ifdef _WIN32
138int ffs(int i);
139
140typedef struct {
141 long tv_sec;
142 long tv_usec;
143} qemu_timeval;
144int qemu_gettimeofday(qemu_timeval *tp);
145#else
146typedef struct timeval qemu_timeval;
147#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
148#endif /* !_WIN32 */
149#endif /* !VBOX */
150
151#ifdef VBOX
152#ifdef _MSC_VER
153#define ALIGNED_MEMBER(type, name, bytes) type name
154#define ALIGNED_MEMBER_DEF(type, name) type name
155#define PACKED_STRUCT(name) struct name
156#define REGISTER_BOUND_GLOBAL(type, var, reg) type var
157#define SAVE_GLOBAL_REGISTER(reg, var)
158#define RESTORE_GLOBAL_REGISTER(reg, var)
159#define DECLALWAYSINLINE(type) DECLINLINE(type)
160#define FORCE_RET() ;
161#else /* ! _MSC_VER */
162#define ALIGNED_MEMBER(type, name, bytes) type name __attribute__((aligned(bytes)))
163#define ALIGNED_MEMBER_DEF(type, name) type name __attribute__((aligned()))
164#define PACKED_STRUCT(name) struct __attribute__ ((__packed__)) name
165#define REGISTER_BOUND_GLOBAL(type, var, reg) register type var asm(reg)
166#define SAVE_GLOBAL_REGISTER(reg, var) __asm__ __volatile__ ("" : "=r" (var))
167#define RESTORE_GLOBAL_REGISTER(reg, var) __asm__ __volatile__ ("" : : "r" (var))
168#define DECLALWAYSINLINE(type) static always_inline type
169#define FORCE_RET() __asm__ __volatile__("" : : : "memory");
170#endif /* !_MSC_VER */
171#endif /* VBOX */
172
173#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette