VirtualBox

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

Last change on this file since 106061 was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1/* $Id: iprt.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * IPRT - Internal header for miscellaneous global defs and types.
4 */
5
6/*
7 * Copyright (C) 2009-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_INTERNAL_iprt_h
38#define IPRT_INCLUDED_INTERNAL_iprt_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/cdefs.h>
44#include <iprt/types.h>
45
46/** @def RT_EXPORT_SYMBOL
47 * This define is really here just for the linux kernel.
48 * @param Name The symbol name.
49 */
50#if defined(RT_OS_LINUX) \
51 && defined(IN_RING0) \
52 && defined(MODULE) \
53 && !defined(RT_NO_EXPORT_SYMBOL)
54# define bool linux_bool /* see r0drv/linux/the-linux-kernel.h */
55# include <linux/version.h>
56# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
57# include <generated/autoconf.h>
58# else
59# ifndef AUTOCONF_INCLUDED
60# include <linux/autoconf.h>
61# endif
62# endif
63# if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
64# define MODVERSIONS
65# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
66# include <linux/modversions.h>
67# endif
68# endif
69# include <linux/module.h>
70# undef bool
71# define RT_EXPORT_SYMBOL(Name) EXPORT_SYMBOL(Name)
72#else
73# define RT_EXPORT_SYMBOL(Name) extern int g_rtExportSymbolDummyVariable
74#endif
75
76/** @def RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL
77 * Creates symbol alias and export a RT_NOCRT symbol.
78 *
79 * For targets using ELF this macro generates weak symbol aliases, for the other
80 * object formats the makefile scans source files for this macro and produces
81 * separate object files with the aliases.
82 *
83 * @param a_Name The CRT function or variable name.
84 *
85 * @todo Does not support ELF targets using underscore prefixed symbols.
86 */
87#if defined(__ELF__) && defined(RT_WITH_NOCRT_ALIASES) && !defined(RT_WITHOUT_NOCRT_ALIASES)
88# ifdef RT_WITH_NOCRT_UNDERSCORE_ALIASES
89# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(a_Name) RT_EXPORT_SYMBOL(a_Name) \
90 __asm__(".weak " #a_Name "\n\t" \
91 ".set " #a_Name "," RT_NOCRT_STR(a_Name) "\n\t" \
92 ".weak _" #a_Name "\n\t" \
93 ".set _" #a_Name "," RT_NOCRT_STR(a_Name) "\n\t")
94# else
95# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(a_Name) RT_EXPORT_SYMBOL(a_Name) \
96 __asm__(".weak " #a_Name "\n\t" \
97 ".set " #a_Name "," RT_NOCRT_STR(a_Name) "\n\t")
98# endif
99#else
100# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(a_Name) RT_EXPORT_SYMBOL(a_Name)
101#endif
102
103/** @def RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL_WITHOUT_UNDERSCORE
104 * Variant of RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL that omits the
105 * underscore-prefixed variant of the symbol.
106 *
107 * @param a_Name The CRT function or variable name.
108 */
109#if defined(__ELF__) && defined(RT_WITH_NOCRT_ALIASES) && !defined(RT_WITHOUT_NOCRT_ALIASES)
110# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL_WITHOUT_UNDERSCORE(a_Name) RT_EXPORT_SYMBOL(a_Name) \
111 __asm__(".weak " #a_Name "\n\t" \
112 ".set " #a_Name "," RT_NOCRT_STR(a_Name) "\n\t")
113#else
114# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL_WITHOUT_UNDERSCORE(a_Name) RT_EXPORT_SYMBOL(a_Name)
115#endif
116
117
118/** @def RT_MORE_STRICT
119 * Enables more assertions in IPRT. */
120#if !defined(RT_MORE_STRICT) && (defined(DEBUG) || defined(RT_STRICT) || defined(DOXYGEN_RUNNING)) && !defined(RT_OS_WINDOWS) /** @todo enable on windows after testing */
121# define RT_MORE_STRICT
122#endif
123
124/** @def RT_ASSERT_PREEMPT_CPUID_VAR
125 * Partner to RT_ASSERT_PREEMPT_CPUID_VAR. Declares and initializes a variable
126 * idAssertCpu to NIL_RTCPUID if preemption is enabled and to RTMpCpuId if
127 * disabled. When RT_MORE_STRICT isn't defined it declares an uninitialized
128 * dummy variable.
129 *
130 * Requires iprt/mp.h and iprt/asm.h.
131 */
132/** @def RT_ASSERT_PREEMPT_CPUID
133 * Asserts that we didn't change CPU since RT_ASSERT_PREEMPT_CPUID_VAR if
134 * preemption is disabled. Will also detect changes in preemption
135 * disable/enable status. This is a noop when RT_MORE_STRICT isn't defined. */
136#ifdef RT_MORE_STRICT
137# define RT_ASSERT_PREEMPT_CPUID_VAR() \
138 RTCPUID const idAssertCpu = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId()
139# define RT_ASSERT_PREEMPT_CPUID() \
140 do \
141 { \
142 RTCPUID const idAssertCpuNow = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId(); \
143 AssertMsg(idAssertCpu == idAssertCpuNow, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
144 } while (0)
145
146#else
147# define RT_ASSERT_PREEMPT_CPUID_VAR() RTCPUID idAssertCpuDummy
148# define RT_ASSERT_PREEMPT_CPUID() NOREF(idAssertCpuDummy)
149#endif
150
151/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED
152 * Extended version of RT_ASSERT_PREEMPT_CPUID for use before
153 * RTSpinlockAcquired* returns. This macro works the idCpuOwner and idAssertCpu
154 * members of the spinlock instance data. */
155#ifdef RT_MORE_STRICT
156# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) \
157 do \
158 { \
159 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
160 AssertMsg(idAssertCpu == idAssertCpuNow || idAssertCpu == NIL_RTCPUID, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
161 (pThis)->idAssertCpu = idAssertCpu; \
162 (pThis)->idCpuOwner = idAssertCpuNow; \
163 } while (0)
164#else
165# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) NOREF(idAssertCpuDummy)
166#endif
167
168/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS
169 * Extended version of RT_ASSERT_PREEMPT_CPUID_VAR for use with
170 * RTSpinlockRelease* returns. */
171#ifdef RT_MORE_STRICT
172# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpu
173#else
174# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpuDummy
175#endif
176
177/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE
178 * Extended version of RT_ASSERT_PREEMPT_CPUID for use in RTSpinlockRelease*
179 * before calling the native API for releasing the spinlock. It must be
180 * teamed up with RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED. */
181#ifdef RT_MORE_STRICT
182# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) \
183 do \
184 { \
185 RTCPUID const idCpuOwner = (pThis)->idCpuOwner; \
186 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
187 AssertMsg(idCpuOwner == idAssertCpuNow, ("%#x, %#x\n", idCpuOwner, idAssertCpuNow)); \
188 (pThis)->idCpuOwner = NIL_RTCPUID; \
189 idAssertCpu = (pThis)->idAssertCpu; \
190 (pThis)->idAssertCpu = NIL_RTCPUID; \
191 } while (0)
192#else
193# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) NOREF(idAssertCpuDummy)
194#endif
195
196/** @def RT_ASSERT_PREEMPT_CPUID_DISABLE
197 * For use in RTThreadPreemptDisable implementations after having disabled
198 * preemption. Requires iprt/mp.h. */
199#ifdef RT_MORE_STRICT
200# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
201 do \
202 { \
203 Assert((pStat)->idCpu == NIL_RTCPUID); \
204 (pStat)->idCpu = RTMpCpuId(); \
205 } while (0)
206#else
207# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
208 Assert((pStat)->idCpu == NIL_RTCPUID)
209#endif
210
211/** @def RT_ASSERT_PREEMPT_CPUID_RESTORE
212 * For use in RTThreadPreemptRestore implementations before restoring
213 * preemption. Requires iprt/mp.h. */
214#ifdef RT_MORE_STRICT
215# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) \
216 do \
217 { \
218 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
219 AssertMsg((pStat)->idCpu == idAssertCpuNow, ("%#x, %#x\n", (pStat)->idCpu, idAssertCpuNow)); \
220 (pStat)->idCpu = NIL_RTCPUID; \
221 } while (0)
222#else
223# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) do { } while (0)
224#endif
225
226
227/** @def RT_ASSERT_INTS_ON
228 * Asserts that interrupts are disabled when RT_MORE_STRICT is defined. */
229#ifdef RT_MORE_STRICT
230# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
231# define RT_ASSERT_INTS_ON() Assert(ASMIntAreEnabled())
232# else /* PORTME: Add architecture/platform specific test. */
233# define RT_ASSERT_INTS_ON() Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD))
234# endif
235#else
236# define RT_ASSERT_INTS_ON() do { } while (0)
237#endif
238
239/** @def RT_ASSERT_PREEMPTIBLE
240 * Asserts that preemption hasn't been disabled (using
241 * RTThreadPreemptDisable) when RT_MORE_STRICT is defined. */
242#ifdef RT_MORE_STRICT
243# define RT_ASSERT_PREEMPTIBLE() Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD))
244#else
245# define RT_ASSERT_PREEMPTIBLE() do { } while (0)
246#endif
247
248
249RT_C_DECLS_BEGIN
250
251#ifdef RT_OS_OS2
252uint32_t rtR0SemWaitOs2ConvertTimeout(uint32_t fFlags, uint64_t uTimeout);
253#endif
254
255RT_C_DECLS_END
256
257#endif /* !IPRT_INCLUDED_INTERNAL_iprt_h */
258
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