From 8d8e5ab9193785acc4e1cb05e0db7f97afde1e2b Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 27 Aug 2021 10:28:11 +0200 Subject: Use PSAPI functionality directly Dynamically trying to obtain the two PSAPI functions was apparently originally done because "This version can fail because PSAPI.DLL is not always part of NT 4 despite MSDN Libary 6.0a say so", according to the comment added with 961512bd9ae008fdd8ab5cdf1ba6b5d25ffb0429 "#94875# Added additional method (for NT4) to determine the module containing an address". (That comment was removed again in 515d2579d305a6127c6c194319a58eac62437e33 "Replace legacy dynamically- loaded functions with statically linked ones", which curiously left the dynamic loading of PSAPI.DLL in place there, though.) states that the PSAPI functionality is available in "Kernel32.dll on Windows 7 and Windows Server 2008 R2; Psapi.dll (if PSAPI_VERSION=1) on Windows 7 and Windows Server 2008 R2; Psapi.dll on Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP". I do not find any mention of PSAPI_VERSION across our code base, so assume that PSAPI_VERSION=1 would be some legacy mode that we do not use, so with our baseline of Windows 7 (cf. README.md), relying on the PSAPI functionality being available without adding anything specific to gb_Library_use_system_win32_libs,sal should presumably be OK. Change-Id: I55ab29be2a3ee3984c6987e953819cb2e92e4aa8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121136 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- sal/osl/w32/module.cxx | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'sal') diff --git a/sal/osl/w32/module.cxx b/sal/osl/w32/module.cxx index 620be0e6d664..ab50450daf7d 100644 --- a/sal/osl/w32/module.cxx +++ b/sal/osl/w32/module.cxx @@ -182,15 +182,6 @@ osl_getAsciiFunctionSymbol( oslModule Module, const char *pSymbol ) sal_Bool SAL_CALL osl_getModuleURLFromAddress( void *pv, rtl_uString **pustrURL ) { - static HMODULE hModPsapi = LoadLibraryW( L"PSAPI.DLL" ); - static auto lpfnEnumProcessModules = reinterpret_cast( - hModPsapi ? GetProcAddress(hModPsapi, "EnumProcessModules") : nullptr); - static auto lpfnGetModuleInformation = reinterpret_cast( - hModPsapi ? GetProcAddress(hModPsapi, "GetModuleInformation") : nullptr); - - if (!lpfnEnumProcessModules || !lpfnGetModuleInformation) - return false; - bool bSuccess = false; /* Assume failure */ DWORD cbNeeded = 0; HMODULE* lpModules = nullptr; @@ -198,16 +189,16 @@ sal_Bool SAL_CALL osl_getModuleURLFromAddress( void *pv, rtl_uString **pustrURL UINT iModule = 0; MODULEINFO modinfo; - lpfnEnumProcessModules(GetCurrentProcess(), nullptr, 0, &cbNeeded); + EnumProcessModules(GetCurrentProcess(), nullptr, 0, &cbNeeded); lpModules = static_cast(_alloca(cbNeeded)); - lpfnEnumProcessModules(GetCurrentProcess(), lpModules, cbNeeded, &cbNeeded); + EnumProcessModules(GetCurrentProcess(), lpModules, cbNeeded, &cbNeeded); nModules = cbNeeded / sizeof(HMODULE); for (iModule = 0; !bSuccess && iModule < nModules; iModule++) { - lpfnGetModuleInformation(GetCurrentProcess(), lpModules[iModule], &modinfo, + GetModuleInformation(GetCurrentProcess(), lpModules[iModule], &modinfo, sizeof(modinfo)); if (static_cast(pv) >= static_cast(modinfo.lpBaseOfDll) -- cgit