summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorGravatar liamwhite2023-10-29 11:24:52 -0400
committerGravatar GitHub2023-10-29 11:24:52 -0400
commit6aee148b170e6886e58a3996f729b2cc87329e95 (patch)
tree39efd9469af6a922ee5f38d906940412333c1455 /src/core/hle/kernel/kernel.cpp
parentMerge pull request #11827 from liamwhite/preallocated (diff)
parentkernel: make sure new process is in list (diff)
downloadyuzu-6aee148b170e6886e58a3996f729b2cc87329e95.tar.gz
yuzu-6aee148b170e6886e58a3996f729b2cc87329e95.tar.xz
yuzu-6aee148b170e6886e58a3996f729b2cc87329e95.zip
Merge pull request #11843 from liamwhite/sync-process
kernel: update KProcess
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp53
1 files changed, 24 insertions, 29 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 24433d32b..4a1559291 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,
@@ -792,8 +788,8 @@ struct KernelCore::Impl {
792 std::mutex registered_in_use_objects_lock; 788 std::mutex registered_in_use_objects_lock;
793 789
794 std::atomic<u32> next_object_id{0}; 790 std::atomic<u32> next_object_id{0};
795 std::atomic<u64> next_kernel_process_id{KProcess::InitialKIPIDMin}; 791 std::atomic<u64> next_kernel_process_id{KProcess::InitialProcessIdMin};
796 std::atomic<u64> next_user_process_id{KProcess::ProcessIDMin}; 792 std::atomic<u64> next_user_process_id{KProcess::ProcessIdMin};
797 std::atomic<u64> next_thread_id{1}; 793 std::atomic<u64> next_thread_id{1};
798 794
799 // Lists all processes that exist in the current session. 795 // Lists all processes that exist in the current session.
@@ -924,10 +920,6 @@ const KProcess* KernelCore::ApplicationProcess() const {
924 return impl->application_process; 920 return impl->application_process;
925} 921}
926 922
927void KernelCore::CloseApplicationProcess() {
928 impl->CloseApplicationProcess();
929}
930
931const std::vector<KProcess*>& KernelCore::GetProcessList() const { 923const std::vector<KProcess*>& KernelCore::GetProcessList() const {
932 return impl->process_list; 924 return impl->process_list;
933} 925}
@@ -1128,8 +1120,8 @@ std::jthread KernelCore::RunOnHostCoreProcess(std::string&& process_name,
1128 std::function<void()> func) { 1120 std::function<void()> func) {
1129 // Make a new process. 1121 // Make a new process.
1130 KProcess* process = KProcess::Create(*this); 1122 KProcess* process = KProcess::Create(*this);
1131 ASSERT(R_SUCCEEDED(KProcess::Initialize(process, System(), "", KProcess::ProcessType::Userland, 1123 ASSERT(R_SUCCEEDED(
1132 GetSystemResourceLimit()))); 1124 process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
1133 1125
1134 // Ensure that we don't hold onto any extra references. 1126 // Ensure that we don't hold onto any extra references.
1135 SCOPE_EXIT({ process->Close(); }); 1127 SCOPE_EXIT({ process->Close(); });
@@ -1156,8 +1148,8 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function
1156 1148
1157 // Make a new process. 1149 // Make a new process.
1158 KProcess* process = KProcess::Create(*this); 1150 KProcess* process = KProcess::Create(*this);
1159 ASSERT(R_SUCCEEDED(KProcess::Initialize(process, System(), "", KProcess::ProcessType::Userland, 1151 ASSERT(R_SUCCEEDED(
1160 GetSystemResourceLimit()))); 1152 process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
1161 1153
1162 // Ensure that we don't hold onto any extra references. 1154 // Ensure that we don't hold onto any extra references.
1163 SCOPE_EXIT({ process->Close(); }); 1155 SCOPE_EXIT({ process->Close(); });
@@ -1266,7 +1258,8 @@ const Kernel::KSharedMemory& KernelCore::GetHidBusSharedMem() const {
1266 1258
1267void KernelCore::SuspendApplication(bool suspended) { 1259void KernelCore::SuspendApplication(bool suspended) {
1268 const bool should_suspend{exception_exited || suspended}; 1260 const bool should_suspend{exception_exited || suspended};
1269 const auto activity = should_suspend ? ProcessActivity::Paused : ProcessActivity::Runnable; 1261 const auto activity =
1262 should_suspend ? Svc::ProcessActivity::Paused : Svc::ProcessActivity::Runnable;
1270 1263
1271 // Get the application process. 1264 // Get the application process.
1272 KScopedAutoObject<KProcess> process = ApplicationProcess(); 1265 KScopedAutoObject<KProcess> process = ApplicationProcess();
@@ -1300,6 +1293,8 @@ void KernelCore::SuspendApplication(bool suspended) {
1300} 1293}
1301 1294
1302void KernelCore::ShutdownCores() { 1295void KernelCore::ShutdownCores() {
1296 impl->TerminateApplicationProcess();
1297
1303 KScopedSchedulerLock lk{*this}; 1298 KScopedSchedulerLock lk{*this};
1304 1299
1305 for (auto* thread : impl->shutdown_threads) { 1300 for (auto* thread : impl->shutdown_threads) {