From 67ba24411fe20fb4d24cc7023834b10ca7466195 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 7 Oct 2019 11:07:05 +0300 Subject: [PATCH] Properly handle exceptions in case of dynamic libraries. (#3428) --- .../src/org/jetbrains/kotlin/backend/konan/OutputFiles.kt | 2 +- runtime/src/main/cpp/ExecFormat.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/OutputFiles.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/OutputFiles.kt index dcb275b2920..588472ee4a0 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/OutputFiles.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/OutputFiles.kt @@ -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. diff --git a/runtime/src/main/cpp/ExecFormat.cpp b/runtime/src/main/cpp/ExecFormat.cpp index fb4fe50f957..f5bd74669dd 100644 --- a/runtime/src/main/cpp/ExecFormat.cpp +++ b/runtime/src/main/cpp/ExecFormat.cpp @@ -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( - GetModuleHandle(nullptr)); + HMODULE hModule = nullptr; + int rv = GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(&AddressToSymbol), &hModule); + RuntimeAssert(rv != 0, "GetModuleHandleExW fails"); + theExeSymbolTable = konanConstructInstance(hModule); } return theExeSymbolTable->functionAddressToSymbol(address, resultBuffer, resultBufferSize); }