Update outdated comments and naming in jit.h/c

This commit is contained in:
fincs 2020-04-27 13:46:55 +02:00
parent dbc4b759e2
commit b0494c1acb
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
2 changed files with 21 additions and 25 deletions

View File

@ -9,8 +9,8 @@
/// JIT implementation type. /// JIT implementation type.
typedef enum { typedef enum {
JitType_CodeMemory, ///< JIT supported using svcSetProcessMemoryPermission JitType_SetProcessMemoryPermission, ///< JIT supported using svcSetProcessMemoryPermission
JitType_JitMemory, ///< JIT supported using [4.0.0+] code-memory syscalls (this isn't usable on [5.0.0+] so JitType_CodeMemory is used instead). JitType_CodeMemory, ///< JIT supported using [4.0.0+] CodeMemory syscalls
} JitType; } JitType;
/// JIT buffer object. /// JIT buffer object.
@ -58,11 +58,15 @@ Result jitClose(Jit* j);
* @param j JIT buffer. * @param j JIT buffer.
* @return Pointer to alias of the JIT buffer that can be written to. * @return Pointer to alias of the JIT buffer that can be written to.
*/ */
void* jitGetRwAddr(Jit* j); NX_CONSTEXPR void* jitGetRwAddr(Jit* j) {
return j->rw_addr;
}
/** /**
* @brief Gets the address of the executable memory alias of a JIT buffer. * @brief Gets the address of the executable memory alias of a JIT buffer.
* @param j JIT buffer. * @param j JIT buffer.
* @return Pointer to alias of the JIT buffer that can be executed. * @return Pointer to alias of the JIT buffer that can be executed.
*/ */
void* jitGetRxAddr(Jit* j); NX_CONSTEXPR void* jitGetRxAddr(Jit* j) {
return j->rx_addr;
}

View File

@ -13,16 +13,16 @@ Result jitCreate(Jit* j, size_t size)
{ {
JitType type; JitType type;
// Use new jit primitive introduced in [4.0.0+], if available. // Use new CodeMemory object introduced in [4.0.0+], if available.
// Not usable with [5.0.0+] since svcMapJitMemory doesn't allow using that SVC under the same process which owns that object. // On [5.0.0+] this is only usable with a kernel patch, as svcControlCodeMemory now errors if it's used under the same process which owns the object.
if (kernelAbove400() && envIsSyscallHinted(0x4B) && envIsSyscallHinted(0x4C) if (kernelAbove400() && envIsSyscallHinted(0x4B) && envIsSyscallHinted(0x4C)
&& (!kernelAbove500() || detectJitKernelPatch())) { && (!kernelAbove500() || detectJitKernelPatch())) {
type = JitType_JitMemory; type = JitType_CodeMemory;
} }
// Fall back to MapProcessCodeMemory if available. // Fall back to JitType_SetProcessMemoryPermission if available.
else if (envIsSyscallHinted(0x73) && envIsSyscallHinted(0x77) && envIsSyscallHinted(0x78) else if (envIsSyscallHinted(0x73) && envIsSyscallHinted(0x77) && envIsSyscallHinted(0x78)
&& (envGetOwnProcessHandle() != INVALID_HANDLE)) { && (envGetOwnProcessHandle() != INVALID_HANDLE)) {
type = JitType_CodeMemory; type = JitType_SetProcessMemoryPermission;
} }
else { else {
// Jit is unavailable. :( // Jit is unavailable. :(
@ -47,11 +47,11 @@ Result jitCreate(Jit* j, size_t size)
switch (j->type) switch (j->type)
{ {
case JitType_CodeMemory: case JitType_SetProcessMemoryPermission:
j->rw_addr = j->src_addr; j->rw_addr = j->src_addr;
break; break;
case JitType_JitMemory: case JitType_CodeMemory:
j->rw_addr = virtmemReserve(j->size); j->rw_addr = virtmemReserve(j->size);
rc = svcCreateCodeMemory(&j->handle, j->src_addr, j->size); rc = svcCreateCodeMemory(&j->handle, j->src_addr, j->size);
@ -95,11 +95,11 @@ Result jitTransitionToWritable(Jit* j)
Result rc = 0; Result rc = 0;
switch (j->type) { switch (j->type) {
case JitType_CodeMemory: case JitType_SetProcessMemoryPermission:
if (j->is_executable) rc = svcUnmapProcessCodeMemory(envGetOwnProcessHandle(), (u64) j->rx_addr, (u64) j->src_addr, j->size); if (j->is_executable) rc = svcUnmapProcessCodeMemory(envGetOwnProcessHandle(), (u64) j->rx_addr, (u64) j->src_addr, j->size);
break; break;
case JitType_JitMemory: case JitType_CodeMemory:
// No need to do anything. // No need to do anything.
break; break;
} }
@ -114,7 +114,7 @@ Result jitTransitionToExecutable(Jit* j)
Result rc = 0; Result rc = 0;
switch (j->type) { switch (j->type) {
case JitType_CodeMemory: case JitType_SetProcessMemoryPermission:
if (!j->is_executable) { if (!j->is_executable) {
rc = svcMapProcessCodeMemory(envGetOwnProcessHandle(), (u64) j->rx_addr, (u64) j->src_addr, j->size); rc = svcMapProcessCodeMemory(envGetOwnProcessHandle(), (u64) j->rx_addr, (u64) j->src_addr, j->size);
@ -128,7 +128,7 @@ Result jitTransitionToExecutable(Jit* j)
} }
break; break;
case JitType_JitMemory: case JitType_CodeMemory:
armDCacheFlush(j->rw_addr, j->size); armDCacheFlush(j->rw_addr, j->size);
armICacheInvalidate(j->rx_addr, j->size); armICacheInvalidate(j->rx_addr, j->size);
break; break;
@ -145,7 +145,7 @@ Result jitClose(Jit* j)
switch (j->type) switch (j->type)
{ {
case JitType_CodeMemory: case JitType_SetProcessMemoryPermission:
rc = jitTransitionToWritable(j); rc = jitTransitionToWritable(j);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
@ -153,7 +153,7 @@ Result jitClose(Jit* j)
} }
break; break;
case JitType_JitMemory: case JitType_CodeMemory:
rc = svcControlCodeMemory(j->handle, CodeMapOperation_UnmapOwner, j->rw_addr, j->size, 0); rc = svcControlCodeMemory(j->handle, CodeMapOperation_UnmapOwner, j->rw_addr, j->size, 0);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
@ -177,11 +177,3 @@ Result jitClose(Jit* j)
} }
return rc; return rc;
} }
void* jitGetRwAddr(Jit* j) {
return j->rw_addr;
}
void* jitGetRxAddr(Jit* j) {
return j->rx_addr;
}