VirtualBox

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

Last change on this file since 96162 was 96043, checked in by vboxsync, 3 years ago

IPRT,/Config.kmk,iprt/asmdefs.mac,Add/3D/Config.kmk: Generate weak CRT name aliases for nocrt_xxx function using genalias on Windows (, OS/2 and possibly macOS), while for ELF targets we'll use a RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL/RT_NOCRT_BEGINPROC macros with the function definition. bugref:10261

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: iprt.h 96043 2022-08-04 22:08:07Z vboxsync $ */
2/** @file
3 * IPRT - Internal header for miscellaneous global defs and types.
4 */
5
6/*
7 * Copyright (C) 2009-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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/** @def RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL
67 * Creates symbol alias and export a RT_NOCRT symbol.
68 *
69 * For targets using ELF this macro generates weak symbol aliases, for the other
70 * object formats the makefile scans source files for this macro and produces
71 * separate object files with the aliases.
72 *
73 * @param a_Name The CRT function or variable name.
74 *
75 * @todo Does not support ELF targets using underscore prefixed symbols.
76 */
77#if defined(__ELF__) && defined(RT_WITH_NOCRT_ALIASES) && !defined(RT_WITHOUT_NOCRT_ALIASES)
78# ifdef RT_WITH_NOCRT_UNDERSCORE_ALIASES
79# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(a_Name) RT_EXPORT_SYMBOL(a_Name) \
80 __asm__(".weak " #a_Name "\n\t" \
81 ".set " #a_Name "," RT_NOCRT_STR(a_Name) "\n\t" \
82 ".weak _" #a_Name "\n\t" \
83 ".set _" #a_Name "," RT_NOCRT_STR(a_Name) "\n\t")
84# else
85# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(a_Name) RT_EXPORT_SYMBOL(a_Name) \
86 __asm__(".weak " #a_Name "\n\t" \
87 ".set " #a_Name "," RT_NOCRT_STR(a_Name) "\n\t")
88# endif
89#else
90# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(a_Name) RT_EXPORT_SYMBOL(a_Name)
91#endif
92
93/** @def RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL_WITHOUT_UNDERSCORE
94 * Variant of RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL that omits the
95 * underscore-prefixed variant of the symbol.
96 *
97 * @param a_Name The CRT function or variable name.
98 */
99#if defined(__ELF__) && defined(RT_WITH_NOCRT_ALIASES) && !defined(RT_WITHOUT_NOCRT_ALIASES)
100# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL_WITHOUT_UNDERSCORE(a_Name) RT_EXPORT_SYMBOL(a_Name) \
101 __asm__(".weak " #a_Name "\n\t" \
102 ".set " #a_Name "," RT_NOCRT_STR(a_Name) "\n\t")
103#else
104# define RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL_WITHOUT_UNDERSCORE(a_Name) RT_EXPORT_SYMBOL(a_Name)
105#endif
106
107
108/** @def RT_MORE_STRICT
109 * Enables more assertions in IPRT. */
110#if !defined(RT_MORE_STRICT) && (defined(DEBUG) || defined(RT_STRICT) || defined(DOXYGEN_RUNNING)) && !defined(RT_OS_WINDOWS) /** @todo enable on windows after testing */
111# define RT_MORE_STRICT
112#endif
113
114/** @def RT_ASSERT_PREEMPT_CPUID_VAR
115 * Partner to RT_ASSERT_PREEMPT_CPUID_VAR. Declares and initializes a variable
116 * idAssertCpu to NIL_RTCPUID if preemption is enabled and to RTMpCpuId if
117 * disabled. When RT_MORE_STRICT isn't defined it declares an uninitialized
118 * dummy variable.
119 *
120 * Requires iprt/mp.h and iprt/asm.h.
121 */
122/** @def RT_ASSERT_PREEMPT_CPUID
123 * Asserts that we didn't change CPU since RT_ASSERT_PREEMPT_CPUID_VAR if
124 * preemption is disabled. Will also detect changes in preemption
125 * disable/enable status. This is a noop when RT_MORE_STRICT isn't defined. */
126#ifdef RT_MORE_STRICT
127# define RT_ASSERT_PREEMPT_CPUID_VAR() \
128 RTCPUID const idAssertCpu = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId()
129# define RT_ASSERT_PREEMPT_CPUID() \
130 do \
131 { \
132 RTCPUID const idAssertCpuNow = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId(); \
133 AssertMsg(idAssertCpu == idAssertCpuNow, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
134 } while (0)
135
136#else
137# define RT_ASSERT_PREEMPT_CPUID_VAR() RTCPUID idAssertCpuDummy
138# define RT_ASSERT_PREEMPT_CPUID() NOREF(idAssertCpuDummy)
139#endif
140
141/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED
142 * Extended version of RT_ASSERT_PREEMPT_CPUID for use before
143 * RTSpinlockAcquired* returns. This macro works the idCpuOwner and idAssertCpu
144 * members of the spinlock instance data. */
145#ifdef RT_MORE_STRICT
146# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) \
147 do \
148 { \
149 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
150 AssertMsg(idAssertCpu == idAssertCpuNow || idAssertCpu == NIL_RTCPUID, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
151 (pThis)->idAssertCpu = idAssertCpu; \
152 (pThis)->idCpuOwner = idAssertCpuNow; \
153 } while (0)
154#else
155# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) NOREF(idAssertCpuDummy)
156#endif
157
158/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS
159 * Extended version of RT_ASSERT_PREEMPT_CPUID_VAR for use with
160 * RTSpinlockRelease* returns. */
161#ifdef RT_MORE_STRICT
162# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpu
163#else
164# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpuDummy
165#endif
166
167/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE
168 * Extended version of RT_ASSERT_PREEMPT_CPUID for use in RTSpinlockRelease*
169 * before calling the native API for releasing the spinlock. It must be
170 * teamed up with RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED. */
171#ifdef RT_MORE_STRICT
172# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) \
173 do \
174 { \
175 RTCPUID const idCpuOwner = (pThis)->idCpuOwner; \
176 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
177 AssertMsg(idCpuOwner == idAssertCpuNow, ("%#x, %#x\n", idCpuOwner, idAssertCpuNow)); \
178 (pThis)->idCpuOwner = NIL_RTCPUID; \
179 idAssertCpu = (pThis)->idAssertCpu; \
180 (pThis)->idAssertCpu = NIL_RTCPUID; \
181 } while (0)
182#else
183# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) NOREF(idAssertCpuDummy)
184#endif
185
186/** @def RT_ASSERT_PREEMPT_CPUID_DISABLE
187 * For use in RTThreadPreemptDisable implementations after having disabled
188 * preemption. Requires iprt/mp.h. */
189#ifdef RT_MORE_STRICT
190# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
191 do \
192 { \
193 Assert((pStat)->idCpu == NIL_RTCPUID); \
194 (pStat)->idCpu = RTMpCpuId(); \
195 } while (0)
196#else
197# define RT_ASSERT_PREEMPT_CPUID_DISABLE(pStat) \
198 Assert((pStat)->idCpu == NIL_RTCPUID)
199#endif
200
201/** @def RT_ASSERT_PREEMPT_CPUID_RESTORE
202 * For use in RTThreadPreemptRestore implementations before restoring
203 * preemption. Requires iprt/mp.h. */
204#ifdef RT_MORE_STRICT
205# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) \
206 do \
207 { \
208 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
209 AssertMsg((pStat)->idCpu == idAssertCpuNow, ("%#x, %#x\n", (pStat)->idCpu, idAssertCpuNow)); \
210 (pStat)->idCpu = NIL_RTCPUID; \
211 } while (0)
212#else
213# define RT_ASSERT_PREEMPT_CPUID_RESTORE(pStat) do { } while (0)
214#endif
215
216
217/** @def RT_ASSERT_INTS_ON
218 * Asserts that interrupts are disabled when RT_MORE_STRICT is defined. */
219#ifdef RT_MORE_STRICT
220# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
221# define RT_ASSERT_INTS_ON() Assert(ASMIntAreEnabled())
222# else /* PORTME: Add architecture/platform specific test. */
223# define RT_ASSERT_INTS_ON() Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD))
224# endif
225#else
226# define RT_ASSERT_INTS_ON() do { } while (0)
227#endif
228
229/** @def RT_ASSERT_PREEMPTIBLE
230 * Asserts that preemption hasn't been disabled (using
231 * RTThreadPreemptDisable) when RT_MORE_STRICT is defined. */
232#ifdef RT_MORE_STRICT
233# define RT_ASSERT_PREEMPTIBLE() Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD))
234#else
235# define RT_ASSERT_PREEMPTIBLE() do { } while (0)
236#endif
237
238
239RT_C_DECLS_BEGIN
240
241#ifdef RT_OS_OS2
242uint32_t rtR0SemWaitOs2ConvertTimeout(uint32_t fFlags, uint64_t uTimeout);
243#endif
244
245RT_C_DECLS_END
246
247#endif /* !IPRT_INCLUDED_INTERNAL_iprt_h */
248
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette