summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/hle/kernel/k_memory_layout.cpp10
-rw-r--r--src/core/hle/kernel/k_memory_layout.h19
-rw-r--r--src/core/hle/kernel/kernel.cpp6
3 files changed, 23 insertions, 12 deletions
diff --git a/src/core/hle/kernel/k_memory_layout.cpp b/src/core/hle/kernel/k_memory_layout.cpp
index 55dc296d0..72c3ee4b7 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_
153 } 153 }
154} 154}
155 155
156size_t KMemoryLayout::GetResourceRegionSizeForInit() { 156size_t KMemoryLayout::GetResourceRegionSizeForInit(bool use_extra_resource) {
157 // Calculate resource region size based on whether we allow extra threads. 157 return KernelResourceSize + KSystemControl::SecureAppletMemorySize +
158 const bool use_extra_resources = KSystemControl::Init::ShouldIncreaseThreadResourceLimit(); 158 (use_extra_resource ? KernelSlabHeapAdditionalSize + KernelPageBufferAdditionalSize : 0);
159 size_t resource_region_size =
160 KernelResourceSize + (use_extra_resources ? KernelSlabHeapAdditionalSize : 0);
161
162 return resource_region_size;
163} 159}
164 160
165} // namespace Kernel 161} // namespace Kernel
diff --git a/src/core/hle/kernel/k_memory_layout.h b/src/core/hle/kernel/k_memory_layout.h
index 884fc623a..fd6e1d3e6 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;
60constexpr std::size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSizeMax; 60constexpr std::size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSizeMax;
61 61
62// NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860. 62// NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860.
63constexpr std::size_t KernelSlabHeapAdditionalSize = 0x68000; 63constexpr size_t KernelPageBufferHeapSize = 0x3E0000;
64constexpr size_t KernelSlabHeapAdditionalSize = 0x148000;
65constexpr size_t KernelPageBufferAdditionalSize = 0x33C000;
64 66
65constexpr std::size_t KernelResourceSize = 67constexpr std::size_t KernelResourceSize = KernelPageTableHeapSize + KernelInitialPageHeapSize +
66 KernelPageTableHeapSize + KernelInitialPageHeapSize + KernelSlabHeapSize; 68 KernelSlabHeapSize + KernelPageBufferHeapSize;
67 69
68constexpr bool IsKernelAddressKey(VAddr key) { 70constexpr bool IsKernelAddressKey(VAddr key) {
69 return KernelVirtualAddressSpaceBase <= key && key <= KernelVirtualAddressSpaceLast; 71 return KernelVirtualAddressSpaceBase <= key && key <= KernelVirtualAddressSpaceLast;
@@ -168,6 +170,11 @@ public:
168 KMemoryRegionType_VirtualDramKernelTraceBuffer)); 170 KMemoryRegionType_VirtualDramKernelTraceBuffer));
169 } 171 }
170 172
173 const KMemoryRegion& GetSecureAppletMemoryRegion() {
174 return Dereference(GetVirtualMemoryRegionTree().FindByType(
175 KMemoryRegionType_VirtualDramKernelSecureAppletMemory));
176 }
177
171 const KMemoryRegion& GetVirtualLinearRegion(VAddr address) const { 178 const KMemoryRegion& GetVirtualLinearRegion(VAddr address) const {
172 return Dereference(FindVirtualLinear(address)); 179 return Dereference(FindVirtualLinear(address));
173 } 180 }
@@ -229,7 +236,7 @@ public:
229 236
230 void InitializeLinearMemoryRegionTrees(PAddr aligned_linear_phys_start, 237 void InitializeLinearMemoryRegionTrees(PAddr aligned_linear_phys_start,
231 VAddr linear_virtual_start); 238 VAddr linear_virtual_start);
232 static size_t GetResourceRegionSizeForInit(); 239 static size_t GetResourceRegionSizeForInit(bool use_extra_resource);
233 240
234 auto GetKernelRegionExtents() const { 241 auto GetKernelRegionExtents() const {
235 return GetVirtualMemoryRegionTree().GetDerivedRegionExtents(KMemoryRegionType_Kernel); 242 return GetVirtualMemoryRegionTree().GetDerivedRegionExtents(KMemoryRegionType_Kernel);
@@ -279,6 +286,10 @@ public:
279 return GetPhysicalMemoryRegionTree().GetDerivedRegionExtents( 286 return GetPhysicalMemoryRegionTree().GetDerivedRegionExtents(
280 KMemoryRegionType_DramKernelSlab); 287 KMemoryRegionType_DramKernelSlab);
281 } 288 }
289 auto GetKernelSecureAppletMemoryRegionPhysicalExtents() {
290 return GetPhysicalMemoryRegionTree().GetDerivedRegionExtents(
291 KMemoryRegionType_DramKernelSecureAppletMemory);
292 }
282 auto GetKernelPageTableHeapRegionPhysicalExtents() const { 293 auto GetKernelPageTableHeapRegionPhysicalExtents() const {
283 return GetPhysicalMemoryRegionTree().GetDerivedRegionExtents( 294 return GetPhysicalMemoryRegionTree().GetDerivedRegionExtents(
284 KMemoryRegionType_DramKernelPtHeap); 295 KMemoryRegionType_DramKernelPtHeap);
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index fdc774e30..fc94cb22c 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -454,6 +454,9 @@ struct KernelCore::Impl {
454 ASSERT(memory_layout->GetVirtualMemoryRegionTree().Insert( 454 ASSERT(memory_layout->GetVirtualMemoryRegionTree().Insert(
455 misc_region_start, misc_region_size, KMemoryRegionType_KernelMisc)); 455 misc_region_start, misc_region_size, KMemoryRegionType_KernelMisc));
456 456
457 // Determine if we'll use extra thread resources.
458 const bool use_extra_resources = KSystemControl::Init::ShouldIncreaseThreadResourceLimit();
459
457 // Setup the stack region. 460 // Setup the stack region.
458 constexpr size_t StackRegionSize = 14_MiB; 461 constexpr size_t StackRegionSize = 14_MiB;
459 constexpr size_t StackRegionAlign = KernelAslrAlignment; 462 constexpr size_t StackRegionAlign = KernelAslrAlignment;
@@ -464,7 +467,8 @@ struct KernelCore::Impl {
464 stack_region_start, StackRegionSize, KMemoryRegionType_KernelStack)); 467 stack_region_start, StackRegionSize, KMemoryRegionType_KernelStack));
465 468
466 // Determine the size of the resource region. 469 // Determine the size of the resource region.
467 const size_t resource_region_size = memory_layout->GetResourceRegionSizeForInit(); 470 const size_t resource_region_size =
471 memory_layout->GetResourceRegionSizeForInit(use_extra_resources);
468 472
469 // Determine the size of the slab region. 473 // Determine the size of the slab region.
470 const size_t slab_region_size = 474 const size_t slab_region_size =