From a69755d9ee4cd880c4993eaaee49ab0342202113 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 21 Aug 2015 17:57:35 -0400 Subject: [PATCH] x64Emitter: Remove pointer casts from Write{8,16,32,64} functions This also silences quite a few ubsan asserts from firing when the emitter is being used. --- Source/Core/Common/x64Emitter.cpp | 24 ++++++++++++++++++++++++ Source/Core/Common/x64Emitter.h | 8 ++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/x64Emitter.cpp b/Source/Core/Common/x64Emitter.cpp index 839e350c16..fd9494f8b1 100644 --- a/Source/Core/Common/x64Emitter.cpp +++ b/Source/Core/Common/x64Emitter.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "Common/CommonTypes.h" #include "Common/CPUDetect.h" @@ -91,6 +92,29 @@ u8* XEmitter::GetWritableCodePtr() return code; } +void XEmitter::Write8(u8 value) +{ + *code++ = value; +} + +void XEmitter::Write16(u16 value) +{ + std::memcpy(code, &value, sizeof(u16)); + code += sizeof(u16); +} + +void XEmitter::Write32(u32 value) +{ + std::memcpy(code, &value, sizeof(u32)); + code += sizeof(u32); +} + +void XEmitter::Write64(u64 value) +{ + std::memcpy(code, &value, sizeof(u64)); + code += sizeof(u64); +} + void XEmitter::ReserveCodeSpace(int bytes) { for (int i = 0; i < bytes; i++) diff --git a/Source/Core/Common/x64Emitter.h b/Source/Core/Common/x64Emitter.h index f7ed6f3e87..2a93e51688 100644 --- a/Source/Core/Common/x64Emitter.h +++ b/Source/Core/Common/x64Emitter.h @@ -309,10 +309,10 @@ private: void ABI_CalculateFrameSize(BitSet32 mask, size_t rsp_alignment, size_t needed_frame_size, size_t* shadowp, size_t* subtractionp, size_t* xmm_offsetp); protected: - inline void Write8(u8 value) {*code++ = value;} - inline void Write16(u16 value) {*(u16*)code = (value); code += 2;} - inline void Write32(u32 value) {*(u32*)code = (value); code += 4;} - inline void Write64(u64 value) {*(u64*)code = (value); code += 8;} + void Write8(u8 value); + void Write16(u16 value); + void Write32(u32 value); + void Write64(u64 value); public: XEmitter() { code = nullptr; flags_locked = false; }