This is an automated email from the ASF dual-hosted git repository.

jdanek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git

commit 542fa4035b9cd9cb74d448d518e388d2a18f7d68
Author: Jiri DanÄ›k <[email protected]>
AuthorDate: Sat Dec 25 14:20:18 2021 +0100

    DISPATCH-1783 Fix issues with cpp-stub
    
    * https://github.com/coolxv/cpp-stub/issues/21
    * https://github.com/coolxv/cpp-stub/issues/22
---
 tests/cpp-stub/cpp_stub.h | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/tests/cpp-stub/cpp_stub.h b/tests/cpp-stub/cpp_stub.h
index 6d6b13a..7532ede 100644
--- a/tests/cpp-stub/cpp_stub.h
+++ b/tests/cpp-stub/cpp_stub.h
@@ -7,6 +7,8 @@
 // See accompanying file LICENSE.txt or copy at
 // https://opensource.org/licenses/MIT
 
+#include "qd_asan_interface.h"
+
 #ifdef _WIN32
 //windows
 #include <windows.h>
@@ -113,19 +115,24 @@
     //13 byte(jmp m16:64)
     //movabs $0x102030405060708,%r11
     //jmpq   *%r11
-    #define REPLACE_FAR(t, fn, fn_stub)\
+    #define REPLACE_FAR(t, fn, fn_stub) \
+        do{\
         *fn = 0x49;\
         *(fn + 1) = 0xbb;\
-        *(long long *)(fn + 2) = (long long)fn_stub;\
+        memcpy((int *)(fn + 2), &fn_stub, sizeof(long long));\
         *(fn + 10) = 0x41;\
         *(fn + 11) = 0xff;\
         *(fn + 12) = 0xe3;\
+        }while(false)
         //CACHEFLUSH((char *)fn, CODESIZE);
 
     //5 byte(jmp rel32)
     #define REPLACE_NEAR(t, fn, fn_stub)\
+        do{\
+        const int addr = fn_stub - fn - CODESIZE_MIN;\
         *fn = 0xE9;\
-        *(int *)(fn + 1) = (int)(fn_stub - fn - CODESIZE_MIN);\
+        memcpy((int *)(fn + 1), &addr, sizeof(int));\
+        }while(false)
         //CACHEFLUSH((char *)fn, CODESIZE);
 #endif
 
@@ -179,13 +186,13 @@ public:
                 }
 
 #if defined(__aarch64__) || defined(_M_ARM64)
-                CACHEFLUSH(pstub->fn, CODESIZE);
+                CACHEFLUSH((char *)pstub->fn, CODESIZE);
 #elif defined(__arm__) || defined(_M_ARM)
-                CACHEFLUSH(pstub->fn, CODESIZE);
+                CACHEFLUSH((char *)pstub->fn, CODESIZE);
 #elif defined(__mips64)
-                CACHEFLUSH(pstub->fn, CODESIZE);
+                CACHEFLUSH((char *)pstub->fn, CODESIZE);
 #else //__i386__ _x86_64__  _M_IX86 _M_X64
-                //CACHEFLUSH(pstub->fn, CODESIZE);
+                //CACHEFLUSH((char *)pstub->fn, CODESIZE);
 #endif
 
 #ifdef _WIN32
@@ -202,6 +209,7 @@ public:
         return;
     }
     template<typename T,typename S>
+    ATTRIBUTE_NO_SANITIZE_THREAD
     void set(T addr, S addr_stub)
     {
         unsigned char * fn;
@@ -292,13 +300,13 @@ public:
         }
 
 #if defined(__aarch64__) || defined(_M_ARM64)
-                CACHEFLUSH(pstub->fn, CODESIZE);
+                CACHEFLUSH((char *)pstub->fn, CODESIZE);
 #elif defined(__arm__) || defined(_M_ARM)
-                CACHEFLUSH(pstub->fn, CODESIZE);
+                CACHEFLUSH((char *)pstub->fn, CODESIZE);
 #elif defined(__mips64)
-                CACHEFLUSH(pstub->fn, CODESIZE);
+                CACHEFLUSH((char *)pstub->fn, CODESIZE);
 #else //__i386__ _x86_64__  _M_IX86 _M_X64
-                //CACHEFLUSH(pstub->fn, CODESIZE);
+                //CACHEFLUSH((char *)pstub->fn, CODESIZE);
 #endif
 
 #ifdef _WIN32

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to