summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2018-08-03 00:28:43 -0400
committerGravatar GitHub2018-08-03 00:28:43 -0400
commit4c3c608d59b8c8d8a9bbccc1b55efcab346e650f (patch)
tree90f6325f37efcb09c79cfa2f84eb82157d4592a7
parentMerge pull request #904 from lioncash/static (diff)
parentkernel: Move object class to its own source files (diff)
downloadyuzu-4c3c608d59b8c8d8a9bbccc1b55efcab346e650f.tar.gz
yuzu-4c3c608d59b8c8d8a9bbccc1b55efcab346e650f.tar.xz
yuzu-4c3c608d59b8c8d8a9bbccc1b55efcab346e650f.zip
Merge pull request #894 from lioncash/object
kernel: Move object class to its own source files
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/core.cpp1
-rw-r--r--src/core/core.h2
-rw-r--r--src/core/core_cpu.cpp1
-rw-r--r--src/core/gdbstub/gdbstub.cpp1
-rw-r--r--src/core/hle/ipc_helpers.h7
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp2
-rw-r--r--src/core/hle/kernel/client_port.cpp2
-rw-r--r--src/core/hle/kernel/client_port.h2
-rw-r--r--src/core/hle/kernel/client_session.h2
-rw-r--r--src/core/hle/kernel/event.cpp2
-rw-r--r--src/core/hle/kernel/event.h2
-rw-r--r--src/core/hle/kernel/handle_table.cpp1
-rw-r--r--src/core/hle/kernel/handle_table.h2
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp6
-rw-r--r--src/core/hle/kernel/hle_ipc.h2
-rw-r--r--src/core/hle/kernel/kernel.h110
-rw-r--r--src/core/hle/kernel/mutex.cpp2
-rw-r--r--src/core/hle/kernel/mutex.h2
-rw-r--r--src/core/hle/kernel/object.cpp35
-rw-r--r--src/core/hle/kernel/object.h100
-rw-r--r--src/core/hle/kernel/process.h2
-rw-r--r--src/core/hle/kernel/resource_limit.h2
-rw-r--r--src/core/hle/kernel/scheduler.h1
-rw-r--r--src/core/hle/kernel/server_port.cpp2
-rw-r--r--src/core/hle/kernel/server_port.h2
-rw-r--r--src/core/hle/kernel/server_session.h2
-rw-r--r--src/core/hle/kernel/session.h2
-rw-r--r--src/core/hle/kernel/shared_memory.h2
-rw-r--r--src/core/hle/kernel/thread.cpp2
-rw-r--r--src/core/hle/kernel/thread.h2
-rw-r--r--src/core/hle/kernel/timer.cpp2
-rw-r--r--src/core/hle/kernel/timer.h2
-rw-r--r--src/core/hle/kernel/wait_object.cpp3
-rw-r--r--src/core/hle/kernel/wait_object.h2
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue.cpp5
-rw-r--r--src/core/hle/service/service.h3
-rw-r--r--src/core/hle/service/sm/sm.h8
-rw-r--r--src/core/loader/deconstructed_rom_directory.h2
-rw-r--r--src/core/loader/loader.h2
-rw-r--r--src/core/loader/nca.h2
-rw-r--r--src/core/loader/nro.h2
-rw-r--r--src/core/loader/nso.h2
-rw-r--r--src/yuzu/debugger/wait_tree.h2
44 files changed, 186 insertions, 156 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index a85397450..d29f6a84f 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -67,6 +67,8 @@ add_library(core STATIC
67 hle/kernel/memory.h 67 hle/kernel/memory.h
68 hle/kernel/mutex.cpp 68 hle/kernel/mutex.cpp
69 hle/kernel/mutex.h 69 hle/kernel/mutex.h
70 hle/kernel/object.cpp
71 hle/kernel/object.h
70 hle/kernel/process.cpp 72 hle/kernel/process.cpp
71 hle/kernel/process.h 73 hle/kernel/process.h
72 hle/kernel/resource_limit.cpp 74 hle/kernel/resource_limit.cpp
diff --git a/src/core/core.cpp b/src/core/core.cpp
index dd845a78a..32551094d 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -16,7 +16,6 @@
16#include "core/hle/service/sm/controller.h" 16#include "core/hle/service/sm/controller.h"
17#include "core/hle/service/sm/sm.h" 17#include "core/hle/service/sm/sm.h"
18#include "core/loader/loader.h" 18#include "core/loader/loader.h"
19#include "core/memory_setup.h"
20#include "core/settings.h" 19#include "core/settings.h"
21#include "file_sys/vfs_real.h" 20#include "file_sys/vfs_real.h"
22#include "video_core/video_core.h" 21#include "video_core/video_core.h"
diff --git a/src/core/core.h b/src/core/core.h
index c123fe401..3355604e4 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -11,7 +11,7 @@
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "core/arm/exclusive_monitor.h" 12#include "core/arm/exclusive_monitor.h"
13#include "core/core_cpu.h" 13#include "core/core_cpu.h"
14#include "core/hle/kernel/kernel.h" 14#include "core/hle/kernel/object.h"
15#include "core/hle/kernel/scheduler.h" 15#include "core/hle/kernel/scheduler.h"
16#include "core/loader/loader.h" 16#include "core/loader/loader.h"
17#include "core/memory.h" 17#include "core/memory.h"
diff --git a/src/core/core_cpu.cpp b/src/core/core_cpu.cpp
index 54e15a701..46a522fcd 100644
--- a/src/core/core_cpu.cpp
+++ b/src/core/core_cpu.cpp
@@ -12,7 +12,6 @@
12#include "core/arm/unicorn/arm_unicorn.h" 12#include "core/arm/unicorn/arm_unicorn.h"
13#include "core/core_cpu.h" 13#include "core/core_cpu.h"
14#include "core/core_timing.h" 14#include "core/core_timing.h"
15#include "core/hle/kernel/kernel.h"
16#include "core/hle/kernel/scheduler.h" 15#include "core/hle/kernel/scheduler.h"
17#include "core/hle/kernel/thread.h" 16#include "core/hle/kernel/thread.h"
18#include "core/settings.h" 17#include "core/settings.h"
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index 5ca573652..75f6b8235 100644
--- a/src/core/gdbstub/gdbstub.cpp
+++ b/src/core/gdbstub/gdbstub.cpp
@@ -37,7 +37,6 @@
37#include "core/core.h" 37#include "core/core.h"
38#include "core/core_cpu.h" 38#include "core/core_cpu.h"
39#include "core/gdbstub/gdbstub.h" 39#include "core/gdbstub/gdbstub.h"
40#include "core/hle/kernel/kernel.h"
41#include "core/hle/kernel/scheduler.h" 40#include "core/hle/kernel/scheduler.h"
42#include "core/loader/loader.h" 41#include "core/loader/loader.h"
43#include "core/memory.h" 42#include "core/memory.h"
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h
index 7fb0da408..d3a734831 100644
--- a/src/core/hle/ipc_helpers.h
+++ b/src/core/hle/ipc_helpers.h
@@ -5,15 +5,18 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <cstring>
9#include <memory>
8#include <tuple> 10#include <tuple>
9#include <type_traits> 11#include <type_traits>
10#include <utility> 12#include <utility>
13#include "common/assert.h"
14#include "common/common_types.h"
11#include "core/hle/ipc.h" 15#include "core/hle/ipc.h"
12#include "core/hle/kernel/client_port.h" 16#include "core/hle/kernel/client_port.h"
13#include "core/hle/kernel/client_session.h" 17#include "core/hle/kernel/client_session.h"
14#include "core/hle/kernel/handle_table.h"
15#include "core/hle/kernel/hle_ipc.h" 18#include "core/hle/kernel/hle_ipc.h"
16#include "core/hle/kernel/kernel.h" 19#include "core/hle/kernel/object.h"
17#include "core/hle/kernel/server_port.h" 20#include "core/hle/kernel/server_port.h"
18 21
19namespace IPC { 22namespace IPC {
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index 6a10efab1..7a17ed162 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -9,7 +9,7 @@
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/core.h" 10#include "core/core.h"
11#include "core/hle/kernel/errors.h" 11#include "core/hle/kernel/errors.h"
12#include "core/hle/kernel/kernel.h" 12#include "core/hle/kernel/object.h"
13#include "core/hle/kernel/process.h" 13#include "core/hle/kernel/process.h"
14#include "core/hle/kernel/thread.h" 14#include "core/hle/kernel/thread.h"
15#include "core/hle/result.h" 15#include "core/hle/result.h"
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp
index 2d6051e8b..7933c105c 100644
--- a/src/core/hle/kernel/client_port.cpp
+++ b/src/core/hle/kernel/client_port.cpp
@@ -8,7 +8,7 @@
8#include "core/hle/kernel/client_session.h" 8#include "core/hle/kernel/client_session.h"
9#include "core/hle/kernel/errors.h" 9#include "core/hle/kernel/errors.h"
10#include "core/hle/kernel/hle_ipc.h" 10#include "core/hle/kernel/hle_ipc.h"
11#include "core/hle/kernel/kernel.h" 11#include "core/hle/kernel/object.h"
12#include "core/hle/kernel/server_port.h" 12#include "core/hle/kernel/server_port.h"
13#include "core/hle/kernel/server_session.h" 13#include "core/hle/kernel/server_session.h"
14 14
diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h
index a829aeb6d..b42c94bde 100644
--- a/src/core/hle/kernel/client_port.h
+++ b/src/core/hle/kernel/client_port.h
@@ -6,7 +6,7 @@
6 6
7#include <string> 7#include <string>
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "core/hle/kernel/kernel.h" 9#include "core/hle/kernel/object.h"
10#include "core/hle/result.h" 10#include "core/hle/result.h"
11 11
12namespace Kernel { 12namespace Kernel {
diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h
index 2258f95bc..dabd93ed7 100644
--- a/src/core/hle/kernel/client_session.h
+++ b/src/core/hle/kernel/client_session.h
@@ -7,7 +7,7 @@
7#include <memory> 7#include <memory>
8#include <string> 8#include <string>
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/object.h"
11#include "core/hle/result.h" 11#include "core/hle/result.h"
12 12
13namespace Kernel { 13namespace Kernel {
diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp
index 37e0766c3..5623c4b6a 100644
--- a/src/core/hle/kernel/event.cpp
+++ b/src/core/hle/kernel/event.cpp
@@ -5,7 +5,7 @@
5#include <algorithm> 5#include <algorithm>
6#include "common/assert.h" 6#include "common/assert.h"
7#include "core/hle/kernel/event.h" 7#include "core/hle/kernel/event.h"
8#include "core/hle/kernel/kernel.h" 8#include "core/hle/kernel/object.h"
9#include "core/hle/kernel/thread.h" 9#include "core/hle/kernel/thread.h"
10 10
11namespace Kernel { 11namespace Kernel {
diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h
index e5c924a75..1c99911b2 100644
--- a/src/core/hle/kernel/event.h
+++ b/src/core/hle/kernel/event.h
@@ -5,7 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "core/hle/kernel/kernel.h" 8#include "core/hle/kernel/object.h"
9#include "core/hle/kernel/wait_object.h" 9#include "core/hle/kernel/wait_object.h"
10 10
11namespace Kernel { 11namespace Kernel {
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index 7dd67f80f..28e21428a 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -8,7 +8,6 @@
8#include "core/core.h" 8#include "core/core.h"
9#include "core/hle/kernel/errors.h" 9#include "core/hle/kernel/errors.h"
10#include "core/hle/kernel/handle_table.h" 10#include "core/hle/kernel/handle_table.h"
11#include "core/hle/kernel/kernel.h"
12#include "core/hle/kernel/process.h" 11#include "core/hle/kernel/process.h"
13#include "core/hle/kernel/thread.h" 12#include "core/hle/kernel/thread.h"
14 13
diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h
index ba968c666..22ddda630 100644
--- a/src/core/hle/kernel/handle_table.h
+++ b/src/core/hle/kernel/handle_table.h
@@ -7,7 +7,7 @@
7#include <array> 7#include <array>
8#include <cstddef> 8#include <cstddef>
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/object.h"
11#include "core/hle/result.h" 11#include "core/hle/result.h"
12 12
13namespace Kernel { 13namespace Kernel {
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 771d6d476..5dd1b68d7 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -3,17 +3,21 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm> 5#include <algorithm>
6#include <array>
7#include <sstream>
6#include <utility> 8#include <utility>
7 9
8#include <boost/range/algorithm_ext/erase.hpp> 10#include <boost/range/algorithm_ext/erase.hpp>
11
9#include "common/assert.h" 12#include "common/assert.h"
10#include "common/common_funcs.h" 13#include "common/common_funcs.h"
11#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/logging/log.h"
12#include "core/hle/ipc_helpers.h" 16#include "core/hle/ipc_helpers.h"
13#include "core/hle/kernel/event.h" 17#include "core/hle/kernel/event.h"
14#include "core/hle/kernel/handle_table.h" 18#include "core/hle/kernel/handle_table.h"
15#include "core/hle/kernel/hle_ipc.h" 19#include "core/hle/kernel/hle_ipc.h"
16#include "core/hle/kernel/kernel.h" 20#include "core/hle/kernel/object.h"
17#include "core/hle/kernel/process.h" 21#include "core/hle/kernel/process.h"
18#include "core/hle/kernel/server_session.h" 22#include "core/hle/kernel/server_session.h"
19#include "core/memory.h" 23#include "core/memory.h"
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index ee4abebf2..9ce52db24 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -13,7 +13,7 @@
13#include "common/common_types.h" 13#include "common/common_types.h"
14#include "common/swap.h" 14#include "common/swap.h"
15#include "core/hle/ipc.h" 15#include "core/hle/ipc.h"
16#include "core/hle/kernel/kernel.h" 16#include "core/hle/kernel/object.h"
17#include "core/hle/kernel/server_session.h" 17#include "core/hle/kernel/server_session.h"
18#include "core/hle/kernel/thread.h" 18#include "core/hle/kernel/thread.h"
19 19
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 402ae900f..2bc45d7db 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -4,120 +4,10 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <cstddef>
8#include <string>
9#include <utility>
10#include <boost/smart_ptr/intrusive_ptr.hpp>
11#include "common/assert.h"
12#include "common/common_types.h" 7#include "common/common_types.h"
13 8
14namespace Kernel { 9namespace Kernel {
15 10
16using Handle = u32;
17
18enum class HandleType : u32 {
19 Unknown,
20 Event,
21 SharedMemory,
22 Thread,
23 Process,
24 AddressArbiter,
25 Timer,
26 ResourceLimit,
27 CodeSet,
28 ClientPort,
29 ServerPort,
30 ClientSession,
31 ServerSession,
32};
33
34enum class ResetType {
35 OneShot,
36 Sticky,
37 Pulse,
38};
39
40class Object : NonCopyable {
41public:
42 virtual ~Object() {}
43
44 /// Returns a unique identifier for the object. For debugging purposes only.
45 unsigned int GetObjectId() const {
46 return object_id;
47 }
48
49 virtual std::string GetTypeName() const {
50 return "[BAD KERNEL OBJECT TYPE]";
51 }
52 virtual std::string GetName() const {
53 return "[UNKNOWN KERNEL OBJECT]";
54 }
55 virtual Kernel::HandleType GetHandleType() const = 0;
56
57 /**
58 * Check if a thread can wait on the object
59 * @return True if a thread can wait on the object, otherwise false
60 */
61 bool IsWaitable() const {
62 switch (GetHandleType()) {
63 case HandleType::Event:
64 case HandleType::Thread:
65 case HandleType::Timer:
66 case HandleType::ServerPort:
67 case HandleType::ServerSession:
68 return true;
69
70 case HandleType::Unknown:
71 case HandleType::SharedMemory:
72 case HandleType::Process:
73 case HandleType::AddressArbiter:
74 case HandleType::ResourceLimit:
75 case HandleType::CodeSet:
76 case HandleType::ClientPort:
77 case HandleType::ClientSession:
78 return false;
79 }
80
81 UNREACHABLE();
82 }
83
84public:
85 static unsigned int next_object_id;
86
87private:
88 friend void intrusive_ptr_add_ref(Object*);
89 friend void intrusive_ptr_release(Object*);
90
91 unsigned int ref_count = 0;
92 unsigned int object_id = next_object_id++;
93};
94
95// Special functions used by boost::instrusive_ptr to do automatic ref-counting
96inline void intrusive_ptr_add_ref(Object* object) {
97 ++object->ref_count;
98}
99
100inline void intrusive_ptr_release(Object* object) {
101 if (--object->ref_count == 0) {
102 delete object;
103 }
104}
105
106template <typename T>
107using SharedPtr = boost::intrusive_ptr<T>;
108
109/**
110 * Attempts to downcast the given Object pointer to a pointer to T.
111 * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T.
112 */
113template <typename T>
114inline SharedPtr<T> DynamicObjectCast(SharedPtr<Object> object) {
115 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) {
116 return boost::static_pointer_cast<T>(std::move(object));
117 }
118 return nullptr;
119}
120
121/// Initialize the kernel with the specified system mode. 11/// Initialize the kernel with the specified system mode.
122void Init(u32 system_mode); 12void Init(u32 system_mode);
123 13
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 12b974c4b..cb7f58b35 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -12,8 +12,8 @@
12#include "core/core.h" 12#include "core/core.h"
13#include "core/hle/kernel/errors.h" 13#include "core/hle/kernel/errors.h"
14#include "core/hle/kernel/handle_table.h" 14#include "core/hle/kernel/handle_table.h"
15#include "core/hle/kernel/kernel.h"
16#include "core/hle/kernel/mutex.h" 15#include "core/hle/kernel/mutex.h"
16#include "core/hle/kernel/object.h"
17#include "core/hle/kernel/thread.h" 17#include "core/hle/kernel/thread.h"
18#include "core/hle/result.h" 18#include "core/hle/result.h"
19 19
diff --git a/src/core/hle/kernel/mutex.h b/src/core/hle/kernel/mutex.h
index febfde698..45268bbe9 100644
--- a/src/core/hle/kernel/mutex.h
+++ b/src/core/hle/kernel/mutex.h
@@ -5,7 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "core/hle/kernel/kernel.h" 8#include "core/hle/kernel/object.h"
9 9
10union ResultCode; 10union ResultCode;
11 11
diff --git a/src/core/hle/kernel/object.cpp b/src/core/hle/kernel/object.cpp
new file mode 100644
index 000000000..cdba272f5
--- /dev/null
+++ b/src/core/hle/kernel/object.cpp
@@ -0,0 +1,35 @@
1// Copyright 2018 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "common/assert.h"
6#include "core/hle/kernel/object.h"
7
8namespace Kernel {
9
10Object::~Object() = default;
11
12bool Object::IsWaitable() const {
13 switch (GetHandleType()) {
14 case HandleType::Event:
15 case HandleType::Thread:
16 case HandleType::Timer:
17 case HandleType::ServerPort:
18 case HandleType::ServerSession:
19 return true;
20
21 case HandleType::Unknown:
22 case HandleType::SharedMemory:
23 case HandleType::Process:
24 case HandleType::AddressArbiter:
25 case HandleType::ResourceLimit:
26 case HandleType::CodeSet:
27 case HandleType::ClientPort:
28 case HandleType::ClientSession:
29 return false;
30 }
31
32 UNREACHABLE();
33}
34
35} // namespace Kernel
diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h
new file mode 100644
index 000000000..83df68dfd
--- /dev/null
+++ b/src/core/hle/kernel/object.h
@@ -0,0 +1,100 @@
1// Copyright 2018 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <string>
8#include <utility>
9
10#include <boost/smart_ptr/intrusive_ptr.hpp>
11
12#include "common/common_types.h"
13
14namespace Kernel {
15
16using Handle = u32;
17
18enum class HandleType : u32 {
19 Unknown,
20 Event,
21 SharedMemory,
22 Thread,
23 Process,
24 AddressArbiter,
25 Timer,
26 ResourceLimit,
27 CodeSet,
28 ClientPort,
29 ServerPort,
30 ClientSession,
31 ServerSession,
32};
33
34enum class ResetType {
35 OneShot,
36 Sticky,
37 Pulse,
38};
39
40class Object : NonCopyable {
41public:
42 virtual ~Object();
43
44 /// Returns a unique identifier for the object. For debugging purposes only.
45 unsigned int GetObjectId() const {
46 return object_id;
47 }
48
49 virtual std::string GetTypeName() const {
50 return "[BAD KERNEL OBJECT TYPE]";
51 }
52 virtual std::string GetName() const {
53 return "[UNKNOWN KERNEL OBJECT]";
54 }
55 virtual HandleType GetHandleType() const = 0;
56
57 /**
58 * Check if a thread can wait on the object
59 * @return True if a thread can wait on the object, otherwise false
60 */
61 bool IsWaitable() const;
62
63public:
64 static unsigned int next_object_id;
65
66private:
67 friend void intrusive_ptr_add_ref(Object*);
68 friend void intrusive_ptr_release(Object*);
69
70 unsigned int ref_count = 0;
71 unsigned int object_id = next_object_id++;
72};
73
74// Special functions used by boost::instrusive_ptr to do automatic ref-counting
75inline void intrusive_ptr_add_ref(Object* object) {
76 ++object->ref_count;
77}
78
79inline void intrusive_ptr_release(Object* object) {
80 if (--object->ref_count == 0) {
81 delete object;
82 }
83}
84
85template <typename T>
86using SharedPtr = boost::intrusive_ptr<T>;
87
88/**
89 * Attempts to downcast the given Object pointer to a pointer to T.
90 * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T.
91 */
92template <typename T>
93inline SharedPtr<T> DynamicObjectCast(SharedPtr<Object> object) {
94 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) {
95 return boost::static_pointer_cast<T>(std::move(object));
96 }
97 return nullptr;
98}
99
100} // namespace Kernel
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 68e77a4d1..1204026be 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -12,7 +12,7 @@
12#include <boost/container/static_vector.hpp> 12#include <boost/container/static_vector.hpp>
13#include "common/bit_field.h" 13#include "common/bit_field.h"
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "core/hle/kernel/kernel.h" 15#include "core/hle/kernel/object.h"
16#include "core/hle/kernel/thread.h" 16#include "core/hle/kernel/thread.h"
17#include "core/hle/kernel/vm_manager.h" 17#include "core/hle/kernel/vm_manager.h"
18 18
diff --git a/src/core/hle/kernel/resource_limit.h b/src/core/hle/kernel/resource_limit.h
index cc689a27a..0fa141db3 100644
--- a/src/core/hle/kernel/resource_limit.h
+++ b/src/core/hle/kernel/resource_limit.h
@@ -5,7 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "core/hle/kernel/kernel.h" 8#include "core/hle/kernel/object.h"
9 9
10namespace Kernel { 10namespace Kernel {
11 11
diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h
index cdc14808b..1a4ee8f36 100644
--- a/src/core/hle/kernel/scheduler.h
+++ b/src/core/hle/kernel/scheduler.h
@@ -8,6 +8,7 @@
8#include <vector> 8#include <vector>
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/thread_queue_list.h" 10#include "common/thread_queue_list.h"
11#include "core/hle/kernel/object.h"
11#include "core/hle/kernel/thread.h" 12#include "core/hle/kernel/thread.h"
12 13
13class ARM_Interface; 14class ARM_Interface;
diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp
index 0b7061403..7b6211fd8 100644
--- a/src/core/hle/kernel/server_port.cpp
+++ b/src/core/hle/kernel/server_port.cpp
@@ -6,7 +6,7 @@
6#include "common/assert.h" 6#include "common/assert.h"
7#include "core/hle/kernel/client_port.h" 7#include "core/hle/kernel/client_port.h"
8#include "core/hle/kernel/errors.h" 8#include "core/hle/kernel/errors.h"
9#include "core/hle/kernel/kernel.h" 9#include "core/hle/kernel/object.h"
10#include "core/hle/kernel/server_port.h" 10#include "core/hle/kernel/server_port.h"
11#include "core/hle/kernel/server_session.h" 11#include "core/hle/kernel/server_session.h"
12#include "core/hle/kernel/thread.h" 12#include "core/hle/kernel/thread.h"
diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h
index e6546687e..7f6d6b3eb 100644
--- a/src/core/hle/kernel/server_port.h
+++ b/src/core/hle/kernel/server_port.h
@@ -9,7 +9,7 @@
9#include <tuple> 9#include <tuple>
10#include <vector> 10#include <vector>
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "core/hle/kernel/kernel.h" 12#include "core/hle/kernel/object.h"
13#include "core/hle/kernel/wait_object.h" 13#include "core/hle/kernel/wait_object.h"
14 14
15namespace Kernel { 15namespace Kernel {
diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h
index c7656cc49..2bce54fee 100644
--- a/src/core/hle/kernel/server_session.h
+++ b/src/core/hle/kernel/server_session.h
@@ -9,7 +9,7 @@
9#include <vector> 9#include <vector>
10 10
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "core/hle/kernel/kernel.h" 12#include "core/hle/kernel/object.h"
13#include "core/hle/kernel/wait_object.h" 13#include "core/hle/kernel/wait_object.h"
14#include "core/hle/result.h" 14#include "core/hle/result.h"
15 15
diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h
index e69b034a7..7a551f5e4 100644
--- a/src/core/hle/kernel/session.h
+++ b/src/core/hle/kernel/session.h
@@ -4,7 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "core/hle/kernel/kernel.h" 7#include "core/hle/kernel/object.h"
8 8
9namespace Kernel { 9namespace Kernel {
10 10
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h
index 17b9cedc4..8a6f68529 100644
--- a/src/core/hle/kernel/shared_memory.h
+++ b/src/core/hle/kernel/shared_memory.h
@@ -9,7 +9,7 @@
9#include <vector> 9#include <vector>
10 10
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "core/hle/kernel/kernel.h" 12#include "core/hle/kernel/object.h"
13#include "core/hle/kernel/process.h" 13#include "core/hle/kernel/process.h"
14#include "core/hle/result.h" 14#include "core/hle/result.h"
15 15
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 8af84d8cc..cdb8120f2 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -20,8 +20,8 @@
20#include "core/core_timing_util.h" 20#include "core/core_timing_util.h"
21#include "core/hle/kernel/errors.h" 21#include "core/hle/kernel/errors.h"
22#include "core/hle/kernel/handle_table.h" 22#include "core/hle/kernel/handle_table.h"
23#include "core/hle/kernel/kernel.h"
24#include "core/hle/kernel/memory.h" 23#include "core/hle/kernel/memory.h"
24#include "core/hle/kernel/object.h"
25#include "core/hle/kernel/process.h" 25#include "core/hle/kernel/process.h"
26#include "core/hle/kernel/thread.h" 26#include "core/hle/kernel/thread.h"
27#include "core/hle/result.h" 27#include "core/hle/result.h"
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 3a96db5f3..146955e13 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -11,7 +11,7 @@
11 11
12#include "common/common_types.h" 12#include "common/common_types.h"
13#include "core/arm/arm_interface.h" 13#include "core/arm/arm_interface.h"
14#include "core/hle/kernel/kernel.h" 14#include "core/hle/kernel/object.h"
15#include "core/hle/kernel/wait_object.h" 15#include "core/hle/kernel/wait_object.h"
16#include "core/hle/result.h" 16#include "core/hle/result.h"
17 17
diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp
index 904a3d0a5..282360745 100644
--- a/src/core/hle/kernel/timer.cpp
+++ b/src/core/hle/kernel/timer.cpp
@@ -8,7 +8,7 @@
8#include "core/core_timing.h" 8#include "core/core_timing.h"
9#include "core/core_timing_util.h" 9#include "core/core_timing_util.h"
10#include "core/hle/kernel/handle_table.h" 10#include "core/hle/kernel/handle_table.h"
11#include "core/hle/kernel/kernel.h" 11#include "core/hle/kernel/object.h"
12#include "core/hle/kernel/thread.h" 12#include "core/hle/kernel/thread.h"
13#include "core/hle/kernel/timer.h" 13#include "core/hle/kernel/timer.h"
14 14
diff --git a/src/core/hle/kernel/timer.h b/src/core/hle/kernel/timer.h
index c63f0ed90..4dddc67e0 100644
--- a/src/core/hle/kernel/timer.h
+++ b/src/core/hle/kernel/timer.h
@@ -5,7 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "core/hle/kernel/kernel.h" 8#include "core/hle/kernel/object.h"
9#include "core/hle/kernel/wait_object.h" 9#include "core/hle/kernel/wait_object.h"
10 10
11namespace Kernel { 11namespace Kernel {
diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp
index 97394bca2..7681cdee7 100644
--- a/src/core/hle/kernel/wait_object.cpp
+++ b/src/core/hle/kernel/wait_object.cpp
@@ -5,8 +5,7 @@
5#include <algorithm> 5#include <algorithm>
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "core/hle/kernel/kernel.h" 8#include "core/hle/kernel/object.h"
9#include "core/hle/kernel/memory.h"
10#include "core/hle/kernel/process.h" 9#include "core/hle/kernel/process.h"
11#include "core/hle/kernel/thread.h" 10#include "core/hle/kernel/thread.h"
12#include "core/hle/kernel/timer.h" 11#include "core/hle/kernel/timer.h"
diff --git a/src/core/hle/kernel/wait_object.h b/src/core/hle/kernel/wait_object.h
index 78bfd8c6c..b5fbc647b 100644
--- a/src/core/hle/kernel/wait_object.h
+++ b/src/core/hle/kernel/wait_object.h
@@ -7,7 +7,7 @@
7#include <vector> 7#include <vector>
8#include <boost/smart_ptr/intrusive_ptr.hpp> 8#include <boost/smart_ptr/intrusive_ptr.hpp>
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/object.h"
11 11
12namespace Kernel { 12namespace Kernel {
13 13
diff --git a/src/core/hle/service/nvflinger/buffer_queue.cpp b/src/core/hle/service/nvflinger/buffer_queue.cpp
index 7132b18ad..adf180509 100644
--- a/src/core/hle/service/nvflinger/buffer_queue.cpp
+++ b/src/core/hle/service/nvflinger/buffer_queue.cpp
@@ -4,9 +4,8 @@
4 4
5#include <algorithm> 5#include <algorithm>
6 6
7#include "common/alignment.h" 7#include "common/assert.h"
8#include "common/scope_exit.h" 8#include "common/logging/log.h"
9#include "core/core_timing.h"
10#include "core/hle/service/nvflinger/buffer_queue.h" 9#include "core/hle/service/nvflinger/buffer_queue.h"
11 10
12namespace Service { 11namespace Service {
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index 180f22703..046c5e18d 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -8,10 +8,9 @@
8#include <string> 8#include <string>
9#include <unordered_map> 9#include <unordered_map>
10#include <boost/container/flat_map.hpp> 10#include <boost/container/flat_map.hpp>
11#include "common/bit_field.h"
12#include "common/common_types.h" 11#include "common/common_types.h"
13#include "core/hle/kernel/hle_ipc.h" 12#include "core/hle/kernel/hle_ipc.h"
14#include "core/hle/kernel/kernel.h" 13#include "core/hle/kernel/object.h"
15 14
16//////////////////////////////////////////////////////////////////////////////////////////////////// 15////////////////////////////////////////////////////////////////////////////////////////////////////
17// Namespace Service 16// Namespace Service
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h
index e2a00e4f6..e8ea62f08 100644
--- a/src/core/hle/service/sm/sm.h
+++ b/src/core/hle/service/sm/sm.h
@@ -4,9 +4,11 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <memory>
7#include <string> 8#include <string>
8#include <unordered_map> 9#include <unordered_map>
9#include "core/hle/kernel/kernel.h" 10
11#include "core/hle/kernel/object.h"
10#include "core/hle/result.h" 12#include "core/hle/result.h"
11#include "core/hle/service/service.h" 13#include "core/hle/service/service.h"
12 14
@@ -19,6 +21,8 @@ class SessionRequestHandler;
19 21
20namespace Service::SM { 22namespace Service::SM {
21 23
24class Controller;
25
22/// Interface to "sm:" service 26/// Interface to "sm:" service
23class SM final : public ServiceFramework<SM> { 27class SM final : public ServiceFramework<SM> {
24public: 28public:
@@ -32,8 +36,6 @@ private:
32 std::shared_ptr<ServiceManager> service_manager; 36 std::shared_ptr<ServiceManager> service_manager;
33}; 37};
34 38
35class Controller;
36
37constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(-1); 39constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(-1);
38constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(-1); 40constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(-1);
39constexpr ResultCode ERR_INVALID_NAME_SIZE(-1); 41constexpr ResultCode ERR_INVALID_NAME_SIZE(-1);
diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h
index 982a037f7..7319ba6ea 100644
--- a/src/core/loader/deconstructed_rom_directory.h
+++ b/src/core/loader/deconstructed_rom_directory.h
@@ -7,7 +7,7 @@
7#include <string> 7#include <string>
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "core/file_sys/program_metadata.h" 9#include "core/file_sys/program_metadata.h"
10#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/object.h"
11#include "core/loader/loader.h" 11#include "core/loader/loader.h"
12 12
13namespace Loader { 13namespace Loader {
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index fbf11e5d0..3ca6bcf8b 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -14,7 +14,7 @@
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/file_util.h" 15#include "common/file_util.h"
16#include "core/file_sys/vfs.h" 16#include "core/file_sys/vfs.h"
17#include "core/hle/kernel/kernel.h" 17#include "core/hle/kernel/object.h"
18 18
19namespace Kernel { 19namespace Kernel {
20struct AddressMapping; 20struct AddressMapping;
diff --git a/src/core/loader/nca.h b/src/core/loader/nca.h
index 52c95953a..2edd81cb9 100644
--- a/src/core/loader/nca.h
+++ b/src/core/loader/nca.h
@@ -8,7 +8,7 @@
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "core/file_sys/content_archive.h" 9#include "core/file_sys/content_archive.h"
10#include "core/file_sys/program_metadata.h" 10#include "core/file_sys/program_metadata.h"
11#include "core/hle/kernel/kernel.h" 11#include "core/hle/kernel/object.h"
12#include "core/loader/loader.h" 12#include "core/loader/loader.h"
13 13
14namespace Loader { 14namespace Loader {
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h
index 04a0f497e..bb01c9e25 100644
--- a/src/core/loader/nro.h
+++ b/src/core/loader/nro.h
@@ -6,7 +6,7 @@
6 6
7#include <string> 7#include <string>
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "core/hle/kernel/kernel.h" 9#include "core/hle/kernel/object.h"
10#include "core/loader/linker.h" 10#include "core/loader/linker.h"
11#include "core/loader/loader.h" 11#include "core/loader/loader.h"
12 12
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h
index 3f7567500..aaeb1f2a9 100644
--- a/src/core/loader/nso.h
+++ b/src/core/loader/nso.h
@@ -6,7 +6,7 @@
6 6
7#include <string> 7#include <string>
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "core/hle/kernel/kernel.h" 9#include "core/hle/kernel/object.h"
10#include "core/loader/linker.h" 10#include "core/loader/linker.h"
11#include "core/loader/loader.h" 11#include "core/loader/loader.h"
12 12
diff --git a/src/yuzu/debugger/wait_tree.h b/src/yuzu/debugger/wait_tree.h
index 10fc9e968..6cbce6856 100644
--- a/src/yuzu/debugger/wait_tree.h
+++ b/src/yuzu/debugger/wait_tree.h
@@ -9,7 +9,7 @@
9#include <QTreeView> 9#include <QTreeView>
10#include <boost/container/flat_set.hpp> 10#include <boost/container/flat_set.hpp>
11#include "core/core.h" 11#include "core/core.h"
12#include "core/hle/kernel/kernel.h" 12#include "core/hle/kernel/object.h"
13 13
14class EmuThread; 14class EmuThread;
15 15