From 49b5860f0f3345362ef0e86621443d006e1e3cad Mon Sep 17 00:00:00 2001 From: RSDuck Date: Wed, 9 Dec 2020 18:58:51 +0100 Subject: [PATCH] aligned_alloc instead of memalign also carry over new Switch changes --- src/ARMJIT_A64/ARMJIT_Compiler.cpp | 18 +++++++++--------- src/ARMJIT_Memory.cpp | 25 ++++++++----------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index 93563b9e..5fe3fe77 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -1,5 +1,11 @@ +#include "ARMJIT_Compiler.h" + +#include "../ARMJIT_Internal.h" +#include "../ARMInterpreter.h" +#include "../Config.h" + #ifdef __SWITCH__ -#include "../switch/compat_switch.h" +#include extern char __start__; #else @@ -7,13 +13,7 @@ extern char __start__; #include #endif -#include "ARMJIT_Compiler.h" - -#include "../ARMJIT_Internal.h" -#include "../ARMInterpreter.h" -#include "../Config.h" - -#include +#include using namespace Arm64Gen; @@ -184,7 +184,7 @@ void Compiler::PopRegs(bool saveHiRegs) Compiler::Compiler() { #ifdef __SWITCH__ - JitRWBase = memalign(0x1000, JitMemSize); + JitRWBase = aligned_alloc(0x1000, JitMemSize); JitRXStart = (u8*)&__start__ - JitMemSize - 0x1000; JitRWStart = virtmemReserve(JitMemSize); diff --git a/src/ARMJIT_Memory.cpp b/src/ARMJIT_Memory.cpp index f9f82aa6..ffc294f6 100644 --- a/src/ARMJIT_Memory.cpp +++ b/src/ARMJIT_Memory.cpp @@ -1,5 +1,6 @@ #if defined(__SWITCH__) -#include "switch/compat_switch.h" +#include +#include "frontend/switch/FaultHandler.h" #elif defined(_WIN32) #include #else @@ -28,9 +29,7 @@ #include "NDSCart.h" #include "SPU.h" -#ifndef __APPLE__ -#include -#endif +#include /* We're handling fastmem here. @@ -97,22 +96,14 @@ void __libnx_exception_handler(ThreadExceptionDump* ctx) integerRegisters[31] = ctx->sp.x; integerRegisters[32] = ctx->pc.x; - if (ARMJIT_Memory::FaultHandler(desc, offset)) + if (ARMJIT_Memory::FaultHandler(desc)) { integerRegisters[32] = (u64)desc.FaultPC; ARM_RestoreContext(integerRegisters); } - if (ctx->pc.x >= (u64)&__start__ && ctx->pc.x < (u64)&__rodata_start) - { - printf("unintentional fault in .text at 0x%x (type %d) (trying to access 0x%x?)\n", - ctx->pc.x - (u64)&__start__, ctx->error_desc, ctx->far.x); - } - else - { - printf("unintentional fault somewhere in deep (address) space at %x (type %d)\n", ctx->pc.x, ctx->error_desc); - } + HandleFault(ctx->pc.x, ctx->lr.x, ctx->fp.x, ctx->far.x, ctx->error_desc); } } @@ -670,12 +661,12 @@ bool FaultHandler(FaultDescription& faultDesc) return false; } +const u64 AddrSpaceSize = 0x100000000; + void Init() { - const u64 AddrSpaceSize = 0x100000000; - #if defined(__SWITCH__) - MemoryBase = (u8*)memalign(0x1000, MemoryTotalSize); + MemoryBase = (u8*)aligned_alloc(0x1000, MemoryTotalSize); MemoryBaseCodeMem = (u8*)virtmemReserve(MemoryTotalSize); bool succeded = R_SUCCEEDED(svcMapProcessCodeMemory(envGetOwnProcessHandle(), (u64)MemoryBaseCodeMem,