skyline/app/src/main/cpp/skyline/nce.h
◱ PixelyIon 668f623256 Implement Exceptional Signal Handler + Fix Destruction Behavior
An exceptional signal handler allows us to convert an OS signal into a C++ exception, this allows us to alleviate a lot of crashes that would otherwise occur from signals being thrown during execution of games and be able to handle them gracefully.
2020-11-22 23:56:17 +05:30

38 lines
1.2 KiB
C++

// SPDX-License-Identifier: MPL-2.0
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
#pragma once
#include "common.h"
#include <sys/wait.h>
namespace skyline::nce {
/**
* @brief The NCE (Native Code Execution) class is responsible for managing state relevant to the layer between the host and guest
*/
class NCE {
private:
const DeviceState &state;
static void SvcHandler(u16 svc, ThreadContext* ctx);
public:
static void SignalHandler(int signal, siginfo *info, ucontext *context, void *oldTls);
NCE(const DeviceState &state);
struct PatchData {
size_t size; //!< Size of the .patch section
std::vector<size_t> offsets; //!< Offsets in .text of instructions that need to be patched
};
static PatchData GetPatchData(const std::vector<u8> &text);
/**
* @brief Writes the .patch section and mutates the code accordingly
* @param patch A pointer to the .patch section which should be exactly patchSize in size and located before the .text section
*/
static void PatchCode(std::vector<u8> &text, u32* patch, size_t patchSize, const std::vector<size_t>& offsets);
};
}