diff options
author | 2016-03-13 14:50:43 +0100 | |
---|---|---|
committer | 2016-03-13 14:50:43 +0100 | |
commit | db72f23b7c31eb8eea969c31926bc25cca072864 (patch) | |
tree | 81a38fe0bc22b84c393bdd40328ea257481db063 /src/lib/util/delegate.cpp | |
parent | 23d4e320af0b22afdbdbd29bfa188dab3408c06c (diff) |
Updated delegates, now works on ARM and ARM64 (nw)
Diffstat (limited to 'src/lib/util/delegate.cpp')
-rw-r--r-- | src/lib/util/delegate.cpp | 54 |
1 files changed, 37 insertions, 17 deletions
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 <assert.h> - -#include "osdcomm.h" +#include <cstdint> +#include <stdio.h> #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<delegate_generic_class *>(reinterpret_cast<std::uint8_t *>(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<delegate_generic_function>(m_function); + } + object = reinterpret_cast<delegate_generic_class *>(reinterpret_cast<std::uint8_t *>(object)); + + // otherwise, it is the byte index into the vtable where the actual function lives + std::uint8_t *vtable_base = *reinterpret_cast<std::uint8_t **>(object); +#if defined(LOG_DELEGATES) + printf("Calculated Addr = %08x (VTAB)\n", (uintptr_t)(void*)(*reinterpret_cast<delegate_generic_function *>(vtable_base + m_function + m_this_delta - 1))); +#endif + return *reinterpret_cast<delegate_generic_function *>(vtable_base + m_function + m_this_delta - 1); +#else // apply the "this" delta to the object first - object = reinterpret_cast<delegate_generic_class *>(reinterpret_cast<UINT8 *>(object) + m_this_delta); + object = reinterpret_cast<delegate_generic_class *>(reinterpret_cast<std::uint8_t *>(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<delegate_generic_function>(m_function); + } // otherwise, it is the byte index into the vtable where the actual function lives - UINT8 *vtable_base = *reinterpret_cast<UINT8 **>(object); + std::uint8_t *vtable_base = *reinterpret_cast<std::uint8_t **>(object); +#if defined(LOG_DELEGATES) + printf("Calculated Addr = %08x (VTAB)\n", (uintptr_t)(void*)(*reinterpret_cast<delegate_generic_function *>(vtable_base + m_function - 1))); +#endif return *reinterpret_cast<delegate_generic_function *>(vtable_base + m_function - 1); +#endif } #endif |