From 5dbff29e1f0ab4dac9a84e950f91a07f971944a9 Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 19 Jul 2022 01:30:14 +0300 Subject: [PATCH] mman: align and clear for 3ds also callers expect cleared mem --- frontend/3ds/sys/mman.h | 12 +++++++++--- frontend/switch/sys/mman.h | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) 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; } -- 2.39.2