3
* IPRT - Internal header for miscellaneous global defs and types.
7
* Copyright (C) 2009 Sun Microsystems, Inc.
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.
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.
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.
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.
31
#ifndef ___internal_iprt_h
32
#define ___internal_iprt_h
34
#include <iprt/cdefs.h>
35
#include <iprt/types.h>
37
/** @def RT_EXPORT_SYMBOL
38
* This define is really here just for the linux kernel.
39
* @param Name The symbol name.
41
#if defined(RT_OS_LINUX) \
42
&& defined(IN_RING0) \
44
&& !defined(RT_NO_EXPORT_SYMBOL)
45
# define bool linux_bool /* see r0drv/linux/the-linux-kernel.h */
46
# include <linux/autoconf.h>
47
# if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
48
# include <linux/version.h>
50
# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
51
# include <linux/modversions.h>
54
# include <linux/module.h>
56
# define RT_EXPORT_SYMBOL(Name) EXPORT_SYMBOL(Name)
58
# define RT_EXPORT_SYMBOL(Name) extern int g_rtExportSymbolDummyVariable
62
/** @def RT_MORE_STRICT
63
* Enables more assertions in IPRT. */
64
#if !defined(RT_MORE_STRICT) && (defined(DEBUG) || defined(RT_STRICT) || defined(DOXYGEN_RUNNING)) && !defined(RT_OS_WINDOWS) /** @todo enable on windows after testing */
65
# define RT_MORE_STRICT
68
/** @def RT_ASSERT_PREEMPT_CPUID_VAR
69
* Partner to RT_ASSERT_PREEMPT_CPUID_VAR. Declares and initializes a variable
70
* idAssertCpu to NIL_RTCPUID if preemption is enabled and to RTMpCpuId if
71
* disabled. When RT_MORE_STRICT isn't defined it declares an uninitialized
74
* Requires iprt/mp.h and iprt/asm.h.
76
/** @def RT_ASSERT_PREEMPT_CPUID
77
* Asserts that we didn't change CPU since RT_ASSERT_PREEMPT_CPUID_VAR if
78
* preemption is disabled. Will also detect changes in preemption
79
* disable/enable status. This is a noop when RT_MORE_STRICT isn't defined. */
81
# define RT_ASSERT_PREEMPT_CPUID_VAR() \
82
RTCPUID const idAssertCpu = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId()
83
# define RT_ASSERT_PREEMPT_CPUID() \
86
RTCPUID const idAssertCpuNow = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId(); \
87
AssertMsg(idAssertCpu == idAssertCpuNow, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
91
# define RT_ASSERT_PREEMPT_CPUID_VAR() RTCPUID idAssertCpuDummy
92
# define RT_ASSERT_PREEMPT_CPUID() NOREF(idAssertCpuDummy)
95
/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED
96
* Extended version of RT_ASSERT_PREEMPT_CPUID for use before
97
* RTSpinlockAcquired* returns. This macro works the idCpuOwner and idAssertCpu
98
* members of the spinlock instance data. */
100
# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) \
103
RTCPUID const idAssertCpuNow = RTMpCpuId(); \
104
AssertMsg(idAssertCpu == idAssertCpuNow || idAssertCpu == NIL_RTCPUID, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
105
(pThis)->idAssertCpu = idAssertCpu; \
106
(pThis)->idCpuOwner = idAssertCpuNow; \
109
# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) NOREF(idAssertCpuDummy)
112
/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS
113
* Extended version of RT_ASSERT_PREEMPT_CPUID_VAR for use with
114
* RTSpinlockRelease* returns. */
115
#ifdef RT_MORE_STRICT
116
# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpu
118
# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpuDummy
121
/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE
122
* Extended version of RT_ASSERT_PREEMPT_CPUID for use in RTSpinlockRelease*
123
* before calling the native API for releasing the spinlock. It must be
124
* teamed up with RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED. */
125
#ifdef RT_MORE_STRICT
126
# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) \
129
RTCPUID const idCpuOwner = (pThis)->idCpuOwner; \
130
RTCPUID const idAssertCpuNow = RTMpCpuId(); \
131
AssertMsg(idCpuOwner == idAssertCpuNow, ("%#x, %#x\n", idCpuOwner, idAssertCpuNow)); \
132
(pThis)->idCpuOwner = NIL_RTCPUID; \
133
idAssertCpu = (pThis)->idAssertCpu; \
134
(pThis)->idAssertCpu = NIL_RTCPUID; \
137
# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) NOREF(idAssertCpuDummy)
140
/** @def RT_ASSERT_PREEMPT_CPUID_DISABLE
141
* For use in RTThreadPreemptDisable implementations after having disabled
142
* preemption. Requires iprt/mp.h. */
143
#ifdef RT_MORE_STRICT
144
# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
147
Assert((pStat)->idCpu == NIL_RTCPUID); \
148
(pStat)->idCpu = RTMpCpuId(); \
151
# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
152
Assert((pStat)->idCpu == NIL_RTCPUID)
155
/** @def RT_ASSERT_PREEMPT_CPUID_RESTORE
156
* For use in RTThreadPreemptRestore implementations before restoring
157
* preemption. Requires iprt/mp.h. */
158
#ifdef RT_MORE_STRICT
159
# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) \
162
RTCPUID const idAssertCpuNow = RTMpCpuId(); \
163
AssertMsg((pStat)->idCpu == idAssertCpuNow, ("%#x, %#x\n", (pStat)->idCpu, idAssertCpuNow)); \
164
(pStat)->idCpu = NIL_RTCPUID; \
167
# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) do { } while (0)
171
/** @def RT_ASSERT_INTS_ON
172
* Asserts that interrupts are disabled when RT_MORE_STRICT is defined. */
173
#ifdef RT_MORE_STRICT
174
# define RT_ASSERT_INTS_ON() Assert(ASMIntAreEnabled())
176
# define RT_ASSERT_INTS_ON() do { } while (0)
179
/** @def RT_ASSERT_PREEMPTIBLE
180
* Asserts that preemption hasn't been disabled (using
181
* RTThreadPreemptDisable) when RT_MORE_STRICT is defined. */
182
#ifdef RT_MORE_STRICT
183
# define RT_ASSERT_PREEMPTIBLE() Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD))
185
# define RT_ASSERT_PREEMPTIBLE() do { } while (0)