wut  v1.5.0
Wii U Toolchain
Typedefs | Enumerations | Functions
Codegen

Controls a memory area that can switch between writable and executable states, allowing dynamic code generation. More...

Collaboration diagram for Codegen:

Typedefs

typedef enum OSCodegenSecMode OSCodegenSecMode
 The memory permissions for the codegen area. More...
 

Enumerations

enum  OSCodegenSecMode {
  CODEGEN_RW_ = 0 ,
  CODEGEN_R_X = 1
}
 The memory permissions for the codegen area. More...
 

Functions

void OSCodegenGetVirtAddrRange (uint32_t *outVirtualAddress, uint32_t *outSize)
 Gets the location and size of codegen memory, if available. More...
 
uint32_t OSGetCodegenCore ()
 Gets the CPU core that's allowed to use codegen. More...
 
uint32_t OSGetCodegenMode ()
 
BOOL OSSwitchSecCodeGenMode (OSCodegenSecMode mode)
 Switches the permissions on the codegen memory area. More...
 
uint32_t OSGetSecCodeGenMode ()
 
BOOL OSCodegenCopy (void *dst, void *src, size_t size)
 Copies data from normal memory into the codegen area, leaving the area in CODEGEN_R_X mode. More...
 
void OSGetCodegenVirtAddrRange (void **outAddr, uint32_t *size)
 

Detailed Description

Controls a memory area that can switch between writable and executable states, allowing dynamic code generation.

For some applications, a codegen area is avilable for things like JIT or otherwise generating CPU instructions on the fly. Enabled apps can use OSCodegenGetVirtAddrRange to discover this area, then use OSSwitchSecCodeGenMode or OSCodegenCopy to move instructions in and out before executing them. Codegen can only be used from a specific, predetermined CPU core - see OSGetCodegenCore. Codegen can only be used when enabled in an app's cos.xml.

Typedef Documentation

◆ OSCodegenSecMode

The memory permissions for the codegen area.

Enumeration Type Documentation

◆ OSCodegenSecMode

The memory permissions for the codegen area.

Enumerator
CODEGEN_RW_ 

The area can be read or written to, but not executed.

CODEGEN_R_X 

The area can be read or executed, but not written to.

Definition at line 33 of file codegen.h.

Function Documentation

◆ OSCodegenGetVirtAddrRange()

void OSCodegenGetVirtAddrRange ( uint32_t *  outVirtualAddress,
uint32_t *  outSize 
)

Gets the location and size of codegen memory, if available.

Parameters
outVirtualAddressPointer to write the virtual address of the codegen area to. Will write 0 if codegen isn't available.
outSizePointer to write the size of the codegen area to. Will write 0 if codegen isn't available.
See also

◆ OSGetCodegenCore()

uint32_t OSGetCodegenCore ( )

Gets the CPU core that's allowed to use codegen.

Returns
The core id of the core that can use codegen.
See also

◆ OSGetCodegenMode()

uint32_t OSGetCodegenMode ( )

◆ OSSwitchSecCodeGenMode()

BOOL OSSwitchSecCodeGenMode ( OSCodegenSecMode  mode)

Switches the permissions on the codegen memory area.

Use this function to move between writing code and executing it.

Parameters
modeThe memory permission mode to use - one of OSCodegenSecMode.
Returns
true on success, or false on a failure, such as codegen not being available for this app or CPU core.

◆ OSGetSecCodeGenMode()

uint32_t OSGetSecCodeGenMode ( )

◆ OSCodegenCopy()

BOOL OSCodegenCopy ( void *  dst,
void *  src,
size_t  size 
)

Copies data from normal memory into the codegen area, leaving the area in CODEGEN_R_X mode.

This function copies into the codegen area regardless of the current permission status by switching modes as required for the copy.

Parameters
dstThe starting virtual address of the area in codegen memory to copy to. Must be a valid pointer
srcThe starting virtual address of the source to copy from. Must be a valid pointer.
sizeThe size of the data to copy. Must not be 0, and must be small enough such that dst + size does not pass the end of the codegen area (see OSCodegenGetVirtAddrRange).
Returns
TRUE on success, indicating the codegen area is now in CODEGEN_R_X, or FALSE on an error, such as invalid pointers or codegen not being available.

◆ OSGetCodegenVirtAddrRange()

void OSGetCodegenVirtAddrRange ( void **  outAddr,
uint32_t *  size 
)