From 844cc6e2ed8d288fd8ebca0aa03072f774c529d6 Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Wed, 8 Apr 2026 09:07:32 +0900 Subject: [PATCH] [Memory] Remove unnecessary 256MB carve-out from v00000000 virtual heap The 4KB-page virtual heap (v00000000, 0x00000000-0x3FFFFFFF) had 256MB reserved at its top end for thread stacks, but thread stacks only use the 64KB-page heap (v40000000) at 0x70000000-0x7F000000. This wasted 256MB of allocatable address space. Keep the carve-out only on the v40000000 heap where stacks actually reside. --- src/xenia/memory.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index f1a1e32f7..9c9b7af43 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -1044,17 +1044,12 @@ bool BaseHeap::Alloc(uint32_t size, uint32_t alignment, size = xe::round_up(size, page_size_); alignment = xe::round_up(alignment, page_size_); - // TODO(Gliniak): Find better way to deal with this! - // Because 0x3XXXXXX and 0x7XXXXXX is used strictly as place for thread stacks - // 0x3 is probably for system threads and 0x7 for title threads + // Exclude the top 240MB of the v40000000 heap (64KB guest pages) from + // general allocation to protect the thread stack region + // (0x70000000-0x7F000000) uint32_t heap_virtual_guest_offset = 0; - if (heap_type_ == HeapType::kGuestVirtual) { - heap_virtual_guest_offset = 0x10000000; - - // Adjust for 64k pages region, to prevent having a bit too little memory - if (page_size_ == 0x10000) { - heap_virtual_guest_offset = 0x0F000000; - } + if (heap_type_ == HeapType::kGuestVirtual && page_size_ == 0x10000) { + heap_virtual_guest_offset = 0x0F000000; } uint32_t low_address = heap_base_;