From: Bart Van Assche Date: Sun, 1 Jun 2008 08:48:48 +0000 (+0000) Subject: Added intercepts for strlen() and strnlen(). X-Git-Tag: svn/VALGRIND_3_4_0~530 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4185dcb248266f584e163fc641c1bf621facc77f;p=thirdparty%2Fvalgrind.git Added intercepts for strlen() and strnlen(). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8165 --- diff --git a/exp-drd/Makefile.am b/exp-drd/Makefile.am index b00516f0bb..15a4b8d82f 100644 --- a/exp-drd/Makefile.am +++ b/exp-drd/Makefile.am @@ -21,9 +21,10 @@ if VGP_PPC64_AIX5 endif if HAVE_OPENMP -VGPRELOAD_DRD_SOURCES_COMMON = drd_pthread_intercepts.c drd_gomp_intercepts.c +VGPRELOAD_DRD_SOURCES_COMMON = \ + drd_strmem_intercepts.c drd_pthread_intercepts.c drd_gomp_intercepts.c else -VGPRELOAD_DRD_SOURCES_COMMON = drd_pthread_intercepts.c +VGPRELOAD_DRD_SOURCES_COMMON = drd_strmem_intercepts.c drd_pthread_intercepts.c endif DRD_CFLAGS=@FLAG_W_EXTRA@ @FLAG_UNLIMITED_INLINE_UNIT_GROWTH@ \ diff --git a/exp-drd/drd_strmem_intercepts.c b/exp-drd/drd_strmem_intercepts.c new file mode 100644 index 0000000000..3eaccac1f0 --- /dev/null +++ b/exp-drd/drd_strmem_intercepts.c @@ -0,0 +1,95 @@ + +/*--------------------------------------------------------------------*/ +/*--- Replacements for strlen() and strnlen(), which run on the ---*/ +/*--- simulated CPU. ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of DRD, a heavyweight Valgrind tool for + detecting threading errors. The code below has been extracted + from memchec/mc_replace_strmem.c, which has the following copyright + notice: + + Copyright (C) 2000-2008 Julian Seward + jseward@acm.org + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307, USA. + + The GNU General Public License is contained in the file COPYING. +*/ + +#include "pub_tool_basics.h" +#include "pub_tool_hashtable.h" +#include "pub_tool_redir.h" +#include "pub_tool_tooliface.h" +#include "valgrind.h" + + +/* --------- Some handy Z-encoded names. --------- */ + +/* --- Soname of the standard C library. --- */ + +#if defined(VGO_linux) +# define m_libc_soname libcZdsoZa // libc.so* +#elif defined(VGP_ppc32_aix5) + /* AIX has both /usr/lib/libc.a and /usr/lib/libc_r.a. */ +# define m_libc_soname libcZaZdaZLshrZdoZR // libc*.a(shr.o) +#elif defined(VGP_ppc64_aix5) +# define m_libc_soname libcZaZdaZLshrZu64ZdoZR // libc*.a(shr_64.o) +#else +# error "Unknown platform" +#endif + +/* --- Sonames for Linux ELF linkers. --- */ + +#define m_ld_linux_so_2 ldZhlinuxZdsoZd2 // ld-linux.so.2 +#define m_ld_linux_x86_64_so_2 ldZhlinuxZhx86Zh64ZdsoZd2 // ld-linux-x86-64.so.2 +#define m_ld64_so_1 ld64ZdsoZd1 // ld64.so.1 +#define m_ld_so_1 ldZdsoZd1 // ld.so.1 + + +#define STRNLEN(soname, fnname) \ + SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ); \ + SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ) \ + { \ + SizeT i = 0; \ + while (i < n && str[i] != 0) i++; \ + return i; \ + } + +STRNLEN(m_libc_soname, strnlen) + + +// Note that this replacement often doesn't get used because gcc inlines +// calls to strlen() with its own built-in version. This can be very +// confusing if you aren't expecting it. Other small functions in this file +// may also be inline by gcc. +#define STRLEN(soname, fnname) \ + SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ); \ + SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ) \ + { \ + SizeT i = 0; \ + while (str[i] != 0) i++; \ + return i; \ + } + +STRLEN(m_libc_soname, strlen) +STRLEN(m_ld_linux_so_2, strlen) +STRLEN(m_ld_linux_x86_64_so_2, strlen) + +/*--------------------------------------------------------------------*/ +/*--- end ---*/ +/*--------------------------------------------------------------------*/