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 <syslog.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "common.h"
|
|
|
|
#include "kernel/types/KSharedMemory.h"
|
|
|
|
|
|
|
|
namespace skyline {
|
|
|
|
/**
|
|
|
|
* @brief The NCE (Native Code Execution) class is responsible for managing the state of catching instructions and directly controlling processes/threads
|
|
|
|
*/
|
|
|
|
class NCE {
|
|
|
|
private:
|
2020-01-07 03:36:08 +01:00
|
|
|
DeviceState &state; //!< The state of the device
|
|
|
|
std::unordered_map<pid_t, std::shared_ptr<std::thread>> threadMap; //!< This maps all of the host threads to their corresponding kernel thread
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-07 03:36:08 +01:00
|
|
|
* @brief This function is the event loop of a kernel thread managing a guest thread
|
|
|
|
* @param thread The PID of the thread to manage
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-07 03:36:08 +01:00
|
|
|
void KernelThread(pid_t thread);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
public:
|
2020-01-07 03:36:08 +01:00
|
|
|
NCE(DeviceState &state);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
2020-01-09 02:37:54 +01:00
|
|
|
/**
|
|
|
|
* @brief The destructor for NCE, this calls join() on all the threads
|
|
|
|
*/
|
|
|
|
~NCE();
|
|
|
|
|
2019-09-24 22:54:27 +02:00
|
|
|
/**
|
2020-01-07 03:36:08 +01:00
|
|
|
* @brief This function is the main event loop of the program
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
|
|
|
void Execute();
|
|
|
|
|
|
|
|
/**
|
2020-01-21 08:16:57 +01:00
|
|
|
* @brief Execute any arbitrary function on a specific child thread
|
2020-01-07 03:36:08 +01:00
|
|
|
* @param call The specific call to execute
|
|
|
|
* @param funcRegs A set of registers to run the function
|
|
|
|
* @param thread The thread to execute the function on
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-11 05:52:25 +01:00
|
|
|
void ExecuteFunction(ThreadCall call, Registers &funcRegs, std::shared_ptr<kernel::type::KThread> &thread);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-21 08:16:57 +01:00
|
|
|
* @brief Execute any arbitrary function on the child process
|
2020-01-07 03:36:08 +01:00
|
|
|
* @param call The specific call to execute
|
|
|
|
* @param funcRegs A set of registers to run the function
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
void ExecuteFunction(ThreadCall call, Registers &funcRegs);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-07 03:36:08 +01:00
|
|
|
* @brief Waits till a thread is ready to execute commands
|
|
|
|
* @param thread The KThread to wait for initialization
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-11 05:52:25 +01:00
|
|
|
void WaitThreadInit(std::shared_ptr<kernel::type::KThread> &thread);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-07 03:36:08 +01:00
|
|
|
* @brief Sets the X0 and X1 registers in a thread and starts it and it's kernel thread
|
2019-09-24 22:54:27 +02:00
|
|
|
* @param entryArg The argument to pass in for the entry function
|
2020-01-07 03:36:08 +01:00
|
|
|
* @param handle The handle of the main thread
|
|
|
|
* @param thread The thread to set the registers and start
|
|
|
|
* @note This function will block forever if the thread has already started
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-07 03:36:08 +01:00
|
|
|
void StartThread(u64 entryArg, u32 handle, std::shared_ptr<kernel::type::KThread> &thread);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @brief This prints out a trace and the CPU context
|
2020-01-07 03:36:08 +01:00
|
|
|
* @param numHist The amount of previous instructions to print (Can be 0)
|
|
|
|
* @param ctx The ThreadContext of the thread to log
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-07 03:36:08 +01:00
|
|
|
void ThreadTrace(u16 numHist = 10, ThreadContext *ctx = nullptr);
|
2019-12-25 20:03:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This patches specific parts of the code
|
|
|
|
* @param code A vector with the code to be patched
|
2020-01-07 03:36:08 +01:00
|
|
|
* @param baseAddress The address at which the code is mapped
|
|
|
|
* @param offset The offset of the code block from the base address
|
2019-12-25 20:03:57 +01:00
|
|
|
*/
|
2020-01-07 03:36:08 +01:00
|
|
|
std::vector<u32> PatchCode(std::vector<u8> &code, u64 baseAddress, i64 offset);
|
2019-09-24 22:54:27 +02:00
|
|
|
};
|
|
|
|
}
|