VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/vcc-fakes.h@ 95765

Last change on this file since 95765 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: vcc-fakes.h 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * IPRT - Common macros for the Visual C++ 2010+ CRT import fakes.
4 */
5
6/*
7 * Copyright (C) 2012-2022 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_vcc_fakes_h
28#define IPRT_INCLUDED_SRC_r3_win_vcc_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# define MY_ASSERT_STMT_RETURN(a_Expr, a_Stmt, a_rc) \
59 do { \
60 if (a_Expr) \
61 { /* likely */ } \
62 else \
63 { \
64 OutputDebugStringA("Assertion failed on line " RT_XSTR(__LINE__) ": " RT_XSTR(a_Expr) "\n"); \
65 RT_BREAKPOINT(); \
66 a_Stmt; \
67 return (a_rc); \
68 } \
69 } while (0)
70# else
71# define MY_ASSERT(a_Expr, ...) \
72 do { \
73 if ((a_Expr)) \
74 { /*likely*/ } \
75 else \
76 { \
77 char szTmp[256]; \
78 _snprintf(szTmp, sizeof(szTmp), "Assertion failed on line %u in '%s': %s", __LINE__, __PRETTY_FUNCTION__, #a_Expr); \
79 OutputDebugStringA(szTmp); \
80 _snprintf(szTmp, sizeof(szTmp), __VA_ARGS__); \
81 OutputDebugStringA(szTmp); \
82 RT_BREAKPOINT(); \
83 } \
84 } while (0)
85# endif
86#else
87# define MY_ASSERT(a_Expr, ...) do { } while (0)
88# define MY_ASSERT_STMT_RETURN(a_Expr, a_Stmt, a_rc) \
89 do { if (a_Expr) { /* likely */ } else { a_Stmt; return (a_rc); }} while (0)
90#endif
91
92
93/** Dynamically resolves an NTDLL API we need. */
94#define RESOLVE_NTDLL_API(ApiNm) \
95 static bool volatile s_fInitialized##ApiNm = false; \
96 static decltype(ApiNm) *s_pfn##ApiNm = NULL; \
97 decltype(ApiNm) *pfn##ApiNm; \
98 if (s_fInitialized##ApiNm) \
99 pfn##ApiNm = s_pfn##ApiNm; \
100 else \
101 { \
102 pfn##ApiNm = (decltype(pfn##ApiNm))GetProcAddress(GetModuleHandleW(L"ntdll"), #ApiNm); \
103 s_pfn##ApiNm = pfn##ApiNm; \
104 s_fInitialized##ApiNm = true; \
105 } do {} while (0)
106
107
108/** Declare a kernel32 API.
109 * @note We are not exporting them as that causes duplicate symbol troubles in
110 * the OpenGL bits. */
111#define DECL_KERNEL32(a_Type) extern "C" a_Type WINAPI
112
113
114/** Ignore comments. */
115#define COMMENT(a_Text)
116
117/** Used for MAKE_IMPORT_ENTRY when declaring external g_pfnXxxx variables. */
118#define DECLARE_FUNCTION_POINTER(a_Name, a_cb) extern "C" decltype(a_Name) *RT_CONCAT(g_pfn, a_Name);
119
120/** Used in the InitFakes method to decl are uCurVersion used by assertion. */
121#ifdef RT_STRICT
122# define CURRENT_VERSION_VARIABLE() \
123 unsigned uCurVersion = GetVersion(); \
124 uCurVersion = ((uCurVersion & 0xff) << 8) | ((uCurVersion >> 8) & 0xff)
125#else
126# define CURRENT_VERSION_VARIABLE() (void)0
127#endif
128
129
130/** Used for MAKE_IMPORT_ENTRY when resolving an import. */
131#define RESOLVE_IMPORT(a_uMajorVer, a_uMinorVer, a_Name, a_cb) \
132 do { \
133 FARPROC pfnApi = GetProcAddress(hmod, #a_Name); \
134 if (pfnApi) \
135 RT_CONCAT(g_pfn, a_Name) = (decltype(a_Name) *)pfnApi; \
136 else \
137 { \
138 MY_ASSERT(uCurVersion < (((a_uMajorVer) << 8) | (a_uMinorVer)), #a_Name); \
139 RT_CONCAT(g_pfn, a_Name) = RT_CONCAT(Fake_,a_Name); \
140 } \
141 } while (0);
142
143
144#endif /* !IPRT_INCLUDED_SRC_r3_win_vcc_fakes_h */
145
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