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 |
From: Yonggang L. <luo...@gm...> - 2024-12-11 11:03:21
|
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 | 76 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/include/valgrind.h.in b/include/valgrind.h.in index bc18f40f7..12da318ea 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,58 @@ 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 uintptr_t _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); + /* TODO: use machine code to support for MSVC 64 bit*/ + return _zzq_result; +} + +#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ + { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ + volatile uintptr_t __addr; \ + /* TODO: use machine code to support for MSVC 64 bit*/ \ + _zzq_orig->nraddr = __addr; \ + } + +#define VALGRIND_CALL_NOREDIR_RAX ERROR + +#define VALGRIND_VEX_INJECT_IR() \ + do { \ + /* TODO: use machine code to support for MSVC 64 bit*/ \ +} while (0) + +#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 |
From: Bart V. A. <bar...@gm...> - 2024-12-12 17:08:22
|
On 12/11/24 3:02 AM, Yonggang Luo wrote: > 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 Please follow the "one change per patch" rule. There are multiple unrelated changes in this patch. A few examples: - Changing "unsigned long int" into "unsigned long long int" should be a patch by itself. - Adding support for MSVC (_MSC_VER) should be a patch by itself too. Bart. |
From: Paul F. <pj...@wa...> - 2024-12-09 06:40:53
|
Hi What are you using Valgrind for on Windows? A+ Paul |
From: 罗勇刚(Yonggang L. <luo...@gm...> - 2024-12-10 15:21:45
|
On Mon, Dec 9, 2024 at 2:41 PM Paul Floyd via Valgrind-developers < val...@li...> wrote: > > Hi > > What are you using Valgrind for on Windows? For jerryscript on windows https://github.com/jerryscript-project/jerryscript and maybe also others > > > A+ > Paul > > > _______________________________________________ > Valgrind-developers mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-developers -- 此致 礼 罗勇刚 Yours sincerely, Yonggang Luo |
From: Paul F. <pj...@wa...> - 2024-12-11 07:43:18
|
On 10-12-24 16:21, 罗勇刚(Yonggang Luo) wrote: > For jerryscript on windows https://github.com/jerryscript-project/ > jerryscript <https://github.com/jerryscript-project/jerryscript> > > and maybe also others Hi It looks to me as though this is using client requests for a custom memory allocator. Is anybody using the client requests on Windows (with a tool such as Valgrind or Dr Memory)? Or is it just for compatibility when building? A+ Paul |
From: Bart V. A. <bva...@ac...> - 2024-12-11 18:25:17
|
On 12/10/24 11:43 PM, Paul Floyd via Valgrind-developers wrote: > Is anybody using the client requests on Windows (with a tool such as > Valgrind or Dr Memory)? Or is it just for compatibility when building? I added Windows support in this header file a long time ago to support the Valgrind + Wine + Windows software combination. I'm not sure whether anyone is still using this combination. Bart. |
From: 罗勇刚(Yonggang L. <luo...@gm...> - 2024-12-12 07:36:45
|
Any reviews? I think this can be get merged On Thu, Dec 12, 2024 at 2:27 AM Bart Van Assche via Valgrind-developers < val...@li...> wrote: > > On 12/10/24 11:43 PM, Paul Floyd via Valgrind-developers wrote: > > Is anybody using the client requests on Windows (with a tool such as > > Valgrind or Dr Memory)? Or is it just for compatibility when building? > > I added Windows support in this header file a long time ago to support > the Valgrind + Wine + Windows software combination. I'm not sure > whether anyone is still using this combination. > > Bart. > > > > _______________________________________________ > Valgrind-developers mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-developers -- 此致 礼 罗勇刚 Yours sincerely, Yonggang Luo |
From: Mark W. <ma...@kl...> - 2024-12-12 11:24:20
|
On Thu, Dec 12, 2024 at 03:36:26PM +0800, 罗勇刚(Yonggang Luo) wrote: > Any reviews? I think this can be get merged There were a couple of questions which I am not sure I saw an answer to. Could you explain how you tested? Why aren't you creating a new section for win64? You are adding it as a variant of 64bit linux/freebsd, but then need to change the data type of some, why is that OK for the existing platforms? The patch Bart added for win32 used uintptr, which seems a better data type than long long. Thanks, Mark |
From: 罗勇刚(Yonggang L. <luo...@gm...> - 2024-12-12 16:28:45
|
On Thu, Dec 12, 2024 at 7:24 PM Mark Wielaard <ma...@kl...> wrote: > > On Thu, Dec 12, 2024 at 03:36:26PM +0800, 罗勇刚(Yonggang Luo) wrote: > > Any reviews? I think this can be get merged > > There were a couple of questions which I am not sure I saw an answer > to. Could you explain how you tested? Why aren't you creating a new > section for win64? You are adding it as a variant of 64bit This is already the section for win64/mingw > linux/freebsd, but then need to change the data type of some, why is sizeof(unsigned long int) === 8*8 on linux/freebsd, but sizeof(unsigned long int) === 4*8 on PLAT_amd64_win64(mingw/msvc) mingw > that OK for the existing platforms? The patch Bart added for win32 > used uintptr, which seems a better data type than long long. uintptr is fine, but I am not sure every compiler have ` uintptr_t`, that depends on header file `unsigned long long it` is always safe for every compiler(without no need the header) PLAT_amd64_win64 > > Thanks, > > Mark -- 此致 礼 罗勇刚 Yours sincerely, Yonggang Luo |
From: Paul F. <pj...@wa...> - 2024-12-12 20:40:52
|
On 12/12/2024 12:18, 罗勇刚(Yonggang Luo) wrote: > > > On Thu, Dec 12, 2024 at 7:24 PM Mark Wielaard <ma...@kl...> wrote: > > > > On Thu, Dec 12, 2024 at 03:36:26PM +0800, 罗勇刚(Yonggang Luo) wrote: > > > Any reviews? I think this can be get merged > > > > There were a couple of questions which I am not sure I saw an answer > > to. Could you explain how you tested? Why aren't you creating a new > > section for win64? You are adding it as a variant of 64bit > This is already the section for win64/mingw > > > linux/freebsd, but then need to change the data type of some, why is > sizeof(unsigned long int) === 8*8 on linux/freebsd, but > sizeof(unsigned long int) === 4*8 on PLAT_amd64_win64(mingw/msvc) > mingw > > > that OK for the existing platforms? The patch Bart added for win32 > > used uintptr, which seems a better data type than long long. > uintptr is fine, but I am not sure every compiler have ` uintptr_t`, that depends on header file > > `unsigned long long it` is always safe for every compiler(without no need the header) No it isn't. All variations of "long long" were added with C99. https://en.cppreference.com/w/c/language/arithmetic_types I would be very surprised if there aren't people still using the Valgrind headers and compiling with c90. I think that the type used should either be compatible with the oldest compilers (along the lines Mark’s suggestion) or else there should be a separate section for win32 non-__GNUC__. I'll have a look at Dr Memory. I think that it uses the same mechanism for client requests and also supports Windows. A+ Paul |
From: Bart V. A. <bar...@gm...> - 2024-12-12 20:55:24
|
On 12/12/24 3:18 AM, 罗勇刚(Yonggang Luo) wrote: > uintptr is fine, but I am not sure every compiler have ` uintptr_t`, > that depends on header file We can ask Windows users to include <stdint.h> before <valgrind/valgrind.h>. We can't ask this from Unix users because this could break existing code bases. In other words, I'm in favor of using uintptr_t for Win64 instead of unsigned long long. Thanks, Bart. |
From: 罗勇刚(Yonggang L. <luo...@gm...> - 2024-12-13 18:34:44
|
On Fri, Dec 13, 2024 at 4:55 AM Bart Van Assche <bar...@gm...> wrote: > > On 12/12/24 3:18 AM, 罗勇刚(Yonggang Luo) wrote: > > uintptr is fine, but I am not sure every compiler have ` uintptr_t`, > > that depends on header file > > We can ask Windows users to include <stdint.h> before > <valgrind/valgrind.h>. We can't ask this from Unix users because this > could break existing code bases. In other words, I'm in favor of using > uintptr_t for Win64 instead of unsigned long long. > Update the patch to not affect Unix users, handling cases for PLAT_amd64_win64 in separate code so that it's won't affect Unix users in Patch V5 > Thanks, > > Bart. -- 此致 礼 罗勇刚 Yours sincerely, Yonggang Luo |