From 771cc143433a2173c6ab6c8373db9742bd7449b6 Mon Sep 17 00:00:00 2001 From: gibbed Date: Sat, 24 Aug 2019 09:48:27 -0500 Subject: [PATCH] [Kernel] Workaround for crash seen on N3 demo boot. Changes NtAllocateVirtualMemory so that it ignores specified page size when a base address is specified. Requires verification if this is desired behavior. --- src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc index 31061a697..bd31c8150 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc @@ -96,10 +96,18 @@ dword_result_t NtAllocateVirtualMemory(lpdword_t base_addr_ptr, XELOGW("Game setting EXECUTE bit on allocation"); } - // Adjust size. - uint32_t page_size = 4096; - if (alloc_type & X_MEM_LARGE_PAGES) { - page_size = 64 * 1024; + uint32_t page_size; + + if (*base_addr_ptr != 0) { + // TODO(gibbed): ignore specified page size when base address is specified. + auto heap = kernel_memory()->LookupHeap(*base_addr_ptr); + page_size = heap->page_size(); + } else { + // Adjust size. + page_size = 4096; + if (alloc_type & X_MEM_LARGE_PAGES) { + page_size = 64 * 1024; + } } // Round the base address down to the nearest page boundary.