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
# include <sys/resource.h>
2020-03-26 15:33:19 +01:00
# include <nce.h>
2019-09-24 22:54:27 +02:00
# include "KThread.h"
# include "KProcess.h"
namespace skyline : : kernel : : type {
2020-04-19 21:56:49 +02:00
KThread : : 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 )
: handle ( handle ) , tid ( selfTid ) , entryPoint ( entryPoint ) , entryArg ( entryArg ) , stackTop ( stackTop ) , tls ( tls ) , priority ( priority ) , parent ( parent ) , ctxMemory ( tlsMemory ) , KSyncObject ( state , KType : : KThread ) {
2019-09-24 22:54:27 +02:00
UpdatePriority ( priority ) ;
}
KThread : : ~ KThread ( ) {
2019-11-22 15:59:50 +01:00
Kill ( ) ;
2019-09-24 22:54:27 +02:00
}
void KThread : : Start ( ) {
2020-01-11 05:52:25 +01:00
if ( status = = Status : : Created ) {
2020-04-19 21:56:49 +02:00
if ( tid = = parent - > pid )
2019-11-17 21:19:01 +01:00
parent - > status = KProcess : : Status : : Started ;
status = Status : : Running ;
2020-03-25 19:57:05 +01:00
2020-04-19 21:56:49 +02:00
state . nce - > StartThread ( entryArg , handle , parent - > threads . at ( tid ) ) ;
2019-11-17 21:19:01 +01:00
}
2019-09-24 22:54:27 +02:00
}
2019-11-22 15:59:50 +01:00
void KThread : : Kill ( ) {
2020-01-11 05:52:25 +01:00
if ( status ! = Status : : Dead ) {
2019-11-22 15:59:50 +01:00
status = Status : : Dead ;
Signal ( ) ;
2020-04-19 21:56:49 +02:00
tgkill ( parent - > pid , tid , SIGKILL ) ;
2019-11-22 15:59:50 +01:00
}
}
2019-09-24 22:54:27 +02:00
void KThread : : UpdatePriority ( u8 priority ) {
this - > priority = priority ;
2020-04-18 23:40:18 +02:00
auto linuxPriority =
static_cast < int8_t > ( constant : : AndroidPriority . first + ( ( static_cast < float > ( constant : : AndroidPriority . second - constant : : AndroidPriority . first ) / static_cast < float > ( constant : : SwitchPriority . second - constant : : SwitchPriority . first ) ) * ( static_cast < float > ( priority ) - constant : : SwitchPriority . first ) ) ) ; // Resize range SwitchPriority (Nintendo Priority) to AndroidPriority (Android Priority)
2020-03-25 18:59:37 +01:00
2020-04-19 21:56:49 +02:00
if ( setpriority ( PRIO_PROCESS , static_cast < id_t > ( tid ) , linuxPriority ) = = - 1 )
throw exception ( " Couldn't set process priority to {} for PID: {} " , linuxPriority , tid ) ;
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
}
2019-09-24 22:54:27 +02:00
}