Browse Source
fx
Signed-off-by: lizzie <lizzie@eden-emu.dev>
pull/2866/head
lizzie
3 months ago
No known key found for this signature in database
GPG Key ID: 287378CADCAB13
2 changed files with
18 additions and
4 deletions
-
src/dynarmic/src/dynarmic/backend/arm64/devirtualize.h
-
src/dynarmic/src/dynarmic/backend/x64/devirtualize.h
|
|
|
@ -14,6 +14,14 @@ |
|
|
|
|
|
|
|
namespace Dynarmic::Backend::Arm64 { |
|
|
|
|
|
|
|
namespace impl { |
|
|
|
template<typename T, typename P> inline T bit_cast_pointee(const P source_ptr) noexcept { |
|
|
|
std::aligned_storage_t<sizeof(T), alignof(T)> dest; |
|
|
|
std::memcpy(&dest, bit_cast<void*>(source_ptr), sizeof(T)); |
|
|
|
return reinterpret_cast<T&>(dest); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
struct DevirtualizedCall { |
|
|
|
u64 fn_ptr; |
|
|
|
u64 this_ptr; |
|
|
|
@ -42,8 +50,8 @@ DevirtualizedCall DevirtualizeDefault(mcl::class_type<decltype(mfp)>* this_) { |
|
|
|
u64 fn_ptr = mfp_struct.ptr; |
|
|
|
u64 this_ptr = std::bit_cast<u64>(this_) + (mfp_struct.adj >> 1); |
|
|
|
if (mfp_struct.adj & 1) { |
|
|
|
u64 vtable = *reinterpret_cast<u64 const*>(this_ptr); |
|
|
|
fn_ptr = *reinterpret_cast<u64 const*>(vtable + fn_ptr); |
|
|
|
u64 vtable = impl::bit_cast_pointee<u64>(this_ptr); |
|
|
|
fn_ptr = impl::bit_cast_pointee<u64>(vtable + fn_ptr); |
|
|
|
} |
|
|
|
return DevirtualizedCall{fn_ptr, this_ptr}; |
|
|
|
} |
|
|
|
|
|
|
|
@ -32,6 +32,12 @@ struct ThunkBuilder<R (C::*)(Args...), mfp> { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
template<typename T, typename P> inline T bit_cast_pointee(const P source_ptr) noexcept { |
|
|
|
std::aligned_storage_t<sizeof(T), alignof(T)> dest; |
|
|
|
std::memcpy(&dest, bit_cast<void*>(source_ptr), sizeof(T)); |
|
|
|
return reinterpret_cast<T&>(dest); |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace impl |
|
|
|
|
|
|
|
template<auto mfp> |
|
|
|
@ -61,8 +67,8 @@ ArgCallback DevirtualizeItanium(mcl::class_type<decltype(mfp)>* this_) { |
|
|
|
u64 fn_ptr = mfp_struct.ptr; |
|
|
|
u64 this_ptr = reinterpret_cast<u64>(this_) + mfp_struct.adj; |
|
|
|
if (mfp_struct.ptr & 1) { |
|
|
|
u64 vtable = *reinterpret_cast<u64 const*>(this_ptr); |
|
|
|
fn_ptr = *reinterpret_cast<u64 const*>(vtable + fn_ptr - 1); |
|
|
|
u64 vtable = impl::bit_cast_pointee<u64>(this_ptr); |
|
|
|
fn_ptr = impl::bit_cast_pointee<u64>(vtable + fn_ptr - 1); |
|
|
|
} |
|
|
|
return ArgCallback{fn_ptr, this_ptr}; |
|
|
|
} |
|
|
|
|