blob: ff61a9cfee55baf41d75f15332b4d55aad73fb96 [file] [log] [blame]
njn3e884182003-04-15 13:03:23 +00001
2/*--------------------------------------------------------------------*/
3/*--- Replacements for strcpy(), memcpy() et al, which run on the ---*/
4/*--- simulated CPU. ---*/
njn1d0825f2006-03-27 11:37:07 +00005/*--- mc_replace_strmem.c ---*/
njn3e884182003-04-15 13:03:23 +00006/*--------------------------------------------------------------------*/
7
8/*
nethercote137bc552003-11-14 17:47:54 +00009 This file is part of MemCheck, a heavyweight Valgrind tool for
njn0e1b5142003-04-15 14:58:06 +000010 detecting memory errors.
njn3e884182003-04-15 13:03:23 +000011
sewardj9eecbbb2010-05-03 21:37:12 +000012 Copyright (C) 2000-2010 Julian Seward
njn3e884182003-04-15 13:03:23 +000013 jseward@acm.org
14
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.
19
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.
24
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.
29
30 The GNU General Public License is contained in the file COPYING.
31*/
32
njnc7561b92005-06-19 01:24:32 +000033#include "pub_tool_basics.h"
njnc7561b92005-06-19 01:24:32 +000034#include "pub_tool_hashtable.h"
njnc7561b92005-06-19 01:24:32 +000035#include "pub_tool_redir.h"
36#include "pub_tool_tooliface.h"
37#include "valgrind.h"
38
njn34419c12003-05-02 17:24:29 +000039#include "mc_include.h"
fitzhardinge98abfc72003-12-16 02:05:15 +000040#include "memcheck.h"
njn3e884182003-04-15 13:03:23 +000041
njn3e884182003-04-15 13:03:23 +000042/* ---------------------------------------------------------------------
njn1f8b3e72005-03-22 04:27:14 +000043 We have our own versions of these functions for two reasons:
44 (a) it allows us to do overlap checking
45 (b) some of the normal versions are hyper-optimised, which fools
46 Memcheck and cause spurious value warnings. Our versions are
47 simpler.
48
njn16eeb4e2005-06-16 03:56:58 +000049 Note that overenthusiastic use of PLT bypassing by the glibc people also
50 means that we need to patch multiple versions of some of the functions to
51 our own implementations.
52
njn1f8b3e72005-03-22 04:27:14 +000053 THEY RUN ON THE SIMD CPU!
njn3e884182003-04-15 13:03:23 +000054 ------------------------------------------------------------------ */
55
sewardjbd2cff22011-08-16 21:45:28 +000056/* Assignment of behavioural equivalence class tags: 2NNN is intended
57 to be reserved for Memcheck. Current usage:
58
59 2001 STRRCHR
60 2002 STRCHR
61 2003 STRCAT
62 2004 STRNCAT
63 2005 STRLCAT
64 2006 STRNLEN
65 2007 STRLEN
66 2008 STRCPY
67 2009 STRNCPY
68 2010 STRLCPY
69 2011 STRNCMP
70 2012 STRCASECMP
71 2013 STRNCASECMP
72 2014 STRCASECMP_L
73 2015 STRNCASECMP_L
74 2016 STRCMP
75 2017 MEMCHR
76 2018 MEMMOVE
77 2019 MEMCMP
78 2020 STPCPY
79 2021 MEMSET
80 2022 MEMCPY
81 2023 BCOPY
82 2024 GLIBC25___MEMMOVE_CHK
83 2025 GLIBC232_STRCHRNUL
84 2026 GLIBC232_RAWMEMCHR
85 2027 GLIBC25___STRCPY_CHK
86 2028 GLIBC25___STPCPY_CHK
87 2029 GLIBC25_MEMPCPY
88 2030 GLIBC26___MEMCPY_CHK
89 2031 STRSTR
90 2032 STRPBRK
91 2033 STRCSPN
92 2034 STRSPN
93*/
94
sewardj126e82d2011-07-12 13:33:00 +000095
sewardjdda830a2003-07-20 22:28:42 +000096/* Figure out if [dst .. dst+dstlen-1] overlaps with
97 [src .. src+srclen-1].
98 We assume that the address ranges do not wrap around
99 (which is safe since on Linux addresses >= 0xC0000000
100 are not accessible and the program will segfault in this
101 circumstance, presumably).
102*/
sewardj126e82d2011-07-12 13:33:00 +0000103static inline
njnc6168192004-11-29 13:54:10 +0000104Bool is_overlap ( void* dst, const void* src, SizeT dstlen, SizeT srclen )
njn3e884182003-04-15 13:03:23 +0000105{
sewardjdda830a2003-07-20 22:28:42 +0000106 Addr loS, hiS, loD, hiD;
107
108 if (dstlen == 0 || srclen == 0)
109 return False;
110
111 loS = (Addr)src;
112 loD = (Addr)dst;
113 hiS = loS + srclen - 1;
114 hiD = loD + dstlen - 1;
115
116 /* So figure out if [loS .. hiS] overlaps with [loD .. hiD]. */
117 if (loS < loD) {
118 return !(hiS < loD);
119 }
120 else if (loD < loS) {
121 return !(hiD < loS);
122 }
123 else {
124 /* They start at same place. Since we know neither of them has
125 zero length, they must overlap. */
126 return True;
127 }
njn3e884182003-04-15 13:03:23 +0000128}
129
sewardj126e82d2011-07-12 13:33:00 +0000130
131/* Call here to exit if we can't continue. On Android we can't call
132 _exit for some reason, so we have to blunt-instrument it. */
133__attribute__ ((__noreturn__))
134static inline void my_exit ( int x )
135{
136# if defined(VGPV_arm_linux_android)
137 __asm__ __volatile__(".word 0xFFFFFFFF");
138 while (1) {}
139# else
140 extern void _exit(int status);
sewardj49665422011-07-12 13:50:59 +0000141 _exit(x);
sewardj126e82d2011-07-12 13:33:00 +0000142# endif
143}
144
145
njn1f8b3e72005-03-22 04:27:14 +0000146// This is a macro rather than a function because we don't want to have an
147// extra function in the stack trace.
bart575ce8e2011-05-15 07:04:03 +0000148#define RECORD_OVERLAP_ERROR(s, src, dst, len) \
149 VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
150 _VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR, \
151 s, src, dst, len, 0)
njn3e884182003-04-15 13:03:23 +0000152
njn16eeb4e2005-06-16 03:56:58 +0000153
154#define STRRCHR(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000155 char* VG_REPLACE_FUNCTION_EZU(2001,soname,fnname)( const char* s, int c ); \
156 char* VG_REPLACE_FUNCTION_EZU(2001,soname,fnname)( const char* s, int c ) \
njn16eeb4e2005-06-16 03:56:58 +0000157 { \
158 UChar ch = (UChar)((UInt)c); \
159 UChar* p = (UChar*)s; \
160 UChar* last = NULL; \
161 while (True) { \
162 if (*p == ch) last = p; \
163 if (*p == 0) return last; \
164 p++; \
165 } \
njn3e884182003-04-15 13:03:23 +0000166 }
njn3e884182003-04-15 13:03:23 +0000167
njn16eeb4e2005-06-16 03:56:58 +0000168// Apparently rindex() is the same thing as strrchr()
njne6154662009-02-10 04:23:41 +0000169STRRCHR(VG_Z_LIBC_SONAME, strrchr)
170STRRCHR(VG_Z_LIBC_SONAME, rindex)
njnb4cfbc42009-05-04 04:20:02 +0000171#if defined(VGO_linux)
tomd2645142009-10-29 09:27:11 +0000172STRRCHR(VG_Z_LIBC_SONAME, __GI_strrchr)
njne6154662009-02-10 04:23:41 +0000173STRRCHR(VG_Z_LD_LINUX_SO_2, rindex)
njnf76d27a2009-05-28 01:53:07 +0000174#elif defined(VGO_darwin)
175STRRCHR(VG_Z_DYLD, strrchr)
176STRRCHR(VG_Z_DYLD, rindex)
njnb4cfbc42009-05-04 04:20:02 +0000177#endif
njn16eeb4e2005-06-16 03:56:58 +0000178
179
180#define STRCHR(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000181 char* VG_REPLACE_FUNCTION_EZU(2002,soname,fnname) ( const char* s, int c ); \
182 char* VG_REPLACE_FUNCTION_EZU(2002,soname,fnname) ( const char* s, int c ) \
njn16eeb4e2005-06-16 03:56:58 +0000183 { \
184 UChar ch = (UChar)((UInt)c); \
185 UChar* p = (UChar*)s; \
186 while (True) { \
187 if (*p == ch) return p; \
188 if (*p == 0) return NULL; \
189 p++; \
190 } \
njn3e884182003-04-15 13:03:23 +0000191 }
njn3e884182003-04-15 13:03:23 +0000192
njn16eeb4e2005-06-16 03:56:58 +0000193// Apparently index() is the same thing as strchr()
njne6154662009-02-10 04:23:41 +0000194STRCHR(VG_Z_LIBC_SONAME, strchr)
njne6154662009-02-10 04:23:41 +0000195STRCHR(VG_Z_LIBC_SONAME, index)
njnb4cfbc42009-05-04 04:20:02 +0000196#if defined(VGO_linux)
tomd2645142009-10-29 09:27:11 +0000197STRCHR(VG_Z_LIBC_SONAME, __GI_strchr)
njnb4cfbc42009-05-04 04:20:02 +0000198STRCHR(VG_Z_LD_LINUX_SO_2, strchr)
njne6154662009-02-10 04:23:41 +0000199STRCHR(VG_Z_LD_LINUX_SO_2, index)
njnb4cfbc42009-05-04 04:20:02 +0000200STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, strchr)
njne6154662009-02-10 04:23:41 +0000201STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, index)
njnf76d27a2009-05-28 01:53:07 +0000202#elif defined(VGO_darwin)
203STRCHR(VG_Z_DYLD, strchr)
204STRCHR(VG_Z_DYLD, index)
njnb4cfbc42009-05-04 04:20:02 +0000205#endif
njn3e884182003-04-15 13:03:23 +0000206
njn3e884182003-04-15 13:03:23 +0000207
njn16eeb4e2005-06-16 03:56:58 +0000208#define STRCAT(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000209 char* VG_REPLACE_FUNCTION_EZU(2003,soname,fnname) \
210 ( char* dst, const char* src ); \
211 char* VG_REPLACE_FUNCTION_EZU(2003,soname,fnname) \
212 ( char* dst, const char* src ) \
njn16eeb4e2005-06-16 03:56:58 +0000213 { \
214 const Char* src_orig = src; \
215 Char* dst_orig = dst; \
216 while (*dst) dst++; \
217 while (*src) *dst++ = *src++; \
218 *dst = 0; \
sewardjb6c04032007-11-13 20:52:29 +0000219 \
njn16eeb4e2005-06-16 03:56:58 +0000220 /* This is a bit redundant, I think; any overlap and the strcat will */ \
221 /* go forever... or until a seg fault occurs. */ \
222 if (is_overlap(dst_orig, \
223 src_orig, \
224 (Addr)dst-(Addr)dst_orig+1, \
225 (Addr)src-(Addr)src_orig+1)) \
njn718d3b12006-12-16 00:54:12 +0000226 RECORD_OVERLAP_ERROR("strcat", dst_orig, src_orig, 0); \
sewardjb6c04032007-11-13 20:52:29 +0000227 \
njn16eeb4e2005-06-16 03:56:58 +0000228 return dst_orig; \
njn3e884182003-04-15 13:03:23 +0000229 }
njn3e884182003-04-15 13:03:23 +0000230
njne6154662009-02-10 04:23:41 +0000231STRCAT(VG_Z_LIBC_SONAME, strcat)
tomd2645142009-10-29 09:27:11 +0000232#if defined(VGO_linux)
233STRCAT(VG_Z_LIBC_SONAME, __GI_strcat)
234#endif
njn16eeb4e2005-06-16 03:56:58 +0000235
236#define STRNCAT(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000237 char* VG_REPLACE_FUNCTION_EZU(2004,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000238 ( char* dst, const char* src, SizeT n ); \
sewardjbd2cff22011-08-16 21:45:28 +0000239 char* VG_REPLACE_FUNCTION_EZU(2004,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000240 ( char* dst, const char* src, SizeT n ) \
njn16eeb4e2005-06-16 03:56:58 +0000241 { \
242 const Char* src_orig = src; \
243 Char* dst_orig = dst; \
244 SizeT m = 0; \
sewardjb6c04032007-11-13 20:52:29 +0000245 \
njn16eeb4e2005-06-16 03:56:58 +0000246 while (*dst) dst++; \
247 while (m < n && *src) { m++; *dst++ = *src++; } /* concat <= n chars */ \
248 *dst = 0; /* always add null */ \
sewardjb6c04032007-11-13 20:52:29 +0000249 \
njn16eeb4e2005-06-16 03:56:58 +0000250 /* This checks for overlap after copying, unavoidable without */ \
251 /* pre-counting lengths... should be ok */ \
252 if (is_overlap(dst_orig, \
253 src_orig, \
sewardjbd2cff22011-08-16 21:45:28 +0000254 (Addr)dst-(Addr)dst_orig+1, \
njn16eeb4e2005-06-16 03:56:58 +0000255 (Addr)src-(Addr)src_orig+1)) \
njn718d3b12006-12-16 00:54:12 +0000256 RECORD_OVERLAP_ERROR("strncat", dst_orig, src_orig, n); \
sewardjb6c04032007-11-13 20:52:29 +0000257 \
njn16eeb4e2005-06-16 03:56:58 +0000258 return dst_orig; \
njn3e884182003-04-15 13:03:23 +0000259 }
njn3e884182003-04-15 13:03:23 +0000260
njne6154662009-02-10 04:23:41 +0000261STRNCAT(VG_Z_LIBC_SONAME, strncat)
njnf76d27a2009-05-28 01:53:07 +0000262#if defined(VGO_darwin)
263STRNCAT(VG_Z_DYLD, strncat)
264#endif
265
266
267/* Append src to dst. n is the size of dst's buffer. dst is guaranteed
268 to be nul-terminated after the copy, unless n <= strlen(dst_orig).
269 Returns min(n, strlen(dst_orig)) + strlen(src_orig).
270 Truncation occurred if retval >= n.
271*/
272#define STRLCAT(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000273 SizeT VG_REPLACE_FUNCTION_EZU(2005,soname,fnname) \
njnf76d27a2009-05-28 01:53:07 +0000274 ( char* dst, const char* src, SizeT n ); \
sewardjbd2cff22011-08-16 21:45:28 +0000275 SizeT VG_REPLACE_FUNCTION_EZU(2005,soname,fnname) \
njnf76d27a2009-05-28 01:53:07 +0000276 ( char* dst, const char* src, SizeT n ) \
277 { \
278 const Char* src_orig = src; \
279 Char* dst_orig = dst; \
280 SizeT m = 0; \
sewardjbd2cff22011-08-16 21:45:28 +0000281 \
njnf76d27a2009-05-28 01:53:07 +0000282 while (m < n && *dst) { m++; dst++; } \
283 if (m < n) { \
284 /* Fill as far as dst_orig[n-2], then nul-terminate. */ \
285 while (m < n-1 && *src) { m++; *dst++ = *src++; } \
286 *dst = 0; \
287 } else { \
288 /* No space to copy anything to dst. m == n */ \
289 } \
290 /* Finish counting min(n, strlen(dst_orig)) + strlen(src_orig) */ \
291 while (*src) { m++; src++; } \
292 /* This checks for overlap after copying, unavoidable without */ \
293 /* pre-counting lengths... should be ok */ \
294 if (is_overlap(dst_orig, \
295 src_orig, \
296 (Addr)dst-(Addr)dst_orig+1, \
297 (Addr)src-(Addr)src_orig+1)) \
298 RECORD_OVERLAP_ERROR("strlcat", dst_orig, src_orig, n); \
sewardjbd2cff22011-08-16 21:45:28 +0000299 \
njnf76d27a2009-05-28 01:53:07 +0000300 return m; \
301 }
302
303#if defined(VGO_darwin)
304STRLCAT(VG_Z_LIBC_SONAME, strlcat)
305STRLCAT(VG_Z_DYLD, strlcat)
306#endif
sewardj31b9ce12006-10-17 01:27:13 +0000307
njn3e884182003-04-15 13:03:23 +0000308
njn16eeb4e2005-06-16 03:56:58 +0000309#define STRNLEN(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000310 SizeT VG_REPLACE_FUNCTION_EZU(2006,soname,fnname) \
311 ( const char* str, SizeT n ); \
312 SizeT VG_REPLACE_FUNCTION_EZU(2006,soname,fnname) \
313 ( const char* str, SizeT n ) \
njn16eeb4e2005-06-16 03:56:58 +0000314 { \
315 SizeT i = 0; \
316 while (i < n && str[i] != 0) i++; \
317 return i; \
njn3e884182003-04-15 13:03:23 +0000318 }
njn3e884182003-04-15 13:03:23 +0000319
njne6154662009-02-10 04:23:41 +0000320STRNLEN(VG_Z_LIBC_SONAME, strnlen)
tomd2645142009-10-29 09:27:11 +0000321#if defined(VGO_linux)
322STRNLEN(VG_Z_LIBC_SONAME, __GI_strnlen)
323#endif
njn16eeb4e2005-06-16 03:56:58 +0000324
sewardj3ceec242003-07-30 21:24:25 +0000325
njn5ec15ed2005-08-24 19:55:51 +0000326// Note that this replacement often doesn't get used because gcc inlines
327// calls to strlen() with its own built-in version. This can be very
328// confusing if you aren't expecting it. Other small functions in this file
329// may also be inline by gcc.
njn16eeb4e2005-06-16 03:56:58 +0000330#define STRLEN(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000331 SizeT VG_REPLACE_FUNCTION_EZU(2007,soname,fnname) \
332 ( const char* str ); \
333 SizeT VG_REPLACE_FUNCTION_EZU(2007,soname,fnname) \
334 ( const char* str ) \
njn16eeb4e2005-06-16 03:56:58 +0000335 { \
336 SizeT i = 0; \
337 while (str[i] != 0) i++; \
338 return i; \
sewardj3ceec242003-07-30 21:24:25 +0000339 }
njn16eeb4e2005-06-16 03:56:58 +0000340
njnb4cfbc42009-05-04 04:20:02 +0000341STRLEN(VG_Z_LIBC_SONAME, strlen)
342#if defined(VGO_linux)
tomd2645142009-10-29 09:27:11 +0000343STRLEN(VG_Z_LIBC_SONAME, __GI_strlen)
njnb4cfbc42009-05-04 04:20:02 +0000344#endif
sewardj31b9ce12006-10-17 01:27:13 +0000345
njn16eeb4e2005-06-16 03:56:58 +0000346
347#define STRCPY(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000348 char* VG_REPLACE_FUNCTION_EZU(2008,soname,fnname) \
349 ( char* dst, const char* src ); \
350 char* VG_REPLACE_FUNCTION_EZU(2008,soname,fnname) \
351 ( char* dst, const char* src ) \
njn16eeb4e2005-06-16 03:56:58 +0000352 { \
353 const Char* src_orig = src; \
354 Char* dst_orig = dst; \
sewardjb6c04032007-11-13 20:52:29 +0000355 \
njn16eeb4e2005-06-16 03:56:58 +0000356 while (*src) *dst++ = *src++; \
357 *dst = 0; \
sewardjb6c04032007-11-13 20:52:29 +0000358 \
njn16eeb4e2005-06-16 03:56:58 +0000359 /* This checks for overlap after copying, unavoidable without */ \
360 /* pre-counting length... should be ok */ \
361 if (is_overlap(dst_orig, \
362 src_orig, \
sewardjbd2cff22011-08-16 21:45:28 +0000363 (Addr)dst-(Addr)dst_orig+1, \
njn16eeb4e2005-06-16 03:56:58 +0000364 (Addr)src-(Addr)src_orig+1)) \
njn718d3b12006-12-16 00:54:12 +0000365 RECORD_OVERLAP_ERROR("strcpy", dst_orig, src_orig, 0); \
sewardjb6c04032007-11-13 20:52:29 +0000366 \
njn16eeb4e2005-06-16 03:56:58 +0000367 return dst_orig; \
368 }
369
njne6154662009-02-10 04:23:41 +0000370STRCPY(VG_Z_LIBC_SONAME, strcpy)
tomd2645142009-10-29 09:27:11 +0000371#if defined(VGO_linux)
372STRCPY(VG_Z_LIBC_SONAME, __GI_strcpy)
373#elif defined(VGO_darwin)
njnf76d27a2009-05-28 01:53:07 +0000374STRCPY(VG_Z_DYLD, strcpy)
375#endif
njn16eeb4e2005-06-16 03:56:58 +0000376
377
378#define STRNCPY(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000379 char* VG_REPLACE_FUNCTION_EZU(2009,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000380 ( char* dst, const char* src, SizeT n ); \
sewardjbd2cff22011-08-16 21:45:28 +0000381 char* VG_REPLACE_FUNCTION_EZU(2009,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000382 ( char* dst, const char* src, SizeT n ) \
njn16eeb4e2005-06-16 03:56:58 +0000383 { \
384 const Char* src_orig = src; \
385 Char* dst_orig = dst; \
386 SizeT m = 0; \
sewardjb6c04032007-11-13 20:52:29 +0000387 \
njn16eeb4e2005-06-16 03:56:58 +0000388 while (m < n && *src) { m++; *dst++ = *src++; } \
389 /* Check for overlap after copying; all n bytes of dst are relevant, */ \
390 /* but only m+1 bytes of src if terminator was found */ \
391 if (is_overlap(dst_orig, src_orig, n, (m < n) ? m+1 : n)) \
njn718d3b12006-12-16 00:54:12 +0000392 RECORD_OVERLAP_ERROR("strncpy", dst, src, n); \
njn16eeb4e2005-06-16 03:56:58 +0000393 while (m++ < n) *dst++ = 0; /* must pad remainder with nulls */ \
394 \
395 return dst_orig; \
396 }
397
njne6154662009-02-10 04:23:41 +0000398STRNCPY(VG_Z_LIBC_SONAME, strncpy)
tomd2645142009-10-29 09:27:11 +0000399#if defined(VGO_linux)
400STRNCPY(VG_Z_LIBC_SONAME, __GI_strncpy)
401#elif defined(VGO_darwin)
njnf76d27a2009-05-28 01:53:07 +0000402STRNCPY(VG_Z_DYLD, strncpy)
403#endif
404
405
406/* Copy up to n-1 bytes from src to dst. Then nul-terminate dst if n > 0.
407 Returns strlen(src). Does not zero-fill the remainder of dst. */
408#define STRLCPY(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000409 SizeT VG_REPLACE_FUNCTION_EZU(2010,soname,fnname) \
njnf76d27a2009-05-28 01:53:07 +0000410 ( char* dst, const char* src, SizeT n ); \
sewardjbd2cff22011-08-16 21:45:28 +0000411 SizeT VG_REPLACE_FUNCTION_EZU(2010,soname,fnname) \
njnf76d27a2009-05-28 01:53:07 +0000412 ( char* dst, const char* src, SizeT n ) \
413 { \
414 const char* src_orig = src; \
415 char* dst_orig = dst; \
416 SizeT m = 0; \
sewardjbd2cff22011-08-16 21:45:28 +0000417 \
njnf76d27a2009-05-28 01:53:07 +0000418 while (m < n-1 && *src) { m++; *dst++ = *src++; } \
419 /* m non-nul bytes have now been copied, and m <= n-1. */ \
420 /* Check for overlap after copying; all n bytes of dst are relevant, */ \
421 /* but only m+1 bytes of src if terminator was found */ \
422 if (is_overlap(dst_orig, src_orig, n, (m < n) ? m+1 : n)) \
423 RECORD_OVERLAP_ERROR("strlcpy", dst, src, n); \
424 /* Nul-terminate dst. */ \
425 if (n > 0) *dst = 0; \
426 /* Finish counting strlen(src). */ \
427 while (*src) src++; \
428 return src - src_orig; \
429 }
430
431#if defined(VGO_darwin)
432STRLCPY(VG_Z_LIBC_SONAME, strlcpy)
433STRLCPY(VG_Z_DYLD, strlcpy)
434#endif
njn16eeb4e2005-06-16 03:56:58 +0000435
436
437#define STRNCMP(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000438 int VG_REPLACE_FUNCTION_EZU(2011,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000439 ( const char* s1, const char* s2, SizeT nmax ); \
sewardjbd2cff22011-08-16 21:45:28 +0000440 int VG_REPLACE_FUNCTION_EZU(2011,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000441 ( const char* s1, const char* s2, SizeT nmax ) \
njn16eeb4e2005-06-16 03:56:58 +0000442 { \
443 SizeT n = 0; \
444 while (True) { \
445 if (n >= nmax) return 0; \
446 if (*s1 == 0 && *s2 == 0) return 0; \
447 if (*s1 == 0) return -1; \
448 if (*s2 == 0) return 1; \
sewardjb6c04032007-11-13 20:52:29 +0000449 \
njn16eeb4e2005-06-16 03:56:58 +0000450 if (*(unsigned char*)s1 < *(unsigned char*)s2) return -1; \
451 if (*(unsigned char*)s1 > *(unsigned char*)s2) return 1; \
sewardjb6c04032007-11-13 20:52:29 +0000452 \
njn16eeb4e2005-06-16 03:56:58 +0000453 s1++; s2++; n++; \
454 } \
455 }
456
njne6154662009-02-10 04:23:41 +0000457STRNCMP(VG_Z_LIBC_SONAME, strncmp)
tomd2645142009-10-29 09:27:11 +0000458#if defined(VGO_linux)
459STRNCMP(VG_Z_LIBC_SONAME, __GI_strncmp)
460#elif defined(VGO_darwin)
njnf76d27a2009-05-28 01:53:07 +0000461STRNCMP(VG_Z_DYLD, strncmp)
462#endif
njn16eeb4e2005-06-16 03:56:58 +0000463
464
tomce6d0ac2010-11-12 10:03:13 +0000465#define STRCASECMP(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000466 int VG_REPLACE_FUNCTION_EZU(2012,soname,fnname) \
tomce6d0ac2010-11-12 10:03:13 +0000467 ( const char* s1, const char* s2 ); \
sewardjbd2cff22011-08-16 21:45:28 +0000468 int VG_REPLACE_FUNCTION_EZU(2012,soname,fnname) \
tomce6d0ac2010-11-12 10:03:13 +0000469 ( const char* s1, const char* s2 ) \
470 { \
tome03c8c42010-11-12 10:40:20 +0000471 extern int tolower(int); \
tomce6d0ac2010-11-12 10:03:13 +0000472 register unsigned char c1; \
473 register unsigned char c2; \
474 while (True) { \
475 c1 = tolower(*(unsigned char *)s1); \
476 c2 = tolower(*(unsigned char *)s2); \
477 if (c1 != c2) break; \
478 if (c1 == 0) break; \
479 s1++; s2++; \
480 } \
481 if ((unsigned char)c1 < (unsigned char)c2) return -1; \
482 if ((unsigned char)c1 > (unsigned char)c2) return 1; \
483 return 0; \
484 }
485
sewardj126e82d2011-07-12 13:33:00 +0000486#if !defined(VGPV_arm_linux_android)
tomce6d0ac2010-11-12 10:03:13 +0000487STRCASECMP(VG_Z_LIBC_SONAME, strcasecmp)
sewardj126e82d2011-07-12 13:33:00 +0000488#endif
489#if defined(VGO_linux) && !defined(VGPV_arm_linux_android)
tomce6d0ac2010-11-12 10:03:13 +0000490STRCASECMP(VG_Z_LIBC_SONAME, __GI_strcasecmp)
491#endif
492
493
494#define STRNCASECMP(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000495 int VG_REPLACE_FUNCTION_EZU(2013,soname,fnname) \
tomce6d0ac2010-11-12 10:03:13 +0000496 ( const char* s1, const char* s2, SizeT nmax ); \
sewardjbd2cff22011-08-16 21:45:28 +0000497 int VG_REPLACE_FUNCTION_EZU(2013,soname,fnname) \
tomce6d0ac2010-11-12 10:03:13 +0000498 ( const char* s1, const char* s2, SizeT nmax ) \
499 { \
tome03c8c42010-11-12 10:40:20 +0000500 extern int tolower(int); \
tomce6d0ac2010-11-12 10:03:13 +0000501 SizeT n = 0; \
502 while (True) { \
503 if (n >= nmax) return 0; \
504 if (*s1 == 0 && *s2 == 0) return 0; \
505 if (*s1 == 0) return -1; \
506 if (*s2 == 0) return 1; \
507 \
sewardjbd2cff22011-08-16 21:45:28 +0000508 if (tolower(*(unsigned char*)s1) \
509 < tolower(*(unsigned char*)s2)) return -1; \
510 if (tolower(*(unsigned char*)s1) \
511 > tolower(*(unsigned char*)s2)) return 1; \
tomce6d0ac2010-11-12 10:03:13 +0000512 \
513 s1++; s2++; n++; \
514 } \
515 }
516
sewardj126e82d2011-07-12 13:33:00 +0000517#if !defined(VGPV_arm_linux_android)
tomce6d0ac2010-11-12 10:03:13 +0000518STRNCASECMP(VG_Z_LIBC_SONAME, strncasecmp)
sewardj126e82d2011-07-12 13:33:00 +0000519#endif
520#if defined(VGO_linux) && !defined(VGPV_arm_linux_android)
tomce6d0ac2010-11-12 10:03:13 +0000521STRNCASECMP(VG_Z_LIBC_SONAME, __GI_strncasecmp)
522#elif defined(VGO_darwin)
523STRNCASECMP(VG_Z_DYLD, strncasecmp)
524#endif
525
526
tomce6d0ac2010-11-12 10:03:13 +0000527#define STRCASECMP_L(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000528 int VG_REPLACE_FUNCTION_EZU(2014,soname,fnname) \
tome03c8c42010-11-12 10:40:20 +0000529 ( const char* s1, const char* s2, void* locale ); \
sewardjbd2cff22011-08-16 21:45:28 +0000530 int VG_REPLACE_FUNCTION_EZU(2014,soname,fnname) \
tome03c8c42010-11-12 10:40:20 +0000531 ( const char* s1, const char* s2, void* locale ) \
tomce6d0ac2010-11-12 10:03:13 +0000532 { \
tome03c8c42010-11-12 10:40:20 +0000533 extern int tolower_l(int, void*) __attribute__((weak)); \
tomce6d0ac2010-11-12 10:03:13 +0000534 register unsigned char c1; \
535 register unsigned char c2; \
536 while (True) { \
537 c1 = tolower_l(*(unsigned char *)s1, locale); \
538 c2 = tolower_l(*(unsigned char *)s2, locale); \
539 if (c1 != c2) break; \
540 if (c1 == 0) break; \
541 s1++; s2++; \
542 } \
543 if ((unsigned char)c1 < (unsigned char)c2) return -1; \
544 if ((unsigned char)c1 > (unsigned char)c2) return 1; \
545 return 0; \
546 }
547
548STRCASECMP_L(VG_Z_LIBC_SONAME, strcasecmp_l)
549#if defined(VGO_linux)
550STRCASECMP_L(VG_Z_LIBC_SONAME, __GI_strcasecmp_l)
sewardjbd2cff22011-08-16 21:45:28 +0000551STRCASECMP_L(VG_Z_LIBC_SONAME, __GI___strcasecmp_l)
tomce6d0ac2010-11-12 10:03:13 +0000552#endif
553
554
555#define STRNCASECMP_L(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000556 int VG_REPLACE_FUNCTION_EZU(2015,soname,fnname) \
tome03c8c42010-11-12 10:40:20 +0000557 ( const char* s1, const char* s2, SizeT nmax, void* locale ); \
sewardjbd2cff22011-08-16 21:45:28 +0000558 int VG_REPLACE_FUNCTION_EZU(2015,soname,fnname) \
tome03c8c42010-11-12 10:40:20 +0000559 ( const char* s1, const char* s2, SizeT nmax, void* locale ) \
tomce6d0ac2010-11-12 10:03:13 +0000560 { \
tome03c8c42010-11-12 10:40:20 +0000561 extern int tolower_l(int, void*) __attribute__((weak)); \
tomce6d0ac2010-11-12 10:03:13 +0000562 SizeT n = 0; \
563 while (True) { \
564 if (n >= nmax) return 0; \
565 if (*s1 == 0 && *s2 == 0) return 0; \
566 if (*s1 == 0) return -1; \
567 if (*s2 == 0) return 1; \
568 \
sewardjbd2cff22011-08-16 21:45:28 +0000569 if (tolower_l(*(unsigned char*)s1, locale) \
570 < tolower_l(*(unsigned char*)s2, locale)) return -1; \
571 if (tolower_l(*(unsigned char*)s1, locale) \
572 > tolower_l(*(unsigned char*)s2, locale)) return 1; \
tomce6d0ac2010-11-12 10:03:13 +0000573 \
574 s1++; s2++; n++; \
575 } \
576 }
577
578STRNCASECMP_L(VG_Z_LIBC_SONAME, strncasecmp_l)
579#if defined(VGO_linux)
580STRNCASECMP_L(VG_Z_LIBC_SONAME, __GI_strncasecmp_l)
581#elif defined(VGO_darwin)
582STRNCASECMP_L(VG_Z_DYLD, strncasecmp_l)
583#endif
584
585
njn16eeb4e2005-06-16 03:56:58 +0000586#define STRCMP(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000587 int VG_REPLACE_FUNCTION_EZU(2016,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000588 ( const char* s1, const char* s2 ); \
sewardjbd2cff22011-08-16 21:45:28 +0000589 int VG_REPLACE_FUNCTION_EZU(2016,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000590 ( const char* s1, const char* s2 ) \
njn16eeb4e2005-06-16 03:56:58 +0000591 { \
592 register unsigned char c1; \
593 register unsigned char c2; \
594 while (True) { \
595 c1 = *(unsigned char *)s1; \
596 c2 = *(unsigned char *)s2; \
597 if (c1 != c2) break; \
598 if (c1 == 0) break; \
599 s1++; s2++; \
600 } \
601 if ((unsigned char)c1 < (unsigned char)c2) return -1; \
602 if ((unsigned char)c1 > (unsigned char)c2) return 1; \
603 return 0; \
604 }
605
njne6154662009-02-10 04:23:41 +0000606STRCMP(VG_Z_LIBC_SONAME, strcmp)
njnb4cfbc42009-05-04 04:20:02 +0000607#if defined(VGO_linux)
tomd2645142009-10-29 09:27:11 +0000608STRCMP(VG_Z_LIBC_SONAME, __GI_strcmp)
njne6154662009-02-10 04:23:41 +0000609STRCMP(VG_Z_LD_LINUX_X86_64_SO_2, strcmp)
610STRCMP(VG_Z_LD64_SO_1, strcmp)
njnb4cfbc42009-05-04 04:20:02 +0000611#endif
njn16eeb4e2005-06-16 03:56:58 +0000612
613
614#define MEMCHR(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000615 void* VG_REPLACE_FUNCTION_EZU(2017,soname,fnname) \
616 (const void *s, int c, SizeT n); \
617 void* VG_REPLACE_FUNCTION_EZU(2017,soname,fnname) \
618 (const void *s, int c, SizeT n) \
njn16eeb4e2005-06-16 03:56:58 +0000619 { \
620 SizeT i; \
621 UChar c0 = (UChar)c; \
622 UChar* p = (UChar*)s; \
623 for (i = 0; i < n; i++) \
624 if (p[i] == c0) return (void*)(&p[i]); \
625 return NULL; \
626 }
627
njne6154662009-02-10 04:23:41 +0000628MEMCHR(VG_Z_LIBC_SONAME, memchr)
njnf76d27a2009-05-28 01:53:07 +0000629#if defined(VGO_darwin)
630MEMCHR(VG_Z_DYLD, memchr)
631#endif
njn16eeb4e2005-06-16 03:56:58 +0000632
633
sewardjbd2cff22011-08-16 21:45:28 +0000634#define MEMMOVE_OR_MEMCPY(becTag, soname, fnname, do_ol_check) \
sewardjd88797f2011-08-17 21:25:50 +0000635 void* VG_REPLACE_FUNCTION_EZZ(becTag,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000636 ( void *dst, const void *src, SizeT len ); \
sewardjd88797f2011-08-17 21:25:50 +0000637 void* VG_REPLACE_FUNCTION_EZZ(becTag,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000638 ( void *dst, const void *src, SizeT len ) \
njn16eeb4e2005-06-16 03:56:58 +0000639 { \
sewardjbd2cff22011-08-16 21:45:28 +0000640 if (do_ol_check && is_overlap(dst, src, len, len)) \
njn718d3b12006-12-16 00:54:12 +0000641 RECORD_OVERLAP_ERROR("memcpy", dst, src, len); \
sewardjb6c04032007-11-13 20:52:29 +0000642 \
sewardj7b4e00b2010-08-24 09:05:52 +0000643 const Addr WS = sizeof(UWord); /* 8 or 4 */ \
644 const Addr WM = WS - 1; /* 7 or 3 */ \
645 \
646 if (dst < src) { \
647 \
648 /* Copying backwards. */ \
649 SizeT n = len; \
650 Addr d = (Addr)dst; \
651 Addr s = (Addr)src; \
652 \
653 if (((s^d) & WM) == 0) { \
654 /* s and d have same UWord alignment. */ \
655 /* Pull up to a UWord boundary. */ \
656 while ((s & WM) != 0 && n >= 1) \
657 { *(UChar*)d = *(UChar*)s; s += 1; d += 1; n -= 1; } \
658 /* Copy UWords. */ \
659 while (n >= WS) \
660 { *(UWord*)d = *(UWord*)s; s += WS; d += WS; n -= WS; } \
661 if (n == 0) \
662 return dst; \
njn16eeb4e2005-06-16 03:56:58 +0000663 } \
sewardj7b4e00b2010-08-24 09:05:52 +0000664 if (((s|d) & 1) == 0) { \
665 /* Both are 16-aligned; copy what we can thusly. */ \
666 while (n >= 2) \
667 { *(UShort*)d = *(UShort*)s; s += 2; d += 2; n -= 2; } \
njn16eeb4e2005-06-16 03:56:58 +0000668 } \
sewardj7b4e00b2010-08-24 09:05:52 +0000669 /* Copy leftovers, or everything if misaligned. */ \
670 while (n >= 1) \
671 { *(UChar*)d = *(UChar*)s; s += 1; d += 1; n -= 1; } \
672 \
673 } else if (dst > src) { \
674 \
675 SizeT n = len; \
676 Addr d = ((Addr)dst) + n; \
677 Addr s = ((Addr)src) + n; \
678 \
679 /* Copying forwards. */ \
680 if (((s^d) & WM) == 0) { \
681 /* s and d have same UWord alignment. */ \
682 /* Back down to a UWord boundary. */ \
683 while ((s & WM) != 0 && n >= 1) \
684 { s -= 1; d -= 1; *(UChar*)d = *(UChar*)s; n -= 1; } \
685 /* Copy UWords. */ \
686 while (n >= WS) \
687 { s -= WS; d -= WS; *(UWord*)d = *(UWord*)s; n -= WS; } \
688 if (n == 0) \
689 return dst; \
njn16eeb4e2005-06-16 03:56:58 +0000690 } \
sewardj7b4e00b2010-08-24 09:05:52 +0000691 if (((s|d) & 1) == 0) { \
692 /* Both are 16-aligned; copy what we can thusly. */ \
693 while (n >= 2) \
694 { s -= 2; d -= 2; *(UShort*)d = *(UShort*)s; n -= 2; } \
njn16eeb4e2005-06-16 03:56:58 +0000695 } \
sewardj7b4e00b2010-08-24 09:05:52 +0000696 /* Copy leftovers, or everything if misaligned. */ \
697 while (n >= 1) \
698 { s -= 1; d -= 1; *(UChar*)d = *(UChar*)s; n -= 1; } \
699 \
njn16eeb4e2005-06-16 03:56:58 +0000700 } \
sewardj7b4e00b2010-08-24 09:05:52 +0000701 \
njn16eeb4e2005-06-16 03:56:58 +0000702 return dst; \
703 }
704
sewardjbd2cff22011-08-16 21:45:28 +0000705#define MEMMOVE(soname, fnname) \
706 MEMMOVE_OR_MEMCPY(2018, soname, fnname, 0)
707
708#define MEMCPY(soname, fnname) \
709 MEMMOVE_OR_MEMCPY(2022, soname, fnname, 1)
710
njnb4cfbc42009-05-04 04:20:02 +0000711#if defined(VGO_linux)
sewardjbd2cff22011-08-16 21:45:28 +0000712/* For older memcpy we have to use memmove-like semantics and skip the
713 overlap check; sigh; see #275284. */
sewardjd88797f2011-08-17 21:25:50 +0000714MEMMOVE(VG_Z_LIBC_SONAME, memcpyZAGLIBCZu2Zd2Zd5) /* memcpy@GLIBC_2.2.5 */
715MEMCPY(VG_Z_LIBC_SONAME, memcpyZAZAGLIBCZu2Zd14) /* memcpy@@GLIBC_2.14 */
716MEMCPY(VG_Z_LD_SO_1, memcpy) /* ld.so.1 */
717MEMCPY(VG_Z_LD64_SO_1, memcpy) /* ld64.so.1 */
njnf76d27a2009-05-28 01:53:07 +0000718#elif defined(VGO_darwin)
sewardjd88797f2011-08-17 21:25:50 +0000719MEMCPY(VG_Z_LIBC_SONAME, memcpy)
720MEMCPY(VG_Z_DYLD, memcpy)
njnb4cfbc42009-05-04 04:20:02 +0000721#endif
sewardjf0b34322007-01-16 21:42:28 +0000722/* icc9 blats these around all over the place. Not only in the main
723 executable but various .so's. They are highly tuned and read
724 memory beyond the source boundary (although work correctly and
725 never go across page boundaries), so give errors when run natively,
726 at least for misaligned source arg. Just intercepting in the exe
727 only until we understand more about the problem. See
728 http://bugs.kde.org/show_bug.cgi?id=139776
729 */
sewardjd88797f2011-08-17 21:25:50 +0000730MEMCPY(NONE, ZuintelZufastZumemcpy)
sewardj31b9ce12006-10-17 01:27:13 +0000731
njn16eeb4e2005-06-16 03:56:58 +0000732
733#define MEMCMP(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000734 int VG_REPLACE_FUNCTION_EZU(2019,soname,fnname) \
sewardj0ec07f32006-01-12 12:32:32 +0000735 ( const void *s1V, const void *s2V, SizeT n ); \
sewardjbd2cff22011-08-16 21:45:28 +0000736 int VG_REPLACE_FUNCTION_EZU(2019,soname,fnname) \
737 ( const void *s1V, const void *s2V, SizeT n ) \
njn16eeb4e2005-06-16 03:56:58 +0000738 { \
739 int res; \
740 unsigned char a0; \
741 unsigned char b0; \
742 unsigned char* s1 = (unsigned char*)s1V; \
743 unsigned char* s2 = (unsigned char*)s2V; \
sewardjb6c04032007-11-13 20:52:29 +0000744 \
njn16eeb4e2005-06-16 03:56:58 +0000745 while (n != 0) { \
746 a0 = s1[0]; \
747 b0 = s2[0]; \
748 s1 += 1; \
749 s2 += 1; \
750 res = ((int)a0) - ((int)b0); \
751 if (res != 0) \
752 return res; \
753 n -= 1; \
754 } \
755 return 0; \
756 }
757
njne6154662009-02-10 04:23:41 +0000758MEMCMP(VG_Z_LIBC_SONAME, memcmp)
759MEMCMP(VG_Z_LIBC_SONAME, bcmp)
njnb4cfbc42009-05-04 04:20:02 +0000760#if defined(VGO_linux)
njne6154662009-02-10 04:23:41 +0000761MEMCMP(VG_Z_LD_SO_1, bcmp)
njnf76d27a2009-05-28 01:53:07 +0000762#elif defined(VGO_darwin)
763MEMCMP(VG_Z_DYLD, memcmp)
764MEMCMP(VG_Z_DYLD, bcmp)
njnb4cfbc42009-05-04 04:20:02 +0000765#endif
njn3e884182003-04-15 13:03:23 +0000766
jseward0845ef82003-12-22 22:31:27 +0000767
768/* Copy SRC to DEST, returning the address of the terminating '\0' in
769 DEST. (minor variant of strcpy) */
njn16eeb4e2005-06-16 03:56:58 +0000770#define STPCPY(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000771 char* VG_REPLACE_FUNCTION_EZU(2020,soname,fnname) \
772 ( char* dst, const char* src ); \
773 char* VG_REPLACE_FUNCTION_EZU(2020,soname,fnname) \
774 ( char* dst, const char* src ) \
njn16eeb4e2005-06-16 03:56:58 +0000775 { \
776 const Char* src_orig = src; \
777 Char* dst_orig = dst; \
sewardjb6c04032007-11-13 20:52:29 +0000778 \
njn16eeb4e2005-06-16 03:56:58 +0000779 while (*src) *dst++ = *src++; \
780 *dst = 0; \
sewardjb6c04032007-11-13 20:52:29 +0000781 \
njn16eeb4e2005-06-16 03:56:58 +0000782 /* This checks for overlap after copying, unavoidable without */ \
783 /* pre-counting length... should be ok */ \
784 if (is_overlap(dst_orig, \
785 src_orig, \
786 (Addr)dst-(Addr)dst_orig+1, \
787 (Addr)src-(Addr)src_orig+1)) \
njn718d3b12006-12-16 00:54:12 +0000788 RECORD_OVERLAP_ERROR("stpcpy", dst_orig, src_orig, 0); \
sewardjb6c04032007-11-13 20:52:29 +0000789 \
njn16eeb4e2005-06-16 03:56:58 +0000790 return dst; \
sewardj44e495f2005-05-12 17:58:28 +0000791 }
njn16eeb4e2005-06-16 03:56:58 +0000792
njne6154662009-02-10 04:23:41 +0000793STPCPY(VG_Z_LIBC_SONAME, stpcpy)
njnb4cfbc42009-05-04 04:20:02 +0000794#if defined(VGO_linux)
tomd2645142009-10-29 09:27:11 +0000795STPCPY(VG_Z_LIBC_SONAME, __GI_stpcpy)
njne6154662009-02-10 04:23:41 +0000796STPCPY(VG_Z_LD_LINUX_SO_2, stpcpy)
797STPCPY(VG_Z_LD_LINUX_X86_64_SO_2, stpcpy)
njnf76d27a2009-05-28 01:53:07 +0000798#elif defined(VGO_darwin)
799STPCPY(VG_Z_DYLD, stpcpy)
njnb4cfbc42009-05-04 04:20:02 +0000800#endif
801
njn16eeb4e2005-06-16 03:56:58 +0000802
803#define MEMSET(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000804 void* VG_REPLACE_FUNCTION_EZU(2021,soname,fnname) \
805 (void *s, Int c, SizeT n); \
806 void* VG_REPLACE_FUNCTION_EZU(2021,soname,fnname) \
807 (void *s, Int c, SizeT n) \
njn16eeb4e2005-06-16 03:56:58 +0000808 { \
sewardj7b4e00b2010-08-24 09:05:52 +0000809 Addr a = (Addr)s; \
810 UInt c4 = (c & 0xFF); \
811 c4 = (c4 << 8) | c4; \
812 c4 = (c4 << 16) | c4; \
813 while ((a & 3) != 0 && n >= 1) \
814 { *(UChar*)a = (UChar)c; a += 1; n -= 1; } \
815 while (n >= 4) \
816 { *(UInt*)a = c4; a += 4; n -= 4; } \
817 while (n >= 1) \
818 { *(UChar*)a = (UChar)c; a += 1; n -= 1; } \
njn16eeb4e2005-06-16 03:56:58 +0000819 return s; \
sewardj44e495f2005-05-12 17:58:28 +0000820 }
njn16eeb4e2005-06-16 03:56:58 +0000821
njne6154662009-02-10 04:23:41 +0000822MEMSET(VG_Z_LIBC_SONAME, memset)
njnf76d27a2009-05-28 01:53:07 +0000823#if defined(VGO_darwin)
824MEMSET(VG_Z_DYLD, memset)
825#endif
njn16eeb4e2005-06-16 03:56:58 +0000826
827
sewardjbd2cff22011-08-16 21:45:28 +0000828/* memmove -- use the MEMMOVE defn which also serves for memcpy. */
njne6154662009-02-10 04:23:41 +0000829MEMMOVE(VG_Z_LIBC_SONAME, memmove)
njnf76d27a2009-05-28 01:53:07 +0000830#if defined(VGO_darwin)
831MEMMOVE(VG_Z_DYLD, memmove)
832#endif
833
834
835#define BCOPY(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000836 void VG_REPLACE_FUNCTION_EZU(2023,soname,fnname) \
njnf76d27a2009-05-28 01:53:07 +0000837 (const void *srcV, void *dstV, SizeT n); \
sewardjbd2cff22011-08-16 21:45:28 +0000838 void VG_REPLACE_FUNCTION_EZU(2023,soname,fnname) \
njnf76d27a2009-05-28 01:53:07 +0000839 (const void *srcV, void *dstV, SizeT n) \
840 { \
841 SizeT i; \
842 Char* dst = (Char*)dstV; \
843 Char* src = (Char*)srcV; \
844 if (dst < src) { \
845 for (i = 0; i < n; i++) \
846 dst[i] = src[i]; \
847 } \
848 else \
849 if (dst > src) { \
850 for (i = 0; i < n; i++) \
851 dst[n-i-1] = src[n-i-1]; \
852 } \
853 }
854
855#if defined(VGO_darwin)
856BCOPY(VG_Z_LIBC_SONAME, bcopy)
857BCOPY(VG_Z_DYLD, bcopy)
858#endif
sewardj44e495f2005-05-12 17:58:28 +0000859
jseward0845ef82003-12-22 22:31:27 +0000860
sewardj24cb2172007-02-23 09:03:26 +0000861/* glibc 2.5 variant of memmove which checks the dest is big enough.
862 There is no specific part of glibc that this is copied from. */
863#define GLIBC25___MEMMOVE_CHK(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000864 void* VG_REPLACE_FUNCTION_EZU(2024,soname,fnname) \
sewardj24cb2172007-02-23 09:03:26 +0000865 (void *dstV, const void *srcV, SizeT n, SizeT destlen); \
sewardjbd2cff22011-08-16 21:45:28 +0000866 void* VG_REPLACE_FUNCTION_EZU(2024,soname,fnname) \
sewardj24cb2172007-02-23 09:03:26 +0000867 (void *dstV, const void *srcV, SizeT n, SizeT destlen) \
868 { \
sewardj24cb2172007-02-23 09:03:26 +0000869 SizeT i; \
870 Char* dst = (Char*)dstV; \
871 Char* src = (Char*)srcV; \
872 if (destlen < n) \
873 goto badness; \
874 if (dst < src) { \
875 for (i = 0; i < n; i++) \
876 dst[i] = src[i]; \
877 } \
878 else \
879 if (dst > src) { \
880 for (i = 0; i < n; i++) \
881 dst[n-i-1] = src[n-i-1]; \
882 } \
883 return dst; \
884 badness: \
885 VALGRIND_PRINTF_BACKTRACE( \
886 "*** memmove_chk: buffer overflow detected ***: " \
njnd55f0d92009-08-03 01:38:56 +0000887 "program terminated\n"); \
sewardj126e82d2011-07-12 13:33:00 +0000888 my_exit(127); \
sewardjc271ec82007-02-27 22:36:14 +0000889 /*NOTREACHED*/ \
890 return NULL; \
sewardj24cb2172007-02-23 09:03:26 +0000891 }
892
njne6154662009-02-10 04:23:41 +0000893GLIBC25___MEMMOVE_CHK(VG_Z_LIBC_SONAME, __memmove_chk)
sewardj24cb2172007-02-23 09:03:26 +0000894
895
sewardj4e9a4b62004-11-23 00:20:17 +0000896/* Find the first occurrence of C in S or the final NUL byte. */
njn16eeb4e2005-06-16 03:56:58 +0000897#define GLIBC232_STRCHRNUL(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000898 char* VG_REPLACE_FUNCTION_EZU(2025,soname,fnname) \
899 (const char* s, int c_in); \
900 char* VG_REPLACE_FUNCTION_EZU(2025,soname,fnname) \
901 (const char* s, int c_in) \
njn16eeb4e2005-06-16 03:56:58 +0000902 { \
903 unsigned char c = (unsigned char) c_in; \
904 unsigned char* char_ptr = (unsigned char *)s; \
905 while (1) { \
906 if (*char_ptr == 0) return char_ptr; \
907 if (*char_ptr == c) return char_ptr; \
908 char_ptr++; \
909 } \
sewardj4e9a4b62004-11-23 00:20:17 +0000910 }
njn16eeb4e2005-06-16 03:56:58 +0000911
njne6154662009-02-10 04:23:41 +0000912GLIBC232_STRCHRNUL(VG_Z_LIBC_SONAME, strchrnul)
sewardj4e9a4b62004-11-23 00:20:17 +0000913
914
915/* Find the first occurrence of C in S. */
njn16eeb4e2005-06-16 03:56:58 +0000916#define GLIBC232_RAWMEMCHR(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000917 char* VG_REPLACE_FUNCTION_EZU(2026,soname,fnname) \
918 (const char* s, int c_in); \
919 char* VG_REPLACE_FUNCTION_EZU(2026,soname,fnname) \
920 (const char* s, int c_in) \
njn16eeb4e2005-06-16 03:56:58 +0000921 { \
922 unsigned char c = (unsigned char) c_in; \
923 unsigned char* char_ptr = (unsigned char *)s; \
924 while (1) { \
925 if (*char_ptr == c) return char_ptr; \
926 char_ptr++; \
927 } \
sewardj4e9a4b62004-11-23 00:20:17 +0000928 }
njn16eeb4e2005-06-16 03:56:58 +0000929
njne6154662009-02-10 04:23:41 +0000930GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, rawmemchr)
tomd2645142009-10-29 09:27:11 +0000931#if defined (VGO_linux)
932GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, __GI___rawmemchr)
933#endif
sewardj4e9a4b62004-11-23 00:20:17 +0000934
sewardjdc5d8322007-01-28 06:32:01 +0000935/* glibc variant of strcpy that checks the dest is big enough.
936 Copied from glibc-2.5/debug/test-strcpy_chk.c. */
sewardj620e5262006-12-31 00:22:30 +0000937#define GLIBC25___STRCPY_CHK(soname,fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000938 char* VG_REPLACE_FUNCTION_EZU(2027,soname,fnname) \
939 (char* dst, const char* src, SizeT len); \
940 char* VG_REPLACE_FUNCTION_EZU(2027,soname,fnname) \
941 (char* dst, const char* src, SizeT len) \
sewardj620e5262006-12-31 00:22:30 +0000942 { \
sewardj620e5262006-12-31 00:22:30 +0000943 char* ret = dst; \
944 if (! len) \
945 goto badness; \
946 while ((*dst++ = *src++) != '\0') \
947 if (--len == 0) \
948 goto badness; \
949 return ret; \
950 badness: \
951 VALGRIND_PRINTF_BACKTRACE( \
sewardj24cb2172007-02-23 09:03:26 +0000952 "*** strcpy_chk: buffer overflow detected ***: " \
njnd55f0d92009-08-03 01:38:56 +0000953 "program terminated\n"); \
sewardj126e82d2011-07-12 13:33:00 +0000954 my_exit(127); \
sewardj620e5262006-12-31 00:22:30 +0000955 /*NOTREACHED*/ \
956 return NULL; \
957 }
958
njne6154662009-02-10 04:23:41 +0000959GLIBC25___STRCPY_CHK(VG_Z_LIBC_SONAME, __strcpy_chk)
sewardj620e5262006-12-31 00:22:30 +0000960
961
sewardjdc5d8322007-01-28 06:32:01 +0000962/* glibc variant of stpcpy that checks the dest is big enough.
963 Copied from glibc-2.5/debug/test-stpcpy_chk.c. */
sewardjb8d03852007-01-27 00:49:44 +0000964#define GLIBC25___STPCPY_CHK(soname,fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000965 char* VG_REPLACE_FUNCTION_EZU(2028,soname,fnname) \
966 (char* dst, const char* src, SizeT len); \
967 char* VG_REPLACE_FUNCTION_EZU(2028,soname,fnname) \
968 (char* dst, const char* src, SizeT len) \
sewardjb8d03852007-01-27 00:49:44 +0000969 { \
sewardjdc5d8322007-01-28 06:32:01 +0000970 if (! len) \
971 goto badness; \
972 while ((*dst++ = *src++) != '\0') \
973 if (--len == 0) \
sewardjb8d03852007-01-27 00:49:44 +0000974 goto badness; \
sewardjb8d03852007-01-27 00:49:44 +0000975 return dst - 1; \
976 badness: \
977 VALGRIND_PRINTF_BACKTRACE( \
sewardj24cb2172007-02-23 09:03:26 +0000978 "*** stpcpy_chk: buffer overflow detected ***: " \
njnd55f0d92009-08-03 01:38:56 +0000979 "program terminated\n"); \
sewardj126e82d2011-07-12 13:33:00 +0000980 my_exit(127); \
sewardjb8d03852007-01-27 00:49:44 +0000981 /*NOTREACHED*/ \
982 return NULL; \
983 }
984
njne6154662009-02-10 04:23:41 +0000985GLIBC25___STPCPY_CHK(VG_Z_LIBC_SONAME, __stpcpy_chk)
sewardjb8d03852007-01-27 00:49:44 +0000986
987
sewardj841b72d2006-12-31 18:55:56 +0000988/* mempcpy */
989#define GLIBC25_MEMPCPY(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +0000990 void* VG_REPLACE_FUNCTION_EZU(2029,soname,fnname) \
sewardj841b72d2006-12-31 18:55:56 +0000991 ( void *dst, const void *src, SizeT len ); \
sewardjbd2cff22011-08-16 21:45:28 +0000992 void* VG_REPLACE_FUNCTION_EZU(2029,soname,fnname) \
sewardj841b72d2006-12-31 18:55:56 +0000993 ( void *dst, const void *src, SizeT len ) \
994 { \
995 register char *d; \
996 register char *s; \
997 SizeT len_saved = len; \
998 \
999 if (len == 0) \
1000 return dst; \
1001 \
1002 if (is_overlap(dst, src, len, len)) \
1003 RECORD_OVERLAP_ERROR("mempcpy", dst, src, len); \
1004 \
1005 if ( dst > src ) { \
1006 d = (char *)dst + len - 1; \
1007 s = (char *)src + len - 1; \
1008 while ( len-- ) { \
1009 *d-- = *s--; \
1010 } \
1011 } else if ( dst < src ) { \
1012 d = (char *)dst; \
1013 s = (char *)src; \
1014 while ( len-- ) { \
1015 *d++ = *s++; \
1016 } \
1017 } \
1018 return (void*)( ((char*)dst) + len_saved ); \
1019 }
1020
njne6154662009-02-10 04:23:41 +00001021GLIBC25_MEMPCPY(VG_Z_LIBC_SONAME, mempcpy)
njnb4cfbc42009-05-04 04:20:02 +00001022#if defined(VGO_linux)
njne6154662009-02-10 04:23:41 +00001023GLIBC25_MEMPCPY(VG_Z_LD_SO_1, mempcpy) /* ld.so.1 */
njnb4cfbc42009-05-04 04:20:02 +00001024#endif
sewardj841b72d2006-12-31 18:55:56 +00001025
1026
sewardjb6c04032007-11-13 20:52:29 +00001027#define GLIBC26___MEMCPY_CHK(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +00001028 void* VG_REPLACE_FUNCTION_EZU(2030,soname,fnname) \
sewardjb6c04032007-11-13 20:52:29 +00001029 (void* dst, const void* src, SizeT len, SizeT dstlen ); \
sewardjbd2cff22011-08-16 21:45:28 +00001030 void* VG_REPLACE_FUNCTION_EZU(2030,soname,fnname) \
sewardjb6c04032007-11-13 20:52:29 +00001031 (void* dst, const void* src, SizeT len, SizeT dstlen ) \
1032 { \
sewardjb6c04032007-11-13 20:52:29 +00001033 register char *d; \
1034 register char *s; \
1035 \
1036 if (dstlen < len) goto badness; \
1037 \
1038 if (len == 0) \
1039 return dst; \
1040 \
1041 if (is_overlap(dst, src, len, len)) \
1042 RECORD_OVERLAP_ERROR("memcpy_chk", dst, src, len); \
1043 \
1044 if ( dst > src ) { \
1045 d = (char *)dst + len - 1; \
1046 s = (char *)src + len - 1; \
1047 while ( len-- ) { \
1048 *d-- = *s--; \
1049 } \
1050 } else if ( dst < src ) { \
1051 d = (char *)dst; \
1052 s = (char *)src; \
1053 while ( len-- ) { \
1054 *d++ = *s++; \
1055 } \
1056 } \
1057 return dst; \
1058 badness: \
1059 VALGRIND_PRINTF_BACKTRACE( \
1060 "*** memcpy_chk: buffer overflow detected ***: " \
njnd55f0d92009-08-03 01:38:56 +00001061 "program terminated\n"); \
sewardj126e82d2011-07-12 13:33:00 +00001062 my_exit(127); \
sewardjb6c04032007-11-13 20:52:29 +00001063 /*NOTREACHED*/ \
1064 return NULL; \
1065 }
1066
njne6154662009-02-10 04:23:41 +00001067GLIBC26___MEMCPY_CHK(VG_Z_LIBC_SONAME, __memcpy_chk)
sewardjb6c04032007-11-13 20:52:29 +00001068
1069
sewardja77687c2010-08-19 13:22:34 +00001070#define STRSTR(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +00001071 void* VG_REPLACE_FUNCTION_EZU(2031,soname,fnname) \
sewardja77687c2010-08-19 13:22:34 +00001072 (void* haystack, void* needle); \
sewardjbd2cff22011-08-16 21:45:28 +00001073 void* VG_REPLACE_FUNCTION_EZU(2031,soname,fnname) \
sewardja77687c2010-08-19 13:22:34 +00001074 (void* haystack, void* needle) \
1075 { \
1076 UChar* h = (UChar*)haystack; \
1077 UChar* n = (UChar*)needle; \
1078 \
1079 /* find the length of n, not including terminating zero */ \
1080 UWord nlen = 0; \
1081 while (n[nlen]) nlen++; \
1082 \
1083 /* if n is the empty string, match immediately. */ \
1084 if (nlen == 0) return h; \
1085 \
1086 /* assert(nlen >= 1); */ \
1087 UChar n0 = n[0]; \
1088 \
1089 while (1) { \
1090 UChar hh = *h; \
1091 if (hh == 0) return NULL; \
1092 if (hh != n0) { h++; continue; } \
1093 \
1094 UWord i; \
1095 for (i = 0; i < nlen; i++) { \
1096 if (n[i] != h[i]) \
1097 break; \
1098 } \
1099 /* assert(i >= 0 && i <= nlen); */ \
1100 if (i == nlen) \
1101 return h; \
1102 \
1103 h++; \
1104 } \
1105 }
1106
1107#if defined(VGO_linux)
1108STRSTR(VG_Z_LIBC_SONAME, strstr)
1109#endif
1110
1111
1112#define STRPBRK(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +00001113 void* VG_REPLACE_FUNCTION_EZU(2032,soname,fnname) \
sewardja77687c2010-08-19 13:22:34 +00001114 (void* sV, void* acceptV); \
sewardjbd2cff22011-08-16 21:45:28 +00001115 void* VG_REPLACE_FUNCTION_EZU(2032,soname,fnname) \
sewardja77687c2010-08-19 13:22:34 +00001116 (void* sV, void* acceptV) \
1117 { \
1118 UChar* s = (UChar*)sV; \
1119 UChar* accept = (UChar*)acceptV; \
1120 \
1121 /* find the length of 'accept', not including terminating zero */ \
1122 UWord nacc = 0; \
1123 while (accept[nacc]) nacc++; \
1124 \
1125 /* if n is the empty string, fail immediately. */ \
1126 if (nacc == 0) return NULL; \
1127 \
1128 /* assert(nacc >= 1); */ \
1129 while (1) { \
1130 UWord i; \
1131 UChar sc = *s; \
1132 if (sc == 0) \
1133 break; \
1134 for (i = 0; i < nacc; i++) { \
1135 if (sc == accept[i]) \
1136 return s; \
1137 } \
1138 s++; \
1139 } \
1140 \
1141 return NULL; \
1142 }
1143
1144#if defined(VGO_linux)
1145STRPBRK(VG_Z_LIBC_SONAME, strpbrk)
1146#endif
1147
1148
1149#define STRCSPN(soname, fnname) \
sewardjbd2cff22011-08-16 21:45:28 +00001150 SizeT VG_REPLACE_FUNCTION_EZU(2033,soname,fnname) \
sewardja77687c2010-08-19 13:22:34 +00001151 (void* sV, void* rejectV); \
sewardjbd2cff22011-08-16 21:45:28 +00001152 SizeT VG_REPLACE_FUNCTION_EZU(2033,soname,fnname) \
sewardja77687c2010-08-19 13:22:34 +00001153 (void* sV, void* rejectV) \
1154 { \
1155 UChar* s = (UChar*)sV; \
1156 UChar* reject = (UChar*)rejectV; \
1157 \
1158 /* find the length of 'reject', not including terminating zero */ \
1159 UWord nrej = 0; \
1160 while (reject[nrej]) nrej++; \
1161 \
1162 UWord len = 0; \
1163 while (1) { \
1164 UWord i; \
1165 UChar sc = *s; \
1166 if (sc == 0) \
1167 break; \
1168 for (i = 0; i < nrej; i++) { \
1169 if (sc == reject[i]) \
1170 break; \
1171 } \
1172 /* assert(i >= 0 && i <= nrej); */ \
1173 if (i < nrej) \
1174 break; \
1175 s++; \
1176 len++; \
1177 } \
1178 \
1179 return len; \
1180 }
1181
1182#if defined(VGO_linux)
1183STRCSPN(VG_Z_LIBC_SONAME, strcspn)
1184#endif
1185
1186
sewardjbd2cff22011-08-16 21:45:28 +00001187#define STRSPN(soname, fnname) \
1188 SizeT VG_REPLACE_FUNCTION_EZU(2034,soname,fnname) \
1189 (void* sV, void* acceptV); \
1190 SizeT VG_REPLACE_FUNCTION_EZU(2034,soname,fnname) \
1191 (void* sV, void* acceptV) \
1192 { \
1193 UChar* s = (UChar*)sV; \
1194 UChar* accept = (UChar*)acceptV; \
1195 \
1196 /* find the length of 'accept', not including terminating zero */ \
1197 UWord nacc = 0; \
1198 while (accept[nacc]) nacc++; \
1199 if (nacc == 0) return 0; \
1200 \
1201 UWord len = 0; \
1202 while (1) { \
1203 UWord i; \
1204 UChar sc = *s; \
1205 if (sc == 0) \
1206 break; \
1207 for (i = 0; i < nacc; i++) { \
1208 if (sc == accept[i]) \
1209 break; \
1210 } \
1211 /* assert(i >= 0 && i <= nacc); */ \
1212 if (i == nacc) \
1213 break; \
1214 s++; \
1215 len++; \
1216 } \
1217 \
1218 return len; \
1219 }
1220
1221#if defined(VGO_linux)
1222STRSPN(VG_Z_LIBC_SONAME, strspn)
1223#endif
sewardjba189352010-08-20 18:24:16 +00001224
1225
sewardj31b9ce12006-10-17 01:27:13 +00001226/*------------------------------------------------------------*/
dirk09beb9e2007-04-19 09:47:32 +00001227/*--- Improve definedness checking of process environment ---*/
1228/*------------------------------------------------------------*/
1229
sewardjddc00dd2007-11-27 11:42:47 +00001230#if defined(VGO_linux)
1231
sewardjbd2cff22011-08-16 21:45:28 +00001232/* If these wind up getting generated via a macro, so that multiple
1233 versions of each function exist (as above), use the _EZU variants
1234 to assign equivalance class tags. */
1235
dirk09beb9e2007-04-19 09:47:32 +00001236/* putenv */
njne6154662009-02-10 04:23:41 +00001237int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, putenv) (char* string);
1238int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, putenv) (char* string)
dirk09beb9e2007-04-19 09:47:32 +00001239{
1240 OrigFn fn;
1241 Word result;
1242 const char* p = string;
1243 VALGRIND_GET_ORIG_FN(fn);
1244 /* Now by walking over the string we magically produce
1245 traces when hitting undefined memory. */
1246 if (p)
1247 while (*p++)
1248 ;
1249 CALL_FN_W_W(result, fn, string);
1250 return result;
1251}
1252
1253/* unsetenv */
njne6154662009-02-10 04:23:41 +00001254int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, unsetenv) (const char* name);
1255int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, unsetenv) (const char* name)
dirk09beb9e2007-04-19 09:47:32 +00001256{
1257 OrigFn fn;
1258 Word result;
1259 const char* p = name;
1260 VALGRIND_GET_ORIG_FN(fn);
1261 /* Now by walking over the string we magically produce
1262 traces when hitting undefined memory. */
1263 if (p)
1264 while (*p++)
1265 ;
1266 CALL_FN_W_W(result, fn, name);
1267 return result;
1268}
1269
1270/* setenv */
njne6154662009-02-10 04:23:41 +00001271int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, setenv)
dirk09beb9e2007-04-19 09:47:32 +00001272 (const char* name, const char* value, int overwrite);
njne6154662009-02-10 04:23:41 +00001273int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, setenv)
dirk09beb9e2007-04-19 09:47:32 +00001274 (const char* name, const char* value, int overwrite)
1275{
1276 OrigFn fn;
1277 Word result;
1278 const char* p;
1279 VALGRIND_GET_ORIG_FN(fn);
1280 /* Now by walking over the string we magically produce
1281 traces when hitting undefined memory. */
1282 if (name)
1283 for (p = name; *p; p++)
1284 ;
1285 if (value)
1286 for (p = value; *p; p++)
1287 ;
1288 VALGRIND_CHECK_VALUE_IS_DEFINED (overwrite);
1289 CALL_FN_W_WWW(result, fn, name, value, overwrite);
1290 return result;
1291}
1292
sewardjddc00dd2007-11-27 11:42:47 +00001293#endif /* defined(VGO_linux) */
1294
njn3e884182003-04-15 13:03:23 +00001295/*--------------------------------------------------------------------*/
njn46275862005-03-24 04:00:03 +00001296/*--- end ---*/
njn3e884182003-04-15 13:03:23 +00001297/*--------------------------------------------------------------------*/