2020-04-19 23:04:05 +02:00
// SPDX-License-Identifier: MPL-2.0
2020-03-27 20:36:02 +01:00
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
2019-09-24 22:54:27 +02:00
# pragma once
# include "KSyncObject.h"
2020-01-07 03:36:08 +01:00
# include "KSharedMemory.h"
2019-09-24 22:54:27 +02:00
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 :
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
enum class Status {
2019-10-16 14:41:30 +02:00
Created , //!< The thread has been created but has not been started yet
Running , //!< The thread is running currently
2019-11-22 15:59:50 +01:00
Dead //!< The thread is dead and not running
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
} status = Status : : Created ; //!< The state of the thread
2020-02-15 10:38:17 +01:00
std : : atomic < bool > cancelSync { false } ; //!< This is to flag to a thread to cancel a synchronization call it currently is in
2020-01-07 03:36:08 +01:00
std : : shared_ptr < type : : KSharedMemory > ctxMemory ; //!< The KSharedMemory of the shared memory allocated by the guest process TLS
2020-03-25 18:59:37 +01:00
KHandle handle ; // The handle of the object in the handle table
2020-04-19 21:56:49 +02:00
pid_t tid ; //!< The TID of the current thread
2019-09-24 22:54:27 +02:00
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
2020-02-01 16:51:32 +01:00
u8 priority ; //!< The priority of a thread in Nintendo format
2019-09-24 22:54:27 +02:00
/**
* @ param state The state of the device
2019-10-13 10:04:47 +02:00
* @ param handle The handle of the current thread
2020-04-19 21:56:49 +02:00
* @ param selfTid The TID of this thread
2019-09-24 22:54:27 +02:00
* @ 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
2020-01-07 03:36:08 +01:00
* @ param tlsMemory The KSharedMemory object for TLS memory allocated by the guest process
2019-09-24 22:54:27 +02:00
*/
2020-04-19 21:56:49 +02:00
KThread ( const DeviceState & state , KHandle handle , pid_t selfTid , u64 entryPoint , u64 entryArg , u64 stackTop , u64 tls , u8 priority , KProcess * parent , std : : shared_ptr < type : : KSharedMemory > & tlsMemory ) ;
2019-09-24 22:54:27 +02:00
/**
* @ brief Kills the thread and deallocates the memory allocated for stack .
*/
~ KThread ( ) ;
/**
2019-11-22 15:59:50 +01:00
* @ brief This starts this thread process
2019-09-24 22:54:27 +02:00
*/
void Start ( ) ;
2019-11-22 15:59:50 +01:00
/**
* @ brief This kills the thread
*/
void Kill ( ) ;
2019-09-24 22:54:27 +02:00
/**
* @ 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 ) ;
} ;
}