summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/kernel.cpp6
-rw-r--r--src/core/hle/kernel/process.cpp2
-rw-r--r--src/core/hle/kernel/process.h5
-rw-r--r--src/core/hle/kernel/thread.cpp2
-rw-r--r--src/core/hle/kernel/thread.h2
-rw-r--r--src/core/hle/svc.cpp33
6 files changed, 46 insertions, 4 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index a3715e555..b5c98b249 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -115,8 +115,7 @@ SharedPtr<Object> HandleTable::GetGeneric(Handle handle) const {
115 if (handle == CurrentThread) { 115 if (handle == CurrentThread) {
116 return GetCurrentThread(); 116 return GetCurrentThread();
117 } else if (handle == CurrentProcess) { 117 } else if (handle == CurrentProcess) {
118 LOG_ERROR(Kernel, "Current process (%08X) pseudo-handle not supported", CurrentProcess); 118 return g_current_process;
119 return nullptr;
120 } 119 }
121 120
122 if (!IsValid(handle)) { 121 if (!IsValid(handle)) {
@@ -139,6 +138,9 @@ void Init() {
139 Kernel::TimersInit(); 138 Kernel::TimersInit();
140 139
141 Object::next_object_id = 0; 140 Object::next_object_id = 0;
141 // TODO(Subv): Start the process ids from 10 for now, as lower PIDs are
142 // reserved for low-level services
143 Process::next_process_id = 10;
142} 144}
143 145
144/// Shutdown the kernel 146/// Shutdown the kernel
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index efae4a179..1e439db9e 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -12,6 +12,8 @@
12 12
13namespace Kernel { 13namespace Kernel {
14 14
15u32 Process::next_process_id;
16
15SharedPtr<Process> Process::Create(std::string name, u64 program_id) { 17SharedPtr<Process> Process::Create(std::string name, u64 program_id) {
16 SharedPtr<Process> process(new Process); 18 SharedPtr<Process> process(new Process);
17 19
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 88ed9a5a5..22cd1049b 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -55,6 +55,8 @@ public:
55 static const HandleType HANDLE_TYPE = HandleType::Process; 55 static const HandleType HANDLE_TYPE = HandleType::Process;
56 HandleType GetHandleType() const override { return HANDLE_TYPE; } 56 HandleType GetHandleType() const override { return HANDLE_TYPE; }
57 57
58 static u32 next_process_id;
59
58 /// Name of the process 60 /// Name of the process
59 std::string name; 61 std::string name;
60 /// Title ID corresponding to the process 62 /// Title ID corresponding to the process
@@ -69,6 +71,9 @@ public:
69 boost::container::static_vector<AddressMapping, 8> address_mappings; 71 boost::container::static_vector<AddressMapping, 8> address_mappings;
70 ProcessFlags flags; 72 ProcessFlags flags;
71 73
74 /// The id of this process
75 u32 process_id = next_process_id++;
76
72 /** 77 /**
73 * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them 78 * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them
74 * to this process. 79 * to this process.
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 957cbdfee..ab69a4262 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -17,6 +17,7 @@
17#include "core/core_timing.h" 17#include "core/core_timing.h"
18#include "core/hle/hle.h" 18#include "core/hle/hle.h"
19#include "core/hle/kernel/kernel.h" 19#include "core/hle/kernel/kernel.h"
20#include "core/hle/kernel/process.h"
20#include "core/hle/kernel/thread.h" 21#include "core/hle/kernel/thread.h"
21#include "core/hle/kernel/mutex.h" 22#include "core/hle/kernel/mutex.h"
22#include "core/hle/result.h" 23#include "core/hle/result.h"
@@ -402,6 +403,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
402 thread->wait_address = 0; 403 thread->wait_address = 0;
403 thread->name = std::move(name); 404 thread->name = std::move(name);
404 thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom(); 405 thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
406 thread->owner_process = g_current_process;
405 407
406 VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200; 408 VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200;
407 409
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index afdaf8511..1d4d010fe 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -45,6 +45,7 @@ enum ThreadStatus {
45namespace Kernel { 45namespace Kernel {
46 46
47class Mutex; 47class Mutex;
48class Process;
48 49
49class Thread final : public WaitObject { 50class Thread final : public WaitObject {
50public: 51public:
@@ -161,6 +162,7 @@ public:
161 /// Mutexes currently held by this thread, which will be released when it exits. 162 /// Mutexes currently held by this thread, which will be released when it exits.
162 boost::container::flat_set<SharedPtr<Mutex>> held_mutexes; 163 boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
163 164
165 SharedPtr<Process> owner_process; ///< Process that owns this thread
164 std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on 166 std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on
165 VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address 167 VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address
166 bool wait_all; ///< True if the thread is waiting on all objects before resuming 168 bool wait_all; ///< True if the thread is waiting on all objects before resuming
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 1ec6599c7..e8159fbdb 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -16,6 +16,7 @@
16#include "core/hle/kernel/address_arbiter.h" 16#include "core/hle/kernel/address_arbiter.h"
17#include "core/hle/kernel/event.h" 17#include "core/hle/kernel/event.h"
18#include "core/hle/kernel/mutex.h" 18#include "core/hle/kernel/mutex.h"
19#include "core/hle/kernel/process.h"
19#include "core/hle/kernel/semaphore.h" 20#include "core/hle/kernel/semaphore.h"
20#include "core/hle/kernel/shared_memory.h" 21#include "core/hle/kernel/shared_memory.h"
21#include "core/hle/kernel/thread.h" 22#include "core/hle/kernel/thread.h"
@@ -424,6 +425,34 @@ static ResultCode ReleaseMutex(Handle handle) {
424 return RESULT_SUCCESS; 425 return RESULT_SUCCESS;
425} 426}
426 427
428/// Get the ID of the specified process
429static ResultCode GetProcessId(u32* process_id, Handle process_handle) {
430 LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle);
431
432 const SharedPtr<Kernel::Process> process = Kernel::g_handle_table.Get<Kernel::Process>(process_handle);
433 if (process == nullptr)
434 return ERR_INVALID_HANDLE;
435
436 *process_id = process->process_id;
437 return RESULT_SUCCESS;
438}
439
440/// Get the ID of the process that owns the specified thread
441static ResultCode GetProcessIdOfThread(u32* process_id, Handle thread_handle) {
442 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle);
443
444 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(thread_handle);
445 if (thread == nullptr)
446 return ERR_INVALID_HANDLE;
447
448 const SharedPtr<Kernel::Process> process = thread->owner_process;
449
450 ASSERT_MSG(process != nullptr, "Invalid parent process for thread=0x%08X", thread_handle);
451
452 *process_id = process->process_id;
453 return RESULT_SUCCESS;
454}
455
427/// Get the ID for the specified thread. 456/// Get the ID for the specified thread.
428static ResultCode GetThreadId(u32* thread_id, Handle handle) { 457static ResultCode GetThreadId(u32* thread_id, Handle handle) {
429 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); 458 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
@@ -674,8 +703,8 @@ static const FunctionDef SVC_Table[] = {
674 {0x32, HLE::Wrap<SendSyncRequest>, "SendSyncRequest"}, 703 {0x32, HLE::Wrap<SendSyncRequest>, "SendSyncRequest"},
675 {0x33, nullptr, "OpenProcess"}, 704 {0x33, nullptr, "OpenProcess"},
676 {0x34, nullptr, "OpenThread"}, 705 {0x34, nullptr, "OpenThread"},
677 {0x35, nullptr, "GetProcessId"}, 706 {0x35, HLE::Wrap<GetProcessId>, "GetProcessId"},
678 {0x36, nullptr, "GetProcessIdOfThread"}, 707 {0x36, HLE::Wrap<GetProcessIdOfThread>, "GetProcessIdOfThread"},
679 {0x37, HLE::Wrap<GetThreadId>, "GetThreadId"}, 708 {0x37, HLE::Wrap<GetThreadId>, "GetThreadId"},
680 {0x38, HLE::Wrap<GetResourceLimit>, "GetResourceLimit"}, 709 {0x38, HLE::Wrap<GetResourceLimit>, "GetResourceLimit"},
681 {0x39, nullptr, "GetResourceLimitLimitValues"}, 710 {0x39, nullptr, "GetResourceLimitLimitValues"},