From: Yonggang L. <luo...@gm...> - 2024-12-07 23:01:29
|
sizeof(unsigned long int) is 4 on mingw 64bit, use unsigned long long int instead __clang__ for MSVC support for inline assembly _MSC_VER win64 do not support inline assembly, use stub instead Signed-off-by: Yonggang Luo <luo...@gm...> --- include/valgrind.h.in | 67 ++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/include/valgrind.h.in b/include/valgrind.h.in index bc18f40f7..a6c6d429b 100644 --- a/include/valgrind.h.in +++ b/include/valgrind.h.in @@ -403,19 +403,20 @@ valgrind_do_client_request_expr(uintptr_t _zzq_default, uintptr_t _zzq_request, #endif /* PLAT_x86_win32 */ -/* ----------------- amd64-{linux,darwin,solaris} --------------- */ +/* ----------------- amd64-{linux,darwin,solaris,freebsd,win64} --------------- */ #if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \ || defined(PLAT_amd64_solaris) \ || defined(PLAT_amd64_freebsd) \ - || (defined(PLAT_amd64_win64) && defined(__GNUC__)) + || defined(PLAT_amd64_win64) typedef struct { - unsigned long int nraddr; /* where's the code? */ + unsigned long long int nraddr; /* where's the code? */ } OrigFn; +#if defined(__GNUC__) || defined(__clang__) #define __SPECIAL_INSTRUCTION_PREAMBLE \ "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \ "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" @@ -424,14 +425,14 @@ typedef _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ - ({ volatile unsigned long int _zzq_args[6]; \ - volatile unsigned long int _zzq_result; \ - _zzq_args[0] = (unsigned long int)(_zzq_request); \ - _zzq_args[1] = (unsigned long int)(_zzq_arg1); \ - _zzq_args[2] = (unsigned long int)(_zzq_arg2); \ - _zzq_args[3] = (unsigned long int)(_zzq_arg3); \ - _zzq_args[4] = (unsigned long int)(_zzq_arg4); \ - _zzq_args[5] = (unsigned long int)(_zzq_arg5); \ + ({ volatile unsigned long long int _zzq_args[6]; \ + volatile unsigned long long int _zzq_result; \ + _zzq_args[0] = (unsigned long long int)(_zzq_request); \ + _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \ + _zzq_args[2] = (unsigned long long int)(_zzq_arg2); \ + _zzq_args[3] = (unsigned long long int)(_zzq_arg3); \ + _zzq_args[4] = (unsigned long long int)(_zzq_arg4); \ + _zzq_args[5] = (unsigned long long int)(_zzq_arg5); \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %RDX = client_request ( %RAX ) */ \ "xchgq %%rbx,%%rbx" \ @@ -444,7 +445,7 @@ typedef #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ - volatile unsigned long int __addr; \ + volatile unsigned long long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %RAX = guest_NRADDR */ \ "xchgq %%rcx,%%rcx" \ @@ -468,15 +469,49 @@ typedef ); \ } while (0) -#endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */ +#elif defined(_MSC_VER) -/* ------------------------- amd64-Win64 ------------------------- */ +#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ + _zzq_default, _zzq_request, \ + _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ + valgrind_do_client_request_expr((uintptr_t)(_zzq_default), \ + (uintptr_t)(_zzq_request), (uintptr_t)(_zzq_arg1), \ + (uintptr_t)(_zzq_arg2), (uintptr_t)(_zzq_arg3), \ + (uintptr_t)(_zzq_arg4), (uintptr_t)(_zzq_arg5)) -#if defined(PLAT_amd64_win64) && !defined(__GNUC__) +static __inline uintptr_t +valgrind_do_client_request_expr(uintptr_t _zzq_default, uintptr_t _zzq_request, + uintptr_t _zzq_arg1, uintptr_t _zzq_arg2, + uintptr_t _zzq_arg3, uintptr_t _zzq_arg4, + uintptr_t _zzq_arg5) +{ + volatile uintptr_t _zzq_args[6]; + volatile unsigned int _zzq_result = 0; + _zzq_args[0] = (uintptr_t)(_zzq_request); + _zzq_args[1] = (uintptr_t)(_zzq_arg1); + _zzq_args[2] = (uintptr_t)(_zzq_arg2); + _zzq_args[3] = (uintptr_t)(_zzq_arg3); + _zzq_args[4] = (uintptr_t)(_zzq_arg4); + _zzq_args[5] = (uintptr_t)(_zzq_arg5); + return _zzq_result; +} + +#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ + { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ + volatile unsigned int __addr = _ReturnAddress(); \ + _zzq_orig->nraddr = __addr; \ + } + +#else /* !defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER) */ #error Unsupported compiler. -#endif /* PLAT_amd64_win64 */ +#endif /* defined(__GNUC__) || defined(__clang__) */ + +#endif /* defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \ + || defined(PLAT_amd64_solaris) \ + || defined(PLAT_amd64_freebsd) \ + || defined(PLAT_amd64_win64) */ /* ------------------------ ppc32-linux ------------------------ */ -- 2.46.0.windows.1 |