]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/drd/drd_strmem_intercepts.c
update
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / drd / drd_strmem_intercepts.c
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-2010 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 STRNLEN(VG_Z_LIBC_SONAME, strnlen)
52
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.
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;                                                         \
65    }
66
67 STRLEN(VG_Z_LIBC_SONAME,          strlen)
68 #if defined(VGO_linux)
69 STRLEN(VG_Z_LD_LINUX_SO_2,        strlen)
70 STRLEN(VG_Z_LD_LINUX_X86_64_SO_2, strlen)
71 #endif
72
73 /*--------------------------------------------------------------------*/
74 /*--- end                                                          ---*/
75 /*--------------------------------------------------------------------*/