VirtualBox

source: vbox/trunk/src/recompiler/osdep.h@ 62180

最後變更 在這個檔案從62180是 55980,由 vboxsync 提交於 10 年 前

iprt/log.h,++: Added extended logger instance getters that also checks whether the given logger and group-flags are enabled, making the LogRel* checks more efficient in avoid uncessary RTLogLoggerEx parameter building and calls. Ditto for debug logging. The LOG_INSTANCE and LOG_REL_INSTANCE tricks are gone for now.

  • 屬性 svn:eol-style 設為 native
檔案大小: 4.2 KB
 
1#ifndef QEMU_OSDEP_H
2#define QEMU_OSDEP_H
3
4#ifdef VBOX /** @todo clean up this, it's not fully synched. */
5
6#include <iprt/alloc.h>
7#ifndef RT_OS_WINDOWS
8# include <iprt/alloca.h>
9#endif
10#include <iprt/stdarg.h>
11#include <iprt/string.h>
12
13#include "config.h"
14
15#define VBOX_ONLY(x) x
16
17#define qemu_snprintf(pszBuf, cbBuf, ...) RTStrPrintf((pszBuf), (cbBuf), __VA_ARGS__)
18#define qemu_vsnprintf(pszBuf, cbBuf, pszFormat, args) \
19 RTStrPrintfV((pszBuf), (cbBuf), (pszFormat), (args))
20#define qemu_vprintf(pszFormat, args) \
21 RTLogPrintfV((pszFormat), (args))
22
23/**@todo the following macros belongs elsewhere */
24#define qemu_malloc(cb) RTMemAlloc(cb)
25#define qemu_mallocz(cb) RTMemAllocZ(cb)
26#define qemu_realloc(ptr, cb) RTMemRealloc(ptr, cb)
27#define qemu_free(pv) RTMemFree(pv)
28#define qemu_strdup(psz) RTStrDup(psz)
29
30/* Misc wrappers */
31#define fflush(file) RTLogFlush(NULL)
32#define printf(...) LogIt(0, LOG_GROUP_REM_PRINTF, (__VA_ARGS__))
33/* If DEBUG_TMP_LOGGING - goes to QEMU log file */
34#ifndef DEBUG_TMP_LOGGING
35# define fprintf(logfile, ...) LogIt(0, LOG_GROUP_REM_PRINTF, (__VA_ARGS__))
36#endif
37
38#define assert(cond) Assert(cond)
39
40#else /* !VBOX */
41
42#include <stdarg.h>
43#include <stddef.h>
44
45#define VBOX_ONLY(x) /* nike */
46#define qemu_snprintf snprintf /* bird */
47#define qemu_vsnprintf vsnprintf /* bird */
48#define qemu_vprintf vprintf /* bird */
49
50#endif /* !VBOX */
51
52#ifdef __OpenBSD__
53#include <sys/types.h>
54#include <sys/signal.h>
55#endif
56
57#ifndef VBOX
58#ifndef _WIN32
59#include <sys/time.h>
60#endif
61#endif /* !VBOX */
62
63#ifndef glue
64#define xglue(x, y) x ## y
65#define glue(x, y) xglue(x, y)
66#define stringify(s) tostring(s)
67#define tostring(s) #s
68#endif
69
70#ifndef likely
71#if __GNUC__ < 3
72#define __builtin_expect(x, n) (x)
73#endif
74
75#define likely(x) __builtin_expect(!!(x), 1)
76#define unlikely(x) __builtin_expect(!!(x), 0)
77#endif
78
79#ifdef CONFIG_NEED_OFFSETOF
80#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
81#endif
82#ifndef container_of
83#define container_of(ptr, type, member) ({ \
84 const typeof(((type *) 0)->member) *__mptr = (ptr); \
85 (type *) ((char *) __mptr - offsetof(type, member));})
86#endif
87
88/* Convert from a base type to a parent type, with compile time checking. */
89#ifdef __GNUC__
90#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
91 char __attribute__((unused)) offset_must_be_zero[ \
92 -offsetof(type, field)]; \
93 container_of(dev, type, field);}))
94#else
95#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
96#endif
97
98#define typeof_field(type, field) typeof(((type *)0)->field)
99#define type_check(t1,t2) ((t1*)0 - (t2*)0)
100
101#ifndef MIN
102#define MIN(a, b) (((a) < (b)) ? (a) : (b))
103#endif
104#ifndef MAX
105#define MAX(a, b) (((a) > (b)) ? (a) : (b))
106#endif
107
108#ifndef ARRAY_SIZE
109#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
110#endif
111
112#ifndef always_inline
113#if !((__GNUC__ < 3) || defined(__APPLE__))
114#ifdef __OPTIMIZE__
115#define inline __attribute__ (( always_inline )) __inline__
116#endif
117#endif
118#else
119#define inline always_inline
120#endif
121
122#ifdef __i386__
123#define REGPARM __attribute((regparm(3)))
124#else
125#define REGPARM
126#endif
127
128#ifndef VBOX
129#define qemu_printf printf
130#else /*VBOX*/
131#define qemu_printf RTLogPrintf
132#endif /*VBOX*/
133
134#if defined (__GNUC__) && defined (__GNUC_MINOR__)
135# define QEMU_GNUC_PREREQ(maj, min) \
136 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
137#else
138# define QEMU_GNUC_PREREQ(maj, min) 0
139#endif
140
141#ifndef VBOX
142void *qemu_memalign(size_t alignment, size_t size);
143void *qemu_vmalloc(size_t size);
144void qemu_vfree(void *ptr);
145
146int qemu_create_pidfile(const char *filename);
147
148#ifdef _WIN32
149int ffs(int i);
150
151typedef struct {
152 long tv_sec;
153 long tv_usec;
154} qemu_timeval;
155int qemu_gettimeofday(qemu_timeval *tp);
156#else
157typedef struct timeval qemu_timeval;
158#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
159#endif /* !_WIN32 */
160#else /* VBOX */
161# define qemu_memalign(alignment, size) ( (alignment) <= PAGE_SIZE ? RTMemPageAlloc((size)) : NULL )
162# define qemu_vfree(pv) RTMemPageFree(pv, missing_size_parameter)
163# define qemu_vmalloc(cb) RTMemPageAlloc(cb)
164#endif /* VBOX */
165
166#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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