From fc0bf91a969cddeb2f84c3e7c3a862fe98f1d438 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 10 Jun 2019 00:28:33 -0400 Subject: kernel: Differentiate kernel and user processes when picking ID This allows kernel internal type processes to be assigned IDs in the KIP range while userland processes are assigned in the user range. --- src/core/hle/kernel/kernel.cpp | 14 ++++++++++---- src/core/hle/kernel/kernel.h | 5 ++++- src/core/hle/kernel/process.cpp | 6 ++++-- src/core/hle/kernel/process.h | 8 +++++++- 4 files changed, 25 insertions(+), 8 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 757e5f21f..799e5e0d8 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -99,7 +99,8 @@ struct KernelCore::Impl { void Shutdown() { next_object_id = 0; - next_process_id = Process::ProcessIDMin; + next_kernel_process_id = Process::InitialKIPIDMin; + next_user_process_id = Process::ProcessIDMin; next_thread_id = 1; process_list.clear(); @@ -132,7 +133,8 @@ struct KernelCore::Impl { } std::atomic next_object_id{0}; - std::atomic next_process_id{Process::ProcessIDMin}; + std::atomic next_kernel_process_id{Process::InitialKIPIDMin}; + std::atomic next_user_process_id{Process::ProcessIDMin}; std::atomic next_thread_id{1}; // Lists all processes that exist in the current session. @@ -226,8 +228,12 @@ u64 KernelCore::CreateNewThreadID() { return impl->next_thread_id++; } -u64 KernelCore::CreateNewProcessID() { - return impl->next_process_id++; +u64 KernelCore::CreateNewKernelProcessID() { + return impl->next_kernel_process_id++; +} + +u64 KernelCore::CreateNewUserProcessID() { + return impl->next_user_process_id++; } Core::Timing::EventType* KernelCore::ThreadWakeupCallbackEventType() const { diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 6b8738599..0cc44ee76 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -96,7 +96,10 @@ private: u32 CreateNewObjectID(); /// Creates a new process ID, incrementing the internal process ID counter; - u64 CreateNewProcessID(); + u64 CreateNewKernelProcessID(); + + /// Creates a new process ID, incrementing the internal process ID counter; + u64 CreateNewUserProcessID(); /// Creates a new thread ID, incrementing the internal thread ID counter. u64 CreateNewThreadID(); diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 2b81a8d4f..7cfc513a1 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -48,7 +48,8 @@ void SetupMainThread(Process& owner_process, KernelCore& kernel, u32 priority) { } } // Anonymous namespace -SharedPtr Process::Create(Core::System& system, std::string name) { +SharedPtr Process::Create(Core::System& system, std::string name, + Process::ProcessType type) { auto& kernel = system.Kernel(); SharedPtr process(new Process(system)); @@ -56,7 +57,8 @@ SharedPtr Process::Create(Core::System& system, std::string name) { process->resource_limit = kernel.GetSystemResourceLimit(); process->status = ProcessStatus::Created; process->program_id = 0; - process->process_id = kernel.CreateNewProcessID(); + process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID() + : kernel.CreateNewUserProcessID(); process->capabilities.InitializeForMetadatalessProcess(); std::mt19937 rng(Settings::values.rng_seed.value_or(0)); diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 29e016983..248fd3840 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -73,9 +73,15 @@ public: ProcessIDMax = 0xFFFFFFFFFFFFFFFF, }; + // Used to determine how process IDs are assigned. + enum class ProcessType { + KernelInternal, + Userland, + }; + static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4; - static SharedPtr Create(Core::System& system, std::string name); + static SharedPtr Create(Core::System& system, std::string name, ProcessType type); std::string GetTypeName() const override { return "Process"; -- cgit v1.2.3