resource_limit.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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/kernel.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 ResourceTypes {
  15. PRIORITY = 0,
  16. COMMIT = 1,
  17. THREAD = 2,
  18. EVENT = 3,
  19. MUTEX = 4,
  20. SEMAPHORE = 5,
  21. TIMER = 6,
  22. SHARED_MEMORY = 7,
  23. ADDRESS_ARBITER = 8,
  24. CPU_TIME = 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 { return "ResourceLimit"; }
  39. std::string GetName() const override { return name; }
  40. static const HandleType HANDLE_TYPE = HandleType::ResourceLimit;
  41. HandleType GetHandleType() const override { return HANDLE_TYPE; }
  42. /**
  43. * Gets the current value for the specified resource.
  44. * @param resource Requested resource type
  45. * @returns The current value of the resource type
  46. */
  47. s32 GetCurrentResourceValue(u32 resource) const;
  48. /**
  49. * Gets the max value for the specified resource.
  50. * @param resource Requested resource type
  51. * @returns The max value of the resource type
  52. */
  53. s32 GetMaxResourceValue(u32 resource) const;
  54. /// Name of resource limit object.
  55. std::string name;
  56. /// Max thread priority that a process in this category can create
  57. s32 max_priority = 0;
  58. /// Max memory that processes in this category can use
  59. s32 max_commit = 0;
  60. ///< Max number of objects that can be collectively created by the processes in this category
  61. s32 max_threads = 0;
  62. s32 max_events = 0;
  63. s32 max_mutexes = 0;
  64. s32 max_semaphores = 0;
  65. s32 max_timers = 0;
  66. s32 max_shared_mems = 0;
  67. s32 max_address_arbiters = 0;
  68. /// Max CPU time that the processes in this category can utilize
  69. s32 max_cpu_time = 0;
  70. // TODO(Subv): Increment these in their respective Kernel::T::Create functions, keeping in mind that
  71. // APPLICATION resource limits should not be affected by the objects created by service modules.
  72. // Currently we have no way of distinguishing if a Create was called by the running application,
  73. // or by a service module. Approach this once we have separated the service modules into their own processes
  74. /// Current memory that the processes in this category are using
  75. s32 current_commit = 0;
  76. ///< Current number of objects among all processes in this category
  77. s32 current_threads = 0;
  78. s32 current_events = 0;
  79. s32 current_mutexes = 0;
  80. s32 current_semaphores = 0;
  81. s32 current_timers = 0;
  82. s32 current_shared_mems = 0;
  83. s32 current_address_arbiters = 0;
  84. /// Current CPU time that the processes in this category are utilizing
  85. s32 current_cpu_time = 0;
  86. private:
  87. ResourceLimit();
  88. ~ResourceLimit() override;
  89. };
  90. /// Initializes the resource limits
  91. void ResourceLimitsInit();
  92. // Destroys the resource limits
  93. void ResourceLimitsShutdown();
  94. } // namespace