2015-05-12 13:25:15 -07:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2018-08-01 19:40:00 -07:00
|
|
|
#include "core/hle/kernel/object.h"
|
2015-05-12 13:25:15 -07:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2018-08-28 09:30:33 -07:00
|
|
|
class KernelCore;
|
|
|
|
|
2015-05-12 13:25:15 -07:00
|
|
|
enum class ResourceLimitCategory : u8 {
|
|
|
|
APPLICATION = 0,
|
2016-09-17 17:38:01 -07:00
|
|
|
SYS_APPLET = 1,
|
|
|
|
LIB_APPLET = 2,
|
|
|
|
OTHER = 3
|
2015-05-12 13:25:15 -07:00
|
|
|
};
|
|
|
|
|
2018-04-20 16:35:02 -07:00
|
|
|
enum class ResourceType {
|
|
|
|
Priority = 0,
|
|
|
|
Commit = 1,
|
|
|
|
Thread = 2,
|
|
|
|
Event = 3,
|
|
|
|
Mutex = 4,
|
|
|
|
Semaphore = 5,
|
|
|
|
Timer = 6,
|
|
|
|
SharedMemory = 7,
|
|
|
|
AddressArbiter = 8,
|
|
|
|
CPUTime = 9,
|
2015-05-12 13:25:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceLimit final : public Object {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a resource limit object.
|
|
|
|
*/
|
2018-08-28 09:30:33 -07:00
|
|
|
static SharedPtr<ResourceLimit> Create(KernelCore& kernel, std::string name = "Unknown");
|
2015-05-12 13:25:15 -07:00
|
|
|
|
2016-09-17 17:38:01 -07:00
|
|
|
std::string GetTypeName() const override {
|
|
|
|
return "ResourceLimit";
|
|
|
|
}
|
|
|
|
std::string GetName() const override {
|
|
|
|
return name;
|
|
|
|
}
|
2015-05-12 13:25:15 -07:00
|
|
|
|
|
|
|
static const HandleType HANDLE_TYPE = HandleType::ResourceLimit;
|
2016-09-17 17:38:01 -07:00
|
|
|
HandleType GetHandleType() const override {
|
|
|
|
return HANDLE_TYPE;
|
|
|
|
}
|
2015-05-12 13:25:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current value for the specified resource.
|
|
|
|
* @param resource Requested resource type
|
|
|
|
* @returns The current value of the resource type
|
|
|
|
*/
|
2018-04-20 16:35:02 -07:00
|
|
|
s32 GetCurrentResourceValue(ResourceType resource) const;
|
2015-05-12 13:25:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the max value for the specified resource.
|
|
|
|
* @param resource Requested resource type
|
|
|
|
* @returns The max value of the resource type
|
|
|
|
*/
|
2018-04-20 16:35:02 -07:00
|
|
|
u32 GetMaxResourceValue(ResourceType resource) const;
|
2015-05-12 13:25:15 -07:00
|
|
|
|
|
|
|
/// 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;
|
|
|
|
|
|
|
|
///< 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;
|
2015-05-25 11:34:09 -07:00
|
|
|
|
2015-05-12 13:25:15 -07:00
|
|
|
/// Max CPU time that the processes in this category can utilize
|
|
|
|
s32 max_cpu_time = 0;
|
|
|
|
|
2016-09-17 17:38:01 -07:00
|
|
|
// TODO(Subv): Increment these in their respective Kernel::T::Create functions, keeping in mind
|
2016-09-18 18:01:46 -07:00
|
|
|
// that APPLICATION resource limits should not be affected by the objects created by service
|
|
|
|
// modules.
|
2015-05-25 11:34:09 -07:00
|
|
|
// Currently we have no way of distinguishing if a Create was called by the running application,
|
2016-09-17 17:38:01 -07:00
|
|
|
// or by a service module. Approach this once we have separated the service modules into their
|
|
|
|
// own processes
|
2015-05-12 13:25:15 -07:00
|
|
|
|
|
|
|
/// Current memory that the processes in this category are using
|
|
|
|
s32 current_commit = 0;
|
|
|
|
|
|
|
|
///< 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;
|
|
|
|
|
|
|
|
/// Current CPU time that the processes in this category are utilizing
|
|
|
|
s32 current_cpu_time = 0;
|
|
|
|
|
|
|
|
private:
|
2018-08-28 09:30:33 -07:00
|
|
|
explicit ResourceLimit(KernelCore& kernel);
|
2015-05-12 13:25:15 -07:00
|
|
|
~ResourceLimit() override;
|
|
|
|
};
|
|
|
|
|
2018-01-19 23:48:02 -08:00
|
|
|
} // namespace Kernel
|