summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar bunnei2021-04-03 22:22:36 -0700
committerGravatar bunnei2021-05-05 16:40:50 -0700
commit7ccbdd4d8d3dea7294d2cac38779cceea9745d52 (patch)
tree3106289a5c5a6e4bf50bc09a548c8408aa29fbad /src/core/hle/kernel
parenthle: kernel: Refactor IPC interfaces to not use std::shared_ptr. (diff)
downloadyuzu-7ccbdd4d8d3dea7294d2cac38779cceea9745d52.tar.gz
yuzu-7ccbdd4d8d3dea7294d2cac38779cceea9745d52.tar.xz
yuzu-7ccbdd4d8d3dea7294d2cac38779cceea9745d52.zip
hle: kernel: Migrate KProcess to KAutoObject.
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/handle_table.cpp10
-rw-r--r--src/core/hle/kernel/handle_table.h4
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.cpp9
-rw-r--r--src/core/hle/kernel/init/init_slab_setup.h2
-rw-r--r--src/core/hle/kernel/k_synchronization_object.h5
-rw-r--r--src/core/hle/kernel/kernel.cpp8
-rw-r--r--src/core/hle/kernel/kernel.h4
-rw-r--r--src/core/hle/kernel/object.h4
-rw-r--r--src/core/hle/kernel/process.cpp31
-rw-r--r--src/core/hle/kernel/process.h32
-rw-r--r--src/core/hle/kernel/svc.cpp6
11 files changed, 68 insertions, 47 deletions
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index 8eec8a3b5..f746c4888 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -100,7 +100,7 @@ ResultCode HandleTable::Add(Handle* out_handle, KAutoObject* obj, u16 type) {
100} 100}
101 101
102ResultVal<Handle> HandleTable::Duplicate(Handle handle) { 102ResultVal<Handle> HandleTable::Duplicate(Handle handle) {
103 std::shared_ptr<Object> object = GetGeneric(handle); 103 std::shared_ptr<Object> object = SharedFrom(GetGeneric(handle));
104 if (object == nullptr) { 104 if (object == nullptr) {
105 LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle); 105 LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle);
106 return ResultInvalidHandle; 106 return ResultInvalidHandle;
@@ -140,17 +140,17 @@ bool HandleTable::IsValid(Handle handle) const {
140 return slot < table_size && is_object_valid && generations[slot] == generation; 140 return slot < table_size && is_object_valid && generations[slot] == generation;
141} 141}
142 142
143std::shared_ptr<Object> HandleTable::GetGeneric(Handle handle) const { 143Object* HandleTable::GetGeneric(Handle handle) const {
144 if (handle == CurrentThread) { 144 if (handle == CurrentThread) {
145 return SharedFrom(kernel.CurrentScheduler()->GetCurrentThread()); 145 return (kernel.CurrentScheduler()->GetCurrentThread());
146 } else if (handle == CurrentProcess) { 146 } else if (handle == CurrentProcess) {
147 return SharedFrom(kernel.CurrentProcess()); 147 return (kernel.CurrentProcess());
148 } 148 }
149 149
150 if (!IsValid(handle)) { 150 if (!IsValid(handle)) {
151 return nullptr; 151 return nullptr;
152 } 152 }
153 return objects[GetSlot(handle)]; 153 return objects[GetSlot(handle)].get();
154} 154}
155 155
156void HandleTable::Clear() { 156void HandleTable::Clear() {
diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h
index 555fb20e5..24a26b81d 100644
--- a/src/core/hle/kernel/handle_table.h
+++ b/src/core/hle/kernel/handle_table.h
@@ -98,7 +98,7 @@ public:
98 * Looks up a handle. 98 * Looks up a handle.
99 * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid. 99 * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid.
100 */ 100 */
101 std::shared_ptr<Object> GetGeneric(Handle handle) const; 101 Object* GetGeneric(Handle handle) const;
102 102
103 /** 103 /**
104 * Looks up a handle while verifying its type. 104 * Looks up a handle while verifying its type.
@@ -106,7 +106,7 @@ public:
106 * type differs from the requested one. 106 * type differs from the requested one.
107 */ 107 */
108 template <class T> 108 template <class T>
109 std::shared_ptr<T> Get(Handle handle) const { 109 T* Get(Handle handle) const {
110 return DynamicObjectCast<T>(GetGeneric(handle)); 110 return DynamicObjectCast<T>(GetGeneric(handle));
111 } 111 }
112 112
diff --git a/src/core/hle/kernel/init/init_slab_setup.cpp b/src/core/hle/kernel/init/init_slab_setup.cpp
index a290249c7..a6fed524b 100644
--- a/src/core/hle/kernel/init/init_slab_setup.cpp
+++ b/src/core/hle/kernel/init/init_slab_setup.cpp
@@ -14,13 +14,16 @@
14#include "core/hle/kernel/k_system_control.h" 14#include "core/hle/kernel/k_system_control.h"
15#include "core/hle/kernel/k_thread.h" 15#include "core/hle/kernel/k_thread.h"
16#include "core/hle/kernel/memory_types.h" 16#include "core/hle/kernel/memory_types.h"
17#include "core/hle/kernel/process.h"
17#include "core/memory.h" 18#include "core/memory.h"
18 19
19namespace Kernel::Init { 20namespace Kernel::Init {
20 21
21#define SLAB_COUNT(CLASS) g_slab_resource_counts.num_##CLASS 22#define SLAB_COUNT(CLASS) g_slab_resource_counts.num_##CLASS
22 23
23#define FOREACH_SLAB_TYPE(HANDLER, ...) HANDLER(KThread, (SLAB_COUNT(KThread)), ##__VA_ARGS__) 24#define FOREACH_SLAB_TYPE(HANDLER, ...) \
25 HANDLER(Process, (SLAB_COUNT(Process)), ##__VA_ARGS__) \
26 HANDLER(KThread, (SLAB_COUNT(KThread)), ##__VA_ARGS__)
24 27
25namespace { 28namespace {
26 29
@@ -33,7 +36,7 @@ enum KSlabType : u32 {
33#undef DEFINE_SLAB_TYPE_ENUM_MEMBER 36#undef DEFINE_SLAB_TYPE_ENUM_MEMBER
34 37
35// Constexpr counts. 38// Constexpr counts.
36constexpr size_t SlabCountKProcess = 80; 39constexpr size_t SlabCountProcess = 80;
37constexpr size_t SlabCountKThread = 800; 40constexpr size_t SlabCountKThread = 800;
38constexpr size_t SlabCountKEvent = 700; 41constexpr size_t SlabCountKEvent = 700;
39constexpr size_t SlabCountKInterruptEvent = 100; 42constexpr size_t SlabCountKInterruptEvent = 100;
@@ -54,7 +57,7 @@ constexpr size_t SlabCountExtraKThread = 160;
54 57
55// Global to hold our resource counts. 58// Global to hold our resource counts.
56KSlabResourceCounts g_slab_resource_counts = { 59KSlabResourceCounts g_slab_resource_counts = {
57 .num_KProcess = SlabCountKProcess, 60 .num_Process = SlabCountProcess,
58 .num_KThread = SlabCountKThread, 61 .num_KThread = SlabCountKThread,
59 .num_KEvent = SlabCountKEvent, 62 .num_KEvent = SlabCountKEvent,
60 .num_KInterruptEvent = SlabCountKInterruptEvent, 63 .num_KInterruptEvent = SlabCountKInterruptEvent,
diff --git a/src/core/hle/kernel/init/init_slab_setup.h b/src/core/hle/kernel/init/init_slab_setup.h
index 6418b97ac..8876678b3 100644
--- a/src/core/hle/kernel/init/init_slab_setup.h
+++ b/src/core/hle/kernel/init/init_slab_setup.h
@@ -15,7 +15,7 @@ class KMemoryLayout;
15namespace Kernel::Init { 15namespace Kernel::Init {
16 16
17struct KSlabResourceCounts { 17struct KSlabResourceCounts {
18 size_t num_KProcess; 18 size_t num_Process;
19 size_t num_KThread; 19 size_t num_KThread;
20 size_t num_KEvent; 20 size_t num_KEvent;
21 size_t num_KInterruptEvent; 21 size_t num_KInterruptEvent;
diff --git a/src/core/hle/kernel/k_synchronization_object.h b/src/core/hle/kernel/k_synchronization_object.h
index c8e840d89..5a99dbd46 100644
--- a/src/core/hle/kernel/k_synchronization_object.h
+++ b/src/core/hle/kernel/k_synchronization_object.h
@@ -53,10 +53,9 @@ private:
53 53
54// Specialization of DynamicObjectCast for KSynchronizationObjects 54// Specialization of DynamicObjectCast for KSynchronizationObjects
55template <> 55template <>
56inline std::shared_ptr<KSynchronizationObject> DynamicObjectCast<KSynchronizationObject>( 56inline KSynchronizationObject* DynamicObjectCast<KSynchronizationObject>(Object* object) {
57 std::shared_ptr<Object> object) {
58 if (object != nullptr && object->IsWaitable()) { 57 if (object != nullptr && object->IsWaitable()) {
59 return std::static_pointer_cast<KSynchronizationObject>(object); 58 return reinterpret_cast<KSynchronizationObject*>(object);
60 } 59 }
61 return nullptr; 60 return nullptr;
62} 61}
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index d1359e434..1b5b11564 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -614,7 +614,7 @@ struct KernelCore::Impl {
614 std::atomic<u64> next_thread_id{1}; 614 std::atomic<u64> next_thread_id{1};
615 615
616 // Lists all processes that exist in the current session. 616 // Lists all processes that exist in the current session.
617 std::vector<std::shared_ptr<Process>> process_list; 617 std::vector<Process*> process_list;
618 Process* current_process = nullptr; 618 Process* current_process = nullptr;
619 std::unique_ptr<Kernel::GlobalSchedulerContext> global_scheduler_context; 619 std::unique_ptr<Kernel::GlobalSchedulerContext> global_scheduler_context;
620 Kernel::TimeManager time_manager; 620 Kernel::TimeManager time_manager;
@@ -699,8 +699,8 @@ KScopedAutoObject<KThread> KernelCore::RetrieveThreadFromGlobalHandleTable(Handl
699 return impl->global_handle_table.GetObject<KThread>(handle); 699 return impl->global_handle_table.GetObject<KThread>(handle);
700} 700}
701 701
702void KernelCore::AppendNewProcess(std::shared_ptr<Process> process) { 702void KernelCore::AppendNewProcess(Process* process) {
703 impl->process_list.push_back(std::move(process)); 703 impl->process_list.push_back(process);
704} 704}
705 705
706void KernelCore::MakeCurrentProcess(Process* process) { 706void KernelCore::MakeCurrentProcess(Process* process) {
@@ -715,7 +715,7 @@ const Process* KernelCore::CurrentProcess() const {
715 return impl->current_process; 715 return impl->current_process;
716} 716}
717 717
718const std::vector<std::shared_ptr<Process>>& KernelCore::GetProcessList() const { 718const std::vector<Process*>& KernelCore::GetProcessList() const {
719 return impl->process_list; 719 return impl->process_list;
720} 720}
721 721
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 3f5c2aec7..b78602f46 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -91,7 +91,7 @@ public:
91 KScopedAutoObject<KThread> RetrieveThreadFromGlobalHandleTable(Handle handle) const; 91 KScopedAutoObject<KThread> RetrieveThreadFromGlobalHandleTable(Handle handle) const;
92 92
93 /// Adds the given shared pointer to an internal list of active processes. 93 /// Adds the given shared pointer to an internal list of active processes.
94 void AppendNewProcess(std::shared_ptr<Process> process); 94 void AppendNewProcess(Process* process);
95 95
96 /// Makes the given process the new current process. 96 /// Makes the given process the new current process.
97 void MakeCurrentProcess(Process* process); 97 void MakeCurrentProcess(Process* process);
@@ -103,7 +103,7 @@ public:
103 const Process* CurrentProcess() const; 103 const Process* CurrentProcess() const;
104 104
105 /// Retrieves the list of processes. 105 /// Retrieves the list of processes.
106 const std::vector<std::shared_ptr<Process>>& GetProcessList() const; 106 const std::vector<Process*>& GetProcessList() const;
107 107
108 /// Gets the sole instance of the global scheduler 108 /// Gets the sole instance of the global scheduler
109 Kernel::GlobalSchedulerContext& GlobalSchedulerContext(); 109 Kernel::GlobalSchedulerContext& GlobalSchedulerContext();
diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h
index 501e58b33..5c14aa46f 100644
--- a/src/core/hle/kernel/object.h
+++ b/src/core/hle/kernel/object.h
@@ -86,9 +86,9 @@ std::shared_ptr<T> SharedFrom(T* raw) {
86 * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T. 86 * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T.
87 */ 87 */
88template <typename T> 88template <typename T>
89inline std::shared_ptr<T> DynamicObjectCast(std::shared_ptr<Object> object) { 89inline T* DynamicObjectCast(Object* object) {
90 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { 90 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) {
91 return std::static_pointer_cast<T>(object); 91 return reinterpret_cast<T*>(object);
92 } 92 }
93 return nullptr; 93 return nullptr;
94} 94}
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 796dca5ef..fe4558648 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -49,6 +49,8 @@ void SetupMainThread(Core::System& system, Process& owner_process, u32 priority,
49 // Register 1 must be a handle to the main thread 49 // Register 1 must be a handle to the main thread
50 Handle thread_handle{}; 50 Handle thread_handle{};
51 owner_process.GetHandleTable().Add(&thread_handle, thread); 51 owner_process.GetHandleTable().Add(&thread_handle, thread);
52
53 thread->SetName("main");
52 thread->GetContext32().cpu_registers[0] = 0; 54 thread->GetContext32().cpu_registers[0] = 0;
53 thread->GetContext64().cpu_registers[0] = 0; 55 thread->GetContext64().cpu_registers[0] = 0;
54 thread->GetContext32().cpu_registers[1] = thread_handle; 56 thread->GetContext32().cpu_registers[1] = thread_handle;
@@ -115,10 +117,10 @@ private:
115 std::bitset<num_slot_entries> is_slot_used; 117 std::bitset<num_slot_entries> is_slot_used;
116}; 118};
117 119
118std::shared_ptr<Process> Process::Create(Core::System& system, std::string name, ProcessType type) { 120ResultCode Process::Initialize(Process* process, Core::System& system, std::string name,
121 ProcessType type) {
119 auto& kernel = system.Kernel(); 122 auto& kernel = system.Kernel();
120 123
121 std::shared_ptr<Process> process = std::make_shared<Process>(system);
122 process->name = std::move(name); 124 process->name = std::move(name);
123 125
124 process->resource_limit = kernel.GetSystemResourceLimit(); 126 process->resource_limit = kernel.GetSystemResourceLimit();
@@ -127,6 +129,7 @@ std::shared_ptr<Process> Process::Create(Core::System& system, std::string name,
127 process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID() 129 process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID()
128 : kernel.CreateNewUserProcessID(); 130 : kernel.CreateNewUserProcessID();
129 process->capabilities.InitializeForMetadatalessProcess(); 131 process->capabilities.InitializeForMetadatalessProcess();
132 process->is_initialized = true;
130 133
131 std::mt19937 rng(Settings::values.rng_seed.GetValue().value_or(std::time(nullptr))); 134 std::mt19937 rng(Settings::values.rng_seed.GetValue().value_or(std::time(nullptr)));
132 std::uniform_int_distribution<u64> distribution; 135 std::uniform_int_distribution<u64> distribution;
@@ -134,7 +137,8 @@ std::shared_ptr<Process> Process::Create(Core::System& system, std::string name,
134 [&] { return distribution(rng); }); 137 [&] { return distribution(rng); });
135 138
136 kernel.AppendNewProcess(process); 139 kernel.AppendNewProcess(process);
137 return process; 140
141 return RESULT_SUCCESS;
138} 142}
139 143
140std::shared_ptr<KResourceLimit> Process::GetResourceLimit() const { 144std::shared_ptr<KResourceLimit> Process::GetResourceLimit() const {
@@ -332,7 +336,7 @@ void Process::Run(s32 main_thread_priority, u64 stack_size) {
332 336
333 ChangeStatus(ProcessStatus::Running); 337 ChangeStatus(ProcessStatus::Running);
334 338
335 SetupMainThread(system, *this, main_thread_priority, main_thread_stack_top); 339 SetupMainThread(kernel.System(), *this, main_thread_priority, main_thread_stack_top);
336} 340}
337 341
338void Process::PrepareForTermination() { 342void Process::PrepareForTermination() {
@@ -354,7 +358,7 @@ void Process::PrepareForTermination() {
354 } 358 }
355 }; 359 };
356 360
357 stop_threads(system.GlobalSchedulerContext().GetThreadList()); 361 stop_threads(kernel.System().GlobalSchedulerContext().GetThreadList());
358 362
359 FreeTLSRegion(tls_region_address); 363 FreeTLSRegion(tls_region_address);
360 tls_region_address = 0; 364 tls_region_address = 0;
@@ -381,7 +385,7 @@ static auto FindTLSPageWithAvailableSlots(std::vector<TLSPage>& tls_pages) {
381} 385}
382 386
383VAddr Process::CreateTLSRegion() { 387VAddr Process::CreateTLSRegion() {
384 KScopedSchedulerLock lock(system.Kernel()); 388 KScopedSchedulerLock lock(kernel);
385 if (auto tls_page_iter{FindTLSPageWithAvailableSlots(tls_pages)}; 389 if (auto tls_page_iter{FindTLSPageWithAvailableSlots(tls_pages)};
386 tls_page_iter != tls_pages.cend()) { 390 tls_page_iter != tls_pages.cend()) {
387 return *tls_page_iter->ReserveSlot(); 391 return *tls_page_iter->ReserveSlot();
@@ -392,7 +396,7 @@ VAddr Process::CreateTLSRegion() {
392 396
393 const VAddr start{page_table->GetKernelMapRegionStart()}; 397 const VAddr start{page_table->GetKernelMapRegionStart()};
394 const VAddr size{page_table->GetKernelMapRegionEnd() - start}; 398 const VAddr size{page_table->GetKernelMapRegionEnd() - start};
395 const PAddr tls_map_addr{system.DeviceMemory().GetPhysicalAddr(tls_page_ptr)}; 399 const PAddr tls_map_addr{kernel.System().DeviceMemory().GetPhysicalAddr(tls_page_ptr)};
396 const VAddr tls_page_addr{page_table 400 const VAddr tls_page_addr{page_table
397 ->AllocateAndMapMemory(1, PageSize, true, start, size / PageSize, 401 ->AllocateAndMapMemory(1, PageSize, true, start, size / PageSize,
398 KMemoryState::ThreadLocal, 402 KMemoryState::ThreadLocal,
@@ -412,7 +416,7 @@ VAddr Process::CreateTLSRegion() {
412} 416}
413 417
414void Process::FreeTLSRegion(VAddr tls_address) { 418void Process::FreeTLSRegion(VAddr tls_address) {
415 KScopedSchedulerLock lock(system.Kernel()); 419 KScopedSchedulerLock lock(kernel);
416 const VAddr aligned_address = Common::AlignDown(tls_address, Core::Memory::PAGE_SIZE); 420 const VAddr aligned_address = Common::AlignDown(tls_address, Core::Memory::PAGE_SIZE);
417 auto iter = 421 auto iter =
418 std::find_if(tls_pages.begin(), tls_pages.end(), [aligned_address](const auto& page) { 422 std::find_if(tls_pages.begin(), tls_pages.end(), [aligned_address](const auto& page) {
@@ -433,7 +437,8 @@ void Process::LoadModule(CodeSet code_set, VAddr base_addr) {
433 page_table->SetCodeMemoryPermission(segment.addr + base_addr, segment.size, permission); 437 page_table->SetCodeMemoryPermission(segment.addr + base_addr, segment.size, permission);
434 }; 438 };
435 439
436 system.Memory().WriteBlock(*this, base_addr, code_set.memory.data(), code_set.memory.size()); 440 kernel.System().Memory().WriteBlock(*this, base_addr, code_set.memory.data(),
441 code_set.memory.size());
437 442
438 ReprotectSegment(code_set.CodeSegment(), KMemoryPermission::ReadAndExecute); 443 ReprotectSegment(code_set.CodeSegment(), KMemoryPermission::ReadAndExecute);
439 ReprotectSegment(code_set.RODataSegment(), KMemoryPermission::Read); 444 ReprotectSegment(code_set.RODataSegment(), KMemoryPermission::Read);
@@ -445,10 +450,10 @@ bool Process::IsSignaled() const {
445 return is_signaled; 450 return is_signaled;
446} 451}
447 452
448Process::Process(Core::System& system) 453Process::Process(KernelCore& kernel)
449 : KSynchronizationObject{system.Kernel()}, page_table{std::make_unique<KPageTable>(system)}, 454 : KAutoObjectWithSlabHeapAndContainer{kernel},
450 handle_table{system.Kernel()}, address_arbiter{system}, condition_var{system}, 455 page_table{std::make_unique<KPageTable>(kernel.System())}, handle_table{kernel},
451 state_lock{system.Kernel()}, system{system} {} 456 address_arbiter{kernel.System()}, condition_var{kernel.System()}, state_lock{kernel} {}
452 457
453Process::~Process() = default; 458Process::~Process() = default;
454 459
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 45eefb90e..df3c7997d 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -13,9 +13,11 @@
13#include "common/common_types.h" 13#include "common/common_types.h"
14#include "core/hle/kernel/handle_table.h" 14#include "core/hle/kernel/handle_table.h"
15#include "core/hle/kernel/k_address_arbiter.h" 15#include "core/hle/kernel/k_address_arbiter.h"
16#include "core/hle/kernel/k_auto_object.h"
16#include "core/hle/kernel/k_condition_variable.h" 17#include "core/hle/kernel/k_condition_variable.h"
17#include "core/hle/kernel/k_synchronization_object.h" 18#include "core/hle/kernel/k_synchronization_object.h"
18#include "core/hle/kernel/process_capability.h" 19#include "core/hle/kernel/process_capability.h"
20#include "core/hle/kernel/slab_helpers.h"
19#include "core/hle/result.h" 21#include "core/hle/result.h"
20 22
21namespace Core { 23namespace Core {
@@ -60,9 +62,11 @@ enum class ProcessStatus {
60 DebugBreak, 62 DebugBreak,
61}; 63};
62 64
63class Process final : public KSynchronizationObject { 65class Process final : public KAutoObjectWithSlabHeapAndContainer<Process, KSynchronizationObject> {
66 KERNEL_AUTOOBJECT_TRAITS(Process, KSynchronizationObject);
67
64public: 68public:
65 explicit Process(Core::System& system); 69 explicit Process(KernelCore& kernel);
66 ~Process() override; 70 ~Process() override;
67 71
68 enum : u64 { 72 enum : u64 {
@@ -85,8 +89,8 @@ public:
85 89
86 static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4; 90 static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4;
87 91
88 static std::shared_ptr<Process> Create(Core::System& system, std::string name, 92 static ResultCode Initialize(Process* process, Core::System& system, std::string name,
89 ProcessType type); 93 ProcessType type);
90 94
91 std::string GetTypeName() const override { 95 std::string GetTypeName() const override {
92 return "Process"; 96 return "Process";
@@ -338,9 +342,21 @@ public:
338 342
339 void LoadModule(CodeSet code_set, VAddr base_addr); 343 void LoadModule(CodeSet code_set, VAddr base_addr);
340 344
341 bool IsSignaled() const override; 345 virtual bool IsInitialized() const override {
346 return is_initialized;
347 }
348
349 static void PostDestroy([[maybe_unused]] uintptr_t arg) {}
350
351 virtual void Finalize() override {
352 UNIMPLEMENTED();
353 }
354
355 virtual u64 GetId() const override final {
356 return GetProcessID();
357 }
342 358
343 void Finalize() override {} 359 virtual bool IsSignaled() const override;
344 360
345 void PinCurrentThread(); 361 void PinCurrentThread();
346 void UnpinCurrentThread(); 362 void UnpinCurrentThread();
@@ -462,6 +478,7 @@ private:
462 478
463 bool is_signaled{}; 479 bool is_signaled{};
464 bool is_suspended{}; 480 bool is_suspended{};
481 bool is_initialized{};
465 482
466 std::atomic<s32> num_created_threads{}; 483 std::atomic<s32> num_created_threads{};
467 std::atomic<u16> num_threads{}; 484 std::atomic<u16> num_threads{};
@@ -474,9 +491,6 @@ private:
474 KThread* exception_thread{}; 491 KThread* exception_thread{};
475 492
476 KLightLock state_lock; 493 KLightLock state_lock;
477
478 /// System context
479 Core::System& system;
480}; 494};
481 495
482} // namespace Kernel 496} // namespace Kernel
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index dca1bcc92..7d676e5f7 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -342,7 +342,7 @@ static ResultCode ConnectToNamedPort32(Core::System& system, Handle* out_handle,
342static ResultCode SendSyncRequest(Core::System& system, Handle handle) { 342static ResultCode SendSyncRequest(Core::System& system, Handle handle) {
343 auto& kernel = system.Kernel(); 343 auto& kernel = system.Kernel();
344 const auto& handle_table = kernel.CurrentProcess()->GetHandleTable(); 344 const auto& handle_table = kernel.CurrentProcess()->GetHandleTable();
345 std::shared_ptr<ClientSession> session = handle_table.Get<ClientSession>(handle); 345 auto session = handle_table.Get<ClientSession>(handle);
346 if (!session) { 346 if (!session) {
347 LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); 347 LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle);
348 return ResultInvalidHandle; 348 return ResultInvalidHandle;
@@ -437,7 +437,7 @@ static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr ha
437 { 437 {
438 auto object = handle_table.Get<KSynchronizationObject>(handle); 438 auto object = handle_table.Get<KSynchronizationObject>(handle);
439 if (object) { 439 if (object) {
440 objects[i] = object.get(); 440 objects[i] = object;
441 succeeded = true; 441 succeeded = true;
442 } 442 }
443 } 443 }
@@ -1190,7 +1190,7 @@ static ResultCode QueryProcessMemory(Core::System& system, VAddr memory_info_add
1190 std::lock_guard lock{HLE::g_hle_lock}; 1190 std::lock_guard lock{HLE::g_hle_lock};
1191 LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address); 1191 LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address);
1192 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1192 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1193 std::shared_ptr<Process> process = handle_table.Get<Process>(process_handle); 1193 auto process = handle_table.Get<Process>(process_handle);
1194 if (!process) { 1194 if (!process) {
1195 LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", 1195 LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
1196 process_handle); 1196 process_handle);