#include #include "KThread.h" #include "KProcess.h" #include "../../nce.h" namespace skyline::kernel::type { KThread::KThread(handle_t handle, pid_t parent_pid, const DeviceState &state, pid_t self_pid, u64 entryPoint, u64 entryArg, u64 stackTop, u64 tls, u8 priority, KProcess *parent) : pid(self_pid), entryPoint(entryPoint), entryArg(entryArg), stackTop(stackTop), tls(tls), priority(priority), parent(parent), KSyncObject(handle, parent_pid, state, KType::KThread) { UpdatePriority(priority); } KThread::~KThread() { kill(pid, SIGKILL); } void KThread::Start() { if (pid == parent->mainThread) parent->status = KProcess::ProcessStatus::Started; status = ThreadStatus::Running; state.nce->StartProcess(entryPoint, entryArg, stackTop, handle, pid); } void KThread::UpdatePriority(u8 priority) { this->priority = priority; auto liPriority = static_cast(constant::PriorityAn.first + ((static_cast(constant::PriorityAn.second - constant::PriorityAn.first) / static_cast(constant::PriorityNin.second - constant::PriorityNin.first)) * (static_cast(priority) - constant::PriorityNin.first))); // Resize range PriorityNin (Nintendo Priority) to PriorityAn (Android Priority) if (setpriority(PRIO_PROCESS, static_cast(pid), liPriority) == -1) throw exception(fmt::format("Couldn't set process priority to {} for PID: {}", liPriority, pid)); } }