summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorGravatar Liam2023-10-21 16:47:43 -0400
committerGravatar Liam2023-10-21 20:03:41 -0400
commit8c59543ee32c8bff575bab7ec1e70f76f8eda437 (patch)
treeafeee77ba66daf7ec6bff18515c8fbf1bb8468e0 /src/core/hle/kernel/kernel.cpp
parentMerge pull request #11831 from liamwhite/hosversionbetween (diff)
downloadyuzu-8c59543ee32c8bff575bab7ec1e70f76f8eda437.tar.gz
yuzu-8c59543ee32c8bff575bab7ec1e70f76f8eda437.tar.xz
yuzu-8c59543ee32c8bff575bab7ec1e70f76f8eda437.zip
kernel: update KProcess
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp54
1 files changed, 25 insertions, 29 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 24433d32b..ac76c71a8 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -101,35 +101,31 @@ struct KernelCore::Impl {
101 101
102 void InitializeCores() { 102 void InitializeCores() {
103 for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { 103 for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) {
104 cores[core_id]->Initialize((*application_process).Is64BitProcess()); 104 cores[core_id]->Initialize((*application_process).Is64Bit());
105 system.ApplicationMemory().SetCurrentPageTable(*application_process, core_id); 105 system.ApplicationMemory().SetCurrentPageTable(*application_process, core_id);
106 } 106 }
107 } 107 }
108 108
109 void CloseApplicationProcess() { 109 void TerminateApplicationProcess() {
110 KProcess* old_process = application_process.exchange(nullptr); 110 application_process.load()->Terminate();
111 if (old_process == nullptr) {
112 return;
113 }
114
115 // old_process->Close();
116 // TODO: The process should be destroyed based on accurate ref counting after
117 // calling Close(). Adding a manual Destroy() call instead to avoid a memory leak.
118 old_process->Finalize();
119 old_process->Destroy();
120 } 111 }
121 112
122 void Shutdown() { 113 void Shutdown() {
123 is_shutting_down.store(true, std::memory_order_relaxed); 114 is_shutting_down.store(true, std::memory_order_relaxed);
124 SCOPE_EXIT({ is_shutting_down.store(false, std::memory_order_relaxed); }); 115 SCOPE_EXIT({ is_shutting_down.store(false, std::memory_order_relaxed); });
125 116
126 process_list.clear();
127
128 CloseServices(); 117 CloseServices();
129 118
119 auto* old_process = application_process.exchange(nullptr);
120 if (old_process) {
121 old_process->Close();
122 }
123
124 process_list.clear();
125
130 next_object_id = 0; 126 next_object_id = 0;
131 next_kernel_process_id = KProcess::InitialKIPIDMin; 127 next_kernel_process_id = KProcess::InitialProcessIdMin;
132 next_user_process_id = KProcess::ProcessIDMin; 128 next_user_process_id = KProcess::ProcessIdMin;
133 next_thread_id = 1; 129 next_thread_id = 1;
134 130
135 global_handle_table->Finalize(); 131 global_handle_table->Finalize();
@@ -176,8 +172,6 @@ struct KernelCore::Impl {
176 } 172 }
177 } 173 }
178 174
179 CloseApplicationProcess();
180
181 // Track kernel objects that were not freed on shutdown 175 // Track kernel objects that were not freed on shutdown
182 { 176 {
183 std::scoped_lock lk{registered_objects_lock}; 177 std::scoped_lock lk{registered_objects_lock};
@@ -344,6 +338,8 @@ struct KernelCore::Impl {
344 // Create the system page table managers. 338 // Create the system page table managers.
345 app_system_resource = std::make_unique<KSystemResource>(kernel); 339 app_system_resource = std::make_unique<KSystemResource>(kernel);
346 sys_system_resource = std::make_unique<KSystemResource>(kernel); 340 sys_system_resource = std::make_unique<KSystemResource>(kernel);
341 KAutoObject::Create(std::addressof(*app_system_resource));
342 KAutoObject::Create(std::addressof(*sys_system_resource));
347 343
348 // Set the managers for the system resources. 344 // Set the managers for the system resources.
349 app_system_resource->SetManagers(*app_memory_block_manager, *app_block_info_manager, 345 app_system_resource->SetManagers(*app_memory_block_manager, *app_block_info_manager,
@@ -368,6 +364,7 @@ struct KernelCore::Impl {
368 364
369 void MakeApplicationProcess(KProcess* process) { 365 void MakeApplicationProcess(KProcess* process) {
370 application_process = process; 366 application_process = process;
367 application_process.load()->Open();
371 } 368 }
372 369
373 static inline thread_local u8 host_thread_id = UINT8_MAX; 370 static inline thread_local u8 host_thread_id = UINT8_MAX;
@@ -792,8 +789,8 @@ struct KernelCore::Impl {
792 std::mutex registered_in_use_objects_lock; 789 std::mutex registered_in_use_objects_lock;
793 790
794 std::atomic<u32> next_object_id{0}; 791 std::atomic<u32> next_object_id{0};
795 std::atomic<u64> next_kernel_process_id{KProcess::InitialKIPIDMin}; 792 std::atomic<u64> next_kernel_process_id{KProcess::InitialProcessIdMin};
796 std::atomic<u64> next_user_process_id{KProcess::ProcessIDMin}; 793 std::atomic<u64> next_user_process_id{KProcess::ProcessIdMin};
797 std::atomic<u64> next_thread_id{1}; 794 std::atomic<u64> next_thread_id{1};
798 795
799 // Lists all processes that exist in the current session. 796 // Lists all processes that exist in the current session.
@@ -924,10 +921,6 @@ const KProcess* KernelCore::ApplicationProcess() const {
924 return impl->application_process; 921 return impl->application_process;
925} 922}
926 923
927void KernelCore::CloseApplicationProcess() {
928 impl->CloseApplicationProcess();
929}
930
931const std::vector<KProcess*>& KernelCore::GetProcessList() const { 924const std::vector<KProcess*>& KernelCore::GetProcessList() const {
932 return impl->process_list; 925 return impl->process_list;
933} 926}
@@ -1128,8 +1121,8 @@ std::jthread KernelCore::RunOnHostCoreProcess(std::string&& process_name,
1128 std::function<void()> func) { 1121 std::function<void()> func) {
1129 // Make a new process. 1122 // Make a new process.
1130 KProcess* process = KProcess::Create(*this); 1123 KProcess* process = KProcess::Create(*this);
1131 ASSERT(R_SUCCEEDED(KProcess::Initialize(process, System(), "", KProcess::ProcessType::Userland, 1124 ASSERT(R_SUCCEEDED(
1132 GetSystemResourceLimit()))); 1125 process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
1133 1126
1134 // Ensure that we don't hold onto any extra references. 1127 // Ensure that we don't hold onto any extra references.
1135 SCOPE_EXIT({ process->Close(); }); 1128 SCOPE_EXIT({ process->Close(); });
@@ -1156,8 +1149,8 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function
1156 1149
1157 // Make a new process. 1150 // Make a new process.
1158 KProcess* process = KProcess::Create(*this); 1151 KProcess* process = KProcess::Create(*this);
1159 ASSERT(R_SUCCEEDED(KProcess::Initialize(process, System(), "", KProcess::ProcessType::Userland, 1152 ASSERT(R_SUCCEEDED(
1160 GetSystemResourceLimit()))); 1153 process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
1161 1154
1162 // Ensure that we don't hold onto any extra references. 1155 // Ensure that we don't hold onto any extra references.
1163 SCOPE_EXIT({ process->Close(); }); 1156 SCOPE_EXIT({ process->Close(); });
@@ -1266,7 +1259,8 @@ const Kernel::KSharedMemory& KernelCore::GetHidBusSharedMem() const {
1266 1259
1267void KernelCore::SuspendApplication(bool suspended) { 1260void KernelCore::SuspendApplication(bool suspended) {
1268 const bool should_suspend{exception_exited || suspended}; 1261 const bool should_suspend{exception_exited || suspended};
1269 const auto activity = should_suspend ? ProcessActivity::Paused : ProcessActivity::Runnable; 1262 const auto activity =
1263 should_suspend ? Svc::ProcessActivity::Paused : Svc::ProcessActivity::Runnable;
1270 1264
1271 // Get the application process. 1265 // Get the application process.
1272 KScopedAutoObject<KProcess> process = ApplicationProcess(); 1266 KScopedAutoObject<KProcess> process = ApplicationProcess();
@@ -1300,6 +1294,8 @@ void KernelCore::SuspendApplication(bool suspended) {
1300} 1294}
1301 1295
1302void KernelCore::ShutdownCores() { 1296void KernelCore::ShutdownCores() {
1297 impl->TerminateApplicationProcess();
1298
1303 KScopedSchedulerLock lk{*this}; 1299 KScopedSchedulerLock lk{*this};
1304 1300
1305 for (auto* thread : impl->shutdown_threads) { 1301 for (auto* thread : impl->shutdown_threads) {