diff options
| author | 2018-10-23 18:43:11 -0400 | |
|---|---|---|
| committer | 2018-10-23 18:43:11 -0400 | |
| commit | e61a62066a1d7668a5e6a792463eccf33baf470e (patch) | |
| tree | 6e58ea645719d31151168763fb9eb2b4196e7b30 | |
| parent | Merge pull request #1552 from FearlessTobi/port-4336 (diff) | |
| parent | kernel/process: Make the handle table per-process (diff) | |
| download | yuzu-e61a62066a1d7668a5e6a792463eccf33baf470e.tar.gz yuzu-e61a62066a1d7668a5e6a792463eccf33baf470e.tar.xz yuzu-e61a62066a1d7668a5e6a792463eccf33baf470e.zip | |
Merge pull request #1540 from lioncash/handle
kernel/process: Make the handle table per-process
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.cpp | 25 | ||||
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.h | 13 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.h | 14 | ||||
| -rw-r--r-- | src/core/hle/kernel/server_session.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 120 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 2 | ||||
| -rw-r--r-- | src/yuzu/debugger/wait_tree.cpp | 4 |
9 files changed, 97 insertions, 100 deletions
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index edad5f1b1..68d5376cb 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp | |||
| @@ -77,7 +77,8 @@ HLERequestContext::HLERequestContext(SharedPtr<Kernel::ServerSession> server_ses | |||
| 77 | 77 | ||
| 78 | HLERequestContext::~HLERequestContext() = default; | 78 | HLERequestContext::~HLERequestContext() = default; |
| 79 | 79 | ||
| 80 | void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { | 80 | void HLERequestContext::ParseCommandBuffer(const HandleTable& handle_table, u32_le* src_cmdbuf, |
| 81 | bool incoming) { | ||
| 81 | IPC::RequestParser rp(src_cmdbuf); | 82 | IPC::RequestParser rp(src_cmdbuf); |
| 82 | command_header = std::make_shared<IPC::CommandHeader>(rp.PopRaw<IPC::CommandHeader>()); | 83 | command_header = std::make_shared<IPC::CommandHeader>(rp.PopRaw<IPC::CommandHeader>()); |
| 83 | 84 | ||
| @@ -94,8 +95,6 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { | |||
| 94 | rp.Skip(2, false); | 95 | rp.Skip(2, false); |
| 95 | } | 96 | } |
| 96 | if (incoming) { | 97 | if (incoming) { |
| 97 | auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); | ||
| 98 | |||
| 99 | // Populate the object lists with the data in the IPC request. | 98 | // Populate the object lists with the data in the IPC request. |
| 100 | for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) { | 99 | for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) { |
| 101 | copy_objects.push_back(handle_table.GetGeneric(rp.Pop<Handle>())); | 100 | copy_objects.push_back(handle_table.GetGeneric(rp.Pop<Handle>())); |
| @@ -189,10 +188,9 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { | |||
| 189 | rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. | 188 | rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. |
| 190 | } | 189 | } |
| 191 | 190 | ||
| 192 | ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdbuf, | 191 | ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const HandleTable& handle_table, |
| 193 | Process& src_process, | 192 | u32_le* src_cmdbuf) { |
| 194 | HandleTable& src_table) { | 193 | ParseCommandBuffer(handle_table, src_cmdbuf, true); |
| 195 | ParseCommandBuffer(src_cmdbuf, true); | ||
| 196 | if (command_header->type == IPC::CommandType::Close) { | 194 | if (command_header->type == IPC::CommandType::Close) { |
| 197 | // Close does not populate the rest of the IPC header | 195 | // Close does not populate the rest of the IPC header |
| 198 | return RESULT_SUCCESS; | 196 | return RESULT_SUCCESS; |
| @@ -207,14 +205,17 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdb | |||
| 207 | return RESULT_SUCCESS; | 205 | return RESULT_SUCCESS; |
| 208 | } | 206 | } |
| 209 | 207 | ||
| 210 | ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread) { | 208 | ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) { |
| 209 | auto& owner_process = *thread.GetOwnerProcess(); | ||
| 210 | auto& handle_table = owner_process.GetHandleTable(); | ||
| 211 | |||
| 211 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf; | 212 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf; |
| 212 | Memory::ReadBlock(*thread.GetOwnerProcess(), thread.GetTLSAddress(), dst_cmdbuf.data(), | 213 | Memory::ReadBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(), |
| 213 | dst_cmdbuf.size() * sizeof(u32)); | 214 | dst_cmdbuf.size() * sizeof(u32)); |
| 214 | 215 | ||
| 215 | // The header was already built in the internal command buffer. Attempt to parse it to verify | 216 | // The header was already built in the internal command buffer. Attempt to parse it to verify |
| 216 | // the integrity and then copy it over to the target command buffer. | 217 | // the integrity and then copy it over to the target command buffer. |
| 217 | ParseCommandBuffer(cmd_buf.data(), false); | 218 | ParseCommandBuffer(handle_table, cmd_buf.data(), false); |
| 218 | 219 | ||
| 219 | // The data_size already includes the payload header, the padding and the domain header. | 220 | // The data_size already includes the payload header, the padding and the domain header. |
| 220 | std::size_t size = data_payload_offset + command_header->data_size - | 221 | std::size_t size = data_payload_offset + command_header->data_size - |
| @@ -236,8 +237,6 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread) | |||
| 236 | ASSERT(copy_objects.size() == handle_descriptor_header->num_handles_to_copy); | 237 | ASSERT(copy_objects.size() == handle_descriptor_header->num_handles_to_copy); |
| 237 | ASSERT(move_objects.size() == handle_descriptor_header->num_handles_to_move); | 238 | ASSERT(move_objects.size() == handle_descriptor_header->num_handles_to_move); |
| 238 | 239 | ||
| 239 | auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); | ||
| 240 | |||
| 241 | // We don't make a distinction between copy and move handles when translating since HLE | 240 | // We don't make a distinction between copy and move handles when translating since HLE |
| 242 | // services don't deal with handles directly. However, the guest applications might check | 241 | // services don't deal with handles directly. However, the guest applications might check |
| 243 | // for specific values in each of these descriptors. | 242 | // for specific values in each of these descriptors. |
| @@ -268,7 +267,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread) | |||
| 268 | } | 267 | } |
| 269 | 268 | ||
| 270 | // Copy the translated command buffer back into the thread's command buffer area. | 269 | // Copy the translated command buffer back into the thread's command buffer area. |
| 271 | Memory::WriteBlock(*thread.GetOwnerProcess(), thread.GetTLSAddress(), dst_cmdbuf.data(), | 270 | Memory::WriteBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(), |
| 272 | dst_cmdbuf.size() * sizeof(u32)); | 271 | dst_cmdbuf.size() * sizeof(u32)); |
| 273 | 272 | ||
| 274 | return RESULT_SUCCESS; | 273 | return RESULT_SUCCESS; |
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 894479ee0..f01491daa 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h | |||
| @@ -24,10 +24,10 @@ class ServiceFrameworkBase; | |||
| 24 | namespace Kernel { | 24 | namespace Kernel { |
| 25 | 25 | ||
| 26 | class Domain; | 26 | class Domain; |
| 27 | class Event; | ||
| 27 | class HandleTable; | 28 | class HandleTable; |
| 28 | class HLERequestContext; | 29 | class HLERequestContext; |
| 29 | class Process; | 30 | class Process; |
| 30 | class Event; | ||
| 31 | 31 | ||
| 32 | /** | 32 | /** |
| 33 | * Interface implemented by HLE Session handlers. | 33 | * Interface implemented by HLE Session handlers. |
| @@ -126,13 +126,12 @@ public: | |||
| 126 | u64 timeout, WakeupCallback&& callback, | 126 | u64 timeout, WakeupCallback&& callback, |
| 127 | Kernel::SharedPtr<Kernel::Event> event = nullptr); | 127 | Kernel::SharedPtr<Kernel::Event> event = nullptr); |
| 128 | 128 | ||
| 129 | void ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming); | ||
| 130 | |||
| 131 | /// Populates this context with data from the requesting process/thread. | 129 | /// Populates this context with data from the requesting process/thread. |
| 132 | ResultCode PopulateFromIncomingCommandBuffer(u32_le* src_cmdbuf, Process& src_process, | 130 | ResultCode PopulateFromIncomingCommandBuffer(const HandleTable& handle_table, |
| 133 | HandleTable& src_table); | 131 | u32_le* src_cmdbuf); |
| 132 | |||
| 134 | /// Writes data from this context back to the requesting process/thread. | 133 | /// Writes data from this context back to the requesting process/thread. |
| 135 | ResultCode WriteToOutgoingCommandBuffer(const Thread& thread); | 134 | ResultCode WriteToOutgoingCommandBuffer(Thread& thread); |
| 136 | 135 | ||
| 137 | u32_le GetCommand() const { | 136 | u32_le GetCommand() const { |
| 138 | return command; | 137 | return command; |
| @@ -255,6 +254,8 @@ public: | |||
| 255 | std::string Description() const; | 254 | std::string Description() const; |
| 256 | 255 | ||
| 257 | private: | 256 | private: |
| 257 | void ParseCommandBuffer(const HandleTable& handle_table, u32_le* src_cmdbuf, bool incoming); | ||
| 258 | |||
| 258 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; | 259 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; |
| 259 | SharedPtr<Kernel::ServerSession> server_session; | 260 | SharedPtr<Kernel::ServerSession> server_session; |
| 260 | // TODO(yuriks): Check common usage of this and optimize size accordingly | 261 | // TODO(yuriks): Check common usage of this and optimize size accordingly |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index bd680adfe..4b6b32dd5 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -118,7 +118,6 @@ struct KernelCore::Impl { | |||
| 118 | process_list.clear(); | 118 | process_list.clear(); |
| 119 | current_process = nullptr; | 119 | current_process = nullptr; |
| 120 | 120 | ||
| 121 | handle_table.Clear(); | ||
| 122 | resource_limits.fill(nullptr); | 121 | resource_limits.fill(nullptr); |
| 123 | 122 | ||
| 124 | thread_wakeup_callback_handle_table.Clear(); | 123 | thread_wakeup_callback_handle_table.Clear(); |
| @@ -209,7 +208,6 @@ struct KernelCore::Impl { | |||
| 209 | std::vector<SharedPtr<Process>> process_list; | 208 | std::vector<SharedPtr<Process>> process_list; |
| 210 | Process* current_process = nullptr; | 209 | Process* current_process = nullptr; |
| 211 | 210 | ||
| 212 | Kernel::HandleTable handle_table; | ||
| 213 | std::array<SharedPtr<ResourceLimit>, 4> resource_limits; | 211 | std::array<SharedPtr<ResourceLimit>, 4> resource_limits; |
| 214 | 212 | ||
| 215 | /// The event type of the generic timer callback event | 213 | /// The event type of the generic timer callback event |
| @@ -241,14 +239,6 @@ void KernelCore::Shutdown() { | |||
| 241 | impl->Shutdown(); | 239 | impl->Shutdown(); |
| 242 | } | 240 | } |
| 243 | 241 | ||
| 244 | Kernel::HandleTable& KernelCore::HandleTable() { | ||
| 245 | return impl->handle_table; | ||
| 246 | } | ||
| 247 | |||
| 248 | const Kernel::HandleTable& KernelCore::HandleTable() const { | ||
| 249 | return impl->handle_table; | ||
| 250 | } | ||
| 251 | |||
| 252 | SharedPtr<ResourceLimit> KernelCore::ResourceLimitForCategory( | 242 | SharedPtr<ResourceLimit> KernelCore::ResourceLimitForCategory( |
| 253 | ResourceLimitCategory category) const { | 243 | ResourceLimitCategory category) const { |
| 254 | return impl->resource_limits.at(static_cast<std::size_t>(category)); | 244 | return impl->resource_limits.at(static_cast<std::size_t>(category)); |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 41554821f..7f822d524 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -47,12 +47,6 @@ public: | |||
| 47 | /// Clears all resources in use by the kernel instance. | 47 | /// Clears all resources in use by the kernel instance. |
| 48 | void Shutdown(); | 48 | void Shutdown(); |
| 49 | 49 | ||
| 50 | /// Provides a reference to the handle table. | ||
| 51 | Kernel::HandleTable& HandleTable(); | ||
| 52 | |||
| 53 | /// Provides a const reference to the handle table. | ||
| 54 | const Kernel::HandleTable& HandleTable() const; | ||
| 55 | |||
| 56 | /// Retrieves a shared pointer to a ResourceLimit identified by the given category. | 50 | /// Retrieves a shared pointer to a ResourceLimit identified by the given category. |
| 57 | SharedPtr<ResourceLimit> ResourceLimitForCategory(ResourceLimitCategory category) const; | 51 | SharedPtr<ResourceLimit> ResourceLimitForCategory(ResourceLimitCategory category) const; |
| 58 | 52 | ||
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index f2816943a..148478488 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <boost/container/static_vector.hpp> | 13 | #include <boost/container/static_vector.hpp> |
| 14 | #include "common/bit_field.h" | 14 | #include "common/bit_field.h" |
| 15 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 16 | #include "core/hle/kernel/handle_table.h" | ||
| 16 | #include "core/hle/kernel/object.h" | 17 | #include "core/hle/kernel/object.h" |
| 17 | #include "core/hle/kernel/thread.h" | 18 | #include "core/hle/kernel/thread.h" |
| 18 | #include "core/hle/kernel/vm_manager.h" | 19 | #include "core/hle/kernel/vm_manager.h" |
| @@ -142,6 +143,16 @@ public: | |||
| 142 | return vm_manager; | 143 | return vm_manager; |
| 143 | } | 144 | } |
| 144 | 145 | ||
| 146 | /// Gets a reference to the process' handle table. | ||
| 147 | HandleTable& GetHandleTable() { | ||
| 148 | return handle_table; | ||
| 149 | } | ||
| 150 | |||
| 151 | /// Gets a const reference to the process' handle table. | ||
| 152 | const HandleTable& GetHandleTable() const { | ||
| 153 | return handle_table; | ||
| 154 | } | ||
| 155 | |||
| 145 | /// Gets the current status of the process | 156 | /// Gets the current status of the process |
| 146 | ProcessStatus GetStatus() const { | 157 | ProcessStatus GetStatus() const { |
| 147 | return status; | 158 | return status; |
| @@ -294,6 +305,9 @@ private: | |||
| 294 | /// specified by metadata provided to the process during loading. | 305 | /// specified by metadata provided to the process during loading. |
| 295 | bool is_64bit_process = true; | 306 | bool is_64bit_process = true; |
| 296 | 307 | ||
| 308 | /// Per-process handle table for storing created object handles in. | ||
| 309 | HandleTable handle_table; | ||
| 310 | |||
| 297 | std::string name; | 311 | std::string name; |
| 298 | }; | 312 | }; |
| 299 | 313 | ||
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 1ece691c7..5fc320403 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp | |||
| @@ -107,8 +107,7 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) { | |||
| 107 | // similar. | 107 | // similar. |
| 108 | Kernel::HLERequestContext context(this); | 108 | Kernel::HLERequestContext context(this); |
| 109 | u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); | 109 | u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); |
| 110 | context.PopulateFromIncomingCommandBuffer(cmd_buf, *Core::CurrentProcess(), | 110 | context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf); |
| 111 | kernel.HandleTable()); | ||
| 112 | 111 | ||
| 113 | ResultCode result = RESULT_SUCCESS; | 112 | ResultCode result = RESULT_SUCCESS; |
| 114 | // If the session has been converted to a domain, handle the domain request | 113 | // If the session has been converted to a domain, handle the domain request |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 690b84930..67ea67666 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -189,14 +189,15 @@ static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address | |||
| 189 | CASCADE_RESULT(client_session, client_port->Connect()); | 189 | CASCADE_RESULT(client_session, client_port->Connect()); |
| 190 | 190 | ||
| 191 | // Return the client session | 191 | // Return the client session |
| 192 | CASCADE_RESULT(*out_handle, kernel.HandleTable().Create(client_session)); | 192 | auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 193 | CASCADE_RESULT(*out_handle, handle_table.Create(client_session)); | ||
| 193 | return RESULT_SUCCESS; | 194 | return RESULT_SUCCESS; |
| 194 | } | 195 | } |
| 195 | 196 | ||
| 196 | /// Makes a blocking IPC call to an OS service. | 197 | /// Makes a blocking IPC call to an OS service. |
| 197 | static ResultCode SendSyncRequest(Handle handle) { | 198 | static ResultCode SendSyncRequest(Handle handle) { |
| 198 | auto& kernel = Core::System::GetInstance().Kernel(); | 199 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 199 | SharedPtr<ClientSession> session = kernel.HandleTable().Get<ClientSession>(handle); | 200 | SharedPtr<ClientSession> session = handle_table.Get<ClientSession>(handle); |
| 200 | if (!session) { | 201 | if (!session) { |
| 201 | LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); | 202 | LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); |
| 202 | return ERR_INVALID_HANDLE; | 203 | return ERR_INVALID_HANDLE; |
| @@ -215,8 +216,8 @@ static ResultCode SendSyncRequest(Handle handle) { | |||
| 215 | static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { | 216 | static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { |
| 216 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); | 217 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); |
| 217 | 218 | ||
| 218 | auto& kernel = Core::System::GetInstance().Kernel(); | 219 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 219 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 220 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 220 | if (!thread) { | 221 | if (!thread) { |
| 221 | return ERR_INVALID_HANDLE; | 222 | return ERR_INVALID_HANDLE; |
| 222 | } | 223 | } |
| @@ -229,8 +230,8 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { | |||
| 229 | static ResultCode GetProcessId(u32* process_id, Handle process_handle) { | 230 | static ResultCode GetProcessId(u32* process_id, Handle process_handle) { |
| 230 | LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); | 231 | LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); |
| 231 | 232 | ||
| 232 | auto& kernel = Core::System::GetInstance().Kernel(); | 233 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 233 | const SharedPtr<Process> process = kernel.HandleTable().Get<Process>(process_handle); | 234 | const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); |
| 234 | if (!process) { | 235 | if (!process) { |
| 235 | return ERR_INVALID_HANDLE; | 236 | return ERR_INVALID_HANDLE; |
| 236 | } | 237 | } |
| @@ -273,11 +274,11 @@ static ResultCode WaitSynchronization(Handle* index, VAddr handles_address, u64 | |||
| 273 | 274 | ||
| 274 | using ObjectPtr = Thread::ThreadWaitObjects::value_type; | 275 | using ObjectPtr = Thread::ThreadWaitObjects::value_type; |
| 275 | Thread::ThreadWaitObjects objects(handle_count); | 276 | Thread::ThreadWaitObjects objects(handle_count); |
| 276 | auto& kernel = Core::System::GetInstance().Kernel(); | 277 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 277 | 278 | ||
| 278 | for (u64 i = 0; i < handle_count; ++i) { | 279 | for (u64 i = 0; i < handle_count; ++i) { |
| 279 | const Handle handle = Memory::Read32(handles_address + i * sizeof(Handle)); | 280 | const Handle handle = Memory::Read32(handles_address + i * sizeof(Handle)); |
| 280 | const auto object = kernel.HandleTable().Get<WaitObject>(handle); | 281 | const auto object = handle_table.Get<WaitObject>(handle); |
| 281 | 282 | ||
| 282 | if (object == nullptr) { | 283 | if (object == nullptr) { |
| 283 | return ERR_INVALID_HANDLE; | 284 | return ERR_INVALID_HANDLE; |
| @@ -325,8 +326,8 @@ static ResultCode WaitSynchronization(Handle* index, VAddr handles_address, u64 | |||
| 325 | static ResultCode CancelSynchronization(Handle thread_handle) { | 326 | static ResultCode CancelSynchronization(Handle thread_handle) { |
| 326 | LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle); | 327 | LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle); |
| 327 | 328 | ||
| 328 | auto& kernel = Core::System::GetInstance().Kernel(); | 329 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 329 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 330 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 330 | if (!thread) { | 331 | if (!thread) { |
| 331 | return ERR_INVALID_HANDLE; | 332 | return ERR_INVALID_HANDLE; |
| 332 | } | 333 | } |
| @@ -354,7 +355,7 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr, | |||
| 354 | return ERR_INVALID_ADDRESS; | 355 | return ERR_INVALID_ADDRESS; |
| 355 | } | 356 | } |
| 356 | 357 | ||
| 357 | auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); | 358 | auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 358 | return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle, | 359 | return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle, |
| 359 | requesting_thread_handle); | 360 | requesting_thread_handle); |
| 360 | } | 361 | } |
| @@ -499,13 +500,12 @@ static ResultCode SetThreadActivity(Handle handle, u32 unknown) { | |||
| 499 | static ResultCode GetThreadContext(VAddr thread_context, Handle handle) { | 500 | static ResultCode GetThreadContext(VAddr thread_context, Handle handle) { |
| 500 | LOG_DEBUG(Kernel_SVC, "called, context=0x{:08X}, thread=0x{:X}", thread_context, handle); | 501 | LOG_DEBUG(Kernel_SVC, "called, context=0x{:08X}, thread=0x{:X}", thread_context, handle); |
| 501 | 502 | ||
| 502 | auto& kernel = Core::System::GetInstance().Kernel(); | 503 | const auto* current_process = Core::CurrentProcess(); |
| 503 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle); | 504 | const SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); |
| 504 | if (!thread) { | 505 | if (!thread) { |
| 505 | return ERR_INVALID_HANDLE; | 506 | return ERR_INVALID_HANDLE; |
| 506 | } | 507 | } |
| 507 | 508 | ||
| 508 | const auto* current_process = Core::CurrentProcess(); | ||
| 509 | if (thread->GetOwnerProcess() != current_process) { | 509 | if (thread->GetOwnerProcess() != current_process) { |
| 510 | return ERR_INVALID_HANDLE; | 510 | return ERR_INVALID_HANDLE; |
| 511 | } | 511 | } |
| @@ -531,10 +531,11 @@ static ResultCode GetThreadContext(VAddr thread_context, Handle handle) { | |||
| 531 | 531 | ||
| 532 | /// Gets the priority for the specified thread | 532 | /// Gets the priority for the specified thread |
| 533 | static ResultCode GetThreadPriority(u32* priority, Handle handle) { | 533 | static ResultCode GetThreadPriority(u32* priority, Handle handle) { |
| 534 | auto& kernel = Core::System::GetInstance().Kernel(); | 534 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 535 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle); | 535 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle); |
| 536 | if (!thread) | 536 | if (!thread) { |
| 537 | return ERR_INVALID_HANDLE; | 537 | return ERR_INVALID_HANDLE; |
| 538 | } | ||
| 538 | 539 | ||
| 539 | *priority = thread->GetPriority(); | 540 | *priority = thread->GetPriority(); |
| 540 | return RESULT_SUCCESS; | 541 | return RESULT_SUCCESS; |
| @@ -546,14 +547,15 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) { | |||
| 546 | return ERR_INVALID_THREAD_PRIORITY; | 547 | return ERR_INVALID_THREAD_PRIORITY; |
| 547 | } | 548 | } |
| 548 | 549 | ||
| 549 | auto& kernel = Core::System::GetInstance().Kernel(); | 550 | const auto* const current_process = Core::CurrentProcess(); |
| 550 | SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle); | 551 | SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); |
| 551 | if (!thread) | 552 | if (!thread) { |
| 552 | return ERR_INVALID_HANDLE; | 553 | return ERR_INVALID_HANDLE; |
| 554 | } | ||
| 553 | 555 | ||
| 554 | // Note: The kernel uses the current process's resource limit instead of | 556 | // Note: The kernel uses the current process's resource limit instead of |
| 555 | // the one from the thread owner's resource limit. | 557 | // the one from the thread owner's resource limit. |
| 556 | const ResourceLimit& resource_limit = Core::CurrentProcess()->GetResourceLimit(); | 558 | const ResourceLimit& resource_limit = current_process->GetResourceLimit(); |
| 557 | if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { | 559 | if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { |
| 558 | return ERR_NOT_AUTHORIZED; | 560 | return ERR_NOT_AUTHORIZED; |
| 559 | } | 561 | } |
| @@ -595,15 +597,13 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s | |||
| 595 | return ERR_INVALID_MEMORY_PERMISSIONS; | 597 | return ERR_INVALID_MEMORY_PERMISSIONS; |
| 596 | } | 598 | } |
| 597 | 599 | ||
| 598 | auto& kernel = Core::System::GetInstance().Kernel(); | 600 | auto* const current_process = Core::CurrentProcess(); |
| 599 | auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle); | 601 | auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle); |
| 600 | if (!shared_memory) { | 602 | if (!shared_memory) { |
| 601 | return ERR_INVALID_HANDLE; | 603 | return ERR_INVALID_HANDLE; |
| 602 | } | 604 | } |
| 603 | 605 | ||
| 604 | auto* const current_process = Core::CurrentProcess(); | ||
| 605 | const auto& vm_manager = current_process->VMManager(); | 606 | const auto& vm_manager = current_process->VMManager(); |
| 606 | |||
| 607 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { | 607 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { |
| 608 | return ERR_INVALID_MEMORY_RANGE; | 608 | return ERR_INVALID_MEMORY_RANGE; |
| 609 | } | 609 | } |
| @@ -627,15 +627,13 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 | |||
| 627 | return ERR_INVALID_ADDRESS_STATE; | 627 | return ERR_INVALID_ADDRESS_STATE; |
| 628 | } | 628 | } |
| 629 | 629 | ||
| 630 | auto& kernel = Core::System::GetInstance().Kernel(); | 630 | auto* const current_process = Core::CurrentProcess(); |
| 631 | auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle); | 631 | auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle); |
| 632 | if (!shared_memory) { | 632 | if (!shared_memory) { |
| 633 | return ERR_INVALID_HANDLE; | 633 | return ERR_INVALID_HANDLE; |
| 634 | } | 634 | } |
| 635 | 635 | ||
| 636 | auto* const current_process = Core::CurrentProcess(); | ||
| 637 | const auto& vm_manager = current_process->VMManager(); | 636 | const auto& vm_manager = current_process->VMManager(); |
| 638 | |||
| 639 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { | 637 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { |
| 640 | return ERR_INVALID_MEMORY_RANGE; | 638 | return ERR_INVALID_MEMORY_RANGE; |
| 641 | } | 639 | } |
| @@ -646,9 +644,8 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 | |||
| 646 | /// Query process memory | 644 | /// Query process memory |
| 647 | static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/, | 645 | static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/, |
| 648 | Handle process_handle, u64 addr) { | 646 | Handle process_handle, u64 addr) { |
| 649 | 647 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | |
| 650 | auto& kernel = Core::System::GetInstance().Kernel(); | 648 | SharedPtr<Process> process = handle_table.Get<Process>(process_handle); |
| 651 | SharedPtr<Process> process = kernel.HandleTable().Get<Process>(process_handle); | ||
| 652 | if (!process) { | 649 | if (!process) { |
| 653 | return ERR_INVALID_HANDLE; | 650 | return ERR_INVALID_HANDLE; |
| 654 | } | 651 | } |
| @@ -695,20 +692,19 @@ static void ExitProcess() { | |||
| 695 | /// Creates a new thread | 692 | /// Creates a new thread |
| 696 | static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top, | 693 | static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top, |
| 697 | u32 priority, s32 processor_id) { | 694 | u32 priority, s32 processor_id) { |
| 698 | std::string name = fmt::format("thread-{:X}", entry_point); | ||
| 699 | |||
| 700 | if (priority > THREADPRIO_LOWEST) { | 695 | if (priority > THREADPRIO_LOWEST) { |
| 701 | return ERR_INVALID_THREAD_PRIORITY; | 696 | return ERR_INVALID_THREAD_PRIORITY; |
| 702 | } | 697 | } |
| 703 | 698 | ||
| 704 | const ResourceLimit& resource_limit = Core::CurrentProcess()->GetResourceLimit(); | 699 | auto* const current_process = Core::CurrentProcess(); |
| 700 | const ResourceLimit& resource_limit = current_process->GetResourceLimit(); | ||
| 705 | if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { | 701 | if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { |
| 706 | return ERR_NOT_AUTHORIZED; | 702 | return ERR_NOT_AUTHORIZED; |
| 707 | } | 703 | } |
| 708 | 704 | ||
| 709 | if (processor_id == THREADPROCESSORID_DEFAULT) { | 705 | if (processor_id == THREADPROCESSORID_DEFAULT) { |
| 710 | // Set the target CPU to the one specified in the process' exheader. | 706 | // Set the target CPU to the one specified in the process' exheader. |
| 711 | processor_id = Core::CurrentProcess()->GetDefaultProcessorID(); | 707 | processor_id = current_process->GetDefaultProcessorID(); |
| 712 | ASSERT(processor_id != THREADPROCESSORID_DEFAULT); | 708 | ASSERT(processor_id != THREADPROCESSORID_DEFAULT); |
| 713 | } | 709 | } |
| 714 | 710 | ||
| @@ -723,11 +719,13 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 723 | return ERR_INVALID_PROCESSOR_ID; | 719 | return ERR_INVALID_PROCESSOR_ID; |
| 724 | } | 720 | } |
| 725 | 721 | ||
| 722 | const std::string name = fmt::format("thread-{:X}", entry_point); | ||
| 726 | auto& kernel = Core::System::GetInstance().Kernel(); | 723 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 727 | CASCADE_RESULT(SharedPtr<Thread> thread, | 724 | CASCADE_RESULT(SharedPtr<Thread> thread, |
| 728 | Thread::Create(kernel, name, entry_point, priority, arg, processor_id, stack_top, | 725 | Thread::Create(kernel, name, entry_point, priority, arg, processor_id, stack_top, |
| 729 | *Core::CurrentProcess())); | 726 | *current_process)); |
| 730 | const auto new_guest_handle = kernel.HandleTable().Create(thread); | 727 | |
| 728 | const auto new_guest_handle = current_process->GetHandleTable().Create(thread); | ||
| 731 | if (new_guest_handle.Failed()) { | 729 | if (new_guest_handle.Failed()) { |
| 732 | return new_guest_handle.Code(); | 730 | return new_guest_handle.Code(); |
| 733 | } | 731 | } |
| @@ -748,8 +746,8 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 748 | static ResultCode StartThread(Handle thread_handle) { | 746 | static ResultCode StartThread(Handle thread_handle) { |
| 749 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); | 747 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); |
| 750 | 748 | ||
| 751 | auto& kernel = Core::System::GetInstance().Kernel(); | 749 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 752 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 750 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 753 | if (!thread) { | 751 | if (!thread) { |
| 754 | return ERR_INVALID_HANDLE; | 752 | return ERR_INVALID_HANDLE; |
| 755 | } | 753 | } |
| @@ -796,8 +794,8 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr condition_var | |||
| 796 | "called mutex_addr={:X}, condition_variable_addr={:X}, thread_handle=0x{:08X}, timeout={}", | 794 | "called mutex_addr={:X}, condition_variable_addr={:X}, thread_handle=0x{:08X}, timeout={}", |
| 797 | mutex_addr, condition_variable_addr, thread_handle, nano_seconds); | 795 | mutex_addr, condition_variable_addr, thread_handle, nano_seconds); |
| 798 | 796 | ||
| 799 | auto& kernel = Core::System::GetInstance().Kernel(); | 797 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 800 | SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 798 | SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 801 | ASSERT(thread); | 799 | ASSERT(thread); |
| 802 | 800 | ||
| 803 | CASCADE_CODE(Mutex::Release(mutex_addr)); | 801 | CASCADE_CODE(Mutex::Release(mutex_addr)); |
| @@ -908,9 +906,9 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target | |||
| 908 | mutex_val | Mutex::MutexHasWaitersFlag)); | 906 | mutex_val | Mutex::MutexHasWaitersFlag)); |
| 909 | 907 | ||
| 910 | // The mutex is already owned by some other thread, make this thread wait on it. | 908 | // The mutex is already owned by some other thread, make this thread wait on it. |
| 911 | auto& kernel = Core::System::GetInstance().Kernel(); | 909 | const Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask); |
| 912 | Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask); | 910 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 913 | auto owner = kernel.HandleTable().Get<Thread>(owner_handle); | 911 | auto owner = handle_table.Get<Thread>(owner_handle); |
| 914 | ASSERT(owner); | 912 | ASSERT(owner); |
| 915 | ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex); | 913 | ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex); |
| 916 | thread->InvalidateWakeupCallback(); | 914 | thread->InvalidateWakeupCallback(); |
| @@ -989,16 +987,16 @@ static u64 GetSystemTick() { | |||
| 989 | static ResultCode CloseHandle(Handle handle) { | 987 | static ResultCode CloseHandle(Handle handle) { |
| 990 | LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle); | 988 | LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle); |
| 991 | 989 | ||
| 992 | auto& kernel = Core::System::GetInstance().Kernel(); | 990 | auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 993 | return kernel.HandleTable().Close(handle); | 991 | return handle_table.Close(handle); |
| 994 | } | 992 | } |
| 995 | 993 | ||
| 996 | /// Reset an event | 994 | /// Reset an event |
| 997 | static ResultCode ResetSignal(Handle handle) { | 995 | static ResultCode ResetSignal(Handle handle) { |
| 998 | LOG_WARNING(Kernel_SVC, "(STUBBED) called handle 0x{:08X}", handle); | 996 | LOG_WARNING(Kernel_SVC, "(STUBBED) called handle 0x{:08X}", handle); |
| 999 | 997 | ||
| 1000 | auto& kernel = Core::System::GetInstance().Kernel(); | 998 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1001 | auto event = kernel.HandleTable().Get<Event>(handle); | 999 | auto event = handle_table.Get<Event>(handle); |
| 1002 | 1000 | ||
| 1003 | ASSERT(event != nullptr); | 1001 | ASSERT(event != nullptr); |
| 1004 | 1002 | ||
| @@ -1017,8 +1015,8 @@ static ResultCode CreateTransferMemory(Handle* handle, VAddr addr, u64 size, u32 | |||
| 1017 | static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) { | 1015 | static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) { |
| 1018 | LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); | 1016 | LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); |
| 1019 | 1017 | ||
| 1020 | auto& kernel = Core::System::GetInstance().Kernel(); | 1018 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1021 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 1019 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 1022 | if (!thread) { | 1020 | if (!thread) { |
| 1023 | return ERR_INVALID_HANDLE; | 1021 | return ERR_INVALID_HANDLE; |
| 1024 | } | 1022 | } |
| @@ -1033,8 +1031,8 @@ static ResultCode SetThreadCoreMask(Handle thread_handle, u32 core, u64 mask) { | |||
| 1033 | LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, mask=0x{:16X}, core=0x{:X}", thread_handle, | 1031 | LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, mask=0x{:16X}, core=0x{:X}", thread_handle, |
| 1034 | mask, core); | 1032 | mask, core); |
| 1035 | 1033 | ||
| 1036 | auto& kernel = Core::System::GetInstance().Kernel(); | 1034 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1037 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 1035 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 1038 | if (!thread) { | 1036 | if (!thread) { |
| 1039 | return ERR_INVALID_HANDLE; | 1037 | return ERR_INVALID_HANDLE; |
| 1040 | } | 1038 | } |
| @@ -1095,7 +1093,7 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss | |||
| 1095 | } | 1093 | } |
| 1096 | 1094 | ||
| 1097 | auto& kernel = Core::System::GetInstance().Kernel(); | 1095 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 1098 | auto& handle_table = kernel.HandleTable(); | 1096 | auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1099 | auto shared_mem_handle = | 1097 | auto shared_mem_handle = |
| 1100 | SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size, | 1098 | SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size, |
| 1101 | local_perms, remote_perms); | 1099 | local_perms, remote_perms); |
| @@ -1107,10 +1105,12 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss | |||
| 1107 | static ResultCode ClearEvent(Handle handle) { | 1105 | static ResultCode ClearEvent(Handle handle) { |
| 1108 | LOG_TRACE(Kernel_SVC, "called, event=0x{:08X}", handle); | 1106 | LOG_TRACE(Kernel_SVC, "called, event=0x{:08X}", handle); |
| 1109 | 1107 | ||
| 1110 | auto& kernel = Core::System::GetInstance().Kernel(); | 1108 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1111 | SharedPtr<Event> evt = kernel.HandleTable().Get<Event>(handle); | 1109 | SharedPtr<Event> evt = handle_table.Get<Event>(handle); |
| 1112 | if (evt == nullptr) | 1110 | if (evt == nullptr) { |
| 1113 | return ERR_INVALID_HANDLE; | 1111 | return ERR_INVALID_HANDLE; |
| 1112 | } | ||
| 1113 | |||
| 1114 | evt->Clear(); | 1114 | evt->Clear(); |
| 1115 | return RESULT_SUCCESS; | 1115 | return RESULT_SUCCESS; |
| 1116 | } | 1116 | } |
| @@ -1123,8 +1123,8 @@ static ResultCode GetProcessInfo(u64* out, Handle process_handle, u32 type) { | |||
| 1123 | Status, | 1123 | Status, |
| 1124 | }; | 1124 | }; |
| 1125 | 1125 | ||
| 1126 | const auto& kernel = Core::System::GetInstance().Kernel(); | 1126 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1127 | const auto process = kernel.HandleTable().Get<Process>(process_handle); | 1127 | const auto process = handle_table.Get<Process>(process_handle); |
| 1128 | if (!process) { | 1128 | if (!process) { |
| 1129 | return ERR_INVALID_HANDLE; | 1129 | return ERR_INVALID_HANDLE; |
| 1130 | } | 1130 | } |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 35ec98c1a..59bc9e0af 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -266,7 +266,7 @@ SharedPtr<Thread> SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 pri | |||
| 266 | SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); | 266 | SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); |
| 267 | 267 | ||
| 268 | // Register 1 must be a handle to the main thread | 268 | // Register 1 must be a handle to the main thread |
| 269 | const Handle guest_handle = kernel.HandleTable().Create(thread).Unwrap(); | 269 | const Handle guest_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); |
| 270 | thread->SetGuestHandle(guest_handle); | 270 | thread->SetGuestHandle(guest_handle); |
| 271 | thread->GetContext().cpu_registers[1] = guest_handle; | 271 | thread->GetContext().cpu_registers[1] = guest_handle; |
| 272 | 272 | ||
diff --git a/src/yuzu/debugger/wait_tree.cpp b/src/yuzu/debugger/wait_tree.cpp index 7403e9ccd..0c831c9f4 100644 --- a/src/yuzu/debugger/wait_tree.cpp +++ b/src/yuzu/debugger/wait_tree.cpp | |||
| @@ -9,8 +9,8 @@ | |||
| 9 | #include "core/core.h" | 9 | #include "core/core.h" |
| 10 | #include "core/hle/kernel/event.h" | 10 | #include "core/hle/kernel/event.h" |
| 11 | #include "core/hle/kernel/handle_table.h" | 11 | #include "core/hle/kernel/handle_table.h" |
| 12 | #include "core/hle/kernel/kernel.h" | ||
| 13 | #include "core/hle/kernel/mutex.h" | 12 | #include "core/hle/kernel/mutex.h" |
| 13 | #include "core/hle/kernel/process.h" | ||
| 14 | #include "core/hle/kernel/scheduler.h" | 14 | #include "core/hle/kernel/scheduler.h" |
| 15 | #include "core/hle/kernel/thread.h" | 15 | #include "core/hle/kernel/thread.h" |
| 16 | #include "core/hle/kernel/timer.h" | 16 | #include "core/hle/kernel/timer.h" |
| @@ -83,7 +83,7 @@ QString WaitTreeText::GetText() const { | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | WaitTreeMutexInfo::WaitTreeMutexInfo(VAddr mutex_address) : mutex_address(mutex_address) { | 85 | WaitTreeMutexInfo::WaitTreeMutexInfo(VAddr mutex_address) : mutex_address(mutex_address) { |
| 86 | auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); | 86 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 87 | 87 | ||
| 88 | mutex_value = Memory::Read32(mutex_address); | 88 | mutex_value = Memory::Read32(mutex_address); |
| 89 | owner_handle = static_cast<Kernel::Handle>(mutex_value & Kernel::Mutex::MutexOwnerMask); | 89 | owner_handle = static_cast<Kernel::Handle>(mutex_value & Kernel::Mutex::MutexOwnerMask); |