VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/iprt.h@ 25591

Last change on this file since 25591 was 25591, checked in by vboxsync, 15 years ago

fix for compiling against Linux 2.6.33+

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/* $Id: iprt.h 25591 2009-12-29 19:11:46Z vboxsync $ */
2/** @file
3 * IPRT - Internal header for miscellaneous global defs and types.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___internal_iprt_h
32#define ___internal_iprt_h
33
34#include <iprt/cdefs.h>
35#include <iprt/types.h>
36
37/** @def RT_EXPORT_SYMBOL
38 * This define is really here just for the linux kernel.
39 * @param Name The symbol name.
40 */
41#if defined(RT_OS_LINUX) \
42 && defined(IN_RING0) \
43 && defined(MODULE) \
44 && !defined(RT_NO_EXPORT_SYMBOL)
45# define bool linux_bool /* see r0drv/linux/the-linux-kernel.h */
46# ifndef AUTOCONF_INCLUDED
47# include <linux/autoconf.h>
48# endif
49# if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
50# include <linux/version.h>
51# define MODVERSIONS
52# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
53# include <linux/modversions.h>
54# endif
55# endif
56# include <linux/module.h>
57# undef bool
58# define RT_EXPORT_SYMBOL(Name) EXPORT_SYMBOL(Name)
59#else
60# define RT_EXPORT_SYMBOL(Name) extern int g_rtExportSymbolDummyVariable
61#endif
62
63
64/** @def RT_MORE_STRICT
65 * Enables more assertions in IPRT. */
66#if !defined(RT_MORE_STRICT) && (defined(DEBUG) || defined(RT_STRICT) || defined(DOXYGEN_RUNNING)) && !defined(RT_OS_WINDOWS) /** @todo enable on windows after testing */
67# define RT_MORE_STRICT
68#endif
69
70/** @def RT_ASSERT_PREEMPT_CPUID_VAR
71 * Partner to RT_ASSERT_PREEMPT_CPUID_VAR. Declares and initializes a variable
72 * idAssertCpu to NIL_RTCPUID if preemption is enabled and to RTMpCpuId if
73 * disabled. When RT_MORE_STRICT isn't defined it declares an uninitialized
74 * dummy variable.
75 *
76 * Requires iprt/mp.h and iprt/asm.h.
77 */
78/** @def RT_ASSERT_PREEMPT_CPUID
79 * Asserts that we didn't change CPU since RT_ASSERT_PREEMPT_CPUID_VAR if
80 * preemption is disabled. Will also detect changes in preemption
81 * disable/enable status. This is a noop when RT_MORE_STRICT isn't defined. */
82#ifdef RT_MORE_STRICT
83# define RT_ASSERT_PREEMPT_CPUID_VAR() \
84 RTCPUID const idAssertCpu = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId()
85# define RT_ASSERT_PREEMPT_CPUID() \
86 do \
87 { \
88 RTCPUID const idAssertCpuNow = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId(); \
89 AssertMsg(idAssertCpu == idAssertCpuNow, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
90 } while (0)
91
92#else
93# define RT_ASSERT_PREEMPT_CPUID_VAR() RTCPUID idAssertCpuDummy
94# define RT_ASSERT_PREEMPT_CPUID() NOREF(idAssertCpuDummy)
95#endif
96
97/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED
98 * Extended version of RT_ASSERT_PREEMPT_CPUID for use before
99 * RTSpinlockAcquired* returns. This macro works the idCpuOwner and idAssertCpu
100 * members of the spinlock instance data. */
101#ifdef RT_MORE_STRICT
102# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) \
103 do \
104 { \
105 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
106 AssertMsg(idAssertCpu == idAssertCpuNow || idAssertCpu == NIL_RTCPUID, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
107 (pThis)->idAssertCpu = idAssertCpu; \
108 (pThis)->idCpuOwner = idAssertCpuNow; \
109 } while (0)
110#else
111# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) NOREF(idAssertCpuDummy)
112#endif
113
114/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS
115 * Extended version of RT_ASSERT_PREEMPT_CPUID_VAR for use with
116 * RTSpinlockRelease* returns. */
117#ifdef RT_MORE_STRICT
118# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpu
119#else
120# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpuDummy
121#endif
122
123/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE
124 * Extended version of RT_ASSERT_PREEMPT_CPUID for use in RTSpinlockRelease*
125 * before calling the native API for releasing the spinlock. It must be
126 * teamed up with RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED. */
127#ifdef RT_MORE_STRICT
128# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) \
129 do \
130 { \
131 RTCPUID const idCpuOwner = (pThis)->idCpuOwner; \
132 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
133 AssertMsg(idCpuOwner == idAssertCpuNow, ("%#x, %#x\n", idCpuOwner, idAssertCpuNow)); \
134 (pThis)->idCpuOwner = NIL_RTCPUID; \
135 idAssertCpu = (pThis)->idAssertCpu; \
136 (pThis)->idAssertCpu = NIL_RTCPUID; \
137 } while (0)
138#else
139# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) NOREF(idAssertCpuDummy)
140#endif
141
142/** @def RT_ASSERT_PREEMPT_CPUID_DISABLE
143 * For use in RTThreadPreemptDisable implementations after having disabled
144 * preemption. Requires iprt/mp.h. */
145#ifdef RT_MORE_STRICT
146# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
147 do \
148 { \
149 Assert((pStat)->idCpu == NIL_RTCPUID); \
150 (pStat)->idCpu = RTMpCpuId(); \
151 } while (0)
152#else
153# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
154 Assert((pStat)->idCpu == NIL_RTCPUID)
155#endif
156
157/** @def RT_ASSERT_PREEMPT_CPUID_RESTORE
158 * For use in RTThreadPreemptRestore implementations before restoring
159 * preemption. Requires iprt/mp.h. */
160#ifdef RT_MORE_STRICT
161# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) \
162 do \
163 { \
164 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
165 AssertMsg((pStat)->idCpu == idAssertCpuNow, ("%#x, %#x\n", (pStat)->idCpu, idAssertCpuNow)); \
166 (pStat)->idCpu = NIL_RTCPUID; \
167 } while (0)
168#else
169# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) do { } while (0)
170#endif
171
172
173/** @def RT_ASSERT_INTS_ON
174 * Asserts that interrupts are disabled when RT_MORE_STRICT is defined. */
175#ifdef RT_MORE_STRICT
176# define RT_ASSERT_INTS_ON() Assert(ASMIntAreEnabled())
177#else
178# define RT_ASSERT_INTS_ON() do { } while (0)
179#endif
180
181/** @def RT_ASSERT_PREEMPTIBLE
182 * Asserts that preemption hasn't been disabled (using
183 * RTThreadPreemptDisable) when RT_MORE_STRICT is defined. */
184#ifdef RT_MORE_STRICT
185# define RT_ASSERT_PREEMPTIBLE() Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD))
186#else
187# define RT_ASSERT_PREEMPTIBLE() do { } while (0)
188#endif
189
190#endif
191
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