diff --git a/Include/Aurora/Console/Commands/Commands.hpp b/Include/Aurora/Console/Commands/Commands.hpp index 81c7b440..fdf9c14f 100644 --- a/Include/Aurora/Console/Commands/Commands.hpp +++ b/Include/Aurora/Console/Commands/Commands.hpp @@ -20,6 +20,8 @@ namespace Aurora::Console::Commands { AUKN_SYM void AddCommand(const AuString &tag, const Parse::ParseObject &commandStructure, const AuSPtr &subscriber); + AUKN_SYM void RemoveCommand(const AuString &tag); + /** * Dispatch a command to the main thread or aurora async overloaded command dispatcher thread worker id */ diff --git a/Include/Aurora/Crypto/X509/EExtendedUsage.hpp b/Include/Aurora/Crypto/X509/EExtendedUsage.hpp index 437f61ca..8c871b42 100644 --- a/Include/Aurora/Crypto/X509/EExtendedUsage.hpp +++ b/Include/Aurora/Crypto/X509/EExtendedUsage.hpp @@ -11,6 +11,7 @@ namespace Aurora::Crypto::X509 { AUE_DEFINE(EExtendedUsage, ( + eServerAuth, eClientAuth, eCodeSigning, eEmailProtection, diff --git a/Include/Aurora/Debug/Debug.hpp b/Include/Aurora/Debug/Debug.hpp index d0c21ebc..ac3255c8 100644 --- a/Include/Aurora/Debug/Debug.hpp +++ b/Include/Aurora/Debug/Debug.hpp @@ -75,6 +75,8 @@ namespace Aurora::Debug */ AUKN_SYM AU_NORETURN void Panic(); + AUKN_SYM AU_NORETURN void Panic2(AuUInt uLineHint = 0); + /** Localize platform dependent abi mangled name */ @@ -86,9 +88,9 @@ namespace Aurora::Debug AUKN_SYM void DecMemoryCrunch(); } +#include "SysErrors.hpp" #include "SysPanic.hpp" #include "SysAssertions.hpp" -#include "SysErrors.hpp" #include "ErrorStack.hpp" struct AuDbgStringSharedException : AuStringException diff --git a/Include/Aurora/Debug/SysAssertions.hpp b/Include/Aurora/Debug/SysAssertions.hpp index cc64a9ce..3e81c549 100644 --- a/Include/Aurora/Debug/SysAssertions.hpp +++ b/Include/Aurora/Debug/SysAssertions.hpp @@ -8,10 +8,22 @@ //#pragma once <- AURORA_NO_ASSERTIONS may be redefined. do not cache -#if !defined(AURORA_NO_ASSERTIONS) +#if defined(AURORA_ASSERTIONS_NO_EXPRESSIONS_UNDER_SHIP) + #if defined(AU_CFG_ID_SHIP) || defined(AURORA_ASSERTIONS_FORCE_SHIP) + #define AURORA_ASSERTIONS_NO_EXPRESSIONS + #endif +#endif + +#if defined(AURORA_ASSERTIONS_NO_EXPRESSIONS) + #define _AUKCON_STRINGIFY_X2(...) +#else + #define _AUKCON_STRINGIFY_X2 _AUKCON_STRINGIFY_X +#endif + +#if !defined(AURORA_NO_ASSERTIONS) && !defined(AURORA_ASSERTIONS_NONE) // defines SysAssert and SysAssertDbg -#if defined(DEBUG) +#if !(defined(AU_CFG_ID_SHIP) || defined(AURORA_ASSERTIONS_FORCE_SHIP)) /// @private template static auline void SysAssertFileEx(const char *file, int fileno, const char *func, bool tru, T... args) @@ -29,11 +41,11 @@ if constexpr (sizeof...(T) == 0) { - SysPanic("That's all folks"); + SysPanic2(fileno, "That's all folks"); } else { - SysPanic(args...); + SysPanic2(fileno, args...); } } @@ -45,7 +57,7 @@ #define SysAssert(tru, ...) \ do \ { \ - SysAssertFileEx(__FILE__, __LINE__, __FUNCTION__, static_cast(tru), ## __VA_ARGS__); \ + SysAssertFileEx(__FILE__, __LINE__, SysSafeFunction, static_cast(tru), ## __VA_ARGS__); \ } while (0) /** @@ -59,7 +71,7 @@ /// @private template - static auline void SysAssertEx(bool tru, T... args) + static auline void SysAssertEx(bool tru, int filenoOpt, T... args) { if (tru) { @@ -68,23 +80,21 @@ if constexpr (sizeof...(T) == 0) { - SysPanic("That's all folks"); + SysPanic2(filenoOpt, "That's all folks"); } else { - SysPanic(args...); + SysPanic2(filenoOpt, args...); } } - - /** A simple assertion with an optional message */ #define SysAssert(tru, ...) \ do \ { \ - SysAssertEx(static_cast(tru), ## __VA_ARGS__); \ + SysAssertEx(static_cast(tru), SysSafeLine, ## __VA_ARGS__); \ } while (0) /** @@ -97,7 +107,7 @@ #endif // defines SysAssertExp and SysAssertDbgExp -#if defined(DEBUG) +#if !(defined(AU_CFG_ID_SHIP) || defined(AURORA_ASSERTIONS_FORCE_SHIP)) /// @private template static auline void SysAssertFileExpEx(const char *file, int fileno, const char *func, const char *exp, bool tru, T... args) @@ -121,28 +131,28 @@ if constexpr (sizeof...(T) == 0) { - SysPanic("That's all folks"); + SysPanic2(fileno, "That's all folks"); } else { - SysPanic(args...); + SysPanic2(fileno, args...); } } /** - A simple assertion with a debug expresison and optional message debugging + A simple assertion with a debug expresison and optional message */ #define SysAssertExp(tru, ...) \ do \ { \ - SysAssertFileExpEx(__FILE__, __LINE__, __FUNCTION__, _AUKCON_STRINGIFY_X(tru), static_cast(tru), ## __VA_ARGS__); \ + SysAssertFileExpEx(__FILE__, __LINE__, SysSafeFunction, _AUKCON_STRINGIFY_X2(tru), static_cast(tru), ## __VA_ARGS__); \ } while (0) /** - A simple assertion with a debug expresison and optional message debugging under debug targets only + A simple assertion with a debug expresison and optional message under debug targets only */ #define SysAssertDbgExp SysAssertExp @@ -151,42 +161,43 @@ #else /// @private template - static auline void SysAssertExpEx(const char *exp, bool tru, T... args) + static auline void SysAssertExpEx(const char *exp, int filenoOpt, bool tru, T... args) { if (tru) { return; } + #if !defined(AURORA_ASSERTIONS_NO_EXPRESSIONS) Aurora::Logging::WriteLinef( static_cast(Aurora::Logging::ELogLevel::eError), Aurora::Console::EAnsiColor::eBoldRed, "Fatal", "Expression failed: {}", exp); + #endif if constexpr (sizeof...(T) == 0) { - SysPanic("That's all folks"); + SysPanic2(filenoOpt, "That's all folks"); } else { - SysPanic(args...); + SysPanic2(filenoOpt, args...); } } - - + /** - A simple assertion with a debug expresison and optional message debugging + A simple assertion with a debug expresison and optional message */ #define SysAssertExp(tru, ...) \ do \ { \ - SysAssertExpEx(_AUKCON_STRINGIFY_X(tru), static_cast(tru), ## __VA_ARGS__); \ + SysAssertExpEx(_AUKCON_STRINGIFY_X2(tru), SysSafeLine, static_cast(tru), ## __VA_ARGS__); \ } while (0) /** - A simple assertion with a debug expresison and optional message debugging under debug targets only + A simple assertion with a debug expresison and optional message under debug targets only */ #define SysAssertDbgExp(tru, ...) do {} while (0) diff --git a/Include/Aurora/Debug/SysErrors.hpp b/Include/Aurora/Debug/SysErrors.hpp index 38ad770b..c9b9c555 100644 --- a/Include/Aurora/Debug/SysErrors.hpp +++ b/Include/Aurora/Debug/SysErrors.hpp @@ -144,6 +144,13 @@ namespace Aurora::Debug #define SysSafeLine 0 #endif +#if defined(AURORA_COMPILER_MSVC) + #define SysSafeFunction __FUNCSIG__ +#else + #define SysSafeFunction __PRETTY_FUNCTION__ +#endif + + #define SysCheckReturn(x, ...) if (!(static_cast(x))) { Aurora::Debug::ErrorMakeNested(); return __VA_ARGS__; } #define SysPushErrorError(error, ...) do { Aurora::Debug::AddMemoryCrunch(); Aurora::Debug::SysPushError(Aurora::Debug::error, SysSafeLine, ## __VA_ARGS__) ;Aurora::Debug::DecMemoryCrunch(); } while (0) diff --git a/Include/Aurora/Debug/SysPanic.hpp b/Include/Aurora/Debug/SysPanic.hpp index 40a7b196..e2270aae 100644 --- a/Include/Aurora/Debug/SysPanic.hpp +++ b/Include/Aurora/Debug/SysPanic.hpp @@ -22,4 +22,20 @@ static inline void AU_NORETURN SysPanic(T... args) } Aurora::Debug::Panic(); } + +template +static inline void AU_NORETURN SysPanic2(AuUInt uLineHintInNonshipBinary, + T... args) +{ + Aurora::Debug::AddMemoryCrunch(); + try + { + Aurora::Logging::WriteLinef(static_cast(Aurora::Logging::ELogLevel::eError), Aurora::Console::EAnsiColor::eBoldRed, "Fatal", AuForward(args)...); + } + catch (...) + { + + } + Aurora::Debug::Panic2(uLineHintInNonshipBinary); +} #endif \ No newline at end of file diff --git a/Include/Aurora/Memory/HeapStats.hpp b/Include/Aurora/Memory/HeapStats.hpp index e09c8333..a40ca8f7 100644 --- a/Include/Aurora/Memory/HeapStats.hpp +++ b/Include/Aurora/Memory/HeapStats.hpp @@ -11,8 +11,8 @@ namespace Aurora::Memory { struct HeapStats { - AuUInt64 qwBytesAllocatedLifeSpan {}; - AuUInt64 qwBytesFreeLifeSpan {}; + AuUInt64 qwBytesAllocatedLifetime {}; + AuUInt64 qwBytesFreeLifetime {}; AuUInt uBytesCapacity {}; diff --git a/Include/Aurora/Memory/MemoryView.hpp b/Include/Aurora/Memory/MemoryView.hpp index 63c0ac47..26418022 100644 --- a/Include/Aurora/Memory/MemoryView.hpp +++ b/Include/Aurora/Memory/MemoryView.hpp @@ -70,7 +70,8 @@ namespace Aurora::Memory } template - constexpr MemoryView(T *start, AuUInt length) + constexpr MemoryView(T *start, AuUInt length) // WARNING: length != count + // where T = whogivesafuck { this->ptr = start; this->length = length; diff --git a/Include/Aurora/Parse/Hex.hpp b/Include/Aurora/Parse/Hex.hpp index e5df3244..e702689a 100644 --- a/Include/Aurora/Parse/Hex.hpp +++ b/Include/Aurora/Parse/Hex.hpp @@ -21,6 +21,6 @@ namespace Aurora::Parse AUKN_SYM void ByteToHex(AuUInt8 val, char(&hex)[2]); AUKN_SYM bool HexToInt (const char *hex, AuUInt32 length, AuUInt64 &val); - AUKN_SYM bool EncodeHex(const void *pBuf, AuUInt32 length, EHexDump formatting, AuString &out); + AUKN_SYM bool EncodeHex(Memory::MemoryViewRead view, EHexDump formatting, AuString &out); AUKN_SYM bool DecodeHex(const AuString &in, Memory::ByteBuffer &out); } \ No newline at end of file diff --git a/Include/Aurora/RNG/IRandomDevice.hpp b/Include/Aurora/RNG/IRandomDevice.hpp index 6c4fed6d..f9e41085 100644 --- a/Include/Aurora/RNG/IRandomDevice.hpp +++ b/Include/Aurora/RNG/IRandomDevice.hpp @@ -11,7 +11,7 @@ namespace Aurora::RNG { struct IRandomDevice { - virtual void Read(void *pIn, AuUInt32 uLength) = 0; + virtual void Read(Memory::MemoryViewWrite view) = 0; virtual AuString NextString(AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0; virtual void NextString(char *pString, AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0; @@ -30,13 +30,13 @@ namespace Aurora::RNG template inline void NextFillArray(T(&array)[N]) { - Read(array, N * sizeof(T)); + Read(Memory::MemoryViewWrite(array)); } template - inline void NextFillArray(T *array, AuUInt32 length) + inline void NextFillArray(T *pArray, AuUInt32 uCount) { - Read(array, length * sizeof(T)); + Read(Memory::MemoryViewWrite(pArray, uCount * sizeof(T))); } template @@ -65,7 +65,7 @@ namespace Aurora::RNG inline T NextFillTmpl() { T ret {}; - Read(&ret, sizeof(T)); + Read(Memory::MemoryViewWrite(&ret, sizeof(T))); return ret; } @@ -76,9 +76,9 @@ namespace Aurora::RNG } template - inline T &NextArray(T *items, AuUInt32 count) + inline T &NextArray(T *pItems, AuUInt32 uCount) { - return items[NextIndex(count)]; + return pItems[NextIndex(uCount)]; } template diff --git a/Include/Aurora/RNG/RNG.hpp b/Include/Aurora/RNG/RNG.hpp index ac88f8b1..a3440768 100644 --- a/Include/Aurora/RNG/RNG.hpp +++ b/Include/Aurora/RNG/RNG.hpp @@ -13,18 +13,18 @@ namespace Aurora::RNG { - AUKN_SYM void ReadSecureRNG(void *in, AuUInt32 length); - AUKN_SYM void ReadFastRNG (void *in, AuUInt32 length); + AUKN_SYM void ReadSecureRNG(Memory::MemoryViewWrite writeView); + AUKN_SYM void ReadFastRNG (Memory::MemoryViewWrite writeView); - AUKN_SYM AuString ReadString(AuUInt32 length, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters); - AUKN_SYM void RngString(char *string, AuUInt32 length, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters); + AUKN_SYM AuString ReadString(AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters); + AUKN_SYM void RngString(char *pString, AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters); AUKN_SYM AuUInt8 RngByte(); AUKN_SYM bool RngBoolean(); AUKN_SYM AuUInt32 RngU32(); - AUKN_SYM AuUInt32 RngU32(AuUInt32 min, AuUInt32 max); + AUKN_SYM AuUInt32 RngU32(AuUInt32 uMin, AuUInt32 uMax); AUKN_SYM AuUInt64 RngU64(); - AUKN_SYM AuInt32 RngInt(AuInt32 min, AuInt32 max); + AUKN_SYM AuInt32 RngInt(AuInt32 uMin, AuInt32 uMax); AUKN_SYM double RngDecimal(); AUKN_SYM float RngNumber(float min, float max); AUKN_SYM AuUInt32 RngIndex(AuUInt32 count /* = max + 1*/); @@ -37,24 +37,24 @@ namespace Aurora::RNG { if constexpr (fast) { - ReadFastRNG(array, N * sizeof(T)); + ReadFastRNG(Memory::MemoryViewWrite(array)); } else { - ReadSecureRNG(array, N * sizeof(T)); + ReadSecureRNG(Memory::MemoryViewWrite(array)); } } template - static auline void RngFillArray(T *array, AuUInt32 length) + static auline void RngFillArray(T *array, AuUInt32 uCount) { if constexpr (fast) { - ReadFastRNG(array, length * sizeof(T)); + ReadFastRNG(Memory::MemoryViewWrite(array, uCount * sizeof(T))); } else { - ReadSecureRNG(array, length * sizeof(T)); + ReadSecureRNG(Memory::MemoryViewWrite(array, uCount * sizeof(T))); } } @@ -86,19 +86,19 @@ namespace Aurora::RNG T ret {}; if constexpr (fast) { - ReadFastRNG(&ret, sizeof(T)); + ReadFastRNG(Memory::MemoryViewWrite(&ret, sizeof(T))); } else { - ReadSecureRNG(&ret, sizeof(T)); + ReadSecureRNG(Memory::MemoryViewWrite(&ret, sizeof(T))); } return ret; } template - static auline T &RngArray(T *items, AuUInt32 count) + static auline T &RngArray(T *pItems, AuUInt32 uCount) { - return items[RngIndex(count)]; + return pItems[RngIndex(uCount)]; } template diff --git a/Include/Aurora/Threading/Primitives/ConditionEx.hpp b/Include/Aurora/Threading/Primitives/ConditionEx.hpp index 07608d50..a71bc0aa 100644 --- a/Include/Aurora/Threading/Primitives/ConditionEx.hpp +++ b/Include/Aurora/Threading/Primitives/ConditionEx.hpp @@ -13,7 +13,9 @@ namespace Aurora::Threading::Primitives A comprehensive CV that does not strictly abide by typical assumptions.
This object is not optimal; however, it will work with any or no IWaitable
On systems where context switches are expensive, this object should be avoided at all costs
- This object depends on the synchronization of primitives within our abstraction layer rather than the OS's implementation of condition variables
+ This object depends on the synchronization of primitives within our abstraction layer rather than the OS's implementation of condition variables.
+ Note: missing pWaitables cannnot serve as an `atomic wait for while is [not] value` operation as found under modern operating system schedulers. + There are no legal use cases for this feature. It's just there. */ struct ConditionEx { diff --git a/Include/Aurora/Threading/Primitives/ConditionVariable.hpp b/Include/Aurora/Threading/Primitives/ConditionVariable.hpp index 8515b889..9a3a8fc1 100644 --- a/Include/Aurora/Threading/Primitives/ConditionVariable.hpp +++ b/Include/Aurora/Threading/Primitives/ConditionVariable.hpp @@ -16,9 +16,8 @@ namespace Aurora::Threading::Primitives 1) we define no waitable as illegal
2) conditional variables may not rebind their mutex */ - class IConditionVariable + struct IConditionVariable { - public: virtual AuSPtr GetMutex() = 0; virtual bool WaitForSignal(AuUInt32 timeout = 0) = 0; virtual void Broadcast() = 0; diff --git a/Include/Aurora/Threading/Primitives/Event.hpp b/Include/Aurora/Threading/Primitives/Event.hpp index 5448f482..5c4806bf 100644 --- a/Include/Aurora/Threading/Primitives/Event.hpp +++ b/Include/Aurora/Threading/Primitives/Event.hpp @@ -12,13 +12,10 @@ namespace Aurora::Threading::Primitives /** Event synchronization primitive */ - class IEvent : public IWaitable + struct IEvent : IWaitable { - public: - // Unlike the other types, unlock is always a nop. It makes sense for the schedular or any other caller to not automatically reset an event, contrary to `::Lock(); work; ::Unlock();` - // Ordinarily, we would expect the thread responsible for dispatching work to Unlock, and the caller Reset, at least in principle. This, however, does not account for reusability. - // It makes sense to implement reset-on-worker-acknowledge, permit-multiple-triggers (a kind of countless semaphores), and any combination thereof - // Besides from atomicRelease, Reset and Set is on your watch. + // Unlike the other types, unlock is always a nop. It makes sense the caller to not automatically reset an event, contrary to `::Lock(); work; ::Unlock();` + // Ordinarily, we would expect the thread responsible for work processing to ::Lock/::Unlock (maybe ::Reset()), and the dispatching thread to ::Reset and ::Set. inline void Wait() { @@ -34,5 +31,8 @@ namespace Aurora::Threading::Primitives virtual void Set() = 0; }; - AUKN_SHARED_API(Event, IEvent, bool triggerd = false, bool atomicRelease = true, bool permitMultipleTriggers = false); + AUKN_SHARED_API(Event, IEvent, + bool bInitiallyTriggerd = false, + bool bAtomicRelease = true, + bool bPermitMultipleTriggers = false); } \ No newline at end of file diff --git a/Include/Aurora/Threading/Primitives/Semaphore.hpp b/Include/Aurora/Threading/Primitives/Semaphore.hpp index 7ede8ce7..93919f2c 100644 --- a/Include/Aurora/Threading/Primitives/Semaphore.hpp +++ b/Include/Aurora/Threading/Primitives/Semaphore.hpp @@ -14,5 +14,5 @@ namespace Aurora::Threading::Primitives virtual void Unlock(long count) = 0; }; - AUKN_SHARED_API(Semaphore, ISemaphore, int initialCount = 0); + AUKN_SHARED_API(Semaphore, ISemaphore, int iInitialCount = 0); } \ No newline at end of file diff --git a/Include/Aurora/Threading/Primitives/SpinLock.hpp b/Include/Aurora/Threading/Primitives/SpinLock.hpp index cb7c85fb..0f6446f4 100644 --- a/Include/Aurora/Threading/Primitives/SpinLock.hpp +++ b/Include/Aurora/Threading/Primitives/SpinLock.hpp @@ -9,11 +9,8 @@ namespace Aurora::Threading::Primitives { - // NOTE: A SPINLOCK CAN NOT BE AN IWAITABLE BY DEFINITION - // Partial interface support exists for completeness alone! - class AUKN_SYM SpinLock : public IWaitable + struct AUKN_SYM SpinLock : IWaitable { - public: SpinLock(); bool HasOSHandle(AuMach &mach) override; diff --git a/Source/Console/Commands/Commands.cpp b/Source/Console/Commands/Commands.cpp index d0bf6c20..e609cb6c 100644 --- a/Source/Console/Commands/Commands.cpp +++ b/Source/Console/Commands/Commands.cpp @@ -119,6 +119,12 @@ namespace Aurora::Console::Commands return true; } + AUKN_SYM void RemoveCommand(const AuString &tag) + { + AU_LOCK_GUARD(gPendingCommandsMutex); + AuTryRemove(gCommands, tag); + } + AUKN_SYM void AddCommand(const AuString &tag, const Parse::ParseObject &commandStructure, const AuSPtr &callback) { AU_LOCK_GUARD(gPendingCommandsMutex); diff --git a/Source/Crypto/X509/GenerateCertificate.cpp b/Source/Crypto/X509/GenerateCertificate.cpp index b2de6cec..15deabc5 100644 --- a/Source/Crypto/X509/GenerateCertificate.cpp +++ b/Source/Crypto/X509/GenerateCertificate.cpp @@ -241,9 +241,9 @@ namespace Aurora::Crypto::X509 switch (A) { - //case EExtendedUsage::eClientAuth: - // SET_OID(ext_key_usage->buf, MBEDTLS_OID_SERVER_AUTH); - // break; + case EExtendedUsage::eServerAuth: + SET_OID(ext_key_usage->buf, MBEDTLS_OID_SERVER_AUTH); + break; case EExtendedUsage::eClientAuth: SET_OID(ext_key_usage->buf, MBEDTLS_OID_CLIENT_AUTH); break; @@ -284,10 +284,10 @@ namespace Aurora::Crypto::X509 } iRet = ::mbedtls_x509write_crt_der(&crt, - buffer.base, - buffer.length, - ::mbedtls_ctr_drbg_random, - &IO::TLS::gCtrDrbg); + buffer.base, + buffer.length, + ::mbedtls_ctr_drbg_random, + &IO::TLS::gCtrDrbg); if (iRet < 0) { SysPushErrorCrypto("Couldn't write x509 cert: {}", iRet); diff --git a/Source/Debug/Panic.cpp b/Source/Debug/Panic.cpp index 7bf76bbe..f8cd5176 100644 --- a/Source/Debug/Panic.cpp +++ b/Source/Debug/Panic.cpp @@ -46,6 +46,12 @@ namespace Aurora::Debug return gHandlingFatal; } + AUKN_SYM void Panic2(AuUInt uLineHintInNonshipBinary) + { + // TODO: telemetry insert crashing from line uLineHintInNonshipBinary + Panic(); + } + AUKN_SYM void Panic() { // diff --git a/Source/Extensions/LTC/LTC.cpp b/Source/Extensions/LTC/LTC.cpp index 2c5fb291..b88e8f96 100644 --- a/Source/Extensions/LTC/LTC.cpp +++ b/Source/Extensions/LTC/LTC.cpp @@ -12,7 +12,7 @@ extern "C" { AUKN_SYM unsigned long rng_get_bytes(unsigned char *out, unsigned long outlen, void (*callback)(void)) { - Aurora::RNG::ReadSecureRNG(out, outlen); + Aurora::RNG::ReadSecureRNG(AuMemoryViewWrite { out, outlen }); return outlen; } } \ No newline at end of file diff --git a/Source/Extensions/LTM/LTM.cpp b/Source/Extensions/LTM/LTM.cpp index 18ebad8e..bd2fcbf4 100644 --- a/Source/Extensions/LTM/LTM.cpp +++ b/Source/Extensions/LTM/LTM.cpp @@ -23,7 +23,7 @@ extern "C" AUKN_SYM mp_err s_mp_rand_platform(void *p, size_t n) { - Aurora::RNG::ReadSecureRNG(p, AuUInt32(n)); + Aurora::RNG::ReadSecureRNG(AuMemoryViewWrite { p, AuUInt32(n) }); return MP_OKAY; } } \ No newline at end of file diff --git a/Source/Extensions/MBedTls/MBedTLS.cpp b/Source/Extensions/MBedTls/MBedTLS.cpp index 9df6ff78..eb983a28 100644 --- a/Source/Extensions/MBedTls/MBedTLS.cpp +++ b/Source/Extensions/MBedTls/MBedTLS.cpp @@ -12,7 +12,7 @@ extern "C" { AUKN_SYM int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, size_t *olen) { - Aurora::RNG::ReadSecureRNG(output, AuUInt32(len)); + Aurora::RNG::ReadSecureRNG(AuMemoryViewWrite { output, AuUInt32(len) }); *olen = len; return 0; } diff --git a/Source/Memory/Heap.cpp b/Source/Memory/Heap.cpp index 09acced5..d3a25349 100644 --- a/Source/Memory/Heap.cpp +++ b/Source/Memory/Heap.cpp @@ -359,7 +359,7 @@ namespace Aurora::Memory auto pDiag = o1heapGetDiagnostics(this->heap_); this->stats.uBytesLiveCounter = pDiag.allocated; - this->stats.uBytesCapacity = pDiag.capacity; + this->stats.uBytesCapacity = pDiag.capacity; this->stats.uBytesPeakCounter = pDiag.peak_allocated; } diff --git a/Source/Memory/Memory.cpp b/Source/Memory/Memory.cpp index 25116262..32d9b61f 100644 --- a/Source/Memory/Memory.cpp +++ b/Source/Memory/Memory.cpp @@ -21,6 +21,8 @@ namespace Aurora::Memory AuUInt gBytesCounterAllocated {}; AuUInt gBytesCounterPeak {}; + thread_local AuInt64 tlsLastOutOfMemory {}; + static void AddBytesToCounter(AuUInt uBytes) { gBytesCounterPeak = AuMax(gBytesCounterPeak, AuAtomicAdd(&gBytesCounterAllocated, uBytes)); @@ -47,6 +49,8 @@ namespace Aurora::Memory auto pRet = exp; \ if (!pRet) \ { \ + tlsLastOutOfMemory = AuTime::CurrentClockNS(); \ + \ bool bCrunchFlag {}; \ if (((bCrunchFlag = AuDebug::IsTlsMemoryCrunchActive()) || \ (gRuntimeConfig.debug.bIsApplicationClientSoftwareOnJitteryMemorySystem)) && \ @@ -73,26 +77,31 @@ namespace Aurora::Memory AUKN_SYM void *_ZAlloc(Types::size_t length) { + SysAssertDbg(length); CHECK_WRAP_RETURN(::mi_zalloc(length), (ZAlloc(length)), "ZAlloc out of memory"); } AUKN_SYM void *_ZAlloc(Types::size_t length, Types::size_t align) { + SysAssertDbg(length); CHECK_WRAP_RETURN(::mi_zalloc_aligned(length, align), (ZAlloc(length, align)), "ZAlloc out of memory"); } AUKN_SYM void *_FAlloc(Types::size_t length) { + SysAssertDbg(length); CHECK_WRAP_RETURN(::mi_malloc(length), (FAlloc(length)), "FAlloc out of memory"); } AUKN_SYM void *_FAlloc(Types::size_t length, Types::size_t align) { + SysAssertDbg(length); CHECK_WRAP_RETURN(::mi_malloc_aligned(length, align), (FAlloc(length, align)), "FAllocEx out of memory"); } AUKN_SYM void *_ZRealloc(void *buffer, Types::size_t length, Types::size_t align) { + SysAssertDbg(length); void *pRet; if (AuDebug::IsPointerReserveRange(buffer)) @@ -119,6 +128,7 @@ namespace Aurora::Memory AUKN_SYM void *_ZRealloc(void *buffer, Types::size_t length) { + SysAssertDbg(length); void *pRet; if (AuDebug::IsPointerReserveRange(buffer)) @@ -145,6 +155,7 @@ namespace Aurora::Memory AUKN_SYM void *_FRealloc(void *buffer, Types::size_t length, Types::size_t align) { + SysAssertDbg(length); void *pRet; if (AuDebug::IsPointerReserveRange(buffer)) @@ -171,6 +182,7 @@ namespace Aurora::Memory AUKN_SYM void *_FRealloc(void *buffer, Types::size_t length) { + SysAssertDbg(length); void *pRet; if (AuDebug::IsPointerReserveRange(buffer)) @@ -213,6 +225,11 @@ namespace Aurora::Memory } } + AUKN_SYM AuInt64 GetLastOutOfMemoryTimeNS() + { + return tlsLastOutOfMemory; + } + AUKN_SYM AuUInt GetPageSize() { return AuHwInfo::GetPageSize(); diff --git a/Source/Parse/AuHex.cpp b/Source/Parse/AuHex.cpp index 4e0f3595..9d67d8b9 100644 --- a/Source/Parse/AuHex.cpp +++ b/Source/Parse/AuHex.cpp @@ -205,8 +205,11 @@ namespace Aurora::Parse return true; } - AUKN_SYM bool EncodeHex(const void *pBuf, AuUInt32 uLength, EHexDump formatting, AuString &in) + AUKN_SYM bool EncodeHex(Memory::MemoryViewRead view, EHexDump formatting, AuString &in) { + auto pBuf = view.ptr; + auto uLength = view.length; + bool hexedit = formatting == EHexDump::eHexEditor; bool squareBracket = formatting == EHexDump::eJSLiteral; diff --git a/Source/RNG/AuRNG.cpp b/Source/RNG/AuRNG.cpp index dee97db2..280f6d0d 100644 --- a/Source/RNG/AuRNG.cpp +++ b/Source/RNG/AuRNG.cpp @@ -15,11 +15,14 @@ namespace Aurora::RNG static WELLRand gWellRand; RandomUnique_t gFastDevice; - AUKN_SYM void ReadSecureRNG(void *pBuffer, AuUInt32 uBytes) + AUKN_SYM void ReadSecureRNG(Memory::MemoryViewWrite writeView) { AuUInt32 offset; AuUInt8 *headPtr; + auto pBuffer = writeView.ptr; + auto uBytes = writeView.length; + SysAssert(pBuffer, "Null RNG out buffer"); headPtr = reinterpret_cast(pBuffer); @@ -34,10 +37,12 @@ namespace Aurora::RNG } } - AUKN_SYM void ReadFastRNG(void *pBuffer, AuUInt32 uBytes) + AUKN_SYM void ReadFastRNG(Memory::MemoryViewWrite writeView) { - SysAssert(pBuffer, "Null RNG out buffer"); + auto pBuffer = writeView.ptr; + auto uBytes = writeView.length; + SysAssert(pBuffer, "Null fast rng out buffer"); WELL_NextBytes(&gWellRand, pBuffer, uBytes); } diff --git a/Source/RNG/AuRandomDevice.cpp b/Source/RNG/AuRandomDevice.cpp index f150e8ae..84fcc98c 100644 --- a/Source/RNG/AuRandomDevice.cpp +++ b/Source/RNG/AuRandomDevice.cpp @@ -38,9 +38,9 @@ namespace Aurora::RNG // secure rng requires no init -> we just passthrough to the global ReadSecureRNG function } - void RandomDevice::Read(void *pIn, AuUInt32 uLength) + void RandomDevice::Read(Memory::MemoryViewWrite view) { - if (!pIn) + if (!view) { SysPushErrorArg(); return; @@ -48,11 +48,11 @@ namespace Aurora::RNG if (this->def_.bSecure) { - ReadSecureRNG(pIn, uLength); + ReadSecureRNG(view); } else { - WELL_NextBytes(&this->fast_, pIn, uLength); + WELL_NextBytes(&this->fast_, view.ptr, AuUInt32(view.length)); } } @@ -81,7 +81,7 @@ namespace Aurora::RNG return; } - ReadSecureRNG(pString, uLength); + ReadSecureRNG(AuMemoryViewWrite { pString, uLength }); if (!ERngStringCharactersIsValid(type)) { diff --git a/Source/RNG/AuRandomDevice.hpp b/Source/RNG/AuRandomDevice.hpp index 3e6f3914..e1d5d169 100644 --- a/Source/RNG/AuRandomDevice.hpp +++ b/Source/RNG/AuRandomDevice.hpp @@ -13,7 +13,7 @@ namespace Aurora::RNG { struct RandomDevice : IRandomDevice { - void Read(void *pIn, AuUInt32 uLength) override; + void Read(Memory::MemoryViewWrite view) override; AuString NextString(AuUInt32 uLength, ERngStringCharacters type) override; void NextString(char *pString, AuUInt32 uLength, ERngStringCharacters type) override;