From: notaz Date: Mon, 18 Jul 2022 22:30:14 +0000 (+0300) Subject: mman: align and clear for 3ds also X-Git-Tag: r24l~442 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5dbff29e1f0ab4dac9a84e950f91a07f971944a9;p=pcsx_rearmed.git mman: align and clear for 3ds also callers expect cleared mem --- diff --git a/frontend/3ds/sys/mman.h b/frontend/3ds/sys/mman.h index 61dde6c2..fdf5ac6a 100644 --- a/frontend/3ds/sys/mman.h +++ b/frontend/3ds/sys/mman.h @@ -7,6 +7,7 @@ extern "C" { #include #include +#include #include #include @@ -39,14 +40,18 @@ static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, of /* this hack works only for pcsx_rearmed */ uint32_t currentHandle; - if(!dynarec_cache) + if (!dynarec_cache) { dynarec_cache = memalign(0x1000, len); + if (!dynarec_cache) + return MAP_FAILED; + } svcDuplicateHandle(¤tHandle, 0xFFFF8001); svcControlProcessMemory(currentHandle, addr, dynarec_cache, len, MEMOP_MAP, prot); svcCloseHandle(currentHandle); dynarec_cache_mapping = addr; + memset(addr, 0, len); return addr; } else @@ -57,10 +62,11 @@ static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, of } - addr_out = malloc(len); - if(!addr_out) + addr_out = memalign(0x1000, len); + if (!addr_out) return MAP_FAILED; + memset(addr_out, 0, len); return addr_out; } diff --git a/frontend/switch/sys/mman.h b/frontend/switch/sys/mman.h index 49fb4454..2e084a64 100644 --- a/frontend/switch/sys/mman.h +++ b/frontend/switch/sys/mman.h @@ -34,9 +34,9 @@ static inline void *mmap(void *addr, size_t len, int prot, int flags, int fd, of //printf("mmap failed\n"); addr = aligned_alloc(ALIGNMENT, len); } - - if (addr) - memset(addr, 0, len); + if (!addr) + return MAP_FAILED; + memset(addr, 0, len); return addr; }