Unix: honor configured pthread stack size

This commit is contained in:
Mounir IDRASSI
2026-06-21 18:07:03 +09:00
parent 4f7d69be53
commit d25bd3d7e5
2 changed files with 25 additions and 9 deletions
+1 -1
View File
@@ -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;
+24 -8
View File
@@ -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);
}