yuzu-emu
/
yuzu
Archived
1
0
Fork 0

Merge pull request #1925 from lioncash/pid

kernel/{process, thread}: Amend behavior related to IDs
This commit is contained in:
bunnei 2018-12-21 13:45:27 -05:00 committed by GitHub
commit 59ac3346eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 28 deletions

View File

@ -201,11 +201,11 @@ void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext) {
modules.push_back(std::move(module)); modules.push_back(std::move(module));
} }
static Kernel::Thread* FindThreadById(int id) { static Kernel::Thread* FindThreadById(s64 id) {
for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) { for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) {
const auto& threads = Core::System::GetInstance().Scheduler(core).GetThreadList(); const auto& threads = Core::System::GetInstance().Scheduler(core).GetThreadList();
for (auto& thread : threads) { for (auto& thread : threads) {
if (thread->GetThreadID() == static_cast<u32>(id)) { if (thread->GetThreadID() == static_cast<u64>(id)) {
current_core = core; current_core = core;
return thread.get(); return thread.get();
} }

View File

@ -112,7 +112,7 @@ struct KernelCore::Impl {
void Shutdown() { void Shutdown() {
next_object_id = 0; next_object_id = 0;
next_process_id = 10; next_process_id = Process::ProcessIDMin;
next_thread_id = 1; next_thread_id = 1;
process_list.clear(); process_list.clear();
@ -153,10 +153,8 @@ struct KernelCore::Impl {
} }
std::atomic<u32> next_object_id{0}; std::atomic<u32> next_object_id{0};
// TODO(Subv): Start the process ids from 10 for now, as lower PIDs are std::atomic<u64> next_process_id{Process::ProcessIDMin};
// reserved for low-level services std::atomic<u64> next_thread_id{1};
std::atomic<u32> next_process_id{10};
std::atomic<u32> next_thread_id{1};
// Lists all processes that exist in the current session. // Lists all processes that exist in the current session.
std::vector<SharedPtr<Process>> process_list; std::vector<SharedPtr<Process>> process_list;
@ -242,11 +240,11 @@ u32 KernelCore::CreateNewObjectID() {
return impl->next_object_id++; return impl->next_object_id++;
} }
u32 KernelCore::CreateNewThreadID() { u64 KernelCore::CreateNewThreadID() {
return impl->next_thread_id++; return impl->next_thread_id++;
} }
u32 KernelCore::CreateNewProcessID() { u64 KernelCore::CreateNewProcessID() {
return impl->next_process_id++; return impl->next_process_id++;
} }

View File

@ -88,10 +88,10 @@ private:
u32 CreateNewObjectID(); u32 CreateNewObjectID();
/// Creates a new process ID, incrementing the internal process ID counter; /// Creates a new process ID, incrementing the internal process ID counter;
u32 CreateNewProcessID(); u64 CreateNewProcessID();
/// Creates a new thread ID, incrementing the internal thread ID counter. /// Creates a new thread ID, incrementing the internal thread ID counter.
u32 CreateNewThreadID(); u64 CreateNewThreadID();
/// Creates a timer callback handle for the given timer. /// Creates a timer callback handle for the given timer.
ResultVal<Handle> CreateTimerCallbackHandle(const SharedPtr<Timer>& timer); ResultVal<Handle> CreateTimerCallbackHandle(const SharedPtr<Timer>& timer);

View File

@ -120,6 +120,18 @@ struct CodeSet final {
class Process final : public WaitObject { class Process final : public WaitObject {
public: public:
enum : u64 {
/// Lowest allowed process ID for a kernel initial process.
InitialKIPIDMin = 1,
/// Highest allowed process ID for a kernel initial process.
InitialKIPIDMax = 80,
/// Lowest allowed process ID for a userland process.
ProcessIDMin = 81,
/// Highest allowed process ID for a userland process.
ProcessIDMax = 0xFFFFFFFFFFFFFFFF,
};
static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4; static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4;
static SharedPtr<Process> Create(KernelCore& kernel, std::string&& name); static SharedPtr<Process> Create(KernelCore& kernel, std::string&& name);
@ -162,7 +174,7 @@ public:
} }
/// Gets the unique ID that identifies this particular process. /// Gets the unique ID that identifies this particular process.
u32 GetProcessID() const { u64 GetProcessID() const {
return process_id; return process_id;
} }
@ -288,10 +300,10 @@ private:
ProcessStatus status; ProcessStatus status;
/// The ID of this process /// The ID of this process
u32 process_id = 0; u64 process_id = 0;
/// Title ID corresponding to the process /// Title ID corresponding to the process
u64 program_id; u64 program_id = 0;
/// Resource limit descriptor for this process /// Resource limit descriptor for this process
SharedPtr<ResourceLimit> resource_limit; SharedPtr<ResourceLimit> resource_limit;

View File

@ -391,7 +391,7 @@ static ResultCode SendSyncRequest(Handle handle) {
} }
/// Get the ID for the specified thread. /// Get the ID for the specified thread.
static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { static ResultCode GetThreadId(u64* thread_id, Handle thread_handle) {
LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
@ -405,20 +405,33 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) {
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
/// Get the ID of the specified process /// Gets the ID of the specified process or a specified thread's owning process.
static ResultCode GetProcessId(u32* process_id, Handle process_handle) { static ResultCode GetProcessId(u64* process_id, Handle handle) {
LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle);
const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); const SharedPtr<Process> process = handle_table.Get<Process>(handle);
if (!process) { if (process) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", *process_id = process->GetProcessID();
process_handle); return RESULT_SUCCESS;
return ERR_INVALID_HANDLE;
} }
*process_id = process->GetProcessID(); const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle);
return RESULT_SUCCESS; if (thread) {
const Process* const owner_process = thread->GetOwnerProcess();
if (!owner_process) {
LOG_ERROR(Kernel_SVC, "Non-existent owning process encountered.");
return ERR_INVALID_HANDLE;
}
*process_id = owner_process->GetProcessID();
return RESULT_SUCCESS;
}
// NOTE: This should also handle debug objects before returning.
LOG_ERROR(Kernel_SVC, "Handle does not exist, handle=0x{:08X}", handle);
return ERR_INVALID_HANDLE;
} }
/// Default thread wakeup callback for WaitSynchronization /// Default thread wakeup callback for WaitSynchronization

View File

@ -73,7 +73,15 @@ void SvcWrap() {
template <ResultCode func(u32*, u64)> template <ResultCode func(u32*, u64)>
void SvcWrap() { void SvcWrap() {
u32 param_1 = 0; u32 param_1 = 0;
u32 retval = func(&param_1, Param(1)).raw; const u32 retval = func(&param_1, Param(1)).raw;
Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval);
}
template <ResultCode func(u64*, u32)>
void SvcWrap() {
u64 param_1 = 0;
const u32 retval = func(&param_1, static_cast<u32>(Param(1))).raw;
Core::CurrentArmInterface().SetReg(1, param_1); Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval); FuncReturn(retval);
} }

View File

@ -151,7 +151,7 @@ public:
* Gets the thread's thread ID * Gets the thread's thread ID
* @return The thread's ID * @return The thread's ID
*/ */
u32 GetThreadID() const { u64 GetThreadID() const {
return thread_id; return thread_id;
} }
@ -379,7 +379,7 @@ private:
Core::ARM_Interface::ThreadContext context{}; Core::ARM_Interface::ThreadContext context{};
u32 thread_id = 0; u64 thread_id = 0;
ThreadStatus status = ThreadStatus::Dormant; ThreadStatus status = ThreadStatus::Dormant;