Skip to content

Commit

Permalink
JIT memory protection fixes for jailed devices
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamLCobb committed May 2, 2016
1 parent dd6b6cf commit 9fa9120
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions desmume/src/ArmLJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7112,8 +7112,13 @@ TEMPLATE static void armcpu_compileblock(BlockInfo &blockinfo, bool runblock)
return;
}
}

uintptr_t opfun = (uintptr_t)jit_set_ip(ptr).ptr;
uintptr_t opfun = (uintptr_t)jit_set_ip(ptr).ptr;

// Protect region for writing -Will
// uintptr_t * opPtr = (uintptr_t*)opfun;
// opPtr = (uintptr_t *)((uintptr_t)opPtr & 0xFFFFF000); //Assuming page size is 4096
// mprotect(opPtr, 4096 * 2, PROT_WRITE);
//

s_pRegisterMap->Start(NULL, GETCPUPTR);

Expand Down Expand Up @@ -7334,6 +7339,9 @@ TEMPLATE static void armcpu_compileblock(BlockInfo &blockinfo, bool runblock)
//}

JITLUT_HANDLE(Address, PROCNUM) = opfun;

// Reprotect page for execution
//mprotect(opPtr, 4096 * 2, PROT_READ | PROT_EXEC);

u8* ptr_end = (u8*)jit_get_ip().ptr;
u32 used_size = (u8*)ptr_end - (u8*)ptr;
Expand Down Expand Up @@ -7452,26 +7460,17 @@ u32 *p;
bool ready;

#define PAGESIZE 4096
uintptr_t * opPtr;


TEMPLATE static u32 cpuExecuteLJIT()
{
ArmOpCompiled opfun = (ArmOpCompiled)JITLUT_HANDLE(ARMPROC.instruct_adr, PROCNUM);
if (!opfun) {
if (opPtr) {
//Reprotect old page
}
opfun = armcpu_compile<PROCNUM>();
if (!opfun)
printf("Unable to compile JIT\n");
}

opPtr = (uintptr_t*)opfun;
opPtr = (uintptr_t *)((uintptr_t)opPtr & 0xFFFFF000); //Assuming page size is 4096
mprotect(opPtr, PAGESIZE* 2, PROT_READ | PROT_EXEC);
u32 cycles = opfun();
mprotect(opPtr, PAGESIZE * 2, PROT_WRITE);
return cycles;
return opfun();
}

static u32 cpuGetCacheReserve()
Expand Down

0 comments on commit 9fa9120

Please sign in to comment.