libnx v4.9.0
Loading...
Searching...
No Matches
jit.h
Go to the documentation of this file.
1/**
2 * @file jit.h
3 * @brief Just-in-time compilation support.
4 * @author plutoo
5 * @copyright libnx Authors
6 */
7#pragma once
8#include "../types.h"
9#include "virtmem.h"
10
11/// JIT implementation type.
12typedef enum {
13 JitType_SetProcessMemoryPermission, ///< JIT supported using svcSetProcessMemoryPermission
14 JitType_CodeMemory, ///< JIT supported using [4.0.0+] CodeMemory syscalls
15} JitType;
16
17/// JIT buffer object.
18typedef struct {
19 JitType type;
20 size_t size;
21 void* src_addr;
22 void* rx_addr;
23 void* rw_addr;
24 bool is_executable;
25 union {
26 Handle handle;
28 };
29} Jit;
30
31/**
32 * @brief Creates a JIT buffer.
33 * @param j JIT buffer.
34 * @param size Size of the JIT buffer.
35 * @return Result code.
36 */
37Result jitCreate(Jit* j, size_t size);
38
39/**
40 * @brief Transition a JIT buffer to have writable permission.
41 * @param j JIT buffer.
42 * @return Result code.
43 */
45
46/**
47 * @brief Transition a JIT buffer to have executable permission.
48 * @param j JIT buffer.
49 * @return Result code.
50 */
52
53/**
54 * @brief Destroys a JIT buffer.
55 * @param j JIT buffer.
56 * @return Result code.
57 */
59
60/**
61 * @brief Gets the address of the writable memory alias of a JIT buffer.
62 * @param j JIT buffer.
63 * @return Pointer to alias of the JIT buffer that can be written to.
64 */
66 return j->rw_addr;
67}
68
69/**
70 * @brief Gets the address of the executable memory alias of a JIT buffer.
71 * @param j JIT buffer.
72 * @return Pointer to alias of the JIT buffer that can be executed.
73 */
75 return j->rx_addr;
76}
Result jitCreate(Jit *j, size_t size)
Creates a JIT buffer.
static void * jitGetRxAddr(Jit *j)
Gets the address of the executable memory alias of a JIT buffer.
Definition jit.h:74
JitType
JIT implementation type.
Definition jit.h:12
@ JitType_SetProcessMemoryPermission
JIT supported using svcSetProcessMemoryPermission.
Definition jit.h:13
@ JitType_CodeMemory
JIT supported using [4.0.0+] CodeMemory syscalls.
Definition jit.h:14
Result jitTransitionToExecutable(Jit *j)
Transition a JIT buffer to have executable permission.
Result jitClose(Jit *j)
Destroys a JIT buffer.
Result jitTransitionToWritable(Jit *j)
Transition a JIT buffer to have writable permission.
static void * jitGetRwAddr(Jit *j)
Gets the address of the writable memory alias of a JIT buffer.
Definition jit.h:65
JIT buffer object.
Definition jit.h:18
u32 Handle
Kernel object handle.
Definition types.h:43
u32 Result
Function error code result type.
Definition types.h:44
#define NX_CONSTEXPR
Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
Definition types.h:92
Virtual memory mapping utilities.
struct VirtmemReservation VirtmemReservation
Address space reservation type (see virtmemAddReservation)
Definition virtmem.h:11