mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-25 09:40:15 +00:00
Core/HLE: Implemented the SVCs GetProcessId and GetProcessIdOfThread
This commit is contained in:
parent
e98fbadf4a
commit
41f74a16fd
@ -115,8 +115,7 @@ SharedPtr<Object> HandleTable::GetGeneric(Handle handle) const {
|
|||||||
if (handle == CurrentThread) {
|
if (handle == CurrentThread) {
|
||||||
return GetCurrentThread();
|
return GetCurrentThread();
|
||||||
} else if (handle == CurrentProcess) {
|
} else if (handle == CurrentProcess) {
|
||||||
LOG_ERROR(Kernel, "Current process (%08X) pseudo-handle not supported", CurrentProcess);
|
return g_current_process;
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValid(handle)) {
|
if (!IsValid(handle)) {
|
||||||
@ -138,6 +137,7 @@ void Init() {
|
|||||||
Kernel::ThreadingInit();
|
Kernel::ThreadingInit();
|
||||||
Kernel::TimersInit();
|
Kernel::TimersInit();
|
||||||
|
|
||||||
|
Process::next_process_id = 0;
|
||||||
Object::next_object_id = 0;
|
Object::next_object_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
u32 Process::next_process_id;
|
||||||
|
|
||||||
SharedPtr<Process> Process::Create(std::string name, u64 program_id) {
|
SharedPtr<Process> Process::Create(std::string name, u64 program_id) {
|
||||||
SharedPtr<Process> process(new Process);
|
SharedPtr<Process> process(new Process);
|
||||||
|
|
||||||
|
@ -55,6 +55,14 @@ public:
|
|||||||
static const HandleType HANDLE_TYPE = HandleType::Process;
|
static const HandleType HANDLE_TYPE = HandleType::Process;
|
||||||
HandleType GetHandleType() const override { return HANDLE_TYPE; }
|
HandleType GetHandleType() const override { return HANDLE_TYPE; }
|
||||||
|
|
||||||
|
static u32 next_process_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gets the process' id
|
||||||
|
* @returns The process' id
|
||||||
|
*/
|
||||||
|
u32 GetProcessId() const { return process_id; }
|
||||||
|
|
||||||
/// Name of the process
|
/// Name of the process
|
||||||
std::string name;
|
std::string name;
|
||||||
/// Title ID corresponding to the process
|
/// Title ID corresponding to the process
|
||||||
@ -69,6 +77,9 @@ public:
|
|||||||
boost::container::static_vector<AddressMapping, 8> address_mappings;
|
boost::container::static_vector<AddressMapping, 8> address_mappings;
|
||||||
ProcessFlags flags;
|
ProcessFlags flags;
|
||||||
|
|
||||||
|
/// The id of this process
|
||||||
|
u32 process_id = next_process_id++;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them
|
* Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them
|
||||||
* to this process.
|
* to this process.
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/hle/hle.h"
|
#include "core/hle/hle.h"
|
||||||
#include "core/hle/kernel/kernel.h"
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
#include "core/hle/kernel/process.h"
|
||||||
#include "core/hle/kernel/thread.h"
|
#include "core/hle/kernel/thread.h"
|
||||||
#include "core/hle/kernel/mutex.h"
|
#include "core/hle/kernel/mutex.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
@ -402,6 +403,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
|
|||||||
thread->wait_address = 0;
|
thread->wait_address = 0;
|
||||||
thread->name = std::move(name);
|
thread->name = std::move(name);
|
||||||
thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
|
thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
|
||||||
|
thread->owner_process = g_current_process;
|
||||||
|
|
||||||
VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200;
|
VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200;
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ enum ThreadStatus {
|
|||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
class Mutex;
|
class Mutex;
|
||||||
|
class Process;
|
||||||
|
|
||||||
class Thread final : public WaitObject {
|
class Thread final : public WaitObject {
|
||||||
public:
|
public:
|
||||||
@ -161,6 +162,7 @@ public:
|
|||||||
/// Mutexes currently held by this thread, which will be released when it exits.
|
/// Mutexes currently held by this thread, which will be released when it exits.
|
||||||
boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
|
boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
|
||||||
|
|
||||||
|
SharedPtr<Process> owner_process; ///< Process that owns this thread
|
||||||
std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on
|
std::vector<SharedPtr<WaitObject>> wait_objects; ///< Objects that the thread is waiting on
|
||||||
VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address
|
VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address
|
||||||
bool wait_all; ///< True if the thread is waiting on all objects before resuming
|
bool wait_all; ///< True if the thread is waiting on all objects before resuming
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "core/hle/kernel/address_arbiter.h"
|
#include "core/hle/kernel/address_arbiter.h"
|
||||||
#include "core/hle/kernel/event.h"
|
#include "core/hle/kernel/event.h"
|
||||||
#include "core/hle/kernel/mutex.h"
|
#include "core/hle/kernel/mutex.h"
|
||||||
|
#include "core/hle/kernel/process.h"
|
||||||
#include "core/hle/kernel/semaphore.h"
|
#include "core/hle/kernel/semaphore.h"
|
||||||
#include "core/hle/kernel/shared_memory.h"
|
#include "core/hle/kernel/shared_memory.h"
|
||||||
#include "core/hle/kernel/thread.h"
|
#include "core/hle/kernel/thread.h"
|
||||||
@ -424,6 +425,34 @@ static ResultCode ReleaseMutex(Handle handle) {
|
|||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the ID of the specified process
|
||||||
|
static ResultCode GetProcessId(u32* process_id, Handle handle) {
|
||||||
|
LOG_TRACE(Kernel_SVC, "called process=0x%08X", handle);
|
||||||
|
|
||||||
|
const SharedPtr<Kernel::Process> process = Kernel::g_handle_table.Get<Kernel::Process>(handle);
|
||||||
|
if (process == nullptr)
|
||||||
|
return ERR_INVALID_HANDLE;
|
||||||
|
|
||||||
|
*process_id = process->GetProcessId();
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the ID of the process that owns the specified thread
|
||||||
|
static ResultCode GetProcessIdOfThread(u32* process_id, Handle handle) {
|
||||||
|
LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
|
||||||
|
|
||||||
|
const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
|
||||||
|
if (thread == nullptr)
|
||||||
|
return ERR_INVALID_HANDLE;
|
||||||
|
|
||||||
|
const SharedPtr<Kernel::Process> process = thread->owner_process;
|
||||||
|
if (process == nullptr)
|
||||||
|
return ERR_INVALID_HANDLE;
|
||||||
|
|
||||||
|
*process_id = process->process_id;
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the ID for the specified thread.
|
/// Get the ID for the specified thread.
|
||||||
static ResultCode GetThreadId(u32* thread_id, Handle handle) {
|
static ResultCode GetThreadId(u32* thread_id, Handle handle) {
|
||||||
LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
|
LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
|
||||||
@ -674,8 +703,8 @@ static const FunctionDef SVC_Table[] = {
|
|||||||
{0x32, HLE::Wrap<SendSyncRequest>, "SendSyncRequest"},
|
{0x32, HLE::Wrap<SendSyncRequest>, "SendSyncRequest"},
|
||||||
{0x33, nullptr, "OpenProcess"},
|
{0x33, nullptr, "OpenProcess"},
|
||||||
{0x34, nullptr, "OpenThread"},
|
{0x34, nullptr, "OpenThread"},
|
||||||
{0x35, nullptr, "GetProcessId"},
|
{0x35, HLE::Wrap<GetProcessId>, "GetProcessId"},
|
||||||
{0x36, nullptr, "GetProcessIdOfThread"},
|
{0x36, HLE::Wrap<GetProcessIdOfThread>, "GetProcessIdOfThread"},
|
||||||
{0x37, HLE::Wrap<GetThreadId>, "GetThreadId"},
|
{0x37, HLE::Wrap<GetThreadId>, "GetThreadId"},
|
||||||
{0x38, HLE::Wrap<GetResourceLimit>, "GetResourceLimit"},
|
{0x38, HLE::Wrap<GetResourceLimit>, "GetResourceLimit"},
|
||||||
{0x39, nullptr, "GetResourceLimitLimitValues"},
|
{0x39, nullptr, "GetResourceLimitLimitValues"},
|
||||||
|
Loading…
Reference in New Issue
Block a user