kernel.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 Core::Timing {
  11. class CoreTiming;
  12. struct EventType;
  13. } // namespace Core::Timing
  14. namespace Kernel {
  15. class AddressArbiter;
  16. class ClientPort;
  17. class HandleTable;
  18. class Process;
  19. class ResourceLimit;
  20. class Thread;
  21. /// Represents a single instance of the kernel.
  22. class KernelCore {
  23. private:
  24. using NamedPortTable = std::unordered_map<std::string, SharedPtr<ClientPort>>;
  25. public:
  26. KernelCore();
  27. ~KernelCore();
  28. KernelCore(const KernelCore&) = delete;
  29. KernelCore& operator=(const KernelCore&) = delete;
  30. KernelCore(KernelCore&&) = delete;
  31. KernelCore& operator=(KernelCore&&) = delete;
  32. /// Resets the kernel to a clean slate for use.
  33. ///
  34. /// @param core_timing CoreTiming instance used to create any necessary
  35. /// kernel-specific callback events.
  36. ///
  37. void Initialize(Core::Timing::CoreTiming& core_timing);
  38. /// Clears all resources in use by the kernel instance.
  39. void Shutdown();
  40. /// Retrieves a shared pointer to the system resource limit instance.
  41. SharedPtr<ResourceLimit> GetSystemResourceLimit() const;
  42. /// Retrieves a shared pointer to a Thread instance within the thread wakeup handle table.
  43. SharedPtr<Thread> RetrieveThreadFromWakeupCallbackHandleTable(Handle handle) const;
  44. /// Adds the given shared pointer to an internal list of active processes.
  45. void AppendNewProcess(SharedPtr<Process> process);
  46. /// Makes the given process the new current process.
  47. void MakeCurrentProcess(Process* process);
  48. /// Retrieves a pointer to the current process.
  49. Process* CurrentProcess();
  50. /// Retrieves a const pointer to the current process.
  51. const Process* CurrentProcess() const;
  52. /// Provides a reference to the kernel's address arbiter.
  53. Kernel::AddressArbiter& AddressArbiter();
  54. /// Provides a const reference to the kernel's address arbiter.
  55. const Kernel::AddressArbiter& AddressArbiter() const;
  56. /// Adds a port to the named port table
  57. void AddNamedPort(std::string name, SharedPtr<ClientPort> port);
  58. /// Finds a port within the named port table with the given name.
  59. NamedPortTable::iterator FindNamedPort(const std::string& name);
  60. /// Finds a port within the named port table with the given name.
  61. NamedPortTable::const_iterator FindNamedPort(const std::string& name) const;
  62. /// Determines whether or not the given port is a valid named port.
  63. bool IsValidNamedPort(NamedPortTable::const_iterator port) const;
  64. private:
  65. friend class Object;
  66. friend class Process;
  67. friend class Thread;
  68. /// Creates a new object ID, incrementing the internal object ID counter.
  69. u32 CreateNewObjectID();
  70. /// Creates a new process ID, incrementing the internal process ID counter;
  71. u64 CreateNewProcessID();
  72. /// Creates a new thread ID, incrementing the internal thread ID counter.
  73. u64 CreateNewThreadID();
  74. /// Retrieves the event type used for thread wakeup callbacks.
  75. Core::Timing::EventType* ThreadWakeupCallbackEventType() const;
  76. /// Provides a reference to the thread wakeup callback handle table.
  77. Kernel::HandleTable& ThreadWakeupCallbackHandleTable();
  78. /// Provides a const reference to the thread wakeup callback handle table.
  79. const Kernel::HandleTable& ThreadWakeupCallbackHandleTable() const;
  80. struct Impl;
  81. std::unique_ptr<Impl> impl;
  82. };
  83. } // namespace Kernel