1 | /* $Id: vcc-fakes.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Common macros for the Visual C++ 2010+ CRT import fakes.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2023 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_SRC_r3_win_vcc_fakes_h
|
---|
38 | #define IPRT_INCLUDED_SRC_r3_win_vcc_fakes_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #ifdef RT_STRICT
|
---|
44 | # include <stdio.h> /* _snprintf */
|
---|
45 | #endif
|
---|
46 |
|
---|
47 |
|
---|
48 | /** @def MY_ASSERT
|
---|
49 | * We use a special assertion macro here to avoid dragging in IPRT bits in
|
---|
50 | * places which cannot handle it (direct GA 3D bits or something like that).
|
---|
51 | *
|
---|
52 | * Turns out snprintf is off limits too. Needs Locale info and runs out of
|
---|
53 | * stack
|
---|
54 | */
|
---|
55 | #ifdef RT_STRICT
|
---|
56 | # if 1
|
---|
57 | # define MY_ASSERT(a_Expr, g_szMsg) \
|
---|
58 | do { \
|
---|
59 | if ((a_Expr)) \
|
---|
60 | { /*likely*/ } \
|
---|
61 | else \
|
---|
62 | { \
|
---|
63 | OutputDebugStringA("Assertion failed on line " RT_XSTR(__LINE__) ": " RT_XSTR(a_Expr) "\n"); \
|
---|
64 | OutputDebugStringA("Assertion message: " g_szMsg "\n"); \
|
---|
65 | RT_BREAKPOINT(); \
|
---|
66 | } \
|
---|
67 | } while (0)
|
---|
68 | # define MY_ASSERT_STMT_RETURN(a_Expr, a_Stmt, a_rc) \
|
---|
69 | do { \
|
---|
70 | if (a_Expr) \
|
---|
71 | { /* likely */ } \
|
---|
72 | else \
|
---|
73 | { \
|
---|
74 | OutputDebugStringA("Assertion failed on line " RT_XSTR(__LINE__) ": " RT_XSTR(a_Expr) "\n"); \
|
---|
75 | RT_BREAKPOINT(); \
|
---|
76 | a_Stmt; \
|
---|
77 | return (a_rc); \
|
---|
78 | } \
|
---|
79 | } while (0)
|
---|
80 | # else
|
---|
81 | # define MY_ASSERT(a_Expr, ...) \
|
---|
82 | do { \
|
---|
83 | if ((a_Expr)) \
|
---|
84 | { /*likely*/ } \
|
---|
85 | else \
|
---|
86 | { \
|
---|
87 | char szTmp[256]; \
|
---|
88 | _snprintf(szTmp, sizeof(szTmp), "Assertion failed on line %u in '%s': %s", __LINE__, __PRETTY_FUNCTION__, #a_Expr); \
|
---|
89 | OutputDebugStringA(szTmp); \
|
---|
90 | _snprintf(szTmp, sizeof(szTmp), __VA_ARGS__); \
|
---|
91 | OutputDebugStringA(szTmp); \
|
---|
92 | RT_BREAKPOINT(); \
|
---|
93 | } \
|
---|
94 | } while (0)
|
---|
95 | # endif
|
---|
96 | #else
|
---|
97 | # define MY_ASSERT(a_Expr, ...) do { } while (0)
|
---|
98 | # define MY_ASSERT_STMT_RETURN(a_Expr, a_Stmt, a_rc) \
|
---|
99 | do { if (a_Expr) { /* likely */ } else { a_Stmt; return (a_rc); }} while (0)
|
---|
100 | #endif
|
---|
101 |
|
---|
102 |
|
---|
103 | /** Dynamically resolves an NTDLL API we need. */
|
---|
104 | #define RESOLVE_NTDLL_API(ApiNm) \
|
---|
105 | static bool volatile s_fInitialized##ApiNm = false; \
|
---|
106 | static decltype(ApiNm) *s_pfn##ApiNm = NULL; \
|
---|
107 | decltype(ApiNm) *pfn##ApiNm; \
|
---|
108 | if (s_fInitialized##ApiNm) \
|
---|
109 | pfn##ApiNm = s_pfn##ApiNm; \
|
---|
110 | else \
|
---|
111 | { \
|
---|
112 | pfn##ApiNm = (decltype(pfn##ApiNm))GetProcAddress(GetModuleHandleW(L"ntdll"), #ApiNm); \
|
---|
113 | s_pfn##ApiNm = pfn##ApiNm; \
|
---|
114 | s_fInitialized##ApiNm = true; \
|
---|
115 | } do {} while (0)
|
---|
116 |
|
---|
117 |
|
---|
118 | /** Declare a kernel32 API.
|
---|
119 | * @note We are not exporting them as that causes duplicate symbol troubles in
|
---|
120 | * the OpenGL bits. */
|
---|
121 | #define DECL_KERNEL32(a_Type) extern "C" a_Type WINAPI
|
---|
122 |
|
---|
123 |
|
---|
124 | /** Ignore comments. */
|
---|
125 | #define COMMENT(a_Text)
|
---|
126 |
|
---|
127 | /** Used for MAKE_IMPORT_ENTRY when declaring external g_pfnXxxx variables. */
|
---|
128 | #define DECLARE_FUNCTION_POINTER(a_Name, a_cb) extern "C" decltype(a_Name) *RT_CONCAT(g_pfn, a_Name);
|
---|
129 |
|
---|
130 | /** Used in the InitFakes method to decl are uCurVersion used by assertion. */
|
---|
131 | #ifdef RT_STRICT
|
---|
132 | # define CURRENT_VERSION_VARIABLE() \
|
---|
133 | unsigned uCurVersion = GetVersion(); \
|
---|
134 | uCurVersion = ((uCurVersion & 0xff) << 8) | ((uCurVersion >> 8) & 0xff)
|
---|
135 | #else
|
---|
136 | # define CURRENT_VERSION_VARIABLE() (void)0
|
---|
137 | #endif
|
---|
138 |
|
---|
139 |
|
---|
140 | /** Used for MAKE_IMPORT_ENTRY when resolving an import. */
|
---|
141 | #define RESOLVE_IMPORT(a_uMajorVer, a_uMinorVer, a_Name, a_cb) \
|
---|
142 | do { \
|
---|
143 | FARPROC pfnApi = GetProcAddress(hmod, #a_Name); \
|
---|
144 | if (pfnApi) \
|
---|
145 | RT_CONCAT(g_pfn, a_Name) = (decltype(a_Name) *)pfnApi; \
|
---|
146 | else \
|
---|
147 | { \
|
---|
148 | MY_ASSERT(uCurVersion < (((a_uMajorVer) << 8) | (a_uMinorVer)), #a_Name); \
|
---|
149 | RT_CONCAT(g_pfn, a_Name) = RT_CONCAT(Fake_,a_Name); \
|
---|
150 | } \
|
---|
151 | } while (0);
|
---|
152 |
|
---|
153 |
|
---|
154 | #endif /* !IPRT_INCLUDED_SRC_r3_win_vcc_fakes_h */
|
---|
155 |
|
---|