diff options
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 4f3366c9d..f33600ca5 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -95,7 +95,7 @@ struct KernelCore::Impl { | |||
| 95 | pt_heap_region.GetSize()); | 95 | pt_heap_region.GetSize()); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | InitializeHackSharedMemory(); | 98 | InitializeHackSharedMemory(kernel); |
| 99 | RegisterHostThread(nullptr); | 99 | RegisterHostThread(nullptr); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| @@ -216,10 +216,12 @@ struct KernelCore::Impl { | |||
| 216 | auto* main_thread{Kernel::KThread::Create(system.Kernel())}; | 216 | auto* main_thread{Kernel::KThread::Create(system.Kernel())}; |
| 217 | main_thread->SetCurrentCore(core); | 217 | main_thread->SetCurrentCore(core); |
| 218 | ASSERT(Kernel::KThread::InitializeMainThread(system, main_thread, core).IsSuccess()); | 218 | ASSERT(Kernel::KThread::InitializeMainThread(system, main_thread, core).IsSuccess()); |
| 219 | KThread::Register(system.Kernel(), main_thread); | ||
| 219 | 220 | ||
| 220 | auto* idle_thread{Kernel::KThread::Create(system.Kernel())}; | 221 | auto* idle_thread{Kernel::KThread::Create(system.Kernel())}; |
| 221 | idle_thread->SetCurrentCore(core); | 222 | idle_thread->SetCurrentCore(core); |
| 222 | ASSERT(Kernel::KThread::InitializeIdleThread(system, idle_thread, core).IsSuccess()); | 223 | ASSERT(Kernel::KThread::InitializeIdleThread(system, idle_thread, core).IsSuccess()); |
| 224 | KThread::Register(system.Kernel(), idle_thread); | ||
| 223 | 225 | ||
| 224 | schedulers[i]->Initialize(main_thread, idle_thread, core); | 226 | schedulers[i]->Initialize(main_thread, idle_thread, core); |
| 225 | } | 227 | } |
| @@ -230,6 +232,7 @@ struct KernelCore::Impl { | |||
| 230 | const Core::Timing::CoreTiming& core_timing) { | 232 | const Core::Timing::CoreTiming& core_timing) { |
| 231 | system_resource_limit = KResourceLimit::Create(system.Kernel()); | 233 | system_resource_limit = KResourceLimit::Create(system.Kernel()); |
| 232 | system_resource_limit->Initialize(&core_timing); | 234 | system_resource_limit->Initialize(&core_timing); |
| 235 | KResourceLimit::Register(kernel, system_resource_limit); | ||
| 233 | 236 | ||
| 234 | const auto sizes{memory_layout->GetTotalAndKernelMemorySizes()}; | 237 | const auto sizes{memory_layout->GetTotalAndKernelMemorySizes()}; |
| 235 | const auto total_size{sizes.first}; | 238 | const auto total_size{sizes.first}; |
| @@ -355,6 +358,7 @@ struct KernelCore::Impl { | |||
| 355 | ASSERT(KThread::InitializeHighPriorityThread(system, shutdown_threads[core_id], {}, {}, | 358 | ASSERT(KThread::InitializeHighPriorityThread(system, shutdown_threads[core_id], {}, {}, |
| 356 | core_id) | 359 | core_id) |
| 357 | .IsSuccess()); | 360 | .IsSuccess()); |
| 361 | KThread::Register(system.Kernel(), shutdown_threads[core_id]); | ||
| 358 | } | 362 | } |
| 359 | } | 363 | } |
| 360 | 364 | ||
| @@ -729,7 +733,7 @@ struct KernelCore::Impl { | |||
| 729 | memory_manager->Initialize(management_region.GetAddress(), management_region.GetSize()); | 733 | memory_manager->Initialize(management_region.GetAddress(), management_region.GetSize()); |
| 730 | } | 734 | } |
| 731 | 735 | ||
| 732 | void InitializeHackSharedMemory() { | 736 | void InitializeHackSharedMemory(KernelCore& kernel) { |
| 733 | // Setup memory regions for emulated processes | 737 | // Setup memory regions for emulated processes |
| 734 | // TODO(bunnei): These should not be hardcoded regions initialized within the kernel | 738 | // TODO(bunnei): These should not be hardcoded regions initialized within the kernel |
| 735 | constexpr std::size_t hid_size{0x40000}; | 739 | constexpr std::size_t hid_size{0x40000}; |
| @@ -746,14 +750,23 @@ struct KernelCore::Impl { | |||
| 746 | 750 | ||
| 747 | hid_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, | 751 | hid_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, |
| 748 | Svc::MemoryPermission::Read, hid_size); | 752 | Svc::MemoryPermission::Read, hid_size); |
| 753 | KSharedMemory::Register(kernel, hid_shared_mem); | ||
| 754 | |||
| 749 | font_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, | 755 | font_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, |
| 750 | Svc::MemoryPermission::Read, font_size); | 756 | Svc::MemoryPermission::Read, font_size); |
| 757 | KSharedMemory::Register(kernel, font_shared_mem); | ||
| 758 | |||
| 751 | irs_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, | 759 | irs_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, |
| 752 | Svc::MemoryPermission::Read, irs_size); | 760 | Svc::MemoryPermission::Read, irs_size); |
| 761 | KSharedMemory::Register(kernel, irs_shared_mem); | ||
| 762 | |||
| 753 | time_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, | 763 | time_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, |
| 754 | Svc::MemoryPermission::Read, time_size); | 764 | Svc::MemoryPermission::Read, time_size); |
| 765 | KSharedMemory::Register(kernel, time_shared_mem); | ||
| 766 | |||
| 755 | hidbus_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, | 767 | hidbus_shared_mem->Initialize(system.DeviceMemory(), nullptr, Svc::MemoryPermission::None, |
| 756 | Svc::MemoryPermission::Read, hidbus_size); | 768 | Svc::MemoryPermission::Read, hidbus_size); |
| 769 | KSharedMemory::Register(kernel, hidbus_shared_mem); | ||
| 757 | } | 770 | } |
| 758 | 771 | ||
| 759 | std::mutex registered_objects_lock; | 772 | std::mutex registered_objects_lock; |
| @@ -1072,12 +1085,15 @@ static std::jthread RunHostThreadFunc(KernelCore& kernel, KProcess* process, | |||
| 1072 | // Commit the thread reservation. | 1085 | // Commit the thread reservation. |
| 1073 | thread_reservation.Commit(); | 1086 | thread_reservation.Commit(); |
| 1074 | 1087 | ||
| 1088 | // Register the thread. | ||
| 1089 | KThread::Register(kernel, thread); | ||
| 1090 | |||
| 1075 | return std::jthread( | 1091 | return std::jthread( |
| 1076 | [&kernel, thread, thread_name{std::move(thread_name)}, func{std::move(func)}] { | 1092 | [&kernel, thread, thread_name{std::move(thread_name)}, func{std::move(func)}] { |
| 1077 | // Set the thread name. | 1093 | // Set the thread name. |
| 1078 | Common::SetCurrentThreadName(thread_name.c_str()); | 1094 | Common::SetCurrentThreadName(thread_name.c_str()); |
| 1079 | 1095 | ||
| 1080 | // Register the thread. | 1096 | // Set the thread as current. |
| 1081 | kernel.RegisterHostThread(thread); | 1097 | kernel.RegisterHostThread(thread); |
| 1082 | 1098 | ||
| 1083 | // Run the callback. | 1099 | // Run the callback. |
| @@ -1099,6 +1115,9 @@ std::jthread KernelCore::RunOnHostCoreProcess(std::string&& process_name, | |||
| 1099 | // Ensure that we don't hold onto any extra references. | 1115 | // Ensure that we don't hold onto any extra references. |
| 1100 | SCOPE_EXIT({ process->Close(); }); | 1116 | SCOPE_EXIT({ process->Close(); }); |
| 1101 | 1117 | ||
| 1118 | // Register the new process. | ||
| 1119 | KProcess::Register(*this, process); | ||
| 1120 | |||
| 1102 | // Run the host thread. | 1121 | // Run the host thread. |
| 1103 | return RunHostThreadFunc(*this, process, std::move(process_name), std::move(func)); | 1122 | return RunHostThreadFunc(*this, process, std::move(process_name), std::move(func)); |
| 1104 | } | 1123 | } |
| @@ -1124,6 +1143,9 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function | |||
| 1124 | // Ensure that we don't hold onto any extra references. | 1143 | // Ensure that we don't hold onto any extra references. |
| 1125 | SCOPE_EXIT({ process->Close(); }); | 1144 | SCOPE_EXIT({ process->Close(); }); |
| 1126 | 1145 | ||
| 1146 | // Register the new process. | ||
| 1147 | KProcess::Register(*this, process); | ||
| 1148 | |||
| 1127 | // Reserve a new thread from the process resource limit. | 1149 | // Reserve a new thread from the process resource limit. |
| 1128 | KScopedResourceReservation thread_reservation(process, LimitableResource::ThreadCountMax); | 1150 | KScopedResourceReservation thread_reservation(process, LimitableResource::ThreadCountMax); |
| 1129 | ASSERT(thread_reservation.Succeeded()); | 1151 | ASSERT(thread_reservation.Succeeded()); |
| @@ -1136,6 +1158,9 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function | |||
| 1136 | // Commit the thread reservation. | 1158 | // Commit the thread reservation. |
| 1137 | thread_reservation.Commit(); | 1159 | thread_reservation.Commit(); |
| 1138 | 1160 | ||
| 1161 | // Register the new thread. | ||
| 1162 | KThread::Register(*this, thread); | ||
| 1163 | |||
| 1139 | // Begin running the thread. | 1164 | // Begin running the thread. |
| 1140 | ASSERT(R_SUCCEEDED(thread->Run())); | 1165 | ASSERT(R_SUCCEEDED(thread->Run())); |
| 1141 | } | 1166 | } |