summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-11-02 04:11:30 +0100
committerGitHub <noreply@github.com>2021-11-02 04:11:30 +0100
commitb118fa8698dbe0e2b6e663c1c37a7eac03422905 (patch)
tree14864116c00d385abba61ad2330c1c0f50e4b961 /src/core/hle/kernel/kernel.cpp
parentMerge pull request #7264 from zhaobot/tx-update-20211101021628 (diff)
parentFix dangling kernel objects when exiting (diff)
downloadyuzu-b118fa8698dbe0e2b6e663c1c37a7eac03422905.tar
yuzu-b118fa8698dbe0e2b6e663c1c37a7eac03422905.tar.gz
yuzu-b118fa8698dbe0e2b6e663c1c37a7eac03422905.tar.bz2
yuzu-b118fa8698dbe0e2b6e663c1c37a7eac03422905.tar.lz
yuzu-b118fa8698dbe0e2b6e663c1c37a7eac03422905.tar.xz
yuzu-b118fa8698dbe0e2b6e663c1c37a7eac03422905.tar.zst
yuzu-b118fa8698dbe0e2b6e663c1c37a7eac03422905.zip
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index bea945301..4a139c5e7 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -91,12 +91,6 @@ struct KernelCore::Impl {
}
void Shutdown() {
- // Shutdown all processes.
- if (current_process) {
- current_process->Finalize();
- current_process->Close();
- current_process = nullptr;
- }
process_list.clear();
// Close all open server ports.
@@ -170,6 +164,24 @@ struct KernelCore::Impl {
// Next host thead ID to use, 0-3 IDs represent core threads, >3 represent others
next_host_thread_id = Core::Hardware::NUM_CPU_CORES;
+ // Close kernel objects that were not freed on shutdown
+ {
+ std::lock_guard lk(registered_in_use_objects_lock);
+ if (registered_in_use_objects.size()) {
+ for (auto& object : registered_in_use_objects) {
+ object->Close();
+ }
+ registered_in_use_objects.clear();
+ }
+ }
+
+ // Shutdown all processes.
+ if (current_process) {
+ current_process->Finalize();
+ current_process->Close();
+ current_process = nullptr;
+ }
+
// Track kernel objects that were not freed on shutdown
{
std::lock_guard lk(registered_objects_lock);
@@ -714,9 +726,11 @@ struct KernelCore::Impl {
std::unordered_set<KServerPort*> server_ports;
std::unordered_set<KServerSession*> server_sessions;
std::unordered_set<KAutoObject*> registered_objects;
+ std::unordered_set<KAutoObject*> registered_in_use_objects;
std::mutex server_ports_lock;
std::mutex server_sessions_lock;
std::mutex registered_objects_lock;
+ std::mutex registered_in_use_objects_lock;
std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor;
std::vector<Kernel::PhysicalCore> cores;
@@ -928,6 +942,16 @@ void KernelCore::UnregisterKernelObject(KAutoObject* object) {
impl->registered_objects.erase(object);
}
+void KernelCore::RegisterInUseObject(KAutoObject* object) {
+ std::lock_guard lk(impl->registered_in_use_objects_lock);
+ impl->registered_in_use_objects.insert(object);
+}
+
+void KernelCore::UnregisterInUseObject(KAutoObject* object) {
+ std::lock_guard lk(impl->registered_in_use_objects_lock);
+ impl->registered_in_use_objects.erase(object);
+}
+
bool KernelCore::IsValidNamedPort(NamedPortTable::const_iterator port) const {
return port != impl->named_ports.cend();
}