[*] mitigations and clean up before two major commits

This commit is contained in:
Reece Wilson 2023-12-26 21:01:29 +00:00
parent d17903251b
commit be2b781ed6
23 changed files with 59 additions and 43 deletions

View File

@ -16,7 +16,7 @@ namespace Aurora::Logging
AUKN_SYM AuResult<AuUInt8> LogClassGetNext(); AUKN_SYM AuResult<AuUInt8> LogClassGetNext();
AUKN_SYM void LogClassRelease(AuUInt8 uIndex); AUKN_SYM void LogClassRelease(AuUInt8 uIndex);
AUKN_SYM void LogClassAssociateName(AuUInt8 uIndex, const AuString &str); AUKN_SYM bool LogClassAssociateName(AuUInt8 uIndex, const AuString &str);
AUKN_SYM AuString LogClassGetNameSafe(AuUInt8 uIndex); AUKN_SYM AuString LogClassGetNameSafe(AuUInt8 uIndex);
AUKN_SYM const AuString &LogClassGetNameUnsafe(AuUInt8 uIndex); AUKN_SYM const AuString &LogClassGetNameUnsafe(AuUInt8 uIndex);

View File

@ -588,15 +588,15 @@ namespace Aurora::Memory
{ {
AuSPtr<void> memory; AuSPtr<void> memory;
inline SharedByteBuffer(AuSPtr<MemoryViewWrite> pReadView) : ByteBuffer() inline SharedByteBuffer(AuSPtr<MemoryViewWrite> pWriteView) : ByteBuffer()
{ {
this->allocSize = 0; this->allocSize = 0;
this->base = (AuUInt8 *)pReadView->ptr; this->base = (AuUInt8 *)pWriteView->ptr;
this->length = pReadView->length; this->length = pWriteView->length;
this->readPtr = this->base; this->readPtr = this->base;
this->writePtr = this->base + this->length; this->writePtr = this->base + this->length;
this->flagNoFree = true; this->flagNoFree = true;
this->memory = pReadView; this->memory = pWriteView;
} }
inline SharedByteBuffer(AuSPtr<void> pRAIIParentOwner, MemoryViewWrite view) : ByteBuffer() inline SharedByteBuffer(AuSPtr<void> pRAIIParentOwner, MemoryViewWrite view) : ByteBuffer()

View File

@ -78,6 +78,7 @@ using AuRWRenterableLock = AuThreadPrimitives::RWRenterableLock;
using AuRWLock = AuThreadPrimitives::RWLock; using AuRWLock = AuThreadPrimitives::RWLock;
using AuCond = AuThreadPrimitives::ConditionVariable; using AuCond = AuThreadPrimitives::ConditionVariable;
using AuConditionVariable = AuThreadPrimitives::ConditionVariable; using AuConditionVariable = AuThreadPrimitives::ConditionVariable;
using AuConditionMutex = AuThreadPrimitives::ConditionMutex;
using AuCondition = AuThreadPrimitives::ConditionVariable; using AuCondition = AuThreadPrimitives::ConditionVariable;
using AuCondMutex = AuThreadPrimitives::ConditionMutex; using AuCondMutex = AuThreadPrimitives::ConditionMutex;
using AuSpinLock = AuThreadPrimitives::SpinLock; using AuSpinLock = AuThreadPrimitives::SpinLock;

View File

@ -25,8 +25,8 @@ namespace Aurora::Async
// sched thread threading: // sched thread threading:
static AuThreads::ThreadUnique_t gThread; static AuThreads::ThreadUnique_t gThread;
static AuThreadPrimitives::ConditionMutex gSchedLock; static AuConditionMutex gSchedLock;
static AuThreadPrimitives::ConditionVariable gSchedCondvar(AuUnsafeRaiiToShared(gSchedLock.AsPointer())); static AuConditionVariable gSchedCondvar(AuUnsafeRaiiToShared(gSchedLock.AsPointer()));
// next tick timing: // next tick timing:
static AuUInt64 uNextSysTickGuessed {}; static AuUInt64 uNextSysTickGuessed {};

View File

@ -27,8 +27,8 @@ namespace Aurora::Async
{ {
ThreadStateSync(); ThreadStateSync();
AuThreadPrimitives::ConditionMutex cvWorkMutex; AuConditionMutex cvWorkMutex;
AuThreadPrimitives::ConditionVariable cvVariable; AuConditionVariable cvVariable;
AuAUInt32 cvLSActive {}; AuAUInt32 cvLSActive {};
AuAUInt32 cvHasWork {}; AuAUInt32 cvHasWork {};
AuSPtr<AuLoop::ILSEvent> eventLs; AuSPtr<AuLoop::ILSEvent> eventLs;

View File

@ -150,10 +150,10 @@ namespace Aurora::Async
AuUInt32 shuttingdown_ {}; AuUInt32 shuttingdown_ {};
bool shutdown {}; bool shutdown {};
AuThreadPrimitives::RWRenterableLock rwlock_; AuRWRenterableLock rwlock_;
AuThreading::IWaitable *pRWReadView {}; AuThreading::IWaitable *pRWReadView {};
AuThreadPrimitives::Event shutdownEvent_; AuEvent shutdownEvent_;
bool runnersRunning_ {}; bool runnersRunning_ {};
AuList<AuWPtr<ThreadPool>> listWeakDeps_; AuList<AuWPtr<ThreadPool>> listWeakDeps_;
AuList<AuWPtr<ThreadPool>> listWeakDepsParents_; AuList<AuWPtr<ThreadPool>> listWeakDepsParents_;

View File

@ -24,8 +24,8 @@ namespace Aurora::Async
{ } { }
// :vomit: // :vomit:
AuThreadPrimitives::Semaphore syncSema; AuSemaphore syncSema;
AuThreadPrimitives::Event isDeadEvent; AuEvent isDeadEvent;
bool exiting {}; bool exiting {};
bool shuttingdown {}; bool shuttingdown {};
bool exitingflag2 {}; bool exitingflag2 {};

View File

@ -78,9 +78,9 @@ namespace Aurora::Async
EWorkPriority prio_ = EWorkPriority::ePriorityNormal; EWorkPriority prio_ = EWorkPriority::ePriorityNormal;
AuList<AuSPtr<IWorkItem>> waitOn_; AuList<AuSPtr<IWorkItem>> waitOn_;
AuList<AuSPtr<IWorkItem>> waiters_; AuList<AuSPtr<IWorkItem>> waiters_;
AuThreadPrimitives::CriticalSection lock; AuCriticalSection lock;
AuThreadPrimitives::CriticalSection lock2; AuCriticalSection lock2;
AuThreadPrimitives::Event finishedEvent_; AuEvent finishedEvent_;
AuUInt32 uShutdownCookie {}; AuUInt32 uShutdownCookie {};
AuOptionalEx<AuUInt32> optOtherCookie {}; AuOptionalEx<AuUInt32> optOtherCookie {};
AuSPtr<AuIO::IIOProcessorItem> pIOWatch; AuSPtr<AuIO::IIOProcessorItem> pIOWatch;

View File

@ -45,14 +45,13 @@ namespace Aurora::Compression
auto bufferSize = meta.uInternalStreamSize; auto bufferSize = meta.uInternalStreamSize;
this->pBufferIn_ = AuSPtr<char>(new char[bufferSize], AuDefaultDeleter<char[]>()); this->pBufferIn_ = AuMakeSharedArray<char>(bufferSize);
if (!this->pBufferIn_) if (!this->pBufferIn_)
{ {
return {}; return {};
} }
this->pBufferOut_ = AuSPtr<char>(new char[bufferSize], AuDefaultDeleter<char[]>()); this->pBufferOut_ = AuMakeSharedArray<char>(bufferSize);
if (!this->pBufferOut_) if (!this->pBufferOut_)
{ {
return {}; return {};

View File

@ -134,7 +134,7 @@ namespace Aurora::Console::ConsoleStd
static AuList<NoncanonicalInput> gCanonicalBuffer; static AuList<NoncanonicalInput> gCanonicalBuffer;
//static AuThreadPrimitives::MutexUnique_t gRingLock = AuThreadPrimitives::MutexUnique(); //static AuThreadPrimitives::MutexUnique_t gRingLock = AuThreadPrimitives::MutexUnique();
static AuThreadPrimitives::SpinLock gRingLock;// = AuThreadPrimitives::MutexUnique(); static AuMutex gRingLock;// = AuThreadPrimitives::MutexUnique();
static bool gBufferMode {}; static bool gBufferMode {};
static bool gCanonicalUnixOn {}; static bool gCanonicalUnixOn {};
@ -1575,9 +1575,9 @@ namespace Aurora::Console::ConsoleStd
return 0; return 0;
} }
gRingLock.Lock(); gRingLock->Lock();
gEncodedIndex += read; gEncodedIndex += read;
gRingLock.Unlock(); gRingLock->Unlock();
return read; return read;
@ -1589,9 +1589,9 @@ namespace Aurora::Console::ConsoleStd
return 0; return 0;
} }
gRingLock.Lock(); gRingLock->Lock();
gEncodedIndex += bread; gEncodedIndex += bread;
gRingLock.Unlock(); gRingLock->Unlock();
return bread; return bread;

View File

@ -230,10 +230,10 @@ namespace Aurora::Console::ConsoleTTY
int iHistoryWritePos {0}; int iHistoryWritePos {0};
AuList<AuString> history; AuList<AuString> history;
AuThreadPrimitives::RWLock historyLock; AuRWLock historyLock;
AuThreadPrimitives::SpinLock messageLock; AuMutex messageLock;
AuList<AuConsole::ConsoleMessage> messagesPending; AuList<AuConsole::ConsoleMessage> messagesPending;
AuList<AuConsole::ConsoleMessage> messages; AuList<AuConsole::ConsoleMessage> messages;

View File

@ -26,7 +26,7 @@
class ConsoleFrame; class ConsoleFrame;
static AuList<Aurora::Console::ConsoleMessage> gPendingLines; static AuList<Aurora::Console::ConsoleMessage> gPendingLines;
static AuThreadPrimitives::Mutex gMutex; static AuMutex gMutex;
static bool gWxConsoleReady; static bool gWxConsoleReady;
static bool gConsoleStarted = false; static bool gConsoleStarted = false;
static ConsoleFrame *gWxFrame; static ConsoleFrame *gWxFrame;

View File

@ -30,7 +30,7 @@ namespace Aurora::Console::ConsoleTTY
namespace Aurora::Exit namespace Aurora::Exit
{ {
static AuThreadPrimitives::Mutex gMutex; static AuMutex gMutex;
static AuList<AuTuple<AuSPtr<IExitSubscriber>, ETriggerLevel>> gTriggerSubscribers; static AuList<AuTuple<AuSPtr<IExitSubscriber>, ETriggerLevel>> gTriggerSubscribers;
static bool gIsAppRunning {true}; static bool gIsAppRunning {true};
@ -158,8 +158,11 @@ namespace Aurora::Exit
AUKN_SYM bool ExitHandlerAdd(ETriggerLevel level, const AuSPtr<IExitSubscriber> &callback) AUKN_SYM bool ExitHandlerAdd(ETriggerLevel level, const AuSPtr<IExitSubscriber> &callback)
{ {
if (!ETriggerLevelIsValid(level))
{
return false;
}
AU_LOCK_GUARD(gMutex); AU_LOCK_GUARD(gMutex);
return AuTryInsert(gTriggerSubscribers, AuMakePair(callback, level)); return AuTryInsert(gTriggerSubscribers, AuMakePair(callback, level));
} }

View File

@ -80,7 +80,11 @@ namespace Aurora::IO::FS
if (AuEndsWith(currentName, "$DATA")) if (AuEndsWith(currentName, "$DATA"))
{ {
currentName.resize(currentName.size() - 5); if (!AuTryResize(currentName, currentName.size() - 5))
{
SysPushErrorMemory();
continue;
}
} }
} }

View File

@ -133,7 +133,11 @@ namespace Aurora::IO::Net
this->addressLengthA_ = 0; this->addressLengthA_ = 0;
this->addresses_.resize((this->pParent_->endpointSize_ + 16) * 2); if (!AuTryResize(this->addresses_,
(this->pParent_->endpointSize_ + 16) * 2))
{
return false;
}
auto bRet = lpfnAcceptEx(this->pParent_->ToPlatformHandle(), auto bRet = lpfnAcceptEx(this->pParent_->ToPlatformHandle(),
this->nextSocket, this->nextSocket,

View File

@ -12,11 +12,15 @@ namespace Aurora::Logging
{ {
AuSPtr<IFormatter> FormatterContainer::GetFormatter() AuSPtr<IFormatter> FormatterContainer::GetFormatter()
{ {
// extreme mitigation: prevent control block race conditions
AU_LOCK_GUARD(this->mutex);
return this->pFormatter; return this->pFormatter;
} }
void FormatterContainer::SetFormatter(const AuSPtr<IFormatter> &pFormatter) void FormatterContainer::SetFormatter(const AuSPtr<IFormatter> &pFormatter)
{ {
// extreme mitigation: prevent control block race conditions
AU_LOCK_GUARD(this->mutex);
this->pFormatter = pFormatter; this->pFormatter = pFormatter;
} }
} }

View File

@ -14,6 +14,7 @@ namespace Aurora::Logging
AuSPtr<IFormatter> GetFormatter() override; AuSPtr<IFormatter> GetFormatter() override;
void SetFormatter(const AuSPtr<IFormatter> &pFormatter) override; void SetFormatter(const AuSPtr<IFormatter> &pFormatter) override;
AuSPtr<IFormatter> pFormatter; AuSPtr<IFormatter> pFormatter;
AuMutex mutex;
}; };
} }

View File

@ -15,7 +15,7 @@ namespace Aurora::Logging
static AuUInt32 gInUseMap[kAvailableSlots / 8] {}; static AuUInt32 gInUseMap[kAvailableSlots / 8] {};
static AuString gStringMap[kAvailableSlots]; static AuString gStringMap[kAvailableSlots];
static AuUInt32 gIterator {}; static AuUInt32 gIterator {};
static AuThreadPrimitives::MutexSOO gMutex; static AuMutex gMutex;
static const auto kBitsPerWord = 8 * sizeof(*gInUseMap); static const auto kBitsPerWord = 8 * sizeof(*gInUseMap);
@ -47,10 +47,10 @@ namespace Aurora::Logging
} }
} }
static void SetString(AuUInt8 uIdx, const AuString &str) static bool SetString(AuUInt8 uIdx, const AuString &str)
{ {
AU_LOCK_GUARD(gMutex); AU_LOCK_GUARD(gMutex);
gStringMap[uIdx] = str; return bool(AuTryConstruct(gStringMap[uIdx], str));
} }
static AuResult<AuUInt8> TryAcquire() static AuResult<AuUInt8> TryAcquire()
@ -77,16 +77,16 @@ namespace Aurora::Logging
} }
} }
AUKN_SYM void LogClassAssociateName(AuUInt8 uIndex, const AuString &str) AUKN_SYM bool LogClassAssociateName(AuUInt8 uIndex, const AuString &str)
{ {
uIndex -= AuLog::kLogLevelUsr; uIndex -= AuLog::kLogLevelUsr;
if (uIndex >= kAvailableSlots) if (uIndex >= kAvailableSlots)
{ {
return; return false;
} }
SetString(uIndex, str); return SetString(uIndex, str);
} }
AUKN_SYM const AuString &LogClassGetNameUnsafe(AuUInt8 uIndex) AUKN_SYM const AuString &LogClassGetNameUnsafe(AuUInt8 uIndex)

View File

@ -72,7 +72,7 @@ namespace Aurora::Process
return false; return false;
} }
path.resize(strlen(path.data())); path.resize(strlen(path.data())); // downsize shouldn't throw
if (!path.ends_with(AuFS::kPathSplitter)) if (!path.ends_with(AuFS::kPathSplitter))
{ {

View File

@ -11,7 +11,7 @@ namespace Aurora::Process
{ {
struct ProcessSectionAllocations struct ProcessSectionAllocations
{ {
AuThreadPrimitives::SpinLock spinlock; AuMutex spinlock;
AuList<AuPair<AuUInt, AuUInt>> allocations; AuList<AuPair<AuUInt, AuUInt>> allocations;
AuUInt uMaxLength {}; AuUInt uMaxLength {};

View File

@ -12,7 +12,7 @@ namespace Aurora::Process
struct ProcessSectionView : IProcessSectionView struct ProcessSectionView : IProcessSectionView
{ {
bool bPanicOnEx { true }; // SysAssert(this->bPanicOnEx) - it's inverted! true -> dont panic bool bPanicOnEx { true }; // SysAssert(this->bPanicOnEx) - it's inverted! true -> dont panic
AuThreadPrimitives::SpinLock spinlock; AuMutex spinlock;
AuList<AuPair<AuUInt, AuUInt>> allocations; AuList<AuPair<AuUInt, AuUInt>> allocations;
void DoVanillaDriverlessExtesionWin7Test(); void DoVanillaDriverlessExtesionWin7Test();

View File

@ -16,8 +16,8 @@
namespace Aurora::Processes namespace Aurora::Processes
{ {
static AuList<AuPair<AuString, bool>> gOpenItems; static AuList<AuPair<AuString, bool>> gOpenItems;
static AuThreadPrimitives::ConditionMutex gCondMutex; static AuConditionMutex gCondMutex;
static AuThreadPrimitives::ConditionVariable gCondVariable(AuUnsafeRaiiToShared(gCondMutex.AsPointer())); static AuConditionVariable gCondVariable(AuUnsafeRaiiToShared(gCondMutex.AsPointer()));
static AuThreads::ThreadUnique_t gOpenerThread; static AuThreads::ThreadUnique_t gOpenerThread;
static void RunTasks() static void RunTasks()

View File

@ -559,7 +559,7 @@ namespace Aurora::Threading::Threads
AuUInt64 OSThread::GetThreadCreationTime(Time::EClock eClock) AuUInt64 OSThread::GetThreadCreationTime(Time::EClock eClock)
{ {
if (AuTime::EClockIsValid(eClock)) if (!AuTime::EClockIsValid(eClock))
{ {
SysPushErrorArg(); SysPushErrorArg();
return {}; return {};