From 0cbcd6ec9aeeafc298fe2e6e4ac10d68bb7267c5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 Aug 2018 12:30:33 -0400 Subject: kernel: Eliminate kernel global state As means to pave the way for getting rid of global state within core, This eliminates kernel global state by removing all globals. Instead this introduces a KernelCore class which acts as a kernel instance. This instance lives in the System class, which keeps its lifetime contained to the lifetime of the System class. This also forces the kernel types to actually interact with the main kernel instance itself instead of having transient kernel state placed all over several translation units, keeping everything together. It also has a nice consequence of making dependencies much more explicit. This also makes our initialization a tad bit more correct. Previously we were creating a kernel process before the actual kernel was initialized, which doesn't really make much sense. The KernelCore class itself follows the PImpl idiom, which allows keeping all the implementation details sealed away from everything else, which forces the use of the exposed API and allows us to avoid any unnecessary inclusions within the main kernel header. --- src/core/hle/kernel/process.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/core/hle/kernel/process.h') diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 992689186..1587d40c1 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -19,6 +19,8 @@ namespace Kernel { +class KernelCore; + struct AddressMapping { // Address and size must be page-aligned VAddr address; @@ -62,7 +64,7 @@ struct CodeSet final : public Object { u32 size = 0; }; - static SharedPtr Create(std::string name); + static SharedPtr Create(KernelCore& kernel, std::string name); std::string GetTypeName() const override { return "CodeSet"; @@ -109,13 +111,13 @@ struct CodeSet final : public Object { std::string name; private: - CodeSet(); + explicit CodeSet(KernelCore& kernel); ~CodeSet() override; }; class Process final : public Object { public: - static SharedPtr Create(std::string&& name); + static SharedPtr Create(KernelCore& kernel, std::string&& name); std::string GetTypeName() const override { return "Process"; @@ -129,8 +131,6 @@ public: return HANDLE_TYPE; } - static u32 next_process_id; - /// Title ID corresponding to the process u64 program_id; @@ -157,8 +157,8 @@ public: /// Current status of the process ProcessStatus status; - /// The id of this process - u32 process_id = next_process_id++; + /// The ID of this process + u32 process_id = 0; /** * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them @@ -206,13 +206,8 @@ public: ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size); private: - Process(); + explicit Process(KernelCore& kernel); ~Process() override; }; -void ClearProcessList(); - -/// Retrieves a process from the current list of processes. -SharedPtr GetProcessById(u32 process_id); - } // namespace Kernel -- cgit v1.2.3