backend/x64: Make ExceptionHandler its own class
This commit is contained in:
parent
325808949f
commit
9d60d92692
8 changed files with 50 additions and 27 deletions
|
@ -46,6 +46,7 @@ protected:
|
|||
const A32::UserConfig config;
|
||||
A32::Jit* jit_interface;
|
||||
BlockRangeInformation<u32> block_ranges;
|
||||
ExceptionHandler exception_handler;
|
||||
|
||||
struct FastDispatchEntry {
|
||||
u64 location_descriptor;
|
||||
|
|
|
@ -83,7 +83,6 @@ BlockOfCode::BlockOfCode(RunCodeCallbacks cb, JitStateInfo jsi)
|
|||
{
|
||||
EnableWriting();
|
||||
GenRunCode();
|
||||
exception_handler.Register(*this);
|
||||
}
|
||||
|
||||
void BlockOfCode::PreludeComplete() {
|
||||
|
@ -286,6 +285,10 @@ CodePtr BlockOfCode::GetCodeBegin() const {
|
|||
return near_code_begin;
|
||||
}
|
||||
|
||||
size_t BlockOfCode::GetTotalCodeSize() const {
|
||||
return maxSize_;
|
||||
}
|
||||
|
||||
void* BlockOfCode::AllocateFromCodeSpace(size_t alloc_size) {
|
||||
if (size_ + alloc_size >= maxSize_) {
|
||||
throw Xbyak::Error(Xbyak::ERR_CODE_IS_TOO_BIG);
|
||||
|
|
|
@ -98,6 +98,7 @@ public:
|
|||
void SwitchToNearCode();
|
||||
|
||||
CodePtr GetCodeBegin() const;
|
||||
size_t GetTotalCodeSize() const;
|
||||
|
||||
const void* GetReturnFromRunCodeAddress() const {
|
||||
return return_from_run_code[0];
|
||||
|
@ -163,18 +164,6 @@ private:
|
|||
std::array<const void*, 4> return_from_run_code;
|
||||
void GenRunCode();
|
||||
|
||||
class ExceptionHandler final {
|
||||
public:
|
||||
ExceptionHandler();
|
||||
~ExceptionHandler();
|
||||
|
||||
void Register(BlockOfCode& code);
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
ExceptionHandler exception_handler;
|
||||
|
||||
Xbyak::util::Cpu cpu_info;
|
||||
};
|
||||
|
||||
|
|
|
@ -33,8 +33,9 @@ void EmitContext::EraseInstruction(IR::Inst* inst) {
|
|||
inst->ClearArgs();
|
||||
}
|
||||
|
||||
EmitX64::EmitX64(BlockOfCode& code)
|
||||
: code(code) {}
|
||||
EmitX64::EmitX64(BlockOfCode& code) : code(code) {
|
||||
exception_handler.Register(code);
|
||||
}
|
||||
|
||||
EmitX64::~EmitX64() = default;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <xbyak_util.h>
|
||||
|
||||
#include "backend/x64/exception_handler.h"
|
||||
#include "backend/x64/reg_alloc.h"
|
||||
#include "common/bit_util.h"
|
||||
#include "common/fp/fpcr.h"
|
||||
|
@ -58,7 +59,7 @@ public:
|
|||
size_t size; // Length in bytes of emitted code
|
||||
};
|
||||
|
||||
EmitX64(BlockOfCode& code);
|
||||
explicit EmitX64(BlockOfCode& code);
|
||||
virtual ~EmitX64();
|
||||
|
||||
/// Looks up an emitted host block in the cache.
|
||||
|
@ -114,6 +115,7 @@ protected:
|
|||
|
||||
// State
|
||||
BlockOfCode& code;
|
||||
ExceptionHandler exception_handler;
|
||||
std::unordered_map<IR::LocationDescriptor, BlockDescriptor> block_descriptors;
|
||||
std::unordered_map<IR::LocationDescriptor, PatchInformation> patch_information;
|
||||
};
|
||||
|
|
26
src/backend/x64/exception_handler.h
Normal file
26
src/backend/x64/exception_handler.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* This file is part of the dynarmic project.
|
||||
* Copyright (c) 2020 MerryMage
|
||||
* This software may be used and distributed according to the terms of the GNU
|
||||
* General Public License version 2 or any later version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Dynarmic::Backend::X64 {
|
||||
|
||||
class BlockOfCode;
|
||||
|
||||
class ExceptionHandler final {
|
||||
public:
|
||||
ExceptionHandler();
|
||||
~ExceptionHandler();
|
||||
|
||||
void Register(BlockOfCode& code);
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
|
||||
} // namespace Dynarmic::Backend::X64
|
|
@ -4,17 +4,17 @@
|
|||
* General Public License version 2 or any later version.
|
||||
*/
|
||||
|
||||
#include "backend/x64/block_of_code.h"
|
||||
#include "backend/x64/exception_handler.h"
|
||||
|
||||
namespace Dynarmic::Backend::X64 {
|
||||
|
||||
struct BlockOfCode::ExceptionHandler::Impl final {
|
||||
struct ExceptionHandler::Impl final {
|
||||
};
|
||||
|
||||
BlockOfCode::ExceptionHandler::ExceptionHandler() = default;
|
||||
BlockOfCode::ExceptionHandler::~ExceptionHandler() = default;
|
||||
ExceptionHandler::ExceptionHandler() = default;
|
||||
ExceptionHandler::~ExceptionHandler() = default;
|
||||
|
||||
void BlockOfCode::ExceptionHandler::Register(BlockOfCode&) {
|
||||
void ExceptionHandler::Register(BlockOfCode&) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <windows.h>
|
||||
|
||||
#include "backend/x64/block_of_code.h"
|
||||
#include "backend/x64/exception_handler.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
|
@ -156,7 +157,7 @@ static PrologueInformation GetPrologueInformation() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
struct BlockOfCode::ExceptionHandler::Impl final {
|
||||
struct ExceptionHandler::Impl final {
|
||||
Impl(RUNTIME_FUNCTION* rfuncs_, const u8* base_ptr) : rfuncs(rfuncs_) {
|
||||
RtlAddFunctionTable(rfuncs, 1, reinterpret_cast<DWORD64>(base_ptr));
|
||||
}
|
||||
|
@ -169,10 +170,10 @@ private:
|
|||
RUNTIME_FUNCTION* rfuncs = nullptr;
|
||||
};
|
||||
|
||||
BlockOfCode::ExceptionHandler::ExceptionHandler() = default;
|
||||
BlockOfCode::ExceptionHandler::~ExceptionHandler() = default;
|
||||
ExceptionHandler::ExceptionHandler() = default;
|
||||
ExceptionHandler::~ExceptionHandler() = default;
|
||||
|
||||
void BlockOfCode::ExceptionHandler::Register(BlockOfCode& code) {
|
||||
void ExceptionHandler::Register(BlockOfCode& code) {
|
||||
const auto prolog_info = GetPrologueInformation();
|
||||
|
||||
code.align(16);
|
||||
|
@ -190,8 +191,8 @@ void BlockOfCode::ExceptionHandler::Register(BlockOfCode& code) {
|
|||
|
||||
code.align(16);
|
||||
RUNTIME_FUNCTION* rfuncs = static_cast<RUNTIME_FUNCTION*>(code.AllocateFromCodeSpace(sizeof(RUNTIME_FUNCTION)));
|
||||
rfuncs->BeginAddress = static_cast<DWORD>(reinterpret_cast<u8*>(code.run_code) - code.getCode());
|
||||
rfuncs->EndAddress = static_cast<DWORD>(code.maxSize_);
|
||||
rfuncs->BeginAddress = static_cast<DWORD>(0);
|
||||
rfuncs->EndAddress = static_cast<DWORD>(code.GetTotalCodeSize());
|
||||
rfuncs->UnwindData = static_cast<DWORD>(reinterpret_cast<u8*>(unwind_info) - code.getCode());
|
||||
|
||||
impl = std::make_unique<Impl>(rfuncs, code.getCode());
|
||||
|
|
Loading…
Reference in a new issue