NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches

#include <game/cLib/c_dylink.hpp>

Inheritance diagram for DynamicModuleControl:
[legend]

Description

Full implementation of a dynamic module handler.

Definition at line 112 of file c_dylink.hpp.

Public Types

enum  ModuleType_e {
  MODULE_TYPE_UNKNOWN ,
  MODULE_TYPE_MEM ,
  MODULE_TYPE_ARAM ,
  MODULE_TYPE_DVD
}
 Identifies where the module data is physically located. More...

Public Member Functions

 DynamicModuleControl (const char *name, EGG::ExpHeap *heap)
 Constructs a new DynamicModuleControl.
virtual ~DynamicModuleControl ()
 Destroys the DynamicModuleControl.
virtual const char * getModuleName () const override
 Gets the module name.
virtual size_t getModuleSize () const override
 Gets the module size in bytes.
virtual const char * getModuleTypeString () const override
 Gets a human-readable module type string.
virtual void dump () override
 Outputs debug information about the module.
virtual bool do_load () override
 Module-specific implementation for loading the module into memory.
virtual bool do_load_async () override
 Module-specific implementation for loading the module into memory asynchronously.
virtual bool do_unload () override
 Module-specific implementation for unloading the module from memory.
virtual bool do_link () override
 Module-specific implementation for linking the module, making it ready for use.
virtual bool do_unlink () override
 Module-specific implementation for unlinking the module.
void checkHeapStatus ()
 Updates the module linking heap statistics.
Public Member Functions inherited from DynamicModuleControlBase
 DynamicModuleControlBase ()
 Constructs a new DynamicModuleControlBase and adds it to the linked list.
virtual ~DynamicModuleControlBase ()
 Destroys the DynamicModuleControlBase and removes it from the linked list.
bool link ()
 Loads and links the module if needed.
bool unlink ()
 Unlinks and unloads the module if needed.
bool load_async ()
 Loads the module asynchronously if needed.

Static Public Member Functions

static void initialize (EGG::ExpHeap *heap)
 Initializes the global dynamic linking system.
static void * callback (void *self)
 Internal callback used for asynchronous loading operations.

Public Attributes

u8 mPad [4]
OSModuleHeader * mpModule
 The data of the module, including the header.
void * mpBss
 The BSS section of the module.
u32 mPrologReturn
 The return value of the module's prolog function.
const char * mModuleName
 The module name.
u8 mType
 The module type. See ModuleType_e.
u8 mLoadCount
 The number of times this module has been loaded.
u16 mChecksum
 The checksum of the module.
int mModuleSize
 The module size, in bytes.
mDvd_callback_cmpDvdCallback
 The DVD command used to load the module asynchronously.
EGG::ExpHeap * mpHeap
 The heap used for module loading and BSS allocation.
DbMapFile mDebugMapFile
 The debug map file for this module.

Static Public Attributes

static EGG::ExpHeap * sDylinkHeap
 The heap used for dynamic module loading and BSS allocation.
static EGG::DvdFile * sDvdFile
 The DVD file handle used for loading the string table file.
static size_t sAllocBytes
 The total number of bytes allocated across all active modules.
static size_t sHeapMinAllocatableSize
 The lowest observed allocatable space in sDylinkHeap during module loading.
static size_t sHeapMinTotalFreeSize
 The lowest observed free space in sDylinkHeap during module loading.
static const char * sModulesDir = "/rels"
 The directory on the disk where the modules are located.
Static Public Attributes inherited from DynamicModuleControlBase
static DynamicModuleControlBasemFirst
 The first module in the linked list.
static DynamicModuleControlBasemLast
 The last module in the linked list.

Additional Inherited Members

Protected Attributes inherited from DynamicModuleControlBase
u16 mUsageCount
 The number of active users of this module. When this reaches zero, the module may be unloaded.
u16 mLinkCount
 The number of times this module has been successfully linked.
DynamicModuleControlBasempPrev
 The previous module in the linked list.
DynamicModuleControlBasempNext
 The next module in the linked list.

Member Enumeration Documentation

◆ ModuleType_e

Identifies where the module data is physically located.

Enumerator
MODULE_TYPE_UNKNOWN 

The module type has not yet been determined.

MODULE_TYPE_MEM 

The module is loaded from main RAM.

MODULE_TYPE_ARAM 

The module is loaded from ARAM.

MODULE_TYPE_DVD 

The module is loaded from the disc.

Definition at line 116 of file c_dylink.hpp.

Constructor & Destructor Documentation

◆ DynamicModuleControl()

DynamicModuleControl::DynamicModuleControl ( const char * name,
EGG::ExpHeap * heap )

Constructs a new DynamicModuleControl.

Parameters
nameThe module name.
heapThe heap to load the module into, or nullptr to use the default heap.

Definition at line 86 of file c_dylink.cpp.

◆ ~DynamicModuleControl()

DynamicModuleControl::~DynamicModuleControl ( )
virtual

Destroys the DynamicModuleControl.

Definition at line 100 of file c_dylink.cpp.

Member Function Documentation

◆ getModuleName()

const char * DynamicModuleControl::getModuleName ( ) const
overridevirtual

Gets the module name.

Returns
A string identifying the module, or nullptr if unnamed.

Reimplemented from DynamicModuleControlBase.

Definition at line 102 of file c_dylink.cpp.

◆ getModuleSize()

size_t DynamicModuleControl::getModuleSize ( ) const
overridevirtual

Gets the module size in bytes.

Returns
The size of the module, or 0 if unknown.

Reimplemented from DynamicModuleControlBase.

Definition at line 329 of file c_dylink.cpp.

◆ getModuleTypeString()

const char * DynamicModuleControl::getModuleTypeString ( ) const
overridevirtual

Gets a human-readable module type string.

Reimplemented from DynamicModuleControlBase.

Definition at line 340 of file c_dylink.cpp.

◆ dump()

void DynamicModuleControl::dump ( )
overridevirtual

Outputs debug information about the module.

Decompilation Note
This function has been stubbed, but was likely used for debugging purposes during development.

Reimplemented from DynamicModuleControlBase.

Definition at line 245 of file c_dylink.cpp.

◆ do_load()

bool DynamicModuleControl::do_load ( )
overridevirtual

Module-specific implementation for loading the module into memory.

Returns
Whether the operation was successful.

Reimplemented from DynamicModuleControlBase.

Definition at line 146 of file c_dylink.cpp.

◆ do_load_async()

bool DynamicModuleControl::do_load_async ( )
overridevirtual

Module-specific implementation for loading the module into memory asynchronously.

Returns
Whether the operation was successfully started.

Reimplemented from DynamicModuleControlBase.

Definition at line 220 of file c_dylink.cpp.

◆ do_unload()

bool DynamicModuleControl::do_unload ( )
overridevirtual

Module-specific implementation for unloading the module from memory.

Returns
Whether the operation was successful.

Reimplemented from DynamicModuleControlBase.

Definition at line 237 of file c_dylink.cpp.

◆ do_link()

bool DynamicModuleControl::do_link ( )
overridevirtual

Module-specific implementation for linking the module, making it ready for use.

Returns
Whether the operation was successful.

Reimplemented from DynamicModuleControlBase.

Reimplemented in dDynamicModuleControl.

Definition at line 247 of file c_dylink.cpp.

◆ do_unlink()

bool DynamicModuleControl::do_unlink ( )
overridevirtual

Module-specific implementation for unlinking the module.

Returns
Whether the operation was successful.

Reimplemented from DynamicModuleControlBase.

Definition at line 313 of file c_dylink.cpp.

◆ checkHeapStatus()

void DynamicModuleControl::checkHeapStatus ( )

Updates the module linking heap statistics.

The function tracks the minimum allocatable space and minimum free space size during module operations, probably to aid in debugging.

Definition at line 122 of file c_dylink.cpp.

◆ initialize()

void DynamicModuleControl::initialize ( EGG::ExpHeap * heap)
static

Initializes the global dynamic linking system.

Parameters
heapThe heap where all modules will be allocated by default.

Definition at line 106 of file c_dylink.cpp.

◆ callback()

void * DynamicModuleControl::callback ( void * self)
static

Internal callback used for asynchronous loading operations.

The return type is void* to satisfy the type required by mDvd_callback_c.

Parameters
selfPointer to the DynamicModuleControl instance.
Returns
The result of do_load().

Definition at line 117 of file c_dylink.cpp.

Member Data Documentation

◆ mPad

u8 DynamicModuleControl::mPad[4]

Definition at line 154 of file c_dylink.hpp.

◆ mpModule

OSModuleHeader* DynamicModuleControl::mpModule

The data of the module, including the header.

Definition at line 155 of file c_dylink.hpp.

◆ mpBss

void* DynamicModuleControl::mpBss

The BSS section of the module.

Definition at line 156 of file c_dylink.hpp.

◆ mPrologReturn

u32 DynamicModuleControl::mPrologReturn

The return value of the module's prolog function.

Definition at line 157 of file c_dylink.hpp.

◆ mModuleName

const char* DynamicModuleControl::mModuleName

The module name.

Definition at line 158 of file c_dylink.hpp.

◆ mType

u8 DynamicModuleControl::mType

The module type. See ModuleType_e.

Definition at line 159 of file c_dylink.hpp.

◆ mLoadCount

u8 DynamicModuleControl::mLoadCount

The number of times this module has been loaded.

Definition at line 160 of file c_dylink.hpp.

◆ mChecksum

u16 DynamicModuleControl::mChecksum

The checksum of the module.

Definition at line 161 of file c_dylink.hpp.

◆ mModuleSize

int DynamicModuleControl::mModuleSize

The module size, in bytes.

Definition at line 162 of file c_dylink.hpp.

◆ mpDvdCallback

mDvd_callback_c* DynamicModuleControl::mpDvdCallback

The DVD command used to load the module asynchronously.

Definition at line 163 of file c_dylink.hpp.

◆ mpHeap

EGG::ExpHeap* DynamicModuleControl::mpHeap

The heap used for module loading and BSS allocation.

Definition at line 164 of file c_dylink.hpp.

◆ mDebugMapFile

DbMapFile DynamicModuleControl::mDebugMapFile

The debug map file for this module.

Definition at line 165 of file c_dylink.hpp.

◆ sDylinkHeap

EGG::ExpHeap * DynamicModuleControl::sDylinkHeap
static

The heap used for dynamic module loading and BSS allocation.

Definition at line 167 of file c_dylink.hpp.

◆ sDvdFile

EGG::DvdFile * DynamicModuleControl::sDvdFile
static

The DVD file handle used for loading the string table file.

Definition at line 168 of file c_dylink.hpp.

◆ sAllocBytes

size_t DynamicModuleControl::sAllocBytes
static

The total number of bytes allocated across all active modules.

Definition at line 169 of file c_dylink.hpp.

◆ sHeapMinAllocatableSize

size_t DynamicModuleControl::sHeapMinAllocatableSize
static

The lowest observed allocatable space in sDylinkHeap during module loading.

Definition at line 170 of file c_dylink.hpp.

◆ sHeapMinTotalFreeSize

size_t DynamicModuleControl::sHeapMinTotalFreeSize
static

The lowest observed free space in sDylinkHeap during module loading.

Definition at line 171 of file c_dylink.hpp.

◆ sModulesDir

const char * DynamicModuleControl::sModulesDir = "/rels"
static

The directory on the disk where the modules are located.

Definition at line 172 of file c_dylink.hpp.