sal/osl/w32/dllentry.cxx |9 -
sal/osl/w32/thread.cxx |8
sfx2/source/appl/shutdowniconw32.cxx |6 +++---
ucbhelper/source/client/proxydecider.cxx |6 --
vcl/inc/win/dnd_target.hxx |4 ++--
vcl/source/app/svmain.cxx|7 +++
vcl/win/dtrans/MtaOleClipb.cxx | 13 ++---
vcl/win/dtrans/MtaOleClipb.hxx |6 +++---
vcl/win/dtrans/source.cxx|8
vcl/win/dtrans/target.cxx|8
10 files changed, 37 insertions(+), 38 deletions(-)
New commits:
commit 8a0c43fa86bd32b4d47fd7e46d3ed414c9282ffa
Author: Mike Kaganski
AuthorDate: Wed Aug 9 14:29:54 2023 +0300
Commit: Mike Kaganski
CommitDate: Wed Aug 9 20:15:43 2023 +0200
Use _beginthreadex instead of CreateThread
The documentation for ExitThread [1] has this comment:
A thread in an executable that calls the C run-time library (CRT) should
use
the _beginthreadex and _endthreadex functions for thread management rather
than CreateThread and ExitThread; this requires the use of the
multithreaded
version of the CRT. If a thread created using CreateThread calls the CRT,
the CRT may terminate the process in low-memory conditions.
Since ~all our code uses CRT, be safe and use _beginthreadex.
[1]
https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createthread
Change-Id: If3e566592e921b00240e08aa759d8cdbc421d44b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155513
Tested-by: Jenkins
Reviewed-by: Mike Kaganski
diff --git a/sal/osl/w32/dllentry.cxx b/sal/osl/w32/dllentry.cxx
index 81139a05852b..5389c056d5a2 100644
--- a/sal/osl/w32/dllentry.cxx
+++ b/sal/osl/w32/dllentry.cxx
@@ -18,6 +18,7 @@
*/
#include
+#include
#include
#include
#include
@@ -159,7 +160,7 @@ static DWORD GetParentProcessId()
return dwParentProcessId;
}
-static DWORD WINAPI ParentMonitorThreadProc( LPVOID lpParam )
+static unsigned __stdcall ParentMonitorThreadProc(void* lpParam)
{
DWORD_PTR dwParentProcessId = reinterpret_cast(lpParam);
@@ -196,8 +197,6 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID )
if ( dwResult && dwResult < SAL_N_ELEMENTS(szBuffer) )
{
-DWORD dwThreadId = 0;
-
DWORD_PTR dwParentProcessId = static_cast(_wtol(
szBuffer ));
if ( dwParentProcessId && GetParentProcessId() ==
dwParentProcessId )
@@ -205,8 +204,8 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID )
// No error check, it works or it does not
// Thread should only be started for headless mode, see
desktop/win32/source/officeloader.cxx
HANDLE hThread
-= CreateThread(nullptr, 0, ParentMonitorThreadProc,
-
reinterpret_cast(dwParentProcessId), 0, );
+= reinterpret_cast(_beginthreadex(nullptr, 0,
ParentMonitorThreadProc,
+
reinterpret_cast(dwParentProcessId), 0, nullptr));
// Note: calling CreateThread in DllMain is discouraged
// but this is only done in the headless mode and in
// that case no other threads should be running at startup
diff --git a/sal/osl/w32/thread.cxx b/sal/osl/w32/thread.cxx
index f6b3109adfb9..3640d43b9992 100644
--- a/sal/osl/w32/thread.cxx
+++ b/sal/osl/w32/thread.cxx
@@ -43,7 +43,7 @@ namespace {
typedef struct
{
HANDLE m_hThread; /* OS-handle used for all
thread-functions */
-DWORD m_ThreadId; /* identifier for this thread */
+unsignedm_ThreadId; /* identifier for this thread */
sal_Int32 m_nTerminationRequested;
oslWorkerFunction m_WorkerFunction;
void* m_pData;
@@ -54,7 +54,7 @@ typedef struct
static oslThread oslCreateThread(oslWorkerFunction pWorker, void* pThreadData,
sal_uInt32 nFlags);
-static DWORD WINAPI oslWorkerWrapperFunction(_In_ LPVOID pData)
+static unsigned __stdcall oslWorkerWrapperFunction(void* pData)
{
osl_TThreadImpl* pThreadImpl= static_cast(pData);
@@ -89,13 +89,13 @@ static oslThread oslCreateThread(oslWorkerFunction pWorker,
pThreadImpl->m_pData= pThreadData;
pThreadImpl->m_nTerminationRequested= 0;
-pThreadImpl->m_hThread= CreateThread(
+pThreadImpl->m_hThread= reinterpret_cast(_beginthreadex(
nullptr, /* no security */
0, /* default
stack-size */
oslWorkerWrapperFunction,/* worker-function
*/
pThreadImpl, /* provide