summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-04-20 09:42:15 -0400
committerGravatar GitHub2018-04-20 09:42:15 -0400
commitcb267093bb61394ea95192111466d116cd39cb3a (patch)
treedbbcc5cebe2bac951779249aef3bec5724c741b6 /src
parentMerge pull request #357 from lioncash/guard (diff)
parentcommon: Remove code_block.h (diff)
downloadyuzu-cb267093bb61394ea95192111466d116cd39cb3a.tar.gz
yuzu-cb267093bb61394ea95192111466d116cd39cb3a.tar.xz
yuzu-cb267093bb61394ea95192111466d116cd39cb3a.zip
Merge pull request #365 from lioncash/codeblock
common: Remove code_block.h
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/code_block.h85
2 files changed, 0 insertions, 86 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index d6eb9055b..32cb85de0 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -34,7 +34,6 @@ add_library(common STATIC
34 chunk_file.h 34 chunk_file.h
35 cityhash.cpp 35 cityhash.cpp
36 cityhash.h 36 cityhash.h
37 code_block.h
38 color.h 37 color.h
39 common_funcs.h 38 common_funcs.h
40 common_paths.h 39 common_paths.h
diff --git a/src/common/code_block.h b/src/common/code_block.h
deleted file mode 100644
index 6a55a8e30..000000000
--- a/src/common/code_block.h
+++ /dev/null
@@ -1,85 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <cstddef>
8#include "common/common_types.h"
9#include "common/memory_util.h"
10
11// Everything that needs to generate code should inherit from this.
12// You get memory management for free, plus, you can use all emitter functions without
13// having to prefix them with gen-> or something similar.
14// Example implementation:
15// class JIT : public CodeBlock<ARMXEmitter> {}
16template <class T>
17class CodeBlock : public T, NonCopyable {
18private:
19 // A privately used function to set the executable RAM space to something invalid.
20 // For debugging usefulness it should be used to set the RAM to a host specific breakpoint
21 // instruction
22 virtual void PoisonMemory() = 0;
23
24protected:
25 u8* region;
26 size_t region_size;
27
28public:
29 CodeBlock() : region(nullptr), region_size(0) {}
30 virtual ~CodeBlock() {
31 if (region)
32 FreeCodeSpace();
33 }
34
35 // Call this before you generate any code.
36 void AllocCodeSpace(int size) {
37 region_size = size;
38 region = (u8*)AllocateExecutableMemory(region_size);
39 T::SetCodePtr(region);
40 }
41
42 // Always clear code space with breakpoints, so that if someone accidentally executes
43 // uninitialized, it just breaks into the debugger.
44 void ClearCodeSpace() {
45 PoisonMemory();
46 ResetCodePtr();
47 }
48
49 // Call this when shutting down. Don't rely on the destructor, even though it'll do the job.
50 void FreeCodeSpace() {
51#ifdef __SYMBIAN32__
52 ResetExecutableMemory(region);
53#else
54 FreeMemoryPages(region, region_size);
55#endif
56 region = nullptr;
57 region_size = 0;
58 }
59
60 bool IsInSpace(const u8* ptr) {
61 return (ptr >= region) && (ptr < (region + region_size));
62 }
63
64 // Cannot currently be undone. Will write protect the entire code region.
65 // Start over if you need to change the code (call FreeCodeSpace(), AllocCodeSpace()).
66 void WriteProtect() {
67 WriteProtectMemory(region, region_size, true);
68 }
69
70 void ResetCodePtr() {
71 T::SetCodePtr(region);
72 }
73
74 size_t GetSpaceLeft() const {
75 return region_size - (T::GetCodePtr() - region);
76 }
77
78 u8* GetBasePtr() {
79 return region;
80 }
81
82 size_t GetOffset(const u8* ptr) const {
83 return ptr - region;
84 }
85};