Improve libk handling
[ps4-sdk.git] / libPS4 / source / jit.c
blob4c19d9dfcf427f5bdae36435aef59a1ca9e4d557
1 #include "kernel.h"
2 #include "module.h"
3 #include "memory.h"
5 #include "jit.h"
7 int (*sceKernelJitCreateSharedMemory)(int flags, size_t size, int protection, int *destinationHandle);
8 int (*sceKernelJitCreateAliasOfSharedMemory)(int handle, int protection, int *destinationHandle);
9 int (*sceKernelJitMapSharedMemory)(int handle, int protection, void **destination);
11 void initJIT(void) {
12 RESOLVE(libKernelHandle, sceKernelJitCreateSharedMemory);
13 RESOLVE(libKernelHandle, sceKernelJitCreateAliasOfSharedMemory);
14 RESOLVE(libKernelHandle, sceKernelJitMapSharedMemory);
17 void allocateJIT(size_t size, void **executableAddress, void **writableAddress) {
18 int executableHandle;
19 int writableHandle;
21 sceKernelJitCreateSharedMemory(0, size, PROT_CPU_READ | PROT_CPU_WRITE | PROT_CPU_EXEC, &executableHandle);
22 sceKernelJitCreateAliasOfSharedMemory(executableHandle, PROT_CPU_READ | PROT_CPU_WRITE, &writableHandle);
24 *executableAddress = mmap(NULL, size, PROT_CPU_READ | PROT_CPU_EXEC, MAP_SHARED, executableHandle, 0);
26 //sceKernelJitMapSharedMemory(writableHandle, PROT_CPU_READ | PROT_CPU_WRITE, writableAddress);
27 *writableAddress = mmap(NULL, size, PROT_CPU_READ | PROT_CPU_WRITE, MAP_PRIVATE | MAP_TYPE, writableHandle, 0);