bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 2 | |
| 3 | /*--------------------------------------------------------------------*/ |
| 4 | /*--- Replacements for strlen() and strnlen(), which run on the ---*/ |
| 5 | /*--- simulated CPU. ---*/ |
| 6 | /*--------------------------------------------------------------------*/ |
| 7 | |
| 8 | /* |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 9 | This file is part of DRD, a heavyweight Valgrind tool for |
| 10 | detecting threading errors. The code below has been extracted |
| 11 | from memchec/mc_replace_strmem.c, which has the following copyright |
| 12 | notice: |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 13 | |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 14 | Copyright (C) 2000-2009 Julian Seward |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 15 | jseward@acm.org |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 16 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 17 | This program is free software; you can redistribute it and/or |
| 18 | modify it under the terms of the GNU General Public License as |
| 19 | published by the Free Software Foundation; either version 2 of the |
| 20 | License, or (at your option) any later version. |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 21 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 22 | This program is distributed in the hope that it will be useful, but |
| 23 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 25 | General Public License for more details. |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 26 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 27 | You should have received a copy of the GNU General Public License |
| 28 | along with this program; if not, write to the Free Software |
| 29 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 30 | 02111-1307, USA. |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 31 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 32 | The GNU General Public License is contained in the file COPYING. |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | #include "pub_tool_basics.h" |
| 36 | #include "pub_tool_hashtable.h" |
| 37 | #include "pub_tool_redir.h" |
| 38 | #include "pub_tool_tooliface.h" |
| 39 | #include "valgrind.h" |
| 40 | |
| 41 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 42 | #define STRNLEN(soname, fnname) \ |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 43 | SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ); \ |
| 44 | SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ) \ |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 45 | { \ |
| 46 | SizeT i = 0; \ |
| 47 | while (i < n && str[i] != 0) i++; \ |
| 48 | return i; \ |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 49 | } |
| 50 | |
njn | e615466 | 2009-02-10 04:23:41 +0000 | [diff] [blame] | 51 | STRNLEN(VG_Z_LIBC_SONAME, strnlen) |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 52 | |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 53 | |
| 54 | // Note that this replacement often doesn't get used because gcc inlines |
| 55 | // calls to strlen() with its own built-in version. This can be very |
| 56 | // confusing if you aren't expecting it. Other small functions in this file |
| 57 | // may also be inline by gcc. |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 58 | #define STRLEN(soname, fnname) \ |
| 59 | SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ); \ |
| 60 | SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ) \ |
| 61 | { \ |
| 62 | SizeT i = 0; \ |
| 63 | while (str[i] != 0) i++; \ |
| 64 | return i; \ |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 65 | } |
| 66 | |
njn | e615466 | 2009-02-10 04:23:41 +0000 | [diff] [blame] | 67 | STRLEN(VG_Z_LIBC_SONAME, strlen) |
njn | b4cfbc4 | 2009-05-04 04:20:02 +0000 | [diff] [blame] | 68 | #if defined(VGO_linux) |
njn | e615466 | 2009-02-10 04:23:41 +0000 | [diff] [blame] | 69 | STRLEN(VG_Z_LD_LINUX_SO_2, strlen) |
| 70 | STRLEN(VG_Z_LD_LINUX_X86_64_SO_2, strlen) |
njn | b4cfbc4 | 2009-05-04 04:20:02 +0000 | [diff] [blame] | 71 | #endif |
bart | afe8226 | 2008-06-01 08:48:48 +0000 | [diff] [blame] | 72 | |
| 73 | /*--------------------------------------------------------------------*/ |
| 74 | /*--- end ---*/ |
| 75 | /*--------------------------------------------------------------------*/ |