From 5d46038c5cd91504b00b76660212a3a28b244f38 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Nov 2018 12:54:06 -0500 Subject: kernel/resource_limit: Clean up interface Cleans out the citra/3DS-specific implementation details that don't apply to the Switch. Sets the stage for implementing ResourceLimit instances properly. While we're at it, remove the erroneous checks within CreateThread() and SetThreadPriority(). While these are indeed checked in some capacity, they are not checked via a ResourceLimit instance. In the process of moving out Citra-specifics, this also replaces the system ResourceLimit instance's values with ones from the Switch. --- src/core/hle/kernel/resource_limit.h | 98 +++++++++++++++--------------------- 1 file changed, 41 insertions(+), 57 deletions(-) (limited to 'src/core/hle/kernel/resource_limit.h') diff --git a/src/core/hle/kernel/resource_limit.h b/src/core/hle/kernel/resource_limit.h index 219e49562..bec065543 100644 --- a/src/core/hle/kernel/resource_limit.h +++ b/src/core/hle/kernel/resource_limit.h @@ -4,31 +4,25 @@ #pragma once +#include #include "common/common_types.h" #include "core/hle/kernel/object.h" +union ResultCode; + namespace Kernel { class KernelCore; -enum class ResourceLimitCategory : u8 { - APPLICATION = 0, - SYS_APPLET = 1, - LIB_APPLET = 2, - OTHER = 3 -}; - enum class ResourceType { - Priority = 0, - Commit = 1, - Thread = 2, - Event = 3, - Mutex = 4, - Semaphore = 5, - Timer = 6, - SharedMemory = 7, - AddressArbiter = 8, - CPUTime = 9, + PhysicalMemory, + Threads, + Events, + TransferMemory, + Sessions, + + // Used as a count, not an actual type. + ResourceTypeCount }; class ResourceLimit final : public Object { @@ -55,61 +49,51 @@ public: * @param resource Requested resource type * @returns The current value of the resource type */ - s32 GetCurrentResourceValue(ResourceType resource) const; + s64 GetCurrentResourceValue(ResourceType resource) const; /** * Gets the max value for the specified resource. * @param resource Requested resource type * @returns The max value of the resource type */ - u32 GetMaxResourceValue(ResourceType resource) const; - - /// Name of resource limit object. - std::string name; - - /// Max thread priority that a process in this category can create - s32 max_priority = 0; - - /// Max memory that processes in this category can use - s32 max_commit = 0; + s64 GetMaxResourceValue(ResourceType resource) const; - ///< Max number of objects that can be collectively created by the processes in this category - s32 max_threads = 0; - s32 max_events = 0; - s32 max_mutexes = 0; - s32 max_semaphores = 0; - s32 max_timers = 0; - s32 max_shared_mems = 0; - s32 max_address_arbiters = 0; + /** + * Sets the limit value for a given resource type. + * + * @param resource The resource type to apply the limit to. + * @param value The limit to apply to the given resource type. + * + * @return A result code indicating if setting the limit value + * was successful or not. + * + * @note The supplied limit value *must* be greater than or equal to + * the current resource value for the given resource type, + * otherwise ERR_INVALID_STATE will be returned. + */ + ResultCode SetLimitValue(ResourceType resource, s64 value); - /// Max CPU time that the processes in this category can utilize - s32 max_cpu_time = 0; +private: + explicit ResourceLimit(KernelCore& kernel); + ~ResourceLimit() override; - // TODO(Subv): Increment these in their respective Kernel::T::Create functions, keeping in mind - // that APPLICATION resource limits should not be affected by the objects created by service - // modules. + // TODO(Subv): Increment resource limit current values in their respective Kernel::T::Create + // functions + // // Currently we have no way of distinguishing if a Create was called by the running application, // or by a service module. Approach this once we have separated the service modules into their // own processes - /// Current memory that the processes in this category are using - s32 current_commit = 0; + using ResourceArray = + std::array(ResourceType::ResourceTypeCount)>; - ///< Current number of objects among all processes in this category - s32 current_threads = 0; - s32 current_events = 0; - s32 current_mutexes = 0; - s32 current_semaphores = 0; - s32 current_timers = 0; - s32 current_shared_mems = 0; - s32 current_address_arbiters = 0; + /// Maximum values a resource type may reach. + ResourceArray limits{}; + /// Current resource limit values. + ResourceArray values{}; - /// Current CPU time that the processes in this category are utilizing - s32 current_cpu_time = 0; - -private: - explicit ResourceLimit(KernelCore& kernel); - ~ResourceLimit() override; + /// Name of resource limit object. + std::string name; }; } // namespace Kernel -- cgit v1.2.3