[+] configurable memory allocator padding

This commit is contained in:
Reece Wilson 2022-12-07 16:20:13 +00:00
parent 73e77d0a97
commit 1b26faf45a
3 changed files with 69 additions and 24 deletions

View File

@ -131,6 +131,9 @@ static inline void AuDebugBreak()
namespace Aurora namespace Aurora
{ {
// The following configuration structures are a mess you probably wont need to think about for a while.
// Let's assume it's safe to move onto some other for now, alright?
struct LocalLogInfo struct LocalLogInfo
{ {
bool enableLogging {true}; bool enableLogging {true};
@ -144,6 +147,7 @@ namespace Aurora
#endif #endif
}; };
// TODO: this struct is mostly placeholder BS
struct TelemetryConfigDoc struct TelemetryConfigDoc
{ {
LocalLogInfo localLogging; LocalLogInfo localLogging;
@ -163,7 +167,8 @@ namespace Aurora
bool readModNameJsonConfig {}; bool readModNameJsonConfig {};
TelemetryConfigDoc defaultConfig; TelemetryConfigDoc defaultConfig;
}; };
// TODO: this struct is mostly placeholder BS
struct SocketConsole struct SocketConsole
{ {
bool enableLogging {false}; bool enableLogging {false};
@ -236,6 +241,7 @@ namespace Aurora
/// Defer to the rationales in the implementation /// Defer to the rationales in the implementation
bool allowRussianCerts {true}; bool allowRussianCerts {true};
// TODO: we have no live or cached builtin CRL and CA retrieval and storage
/// WIP /// WIP
bool allowHTTPRetrievalOfCerts {true}; bool allowHTTPRetrievalOfCerts {true};
@ -243,14 +249,15 @@ namespace Aurora
bool enablePinning {true}; bool enablePinning {true};
/// ///
// TODO: these placeholder bits will be made redundant once AuCrypto is overhauled
AuList<AuString> blacklistedCerts{}; AuList<AuString> blacklistedCerts{};
AuList<AuString> whitelistedCerts{}; AuList<AuString> whitelistedCerts{};
}; };
struct AsyncConfig struct AsyncConfig
{ {
bool enableSchedularThread {true}; // turn this off to make your application lighter weight, turn this on for higher performance (+expensive) scheduling bool enableSchedularThread {true}; // turn this off to make your application lighter-weight; turn this on for higher performance (+expensive) scheduling
bool enableSysPumpFreqnecy {false}; // turn this on to enable an async app's singleton threadpool to SysPump on worker id zero. Alternatively, use SetMainThreadForSysPumpScheduling once you have a thread pool and worker id. bool enableSysPumpFreqnecy {false}; // turn this on to enable an async apps singleton threadpool to SysPump on worker id zero. Alternatively, use SetMainThreadForSysPumpScheduling once you have a thread pool and worker id.
AuUInt32 threadPoolDefaultStackSize {}; AuUInt32 threadPoolDefaultStackSize {};
AuUInt32 schedularFrequency {2}; // * 0.5 or 1 MS depending on the platform AuUInt32 schedularFrequency {2}; // * 0.5 or 1 MS depending on the platform
AuUInt32 sysPumpFrequency {25}; // x amount of schedularFrequencys AuUInt32 sysPumpFrequency {25}; // x amount of schedularFrequencys
@ -266,30 +273,57 @@ namespace Aurora
{ {
/** /**
* @brief Precache/initialize symbols for printable stack traces under binaries not intended for shipping to consumers * @brief Precache/initialize symbols for printable stack traces under binaries not intended for shipping to consumers
*
* @warning true will result in artificially high commit charge under certain monitoring applications as application databases are
* precached into memory. these maps shouldn't be duplicated across processes (if the kernel plays nice). regardless,
* end users shouldn't see the hit. in the best case scenario, this serves as a quality of life upgrade for stage/debug
* binaries that want real time stack traces with file locations cached. noting that this isn't optional for stage win32
* builds with live exception traces with line info. in the future, debug tools should be able to parse telemetry dumps, though.
*/ */
bool bNonshipPrecachesSymbols {true}; bool bNonshipPrecachesSymbols { true };
/** /**
* @brief Activates the internal AddVectoredExceptionHandler handler. Might conflict with DRM and other debugging utilities * @brief Activates the internal AddVectoredExceptionHandler handler. Might conflict with DRM and other debugging utilities
*/ */
bool bEnableWin32RootExceptionHandler {true}; bool bEnableWin32RootExceptionHandler { true };
/** /**
* @brief * @brief
*/ */
bool bEnableInjectedExceptionHandler {true}; bool bEnableInjectedExceptionHandler { true };
/** /**
* @brief Causes a SysPanic * @brief Raises a SysPanic in place of returning null over all allocators. This includes C++ containers which *should* be configured to use our overloaded allocators (compile ./Source/Alloc.cpp & link in with your application/library).
* If you're one of those people who don't like the idea of raising out of memory exceptions, and therefore compile without exceptions, this is an alternative this allows for exceptions to remain enabled for truly exceptional behaviour
* IE: we're fucked. Lets see if we can restart the root tick, at the risk of unaccounted for behaviour, because crashing over a STL parse exception or something stupid in that ballpark would be a really terrible **[end]user**-experience.
*/ */
bool bIsMemoryErrorFatal {false}; bool bIsMemoryErrorFatal { false };
/** /**
* @brief * @brief
*/ */
bool bIsExceptionThrowFatal {false}; bool bIsExceptionThrowFatal { false };
bool bPrintExceptionStackTracesOut {true}; bool bPrintExceptionStackTracesOut { true };
bool bIsApplicationClientSoftwareOnJitteryMemorySystem { false }; // enable me to enable padding from system out of memory conditions.
// the catch: usually this memory is reserved for exit callbacks, internal low memory conditions, error reporting, and the like.
//
// generally you should not exploit this without ** acknowledging this thread-local condition via AuDebug::[Add/Dec]MemoryCrunch. ** ( << tl;dr: recommended way of accessing this memory)
//
// setting this flag enables debug buffer memory to be used at any point during any threads execution - the moment mimalloc runs
// out of pre-reserved and system mappable memory. i wouldn't use this for anything except monolithic client/user-facing applications
// that are likely to run on low resource systems (low spec or heavy app), with untested/uncaught C++ allocations splattered everywhere.
// this could be VERY useful to end users who are running into `bIsMemoryErrorFatal` crashes.
AuUInt32 uDebugMemoryReserveSize { 3 * 1024 * 1024 }; /* nowdays: a single v8 isolate is low sub-tens MB of memory, executable file sizes are low mbs, image sizes are much larger. forget small low-footprint vms
of flex and bison yesteryear. 3MB given our heavyish standard footprint already is probably fine. how much memory do Java heap+JIT engines sink just to boot again?
this'll allow us to high tens of KBs of malicous strings, overhead for doing telemetry/(structured ???)logging, overhead to stack traces, module cache, etc.
i'm sure it'll also be enough to give back to the user, if need be.
@warning: 0 = 3 * 1024 * 1024
*/
}; };
struct RuntimeStartInfo struct RuntimeStartInfo

View File

@ -21,7 +21,9 @@ namespace Aurora::Debug
void InitMemoryCrunch() void InitMemoryCrunch()
{ {
gReserveHeap = AuMemory::AllocHeapShared(kAutoReservePool); gReserveHeap = AuMemory::AllocHeapShared(gRuntimeConfig.debug.uDebugMemoryReserveSize ?
gRuntimeConfig.debug.uDebugMemoryReserveSize :
kAutoReservePool);
SysAssert(gReserveHeap); SysAssert(gReserveHeap);
auto pHeap = AuStaticCast<AuMemory::BaseHeap>(gReserveHeap); auto pHeap = AuStaticCast<AuMemory::BaseHeap>(gReserveHeap);

View File

@ -30,19 +30,28 @@ namespace Aurora::Memory
} }
} }
#define CHECK_WRAP_RETURN(exp, exp2, string) \ #define CHECK_WRAP_RETURN(exp, exp2, string) \
auto pRet = exp; \ auto pRet = exp; \
if (!pRet) \ if (!pRet) \
{ \ { \
if (AuDebug::IsTlsMemoryCrunchActive() && AuDebug::gReserveHeap) \ bool bCrunchFlag {}; \
{ \ if (((bCrunchFlag = AuDebug::IsTlsMemoryCrunchActive()) || \
return AuDebug::gReserveHeap-> AU_WHAT exp2; \ (gRuntimeConfig.debug.bIsApplicationClientSoftwareOnJitteryMemorySystem)) && \
} \ AuDebug::gReserveHeap) \
else if (gRuntimeConfig.debug.bIsMemoryErrorFatal) \ { \
{ \ if (!(pRet = AuDebug::gReserveHeap-> AU_WHAT exp2)) \
SysPanic(string); \ { \
} \ if (bCrunchFlag || gRuntimeConfig.debug.bIsMemoryErrorFatal) \
} \ { \
SysPanic("out of contingency memory"); \
} \
} \
} \
else if (gRuntimeConfig.debug.bIsMemoryErrorFatal) \
{ \
SysPanic(string); \
} \
} \
return pRet; return pRet;
AUKN_SYM void *_ZAlloc(Types::size_t length) AUKN_SYM void *_ZAlloc(Types::size_t length)