VirtualBox

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

Last change on this file since 80346 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

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