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 | |
| 41 | /* --------- Some handy Z-encoded names. --------- */ |
| 42 | |
| 43 | /* --- Soname of the standard C library. --- */ |
| 44 | |
| 45 | #if defined(VGO_linux) |
| 46 | # define m_libc_soname libcZdsoZa // libc.so* |
| 47 | #elif defined(VGP_ppc32_aix5) |
| 48 | /* AIX has both /usr/lib/libc.a and /usr/lib/libc_r.a. */ |
| 49 | # define m_libc_soname libcZaZdaZLshrZdoZR // libc*.a(shr.o) |
| 50 | #elif defined(VGP_ppc64_aix5) |
| 51 | # define m_libc_soname libcZaZdaZLshrZu64ZdoZR // libc*.a(shr_64.o) |
| 52 | #else |
| 53 | # error "Unknown platform" |
| 54 | #endif |
| 55 | |
| 56 | /* --- Sonames for Linux ELF linkers. --- */ |
| 57 | |
| 58 | #define m_ld_linux_so_2 ldZhlinuxZdsoZd2 // ld-linux.so.2 |
| 59 | #define m_ld_linux_x86_64_so_2 ldZhlinuxZhx86Zh64ZdsoZd2 // ld-linux-x86-64.so.2 |
| 60 | #define m_ld64_so_1 ld64ZdsoZd1 // ld64.so.1 |
| 61 | #define m_ld_so_1 ldZdsoZd1 // ld.so.1 |
| 62 | |
| 63 | |
| 64 | #define STRNLEN(soname, fnname) \ |
| 65 | SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ); \ |
| 66 | SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ) \ |
| 67 | { \ |
| 68 | SizeT i = 0; \ |
| 69 | while (i < n && str[i] != 0) i++; \ |
| 70 | return i; \ |
| 71 | } |
| 72 | |
| 73 | STRNLEN(m_libc_soname, strnlen) |
| 74 | |
| 75 | |
| 76 | // Note that this replacement often doesn't get used because gcc inlines |
| 77 | // calls to strlen() with its own built-in version. This can be very |
| 78 | // confusing if you aren't expecting it. Other small functions in this file |
| 79 | // may also be inline by gcc. |
| 80 | #define STRLEN(soname, fnname) \ |
| 81 | SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ); \ |
| 82 | SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ) \ |
| 83 | { \ |
| 84 | SizeT i = 0; \ |
| 85 | while (str[i] != 0) i++; \ |
| 86 | return i; \ |
| 87 | } |
| 88 | |
| 89 | STRLEN(m_libc_soname, strlen) |
| 90 | STRLEN(m_ld_linux_so_2, strlen) |
| 91 | STRLEN(m_ld_linux_x86_64_so_2, strlen) |
| 92 | |
| 93 | /*--------------------------------------------------------------------*/ |
| 94 | /*--- end ---*/ |
| 95 | /*--------------------------------------------------------------------*/ |