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