| 1 | // Copyright 2016 Klemens Morgenstern, Antony Polukhin |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. |
| 4 | // (See accompanying file LICENSE_1_0.txt |
| 5 | // or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | // For more information, see http://www.boost.org |
| 8 | |
| 9 | #ifndef BOOST_DLL_DETAIL_TYPE_INFO_HPP_ |
| 10 | #define BOOST_DLL_DETAIL_TYPE_INFO_HPP_ |
| 11 | |
| 12 | #include <typeinfo> |
| 13 | #include <cstring> |
| 14 | #include <boost/dll/config.hpp> |
| 15 | #if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows |
| 16 | #include <boost/winapi/basic_types.hpp> |
| 17 | #endif |
| 18 | |
| 19 | namespace boost { namespace dll { namespace detail { |
| 20 | |
| 21 | #if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows |
| 22 | |
| 23 | #if defined ( _WIN64 ) |
| 24 | |
| 25 | template<typename Class, typename Lib, typename Storage> |
| 26 | const std::type_info& load_type_info(Lib & lib, Storage & storage) |
| 27 | { |
| 28 | struct RTTICompleteObjectLocator |
| 29 | { |
| 30 | boost::winapi::DWORD_ signature; //always zero ? |
| 31 | boost::winapi::DWORD_ offset; //offset of this vtable in the complete class |
| 32 | boost::winapi::DWORD_ cdOffset; //constructor displacement offset |
| 33 | boost::winapi::DWORD_ pTypeDescriptorOffset; //TypeDescriptor of the complete class |
| 34 | boost::winapi::DWORD_ pClassDescriptorOffset; //describes inheritance hierarchy (ignored) |
| 35 | }; |
| 36 | |
| 37 | RTTICompleteObjectLocator** vtable_p = &lib.template get<RTTICompleteObjectLocator*>(storage.template get_vtable<Class>()); |
| 38 | |
| 39 | vtable_p--; |
| 40 | auto vtable = *vtable_p; |
| 41 | |
| 42 | auto nat = reinterpret_cast<const char*>(lib.native()); |
| 43 | |
| 44 | nat += vtable->pTypeDescriptorOffset; |
| 45 | |
| 46 | return *reinterpret_cast<const std::type_info*>(nat); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | #else |
| 51 | |
| 52 | template<typename Class, typename Lib, typename Storage> |
| 53 | const std::type_info& load_type_info(Lib & lib, Storage & storage) |
| 54 | { |
| 55 | struct RTTICompleteObjectLocator |
| 56 | { |
| 57 | boost::winapi::DWORD_ signature; //always zero ? |
| 58 | boost::winapi::DWORD_ offset; //offset of this vtable in the complete class |
| 59 | boost::winapi::DWORD_ cdOffset; //constructor displacement offset |
| 60 | const std::type_info* pTypeDescriptor; //TypeDescriptor of the complete class |
| 61 | void* pClassDescriptor; //describes inheritance hierarchy (ignored) |
| 62 | }; |
| 63 | |
| 64 | RTTICompleteObjectLocator** vtable_p = &lib.template get<RTTICompleteObjectLocator*>(storage.template get_vtable<Class>()); |
| 65 | |
| 66 | vtable_p--; |
| 67 | auto vtable = *vtable_p; |
| 68 | return *vtable->pTypeDescriptor; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | #endif //_WIN64 |
| 73 | |
| 74 | #else |
| 75 | |
| 76 | template<typename Class, typename Lib, typename Storage> |
| 77 | const std::type_info& load_type_info(Lib & lib, Storage & storage) |
| 78 | { |
| 79 | return lib.template get<const std::type_info>(storage.template get_type_info<Class>()); |
| 80 | |
| 81 | } |
| 82 | |
| 83 | #endif |
| 84 | |
| 85 | |
| 86 | }}} |
| 87 | #endif /* BOOST_DLL_DETAIL_TYPE_INFO_HPP_ */ |
| 88 | |