Merge pull request #1925 from lioncash/pid
kernel/{process, thread}: Amend behavior related to IDs
This commit is contained in:
commit
59ac3346eb
7 changed files with 59 additions and 28 deletions
|
@ -201,11 +201,11 @@ void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext) {
|
|||
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++) {
|
||||
const auto& threads = Core::System::GetInstance().Scheduler(core).GetThreadList();
|
||||
for (auto& thread : threads) {
|
||||
if (thread->GetThreadID() == static_cast<u32>(id)) {
|
||||
if (thread->GetThreadID() == static_cast<u64>(id)) {
|
||||
current_core = core;
|
||||
return thread.get();
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ struct KernelCore::Impl {
|
|||
|
||||
void Shutdown() {
|
||||
next_object_id = 0;
|
||||
next_process_id = 10;
|
||||
next_process_id = Process::ProcessIDMin;
|
||||
next_thread_id = 1;
|
||||
|
||||
process_list.clear();
|
||||
|
@ -153,10 +153,8 @@ struct KernelCore::Impl {
|
|||
}
|
||||
|
||||
std::atomic<u32> next_object_id{0};
|
||||
// TODO(Subv): Start the process ids from 10 for now, as lower PIDs are
|
||||
// reserved for low-level services
|
||||
std::atomic<u32> next_process_id{10};
|
||||
std::atomic<u32> next_thread_id{1};
|
||||
std::atomic<u64> next_process_id{Process::ProcessIDMin};
|
||||
std::atomic<u64> next_thread_id{1};
|
||||
|
||||
// Lists all processes that exist in the current session.
|
||||
std::vector<SharedPtr<Process>> process_list;
|
||||
|
@ -242,11 +240,11 @@ u32 KernelCore::CreateNewObjectID() {
|
|||
return impl->next_object_id++;
|
||||
}
|
||||
|
||||
u32 KernelCore::CreateNewThreadID() {
|
||||
u64 KernelCore::CreateNewThreadID() {
|
||||
return impl->next_thread_id++;
|
||||
}
|
||||
|
||||
u32 KernelCore::CreateNewProcessID() {
|
||||
u64 KernelCore::CreateNewProcessID() {
|
||||
return impl->next_process_id++;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,10 +88,10 @@ private:
|
|||
u32 CreateNewObjectID();
|
||||
|
||||
/// 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.
|
||||
u32 CreateNewThreadID();
|
||||
u64 CreateNewThreadID();
|
||||
|
||||
/// Creates a timer callback handle for the given timer.
|
||||
ResultVal<Handle> CreateTimerCallbackHandle(const SharedPtr<Timer>& timer);
|
||||
|
|
|
@ -120,6 +120,18 @@ struct CodeSet final {
|
|||
|
||||
class Process final : public WaitObject {
|
||||
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 SharedPtr<Process> Create(KernelCore& kernel, std::string&& name);
|
||||
|
@ -162,7 +174,7 @@ public:
|
|||
}
|
||||
|
||||
/// Gets the unique ID that identifies this particular process.
|
||||
u32 GetProcessID() const {
|
||||
u64 GetProcessID() const {
|
||||
return process_id;
|
||||
}
|
||||
|
||||
|
@ -288,10 +300,10 @@ private:
|
|||
ProcessStatus status;
|
||||
|
||||
/// The ID of this process
|
||||
u32 process_id = 0;
|
||||
u64 process_id = 0;
|
||||
|
||||
/// Title ID corresponding to the process
|
||||
u64 program_id;
|
||||
u64 program_id = 0;
|
||||
|
||||
/// Resource limit descriptor for this process
|
||||
SharedPtr<ResourceLimit> resource_limit;
|
||||
|
|
|
@ -391,7 +391,7 @@ static ResultCode SendSyncRequest(Handle handle) {
|
|||
}
|
||||
|
||||
/// 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);
|
||||
|
||||
const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
|
||||
|
@ -405,22 +405,35 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) {
|
|||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
/// Get the ID of the specified process
|
||||
static ResultCode GetProcessId(u32* process_id, Handle process_handle) {
|
||||
LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle);
|
||||
/// Gets the ID of the specified process or a specified thread's owning process.
|
||||
static ResultCode GetProcessId(u64* process_id, Handle handle) {
|
||||
LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle);
|
||||
|
||||
const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
|
||||
const SharedPtr<Process> process = handle_table.Get<Process>(process_handle);
|
||||
if (!process) {
|
||||
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
|
||||
process_handle);
|
||||
const SharedPtr<Process> process = handle_table.Get<Process>(handle);
|
||||
if (process) {
|
||||
*process_id = process->GetProcessID();
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle);
|
||||
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 = process->GetProcessID();
|
||||
*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
|
||||
static bool DefaultThreadWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread,
|
||||
SharedPtr<WaitObject> object, std::size_t index) {
|
||||
|
|
|
@ -73,7 +73,15 @@ void SvcWrap() {
|
|||
template <ResultCode func(u32*, u64)>
|
||||
void SvcWrap() {
|
||||
u32 param_1 = 0;
|
||||
u32 retval = func(¶m_1, Param(1)).raw;
|
||||
const u32 retval = func(¶m_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(¶m_1, static_cast<u32>(Param(1))).raw;
|
||||
Core::CurrentArmInterface().SetReg(1, param_1);
|
||||
FuncReturn(retval);
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ public:
|
|||
* Gets the thread's thread ID
|
||||
* @return The thread's ID
|
||||
*/
|
||||
u32 GetThreadID() const {
|
||||
u64 GetThreadID() const {
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,7 @@ private:
|
|||
|
||||
Core::ARM_Interface::ThreadContext context{};
|
||||
|
||||
u32 thread_id = 0;
|
||||
u64 thread_id = 0;
|
||||
|
||||
ThreadStatus status = ThreadStatus::Dormant;
|
||||
|
||||
|
|
Loading…
Reference in a new issue