1/* -*- mode: C; c-basic-offset: 3; indent-tabs-mode: nil; -*- */ 2 3/*--------------------------------------------------------------------*/ 4/*--- Replacements for strlen() and strnlen(), which run on the ---*/ 5/*--- simulated CPU. ---*/ 6/*--------------------------------------------------------------------*/ 7 8/* 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: 13 14 Copyright (C) 2000-2011 Julian Seward 15 jseward@acm.org 16 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. 21 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. 26 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. 31 32 The GNU General Public License is contained in the file COPYING. 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 42#define STRNLEN(soname, fnname) \ 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 ) \ 45 { \ 46 SizeT i = 0; \ 47 while (i < n && str[i] != 0) i++; \ 48 return i; \ 49 } 50 51#if defined(VGO_linux) 52 STRNLEN(VG_Z_LIBC_SONAME, strnlen) 53#elif defined(VGO_darwin) 54 STRNLEN(VG_Z_LIBC_SONAME, strnlen) 55#endif 56 57 58// Note that this replacement often doesn't get used because gcc inlines 59// calls to strlen() with its own built-in version. This can be very 60// confusing if you aren't expecting it. Other small functions in this file 61// may also be inline by gcc. 62#define STRLEN(soname, fnname) \ 63 SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ); \ 64 SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ) \ 65 { \ 66 SizeT i = 0; \ 67 while (str[i] != 0) i++; \ 68 return i; \ 69 } 70 71#if defined(VGO_linux) 72 STRLEN(VG_Z_LIBC_SONAME, strlen) 73 STRLEN(VG_Z_LD_LINUX_SO_2, strlen) 74 STRLEN(VG_Z_LD_LINUX_X86_64_SO_2, strlen) 75#elif defined(VGO_darwin) 76 STRLEN(VG_Z_LIBC_SONAME, strlen) 77#endif 78 79/*--------------------------------------------------------------------*/ 80/*--- end ---*/ 81/*--------------------------------------------------------------------*/ 82