diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-08-27 10:28:11 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-08-27 11:32:29 +0200 |
commit | 8d8e5ab9193785acc4e1cb05e0db7f97afde1e2b (patch) | |
tree | 367a74edb2f2d7e65bf6c34c6bf009eca0ad87b3 /sal | |
parent | c4709b6192340a4d5a82bf156a7342aba6aa99a1 (diff) |
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.)
<https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumprocessmodules>
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 <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/w32/module.cxx | 15 |
1 files changed, 3 insertions, 12 deletions
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<decltype(EnumProcessModules)*>( - hModPsapi ? GetProcAddress(hModPsapi, "EnumProcessModules") : nullptr); - static auto lpfnGetModuleInformation = reinterpret_cast<decltype(GetModuleInformation)*>( - 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<HMODULE*>(_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<BYTE*>(pv) >= static_cast<BYTE*>(modinfo.lpBaseOfDll) |