resource_limit.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "core/hle/kernel/object.h"
  7. namespace Kernel {
  8. enum class ResourceLimitCategory : u8 {
  9. APPLICATION = 0,
  10. SYS_APPLET = 1,
  11. LIB_APPLET = 2,
  12. OTHER = 3
  13. };
  14. enum class ResourceType {
  15. Priority = 0,
  16. Commit = 1,
  17. Thread = 2,
  18. Event = 3,
  19. Mutex = 4,
  20. Semaphore = 5,
  21. Timer = 6,
  22. SharedMemory = 7,
  23. AddressArbiter = 8,
  24. CPUTime = 9,
  25. };
  26. class ResourceLimit final : public Object {
  27. public:
  28. /**
  29. * Creates a resource limit object.
  30. */
  31. static SharedPtr<ResourceLimit> Create(std::string name = "Unknown");
  32. /**
  33. * Retrieves the resource limit associated with the specified resource limit category.
  34. * @param category The resource limit category
  35. * @returns The resource limit associated with the category
  36. */
  37. static SharedPtr<ResourceLimit> GetForCategory(ResourceLimitCategory category);
  38. std::string GetTypeName() const override {
  39. return "ResourceLimit";
  40. }
  41. std::string GetName() const override {
  42. return name;
  43. }
  44. static const HandleType HANDLE_TYPE = HandleType::ResourceLimit;
  45. HandleType GetHandleType() const override {
  46. return HANDLE_TYPE;
  47. }
  48. /**
  49. * Gets the current value for the specified resource.
  50. * @param resource Requested resource type
  51. * @returns The current value of the resource type
  52. */
  53. s32 GetCurrentResourceValue(ResourceType resource) const;
  54. /**
  55. * Gets the max value for the specified resource.
  56. * @param resource Requested resource type
  57. * @returns The max value of the resource type
  58. */
  59. u32 GetMaxResourceValue(ResourceType resource) const;
  60. /// Name of resource limit object.
  61. std::string name;
  62. /// Max thread priority that a process in this category can create
  63. s32 max_priority = 0;
  64. /// Max memory that processes in this category can use
  65. s32 max_commit = 0;
  66. ///< Max number of objects that can be collectively created by the processes in this category
  67. s32 max_threads = 0;
  68. s32 max_events = 0;
  69. s32 max_mutexes = 0;
  70. s32 max_semaphores = 0;
  71. s32 max_timers = 0;
  72. s32 max_shared_mems = 0;
  73. s32 max_address_arbiters = 0;
  74. /// Max CPU time that the processes in this category can utilize
  75. s32 max_cpu_time = 0;
  76. // TODO(Subv): Increment these in their respective Kernel::T::Create functions, keeping in mind
  77. // that APPLICATION resource limits should not be affected by the objects created by service
  78. // modules.
  79. // Currently we have no way of distinguishing if a Create was called by the running application,
  80. // or by a service module. Approach this once we have separated the service modules into their
  81. // own processes
  82. /// Current memory that the processes in this category are using
  83. s32 current_commit = 0;
  84. ///< Current number of objects among all processes in this category
  85. s32 current_threads = 0;
  86. s32 current_events = 0;
  87. s32 current_mutexes = 0;
  88. s32 current_semaphores = 0;
  89. s32 current_timers = 0;
  90. s32 current_shared_mems = 0;
  91. s32 current_address_arbiters = 0;
  92. /// Current CPU time that the processes in this category are utilizing
  93. s32 current_cpu_time = 0;
  94. private:
  95. ResourceLimit();
  96. ~ResourceLimit() override;
  97. };
  98. /// Initializes the resource limits
  99. void ResourceLimitsInit();
  100. // Destroys the resource limits
  101. void ResourceLimitsShutdown();
  102. } // namespace Kernel