FModuleManager
- Module
- Core
- Header
#include "Core/FModuleManager.h"- Namespace
Mowo
Type aliases
| Alias | Description |
|---|---|
using FUnloadHandler = void (*)(void* moduleHandle) | Module-unload broadcast: fired from UnloadModule after the module's own ShutdownModule hook and BEFORE the image is freed, so a handler can still touch code and data inside the dying module. This is how the additive registries (scene systems, reflection descriptors, online services, asset validators, net-session providers) drop function pointers that would otherwise keep pointing into freed pages. Handlers are process-lifetime plain function pointers from never-unloaded engine modules; duplicates are ignored. |
using FModuleVerifier = bool (*)(const std::string& resolvedPath, void* image, std::string& outReason) | Verify-before-load gate. The ABI check in LoadModuleFromPath only runs AFTER LoadLibrary has already executed the image's static init (DllMain), so a hostile or wrong module gets to run code before it is (maybe) refused. A higher tier — one that can reach the EdDSA/hash crypto in Filesystem — registers a verifier here; the loader calls it on the resolved binary PATH *before* the image is mapped, and a false result refuses the load with the image never touched. With no verifier registered the loader behaves exactly as before (unsigned local/dev modules load), so this is opt-in hardening a shipping host arms. One verifier, process-lifetime; the last registration wins. outReason is logged on refusal. A distribution build also checks every engine library against the engine's signed statement before this verifier runs (Core/ModuleIntegrity.h), whether or not one is registered. image is the IPlatformLibrary::OpenImageForLoad handle the loader holds from before the verifier runs until after the image is mapped: the verifier reads the bytes through it (IPlatformLibrary::ReadImage), so what it vouches for is what gets mapped. The module's imports that are files the game ships, not yet mapped, are held and verified the same way before the load — an unsigned DLL beside a signed plugin would otherwise come in as its dependency, without ever passing the gate. |
Constructors
| Signature | Name | Description |
|---|---|---|
FModuleManager(const FModuleManager&) = delete | FModuleManager |
Public functions
| Returns | Name | Description |
|---|---|---|
FModuleManager& | Get | |
FModuleManager& | operator= | |
void | AddUnloadHandler | |
void | SetModuleVerifier | |
bool | HasModuleVerifier | |
bool | OwnsAddress | True when address lies inside the loaded image handle refers to — the attribution primitive the unload handlers filter with (same Platform query FMObjectArray::PurgeModuleObjects uses on vtables). |
bool | LoadModule | Load name from the executable's directory — the newest versioned binary when one exists, else <name>.dll. |
bool | LoadModuleFromPath | Load a specific binary path under a module name (hot reload hands the freshly-built versioned file directly). |
std::string | GetLoadFailure | Why the last attempt to load name failed, in a sentence a person can act on: the missing file or dependency DLL, both build ids of a mismatch, the OS's own error text. |
void | NoteLoadFailure | Records a reason a host knows before it ever calls LoadModule (the binary is not built), so GetLoadFailures and the Play error can report it. |
void | SetProjectSourceDir | The project whose game modules the failures belong to: its Source/ folder is what an out-of-tree build needs as --extra-source. |
void | ClearLoadFailures | |
std::vector<std::string> | OrderByImports | modules ordered so a module that imports another's binary comes after it, so the dependency's InitializeModule has run when the dependent's does. |
std::string | BuildCommand | The one spelling of "build this module" every refusal quotes. |
std::vector<std::pair<std::string, std::string>> | GetLoadFailures | Every module whose last load failed, as (name, reason). |
uint32_t | ModuleApiVersion | The version the loader compares against; a module exports the same number through MOWO_IMPLEMENT_MODULE_API_VERSION(). |
const char* | BuildAbi | The engine's own MOWO_BUILD_ABI_SIGNATURE, as compiled into Core. |
std::string | CompatibilityProblem | Why a module with these exports may not load, or empty when it may. |
bool | IsEngineOwnedModule | Engine runtime modules ("MowoEngine.<Name>") ship with the loader and need no version export; every other module (plugin, game, sandbox) must carry one or is refused. |
bool | UnloadModule | Calls the optional ShutdownModule export, then frees the library. |
bool | IsModuleLoaded | |
void* | GetModuleHandle | Native handle (HMODULE / dlopen handle) as void*. |
std::string | FindModuleBinary | Path of the binary LoadModule would pick for name right now: the highest <name>.v<N>.dll in the executable directory, else <name>.dll, else empty when neither exists. |
Function details
FModuleManager
FModuleManager(const FModuleManager&) = deleteGet
static FModuleManager& Get()operator=
FModuleManager& operator=(const FModuleManager&) = deleteAddUnloadHandler
static void AddUnloadHandler(FUnloadHandler handler)SetModuleVerifier
static void SetModuleVerifier(FModuleVerifier verifier)HasModuleVerifier
static bool HasModuleVerifier()OwnsAddress
static bool OwnsAddress(void* moduleHandle, const void* address)True when address lies inside the loaded image handle refers to — the attribution primitive the unload handlers filter with (same Platform query FMObjectArray::PurgeModuleObjects uses on vtables).
LoadModule
bool LoadModule(const std::string& name)Load name from the executable's directory — the newest versioned binary when one exists, else <name>.dll. Loading an already-loaded module is a no-op returning true. Calls the optional InitializeModule export.
LoadModuleFromPath
bool LoadModuleFromPath(const std::string& name, const std::string& path)Load a specific binary path under a module name (hot reload hands the freshly-built versioned file directly). A binary whose MowoModuleApiVersion export is missing or differs from MOWO_MODULE_API_VERSION is refused: its static registrations are swept back out and the image is freed before this returns false.
GetLoadFailure
std::string GetLoadFailure(const std::string& name) constWhy the last attempt to load name failed, in a sentence a person can act on: the missing file or dependency DLL, both build ids of a mismatch, the OS's own error text. Empty when the last attempt succeeded or none was made. The same text goes to stderr; this is how a host with a log (the editor's Output Log) reports it too.
NoteLoadFailure
void NoteLoadFailure(const std::string& name, const std::string& reason)Records a reason a host knows before it ever calls LoadModule (the binary is not built), so GetLoadFailures and the Play error can report it.
SetProjectSourceDir
void SetProjectSourceDir(const std::string& dir)The project whose game modules the failures belong to: its Source/ folder is what an out-of-tree build needs as --extra-source. ClearLoadFailures runs when a project opens so one project's failures never read as another's.
ClearLoadFailures
void ClearLoadFailures()OrderByImports
std::vector<std::string> OrderByImports(const std::vector<std::string>& modules) constmodules ordered so a module that imports another's binary comes after it, so the dependency's InitializeModule has run when the dependent's does. The OS loads an import by itself, without running InitializeModule, which is why directory order alone is wrong whenever a dependent sorts first. Ties and cycles keep the given order.
BuildCommand
std::string BuildCommand(const std::string& module) constThe one spelling of "build this module" every refusal quotes.
GetLoadFailures
std::vector<std::pair<std::string, std::string>> GetLoadFailures() constEvery module whose last load failed, as (name, reason).
ModuleApiVersion
static uint32_t ModuleApiVersion()The version the loader compares against; a module exports the same number through MOWO_IMPLEMENT_MODULE_API_VERSION().
BuildAbi
static const char* BuildAbi()The engine's own MOWO_BUILD_ABI_SIGNATURE, as compiled into Core.
CompatibilityProblem
static std::string CompatibilityProblem(bool hasVersionExport, uint32_t version, const char* buildAbi)Why a module with these exports may not load, or empty when it may. buildAbi is null when the module exports no MowoModuleBuildAbi. Pure, so the refusal rules can be pinned without building a binary for every way of getting them wrong.
IsEngineOwnedModule
static bool IsEngineOwnedModule(const std::string& name)Engine runtime modules ("MowoEngine.<Name>") ship with the loader and need no version export; every other module (plugin, game, sandbox) must carry one or is refused. A layout question only: anyone can name a DLL "MowoEngine.X", so no trust decision may read it — the signature gate verifies every module it is handed, whatever the name.
UnloadModule
bool UnloadModule(const std::string& name)Calls the optional ShutdownModule export, then frees the library. Returns false when the module isn't loaded.
IsModuleLoaded
bool IsModuleLoaded(const std::string& name) constGetModuleHandle
void* GetModuleHandle(const std::string& name) constNative handle (HMODULE / dlopen handle) as void*. nullptr when not loaded. Pass to MClassRegistry::UnregisterAllInModule.
FindModuleBinary
std::string FindModuleBinary(const std::string& name) constPath of the binary LoadModule would pick for name right now: the highest <name>.v<N>.dll in the executable directory, else <name>.dll, else empty when neither exists.