1 | /** @file
|
---|
2 | * Symbols from dbghelp.dll, allowing us to select which one to load.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2013-2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_win_lazy_dbghelp_h
|
---|
27 | #define IPRT_INCLUDED_win_lazy_dbghelp_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/ldrlazy.h>
|
---|
33 | #include <iprt/path.h>
|
---|
34 | #include <iprt/env.h>
|
---|
35 | #include <iprt/errcore.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Custom loader callback.
|
---|
40 | * @returns Module handle or NIL_RTLDRMOD.
|
---|
41 | */
|
---|
42 | static int rtLdrLazyLoadDbgHelp(const char *pszFile, PRTLDRMOD phMod)
|
---|
43 | {
|
---|
44 | static const struct
|
---|
45 | {
|
---|
46 | const char *pszEnv;
|
---|
47 | const char *pszSubDir;
|
---|
48 | } s_aLocations[] =
|
---|
49 | {
|
---|
50 | #ifdef RT_ARCH_AMD64
|
---|
51 | { "ProgramFiles(x86)", "Windows Kits\\8.1\\Debuggers\\x64\\dbghelp.dll" },
|
---|
52 | { "ProgramFiles(x86)", "Windows Kits\\8.0\\Debuggers\\x64\\dbghelp.dll" },
|
---|
53 | { "ProgramFiles", "Debugging Tools for Windows (x64)\\dbghelp.dll" },
|
---|
54 | #else
|
---|
55 | { "ProgramFiles", "Windows Kits\\8.1\\Debuggers\\x86\\dbghelp.dll" },
|
---|
56 | { "ProgramFiles", "Windows Kits\\8.0\\Debuggers\\x86\\dbghelp.dll" },
|
---|
57 | { "ProgramFiles", "Debugging Tools for Windows (x86)\\dbghelp.dll" },
|
---|
58 | #endif /** @todo More places we should look? */
|
---|
59 | };
|
---|
60 | uint32_t i;
|
---|
61 | for (i = 0; i < RT_ELEMENTS(s_aLocations); i++)
|
---|
62 | {
|
---|
63 | char szPath[RTPATH_MAX];
|
---|
64 | size_t cchPath;
|
---|
65 | int rc = RTEnvGetEx(RTENV_DEFAULT, s_aLocations[i].pszEnv, szPath, sizeof(szPath), &cchPath);
|
---|
66 | if (RT_SUCCESS(rc))
|
---|
67 | {
|
---|
68 | rc = RTPathAppend(szPath, sizeof(szPath), s_aLocations[i].pszSubDir);
|
---|
69 | if (RT_SUCCESS(rc))
|
---|
70 | {
|
---|
71 | rc = RTLdrLoad(szPath, phMod);
|
---|
72 | if (RT_SUCCESS(rc))
|
---|
73 | return rc;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* Fall back on the system one, if present. */
|
---|
79 | return RTLdrLoadSystem(pszFile, true /*fNoUnload*/, phMod);
|
---|
80 | }
|
---|
81 |
|
---|
82 | RTLDRLAZY_MODULE_EX(dbghelp, "dbghelp.dll", rtLdrLazyLoadDbgHelp);
|
---|
83 |
|
---|
84 | RTLDRLAZY_FUNC(dbghelp, BOOL, WINAPI, SymInitialize, (HANDLE a1, PCWSTR a2, BOOL a3), (a1, a2, a3), FALSE);
|
---|
85 | #undef SymInitialize
|
---|
86 | #define SymInitialize RTLDRLAZY_FUNC_NAME(dbghelp, SymInitialize)
|
---|
87 |
|
---|
88 | RTLDRLAZY_FUNC(dbghelp, BOOL, WINAPI, SymCleanup, (HANDLE a1), (a1), FALSE);
|
---|
89 | #undef SymCleanup
|
---|
90 | #define SymCleanup RTLDRLAZY_FUNC_NAME(dbghelp, SymCleanup)
|
---|
91 |
|
---|
92 | RTLDRLAZY_FUNC(dbghelp, DWORD, WINAPI, SymGetOptions, (VOID), (), 0);
|
---|
93 | #undef SymGetOptions
|
---|
94 | #define SymGetOptions RTLDRLAZY_FUNC_NAME(dbghelp, SymGetOptions)
|
---|
95 |
|
---|
96 | RTLDRLAZY_FUNC(dbghelp, DWORD, WINAPI, SymSetOptions, (DWORD a1), (a1), 0);
|
---|
97 | #undef SymSetOptions
|
---|
98 | #define SymSetOptions RTLDRLAZY_FUNC_NAME(dbghelp, SymSetOptions)
|
---|
99 |
|
---|
100 | RTLDRLAZY_FUNC(dbghelp, BOOL, WINAPI, SymRegisterCallback64, (HANDLE a1, PSYMBOL_REGISTERED_CALLBACK64 a2, ULONG64 a3),
|
---|
101 | (a1, a2, a3), FALSE);
|
---|
102 | #undef SymRegisterCallback64
|
---|
103 | #define SymRegisterCallback64 RTLDRLAZY_FUNC_NAME(dbghelp, SymRegisterCallback64)
|
---|
104 |
|
---|
105 | RTLDRLAZY_FUNC(dbghelp, DWORD64, WINAPI, SymLoadModuleEx,
|
---|
106 | (HANDLE a1, HANDLE a2, PCSTR a3, PCSTR a4, DWORD64 a5, DWORD a6, PMODLOAD_DATA a7, DWORD a8),
|
---|
107 | (a1, a2, a3, a4, a5, a6, a7, a8), 0);
|
---|
108 | #undef SymLoadModuleEx
|
---|
109 | #define SymLoadModuleEx RTLDRLAZY_FUNC_NAME(dbghelp, SymLoadModuleEx)
|
---|
110 |
|
---|
111 | RTLDRLAZY_FUNC(dbghelp, DWORD64, WINAPI, SymLoadModuleExW,
|
---|
112 | (HANDLE a1, HANDLE a2, PCWSTR a3, PCWSTR a4, DWORD64 a5, DWORD a6, PMODLOAD_DATA a7, DWORD a8),
|
---|
113 | (a1, a2, a3, a4, a5, a6, a7, a8), 0);
|
---|
114 | #undef SymLoadModuleExW
|
---|
115 | #define SymLoadModuleExW RTLDRLAZY_FUNC_NAME(dbghelp, SymLoadModuleExW)
|
---|
116 |
|
---|
117 | RTLDRLAZY_FUNC(dbghelp, DWORD64, WINAPI, SymUnloadModule64, (HANDLE a1, DWORD64 a2), (a1, a2), 0);
|
---|
118 | #undef SymUnloadModule64
|
---|
119 | #define SymUnloadModule64 RTLDRLAZY_FUNC_NAME(dbghelp, SymUnloadModule64)
|
---|
120 |
|
---|
121 | RTLDRLAZY_FUNC(dbghelp, BOOL, WINAPI, SymEnumSymbols,
|
---|
122 | (HANDLE a1, ULONG64 a2, PCSTR a3, PSYM_ENUMERATESYMBOLS_CALLBACK a4, PVOID a5),
|
---|
123 | (a1, a2, a3, a4, a5), FALSE);
|
---|
124 | #undef SymEnumSymbols
|
---|
125 | #define SymEnumSymbols RTLDRLAZY_FUNC_NAME(dbghelp, SymEnumSymbols)
|
---|
126 |
|
---|
127 | RTLDRLAZY_FUNC(dbghelp, BOOL, WINAPI, SymEnumLinesW,
|
---|
128 | (HANDLE a1, ULONG64 a2, PCWSTR a3, PCWSTR a4, PSYM_ENUMLINES_CALLBACKW a5, PVOID a6),
|
---|
129 | (a1, a2, a3, a4, a5, a6), FALSE);
|
---|
130 | #undef SymEnumLinesW
|
---|
131 | #define SymEnumLinesW RTLDRLAZY_FUNC_NAME(dbghelp, SymEnumLinesW)
|
---|
132 |
|
---|
133 | RTLDRLAZY_FUNC(dbghelp, BOOL, WINAPI, SymGetModuleInfo64, (HANDLE a1, DWORD64 a2, PIMAGEHLP_MODULE64 a3), (a1, a2, a3), FALSE);
|
---|
134 | #undef SymGetModuleInfo64
|
---|
135 | #define SymGetModuleInfo64 RTLDRLAZY_FUNC_NAME(dbghelp, SymGetModuleInfo64)
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 | #endif /* !IPRT_INCLUDED_win_lazy_dbghelp_h */
|
---|
141 |
|
---|