VirtualBox

source: vbox/trunk/include/iprt/win/lazy-dbghelp.h@ 104212

Last change on this file since 104212 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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