diff options
| author | 2021-02-03 14:53:25 -0800 | |
|---|---|---|
| committer | 2021-02-03 14:53:25 -0800 | |
| commit | b0c97526633dffdf105f6d0a854ee2d02ae5a516 (patch) | |
| tree | 9da902b04fb9424a3f1e32ee05b81327da521157 /src/core/hle/kernel/svc.cpp | |
| parent | Merge pull request #5842 from german77/userfix (diff) | |
| parent | Simplify limitableresource names (diff) | |
| download | yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.tar.gz yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.tar.xz yuzu-b0c97526633dffdf105f6d0a854ee2d02ae5a516.zip | |
Merge pull request #5848 from ogniK5377/k-resourcelimit
kernel: Rewrite resource limit to be more accurate
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 7fd514e9d..74eb90100 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include "core/hle/kernel/handle_table.h" | 26 | #include "core/hle/kernel/handle_table.h" |
| 27 | #include "core/hle/kernel/k_address_arbiter.h" | 27 | #include "core/hle/kernel/k_address_arbiter.h" |
| 28 | #include "core/hle/kernel/k_condition_variable.h" | 28 | #include "core/hle/kernel/k_condition_variable.h" |
| 29 | #include "core/hle/kernel/k_resource_limit.h" | ||
| 29 | #include "core/hle/kernel/k_scheduler.h" | 30 | #include "core/hle/kernel/k_scheduler.h" |
| 30 | #include "core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h" | 31 | #include "core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h" |
| 31 | #include "core/hle/kernel/k_synchronization_object.h" | 32 | #include "core/hle/kernel/k_synchronization_object.h" |
| @@ -37,7 +38,6 @@ | |||
| 37 | #include "core/hle/kernel/physical_core.h" | 38 | #include "core/hle/kernel/physical_core.h" |
| 38 | #include "core/hle/kernel/process.h" | 39 | #include "core/hle/kernel/process.h" |
| 39 | #include "core/hle/kernel/readable_event.h" | 40 | #include "core/hle/kernel/readable_event.h" |
| 40 | #include "core/hle/kernel/resource_limit.h" | ||
| 41 | #include "core/hle/kernel/shared_memory.h" | 41 | #include "core/hle/kernel/shared_memory.h" |
| 42 | #include "core/hle/kernel/svc.h" | 42 | #include "core/hle/kernel/svc.h" |
| 43 | #include "core/hle/kernel/svc_results.h" | 43 | #include "core/hle/kernel/svc_results.h" |
| @@ -141,7 +141,7 @@ enum class ResourceLimitValueType { | |||
| 141 | ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_limit, | 141 | ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_limit, |
| 142 | u32 resource_type, ResourceLimitValueType value_type) { | 142 | u32 resource_type, ResourceLimitValueType value_type) { |
| 143 | std::lock_guard lock{HLE::g_hle_lock}; | 143 | std::lock_guard lock{HLE::g_hle_lock}; |
| 144 | const auto type = static_cast<ResourceType>(resource_type); | 144 | const auto type = static_cast<LimitableResource>(resource_type); |
| 145 | if (!IsValidResourceType(type)) { | 145 | if (!IsValidResourceType(type)) { |
| 146 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); | 146 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); |
| 147 | return ERR_INVALID_ENUM_VALUE; | 147 | return ERR_INVALID_ENUM_VALUE; |
| @@ -151,7 +151,7 @@ ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_ | |||
| 151 | ASSERT(current_process != nullptr); | 151 | ASSERT(current_process != nullptr); |
| 152 | 152 | ||
| 153 | const auto resource_limit_object = | 153 | const auto resource_limit_object = |
| 154 | current_process->GetHandleTable().Get<ResourceLimit>(resource_limit); | 154 | current_process->GetHandleTable().Get<KResourceLimit>(resource_limit); |
| 155 | if (!resource_limit_object) { | 155 | if (!resource_limit_object) { |
| 156 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", | 156 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", |
| 157 | resource_limit); | 157 | resource_limit); |
| @@ -159,10 +159,10 @@ ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_ | |||
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | if (value_type == ResourceLimitValueType::CurrentValue) { | 161 | if (value_type == ResourceLimitValueType::CurrentValue) { |
| 162 | return MakeResult(resource_limit_object->GetCurrentResourceValue(type)); | 162 | return MakeResult(resource_limit_object->GetCurrentValue(type)); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | return MakeResult(resource_limit_object->GetMaxResourceValue(type)); | 165 | return MakeResult(resource_limit_object->GetLimitValue(type)); |
| 166 | } | 166 | } |
| 167 | } // Anonymous namespace | 167 | } // Anonymous namespace |
| 168 | 168 | ||
| @@ -312,7 +312,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle, | |||
| 312 | return ERR_NOT_FOUND; | 312 | return ERR_NOT_FOUND; |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(ResourceType::Sessions, 1)); | 315 | ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(LimitableResource::Sessions, 1)); |
| 316 | 316 | ||
| 317 | auto client_port = it->second; | 317 | auto client_port = it->second; |
| 318 | 318 | ||
| @@ -1450,7 +1450,8 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr e | |||
| 1450 | Svc::ResultInvalidPriority); | 1450 | Svc::ResultInvalidPriority); |
| 1451 | R_UNLESS(process.CheckThreadPriority(priority), Svc::ResultInvalidPriority); | 1451 | R_UNLESS(process.CheckThreadPriority(priority), Svc::ResultInvalidPriority); |
| 1452 | 1452 | ||
| 1453 | ASSERT(process.GetResourceLimit()->Reserve(ResourceType::Threads, 1)); | 1453 | ASSERT(process.GetResourceLimit()->Reserve( |
| 1454 | LimitableResource::Threads, 1, system.CoreTiming().GetGlobalTimeNs().count() + 100000000)); | ||
| 1454 | 1455 | ||
| 1455 | std::shared_ptr<KThread> thread; | 1456 | std::shared_ptr<KThread> thread; |
| 1456 | { | 1457 | { |
| @@ -1972,7 +1973,7 @@ static ResultCode CreateResourceLimit(Core::System& system, Handle* out_handle) | |||
| 1972 | LOG_DEBUG(Kernel_SVC, "called"); | 1973 | LOG_DEBUG(Kernel_SVC, "called"); |
| 1973 | 1974 | ||
| 1974 | auto& kernel = system.Kernel(); | 1975 | auto& kernel = system.Kernel(); |
| 1975 | auto resource_limit = ResourceLimit::Create(kernel); | 1976 | auto resource_limit = std::make_shared<KResourceLimit>(kernel, system); |
| 1976 | 1977 | ||
| 1977 | auto* const current_process = kernel.CurrentProcess(); | 1978 | auto* const current_process = kernel.CurrentProcess(); |
| 1978 | ASSERT(current_process != nullptr); | 1979 | ASSERT(current_process != nullptr); |
| @@ -2019,7 +2020,7 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour | |||
| 2019 | LOG_DEBUG(Kernel_SVC, "called. Handle={:08X}, Resource type={}, Value={}", resource_limit, | 2020 | LOG_DEBUG(Kernel_SVC, "called. Handle={:08X}, Resource type={}, Value={}", resource_limit, |
| 2020 | resource_type, value); | 2021 | resource_type, value); |
| 2021 | 2022 | ||
| 2022 | const auto type = static_cast<ResourceType>(resource_type); | 2023 | const auto type = static_cast<LimitableResource>(resource_type); |
| 2023 | if (!IsValidResourceType(type)) { | 2024 | if (!IsValidResourceType(type)) { |
| 2024 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); | 2025 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); |
| 2025 | return ERR_INVALID_ENUM_VALUE; | 2026 | return ERR_INVALID_ENUM_VALUE; |
| @@ -2029,7 +2030,7 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour | |||
| 2029 | ASSERT(current_process != nullptr); | 2030 | ASSERT(current_process != nullptr); |
| 2030 | 2031 | ||
| 2031 | auto resource_limit_object = | 2032 | auto resource_limit_object = |
| 2032 | current_process->GetHandleTable().Get<ResourceLimit>(resource_limit); | 2033 | current_process->GetHandleTable().Get<KResourceLimit>(resource_limit); |
| 2033 | if (!resource_limit_object) { | 2034 | if (!resource_limit_object) { |
| 2034 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", | 2035 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", |
| 2035 | resource_limit); | 2036 | resource_limit); |
| @@ -2041,8 +2042,8 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour | |||
| 2041 | LOG_ERROR( | 2042 | LOG_ERROR( |
| 2042 | Kernel_SVC, | 2043 | Kernel_SVC, |
| 2043 | "Attempted to lower resource limit ({}) for category '{}' below its current value ({})", | 2044 | "Attempted to lower resource limit ({}) for category '{}' below its current value ({})", |
| 2044 | resource_limit_object->GetMaxResourceValue(type), resource_type, | 2045 | resource_limit_object->GetLimitValue(type), resource_type, |
| 2045 | resource_limit_object->GetCurrentResourceValue(type)); | 2046 | resource_limit_object->GetCurrentValue(type)); |
| 2046 | return set_result; | 2047 | return set_result; |
| 2047 | } | 2048 | } |
| 2048 | 2049 | ||