summaryrefslogtreecommitdiff
path: root/sal/osl
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-01-05 19:20:36 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-01-05 19:49:13 +0100
commit9d886e80ab742de49e2fe4fe62763edb21485d4e (patch)
tree1997ef52d5408779a4e664402032b4c91efc9ce3 /sal/osl
parent9b85e4e3263fe2bc75c371969256064e952d7fd4 (diff)
Simplify osl_getModuleURLFromAddress using GetModuleHandleExW
Somehow missed that in commit 515d2579d305a6127c6c194319a58eac62437e33 Date Fri Apr 05 13:15:42 2019 +0300 Replace legacy dynamically-loaded functions with statically linked ones Also drop obsolete suppressions of warning not emitted by MSVC anymore. Change-Id: If4a4c2ec76b275fb358b325652422e81e9003eb6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128019 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal/osl')
-rw-r--r--sal/osl/w32/module.cxx62
1 files changed, 13 insertions, 49 deletions
diff --git a/sal/osl/w32/module.cxx b/sal/osl/w32/module.cxx
index 798da4183e7c..201f2dd164ee 100644
--- a/sal/osl/w32/module.cxx
+++ b/sal/osl/w32/module.cxx
@@ -18,7 +18,6 @@
*/
#include "system.h"
-#include <psapi.h>
#include "file_url.hxx"
#include "path_helper.hxx"
@@ -137,14 +136,7 @@ void* SAL_CALL osl_getSymbol(oslModule Module, rtl_uString *strSymbolName)
be in this case unavoidable because the API has to stay
compatible. We need to keep this function which returns a
void* by definition */
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable:4054)
-#endif
return reinterpret_cast<void*>(osl_getFunctionSymbol(Module, strSymbolName));
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
}
oslGenericFunction SAL_CALL osl_getFunctionSymbol( oslModule Module, rtl_uString *strSymbolName )
@@ -182,44 +174,23 @@ osl_getAsciiFunctionSymbol( oslModule Module, const char *pSymbol )
sal_Bool SAL_CALL osl_getModuleURLFromAddress( void *pv, rtl_uString **pustrURL )
{
- bool bSuccess = false; /* Assume failure */
- DWORD cbNeeded = 0;
- HMODULE* lpModules = nullptr;
- DWORD nModules = 0;
- UINT iModule = 0;
- MODULEINFO modinfo;
-
- EnumProcessModules(GetCurrentProcess(), nullptr, 0, &cbNeeded);
-
- lpModules = static_cast<HMODULE*>(_alloca(cbNeeded));
- EnumProcessModules(GetCurrentProcess(), lpModules, cbNeeded, &cbNeeded);
+ HMODULE hModule{};
+ GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
+ | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ reinterpret_cast<LPCWSTR>(pv), &hModule);
+ if (!hModule)
+ return false;
- nModules = cbNeeded / sizeof(HMODULE);
+ ::osl::LongPathBuffer<sal_Unicode> aBuffer(MAX_LONG_PATH);
+ rtl_uString* ustrSysPath = nullptr;
- for (iModule = 0; !bSuccess && iModule < nModules; iModule++)
- {
- GetModuleInformation(GetCurrentProcess(), lpModules[iModule], &modinfo,
- sizeof(modinfo));
-
- if (static_cast<BYTE*>(pv) >= static_cast<BYTE*>(modinfo.lpBaseOfDll)
- && static_cast<BYTE*>(pv)
- < static_cast<BYTE*>(modinfo.lpBaseOfDll) + modinfo.SizeOfImage)
- {
- ::osl::LongPathBuffer<sal_Unicode> aBuffer(MAX_LONG_PATH);
- rtl_uString* ustrSysPath = nullptr;
+ GetModuleFileNameW(hModule, o3tl::toW(aBuffer), aBuffer.getBufSizeInSymbols());
- GetModuleFileNameW(lpModules[iModule], o3tl::toW(aBuffer),
- aBuffer.getBufSizeInSymbols());
+ rtl_uString_newFromStr(&ustrSysPath, aBuffer);
+ osl_getFileURLFromSystemPath(ustrSysPath, pustrURL);
+ rtl_uString_release(ustrSysPath);
- rtl_uString_newFromStr(&ustrSysPath, aBuffer);
- osl_getFileURLFromSystemPath(ustrSysPath, pustrURL);
- rtl_uString_release(ustrSysPath);
-
- bSuccess = true;
- }
- }
-
- return bSuccess;
+ return true;
}
sal_Bool SAL_CALL osl_getModuleURLFromFunctionAddress( oslGenericFunction addr, rtl_uString ** ppLibraryUrl )
@@ -228,14 +199,7 @@ sal_Bool SAL_CALL osl_getModuleURLFromFunctionAddress( oslGenericFunction addr,
not allowed according to the C/C++ standards. In this case
it is unavoidable because we have to stay compatible we
cannot remove any function. */
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable:4054)
-#endif
return osl_getModuleURLFromAddress(reinterpret_cast<void*>(addr), ppLibraryUrl);
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */