kernel.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright 2014 Citra Emulator Project / PPSSPP Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include <unordered_map>
  7. #include "core/hle/kernel/object.h"
  8. template <typename T>
  9. class ResultVal;
  10. namespace CoreTiming {
  11. struct EventType;
  12. }
  13. namespace Kernel {
  14. class ClientPort;
  15. class HandleTable;
  16. class Process;
  17. class ResourceLimit;
  18. class Thread;
  19. class Timer;
  20. /// Represents a single instance of the kernel.
  21. class KernelCore {
  22. private:
  23. using NamedPortTable = std::unordered_map<std::string, SharedPtr<ClientPort>>;
  24. public:
  25. KernelCore();
  26. ~KernelCore();
  27. KernelCore(const KernelCore&) = delete;
  28. KernelCore& operator=(const KernelCore&) = delete;
  29. KernelCore(KernelCore&&) = delete;
  30. KernelCore& operator=(KernelCore&&) = delete;
  31. /// Resets the kernel to a clean slate for use.
  32. void Initialize();
  33. /// Clears all resources in use by the kernel instance.
  34. void Shutdown();
  35. /// Retrieves a shared pointer to the system resource limit instance.
  36. SharedPtr<ResourceLimit> GetSystemResourceLimit() const;
  37. /// Retrieves a shared pointer to a Thread instance within the thread wakeup handle table.
  38. SharedPtr<Thread> RetrieveThreadFromWakeupCallbackHandleTable(Handle handle) const;
  39. /// Retrieves a shared pointer to a Timer instance within the timer callback handle table.
  40. SharedPtr<Timer> RetrieveTimerFromCallbackHandleTable(Handle handle) const;
  41. /// Adds the given shared pointer to an internal list of active processes.
  42. void AppendNewProcess(SharedPtr<Process> process);
  43. /// Makes the given process the new current process.
  44. void MakeCurrentProcess(Process* process);
  45. /// Retrieves a pointer to the current process.
  46. Process* CurrentProcess();
  47. /// Retrieves a const pointer to the current process.
  48. const Process* CurrentProcess() const;
  49. /// Adds a port to the named port table
  50. void AddNamedPort(std::string name, SharedPtr<ClientPort> port);
  51. /// Finds a port within the named port table with the given name.
  52. NamedPortTable::iterator FindNamedPort(const std::string& name);
  53. /// Finds a port within the named port table with the given name.
  54. NamedPortTable::const_iterator FindNamedPort(const std::string& name) const;
  55. /// Determines whether or not the given port is a valid named port.
  56. bool IsValidNamedPort(NamedPortTable::const_iterator port) const;
  57. private:
  58. friend class Object;
  59. friend class Process;
  60. friend class Thread;
  61. friend class Timer;
  62. /// Creates a new object ID, incrementing the internal object ID counter.
  63. u32 CreateNewObjectID();
  64. /// Creates a new process ID, incrementing the internal process ID counter;
  65. u32 CreateNewProcessID();
  66. /// Creates a new thread ID, incrementing the internal thread ID counter.
  67. u32 CreateNewThreadID();
  68. /// Creates a timer callback handle for the given timer.
  69. ResultVal<Handle> CreateTimerCallbackHandle(const SharedPtr<Timer>& timer);
  70. /// Retrieves the event type used for thread wakeup callbacks.
  71. CoreTiming::EventType* ThreadWakeupCallbackEventType() const;
  72. /// Retrieves the event type used for timer callbacks.
  73. CoreTiming::EventType* TimerCallbackEventType() const;
  74. /// Provides a reference to the thread wakeup callback handle table.
  75. Kernel::HandleTable& ThreadWakeupCallbackHandleTable();
  76. /// Provides a const reference to the thread wakeup callback handle table.
  77. const Kernel::HandleTable& ThreadWakeupCallbackHandleTable() const;
  78. struct Impl;
  79. std::unique_ptr<Impl> impl;
  80. };
  81. } // namespace Kernel