3
0
Fork 0
forked from suyu/suyu

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.
This commit is contained in:
Zach Hilman 2019-06-10 00:28:33 -04:00
parent 364932df3a
commit fc0bf91a96
6 changed files with 29 additions and 10 deletions

View file

@ -150,7 +150,8 @@ struct System::Impl {
} }
telemetry_session->AddInitialInfo(*app_loader); telemetry_session->AddInitialInfo(*app_loader);
auto main_process = Kernel::Process::Create(system, "main"); auto main_process =
Kernel::Process::Create(system, "main", Kernel::Process::ProcessType::Userland);
const auto [load_result, load_parameters] = app_loader->Load(*main_process); const auto [load_result, load_parameters] = app_loader->Load(*main_process);
if (load_result != Loader::ResultStatus::Success) { if (load_result != Loader::ResultStatus::Success) {
LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", static_cast<int>(load_result)); LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", static_cast<int>(load_result));

View file

@ -99,7 +99,8 @@ struct KernelCore::Impl {
void Shutdown() { void Shutdown() {
next_object_id = 0; 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; next_thread_id = 1;
process_list.clear(); process_list.clear();
@ -132,7 +133,8 @@ struct KernelCore::Impl {
} }
std::atomic<u32> next_object_id{0}; std::atomic<u32> next_object_id{0};
std::atomic<u64> next_process_id{Process::ProcessIDMin}; std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin};
std::atomic<u64> next_user_process_id{Process::ProcessIDMin};
std::atomic<u64> next_thread_id{1}; std::atomic<u64> next_thread_id{1};
// Lists all processes that exist in the current session. // Lists all processes that exist in the current session.
@ -226,8 +228,12 @@ u64 KernelCore::CreateNewThreadID() {
return impl->next_thread_id++; return impl->next_thread_id++;
} }
u64 KernelCore::CreateNewProcessID() { u64 KernelCore::CreateNewKernelProcessID() {
return impl->next_process_id++; return impl->next_kernel_process_id++;
}
u64 KernelCore::CreateNewUserProcessID() {
return impl->next_user_process_id++;
} }
Core::Timing::EventType* KernelCore::ThreadWakeupCallbackEventType() const { Core::Timing::EventType* KernelCore::ThreadWakeupCallbackEventType() const {

View file

@ -96,7 +96,10 @@ private:
u32 CreateNewObjectID(); u32 CreateNewObjectID();
/// Creates a new process ID, incrementing the internal process ID counter; /// 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. /// Creates a new thread ID, incrementing the internal thread ID counter.
u64 CreateNewThreadID(); u64 CreateNewThreadID();

View file

@ -48,7 +48,8 @@ void SetupMainThread(Process& owner_process, KernelCore& kernel, u32 priority) {
} }
} // Anonymous namespace } // Anonymous namespace
SharedPtr<Process> Process::Create(Core::System& system, std::string name) { SharedPtr<Process> Process::Create(Core::System& system, std::string name,
Process::ProcessType type) {
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
SharedPtr<Process> process(new Process(system)); SharedPtr<Process> process(new Process(system));
@ -56,7 +57,8 @@ SharedPtr<Process> Process::Create(Core::System& system, std::string name) {
process->resource_limit = kernel.GetSystemResourceLimit(); process->resource_limit = kernel.GetSystemResourceLimit();
process->status = ProcessStatus::Created; process->status = ProcessStatus::Created;
process->program_id = 0; process->program_id = 0;
process->process_id = kernel.CreateNewProcessID(); process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID()
: kernel.CreateNewUserProcessID();
process->capabilities.InitializeForMetadatalessProcess(); process->capabilities.InitializeForMetadatalessProcess();
std::mt19937 rng(Settings::values.rng_seed.value_or(0)); std::mt19937 rng(Settings::values.rng_seed.value_or(0));

View file

@ -73,9 +73,15 @@ public:
ProcessIDMax = 0xFFFFFFFFFFFFFFFF, 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 constexpr std::size_t RANDOM_ENTROPY_SIZE = 4;
static SharedPtr<Process> Create(Core::System& system, std::string name); static SharedPtr<Process> Create(Core::System& system, std::string name, ProcessType type);
std::string GetTypeName() const override { std::string GetTypeName() const override {
return "Process"; return "Process";

View file

@ -16,7 +16,8 @@ namespace ArmTests {
TestEnvironment::TestEnvironment(bool mutable_memory_) TestEnvironment::TestEnvironment(bool mutable_memory_)
: mutable_memory(mutable_memory_), : mutable_memory(mutable_memory_),
test_memory(std::make_shared<TestMemory>(this)), kernel{Core::System::GetInstance()} { test_memory(std::make_shared<TestMemory>(this)), kernel{Core::System::GetInstance()} {
auto process = Kernel::Process::Create(Core::System::GetInstance(), ""); auto process = Kernel::Process::Create(Core::System::GetInstance(), "",
Kernel::Process::ProcessType::Userland);
page_table = &process->VMManager().page_table; page_table = &process->VMManager().page_table;
std::fill(page_table->pointers.begin(), page_table->pointers.end(), nullptr); std::fill(page_table->pointers.begin(), page_table->pointers.end(), nullptr);