From 7e39a7018f865b80082fb7bd53ad881a20af162c Mon Sep 17 00:00:00 2001 From: Gliniak <153369+Gliniak@users.noreply.github.com> Date: Tue, 31 Mar 2026 20:43:49 +0200 Subject: [PATCH] [Memory] Added heap offset to alignment guards - This was causing page deallocation on proper allocations --- src/xenia/memory.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index d3d101784..1d4f15597 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -980,7 +980,7 @@ bool BaseHeap::AllocFixed(uint32_t base_address, uint32_t size, uint32_t protect) { alignment = xe::round_up(alignment, page_size_); size = xe::align(size, alignment); - assert_true(base_address % alignment == 0); + assert_true((base_address + host_address_offset_) % alignment == 0); uint32_t page_count = get_page_count(size, page_size_); uint32_t start_page_number = (base_address - heap_base_) / page_size_; uint32_t end_page_number = start_page_number + page_count - 1; @@ -1691,8 +1691,8 @@ bool PhysicalHeap::Alloc(uint32_t size, uint32_t alignment, // Given the address we've reserved in the parent heap, pin that here. // Shouldn't be possible for it to be allocated already. - uint32_t address = heap_base_ + parent_address - parent_heap_start; - if (address % alignment != 0) { + const uint32_t address = heap_base_ + parent_address - parent_heap_start; + if ((address + host_address_offset_) % alignment != 0) { XELOGE( "PhysicalHeap::Alloc translated address {:08X} misaligned " "(alignment {:08X}, physical base offset {:08X})", @@ -1734,9 +1734,9 @@ bool PhysicalHeap::AllocFixed(uint32_t base_address, uint32_t size, // Given the address we've reserved in the parent heap, pin that here. // Shouldn't be possible for it to be allocated already. - uint32_t address = + const uint32_t address = heap_base_ + parent_base_address - GetPhysicalAddress(heap_base_); - if (address % alignment != 0) { + if ((address + host_address_offset_) % alignment != 0) { XELOGE( "PhysicalHeap::AllocFixed translated address {:08X} misaligned " "(alignment {:08X}, physical base offset {:08X})", @@ -1780,12 +1780,11 @@ bool PhysicalHeap::AllocRange(uint32_t low_address, uint32_t high_address, "PhysicalHeap::Alloc unable to alloc physical memory in parent heap"); return false; } - // Given the address we've reserved in the parent heap, pin that here. // Shouldn't be possible for it to be allocated already. - uint32_t address = + const uint32_t address = heap_base_ + parent_address - GetPhysicalAddress(heap_base_); - if (address % alignment != 0) { + if ((address + host_address_offset_) % alignment != 0) { XELOGE( "PhysicalHeap::AllocRange translated address {:08X} misaligned " "(alignment {:08X}, physical base offset {:08X})",