[*] Move setjmp to beginning of task invoker function for Linux thread kills

This commit is contained in:
Reece Wilson 2022-08-14 23:59:48 +01:00
parent e30e004d04
commit 58d53c92c1
2 changed files with 40 additions and 23 deletions

View File

@ -84,7 +84,7 @@ static void RuntimeLateClean();
static void Deinit()
{
tlsHackIsMainThread = true;
//tlsHackIsMainThread = true;
gRuntimeRunLevel = 3;
Aurora::Exit::PostLevel(AuThreads::GetThread(), Aurora::Exit::ETriggerLevel::eSafeTermination);
gRuntimeRunLevel = 4;

View File

@ -14,6 +14,7 @@
#if defined(AURORA_IS_LINUX_DERIVED)
#include <sys/resource.h>
#include <cxxabi.h>
#endif
#if defined(AURORA_HAS_PTHREADS)
@ -97,6 +98,13 @@ namespace Aurora::Threading::Threads
bool bDetached {};
bool bDetachedSuccess {};
#if defined(AURORA_IS_POSIX_DERIVED)
if (getpid() == gettid())
{
RuntimeLateClean();
}
#endif
if (this->bNotOwned)
{
return;
@ -113,7 +121,6 @@ namespace Aurora::Threading::Threads
return;
}
#endif
if (this->contextUsed_)
{
if (this->detached_)
@ -122,39 +129,38 @@ namespace Aurora::Threading::Threads
}
else
{
if (gRuntimeRunLevel < 3)
if (gRuntimeRunLevel <= 3)
{
Exit();
}
else if (gRuntimeRunLevel >= 5)
{
// Application is dead
}
else
{
if (RuntimeIsMainThread())
{
HookReleaseThreadResources();
return;
}
// Kill the current OS thread instance
TeminateOSContext(false);
if (this->exitOnlyOnce_)
{
this->exitOnlyOnce_->Unlock();
}
}
if (gRuntimeRunLevel < 4) // minimum: async deinit level
{
WaitFor(this->terminated_.get());
#if defined(AURORA_IS_POSIX_DERIVED)
if (this->terminated_)
{
WaitFor(this->terminated_.get());
}
#endif
}
}
}
this->terminated_.reset();
FreeOSContext();
if (bDetached)
{
if (this->tlsReferenceThread_)
@ -446,6 +452,15 @@ namespace Aurora::Threading::Threads
bool bFailing {};
OSAttach();
#if defined(AURORA_IS_POSIX_DERIVED)
this->bLongJmpOnce = false;
if (setjmp(env) != 0)
{
Exit(true);
}
#endif
try
{
if (task_)
@ -461,6 +476,12 @@ namespace Aurora::Threading::Threads
}
Exit(true);
#else
#if defined(AURORA_COMPILER_GCC)
catch (abi::__forced_unwind&)
{
throw;
}
#endif
catch (...)
{
bFailing = true;
@ -474,7 +495,10 @@ namespace Aurora::Threading::Threads
if (this->terminated_)
{
this->exitOnlyOnce_->Unlock();
if (this->exitOnlyOnce_)
{
this->exitOnlyOnce_->Unlock();
}
this->terminated_->Set();
}
@ -624,13 +648,6 @@ namespace Aurora::Threading::Threads
this->unixThreadId_ = 0; // !!!!
#endif
#if defined(AURORA_IS_POSIX_DERIVED)
if (setjmp(env) != 0)
{
pthread_exit(nullptr);
}
#endif
UpdatePrio(this->throttle_, this->prio_);
SetAffinity(this->mask_);
UpdateName();
@ -1077,7 +1094,7 @@ namespace Aurora::Threading::Threads
{
}
//::pthread_exit(nullptr);
::pthread_exit(nullptr);
}
else
{