VirtualBox

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

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

iprt/asm*.h: split out asm-math.h, don't include asm-*.h from asm.h, don't include asm.h from sup.h. Fixed a couple file headers.

  • 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 29250 2010-05-09 17:53:58Z vboxsync $ */
2/** @file
3 * IPRT - Internal header for miscellaneous global defs and types.
4 */
5
6/*
7 * Copyright (C) 2009 Oracle Corporation
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
27#ifndef ___internal_iprt_h
28#define ___internal_iprt_h
29
30#include <iprt/cdefs.h>
31#include <iprt/types.h>
32
33/** @def RT_EXPORT_SYMBOL
34 * This define is really here just for the linux kernel.
35 * @param Name The symbol name.
36 */
37#if defined(RT_OS_LINUX) \
38 && defined(IN_RING0) \
39 && defined(MODULE) \
40 && !defined(RT_NO_EXPORT_SYMBOL)
41# define bool linux_bool /* see r0drv/linux/the-linux-kernel.h */
42# ifndef AUTOCONF_INCLUDED
43# include <linux/autoconf.h>
44# endif
45# if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
46# include <linux/version.h>
47# define MODVERSIONS
48# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
49# include <linux/modversions.h>
50# endif
51# endif
52# include <linux/module.h>
53# undef bool
54# define RT_EXPORT_SYMBOL(Name) EXPORT_SYMBOL(Name)
55#else
56# define RT_EXPORT_SYMBOL(Name) extern int g_rtExportSymbolDummyVariable
57#endif
58
59
60/** @def RT_MORE_STRICT
61 * Enables more assertions in IPRT. */
62#if !defined(RT_MORE_STRICT) && (defined(DEBUG) || defined(RT_STRICT) || defined(DOXYGEN_RUNNING)) && !defined(RT_OS_WINDOWS) /** @todo enable on windows after testing */
63# define RT_MORE_STRICT
64#endif
65
66/** @def RT_ASSERT_PREEMPT_CPUID_VAR
67 * Partner to RT_ASSERT_PREEMPT_CPUID_VAR. Declares and initializes a variable
68 * idAssertCpu to NIL_RTCPUID if preemption is enabled and to RTMpCpuId if
69 * disabled. When RT_MORE_STRICT isn't defined it declares an uninitialized
70 * dummy variable.
71 *
72 * Requires iprt/mp.h and iprt/asm.h.
73 */
74/** @def RT_ASSERT_PREEMPT_CPUID
75 * Asserts that we didn't change CPU since RT_ASSERT_PREEMPT_CPUID_VAR if
76 * preemption is disabled. Will also detect changes in preemption
77 * disable/enable status. This is a noop when RT_MORE_STRICT isn't defined. */
78#ifdef RT_MORE_STRICT
79# define RT_ASSERT_PREEMPT_CPUID_VAR() \
80 RTCPUID const idAssertCpu = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId()
81# define RT_ASSERT_PREEMPT_CPUID() \
82 do \
83 { \
84 RTCPUID const idAssertCpuNow = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId(); \
85 AssertMsg(idAssertCpu == idAssertCpuNow, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
86 } while (0)
87
88#else
89# define RT_ASSERT_PREEMPT_CPUID_VAR() RTCPUID idAssertCpuDummy
90# define RT_ASSERT_PREEMPT_CPUID() NOREF(idAssertCpuDummy)
91#endif
92
93/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED
94 * Extended version of RT_ASSERT_PREEMPT_CPUID for use before
95 * RTSpinlockAcquired* returns. This macro works the idCpuOwner and idAssertCpu
96 * members of the spinlock instance data. */
97#ifdef RT_MORE_STRICT
98# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) \
99 do \
100 { \
101 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
102 AssertMsg(idAssertCpu == idAssertCpuNow || idAssertCpu == NIL_RTCPUID, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
103 (pThis)->idAssertCpu = idAssertCpu; \
104 (pThis)->idCpuOwner = idAssertCpuNow; \
105 } while (0)
106#else
107# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) NOREF(idAssertCpuDummy)
108#endif
109
110/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS
111 * Extended version of RT_ASSERT_PREEMPT_CPUID_VAR for use with
112 * RTSpinlockRelease* returns. */
113#ifdef RT_MORE_STRICT
114# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpu
115#else
116# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpuDummy
117#endif
118
119/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE
120 * Extended version of RT_ASSERT_PREEMPT_CPUID for use in RTSpinlockRelease*
121 * before calling the native API for releasing the spinlock. It must be
122 * teamed up with RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED. */
123#ifdef RT_MORE_STRICT
124# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) \
125 do \
126 { \
127 RTCPUID const idCpuOwner = (pThis)->idCpuOwner; \
128 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
129 AssertMsg(idCpuOwner == idAssertCpuNow, ("%#x, %#x\n", idCpuOwner, idAssertCpuNow)); \
130 (pThis)->idCpuOwner = NIL_RTCPUID; \
131 idAssertCpu = (pThis)->idAssertCpu; \
132 (pThis)->idAssertCpu = NIL_RTCPUID; \
133 } while (0)
134#else
135# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) NOREF(idAssertCpuDummy)
136#endif
137
138/** @def RT_ASSERT_PREEMPT_CPUID_DISABLE
139 * For use in RTThreadPreemptDisable implementations after having disabled
140 * preemption. Requires iprt/mp.h. */
141#ifdef RT_MORE_STRICT
142# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
143 do \
144 { \
145 Assert((pStat)->idCpu == NIL_RTCPUID); \
146 (pStat)->idCpu = RTMpCpuId(); \
147 } while (0)
148#else
149# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
150 Assert((pStat)->idCpu == NIL_RTCPUID)
151#endif
152
153/** @def RT_ASSERT_PREEMPT_CPUID_RESTORE
154 * For use in RTThreadPreemptRestore implementations before restoring
155 * preemption. Requires iprt/mp.h. */
156#ifdef RT_MORE_STRICT
157# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) \
158 do \
159 { \
160 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
161 AssertMsg((pStat)->idCpu == idAssertCpuNow, ("%#x, %#x\n", (pStat)->idCpu, idAssertCpuNow)); \
162 (pStat)->idCpu = NIL_RTCPUID; \
163 } while (0)
164#else
165# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) do { } while (0)
166#endif
167
168
169/** @def RT_ASSERT_INTS_ON
170 * Asserts that interrupts are disabled when RT_MORE_STRICT is defined. */
171#ifdef RT_MORE_STRICT
172# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
173# define RT_ASSERT_INTS_ON() Assert(ASMIntAreEnabled())
174# else /* PORTME: Add architecture/platform specific test. */
175# define RT_ASSERT_INTS_ON() Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD))
176# endif
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