diff options
Diffstat (limited to 'src/common/code_block.h')
| -rw-r--r-- | src/common/code_block.h | 85 |
1 files changed, 0 insertions, 85 deletions
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> {} | ||
| 16 | template <class T> | ||
| 17 | class CodeBlock : public T, NonCopyable { | ||
| 18 | private: | ||
| 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 | |||
| 24 | protected: | ||
| 25 | u8* region; | ||
| 26 | size_t region_size; | ||
| 27 | |||
| 28 | public: | ||
| 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 | }; | ||