From: Andreas Arnez Date: Thu, 19 May 2022 11:54:06 +0000 (+0200) Subject: Bug 454040 - Add intercept for memmem on s390x X-Git-Tag: VALGRIND_3_20_0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38acc04ac2f5ae2919631cd6cac46b027d2864ef;p=thirdparty%2Fvalgrind.git Bug 454040 - Add intercept for memmem on s390x Memcheck may report false positives in an optimized version of memmem on s390x, specifically on arch13 systems. Prevent this by adding an intercept for memmem on s390x platforms. --- diff --git a/NEWS b/NEWS index 13b576e873..b3c3590b90 100644 --- a/NEWS +++ b/NEWS @@ -42,6 +42,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 453055 shared_timed_mutex drd test fails with "Lock shared failed" message 453602 Missing command line option to enable/disable debuginfod 452802 Handle lld 9+ split RW PT_LOAD segments correctly +454040 s390x: False-positive memcheck:cond in memmem on arch13 systems 456171 [PATCH] FreeBSD: Don't record address errors when accessing the 'kern.ps_strings' sysctl struct n-i-bz Implement vgdb invoker on FreeBSD diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c index aab1413917..71b0e14cf5 100644 --- a/shared/vg_replace_strmem.c +++ b/shared/vg_replace_strmem.c @@ -103,6 +103,7 @@ 20430 WMEMCHR 20440 WCSNLEN 20450 WSTRNCMP + 20460 MEMMEM */ #if defined(VGO_solaris) @@ -1800,6 +1801,41 @@ static inline void my_exit ( int x ) #endif +/*---------------------- memmem ----------------------*/ + +#define MEMMEM(soname, fnname) \ + void* VG_REPLACE_FUNCTION_EZU(20460,soname,fnname) \ + (const void* haystack, SizeT hlen, const void* needle, SizeT nlen); \ + void* VG_REPLACE_FUNCTION_EZU(20460,soname,fnname) \ + (const void* haystack, SizeT hlen, const void* needle, SizeT nlen) \ + { \ + const HChar* h = haystack; \ + const HChar* n = needle; \ + \ + /* If the needle is the empty string, match immediately. */ \ + if (nlen == 0) return CONST_CAST(void *,h); \ + \ + HChar n0 = n[0]; \ + \ + for (; hlen >= nlen; hlen--, h++) { \ + if (h[0] != n0) continue; \ + \ + UWord i; \ + for (i = 1; i < nlen; i++) { \ + if (n[i] != h[i]) \ + break; \ + } \ + if (i == nlen) \ + return CONST_CAST(HChar *,h); \ + \ + } \ + return NULL; \ + } + +#if defined(VGP_s390x_linux) + MEMMEM(VG_Z_LIBC_SONAME, memmem) +#endif + /*---------------------- strpbrk ----------------------*/