diff options
| author | 2021-04-13 21:08:59 -0700 | |
|---|---|---|
| committer | 2021-04-13 21:08:59 -0700 | |
| commit | bb922d6ff62e3acbc7929cafa25686e314bb51cc (patch) | |
| tree | f9cee211b7d444af5842f412488bb2766544112b /src/core/hle/kernel/kernel.cpp | |
| parent | Merge pull request #6191 from lioncash/vdtor (diff) | |
| parent | kernel/process: Replace process resource limit instance with the kernel's res... (diff) | |
| download | yuzu-bb922d6ff62e3acbc7929cafa25686e314bb51cc.tar.gz yuzu-bb922d6ff62e3acbc7929cafa25686e314bb51cc.tar.xz yuzu-bb922d6ff62e3acbc7929cafa25686e314bb51cc.zip | |
Merge pull request #6185 from ameerj/process-reslimit
kernel/process: Replace process resource limit instance with the kernel's resource limit
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 8fd990577..f7d3f218a 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -67,8 +67,13 @@ struct KernelCore::Impl { | |||
| 67 | is_phantom_mode_for_singlecore = false; | 67 | is_phantom_mode_for_singlecore = false; |
| 68 | 68 | ||
| 69 | InitializePhysicalCores(); | 69 | InitializePhysicalCores(); |
| 70 | InitializeSystemResourceLimit(kernel, system); | 70 | |
| 71 | InitializeMemoryLayout(); | 71 | // Derive the initial memory layout from the emulated board |
| 72 | KMemoryLayout memory_layout; | ||
| 73 | DeriveInitialMemoryLayout(memory_layout); | ||
| 74 | InitializeMemoryLayout(memory_layout); | ||
| 75 | InitializeSystemResourceLimit(kernel, system, memory_layout); | ||
| 76 | InitializeSlabHeaps(); | ||
| 72 | InitializeSchedulers(); | 77 | InitializeSchedulers(); |
| 73 | InitializeSuspendThreads(); | 78 | InitializeSuspendThreads(); |
| 74 | InitializePreemption(kernel); | 79 | InitializePreemption(kernel); |
| @@ -137,27 +142,32 @@ struct KernelCore::Impl { | |||
| 137 | } | 142 | } |
| 138 | 143 | ||
| 139 | // Creates the default system resource limit | 144 | // Creates the default system resource limit |
| 140 | void InitializeSystemResourceLimit(KernelCore& kernel, Core::System& system) { | 145 | void InitializeSystemResourceLimit(KernelCore& kernel, Core::System& system, |
| 146 | const KMemoryLayout& memory_layout) { | ||
| 141 | system_resource_limit = std::make_shared<KResourceLimit>(kernel, system); | 147 | system_resource_limit = std::make_shared<KResourceLimit>(kernel, system); |
| 148 | const auto [total_size, kernel_size] = memory_layout.GetTotalAndKernelMemorySizes(); | ||
| 142 | 149 | ||
| 143 | // If setting the default system values fails, then something seriously wrong has occurred. | 150 | // If setting the default system values fails, then something seriously wrong has occurred. |
| 144 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::PhysicalMemory, 0x100000000) | 151 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::PhysicalMemory, total_size) |
| 145 | .IsSuccess()); | 152 | .IsSuccess()); |
| 146 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Threads, 800).IsSuccess()); | 153 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Threads, 800).IsSuccess()); |
| 147 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Events, 900).IsSuccess()); | 154 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Events, 900).IsSuccess()); |
| 148 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::TransferMemory, 200) | 155 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::TransferMemory, 200) |
| 149 | .IsSuccess()); | 156 | .IsSuccess()); |
| 150 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Sessions, 1133).IsSuccess()); | 157 | ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Sessions, 1133).IsSuccess()); |
| 158 | system_resource_limit->Reserve(LimitableResource::PhysicalMemory, kernel_size); | ||
| 151 | 159 | ||
| 152 | // Derived from recent software updates. The kernel reserves 27MB | ||
| 153 | constexpr u64 kernel_size{0x1b00000}; | ||
| 154 | if (!system_resource_limit->Reserve(LimitableResource::PhysicalMemory, kernel_size)) { | ||
| 155 | UNREACHABLE(); | ||
| 156 | } | ||
| 157 | // Reserve secure applet memory, introduced in firmware 5.0.0 | 160 | // Reserve secure applet memory, introduced in firmware 5.0.0 |
| 158 | constexpr u64 secure_applet_memory_size{0x400000}; | 161 | constexpr u64 secure_applet_memory_size{Common::Size_4_MB}; |
| 159 | ASSERT(system_resource_limit->Reserve(LimitableResource::PhysicalMemory, | 162 | ASSERT(system_resource_limit->Reserve(LimitableResource::PhysicalMemory, |
| 160 | secure_applet_memory_size)); | 163 | secure_applet_memory_size)); |
| 164 | |||
| 165 | // This memory seems to be reserved on hardware, but is not reserved/used by yuzu. | ||
| 166 | // Likely Horizon OS reserved memory | ||
| 167 | // TODO(ameerj): Derive the memory rather than hardcode it. | ||
| 168 | constexpr u64 unknown_reserved_memory{0x2f896000}; | ||
| 169 | ASSERT(system_resource_limit->Reserve(LimitableResource::PhysicalMemory, | ||
| 170 | unknown_reserved_memory)); | ||
| 161 | } | 171 | } |
| 162 | 172 | ||
| 163 | void InitializePreemption(KernelCore& kernel) { | 173 | void InitializePreemption(KernelCore& kernel) { |
| @@ -531,11 +541,7 @@ struct KernelCore::Impl { | |||
| 531 | linear_region_start); | 541 | linear_region_start); |
| 532 | } | 542 | } |
| 533 | 543 | ||
| 534 | void InitializeMemoryLayout() { | 544 | void InitializeMemoryLayout(const KMemoryLayout& memory_layout) { |
| 535 | // Derive the initial memory layout from the emulated board | ||
| 536 | KMemoryLayout memory_layout; | ||
| 537 | DeriveInitialMemoryLayout(memory_layout); | ||
| 538 | |||
| 539 | const auto system_pool = memory_layout.GetKernelSystemPoolRegionPhysicalExtents(); | 545 | const auto system_pool = memory_layout.GetKernelSystemPoolRegionPhysicalExtents(); |
| 540 | const auto applet_pool = memory_layout.GetKernelAppletPoolRegionPhysicalExtents(); | 546 | const auto applet_pool = memory_layout.GetKernelAppletPoolRegionPhysicalExtents(); |
| 541 | const auto application_pool = memory_layout.GetKernelApplicationPoolRegionPhysicalExtents(); | 547 | const auto application_pool = memory_layout.GetKernelApplicationPoolRegionPhysicalExtents(); |
| @@ -578,11 +584,14 @@ struct KernelCore::Impl { | |||
| 578 | system.Kernel(), system.DeviceMemory(), nullptr, {time_phys_addr, time_size / PageSize}, | 584 | system.Kernel(), system.DeviceMemory(), nullptr, {time_phys_addr, time_size / PageSize}, |
| 579 | KMemoryPermission::None, KMemoryPermission::Read, time_phys_addr, time_size, | 585 | KMemoryPermission::None, KMemoryPermission::Read, time_phys_addr, time_size, |
| 580 | "Time:SharedMemory"); | 586 | "Time:SharedMemory"); |
| 587 | } | ||
| 581 | 588 | ||
| 589 | void InitializeSlabHeaps() { | ||
| 582 | // Allocate slab heaps | 590 | // Allocate slab heaps |
| 583 | user_slab_heap_pages = std::make_unique<KSlabHeap<Page>>(); | 591 | user_slab_heap_pages = std::make_unique<KSlabHeap<Page>>(); |
| 584 | 592 | ||
| 585 | constexpr u64 user_slab_heap_size{0x1ef000}; | 593 | // TODO(ameerj): This should be derived, not hardcoded within the kernel |
| 594 | constexpr u64 user_slab_heap_size{0x3de000}; | ||
| 586 | // Reserve slab heaps | 595 | // Reserve slab heaps |
| 587 | ASSERT( | 596 | ASSERT( |
| 588 | system_resource_limit->Reserve(LimitableResource::PhysicalMemory, user_slab_heap_size)); | 597 | system_resource_limit->Reserve(LimitableResource::PhysicalMemory, user_slab_heap_size)); |