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.
◆ OSCodegenSecMode
The memory permissions for the codegen area.
◆ 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.
◆ OSCodegenGetVirtAddrRange()
void OSCodegenGetVirtAddrRange |
( |
uint32_t * |
outVirtualAddress, |
|
|
uint32_t * |
outSize |
|
) |
| |
Gets the location and size of codegen memory, if available.
- Parameters
-
outVirtualAddress | Pointer to write the virtual address of the codegen area to. Will write 0 if codegen isn't available. |
outSize | Pointer 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()
Switches the permissions on the codegen memory area.
Use this function to move between writing code and executing it.
- Parameters
-
- 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
-
dst | The starting virtual address of the area in codegen memory to copy to. Must be a valid pointer |
src | The starting virtual address of the source to copy from. Must be a valid pointer. |
size | The 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.