[*] Refactor public headers

[+] AuConsole::Commands::RemoveCommand
[+] EExtendedUsage::eServerAuth
[+] SysPanic2 for SysSafeLine hints (backtrace may contain optimized SysPanics, making tracing the true origin difficult)
[*] Reworked SysAssertions
[*] AuParse::EncodeHex now takes AuMemoryViewRead
[*] AuRng::ReadSecureRNG now takes AuMemoryViewWrite
[*] AuRng::ReadFastRNG now takes AuMemoryViewWrite
This commit is contained in:
Reece Wilson 2023-01-15 06:05:22 +00:00
parent 3d763e58b4
commit 124038df62
28 changed files with 163 additions and 88 deletions

View File

@ -20,6 +20,8 @@ namespace Aurora::Console::Commands
{ {
AUKN_SYM void AddCommand(const AuString &tag, const Parse::ParseObject &commandStructure, const AuSPtr<ICommandSubscriber> &subscriber); AUKN_SYM void AddCommand(const AuString &tag, const Parse::ParseObject &commandStructure, const AuSPtr<ICommandSubscriber> &subscriber);
AUKN_SYM void RemoveCommand(const AuString &tag);
/** /**
* Dispatch a command to the main thread or aurora async overloaded command dispatcher thread worker id * Dispatch a command to the main thread or aurora async overloaded command dispatcher thread worker id
*/ */

View File

@ -11,6 +11,7 @@ namespace Aurora::Crypto::X509
{ {
AUE_DEFINE(EExtendedUsage, AUE_DEFINE(EExtendedUsage,
( (
eServerAuth,
eClientAuth, eClientAuth,
eCodeSigning, eCodeSigning,
eEmailProtection, eEmailProtection,

View File

@ -75,6 +75,8 @@ namespace Aurora::Debug
*/ */
AUKN_SYM AU_NORETURN void Panic(); AUKN_SYM AU_NORETURN void Panic();
AUKN_SYM AU_NORETURN void Panic2(AuUInt uLineHint = 0);
/** /**
Localize platform dependent abi mangled name Localize platform dependent abi mangled name
*/ */
@ -86,9 +88,9 @@ namespace Aurora::Debug
AUKN_SYM void DecMemoryCrunch(); AUKN_SYM void DecMemoryCrunch();
} }
#include "SysErrors.hpp"
#include "SysPanic.hpp" #include "SysPanic.hpp"
#include "SysAssertions.hpp" #include "SysAssertions.hpp"
#include "SysErrors.hpp"
#include "ErrorStack.hpp" #include "ErrorStack.hpp"
struct AuDbgStringSharedException : AuStringException struct AuDbgStringSharedException : AuStringException

View File

@ -8,10 +8,22 @@
//#pragma once <- AURORA_NO_ASSERTIONS may be redefined. do not cache //#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 // defines SysAssert and SysAssertDbg
#if defined(DEBUG) #if !(defined(AU_CFG_ID_SHIP) || defined(AURORA_ASSERTIONS_FORCE_SHIP))
/// @private /// @private
template<typename ... T> template<typename ... T>
static auline void SysAssertFileEx(const char *file, int fileno, const char *func, bool tru, T... args) 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) if constexpr (sizeof...(T) == 0)
{ {
SysPanic("That's all folks"); SysPanic2(fileno, "That's all folks");
} }
else else
{ {
SysPanic(args...); SysPanic2(fileno, args...);
} }
} }
@ -45,7 +57,7 @@
#define SysAssert(tru, ...) \ #define SysAssert(tru, ...) \
do \ do \
{ \ { \
SysAssertFileEx(__FILE__, __LINE__, __FUNCTION__, static_cast<bool>(tru), ## __VA_ARGS__); \ SysAssertFileEx(__FILE__, __LINE__, SysSafeFunction, static_cast<bool>(tru), ## __VA_ARGS__); \
} while (0) } while (0)
/** /**
@ -59,7 +71,7 @@
/// @private /// @private
template<typename ... T> template<typename ... T>
static auline void SysAssertEx(bool tru, T... args) static auline void SysAssertEx(bool tru, int filenoOpt, T... args)
{ {
if (tru) if (tru)
{ {
@ -68,23 +80,21 @@
if constexpr (sizeof...(T) == 0) if constexpr (sizeof...(T) == 0)
{ {
SysPanic("That's all folks"); SysPanic2(filenoOpt, "That's all folks");
} }
else else
{ {
SysPanic(args...); SysPanic2(filenoOpt, args...);
} }
} }
/** /**
A simple assertion with an optional message A simple assertion with an optional message
*/ */
#define SysAssert(tru, ...) \ #define SysAssert(tru, ...) \
do \ do \
{ \ { \
SysAssertEx(static_cast<bool>(tru), ## __VA_ARGS__); \ SysAssertEx(static_cast<bool>(tru), SysSafeLine, ## __VA_ARGS__); \
} while (0) } while (0)
/** /**
@ -97,7 +107,7 @@
#endif #endif
// defines SysAssertExp and SysAssertDbgExp // defines SysAssertExp and SysAssertDbgExp
#if defined(DEBUG) #if !(defined(AU_CFG_ID_SHIP) || defined(AURORA_ASSERTIONS_FORCE_SHIP))
/// @private /// @private
template<typename ... T> template<typename ... T>
static auline void SysAssertFileExpEx(const char *file, int fileno, const char *func, const char *exp, bool tru, T... args) 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) if constexpr (sizeof...(T) == 0)
{ {
SysPanic("That's all folks"); SysPanic2(fileno, "That's all folks");
} }
else 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, ...) \ #define SysAssertExp(tru, ...) \
do \ do \
{ \ { \
SysAssertFileExpEx(__FILE__, __LINE__, __FUNCTION__, _AUKCON_STRINGIFY_X(tru), static_cast<bool>(tru), ## __VA_ARGS__); \ SysAssertFileExpEx(__FILE__, __LINE__, SysSafeFunction, _AUKCON_STRINGIFY_X2(tru), static_cast<bool>(tru), ## __VA_ARGS__); \
} while (0) } 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 #define SysAssertDbgExp SysAssertExp
@ -151,42 +161,43 @@
#else #else
/// @private /// @private
template<typename ... T> template<typename ... T>
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) if (tru)
{ {
return; return;
} }
#if !defined(AURORA_ASSERTIONS_NO_EXPRESSIONS)
Aurora::Logging::WriteLinef( Aurora::Logging::WriteLinef(
static_cast<AuUInt8>(Aurora::Logging::ELogLevel::eError), static_cast<AuUInt8>(Aurora::Logging::ELogLevel::eError),
Aurora::Console::EAnsiColor::eBoldRed, Aurora::Console::EAnsiColor::eBoldRed,
"Fatal", "Fatal",
"Expression failed: {}", exp); "Expression failed: {}", exp);
#endif
if constexpr (sizeof...(T) == 0) if constexpr (sizeof...(T) == 0)
{ {
SysPanic("That's all folks"); SysPanic2(filenoOpt, "That's all folks");
} }
else 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, ...) \ #define SysAssertExp(tru, ...) \
do \ do \
{ \ { \
SysAssertExpEx(_AUKCON_STRINGIFY_X(tru), static_cast<bool>(tru), ## __VA_ARGS__); \ SysAssertExpEx(_AUKCON_STRINGIFY_X2(tru), SysSafeLine, static_cast<bool>(tru), ## __VA_ARGS__); \
} while (0) } 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) #define SysAssertDbgExp(tru, ...) do {} while (0)

View File

@ -144,6 +144,13 @@ namespace Aurora::Debug
#define SysSafeLine 0 #define SysSafeLine 0
#endif #endif
#if defined(AURORA_COMPILER_MSVC)
#define SysSafeFunction __FUNCSIG__
#else
#define SysSafeFunction __PRETTY_FUNCTION__
#endif
#define SysCheckReturn(x, ...) if (!(static_cast<bool>(x))) { Aurora::Debug::ErrorMakeNested(); return __VA_ARGS__; } #define SysCheckReturn(x, ...) if (!(static_cast<bool>(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) #define SysPushErrorError(error, ...) do { Aurora::Debug::AddMemoryCrunch(); Aurora::Debug::SysPushError(Aurora::Debug::error, SysSafeLine, ## __VA_ARGS__) ;Aurora::Debug::DecMemoryCrunch(); } while (0)

View File

@ -22,4 +22,20 @@ static inline void AU_NORETURN SysPanic(T... args)
} }
Aurora::Debug::Panic(); Aurora::Debug::Panic();
} }
template<typename ... T>
static inline void AU_NORETURN SysPanic2(AuUInt uLineHintInNonshipBinary,
T... args)
{
Aurora::Debug::AddMemoryCrunch();
try
{
Aurora::Logging::WriteLinef(static_cast<AuUInt8>(Aurora::Logging::ELogLevel::eError), Aurora::Console::EAnsiColor::eBoldRed, "Fatal", AuForward<T>(args)...);
}
catch (...)
{
}
Aurora::Debug::Panic2(uLineHintInNonshipBinary);
}
#endif #endif

View File

@ -11,8 +11,8 @@ namespace Aurora::Memory
{ {
struct HeapStats struct HeapStats
{ {
AuUInt64 qwBytesAllocatedLifeSpan {}; AuUInt64 qwBytesAllocatedLifetime {};
AuUInt64 qwBytesFreeLifeSpan {}; AuUInt64 qwBytesFreeLifetime {};
AuUInt uBytesCapacity {}; AuUInt uBytesCapacity {};

View File

@ -70,7 +70,8 @@ namespace Aurora::Memory
} }
template<typename T> template<typename T>
constexpr MemoryView(T *start, AuUInt length) constexpr MemoryView(T *start, AuUInt length) // WARNING: length != count
// where T = whogivesafuck
{ {
this->ptr = start; this->ptr = start;
this->length = length; this->length = length;

View File

@ -21,6 +21,6 @@ namespace Aurora::Parse
AUKN_SYM void ByteToHex(AuUInt8 val, char(&hex)[2]); AUKN_SYM void ByteToHex(AuUInt8 val, char(&hex)[2]);
AUKN_SYM bool HexToInt (const char *hex, AuUInt32 length, AuUInt64 &val); 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); AUKN_SYM bool DecodeHex(const AuString &in, Memory::ByteBuffer &out);
} }

View File

@ -11,7 +11,7 @@ namespace Aurora::RNG
{ {
struct IRandomDevice 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 AuString NextString(AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
virtual void NextString(char *pString, 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<typename T, int N> template<typename T, int N>
inline void NextFillArray(T(&array)[N]) inline void NextFillArray(T(&array)[N])
{ {
Read(array, N * sizeof(T)); Read(Memory::MemoryViewWrite(array));
} }
template<typename T> template<typename T>
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<typename T> template<typename T>
@ -65,7 +65,7 @@ namespace Aurora::RNG
inline T NextFillTmpl() inline T NextFillTmpl()
{ {
T ret {}; T ret {};
Read(&ret, sizeof(T)); Read(Memory::MemoryViewWrite(&ret, sizeof(T)));
return ret; return ret;
} }
@ -76,9 +76,9 @@ namespace Aurora::RNG
} }
template<typename T> template<typename T>
inline T &NextArray(T *items, AuUInt32 count) inline T &NextArray(T *pItems, AuUInt32 uCount)
{ {
return items[NextIndex(count)]; return pItems[NextIndex(uCount)];
} }
template<typename T> template<typename T>

View File

@ -13,18 +13,18 @@
namespace Aurora::RNG namespace Aurora::RNG
{ {
AUKN_SYM void ReadSecureRNG(void *in, AuUInt32 length); AUKN_SYM void ReadSecureRNG(Memory::MemoryViewWrite writeView);
AUKN_SYM void ReadFastRNG (void *in, AuUInt32 length); AUKN_SYM void ReadFastRNG (Memory::MemoryViewWrite writeView);
AUKN_SYM AuString ReadString(AuUInt32 length, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters); AUKN_SYM AuString ReadString(AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters);
AUKN_SYM void RngString(char *string, AuUInt32 length, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters); AUKN_SYM void RngString(char *pString, AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters);
AUKN_SYM AuUInt8 RngByte(); AUKN_SYM AuUInt8 RngByte();
AUKN_SYM bool RngBoolean(); AUKN_SYM bool RngBoolean();
AUKN_SYM AuUInt32 RngU32(); 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 AuUInt64 RngU64();
AUKN_SYM AuInt32 RngInt(AuInt32 min, AuInt32 max); AUKN_SYM AuInt32 RngInt(AuInt32 uMin, AuInt32 uMax);
AUKN_SYM double RngDecimal(); AUKN_SYM double RngDecimal();
AUKN_SYM float RngNumber(float min, float max); AUKN_SYM float RngNumber(float min, float max);
AUKN_SYM AuUInt32 RngIndex(AuUInt32 count /* = max + 1*/); AUKN_SYM AuUInt32 RngIndex(AuUInt32 count /* = max + 1*/);
@ -37,24 +37,24 @@ namespace Aurora::RNG
{ {
if constexpr (fast) if constexpr (fast)
{ {
ReadFastRNG(array, N * sizeof(T)); ReadFastRNG(Memory::MemoryViewWrite(array));
} }
else else
{ {
ReadSecureRNG(array, N * sizeof(T)); ReadSecureRNG(Memory::MemoryViewWrite(array));
} }
} }
template<bool fast = true, typename T> template<bool fast = true, typename T>
static auline void RngFillArray(T *array, AuUInt32 length) static auline void RngFillArray(T *array, AuUInt32 uCount)
{ {
if constexpr (fast) if constexpr (fast)
{ {
ReadFastRNG(array, length * sizeof(T)); ReadFastRNG(Memory::MemoryViewWrite(array, uCount * sizeof(T)));
} }
else else
{ {
ReadSecureRNG(array, length * sizeof(T)); ReadSecureRNG(Memory::MemoryViewWrite(array, uCount * sizeof(T)));
} }
} }
@ -86,19 +86,19 @@ namespace Aurora::RNG
T ret {}; T ret {};
if constexpr (fast) if constexpr (fast)
{ {
ReadFastRNG(&ret, sizeof(T)); ReadFastRNG(Memory::MemoryViewWrite(&ret, sizeof(T)));
} }
else else
{ {
ReadSecureRNG(&ret, sizeof(T)); ReadSecureRNG(Memory::MemoryViewWrite(&ret, sizeof(T)));
} }
return ret; return ret;
} }
template<typename T> template<typename T>
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<typename T> template<typename T>

View File

@ -13,7 +13,9 @@ namespace Aurora::Threading::Primitives
A comprehensive CV that does not strictly abide by typical assumptions. <br> A comprehensive CV that does not strictly abide by typical assumptions. <br>
This object is not optimal; however, it will work with any or no IWaitable <br> This object is not optimal; however, it will work with any or no IWaitable <br>
On systems where context switches are expensive, this object should be avoided at all costs <br> On systems where context switches are expensive, this object should be avoided at all costs <br>
This object depends on the synchronization of primitives within our abstraction layer rather than the OS's implementation of condition variables <br> This object depends on the synchronization of primitives within our abstraction layer rather than the OS's implementation of condition variables. <br>
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 struct ConditionEx
{ {

View File

@ -16,9 +16,8 @@ namespace Aurora::Threading::Primitives
1) we define no waitable as illegal <br> 1) we define no waitable as illegal <br>
2) conditional variables may not rebind their mutex 2) conditional variables may not rebind their mutex
*/ */
class IConditionVariable struct IConditionVariable
{ {
public:
virtual AuSPtr<IConditionMutex> GetMutex() = 0; virtual AuSPtr<IConditionMutex> GetMutex() = 0;
virtual bool WaitForSignal(AuUInt32 timeout = 0) = 0; virtual bool WaitForSignal(AuUInt32 timeout = 0) = 0;
virtual void Broadcast() = 0; virtual void Broadcast() = 0;

View File

@ -12,13 +12,10 @@ namespace Aurora::Threading::Primitives
/** /**
Event synchronization primitive Event synchronization primitive
*/ */
class IEvent : public IWaitable struct IEvent : IWaitable
{ {
public: // 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();`
// 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 work processing to ::Lock/::Unlock (maybe ::Reset()), and the dispatching thread to ::Reset and ::Set.
// 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.
inline void Wait() inline void Wait()
{ {
@ -34,5 +31,8 @@ namespace Aurora::Threading::Primitives
virtual void Set() = 0; 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);
} }

View File

@ -14,5 +14,5 @@ namespace Aurora::Threading::Primitives
virtual void Unlock(long count) = 0; virtual void Unlock(long count) = 0;
}; };
AUKN_SHARED_API(Semaphore, ISemaphore, int initialCount = 0); AUKN_SHARED_API(Semaphore, ISemaphore, int iInitialCount = 0);
} }

View File

@ -9,11 +9,8 @@
namespace Aurora::Threading::Primitives namespace Aurora::Threading::Primitives
{ {
// NOTE: A SPINLOCK CAN NOT BE AN IWAITABLE BY DEFINITION struct AUKN_SYM SpinLock : IWaitable
// Partial interface support exists for completeness alone!
class AUKN_SYM SpinLock : public IWaitable
{ {
public:
SpinLock(); SpinLock();
bool HasOSHandle(AuMach &mach) override; bool HasOSHandle(AuMach &mach) override;

View File

@ -119,6 +119,12 @@ namespace Aurora::Console::Commands
return true; 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<ICommandSubscriber> &callback) AUKN_SYM void AddCommand(const AuString &tag, const Parse::ParseObject &commandStructure, const AuSPtr<ICommandSubscriber> &callback)
{ {
AU_LOCK_GUARD(gPendingCommandsMutex); AU_LOCK_GUARD(gPendingCommandsMutex);

View File

@ -241,9 +241,9 @@ namespace Aurora::Crypto::X509
switch (A) switch (A)
{ {
//case EExtendedUsage::eClientAuth: case EExtendedUsage::eServerAuth:
// SET_OID(ext_key_usage->buf, MBEDTLS_OID_SERVER_AUTH); SET_OID(ext_key_usage->buf, MBEDTLS_OID_SERVER_AUTH);
// break; break;
case EExtendedUsage::eClientAuth: case EExtendedUsage::eClientAuth:
SET_OID(ext_key_usage->buf, MBEDTLS_OID_CLIENT_AUTH); SET_OID(ext_key_usage->buf, MBEDTLS_OID_CLIENT_AUTH);
break; break;
@ -284,10 +284,10 @@ namespace Aurora::Crypto::X509
} }
iRet = ::mbedtls_x509write_crt_der(&crt, iRet = ::mbedtls_x509write_crt_der(&crt,
buffer.base, buffer.base,
buffer.length, buffer.length,
::mbedtls_ctr_drbg_random, ::mbedtls_ctr_drbg_random,
&IO::TLS::gCtrDrbg); &IO::TLS::gCtrDrbg);
if (iRet < 0) if (iRet < 0)
{ {
SysPushErrorCrypto("Couldn't write x509 cert: {}", iRet); SysPushErrorCrypto("Couldn't write x509 cert: {}", iRet);

View File

@ -46,6 +46,12 @@ namespace Aurora::Debug
return gHandlingFatal; return gHandlingFatal;
} }
AUKN_SYM void Panic2(AuUInt uLineHintInNonshipBinary)
{
// TODO: telemetry insert crashing from line uLineHintInNonshipBinary
Panic();
}
AUKN_SYM void Panic() AUKN_SYM void Panic()
{ {
// //

View File

@ -12,7 +12,7 @@ extern "C"
{ {
AUKN_SYM unsigned long rng_get_bytes(unsigned char *out, unsigned long outlen, void (*callback)(void)) 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; return outlen;
} }
} }

View File

@ -23,7 +23,7 @@ extern "C"
AUKN_SYM mp_err s_mp_rand_platform(void *p, size_t n) 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; return MP_OKAY;
} }
} }

View File

@ -12,7 +12,7 @@ extern "C"
{ {
AUKN_SYM int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, size_t *olen) 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; *olen = len;
return 0; return 0;
} }

View File

@ -359,7 +359,7 @@ namespace Aurora::Memory
auto pDiag = o1heapGetDiagnostics(this->heap_); auto pDiag = o1heapGetDiagnostics(this->heap_);
this->stats.uBytesLiveCounter = pDiag.allocated; this->stats.uBytesLiveCounter = pDiag.allocated;
this->stats.uBytesCapacity = pDiag.capacity; this->stats.uBytesCapacity = pDiag.capacity;
this->stats.uBytesPeakCounter = pDiag.peak_allocated; this->stats.uBytesPeakCounter = pDiag.peak_allocated;
} }

View File

@ -21,6 +21,8 @@ namespace Aurora::Memory
AuUInt gBytesCounterAllocated {}; AuUInt gBytesCounterAllocated {};
AuUInt gBytesCounterPeak {}; AuUInt gBytesCounterPeak {};
thread_local AuInt64 tlsLastOutOfMemory {};
static void AddBytesToCounter(AuUInt uBytes) static void AddBytesToCounter(AuUInt uBytes)
{ {
gBytesCounterPeak = AuMax(gBytesCounterPeak, AuAtomicAdd(&gBytesCounterAllocated, uBytes)); gBytesCounterPeak = AuMax(gBytesCounterPeak, AuAtomicAdd(&gBytesCounterAllocated, uBytes));
@ -47,6 +49,8 @@ namespace Aurora::Memory
auto pRet = exp; \ auto pRet = exp; \
if (!pRet) \ if (!pRet) \
{ \ { \
tlsLastOutOfMemory = AuTime::CurrentClockNS(); \
\
bool bCrunchFlag {}; \ bool bCrunchFlag {}; \
if (((bCrunchFlag = AuDebug::IsTlsMemoryCrunchActive()) || \ if (((bCrunchFlag = AuDebug::IsTlsMemoryCrunchActive()) || \
(gRuntimeConfig.debug.bIsApplicationClientSoftwareOnJitteryMemorySystem)) && \ (gRuntimeConfig.debug.bIsApplicationClientSoftwareOnJitteryMemorySystem)) && \
@ -73,26 +77,31 @@ namespace Aurora::Memory
AUKN_SYM void *_ZAlloc(Types::size_t length) AUKN_SYM void *_ZAlloc(Types::size_t length)
{ {
SysAssertDbg(length);
CHECK_WRAP_RETURN(::mi_zalloc(length), (ZAlloc(length)), "ZAlloc out of memory"); CHECK_WRAP_RETURN(::mi_zalloc(length), (ZAlloc(length)), "ZAlloc out of memory");
} }
AUKN_SYM void *_ZAlloc(Types::size_t length, Types::size_t align) 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"); CHECK_WRAP_RETURN(::mi_zalloc_aligned(length, align), (ZAlloc(length, align)), "ZAlloc out of memory");
} }
AUKN_SYM void *_FAlloc(Types::size_t length) AUKN_SYM void *_FAlloc(Types::size_t length)
{ {
SysAssertDbg(length);
CHECK_WRAP_RETURN(::mi_malloc(length), (FAlloc(length)), "FAlloc out of memory"); CHECK_WRAP_RETURN(::mi_malloc(length), (FAlloc(length)), "FAlloc out of memory");
} }
AUKN_SYM void *_FAlloc(Types::size_t length, Types::size_t align) 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"); 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) AUKN_SYM void *_ZRealloc(void *buffer, Types::size_t length, Types::size_t align)
{ {
SysAssertDbg(length);
void *pRet; void *pRet;
if (AuDebug::IsPointerReserveRange(buffer)) if (AuDebug::IsPointerReserveRange(buffer))
@ -119,6 +128,7 @@ namespace Aurora::Memory
AUKN_SYM void *_ZRealloc(void *buffer, Types::size_t length) AUKN_SYM void *_ZRealloc(void *buffer, Types::size_t length)
{ {
SysAssertDbg(length);
void *pRet; void *pRet;
if (AuDebug::IsPointerReserveRange(buffer)) 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) AUKN_SYM void *_FRealloc(void *buffer, Types::size_t length, Types::size_t align)
{ {
SysAssertDbg(length);
void *pRet; void *pRet;
if (AuDebug::IsPointerReserveRange(buffer)) if (AuDebug::IsPointerReserveRange(buffer))
@ -171,6 +182,7 @@ namespace Aurora::Memory
AUKN_SYM void *_FRealloc(void *buffer, Types::size_t length) AUKN_SYM void *_FRealloc(void *buffer, Types::size_t length)
{ {
SysAssertDbg(length);
void *pRet; void *pRet;
if (AuDebug::IsPointerReserveRange(buffer)) if (AuDebug::IsPointerReserveRange(buffer))
@ -213,6 +225,11 @@ namespace Aurora::Memory
} }
} }
AUKN_SYM AuInt64 GetLastOutOfMemoryTimeNS()
{
return tlsLastOutOfMemory;
}
AUKN_SYM AuUInt GetPageSize() AUKN_SYM AuUInt GetPageSize()
{ {
return AuHwInfo::GetPageSize(); return AuHwInfo::GetPageSize();

View File

@ -205,8 +205,11 @@ namespace Aurora::Parse
return true; 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 hexedit = formatting == EHexDump::eHexEditor;
bool squareBracket = formatting == EHexDump::eJSLiteral; bool squareBracket = formatting == EHexDump::eJSLiteral;

View File

@ -15,11 +15,14 @@ namespace Aurora::RNG
static WELLRand gWellRand; static WELLRand gWellRand;
RandomUnique_t gFastDevice; RandomUnique_t gFastDevice;
AUKN_SYM void ReadSecureRNG(void *pBuffer, AuUInt32 uBytes) AUKN_SYM void ReadSecureRNG(Memory::MemoryViewWrite writeView)
{ {
AuUInt32 offset; AuUInt32 offset;
AuUInt8 *headPtr; AuUInt8 *headPtr;
auto pBuffer = writeView.ptr;
auto uBytes = writeView.length;
SysAssert(pBuffer, "Null RNG out buffer"); SysAssert(pBuffer, "Null RNG out buffer");
headPtr = reinterpret_cast<AuUInt8 *>(pBuffer); headPtr = reinterpret_cast<AuUInt8 *>(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); WELL_NextBytes(&gWellRand, pBuffer, uBytes);
} }

View File

@ -38,9 +38,9 @@ namespace Aurora::RNG
// secure rng requires no init -> we just passthrough to the global ReadSecureRNG function // 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(); SysPushErrorArg();
return; return;
@ -48,11 +48,11 @@ namespace Aurora::RNG
if (this->def_.bSecure) if (this->def_.bSecure)
{ {
ReadSecureRNG(pIn, uLength); ReadSecureRNG(view);
} }
else else
{ {
WELL_NextBytes(&this->fast_, pIn, uLength); WELL_NextBytes(&this->fast_, view.ptr, AuUInt32(view.length));
} }
} }
@ -81,7 +81,7 @@ namespace Aurora::RNG
return; return;
} }
ReadSecureRNG(pString, uLength); ReadSecureRNG(AuMemoryViewWrite { pString, uLength });
if (!ERngStringCharactersIsValid(type)) if (!ERngStringCharactersIsValid(type))
{ {

View File

@ -13,7 +13,7 @@ namespace Aurora::RNG
{ {
struct RandomDevice : IRandomDevice struct RandomDevice : IRandomDevice
{ {
void Read(void *pIn, AuUInt32 uLength) override; void Read(Memory::MemoryViewWrite view) override;
AuString NextString(AuUInt32 uLength, ERngStringCharacters type) override; AuString NextString(AuUInt32 uLength, ERngStringCharacters type) override;
void NextString(char *pString, AuUInt32 uLength, ERngStringCharacters type) override; void NextString(char *pString, AuUInt32 uLength, ERngStringCharacters type) override;