@@ -47,16 +47,11 @@ int swift::lookupSymbol(const void *address, SymbolInfo *info) {
47
47
return 0 ;
48
48
}
49
49
50
- char buffer[sizeof (SYMBOL_INFO) + kSymbolMaxNameLen ];
51
- PSYMBOL_INFO pSymbol = reinterpret_cast <PSYMBOL_INFO>(buffer);
50
+ SYMBOL_INFO_PACKAGE symbol = {};
52
51
pSymbol->SizeOfStruct = sizeof (SYMBOL_INFO);
53
- pSymbol->MaxNameLen = kSymbolMaxNameLen ;
54
-
55
- DWORD64 dwDisplacement = 0 ;
56
-
57
- if (SymFromAddr (GetCurrentProcess (),
58
- reinterpret_cast <const DWORD64>(address),
59
- &dwDisplacement, pSymbol) == FALSE ) {
52
+ pSymbol->MaxNameLen = MAX_SYM_NAME;
53
+ if (SymFromAddr (hProcess, reinterpret_cast <const DWORD64>(address),
54
+ &nullptr , pSymbol) == FALSE ) {
60
55
return 0 ;
61
56
}
62
57
@@ -83,7 +78,18 @@ void swift::_swift_withWin32DbgHelpLibrary(
83
78
// now. This handle belongs to the Swift runtime and should not be closed by
84
79
// `body` (or anybody else.)
85
80
if (!dbgHelpHandle) {
86
- dbgHelpHandle = HeapAlloc (GetProcessHeap (), 0 , 1 );
81
+ // Per the documentation for the Debug Help library, we should not use the
82
+ // current process handle because other subsystems might also use it and
83
+ // end up stomping on each other. So we'll try to duplicate that handle to
84
+ // get a unique one that still fulfills the needs of the library. If that
85
+ // fails (presumably because the current process doesn't have the
86
+ // PROCESS_DUP_HANDLE access right) then fall back to using the original
87
+ // process handle and hope nobody else is using it too.
88
+ HANDLE currentProcess = GetCurrentProcess ();
89
+ if (!DuplicateHandle (currentProcess, currentProcess, currentProcess,
90
+ &dbgHelpHandle, 0 , false , DUPLICATE_SAME_ACCESS)) {
91
+ dbgHelpHandle = currentProcess;
92
+ }
87
93
}
88
94
89
95
// If we have not previously initialized the Debug Help library, do so now.
@@ -96,7 +102,7 @@ void swift::_swift_withWin32DbgHelpLibrary(
96
102
// Set the library's options to what the Swift runtime generally expects.
97
103
// If the options aren't going to change, we can skip the call and save a
98
104
// few CPU cycles on the library call.
99
- static constexpr const DWORD options = SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS;
105
+ constexpr const DWORD options = SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS;
100
106
DWORD oldOptions = SymGetOptions ();
101
107
if (oldOptions != options) {
102
108
SymSetOptions (options);
0 commit comments