From db72f23b7c31eb8eea969c31926bc25cca072864 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 13 Mar 2016 14:50:43 +0100 Subject: Updated delegates, now works on ARM and ARM64 (nw) --- src/lib/util/delegate.cpp | 54 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'src/lib/util/delegate.cpp') diff --git a/src/lib/util/delegate.cpp b/src/lib/util/delegate.cpp index 964b4f9c0ac..9c9e0fd3bf7 100644 --- a/src/lib/util/delegate.cpp +++ b/src/lib/util/delegate.cpp @@ -9,8 +9,8 @@ ***************************************************************************/ #include - -#include "osdcomm.h" +#include +#include #include "delegate.h" @@ -32,31 +32,51 @@ delegate_mfp::raw_mfp_data delegate_mfp::s_null_mfp = { {0 }}; #if (USE_DELEGATE_TYPE == DELEGATE_TYPE_INTERNAL) -/** - * @fn delegate_generic_function delegate_mfp::convert_to_generic(delegate_generic_class *&object) const - * - * @brief ------------------------------------------------- - * delegate_convert_raw - given an object and an raw function, adjust the object base - * and return the actual final code pointer - * -------------------------------------------------. - * - * @param [in,out] object [in,out] If non-null, the object. - * - * @return The given data converted to a generic. - */ +//------------------------------------------------- +// delegate_convert_raw - given an object and an raw function, adjust the object base +// and return the actual final code pointer +//-------------------------------------------------// delegate_generic_function delegate_mfp::convert_to_generic(delegate_generic_class *&object) const { +#if defined(__arm__) || defined(__ARMEL__) || defined(__aarch64__) + // apply the "this" delta to the object first + object = reinterpret_cast(reinterpret_cast(object)); + + // if the low bit of the vtable index is clear, then it is just a raw function pointer + if (m_this_delta==0) { +#if defined(LOG_DELEGATES) + printf("Calculated Addr = %08x\n", (uintptr_t)(void*)(m_function)); +#endif + return reinterpret_cast(m_function); + } + object = reinterpret_cast(reinterpret_cast(object)); + + // otherwise, it is the byte index into the vtable where the actual function lives + std::uint8_t *vtable_base = *reinterpret_cast(object); +#if defined(LOG_DELEGATES) + printf("Calculated Addr = %08x (VTAB)\n", (uintptr_t)(void*)(*reinterpret_cast(vtable_base + m_function + m_this_delta - 1))); +#endif + return *reinterpret_cast(vtable_base + m_function + m_this_delta - 1); +#else // apply the "this" delta to the object first - object = reinterpret_cast(reinterpret_cast(object) + m_this_delta); + object = reinterpret_cast(reinterpret_cast(object) + m_this_delta); // if the low bit of the vtable index is clear, then it is just a raw function pointer - if (!(m_function & 1)) + if (!(m_function & 1)) { +#if defined(LOG_DELEGATES) + printf("Calculated Addr = %08x\n", (uintptr_t)(void*)(m_function)); +#endif return reinterpret_cast(m_function); + } // otherwise, it is the byte index into the vtable where the actual function lives - UINT8 *vtable_base = *reinterpret_cast(object); + std::uint8_t *vtable_base = *reinterpret_cast(object); +#if defined(LOG_DELEGATES) + printf("Calculated Addr = %08x (VTAB)\n", (uintptr_t)(void*)(*reinterpret_cast(vtable_base + m_function - 1))); +#endif return *reinterpret_cast(vtable_base + m_function - 1); +#endif } #endif -- cgit v1.2.3-70-g09d2