diff options
| author | 2018-12-21 13:45:27 -0500 | |
|---|---|---|
| committer | 2018-12-21 13:45:27 -0500 | |
| commit | 59ac3346ebe605bfb0f538d9fa045b32d86168cb (patch) | |
| tree | d2793ede352840b4326cc7c56fc8e7b7a3e6670f /src | |
| parent | Merge pull request #1914 from lioncash/id (diff) | |
| parent | kernel/svc: Handle thread handles within GetProcessId (diff) | |
| download | yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.gz yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.xz yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.zip | |
Merge pull request #1925 from lioncash/pid
kernel/{process, thread}: Amend behavior related to IDs
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/gdbstub/gdbstub.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.h | 18 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 35 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc_wrap.h | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 4 |
7 files changed, 59 insertions, 28 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index e6b5171ee..a1cad4fcb 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp | |||
| @@ -201,11 +201,11 @@ void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext) { | |||
| 201 | modules.push_back(std::move(module)); | 201 | modules.push_back(std::move(module)); |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | static Kernel::Thread* FindThreadById(int id) { | 204 | static Kernel::Thread* FindThreadById(s64 id) { |
| 205 | for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) { | 205 | for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) { |
| 206 | const auto& threads = Core::System::GetInstance().Scheduler(core).GetThreadList(); | 206 | const auto& threads = Core::System::GetInstance().Scheduler(core).GetThreadList(); |
| 207 | for (auto& thread : threads) { | 207 | for (auto& thread : threads) { |
| 208 | if (thread->GetThreadID() == static_cast<u32>(id)) { | 208 | if (thread->GetThreadID() == static_cast<u64>(id)) { |
| 209 | current_core = core; | 209 | current_core = core; |
| 210 | return thread.get(); | 210 | return thread.get(); |
| 211 | } | 211 | } |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index e441c5bc6..1c2290651 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -112,7 +112,7 @@ struct KernelCore::Impl { | |||
| 112 | 112 | ||
| 113 | void Shutdown() { | 113 | void Shutdown() { |
| 114 | next_object_id = 0; | 114 | next_object_id = 0; |
| 115 | next_process_id = 10; | 115 | next_process_id = Process::ProcessIDMin; |
| 116 | next_thread_id = 1; | 116 | next_thread_id = 1; |
| 117 | 117 | ||
| 118 | process_list.clear(); | 118 | process_list.clear(); |
| @@ -153,10 +153,8 @@ struct KernelCore::Impl { | |||
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | std::atomic<u32> next_object_id{0}; | 155 | std::atomic<u32> next_object_id{0}; |
| 156 | // TODO(Subv): Start the process ids from 10 for now, as lower PIDs are | 156 | std::atomic<u64> next_process_id{Process::ProcessIDMin}; |
| 157 | // reserved for low-level services | 157 | std::atomic<u64> next_thread_id{1}; |
| 158 | std::atomic<u32> next_process_id{10}; | ||
| 159 | std::atomic<u32> next_thread_id{1}; | ||
| 160 | 158 | ||
| 161 | // Lists all processes that exist in the current session. | 159 | // Lists all processes that exist in the current session. |
| 162 | std::vector<SharedPtr<Process>> process_list; | 160 | std::vector<SharedPtr<Process>> process_list; |
| @@ -242,11 +240,11 @@ u32 KernelCore::CreateNewObjectID() { | |||
| 242 | return impl->next_object_id++; | 240 | return impl->next_object_id++; |
| 243 | } | 241 | } |
| 244 | 242 | ||
| 245 | u32 KernelCore::CreateNewThreadID() { | 243 | u64 KernelCore::CreateNewThreadID() { |
| 246 | return impl->next_thread_id++; | 244 | return impl->next_thread_id++; |
| 247 | } | 245 | } |
| 248 | 246 | ||
| 249 | u32 KernelCore::CreateNewProcessID() { | 247 | u64 KernelCore::CreateNewProcessID() { |
| 250 | return impl->next_process_id++; | 248 | return impl->next_process_id++; |
| 251 | } | 249 | } |
| 252 | 250 | ||
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index ea00c89f5..58c9d108b 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -88,10 +88,10 @@ private: | |||
| 88 | u32 CreateNewObjectID(); | 88 | u32 CreateNewObjectID(); |
| 89 | 89 | ||
| 90 | /// Creates a new process ID, incrementing the internal process ID counter; | 90 | /// Creates a new process ID, incrementing the internal process ID counter; |
| 91 | u32 CreateNewProcessID(); | 91 | u64 CreateNewProcessID(); |
| 92 | 92 | ||
| 93 | /// Creates a new thread ID, incrementing the internal thread ID counter. | 93 | /// Creates a new thread ID, incrementing the internal thread ID counter. |
| 94 | u32 CreateNewThreadID(); | 94 | u64 CreateNewThreadID(); |
| 95 | 95 | ||
| 96 | /// Creates a timer callback handle for the given timer. | 96 | /// Creates a timer callback handle for the given timer. |
| 97 | ResultVal<Handle> CreateTimerCallbackHandle(const SharedPtr<Timer>& timer); | 97 | ResultVal<Handle> CreateTimerCallbackHandle(const SharedPtr<Timer>& timer); |
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 459eedfa6..7da367251 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h | |||
| @@ -120,6 +120,18 @@ struct CodeSet final { | |||
| 120 | 120 | ||
| 121 | class Process final : public WaitObject { | 121 | class Process final : public WaitObject { |
| 122 | public: | 122 | public: |
| 123 | enum : u64 { | ||
| 124 | /// Lowest allowed process ID for a kernel initial process. | ||
| 125 | InitialKIPIDMin = 1, | ||
| 126 | /// Highest allowed process ID for a kernel initial process. | ||
| 127 | InitialKIPIDMax = 80, | ||
| 128 | |||
| 129 | /// Lowest allowed process ID for a userland process. | ||
| 130 | ProcessIDMin = 81, | ||
| 131 | /// Highest allowed process ID for a userland process. | ||
| 132 | ProcessIDMax = 0xFFFFFFFFFFFFFFFF, | ||
| 133 | }; | ||
| 134 | |||
| 123 | static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4; | 135 | static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4; |
| 124 | 136 | ||
| 125 | static SharedPtr<Process> Create(KernelCore& kernel, std::string&& name); | 137 | static SharedPtr<Process> Create(KernelCore& kernel, std::string&& name); |
| @@ -162,7 +174,7 @@ public: | |||
| 162 | } | 174 | } |
| 163 | 175 | ||
| 164 | /// Gets the unique ID that identifies this particular process. | 176 | /// Gets the unique ID that identifies this particular process. |
| 165 | u32 GetProcessID() const { | 177 | u64 GetProcessID() const { |
| 166 | return process_id; | 178 | return process_id; |
| 167 | } | 179 | } |
| 168 | 180 | ||
| @@ -288,10 +300,10 @@ private: | |||
| 288 | ProcessStatus status; | 300 | ProcessStatus status; |
| 289 | 301 | ||
| 290 | /// The ID of this process | 302 | /// The ID of this process |
| 291 | u32 process_id = 0; | 303 | u64 process_id = 0; |
| 292 | 304 | ||
| 293 | /// Title ID corresponding to the process | 305 | /// Title ID corresponding to the process |
| 294 | u64 program_id; | 306 | u64 program_id = 0; |
| 295 | 307 | ||
| 296 | /// Resource limit descriptor for this process | 308 | /// Resource limit descriptor for this process |
| 297 | SharedPtr<ResourceLimit> resource_limit; | 309 | SharedPtr<ResourceLimit> resource_limit; |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index c826dfd96..28268e112 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -391,7 +391,7 @@ static ResultCode SendSyncRequest(Handle handle) { | |||
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | /// Get the ID for the specified thread. | 393 | /// Get the ID for the specified thread. |
| 394 | static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { | 394 | static ResultCode GetThreadId(u64* thread_id, Handle thread_handle) { |
| 395 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); | 395 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); |
| 396 | 396 | ||
| 397 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 397 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| @@ -405,20 +405,33 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { | |||
| 405 | return RESULT_SUCCESS; | 405 | return RESULT_SUCCESS; |
| 406 | } | 406 | } |
| 407 | 407 | ||
| 408 | /// Get the ID of the specified process | 408 | /// Gets the ID of the specified process or a specified thread's owning process. |
| 409 | static ResultCode GetProcessId(u32* process_id, Handle process_handle) { | 409 | static ResultCode GetProcessId(u64* process_id, Handle handle) { |
| 410 | LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); | 410 | LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle); |
| 411 | 411 | ||
| 412 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 412 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 413 | const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); | 413 | const SharedPtr<Process> process = handle_table.Get<Process>(handle); |
| 414 | if (!process) { | 414 | if (process) { |
| 415 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", | 415 | *process_id = process->GetProcessID(); |
| 416 | process_handle); | 416 | return RESULT_SUCCESS; |
| 417 | return ERR_INVALID_HANDLE; | ||
| 418 | } | 417 | } |
| 419 | 418 | ||
| 420 | *process_id = process->GetProcessID(); | 419 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle); |
| 421 | return RESULT_SUCCESS; | 420 | if (thread) { |
| 421 | const Process* const owner_process = thread->GetOwnerProcess(); | ||
| 422 | if (!owner_process) { | ||
| 423 | LOG_ERROR(Kernel_SVC, "Non-existent owning process encountered."); | ||
| 424 | return ERR_INVALID_HANDLE; | ||
| 425 | } | ||
| 426 | |||
| 427 | *process_id = owner_process->GetProcessID(); | ||
| 428 | return RESULT_SUCCESS; | ||
| 429 | } | ||
| 430 | |||
| 431 | // NOTE: This should also handle debug objects before returning. | ||
| 432 | |||
| 433 | LOG_ERROR(Kernel_SVC, "Handle does not exist, handle=0x{:08X}", handle); | ||
| 434 | return ERR_INVALID_HANDLE; | ||
| 422 | } | 435 | } |
| 423 | 436 | ||
| 424 | /// Default thread wakeup callback for WaitSynchronization | 437 | /// Default thread wakeup callback for WaitSynchronization |
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h index 2f758b959..2a2c2c5ea 100644 --- a/src/core/hle/kernel/svc_wrap.h +++ b/src/core/hle/kernel/svc_wrap.h | |||
| @@ -73,7 +73,15 @@ void SvcWrap() { | |||
| 73 | template <ResultCode func(u32*, u64)> | 73 | template <ResultCode func(u32*, u64)> |
| 74 | void SvcWrap() { | 74 | void SvcWrap() { |
| 75 | u32 param_1 = 0; | 75 | u32 param_1 = 0; |
| 76 | u32 retval = func(¶m_1, Param(1)).raw; | 76 | const u32 retval = func(¶m_1, Param(1)).raw; |
| 77 | Core::CurrentArmInterface().SetReg(1, param_1); | ||
| 78 | FuncReturn(retval); | ||
| 79 | } | ||
| 80 | |||
| 81 | template <ResultCode func(u64*, u32)> | ||
| 82 | void SvcWrap() { | ||
| 83 | u64 param_1 = 0; | ||
| 84 | const u32 retval = func(¶m_1, static_cast<u32>(Param(1))).raw; | ||
| 77 | Core::CurrentArmInterface().SetReg(1, param_1); | 85 | Core::CurrentArmInterface().SetReg(1, param_1); |
| 78 | FuncReturn(retval); | 86 | FuncReturn(retval); |
| 79 | } | 87 | } |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 77aec099a..d6e7981d3 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -151,7 +151,7 @@ public: | |||
| 151 | * Gets the thread's thread ID | 151 | * Gets the thread's thread ID |
| 152 | * @return The thread's ID | 152 | * @return The thread's ID |
| 153 | */ | 153 | */ |
| 154 | u32 GetThreadID() const { | 154 | u64 GetThreadID() const { |
| 155 | return thread_id; | 155 | return thread_id; |
| 156 | } | 156 | } |
| 157 | 157 | ||
| @@ -379,7 +379,7 @@ private: | |||
| 379 | 379 | ||
| 380 | Core::ARM_Interface::ThreadContext context{}; | 380 | Core::ARM_Interface::ThreadContext context{}; |
| 381 | 381 | ||
| 382 | u32 thread_id = 0; | 382 | u64 thread_id = 0; |
| 383 | 383 | ||
| 384 | ThreadStatus status = ThreadStatus::Dormant; | 384 | ThreadStatus status = ThreadStatus::Dormant; |
| 385 | 385 | ||