2015-05-12 22:25:15 +02:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-10-13 22:41:34 +02:00
|
|
|
#include <array>
|
2019-03-23 22:09:02 +01:00
|
|
|
#include <memory>
|
2019-08-11 01:20:09 +02:00
|
|
|
#include <boost/serialization/array.hpp>
|
|
|
|
#include <boost/serialization/shared_ptr.hpp>
|
2015-05-12 22:25:15 +02:00
|
|
|
#include "common/common_types.h"
|
2018-08-02 04:40:00 +02:00
|
|
|
#include "core/hle/kernel/object.h"
|
2015-05-12 22:25:15 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
enum class ResourceLimitCategory : u8 {
|
|
|
|
APPLICATION = 0,
|
2016-09-18 02:38:01 +02:00
|
|
|
SYS_APPLET = 1,
|
|
|
|
LIB_APPLET = 2,
|
|
|
|
OTHER = 3
|
2015-05-12 22:25:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ResourceTypes {
|
2016-09-18 02:38:01 +02:00
|
|
|
PRIORITY = 0,
|
|
|
|
COMMIT = 1,
|
|
|
|
THREAD = 2,
|
|
|
|
EVENT = 3,
|
|
|
|
MUTEX = 4,
|
|
|
|
SEMAPHORE = 5,
|
|
|
|
TIMER = 6,
|
|
|
|
SHARED_MEMORY = 7,
|
|
|
|
ADDRESS_ARBITER = 8,
|
|
|
|
CPU_TIME = 9,
|
2015-05-12 22:25:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceLimit final : public Object {
|
|
|
|
public:
|
2019-12-27 19:52:33 +01:00
|
|
|
explicit ResourceLimit(KernelSystem& kernel);
|
|
|
|
~ResourceLimit() override;
|
2019-03-23 21:04:19 +01:00
|
|
|
|
2015-05-12 22:25:15 +02:00
|
|
|
/**
|
|
|
|
* Creates a resource limit object.
|
|
|
|
*/
|
2019-03-23 21:04:19 +01:00
|
|
|
static std::shared_ptr<ResourceLimit> Create(KernelSystem& kernel,
|
|
|
|
std::string name = "Unknown");
|
2015-05-12 22:25:15 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
std::string GetTypeName() const override {
|
|
|
|
return "ResourceLimit";
|
|
|
|
}
|
|
|
|
std::string GetName() const override {
|
|
|
|
return name;
|
|
|
|
}
|
2015-05-12 22:25:15 +02:00
|
|
|
|
2019-04-11 22:30:52 +02:00
|
|
|
static constexpr HandleType HANDLE_TYPE = HandleType::ResourceLimit;
|
2016-09-18 02:38:01 +02:00
|
|
|
HandleType GetHandleType() const override {
|
|
|
|
return HANDLE_TYPE;
|
|
|
|
}
|
2015-05-12 22:25:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current value for the specified resource.
|
|
|
|
* @param resource Requested resource type
|
|
|
|
* @returns The current value of the resource type
|
|
|
|
*/
|
|
|
|
s32 GetCurrentResourceValue(u32 resource) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the max value for the specified resource.
|
|
|
|
* @param resource Requested resource type
|
|
|
|
* @returns The max value of the resource type
|
|
|
|
*/
|
2017-09-27 01:26:09 +02:00
|
|
|
u32 GetMaxResourceValue(u32 resource) const;
|
2015-05-12 22:25:15 +02: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 20:34:09 +02:00
|
|
|
|
2015-05-12 22:25:15 +02:00
|
|
|
/// Max CPU time that the processes in this category can utilize
|
|
|
|
s32 max_cpu_time = 0;
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
// TODO(Subv): Increment these in their respective Kernel::T::Create functions, keeping in mind
|
2016-09-19 03:01:46 +02:00
|
|
|
// that APPLICATION resource limits should not be affected by the objects created by service
|
|
|
|
// modules.
|
2015-05-25 20:34:09 +02:00
|
|
|
// Currently we have no way of distinguishing if a Create was called by the running application,
|
2016-09-18 02:38:01 +02:00
|
|
|
// or by a service module. Approach this once we have separated the service modules into their
|
|
|
|
// own processes
|
2015-05-12 22:25:15 +02: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;
|
2019-08-11 01:20:09 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
template <class Archive>
|
|
|
|
void serialize(Archive& ar, const unsigned int file_version)
|
|
|
|
{
|
|
|
|
ar & boost::serialization::base_object<Object>(*this);
|
|
|
|
// NB most of these aren't used at all currently, but we're adding them here for forwards compatibility
|
|
|
|
ar & name;
|
|
|
|
ar & max_priority;
|
|
|
|
ar & max_commit;
|
|
|
|
ar & max_threads;
|
|
|
|
ar & max_events;
|
|
|
|
ar & max_mutexes;
|
|
|
|
ar & max_semaphores;
|
|
|
|
ar & max_timers;
|
|
|
|
ar & max_shared_mems;
|
|
|
|
ar & max_address_arbiters;
|
|
|
|
ar & max_cpu_time;
|
|
|
|
ar & current_commit;
|
|
|
|
ar & current_threads;
|
|
|
|
ar & current_events;
|
|
|
|
ar & current_mutexes;
|
|
|
|
ar & current_semaphores;
|
|
|
|
ar & current_timers;
|
|
|
|
ar & current_shared_mems;
|
|
|
|
ar & current_address_arbiters;
|
|
|
|
ar & current_cpu_time;
|
|
|
|
}
|
2015-05-12 22:25:15 +02:00
|
|
|
};
|
|
|
|
|
2018-10-13 22:41:34 +02:00
|
|
|
class ResourceLimitList {
|
|
|
|
public:
|
|
|
|
explicit ResourceLimitList(KernelSystem& kernel);
|
|
|
|
~ResourceLimitList();
|
2015-05-12 22:25:15 +02:00
|
|
|
|
2018-10-13 22:41:34 +02:00
|
|
|
/**
|
|
|
|
* Retrieves the resource limit associated with the specified resource limit category.
|
|
|
|
* @param category The resource limit category
|
|
|
|
* @returns The resource limit associated with the category
|
|
|
|
*/
|
2019-03-23 21:04:19 +01:00
|
|
|
std::shared_ptr<ResourceLimit> GetForCategory(ResourceLimitCategory category);
|
2018-10-13 22:41:34 +02:00
|
|
|
|
|
|
|
private:
|
2019-03-23 21:04:19 +01:00
|
|
|
std::array<std::shared_ptr<ResourceLimit>, 4> resource_limits;
|
2019-08-11 01:20:09 +02:00
|
|
|
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
template <class Archive>
|
|
|
|
void serialize(Archive& ar, const unsigned int file_version)
|
|
|
|
{
|
|
|
|
ar & resource_limits;
|
|
|
|
}
|
2018-10-13 22:41:34 +02:00
|
|
|
};
|
2015-05-12 22:25:15 +02:00
|
|
|
|
2018-03-09 18:54:43 +01:00
|
|
|
} // namespace Kernel
|
2019-12-27 19:52:33 +01:00
|
|
|
|
|
|
|
BOOST_CLASS_EXPORT_KEY(Kernel::ResourceLimit)
|
|
|
|
CONSTRUCT_KERNEL_OBJECT(Kernel::ResourceLimit)
|