From d25bd3d7e5e5d242092d893c630df04358cfe669 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 21 Jun 2026 18:07:03 +0900 Subject: [PATCH] Unix: honor configured pthread stack size --- src/Platform/Thread.h | 2 +- src/Platform/Unix/Thread.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Platform/Thread.h b/src/Platform/Thread.h index f0c45be5..b1152af5 100644 --- a/src/Platform/Thread.h +++ b/src/Platform/Thread.h @@ -64,7 +64,7 @@ namespace VeraCrypt return 0; } - static const size_t MinThreadStackSize = 1024 * 1024; + static const size_t MinThreadStackSize = 8 * 1024 * 1024; ThreadSystemHandle SystemHandle; diff --git a/src/Platform/Unix/Thread.cpp b/src/Platform/Unix/Thread.cpp index 47046eee..3bfcd956 100644 --- a/src/Platform/Unix/Thread.cpp +++ b/src/Platform/Unix/Thread.cpp @@ -18,6 +18,26 @@ namespace VeraCrypt { + namespace + { + struct PthreadAttr + { + PthreadAttr () + { + int status = pthread_attr_init (&Attr); + if (status != 0) + throw SystemException (SRC_POS, status); + } + + ~PthreadAttr () + { + pthread_attr_destroy (&Attr); + } + + pthread_attr_t Attr; + }; + } + void Thread::Join () const { int status = pthread_join (SystemHandle, nullptr); @@ -27,26 +47,22 @@ namespace VeraCrypt void Thread::Start (ThreadProcPtr threadProc, void *parameter) { - pthread_attr_t attr; + PthreadAttr attr; size_t stackSize = 0; int status; - status = pthread_attr_init (&attr); - if (status != 0) - throw SystemException (SRC_POS, status); - - status = pthread_attr_getstacksize (&attr, &stackSize); + status = pthread_attr_getstacksize (&attr.Attr, &stackSize); if (status != 0) throw SystemException (SRC_POS, status); if (stackSize < MinThreadStackSize) { - status = pthread_attr_setstacksize (&attr, MinThreadStackSize); + status = pthread_attr_setstacksize (&attr.Attr, MinThreadStackSize); if (status != 0) throw SystemException (SRC_POS, status); } - status = pthread_create (&SystemHandle, nullptr, threadProc, parameter); + status = pthread_create (&SystemHandle, &attr.Attr, threadProc, parameter); if (status != 0) throw SystemException (SRC_POS, status); }