Properly handle exceptions in case of dynamic libraries. (#3428)

This commit is contained in:
Nikolay Igotti
2019-10-07 11:07:05 +03:00
committed by GitHub
parent c42a53bcc9
commit 67ba24411f
2 changed files with 6 additions and 3 deletions
@@ -27,7 +27,7 @@ class OutputFiles(outputPath: String?, target: KonanTarget, produce: CompilerOut
* Header file for dynamic library.
*/
val cAdapterHeader by lazy { File("${outputName}_api.h") }
val cAdapterDef by lazy { File("${outputName}_symbols.def") }
val cAdapterDef by lazy { File("${outputName}.def") }
/**
* Main compiler's output file.
+5 -2
View File
@@ -315,8 +315,11 @@ extern "C" bool AddressToSymbol(const void* address, char* resultBuffer, size_t
if (theExeSymbolTable == nullptr) {
// Note: do not protecting the lazy initialization by critical sections for simplicity;
// this doesn't have any serious consequences.
theExeSymbolTable = konanConstructInstance<SymbolTable>(
GetModuleHandle(nullptr));
HMODULE hModule = nullptr;
int rv = GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(&AddressToSymbol), &hModule);
RuntimeAssert(rv != 0, "GetModuleHandleExW fails");
theExeSymbolTable = konanConstructInstance<SymbolTable>(hModule);
}
return theExeSymbolTable->functionAddressToSymbol(address, resultBuffer, resultBufferSize);
}