|
From: <sv...@va...> - 2008-06-01 09:33:03
|
Author: bart
Date: 2008-06-01 09:48:48 +0100 (Sun, 01 Jun 2008)
New Revision: 8165
Log:
Added intercepts for strlen() and strnlen().
Added:
trunk/exp-drd/drd_strmem_intercepts.c
Modified:
trunk/exp-drd/Makefile.am
Modified: trunk/exp-drd/Makefile.am
===================================================================
--- trunk/exp-drd/Makefile.am 2008-06-01 07:33:14 UTC (rev 8164)
+++ trunk/exp-drd/Makefile.am 2008-06-01 08:48:48 UTC (rev 8165)
@@ -21,9 +21,10 @@
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@ \
Added: trunk/exp-drd/drd_strmem_intercepts.c
===================================================================
--- trunk/exp-drd/drd_strmem_intercepts.c (rev 0)
+++ trunk/exp-drd/drd_strmem_intercepts.c 2008-06-01 08:48:48 UTC (rev 8165)
@@ -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
+ js...@ac...
+
+ 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 ---*/
+/*--------------------------------------------------------------------*/
|