15 //#include "3ds_utils.h"
17 #define PROT_READ 0b001
18 #define PROT_WRITE 0b010
19 #define PROT_EXEC 0b100
21 #define MAP_FIXED 0x10
22 #define MAP_ANONYMOUS 0x20
24 #define MAP_FAILED ((void *)-1)
26 static void* dynarec_cache = NULL;
27 static void* dynarec_cache_mapping = NULL;
29 static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
35 Result rc = svcMapPhysicalMemory(addr, len);
38 printf("mmap failed\n");
44 // if((prot == (PROT_READ | PROT_WRITE | PROT_EXEC)) &&
45 // (flags == (MAP_PRIVATE | MAP_ANONYMOUS)))
47 // if(true)// __ctr_svchax)
49 // /* this hack works only for pcsx_rearmed */
50 // uint32_t currentHandle;
53 // dynarec_cache = memalign(0x1000, len);
55 // //svcDuplicateHandle(¤tHandle, 0xFFFF8001);
56 // //svcControlProcessMemory(currentHandle, addr, dynarec_cache,
57 // // len, MEMOP_MAP, prot);
58 // svcCloseHandle(currentHandle);
59 // dynarec_cache_mapping = addr;
64 // printf("tried to mmap RWX pages without svcControlProcessMemory access !\n");
70 // addr_out = memalign(0x1000, len);
77 static inline int mprotect(void *addr, size_t len, int prot)
80 //if(true) // __ctr_svchax)
82 // uint32_t currentHandle;
83 // //svcDuplicateHandle(¤tHandle, 0xFFFF8001);
84 // //svcControlProcessMemory(currentHandle, addr, NULL,
85 // // len, MEMOP_PROT, prot);
86 // svcCloseHandle(currentHandle);
90 //printf("mprotect called without svcControlProcessMemory access !\n");
94 static inline int munmap(void *addr, size_t len)
96 Result rc = svcUnmapPhysicalMemory(addr, len);
99 printf("munmap failed\n");
103 // if((addr == dynarec_cache_mapping) && true)//__ctr_svchax)
105 // uint32_t currentHandle;
106 // //svcDuplicateHandle(¤tHandle, 0xFFFF8001);
107 // //svcControlProcessMemory(currentHandle,
108 // // dynarec_cache, dynarec_cache_mapping,
109 // // len, MEMOP_UNMAP, 0b111);
110 // svcCloseHandle(currentHandle);
111 // dynarec_cache_mapping = NULL;