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