From d5c99a5b48a6cce702a1aa1e2b105ffe558d9ac9 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 7 Aug 2015 22:08:57 -0500 Subject: [PATCH] Add support for a CodeBlock holding a child. This is required to make sure two code spaces are relatively close to one another. In this case I need the AArch64 JIT codespace and its farcode space to be within 128MB of one another for branches. --- Source/Core/Common/CodeBlock.h | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/CodeBlock.h b/Source/Core/Common/CodeBlock.h index 5699fc5385..865c4513ca 100644 --- a/Source/Core/Common/CodeBlock.h +++ b/Source/Core/Common/CodeBlock.h @@ -22,9 +22,19 @@ private: protected: u8 *region; size_t region_size; + size_t parent_region_size; + + bool m_has_child; + bool m_is_child; + CodeBlock* m_child; public: - CodeBlock() : region(nullptr), region_size(0) {} + CodeBlock() + : region(nullptr), region_size(0), parent_region_size(0), + m_has_child(false), m_is_child(false), m_child(nullptr) + { + } + virtual ~CodeBlock() { if (region) FreeCodeSpace(); } // Call this before you generate any code. @@ -49,6 +59,12 @@ public: FreeMemoryPages(region, region_size); region = nullptr; region_size = 0; + parent_region_size = 0; + if (m_has_child) + { + m_child->region = nullptr; + m_child->region_size = 0; + } } bool IsInSpace(u8 *ptr) const @@ -70,7 +86,7 @@ public: size_t GetSpaceLeft() const { - return region_size - (T::GetCodePtr() - region); + return (m_has_child ? parent_region_size : region_size) - (T::GetCodePtr() - region); } bool IsAlmostFull() const @@ -78,5 +94,16 @@ public: // This should be bigger than the biggest block ever. return GetSpaceLeft() < 0x10000; } + void AddChildCodeSpace(CodeBlock* child, size_t size) + { + _assert_msg_(DYNA_REC, !m_has_child, "Already have a child! Can't have another!"); + m_child = child; + m_has_child = true; + m_child->m_is_child = true; + u8* child_region = region + region_size - size; + m_child->region = child_region; + m_child->region_size = size; + m_child->ResetCodePtr(); + parent_region_size = region_size - size; + } }; -