VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/vcc100-fakes.h@ 70375

Last change on this file since 70375 was 70375, checked in by vboxsync, 7 years ago

iprt/vcc100-kernel32-fakes*: Redid the resolving to be more optimal for platforms that provides the APIs we fake, and also added version checks (in strict builds) that we're able to resolve the symbols.

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