summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/process.cpp')
-rw-r--r--src/core/hle/kernel/process.cpp40
1 files changed, 11 insertions, 29 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index edf34c5a3..b025e323f 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -8,6 +8,7 @@
8#include "common/common_funcs.h" 8#include "common/common_funcs.h"
9#include "common/logging/log.h" 9#include "common/logging/log.h"
10#include "core/hle/kernel/errors.h" 10#include "core/hle/kernel/errors.h"
11#include "core/hle/kernel/kernel.h"
11#include "core/hle/kernel/process.h" 12#include "core/hle/kernel/process.h"
12#include "core/hle/kernel/resource_limit.h" 13#include "core/hle/kernel/resource_limit.h"
13#include "core/hle/kernel/thread.h" 14#include "core/hle/kernel/thread.h"
@@ -16,30 +17,26 @@
16 17
17namespace Kernel { 18namespace Kernel {
18 19
19// Lists all processes that exist in the current session. 20SharedPtr<CodeSet> CodeSet::Create(KernelCore& kernel, std::string name) {
20static std::vector<SharedPtr<Process>> process_list; 21 SharedPtr<CodeSet> codeset(new CodeSet(kernel));
21
22SharedPtr<CodeSet> CodeSet::Create(std::string name) {
23 SharedPtr<CodeSet> codeset(new CodeSet);
24 codeset->name = std::move(name); 22 codeset->name = std::move(name);
25 return codeset; 23 return codeset;
26} 24}
27 25
28CodeSet::CodeSet() {} 26CodeSet::CodeSet(KernelCore& kernel) : Object{kernel} {}
29CodeSet::~CodeSet() {} 27CodeSet::~CodeSet() = default;
30
31u32 Process::next_process_id;
32 28
33SharedPtr<Process> Process::Create(std::string&& name) { 29SharedPtr<Process> Process::Create(KernelCore& kernel, std::string&& name) {
34 SharedPtr<Process> process(new Process); 30 SharedPtr<Process> process(new Process(kernel));
35 31
36 process->name = std::move(name); 32 process->name = std::move(name);
37 process->flags.raw = 0; 33 process->flags.raw = 0;
38 process->flags.memory_region.Assign(MemoryRegion::APPLICATION); 34 process->flags.memory_region.Assign(MemoryRegion::APPLICATION);
39 process->status = ProcessStatus::Created; 35 process->status = ProcessStatus::Created;
40 process->program_id = 0; 36 process->program_id = 0;
37 process->process_id = kernel.CreateNewProcessID();
41 38
42 process_list.push_back(process); 39 kernel.AppendNewProcess(process);
43 return process; 40 return process;
44} 41}
45 42
@@ -128,7 +125,7 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) {
128 vm_manager.LogLayout(); 125 vm_manager.LogLayout();
129 status = ProcessStatus::Running; 126 status = ProcessStatus::Running;
130 127
131 Kernel::SetupMainThread(entry_point, main_thread_priority, this); 128 Kernel::SetupMainThread(kernel, entry_point, main_thread_priority, this);
132} 129}
133 130
134void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) { 131void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) {
@@ -231,22 +228,7 @@ ResultCode Process::UnmapMemory(VAddr dst_addr, VAddr /*src_addr*/, u64 size) {
231 return vm_manager.UnmapRange(dst_addr, size); 228 return vm_manager.UnmapRange(dst_addr, size);
232} 229}
233 230
234Kernel::Process::Process() {} 231Kernel::Process::Process(KernelCore& kernel) : Object{kernel} {}
235Kernel::Process::~Process() {} 232Kernel::Process::~Process() {}
236 233
237void ClearProcessList() {
238 process_list.clear();
239}
240
241SharedPtr<Process> GetProcessById(u32 process_id) {
242 auto itr = std::find_if(
243 process_list.begin(), process_list.end(),
244 [&](const SharedPtr<Process>& process) { return process->process_id == process_id; });
245
246 if (itr == process_list.end())
247 return nullptr;
248
249 return *itr;
250}
251
252} // namespace Kernel 234} // namespace Kernel