diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/k_resource_limit.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_resource_limit.h | 12 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 2 |
4 files changed, 13 insertions, 21 deletions
diff --git a/src/core/hle/kernel/k_resource_limit.cpp b/src/core/hle/kernel/k_resource_limit.cpp index d7a4a38e6..d05b34ea3 100644 --- a/src/core/hle/kernel/k_resource_limit.cpp +++ b/src/core/hle/kernel/k_resource_limit.cpp | |||
| @@ -2,21 +2,16 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | // This file references various implementation details from Atmosphere, an open-source firmware for | ||
| 6 | // the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX. | ||
| 7 | |||
| 8 | #include "common/assert.h" | 5 | #include "common/assert.h" |
| 9 | #include "core/core.h" | ||
| 10 | #include "core/core_timing.h" | 6 | #include "core/core_timing.h" |
| 11 | #include "core/core_timing_util.h" | ||
| 12 | #include "core/hle/kernel/k_resource_limit.h" | 7 | #include "core/hle/kernel/k_resource_limit.h" |
| 13 | #include "core/hle/kernel/svc_results.h" | 8 | #include "core/hle/kernel/svc_results.h" |
| 14 | 9 | ||
| 15 | namespace Kernel { | 10 | namespace Kernel { |
| 16 | constexpr s64 DefaultTimeout = 10000000000; // 10 seconds | 11 | constexpr s64 DefaultTimeout = 10000000000; // 10 seconds |
| 17 | 12 | ||
| 18 | KResourceLimit::KResourceLimit(KernelCore& kernel, Core::System& system) | 13 | KResourceLimit::KResourceLimit(KernelCore& kernel, const Core::Timing::CoreTiming& core_timing_) |
| 19 | : Object{kernel}, lock{kernel}, cond_var{kernel}, kernel{kernel}, system(system) {} | 14 | : Object{kernel}, lock{kernel}, cond_var{kernel}, core_timing(core_timing_) {} |
| 20 | KResourceLimit::~KResourceLimit() = default; | 15 | KResourceLimit::~KResourceLimit() = default; |
| 21 | 16 | ||
| 22 | s64 KResourceLimit::GetLimitValue(LimitableResource which) const { | 17 | s64 KResourceLimit::GetLimitValue(LimitableResource which) const { |
| @@ -83,7 +78,7 @@ ResultCode KResourceLimit::SetLimitValue(LimitableResource which, s64 value) { | |||
| 83 | } | 78 | } |
| 84 | 79 | ||
| 85 | bool KResourceLimit::Reserve(LimitableResource which, s64 value) { | 80 | bool KResourceLimit::Reserve(LimitableResource which, s64 value) { |
| 86 | return Reserve(which, value, system.CoreTiming().GetGlobalTimeNs().count() + DefaultTimeout); | 81 | return Reserve(which, value, core_timing.GetGlobalTimeNs().count() + DefaultTimeout); |
| 87 | } | 82 | } |
| 88 | 83 | ||
| 89 | bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) { | 84 | bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) { |
| @@ -114,7 +109,7 @@ bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) { | |||
| 114 | } | 109 | } |
| 115 | 110 | ||
| 116 | if (current_hints[index] + value <= limit_values[index] && | 111 | if (current_hints[index] + value <= limit_values[index] && |
| 117 | (timeout < 0 || system.CoreTiming().GetGlobalTimeNs().count() < timeout)) { | 112 | (timeout < 0 || core_timing.GetGlobalTimeNs().count() < timeout)) { |
| 118 | waiter_count++; | 113 | waiter_count++; |
| 119 | cond_var.Wait(&lock, timeout); | 114 | cond_var.Wait(&lock, timeout); |
| 120 | waiter_count--; | 115 | waiter_count--; |
diff --git a/src/core/hle/kernel/k_resource_limit.h b/src/core/hle/kernel/k_resource_limit.h index 58ae456f1..4542317d0 100644 --- a/src/core/hle/kernel/k_resource_limit.h +++ b/src/core/hle/kernel/k_resource_limit.h | |||
| @@ -2,9 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | // This file references various implementation details from Atmosphere, an open-source firmware for | ||
| 6 | // the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX. | ||
| 7 | |||
| 8 | #pragma once | 5 | #pragma once |
| 9 | 6 | ||
| 10 | #include <array> | 7 | #include <array> |
| @@ -15,8 +12,8 @@ | |||
| 15 | 12 | ||
| 16 | union ResultCode; | 13 | union ResultCode; |
| 17 | 14 | ||
| 18 | namespace Core { | 15 | namespace Core::Timing { |
| 19 | class System; | 16 | class CoreTiming; |
| 20 | } | 17 | } |
| 21 | 18 | ||
| 22 | namespace Kernel { | 19 | namespace Kernel { |
| @@ -37,7 +34,7 @@ constexpr bool IsValidResourceType(LimitableResource type) { | |||
| 37 | 34 | ||
| 38 | class KResourceLimit final : public Object { | 35 | class KResourceLimit final : public Object { |
| 39 | public: | 36 | public: |
| 40 | explicit KResourceLimit(KernelCore& kernel, Core::System& system); | 37 | explicit KResourceLimit(KernelCore& kernel, const Core::Timing::CoreTiming& core_timing_); |
| 41 | ~KResourceLimit(); | 38 | ~KResourceLimit(); |
| 42 | 39 | ||
| 43 | s64 GetLimitValue(LimitableResource which) const; | 40 | s64 GetLimitValue(LimitableResource which) const; |
| @@ -75,7 +72,6 @@ private: | |||
| 75 | mutable KLightLock lock; | 72 | mutable KLightLock lock; |
| 76 | s32 waiter_count{}; | 73 | s32 waiter_count{}; |
| 77 | KLightConditionVariable cond_var; | 74 | KLightConditionVariable cond_var; |
| 78 | KernelCore& kernel; | 75 | const Core::Timing::CoreTiming& core_timing; |
| 79 | Core::System& system; | ||
| 80 | }; | 76 | }; |
| 81 | } // namespace Kernel | 77 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index f7d3f218a..5c4f45ab4 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -72,7 +72,7 @@ struct KernelCore::Impl { | |||
| 72 | KMemoryLayout memory_layout; | 72 | KMemoryLayout memory_layout; |
| 73 | DeriveInitialMemoryLayout(memory_layout); | 73 | DeriveInitialMemoryLayout(memory_layout); |
| 74 | InitializeMemoryLayout(memory_layout); | 74 | InitializeMemoryLayout(memory_layout); |
| 75 | InitializeSystemResourceLimit(kernel, system, memory_layout); | 75 | InitializeSystemResourceLimit(kernel, system.CoreTiming(), memory_layout); |
| 76 | InitializeSlabHeaps(); | 76 | InitializeSlabHeaps(); |
| 77 | InitializeSchedulers(); | 77 | InitializeSchedulers(); |
| 78 | InitializeSuspendThreads(); | 78 | InitializeSuspendThreads(); |
| @@ -142,9 +142,10 @@ struct KernelCore::Impl { | |||
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | // Creates the default system resource limit | 144 | // Creates the default system resource limit |
| 145 | void InitializeSystemResourceLimit(KernelCore& kernel, Core::System& system, | 145 | void InitializeSystemResourceLimit(KernelCore& kernel, |
| 146 | const Core::Timing::CoreTiming& core_timing, | ||
| 146 | const KMemoryLayout& memory_layout) { | 147 | const KMemoryLayout& memory_layout) { |
| 147 | system_resource_limit = std::make_shared<KResourceLimit>(kernel, system); | 148 | system_resource_limit = std::make_shared<KResourceLimit>(kernel, core_timing); |
| 148 | const auto [total_size, kernel_size] = memory_layout.GetTotalAndKernelMemorySizes(); | 149 | const auto [total_size, kernel_size] = memory_layout.GetTotalAndKernelMemorySizes(); |
| 149 | 150 | ||
| 150 | // If setting the default system values fails, then something seriously wrong has occurred. | 151 | // If setting the default system values fails, then something seriously wrong has occurred. |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index fcffc746d..bebb86154 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -2156,7 +2156,7 @@ static ResultCode CreateResourceLimit(Core::System& system, Handle* out_handle) | |||
| 2156 | LOG_DEBUG(Kernel_SVC, "called"); | 2156 | LOG_DEBUG(Kernel_SVC, "called"); |
| 2157 | 2157 | ||
| 2158 | auto& kernel = system.Kernel(); | 2158 | auto& kernel = system.Kernel(); |
| 2159 | auto resource_limit = std::make_shared<KResourceLimit>(kernel, system); | 2159 | auto resource_limit = std::make_shared<KResourceLimit>(kernel, system.CoreTiming()); |
| 2160 | 2160 | ||
| 2161 | auto* const current_process = kernel.CurrentProcess(); | 2161 | auto* const current_process = kernel.CurrentProcess(); |
| 2162 | ASSERT(current_process != nullptr); | 2162 | ASSERT(current_process != nullptr); |