ReXGlue SDK
Loading...
Searching...
No Matches
rex::kernel::ModuleObject Struct Reference
Inheritance diagram for rex::kernel::ModuleObject:
[legend]

Public Member Functions

 ModuleObject (TitleRuntime *runtime_in, ModuleType type_in)
 ~ModuleObject ()
bool IsNamed (std::string_view query) const
X_STATUS GetSection (std::string_view section_name, u32 *out_section_data, u32 *out_section_size) const override
u32 GetExportAddress (TitleRuntime &owning_runtime, u16 ordinal, u32 caller_address=0)
u32 GetExportAddress (std::string_view export_name) const
rex::kernel::XEXModule * GetXEX ()
const rex::kernel::XEXModule * GetXEX () const
u32 GetTitleID () const override
std::vector< u32 > GetAlternateTitleIDs () const override
const std::string & GetPath () const override
X_STATUS LoadFromFile (TitleRuntime &owning_runtime, std::string_view guest_path)
X_STATUS LoadFromMemory (TitleRuntime &owning_runtime, const void *addr, size_t length)
X_STATUS Unload ()
X_STATUS GetOptHeader (XEXHeaderKey key, void **out_ptr) override
template<typename T>
X_STATUS OptHeader (XEXHeaderKey key, T *out_ptr)
X_STATUS GetOptHeaderGuestAddress (XEXHeaderKey key, u32 *out_guest_address) const override
void InvalidateThunkCache (u32 lo, u32 hi)
void SetVariable (u16 ordinal, u32 address)
u32 GetVariable (u16 ordinal) const
Public Member Functions inherited from rex::kernel::ILoadedModule
template<typename T>
X_STATUS OptHeader (XEXHeaderKey key, T *out_ptr)

Static Public Member Functions

static u32 HandleFromHModule (void *hmodule)
static X_HANDLE FromHModule (TitleRuntime &runtime, void *hmodule)
static X_HANDLE CreateKernelModule (TitleRuntime &runtime, std::string_view path)
static X_HANDLE CreateUserModule (TitleRuntime &runtime)
static X_STATUS GetOptHeader (const kernel::GuestAddressSpace *memory, const XEXHeader *header, XEXHeaderKey key, u32 *out_header_guest_ptr)

Public Attributes

ModuleType type
std::string name
std::string path
PropagateConst< std::unique_ptr< rex::kernel::GuestModule > > processor_module
u32 hmodule_ptr = 0
TitleRuntime * runtime
UserModuleState user
KernelModuleState kernel

Additional Inherited Members

Protected Member Functions inherited from rex::NonCopyable
 NonCopyable (const NonCopyable &)=delete
NonCopyable & operator= (const NonCopyable &)=delete

Constructor & Destructor Documentation

◆ ModuleObject()

rex::kernel::ModuleObject::ModuleObject ( TitleRuntime * runtime_in,
ModuleType type_in )

Allocates the loader data entry.

Parameters
type_inWhether the module is kernel or user.

◆ ~ModuleObject()

rex::kernel::ModuleObject::~ModuleObject ( )

Unloads a user module and frees the loader data entry.

Member Function Documentation

◆ CreateKernelModule()

X_HANDLE rex::kernel::ModuleObject::CreateKernelModule ( TitleRuntime & runtime,
std::string_view path )
static

Creates the KernelObject of a kernel module with its first handle.

Parameters
pathGuest path of the module. Its file name is the module name.
Returns
The handle with a count of 1, 0 when the table cannot grow.

◆ CreateUserModule()

X_HANDLE rex::kernel::ModuleObject::CreateUserModule ( TitleRuntime & runtime)
static

Creates the KernelObject of a user module with its first handle.

Returns
The handle with a count of 1, 0 when the table cannot grow.

◆ FromHModule()

X_HANDLE rex::kernel::ModuleObject::FromHModule ( TitleRuntime & runtime,
void * hmodule )
static

Finds the module of an HMODULE.

Parameters
hmoduleThe host pointer of the loader data entry.
Returns
The module handle, 0 when the stored handle does not name a module.

◆ GetAlternateTitleIDs()

std::vector< u32 > rex::kernel::ModuleObject::GetAlternateTitleIDs ( ) const
overridevirtual

Lists the alternate title IDs of the XEX header of a user module.

Returns
The title IDs, empty when the module is not an XEX.

Implements rex::kernel::ILoadedModule.

◆ GetExportAddress() [1/2]

u32 rex::kernel::ModuleObject::GetExportAddress ( std::string_view export_name) const

Finds an exported function of a module by name.

Returns
The guest address, 0 when the module has no such export.

◆ GetExportAddress() [2/2]

u32 rex::kernel::ModuleObject::GetExportAddress ( TitleRuntime & owning_runtime,
u16 ordinal,
u32 caller_address = 0 )

Finds an exported function of a module. A kernel module returns a thunk.

Parameters
caller_addressThe guest address of the caller, used to key kernel thunks.
Returns
The guest address, 0 when the module has no such export.

◆ GetOptHeader() [1/2]

X_STATUS rex::kernel::ModuleObject::GetOptHeader ( const kernel::GuestAddressSpace * memory,
const XEXHeader * header,
XEXHeaderKey key,
u32 * out_header_guest_ptr )
static

Finds an optional header in an XEX header in memory and returns an address that the title can read.

Parameters
headerThe XEX header.
out_header_guest_ptrReceives the header value or the guest address of its data.
Returns
X_STATUS_SUCCESS, or X_STATUS_NOT_FOUND.

◆ GetOptHeader() [2/2]

X_STATUS rex::kernel::ModuleObject::GetOptHeader ( XEXHeaderKey key,
void ** out_ptr )
overridevirtual

Finds an optional XEX header. For host use only.

Parameters
out_ptrReceives the header value or a pointer to its data.
Returns
X_STATUS_SUCCESS, X_STATUS_NOT_FOUND, or X_STATUS_UNSUCCESSFUL for an ELF.

Implements rex::kernel::ILoadedModule.

◆ GetOptHeaderGuestAddress()

X_STATUS rex::kernel::ModuleObject::GetOptHeaderGuestAddress ( XEXHeaderKey key,
u32 * out_guest_address ) const
overridevirtual

Finds an optional XEX header the way RtlImageXexHeaderField does: the value for a key whose low byte is 0, otherwise the guest address of the field.

Parameters
keyThe header key.
out_guest_addressReceives the value or the guest address, 0 when absent.
Returns
X_STATUS_SUCCESS, X_STATUS_NOT_FOUND, or X_STATUS_UNSUCCESSFUL for an ELF.

Implements rex::kernel::ILoadedModule.

◆ GetPath()

const std::string & rex::kernel::ModuleObject::GetPath ( ) const
inlineoverridevirtual

Returns the absolute path of the file a user module was loaded from.

Implements rex::kernel::ILoadedModule.

◆ GetSection()

X_STATUS rex::kernel::ModuleObject::GetSection ( std::string_view section_name,
u32 * out_section_data,
u32 * out_section_size ) const
overridevirtual

Finds a resource section of a module.

Parameters
out_section_dataReceives the guest address of the section.
out_section_sizeReceives the size of the section.
Returns
X_STATUS_SUCCESS, X_STATUS_NOT_FOUND, or X_STATUS_UNSUCCESSFUL for a kernel module.

Implements rex::kernel::ILoadedModule.

◆ GetTitleID()

u32 rex::kernel::ModuleObject::GetTitleID ( ) const
overridevirtual

Returns the title ID of a user module, 0 when the module is not an XEX or has none.

Implements rex::kernel::ILoadedModule.

◆ GetVariable()

u32 rex::kernel::ModuleObject::GetVariable ( u16 ordinal) const
inline

Returns the address of a variable export, or 0 when the module never created the variable.

◆ GetXEX()

rex::kernel::XEXModule * rex::kernel::ModuleObject::GetXEX ( )

Returns the XEX image of a user module, null when the module is not an XEX.

◆ HandleFromHModule()

u32 rex::kernel::ModuleObject::HandleFromHModule ( void * hmodule)
static

Reads the handle that the loader data entry of an HMODULE holds.

Parameters
hmoduleThe host pointer of the loader data entry.

◆ InvalidateThunkCache()

void rex::kernel::ModuleObject::InvalidateThunkCache ( u32 lo,
u32 hi )

Erases the cached thunks whose guest address falls in a range.

Parameters
hiThe address after the last address of the range.

◆ IsNamed()

bool rex::kernel::ModuleObject::IsNamed ( std::string_view query) const

Reports whether a name matches the module.

Parameters
queryA path, a file name or a module name, compared case insensitively.
Returns
True when the query matches the path, the file name or the name of the module.

◆ LoadFromFile()

X_STATUS rex::kernel::ModuleObject::LoadFromFile ( TitleRuntime & owning_runtime,
std::string_view guest_path )

Loads a module image from a file and applies a sibling XEX patch when one exists.

Returns
X_STATUS_SUCCESS, or the status of the first step that failed.

◆ LoadFromMemory()

X_STATUS rex::kernel::ModuleObject::LoadFromMemory ( TitleRuntime & owning_runtime,
const void * addr,
size_t length )

Loads a module image from memory.

Returns
X_STATUS_PENDING for an XEX that needs its second load step, X_STATUS_SUCCESS for an ELF, or the failure status.

◆ OptHeader()

template<typename T>
X_STATUS rex::kernel::ModuleObject::OptHeader ( XEXHeaderKey key,
T * out_ptr )
inline

Finds an optional XEX header. For host use only.

Template Parameters
TThe type of the value the header holds.
Parameters
out_ptrReceives the header value or a pointer to its data.
Returns
X_STATUS_SUCCESS, X_STATUS_NOT_FOUND, or X_STATUS_UNSUCCESSFUL for an ELF.

◆ SetVariable()

void rex::kernel::ModuleObject::SetVariable ( u16 ordinal,
u32 address )
inline

Binds a variable export to the guest address that holds it.

◆ Unload()

X_STATUS rex::kernel::ModuleObject::Unload ( )

Unloads the image of a user module.

Returns
X_STATUS_SUCCESS, or X_STATUS_UNSUCCESSFUL when the image cannot be unloaded.

Member Data Documentation

◆ hmodule_ptr

u32 rex::kernel::ModuleObject::hmodule_ptr = 0

Guest address of the module X_LDR_DATA_TABLE_ENTRY, the HMODULE titles use.

◆ kernel

KernelModuleState rex::kernel::ModuleObject::kernel

State of a kernel module, unused for a user module.

◆ name

std::string rex::kernel::ModuleObject::name

Module name, the file name of path for a user module.

◆ path

std::string rex::kernel::ModuleObject::path

Absolute path of the file a user module was loaded from.

◆ processor_module

PropagateConst<std::unique_ptr<rex::kernel::GuestModule> > rex::kernel::ModuleObject::processor_module

Loaded XEX or ELF image of a user module, owned by this object, null until loaded.

◆ runtime

TitleRuntime* rex::kernel::ModuleObject::runtime

TitleRuntime that owns the module, used to free hmodule_ptr.

◆ type

ModuleType rex::kernel::ModuleObject::type

Selects whether kernel or user holds the state.

◆ user

UserModuleState rex::kernel::ModuleObject::user

State of a user module, unused for a kernel module.


The documentation for this struct was generated from the following file: