skyline/app/src/main/cpp/skyline/kernel/types/KThread.h

56 lines
2.5 KiB
C
Raw Normal View History

#pragma once
#include "KSyncObject.h"
namespace skyline::kernel::type {
/**
* @brief KThread class is responsible for holding the state of a thread
*/
class KThread : public KSyncObject {
private:
KProcess *parent; //!< The parent process of this thread
u64 entryPoint; //!< The address to start execution at
u64 entryArg; //!< An argument to pass to the process on entry
public:
enum class ThreadStatus { Created, Running, Waiting, Runnable } status = ThreadStatus::Created; //!< The state of the thread
std::vector<handle_t> waitHandles; //!< A vector holding handles this thread is waiting for
u64 timeoutEnd{}; //!< The time when a svcWaitSynchronization
pid_t pid; //!< The PID of the current thread (As in kernel PID and not PGID [In short, Linux implements threads as processes that share a lot of stuff at the kernel level])
u64 stackTop; //!< The top of the stack (Where it starts growing downwards from)
u64 tls; //!< The address of TLS (Thread Local Storage) slot assigned to the current thread
u8 priority; //!< Hold the priority of a thread in Nintendo format
/**
* @param handle The handle of the current thread
* @param parent_pid The PID of the main thread
* @param state The state of the device
* @param self_pid The PID of this thread
* @param entryPoint The address to start execution at
* @param entryArg An argument to pass to the process on entry
* @param stackTop The top of the stack
* @param tls The address of the TLS slot assigned
* @param priority The priority of the thread in Nintendo format
* @param parent The parent process of this thread
*/
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);
/**
* @brief Kills the thread and deallocates the memory allocated for stack.
*/
~KThread();
/**
* @brief Starts the current thread
*/
void Start();
/**
* @brief Update the priority level for the process.
* @details Set the priority of the current thread to `priority` using setpriority [https://linux.die.net/man/3/setpriority]. We rescale the priority from Nintendo scale to that of Android.
* @param priority The priority of the thread in Nintendo format
*/
void UpdatePriority(u8 priority);
};
}