resource_limit.h 3.2 KB

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