[*] 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 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 const AuString &LogClassGetNameUnsafe(AuUInt8 uIndex);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -80,7 +80,11 @@ namespace Aurora::IO::FS
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->addresses_.resize((this->pParent_->endpointSize_ + 16) * 2);
if (!AuTryResize(this->addresses_,
(this->pParent_->endpointSize_ + 16) * 2))
{
return false;
}
auto bRet = lpfnAcceptEx(this->pParent_->ToPlatformHandle(),
this->nextSocket,

View File

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

View File

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

View File

@ -15,7 +15,7 @@ namespace Aurora::Logging
static AuUInt32 gInUseMap[kAvailableSlots / 8] {};
static AuString gStringMap[kAvailableSlots];
static AuUInt32 gIterator {};
static AuThreadPrimitives::MutexSOO gMutex;
static AuMutex gMutex;
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);
gStringMap[uIdx] = str;
return bool(AuTryConstruct(gStringMap[uIdx], str));
}
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;
if (uIndex >= kAvailableSlots)
{
return;
return false;
}
SetString(uIndex, str);
return SetString(uIndex, str);
}
AUKN_SYM const AuString &LogClassGetNameUnsafe(AuUInt8 uIndex)

View File

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

View File

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

View File

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

View File

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

View File

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