From 02339164897fbf6a17f178fc46cb8f3ff76ed464 Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Tue, 2 Mar 2021 15:27:55 +0530 Subject: [PATCH] Increase Code Region Size to 4GiB The code region's size was previously set at the same value as it is for 36-bit ASes, this value is inadequate for certain larger games and needed to be expanded. We've chosen 4GiB as the new value which should easily encompass all Switch games. --- app/src/main/cpp/skyline/kernel/memory.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/skyline/kernel/memory.cpp b/app/src/main/cpp/skyline/kernel/memory.cpp index 965b38cd..a8b19321 100644 --- a/app/src/main/cpp/skyline/kernel/memory.cpp +++ b/app/src/main/cpp/skyline/kernel/memory.cpp @@ -13,6 +13,7 @@ namespace skyline::kernel { } constexpr size_t RegionAlignment{1ULL << 21}; //!< The minimum alignment of a HOS memory region + constexpr size_t CodeRegionSize{4ULL * 1024 * 1024 * 1024}; //!< The assumed maximum size of the code region (4GiB) void MemoryManager::InitializeVmm(memory::AddressSpaceType type) { switch (type) { @@ -30,7 +31,7 @@ namespace skyline::kernel { case memory::AddressSpaceType::AddressSpace39Bit: { addressSpace.address = 0; addressSpace.size = 1UL << 39; - base.size = 0x78000000 + 0x1000000000 + 0x180000000 + 0x80000000 + 0x1000000000; // Code region size is an assumed maximum here + base.size = CodeRegionSize + 0x1000000000 + 0x180000000 + 0x80000000 + 0x1000000000; break; } @@ -53,7 +54,7 @@ namespace skyline::kernel { start = util::HexStringToInt(std::string_view(maps.data() + maps.find_first_of('-', line) + 1, sizeof(u64) * 2)); alignedStart = util::AlignUp(start, RegionAlignment); - if (alignedStart + base.size > addressSpace.size) + if (alignedStart + base.size > addressSpace.size) // We don't want to map past the end of the address space break; } while ((line = maps.find_first_of('\n', line)) != std::string::npos && line++); @@ -121,7 +122,7 @@ namespace skyline::kernel { auto newSize{code.size + alias.size + stack.size + heap.size + ((addressSpace.size == 1UL << 39) ? tlsIo.size : 0)}; if (newSize > base.size) - throw exception("Region size has exceeded pre-allocated area: 0x{:X}/0x{:X}", newSize, base.size); + throw exception("Guest VMM size has exceeded host carveout size: 0x{:X}/0x{:X} (Code: 0x{:X}/0x{:X})", newSize, base.size, code.size, CodeRegionSize); if (newSize != base.size) munmap(reinterpret_cast(base.address) + base.size, newSize - base.size);