summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_auto_object.cpp9
-rw-r--r--src/core/hle/kernel/k_auto_object.h12
-rw-r--r--src/core/hle/kernel/kernel.cpp16
-rw-r--r--src/core/hle/kernel/kernel.h8
4 files changed, 43 insertions, 2 deletions
diff --git a/src/core/hle/kernel/k_auto_object.cpp b/src/core/hle/kernel/k_auto_object.cpp
index dbe237f09..c99a9ebb7 100644
--- a/src/core/hle/kernel/k_auto_object.cpp
+++ b/src/core/hle/kernel/k_auto_object.cpp
@@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include "core/hle/kernel/k_auto_object.h"
+#include "core/hle/kernel/kernel.h"
namespace Kernel {
@@ -11,4 +12,12 @@ KAutoObject* KAutoObject::Create(KAutoObject* obj) {
return obj;
}
+void KAutoObject::RegisterWithKernel() {
+ kernel.RegisterKernelObject(this);
+}
+
+void KAutoObject::UnregisterWithKernel() {
+ kernel.UnregisterKernelObject(this);
+}
+
} // namespace Kernel
diff --git a/src/core/hle/kernel/k_auto_object.h b/src/core/hle/kernel/k_auto_object.h
index 88a052f65..e4fcdbc67 100644
--- a/src/core/hle/kernel/k_auto_object.h
+++ b/src/core/hle/kernel/k_auto_object.h
@@ -85,8 +85,12 @@ private:
KERNEL_AUTOOBJECT_TRAITS(KAutoObject, KAutoObject);
public:
- explicit KAutoObject(KernelCore& kernel_) : kernel(kernel_) {}
- virtual ~KAutoObject() = default;
+ explicit KAutoObject(KernelCore& kernel_) : kernel(kernel_) {
+ RegisterWithKernel();
+ }
+ virtual ~KAutoObject() {
+ UnregisterWithKernel();
+ }
static KAutoObject* Create(KAutoObject* ptr);
@@ -166,6 +170,10 @@ public:
}
}
+private:
+ void RegisterWithKernel();
+ void UnregisterWithKernel();
+
protected:
KernelCore& kernel;
std::string name;
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 64bd0c494..ee60072c2 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -142,6 +142,13 @@ 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;
+
+ // Track kernel objects that were not freed on shutdown
+ if (registered_objects.size()) {
+ LOG_WARNING(Kernel, "{} kernel objects were dangling on shutdown!",
+ registered_objects.size());
+ registered_objects.clear();
+ }
}
void InitializePhysicalCores() {
@@ -656,6 +663,7 @@ struct KernelCore::Impl {
/// the ConnectToPort SVC.
std::unordered_map<std::string, ServiceInterfaceFactory> service_interface_factory;
NamedPortTable named_ports;
+ std::unordered_set<KAutoObject*> registered_objects;
std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor;
std::vector<Kernel::PhysicalCore> cores;
@@ -852,6 +860,14 @@ KClientPort* KernelCore::CreateNamedServicePort(std::string name) {
return &search->second(impl->system.ServiceManager(), impl->system);
}
+void KernelCore::RegisterKernelObject(KAutoObject* object) {
+ impl->registered_objects.insert(object);
+}
+
+void KernelCore::UnregisterKernelObject(KAutoObject* object) {
+ impl->registered_objects.erase(object);
+}
+
bool KernelCore::IsValidNamedPort(NamedPortTable::const_iterator port) const {
return port != impl->named_ports.cend();
}
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 2d01e1ae0..b669ca74e 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -185,6 +185,14 @@ public:
/// Opens a port to a service previously registered with RegisterNamedService.
KClientPort* CreateNamedServicePort(std::string name);
+ /// Registers all kernel objects with the global emulation state, this is purely for tracking
+ /// leaks after emulation has been shutdown.
+ void RegisterKernelObject(KAutoObject* object);
+
+ /// Unregisters a kernel object previously registered with RegisterKernelObject when it was
+ /// destroyed during the current emulation session.
+ void UnregisterKernelObject(KAutoObject* object);
+
/// Determines whether or not the given port is a valid named port.
bool IsValidNamedPort(NamedPortTable::const_iterator port) const;