From 79787e7dce6b60e8e4fc01fad5fc2e9dba51b2e8 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 12 Feb 2022 20:11:54 +0100 Subject: [PATCH] The allocated size is now always an integral multiple of alignment. --- source/memory_mapping.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/source/memory_mapping.cpp b/source/memory_mapping.cpp index e24dfb7..aaa1ac4 100644 --- a/source/memory_mapping.cpp +++ b/source/memory_mapping.cpp @@ -395,9 +395,6 @@ void MemoryMapping_setupMemoryMapping() { OSInitMutex(&allocMutex); } -#define ROUNDDOWN(val, align) ((val) & ~(align - 1)) -#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align) - void *MemoryMapping_allocEx(uint32_t size, int32_t align, bool videoOnly) { OSLockMutex(&allocMutex); void *res = nullptr; @@ -414,10 +411,7 @@ void *MemoryMapping_allocEx(uint32_t size, int32_t align, bool videoOnly) { continue; } - // We round up the size to avoid heap corruption. - // FSReadFile expects the buffer size to be a multiple of 0x40 - // This can remove once all modules/plugins have been updated :) - res = MEMAllocFromExpHeapEx(heapHandle, ROUNDUP(size, 0x40), align); + res = MEMAllocFromExpHeapEx(heapHandle, (size + align - 1) & ~(align - 1), align); if (res != nullptr) { break; }