X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=frontend%2Fswitch%2Fsys%2Fmman.h;h=2e084a64e73bee7d05c464d9e34291ab6de235cf;hb=ebcd59b7ac1170dda42b7352ffdc1289f60ad174;hp=5e8d22efe90efed65efa4668b76dd3ee089264e1;hpb=3918505613cb814f8f5e0e8e0471f7b2a2cd8464;p=pcsx_rearmed.git diff --git a/frontend/switch/sys/mman.h b/frontend/switch/sys/mman.h index 5e8d22ef..2e084a64 100644 --- a/frontend/switch/sys/mman.h +++ b/frontend/switch/sys/mman.h @@ -6,13 +6,8 @@ extern "C" { #endif #include -#include -#include -#include +#include #include -#include - -//#include "3ds_utils.h" #define PROT_READ 0b001 #define PROT_WRITE 0b010 @@ -23,98 +18,38 @@ extern "C" { #define MAP_FAILED ((void *)-1) -static void* dynarec_cache = NULL; -static void* dynarec_cache_mapping = NULL; +#define ALIGNMENT 0x1000 -static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) +static inline void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { - (void)fd; - (void)offset; + (void)fd; + (void)offset; + + // match Linux behavior + len = (len + ALIGNMENT - 1) & ~(ALIGNMENT - 1); - //void* addr_out; Result rc = svcMapPhysicalMemory(addr, len); if (R_FAILED(rc)) { - printf("mmap failed\n"); - return malloc(len); + //printf("mmap failed\n"); + addr = aligned_alloc(ALIGNMENT, len); } - + if (!addr) + return MAP_FAILED; + memset(addr, 0, len); return addr; - -// if((prot == (PROT_READ | PROT_WRITE | PROT_EXEC)) && -// (flags == (MAP_PRIVATE | MAP_ANONYMOUS))) -// { -// if(true)// __ctr_svchax) -// { -// /* this hack works only for pcsx_rearmed */ -// uint32_t currentHandle; -// -// if(!dynarec_cache) -// dynarec_cache = memalign(0x1000, len); -// -// //svcDuplicateHandle(¤tHandle, 0xFFFF8001); -// //svcControlProcessMemory(currentHandle, addr, dynarec_cache, -// // len, MEMOP_MAP, prot); -// svcCloseHandle(currentHandle); -// dynarec_cache_mapping = addr; -// return addr; -// } -// else -// { -// printf("tried to mmap RWX pages without svcControlProcessMemory access !\n"); -// return MAP_FAILED; -// } -// -// } - -// addr_out = memalign(0x1000, len); -// if(!addr_out) -// return MAP_FAILED; -// -// return addr_out; -} - -static inline int mprotect(void *addr, size_t len, int prot) -{ - return 0; - //if(true) // __ctr_svchax) - //{ - // uint32_t currentHandle; - // //svcDuplicateHandle(¤tHandle, 0xFFFF8001); - // //svcControlProcessMemory(currentHandle, addr, NULL, - // // len, MEMOP_PROT, prot); - // svcCloseHandle(currentHandle); - // return 0; - //} - - //printf("mprotect called without svcControlProcessMemory access !\n"); - //return -1; } static inline int munmap(void *addr, size_t len) { + len = (len + ALIGNMENT - 1) & ~(ALIGNMENT - 1); Result rc = svcUnmapPhysicalMemory(addr, len); if (R_FAILED(rc)) { - printf("munmap failed\n"); + //printf("munmap failed\n"); free(addr); } return 0; -// if((addr == dynarec_cache_mapping) && true)//__ctr_svchax) -// { -// uint32_t currentHandle; -// //svcDuplicateHandle(¤tHandle, 0xFFFF8001); -// //svcControlProcessMemory(currentHandle, -// // dynarec_cache, dynarec_cache_mapping, -// // len, MEMOP_UNMAP, 0b111); -// svcCloseHandle(currentHandle); -// dynarec_cache_mapping = NULL; -// -// } -// else - free(addr); - - return 0; } #ifdef __cplusplus