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