VERY experimental Nintendo Switch 2 emulator
C++
core: hle: kernel: k_memory_layout: Refresh.
bunneia6e1e61bd642
diff --git a/src/core/hle/kernel/k_memory_layout.cpp b/src/core/hle/kernel/k_memory_layout.cppindex 55dc296d0f..72c3ee4b78 100644--- a/src/core/hle/kernel/k_memory_layout.cpp+++ b/src/core/hle/kernel/k_memory_layout.cpp@@ -153,13 +153,9 @@ void KMemoryLayout::InitializeLinearMemoryRegionTrees(PAddr aligned_linear_phys_}}-size_t KMemoryLayout::GetResourceRegionSizeForInit() {- // Calculate resource region size based on whether we allow extra threads.- const bool use_extra_resources = KSystemControl::Init::ShouldIncreaseThreadResourceLimit();- size_t resource_region_size =- KernelResourceSize + (use_extra_resources ? KernelSlabHeapAdditionalSize : 0);-- return resource_region_size;+size_t KMemoryLayout::GetResourceRegionSizeForInit(bool use_extra_resource) {+ return KernelResourceSize + KSystemControl::SecureAppletMemorySize ++ (use_extra_resource ? KernelSlabHeapAdditionalSize + KernelPageBufferAdditionalSize : 0);}} // namespace Kerneldiff --git a/src/core/hle/kernel/k_memory_layout.h b/src/core/hle/kernel/k_memory_layout.hindex 884fc623a0..fd6e1d3e6b 100644--- a/src/core/hle/kernel/k_memory_layout.h+++ b/src/core/hle/kernel/k_memory_layout.h@@ -60,10 +60,12 @@ constexpr std::size_t KernelSlabHeapGapsSizeMax = 2_MiB - 64_KiB;constexpr std::size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSizeMax;// NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860.-constexpr std::size_t KernelSlabHeapAdditionalSize = 0x68000;+constexpr size_t KernelPageBufferHeapSize = 0x3E0000;+constexpr size_t KernelSlabHeapAdditionalSize = 0x148000;+constexpr size_t KernelPageBufferAdditionalSize = 0x33C000;-constexpr std::size_t KernelResourceSize =- KernelPageTableHeapSize + KernelInitialPageHeapSize + KernelSlabHeapSize;+constexpr std::size_t KernelResourceSize = KernelPageTableHeapSize + KernelInitialPageHeapSize ++ KernelSlabHeapSize + KernelPageBufferHeapSize;constexpr bool IsKernelAddressKey(VAddr key) {return KernelVirtualAddressSpaceBase <= key && key <= KernelVirtualAddressSpaceLast;@@ -168,6 +170,11 @@ public:KMemoryRegionType_VirtualDramKernelTraceBuffer));}+ const KMemoryRegion& GetSecureAppletMemoryRegion() {+ return Dereference(GetVirtualMemoryRegionTree().FindByType(+ KMemoryRegionType_VirtualDramKernelSecureAppletMemory));+ }+const KMemoryRegion& GetVirtualLinearRegion(VAddr address) const {return Dereference(FindVirtualLinear(address));}@@ -229,7 +236,7 @@ public:void InitializeLinearMemoryRegionTrees(PAddr aligned_linear_phys_start,VAddr linear_virtual_start);- static size_t GetResourceRegionSizeForInit();+ static size_t GetResourceRegionSizeForInit(bool use_extra_resource);auto GetKernelRegionExtents() const {return GetVirtualMemoryRegionTree().GetDerivedRegionExtents(KMemoryRegionType_Kernel);@@ -279,6 +286,10 @@ public:return GetPhysicalMemoryRegionTree().GetDerivedRegionExtents(KMemoryRegionType_DramKernelSlab);}+ auto GetKernelSecureAppletMemoryRegionPhysicalExtents() {+ return GetPhysicalMemoryRegionTree().GetDerivedRegionExtents(+ KMemoryRegionType_DramKernelSecureAppletMemory);+ }auto GetKernelPageTableHeapRegionPhysicalExtents() const {return GetPhysicalMemoryRegionTree().GetDerivedRegionExtents(KMemoryRegionType_DramKernelPtHeap);diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex fdc774e307..fc94cb22ce 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -454,6 +454,9 @@ struct KernelCore::Impl {ASSERT(memory_layout->GetVirtualMemoryRegionTree().Insert(misc_region_start, misc_region_size, KMemoryRegionType_KernelMisc));+ // Determine if we'll use extra thread resources.+ const bool use_extra_resources = KSystemControl::Init::ShouldIncreaseThreadResourceLimit();+// Setup the stack region.constexpr size_t StackRegionSize = 14_MiB;constexpr size_t StackRegionAlign = KernelAslrAlignment;@@ -464,7 +467,8 @@ struct KernelCore::Impl {stack_region_start, StackRegionSize, KMemoryRegionType_KernelStack));// Determine the size of the resource region.- const size_t resource_region_size = memory_layout->GetResourceRegionSizeForInit();+ const size_t resource_region_size =+ memory_layout->GetResourceRegionSizeForInit(use_extra_resources);// Determine the size of the slab region.const size_t slab_region_size =