// ============================================================================ // RynthCore.Loader.dll - native loader (docs/UNLOADABLE_ENGINE_PLAN.md, Phase 1) // // Injected into acclient.exe by RynthCore.Injector / the launcher, which call the // RynthCoreInit export on a remote thread (same contract as the old NativeAOT loader). // // Two engine hosts, chosen by looking at Runtime\RynthCore.Engine.dll: // - NativeAOT engine (a native DLL exporting RynthCoreEngineInit): staged to // .engine_loads\, LoadLibrary'd, never freed. Today's behaviour. // - Managed engine (a PE with a CLR header): the loader starts CoreCLR once from // Runtime\dotnet\ and hands the engine to RynthCore.Shim.dll (default ALC), which // loads each generation into a collectible AssemblyLoadContext and unloads it on // reload, so a reload gives its memory back. // // Either way the loader owns the reload event, the file watcher, the address-space // guard, the reload cap (MaxHotReloads per client) and a MinHook facade (Hooks.c): // every hook is installed once, through a permanent stub, and a reload only re-points // the stub. For the managed engine it also sets up CoreCLR's crash dumps (Logs\dumps). // ============================================================================ #include "Loader.h" #include #include #include #define ENGINE_DLL_NAME "RynthCore.Engine.dll" #define ENGINE_INIT_EXPORT "RynthCoreEngineInit" #define ENGINE_SHUTDOWN_EXPORT "RynthCoreShutdown" #define ENGINE_REFUSED_EXPORT "RynthCoreReloadRefused" #define ENGINE_MAXRELOADS_EXPORT "RynthCoreMaxHotReloads" #define ENGINE_CAPPED_EXPORT "RynthCoreReloadCapped" #ifndef LOG_DIR // the offline tests (tools\Loader*Tests) log into their own folder #define LOG_DIR "C:\\Games\\RynthCore\\Logs" #define LOG_PARENT "C:\\Games\\RynthCore" #endif #define STAGING_SUBDIR ".engine_loads" // Hot reloads one client takes before it refuses the rest (until it restarts). The engine // says the real number (engine.json MaxHotReloads, RynthCoreMaxHotReloads export); this is // for an engine without the export. 3 from 2026-10-11, after clients died with CoreCLR fatal // error 0x80131506 at coreclr+0x256E19 after 4+ reloads in one process (2026-10-08..10). The // 10-15 dump triage put those on the v1 SehTrampoline crash logger (ReversePInvokeBadTransition, // fixed by db645ba on 10-12), not on reloading: none since, and address space was healthy at // every crash. So 20 since 2026-10-15: a backstop, not a known CoreCLR limit. #define DEFAULT_MAX_HOT_RELOADS 20 // CoreCLR's own crash dump (createdump.exe, DOTNET_DbgEnableMiniDump): clr__