From c236e10be6a269eef9c237989358fd495c5306d7 Mon Sep 17 00:00:00 2001 From: Shweta Khatri Date: Fri, 21 Oct 2022 13:46:17 -0400 Subject: [PATCH] Fixed callback method for dl_iterate_phdr api which is called for each loaded shared object Simplified the callback method. Also fixed the way, loaded shared object were getting appended into a string vector, which was not being passed to this callback method. Change-Id: I68661dd73f61a11c42fa92f670e8e7b6ffcb5711 [ROCm/ROCR-Runtime commit: 8751e65b79d2cf399aa69a333cb489a879313800] --- .../hsa-runtime/core/util/lnx/os_linux.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp index afa71bd5cd..c80cad67e2 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp @@ -204,24 +204,24 @@ void* GetExportAddress(LibHandle lib, std::string export_name) { void CloseLib(LibHandle lib) { dlclose(*(void**)&lib); } +static int callback(struct dl_phdr_info* info, size_t size, void* data) { + if ((info) && (info->dlpi_name[0] != '\0')) { + std::vector* loadedlib = (std::vector*)data; + loadedlib->push_back(info->dlpi_name); + } + return 0; +} + std::vector GetLoadedLibs() { std::vector ret; std::vector names; - auto callback = [&](dl_phdr_info* info) { - if(info->dlpi_name[0] != '\0') - names.push_back(info->dlpi_name); - }; - typedef decltype(callback) call_t; - dl_iterate_phdr([](dl_phdr_info* info, size_t size, void* data){ - auto& call = *(call_t*)data; - call(info); - return 0; - }, &callback); + dl_iterate_phdr(callback, &names); - for(auto& name : names) - ret.push_back(LoadLib(name)); + if (!names.empty()) { + for (auto& name : names) ret.push_back(LoadLib(name)); + } return ret; }