Command line help - demangling isn't just for C++
[valgrind.git] / coregrind / m_replacemalloc / vg_replace_malloc.c
blobaff2d27b3c1cc45ea3902c132e6efdff7fa597b9
2 /*--------------------------------------------------------------------*/
3 /*--- Replacements for malloc() et al, which run on the simulated ---*/
4 /*--- CPU. vg_replace_malloc.c ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
11 Copyright (C) 2000-2017 Julian Seward
12 jseward@acm.org
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
30 /* ---------------------------------------------------------------------
31 ALL THE CODE IN THIS FILE RUNS ON THE SIMULATED CPU.
33 These functions are drop-in replacements for malloc() and friends.
34 They have global scope, but are not intended to be called directly.
35 See pub_core_redir.h for the gory details.
37 This file can be linked into the vg_preload_<tool>.so file for any tool
38 that wishes to know about calls to malloc(). The tool must define all
39 the functions that will be called via 'info'.
41 It is called vg_replace_malloc.c because this filename appears in stack
42 traces, so we want the name to be (hopefully!) meaningful to users.
44 IMPORTANT: this file must not contain any floating point code, nor
45 any integer division. This is because on ARM these can cause calls
46 to helper functions, which will be unresolved within this .so.
47 Although it is usually the case that the client's ld.so instance
48 can bind them at runtime to the relevant functions in the client
49 executable, there is no guarantee of this; and so the client may
50 die via a runtime link failure. Hence the only safe approach is to
51 avoid such function calls in the first place. See "#define CALLOC"
52 below for a specific example.
54 A useful command is
55 for f in `find . -name "*preload*.so*"` ; \
56 do nm -A $f | grep " U " ; \
57 done
59 to see all the undefined symbols in all the preload shared objects.
60 ------------------------------------------------------------------ */
62 #include "pub_core_basics.h"
63 #include "pub_core_vki.h" // VKI_EINVAL, VKI_ENOMEM
64 #include "pub_core_clreq.h" // for VALGRIND_INTERNAL_PRINTF,
65 // VALGRIND_NON_SIMD_CALL[12]
66 #include "pub_core_debuginfo.h" // needed for pub_core_redir.h :(
67 #include "pub_core_mallocfree.h" // for VG_MIN_MALLOC_SZB, VG_AR_CLIENT
68 #include "pub_core_redir.h" // for VG_REPLACE_FUNCTION_*
69 #include "pub_core_replacemalloc.h"
70 #include "../../memcheck/memcheck.h"
72 #define VG_ALIGN_ROUNDUP(size, alignment) (((size) + (alignment) - 1) & ~((alignment) - 1))
74 #define VERIFY_ALIGNMENT(aligned_alloc_info) \
75 VALGRIND_DO_CLIENT_REQUEST_STMT(_VG_USERREQ__MEMCHECK_VERIFY_ALIGNMENT, \
76 aligned_alloc_info, 0, 0, 0, 0)
78 /* Assignment of behavioural equivalence class tags: 1NNNP is intended
79 to be reserved for the Valgrind core. Current usage:
81 10010 ALLOC_or_NULL
82 10020 ZONEALLOC_or_NULL
83 10030 ALLOC_or_BOMB
84 10040 ZONEFREE
85 10050 FREE
86 10051 FREE_SIZED
87 10052 FREE_ALIGNED_SIZED
88 10060 ZONECALLOC
89 10070 CALLOC
90 10080 ZONEREALLOC
91 10090 REALLOC
92 10091 REALLOCF
93 10092 REALLOCARRAY
94 10100 ZONEMEMALIGN
95 10110 MEMALIGN
96 10120 VALLOC
97 10130 ZONEVALLOC
98 10140 MALLOPT
99 10150 MALLOC_TRIM
100 10160 POSIX_MEMALIGN
101 10170 ALIGNED_ALL0C
102 10180 MALLOC_USABLE_SIZE
103 10190 PANIC
104 10200 MALLOC_STATS
105 10210 MALLINFO
106 10220 DEFAULT_ZONE
107 10230 CREATE_ZONE
108 10240 ZONE_FROM_PTR
109 10250 ZONE_CHECK
110 10260 ZONE_REGISTER
111 10270 ZONE_UNREGISTER
112 10280 ZONE_SET_NAME
113 10290 ZONE_GET_NAME
116 /* 2 Apr 05: the Portland Group compiler, which uses cfront/ARM style
117 mangling, could be supported properly by the redirects in this
118 module. Except we can't because it doesn't put its allocation
119 functions in libpgc.so but instead hardwires them into the
120 compilation unit holding main(), which makes them impossible to
121 intercept directly. Fortunately those fns seem to route everything
122 through to malloc/free.
124 mid-06: could be improved, since we can now intercept in the main
125 executable too.
127 2023-03:
129 There seem to be an ever increasing number of C++ new and delete
130 oveloads.
133 https://en.cppreference.com/w/cpp/memory/new/operator_new
134 https://en.cppreference.com/w/cpp/memory/new/operator_delete
136 We need to redirect the "replaceable" versions.
138 Anything "user-defined" or "class-specific" we can't know
139 about and the user needs to use memory pool annotation.
141 "non-allocating placement" as the name implies does not
142 allocate. Placement deletes are no-ops.
147 /* Call here to exit if we can't continue. On Android we can't call
148 _exit for some reason, so we have to blunt-instrument it. */
149 __attribute__ ((__noreturn__))
150 static inline void my_exit ( int x )
152 # if defined(VGPV_arm_linux_android) || defined(VGPV_mips32_linux_android) \
153 || defined(VGPV_arm64_linux_android)
154 __asm__ __volatile__(".word 0xFFFFFFFF");
155 while (1) {}
156 # elif defined(VGPV_x86_linux_android)
157 __asm__ __volatile__("ud2");
158 while (1) {}
159 # else
160 extern __attribute__ ((__noreturn__)) void _exit(int status);
161 _exit(x);
162 # endif
165 /* Same problem with getpagesize. */
166 static inline int my_getpagesize ( void )
168 # if defined(VGPV_arm_linux_android) \
169 || defined(VGPV_x86_linux_android) \
170 || defined(VGPV_mips32_linux_android) \
171 || defined(VGPV_arm64_linux_android)
172 return 4096; /* kludge - link failure on Android, for some reason */
173 # else
174 extern int getpagesize (void);
175 return getpagesize();
176 # endif
180 /* Compute the high word of the double-length unsigned product of U
181 and V. This is for calloc argument overflow checking; see comments
182 below. Algorithm as described in Hacker's Delight, chapter 8. */
183 static UWord umulHW ( UWord u, UWord v )
185 UWord u0, v0, w0, rHi;
186 UWord u1, v1, w1,w2,t;
187 UWord halfMask = sizeof(UWord)==4 ? (UWord)0xFFFF
188 : (UWord)0xFFFFFFFFULL;
189 UWord halfShift = sizeof(UWord)==4 ? 16 : 32;
190 u0 = u & halfMask;
191 u1 = u >> halfShift;
192 v0 = v & halfMask;
193 v1 = v >> halfShift;
194 w0 = u0 * v0;
195 t = u1 * v0 + (w0 >> halfShift);
196 w1 = t & halfMask;
197 w2 = t >> halfShift;
198 w1 = u0 * v1 + w1;
199 rHi = u1 * v1 + w2 + (w1 >> halfShift);
200 return rHi;
204 /*------------------------------------------------------------*/
205 /*--- Replacing malloc() et al ---*/
206 /*------------------------------------------------------------*/
208 /* This struct is initially empty. Before the first use of any of
209 these functions, we make a client request which fills in the
210 fields.
212 static struct vg_mallocfunc_info info;
213 static int init_done;
214 #define DO_INIT if (UNLIKELY(!init_done)) init()
216 /* Startup hook - called as init section */
217 __attribute__((constructor))
218 static void init(void);
220 #define MALLOC_TRACE(format, args...) \
221 if (info.clo_trace_malloc) { \
222 VALGRIND_INTERNAL_PRINTF(format, ## args ); }
224 // @todo PJF this mechanism doesn't work for MUSL C
225 // not sure why
226 // source here https://elixir.bootlin.com/musl/latest/source/src/errno/__errno_location.c#L4
228 /* Tries to set ERRNO to ENOMEM/EINVAL if possible. */
229 #if defined(VGO_linux)
230 extern int *__errno_location (void) __attribute__((weak));
231 #define SET_ERRNO_ENOMEM if (__errno_location) \
232 (*__errno_location ()) = VKI_ENOMEM;
233 #define SET_ERRNO_EINVAL {}
234 #elif defined(VGO_freebsd)
235 extern int *__error (void) __attribute__((weak));
236 #define SET_ERRNO_ENOMEM if (__error) \
237 (*__error ()) = VKI_ENOMEM;
238 #define SET_ERRNO_EINVAL if (__error) \
239 (*__error ()) = VKI_EINVAL;
240 #elif defined(VGO_solaris)
241 extern int *___errno (void) __attribute__((weak));
242 #define SET_ERRNO_ENOMEM if (___errno) \
243 (*___errno ()) = VKI_ENOMEM;
244 #define SET_ERRNO_EINVAL if (___errno) \
245 (*___errno ()) = VKI_EINVAL;
246 #elif defined(VGO_darwin)
247 extern int * __error(void) __attribute__((weak));
248 #define SET_ERRNO_ENOMEM if (__error) \
249 (*__error ()) = VKI_ENOMEM;
250 #define SET_ERRNO_EINVAL if (__error) \
251 (*__error ()) = VKI_EINVAL;
253 #else
254 #define SET_ERRNO_ENOMEM {}
255 #define SET_ERRNO_EINVAL {}
256 #endif
258 /* Below are new versions of malloc, __builtin_new, free,
259 __builtin_delete, calloc, realloc, memalign, and friends.
261 None of these functions are called directly - they are not meant to
262 be found by the dynamic linker. But ALL client calls to malloc()
263 and friends wind up here eventually. They get called because
264 vg_replace_malloc installs a bunch of code redirects which causes
265 Valgrind to use these functions rather than the ones they're
266 replacing.
269 /* The replacement functions are running on the simulated CPU.
270 The code on the simulated CPU does not necessarily use
271 all arguments. E.g. args can be ignored and/or only given
272 to a NON SIMD call.
273 The definedness of such 'unused' arguments will not be verified
274 by memcheck.
275 The macro 'TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED' allows
276 memcheck to detect such errors for the otherwise unused args.
277 Apart of allowing memcheck to detect an error, the macro
278 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED has no effect and
279 has a minimal cost for other tools replacing malloc functions.
281 Creating an "artificial" use of _x that works reliably is not entirely
282 straightforward. Simply comparing it against zero often produces no
283 warning if _x contains at least one nonzero bit is defined, because
284 Memcheck knows that the result of the comparison will be defined (cf
285 expensiveCmpEQorNE).
287 Really we want to PCast _x, so as to create a value which is entirely
288 undefined if any bit of _x is undefined. But there's no portable way to do
289 that.
291 #define TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(_x) \
292 if ((UWord)(_x) == 0) __asm__ __volatile__( "" ::: "memory" )
294 /*---------------------- malloc ----------------------*/
296 /* Generate a replacement for 'fnname' in object 'soname', which calls
297 'vg_replacement' to allocate memory. If that fails, return NULL.
299 #define ALLOC_or_NULL(soname, fnname, vg_replacement) \
301 void* VG_REPLACE_FUNCTION_EZU(10010,soname,fnname) (SizeT n); \
302 void* VG_REPLACE_FUNCTION_EZU(10010,soname,fnname) (SizeT n) \
304 void* v; \
306 DO_INIT; \
307 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
308 MALLOC_TRACE(#fnname "(%llu)", (ULong)n ); \
310 v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
311 MALLOC_TRACE(" = %p\n", v ); \
312 if (!v) SET_ERRNO_ENOMEM; \
313 return v; \
316 /* Generate a replacement for 'fnname' in object 'soname', which calls
317 'vg_replacement' to allocate aligned memory. If that fails, return NULL.
319 #define ALLOC_or_NULL_ALIGNED(soname, fnname, vg_replacement, tag) \
321 void* VG_REPLACE_FUNCTION_EZU(10010,soname,fnname) (SizeT n, SizeT alignment); \
322 void* VG_REPLACE_FUNCTION_EZU(10010,soname,fnname) (SizeT n, SizeT alignment) \
324 void* v; \
325 SizeT orig_alignment = alignment; \
327 DO_INIT; \
328 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
329 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .size=n, .alloc_kind=AllocKind##tag}; \
330 VERIFY_ALIGNMENT(&aligned_alloc_info); \
331 MALLOC_TRACE(#fnname "(size %llu, al %llu)", (ULong)n, (ULong)alignment ); \
333 if ((alignment == 0) \
334 || ((alignment & (alignment - 1)) != 0)) { \
335 return 0; \
338 /* Round up to minimum alignment if necessary. */ \
339 if (alignment < VG_MIN_MALLOC_SZB) \
340 alignment = VG_MIN_MALLOC_SZB; \
342 v = (void*)VALGRIND_NON_SIMD_CALL3( info.tl_##vg_replacement, n, alignment, orig_alignment ); \
343 MALLOC_TRACE(" = %p\n", v ); \
344 if (!v) SET_ERRNO_ENOMEM; \
345 return v; \
348 #define ZONEALLOC_or_NULL(soname, fnname, vg_replacement) \
350 void* VG_REPLACE_FUNCTION_EZU(10020,soname,fnname) (void *zone, SizeT n); \
351 void* VG_REPLACE_FUNCTION_EZU(10020,soname,fnname) (void *zone, SizeT n) \
353 void* v; \
355 DO_INIT; \
356 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone); \
357 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
358 MALLOC_TRACE(#fnname "(%p, %llu)", zone, (ULong)n ); \
360 v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
361 MALLOC_TRACE(" = %p\n", v ); \
362 return v; \
366 /* Generate a replacement for 'fnname' in object 'soname', which calls
367 'vg_replacement' to allocate memory. If that fails, it bombs the
368 system.
370 #define ALLOC_or_BOMB(soname, fnname, vg_replacement) \
372 void* VG_REPLACE_FUNCTION_EZU(10030,soname,fnname) (SizeT n); \
373 void* VG_REPLACE_FUNCTION_EZU(10030,soname,fnname) (SizeT n) \
375 void* v; \
377 DO_INIT; \
378 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
379 MALLOC_TRACE(#fnname "(%llu)", (ULong)n ); \
381 v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
382 MALLOC_TRACE(" = %p\n", v ); \
383 if (NULL == v) { \
384 VALGRIND_PRINTF( \
385 "new/new[] failed and should throw an exception, but Valgrind\n"); \
386 VALGRIND_PRINTF_BACKTRACE( \
387 " cannot throw exceptions and so is aborting instead. Sorry.\n"); \
388 my_exit(1); \
390 return v; \
393 /* Generate a replacement for 'fnname' in object 'soname', which calls
394 'vg_replacement' to allocate aligned memory. If that fails, it bombs the
395 system.
397 #define ALLOC_or_BOMB_ALIGNED(soname, fnname, vg_replacement, tag) \
399 void* VG_REPLACE_FUNCTION_EZU(10030,soname,fnname) (SizeT n, SizeT alignment); \
400 void* VG_REPLACE_FUNCTION_EZU(10030,soname,fnname) (SizeT n, SizeT alignment) \
402 void* v; \
403 SizeT orig_alignment = alignment; \
405 DO_INIT; \
406 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
407 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .size=n, .alloc_kind=AllocKind##tag }; \
408 VERIFY_ALIGNMENT(&aligned_alloc_info); \
409 MALLOC_TRACE(#fnname "(size %llu, al %llu)", (ULong)n, (ULong)alignment ); \
411 if ((alignment == 0) \
412 || ((alignment & (alignment - 1)) != 0)) { \
413 VALGRIND_PRINTF( \
414 "new/new[] aligned failed and should throw an exception, but Valgrind\n"); \
415 VALGRIND_PRINTF_BACKTRACE( \
416 " cannot throw exceptions and so is aborting instead. Sorry.\n"); \
417 my_exit(1); \
420 /* Round up to minimum alignment if necessary. */ \
421 if (alignment < VG_MIN_MALLOC_SZB) \
422 alignment = VG_MIN_MALLOC_SZB; \
424 v = (void*)VALGRIND_NON_SIMD_CALL3( info.tl_##vg_replacement, n, alignment, orig_alignment ); \
425 MALLOC_TRACE(" = %p\n", v ); \
426 if (NULL == v) { \
427 VALGRIND_PRINTF( \
428 "new/new[] aligned failed and should throw an exception, but Valgrind\n"); \
429 VALGRIND_PRINTF_BACKTRACE( \
430 " cannot throw exceptions and so is aborting instead. Sorry.\n"); \
431 my_exit(1); \
433 return v; \
436 // Each of these lines generates a replacement function:
437 // (from_so, from_fn, v's replacement)
438 // For some lines, we will also define a replacement function
439 // whose only purpose is to be a soname synonym place holder
440 // that can be replaced using --soname-synonyms.
442 // malloc
443 #if defined(VGO_linux)
444 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, malloc, malloc);
445 ALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc, malloc);
446 ALLOC_or_NULL(SO_SYN_MALLOC, malloc, malloc);
448 #elif defined(VGO_freebsd)
449 ALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc, malloc);
450 ALLOC_or_NULL(SO_SYN_MALLOC, malloc, malloc);
452 #elif defined(VGO_darwin)
453 ALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc, malloc);
454 ALLOC_or_NULL(SO_SYN_MALLOC, malloc, malloc);
455 ZONEALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc_zone_malloc, malloc);
456 ZONEALLOC_or_NULL(SO_SYN_MALLOC, malloc_zone_malloc, malloc);
458 #elif defined(VGO_solaris)
459 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, malloc, malloc);
460 ALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc, malloc);
461 ALLOC_or_NULL(VG_Z_LIBUMEM_SO_1, malloc, malloc);
462 ALLOC_or_NULL(SO_SYN_MALLOC, malloc, malloc);
464 #endif
467 /*---------------------- new ----------------------*/
469 #if defined(VGO_linux)
470 // operator new(unsigned int), not mangled (for gcc 2.96)
471 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, builtin_new, __builtin_new);
472 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, builtin_new, __builtin_new);
473 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, __builtin_new, __builtin_new);
474 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, __builtin_new, __builtin_new);
475 // operator new(unsigned int)
476 #if VG_WORDSIZE == 4
477 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj, __builtin_new);
478 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwj, __builtin_new);
479 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znwj, __builtin_new);
480 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwj, __builtin_new);
481 #endif
482 // operator new(unsigned long)
483 #if VG_WORDSIZE == 8
484 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm, __builtin_new);
485 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwm, __builtin_new);
486 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znwm, __builtin_new);
487 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwm, __builtin_new);
488 #endif
490 #elif defined(VGO_freebsd)
491 // operator new(unsigned int)
492 #if VG_WORDSIZE == 4
493 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj, __builtin_new);
494 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwj, __builtin_new);
495 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwj, __builtin_new);
496 #endif
497 // operator new(unsigned long)
498 #if VG_WORDSIZE == 8
499 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm, __builtin_new);
500 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwm, __builtin_new);
501 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwm, __builtin_new);
502 #endif
504 #elif defined(VGO_darwin)
505 // operator new(unsigned int)
506 #if VG_WORDSIZE == 4
507 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj, __builtin_new);
508 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwj, __builtin_new);
509 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znwj, __builtin_new);
510 #endif
511 // operator new(unsigned long)
512 #if VG_WORDSIZE == 8
513 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm, __builtin_new);
514 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwm, __builtin_new);
515 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwm, __builtin_new);
516 #endif
518 #elif defined(VGO_solaris)
519 // operator new(unsigned int)
520 #if VG_WORDSIZE == 4
521 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj, __builtin_new);
522 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwj, __builtin_new);
523 #endif
524 // operator new(unsigned long)
525 #if VG_WORDSIZE == 8
526 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm, __builtin_new);
527 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwm, __builtin_new);
528 #endif
530 #endif
532 /*------------------- C++17 new aligned -------------------*/
534 #if defined(VGO_linux)
535 // operator new(unsigned int, std::align_val_t)
536 #if VG_WORDSIZE == 4
537 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
538 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
539 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBC_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
540 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
541 #endif
542 // operator new(unsigned long, std::align_val_t)
543 #if VG_WORDSIZE == 8
544 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
545 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
546 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBC_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
547 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
548 #endif
550 #elif defined(VGO_freebsd)
551 // operator new(unsigned int, std::align_val_t)
552 #if VG_WORDSIZE == 4
553 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
554 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
555 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
556 #endif
557 // operator new(unsigned long, std::align_val_t)
558 #if VG_WORDSIZE == 8
559 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
560 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
561 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
562 #endif
564 #elif defined(VGO_darwin)
565 #if VG_WORDSIZE == 4
566 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
567 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
568 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
569 #endif
570 #if VG_WORDSIZE == 8
571 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
572 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
573 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
574 #endif
576 #elif defined(VGO_solaris)
577 // operator new(unsigned int, std::align_val_t)
578 #if VG_WORDSIZE == 4
579 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
580 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_t, __builtin_new_aligned, NewAligned);
581 #endif
582 // operator new(unsigned long, std::align_val_t)
583 #if VG_WORDSIZE == 8
584 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
585 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_t, __builtin_new_aligned, NewAligned);
587 #endif
589 #endif
592 /*---------------------- new nothrow ----------------------*/
594 #if defined(VGO_linux)
595 // operator new(unsigned, std::nothrow_t const&)
596 #if VG_WORDSIZE == 4
597 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
598 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
599 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
600 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwjRKSt9nothrow_t, __builtin_new);
601 #endif
602 // operator new(unsigned long, std::nothrow_t const&)
603 #if VG_WORDSIZE == 8
604 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
605 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
606 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
607 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwmRKSt9nothrow_t, __builtin_new);
608 #endif
610 #elif defined(VGO_freebsd)
611 // operator new(unsigned, std::nothrow_t const&)
612 #if VG_WORDSIZE == 4
613 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
614 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
615 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwjRKSt9nothrow_t, __builtin_new);
616 #endif
617 // operator new(unsigned long, std::nothrow_t const&)
618 #if VG_WORDSIZE == 8
619 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
620 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
621 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwmRKSt9nothrow_t, __builtin_new);
622 #endif
624 #elif defined(VGO_darwin)
625 // operator new(unsigned, std::nothrow_t const&)
626 #if VG_WORDSIZE == 4
627 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
628 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
629 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
630 #endif
631 // operator new(unsigned long, std::nothrow_t const&)
632 #if VG_WORDSIZE == 8
633 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
634 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
635 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwmRKSt9nothrow_t, __builtin_new);
636 #endif
638 #elif defined(VGO_solaris)
639 // operator new(unsigned, std::nothrow_t const&)
640 #if VG_WORDSIZE == 4
641 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
642 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwjRKSt9nothrow_t, __builtin_new);
643 #endif
644 // operator new(unsigned long, std::nothrow_t const&)
645 #if VG_WORDSIZE == 8
646 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
647 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwmRKSt9nothrow_t, __builtin_new);
648 #endif
650 #endif
652 /*----------------- C++17 new aligned nothrow -----------------*/
654 #if defined(VGO_linux)
655 // operator new(unsigned int, std::align_val_t, std::nothrow_t const&)
656 #if VG_WORDSIZE == 4
657 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
658 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
659 ALLOC_or_NULL_ALIGNED(VG_Z_LIBC_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
660 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
661 #endif
662 // operator new(unsigned long, std::align_val_t, std::nothrow_t const&)
663 #if VG_WORDSIZE == 8
664 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
665 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
666 ALLOC_or_NULL_ALIGNED(VG_Z_LIBC_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
667 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
668 #endif
670 #elif defined(VGO_freebsd)
671 // operator new(unsigned int, std::align_val_t, std::nothrow_t const&)
672 #if VG_WORDSIZE == 4
673 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
674 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
675 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
676 #endif
677 // operator new(unsigned long, std::align_val_t, std::nothrow_t const&)
678 #if VG_WORDSIZE == 8
679 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
680 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
681 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
682 #endif
684 #elif defined(VGO_darwin)
685 #if VG_WORDSIZE == 4
686 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
687 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
688 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
689 #endif
690 #if VG_WORDSIZE == 8
691 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
692 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
693 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
694 #endif
696 #elif defined(VGO_solaris)
697 // operator new(unsigned, std::align_val_t, std::nothrow_t const&)
698 #if VG_WORDSIZE == 4
699 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, __ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
700 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, __ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
701 #endif
702 // operator new(unsigned long, std::align_val_t, std::nothrow_t const&)
703 #if VG_WORDSIZE == 8
704 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
705 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned, NewAligned);
706 #endif
708 #endif
711 /*---------------------- new [] ----------------------*/
713 #if defined(VGO_linux)
714 // operator new[](unsigned int), not mangled (for gcc 2.96)
715 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, __builtin_vec_new, __builtin_vec_new );
716 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, __builtin_vec_new, __builtin_vec_new );
717 // operator new[](unsigned int)
718 #if VG_WORDSIZE == 4
719 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj, __builtin_vec_new );
720 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znaj, __builtin_vec_new );
721 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znaj, __builtin_vec_new );
722 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znaj, __builtin_vec_new );
723 #endif
724 // operator new[](unsigned long),
725 #if VG_WORDSIZE == 8
726 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam, __builtin_vec_new );
727 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znam, __builtin_vec_new );
728 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znam, __builtin_vec_new );
729 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znam, __builtin_vec_new );
730 #endif
732 #elif defined(VGO_freebsd)
733 // operator new[](unsigned int)
734 #if VG_WORDSIZE == 4
735 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj, __builtin_vec_new );
736 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znaj, __builtin_vec_new );
737 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znaj, __builtin_vec_new );
738 #endif
739 // operator new[](unsigned long)
740 #if VG_WORDSIZE == 8
741 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam, __builtin_vec_new );
742 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znam, __builtin_vec_new );
743 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znam, __builtin_vec_new );
744 #endif
746 #elif defined(VGO_darwin)
747 // operator new[](unsigned int)
748 #if VG_WORDSIZE == 4
749 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj, __builtin_vec_new );
750 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znaj, __builtin_vec_new );
751 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znaj, __builtin_vec_new );
752 #endif
753 // operator new[](unsigned long)
754 #if VG_WORDSIZE == 8
755 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam, __builtin_vec_new );
756 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znam, __builtin_vec_new );
757 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znam, __builtin_vec_new );
758 #endif
760 #elif defined(VGO_solaris)
761 // operator new[](unsigned int)
762 #if VG_WORDSIZE == 4
763 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj, __builtin_vec_new );
764 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znaj, __builtin_vec_new );
765 #endif
766 // operator new[](unsigned long)
767 #if VG_WORDSIZE == 8
768 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam, __builtin_vec_new );
769 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znam, __builtin_vec_new );
770 #endif
772 #endif
774 /*------------------ C++ 17 new aligned [] ------------------*/
776 #if defined(VGO_linux)
777 // operator new[](unsigned int, std::align_val_t)
778 #if VG_WORDSIZE == 4
779 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
780 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
781 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBC_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
782 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
783 #endif
784 // operator new[](unsigned long, std::align_val_t)
785 #if VG_WORDSIZE == 8
786 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
787 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
788 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBC_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
789 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
790 #endif
792 #elif defined(VGO_freebsd)
793 // operator new[](unsigned int, std::align_val_t)
794 #if VG_WORDSIZE == 4
795 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
796 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
797 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
798 #endif
799 // operator new[](unsigned long, std::align_val_t)
800 #if VG_WORDSIZE == 8
801 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
802 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
803 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
804 #endif
806 #elif defined(VGO_darwin)
808 #if VG_WORDSIZE == 4
809 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
810 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
811 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
812 #endif
813 // operator new[](unsigned long, std::align_val_t)
814 #if VG_WORDSIZE == 8
815 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
816 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
817 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
818 #endif
820 #elif defined(VGO_solaris)
821 // operator new[](unsigned int, std::align_val_t)
822 #if VG_WORDSIZE == 4
823 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
824 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
825 #endif
826 // operator new[](unsigned long, std::align_val_t)
827 #if VG_WORDSIZE == 8
828 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
829 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_t, __builtin_vec_new_aligned, VecNewAligned );
830 #endif
832 #endif
835 /*---------------------- new [] nothrow ----------------------*/
837 #if defined(VGO_linux)
838 // operator new[](unsigned, std::nothrow_t const&)
839 #if VG_WORDSIZE == 4
840 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
841 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
842 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
843 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnajRKSt9nothrow_t, __builtin_vec_new );
844 #endif
845 // operator new[](unsigned long, std::nothrow_t const&)
846 #if VG_WORDSIZE == 8
847 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
848 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
849 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
850 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnamRKSt9nothrow_t, __builtin_vec_new );
851 #endif
853 #elif defined(VGO_freebsd)
854 // operator new[](unsigned, std::nothrow_t const&)
855 #if VG_WORDSIZE == 4
856 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
857 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
858 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnajRKSt9nothrow_t, __builtin_vec_new );
859 #endif
860 // operator new[](unsigned long, std::nothrow_t const&)
861 #if VG_WORDSIZE == 8
862 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
863 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
864 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnamRKSt9nothrow_t, __builtin_vec_new );
865 #endif
867 #elif defined(VGO_darwin)
868 // operator new[](unsigned, std::nothrow_t const&)
869 #if VG_WORDSIZE == 4
870 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
871 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
872 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
873 #endif
874 // operator new[](unsigned long, std::nothrow_t const&)
875 #if VG_WORDSIZE == 8
876 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
877 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
878 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnamRKSt9nothrow_t, __builtin_vec_new );
879 #endif
881 #elif defined(VGO_solaris)
882 // operator new[](unsigned, std::nothrow_t const&)
883 #if VG_WORDSIZE == 4
884 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
885 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnajRKSt9nothrow_t, __builtin_vec_new );
886 #endif
887 // operator new[](unsigned long, std::nothrow_t const&)
888 #if VG_WORDSIZE == 8
889 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
890 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnamRKSt9nothrow_t, __builtin_vec_new );
891 #endif
893 #endif
895 /*----------------- C++17 new aligned [] nothrow -----------------*/
897 #if defined(VGO_linux)
898 // operator new[](unsigned int, std::align_val_t, std::nothrow_t const&)
899 #if VG_WORDSIZE == 4
900 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
901 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
902 ALLOC_or_NULL_ALIGNED(VG_Z_LIBC_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
903 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
904 #endif
905 // operator new[](unsigned long, std::align_val_t, std::nothrow_t const&)
906 #if VG_WORDSIZE == 8
907 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
908 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
909 ALLOC_or_NULL_ALIGNED(VG_Z_LIBC_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
910 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
911 #endif
913 #elif defined(VGO_freebsd)
914 // operator new[](unsigned int, std::align_val_t, std::nothrow_t const&)
915 #if VG_WORDSIZE == 4
916 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
917 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
918 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
919 #endif
920 // operator new[](unsigned long, std::align_val_t, std::nothrow_t const&)
921 #if VG_WORDSIZE == 8
922 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
923 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
924 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
925 #endif
927 #elif defined(VGO_darwin)
929 #if VG_WORDSIZE == 4
930 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
931 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
932 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
933 #endif
934 // operator new[](unsigned long, std::align_val_t, std::nothrow_t const&)
935 #if VG_WORDSIZE == 8
936 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
937 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
938 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
939 #endif
941 #elif defined(VGO_solaris)
942 // operator new[](unsigned int, std::align_val_t, std::nothrow_t const&)
943 #if VG_WORDSIZE == 4
944 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
945 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
946 #endif
947 // operator new[](unsigned long, std::align_val_t, std::nothrow_t const&)
948 #if VG_WORDSIZE == 8
949 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
950 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned, VecNewAligned );
951 #endif
953 #endif
955 /*---------------------- free ----------------------*/
957 /* Generate a replacement for 'fnname' in object 'soname', which calls
958 'vg_replacement' to free previously allocated memory.
960 #define ZONEFREE(soname, fnname, vg_replacement) \
962 void VG_REPLACE_FUNCTION_EZU(10040,soname,fnname) (void *zone, void *p); \
963 void VG_REPLACE_FUNCTION_EZU(10040,soname,fnname) (void *zone, void *p) \
965 DO_INIT; \
966 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)zone ^ (UWord)p); \
967 MALLOC_TRACE(#fnname "(%p, %p)\n", zone, p ); \
968 if (p == NULL) \
969 return; \
970 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
973 #define FREE(soname, fnname, vg_replacement) \
975 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p); \
976 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p) \
978 DO_INIT; \
979 MALLOC_TRACE(#fnname "(%p)\n", p ); \
980 if (p == NULL) \
981 return; \
982 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
986 #if defined(VGO_linux)
987 FREE(VG_Z_LIBSTDCXX_SONAME, free, free );
988 FREE(VG_Z_LIBC_SONAME, free, free );
989 FREE(SO_SYN_MALLOC, free, free );
991 #elif defined(VGO_freebsd)
992 FREE(VG_Z_LIBC_SONAME, free, free );
993 FREE(SO_SYN_MALLOC, free, free );
995 #elif defined(VGO_darwin)
996 FREE(VG_Z_LIBC_SONAME, free, free );
997 FREE(SO_SYN_MALLOC, free, free );
998 ZONEFREE(VG_Z_LIBC_SONAME, malloc_zone_free, free );
999 ZONEFREE(SO_SYN_MALLOC, malloc_zone_free, free );
1001 #elif defined(VGO_solaris)
1002 FREE(VG_Z_LIBC_SONAME, free, free );
1003 FREE(VG_Z_LIBUMEM_SO_1, free, free );
1004 FREE(SO_SYN_MALLOC, free, free );
1006 #endif
1008 /*------------------- free_sized -------------------*/
1010 /* Generate a replacement for 'fnname' in object 'soname', which calls
1011 'vg_replacement' to free previously allocated memory.
1014 #define FREE_SIZED(soname, fnname, vg_replacement, tag) \
1016 void VG_REPLACE_FUNCTION_EZU(10051,soname,fnname) (void *p, SizeT size); \
1017 void VG_REPLACE_FUNCTION_EZU(10051,soname,fnname) (void *p, SizeT size) \
1019 struct AlignedAllocInfo aligned_alloc_info = { .size=size, .mem=p, .alloc_kind=AllocKind##tag }; \
1021 DO_INIT; \
1022 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)size); \
1023 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1024 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1025 if (p == NULL) \
1026 return; \
1027 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1031 #if defined(VGO_linux)
1032 FREE_SIZED(VG_Z_LIBC_SONAME, free_sized, free, FreeSized );
1033 FREE_SIZED(SO_SYN_MALLOC, free_sized, free, FreeSized );
1035 #elif defined(VGO_freebsd)
1036 FREE_SIZED(VG_Z_LIBC_SONAME, free_sized, free, FreeSized );
1037 FREE_SIZED(SO_SYN_MALLOC, free_sized, free, FreeSized );
1039 #elif defined(VGO_darwin)
1040 FREE_SIZED(VG_Z_LIBC_SONAME, free_sized, free, FreeSized );
1041 FREE_SIZED(SO_SYN_MALLOC, free_sized, free, FreeSized );
1043 #elif defined(VGO_solaris)
1044 FREE_SIZED(VG_Z_LIBC_SONAME, free_sized, free, FreeSized );
1045 FREE_SIZED(SO_SYN_MALLOC, free_sized, free, FreeSized );
1047 #endif
1050 /*--------------- free_aligned_sized ---------------*/
1052 /* Generate a replacement for 'fnname' in object 'soname', which calls
1053 'vg_replacement' to free previously allocated memory.
1056 #define FREE_ALIGNED_SIZED(soname, fnname, vg_replacement, tag) \
1058 void VG_REPLACE_FUNCTION_EZU(10052,soname,fnname) (void *p, SizeT alignment, SizeT size); \
1059 void VG_REPLACE_FUNCTION_EZU(10052,soname,fnname) (void *p, SizeT alignment, SizeT size) \
1061 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .size=size, .mem=p, .alloc_kind=AllocKind##tag }; \
1063 DO_INIT; \
1064 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)alignment); \
1065 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)size); \
1066 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1067 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1068 if (p == NULL) \
1069 return; \
1070 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1074 #if defined(VGO_linux)
1076 #elif defined(VGO_freebsd)
1077 FREE_ALIGNED_SIZED(VG_Z_LIBC_SONAME, free_aligned_sized, free, FreeAlignedSized );
1078 FREE_ALIGNED_SIZED(SO_SYN_MALLOC, free_aligned_sized, free, FreeAlignedSized );
1080 #elif defined(VGO_darwin)
1082 #elif defined(VGO_solaris)
1084 #endif
1085 /*---------------------- cfree ----------------------*/
1087 // cfree
1088 #if defined(VGO_linux)
1089 FREE(VG_Z_LIBSTDCXX_SONAME, cfree, free );
1090 FREE(VG_Z_LIBC_SONAME, cfree, free );
1091 FREE(SO_SYN_MALLOC, cfree, free );
1093 #elif defined(VGO_darwin)
1094 //FREE(VG_Z_LIBSTDCXX_SONAME, cfree, free );
1095 //FREE(VG_Z_LIBC_SONAME, cfree, free );
1097 #elif defined(VGO_solaris)
1098 FREE(VG_Z_LIBC_SONAME, cfree, free );
1099 /* libumem does not implement cfree(). */
1100 //FREE(VG_Z_LIBUMEM_SO_1, cfree, free );
1101 FREE(SO_SYN_MALLOC, cfree, free );
1103 #endif
1106 /*---------------------- delete ----------------------*/
1108 #define DELETE(soname, fnname, vg_replacement, tag) \
1110 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p); \
1111 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p) \
1113 struct AlignedAllocInfo aligned_alloc_info = { .mem=p, .alloc_kind=AllocKind##tag }; \
1115 DO_INIT; \
1116 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1117 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1118 if (p == NULL) \
1119 return; \
1120 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1123 #if defined(VGO_linux)
1124 // operator delete(void*), not mangled (for gcc 2.96)
1125 DELETE(VG_Z_LIBSTDCXX_SONAME, __builtin_delete, __builtin_delete, DeleteDefault );
1126 DELETE(VG_Z_LIBC_SONAME, __builtin_delete, __builtin_delete, DeleteDefault );
1127 // operator delete(void*)
1128 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete, DeleteDefault );
1129 DELETE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete, DeleteDefault );
1130 DELETE(VG_Z_LIBC_SONAME, _ZdlPv, __builtin_delete, DeleteDefault );
1131 DELETE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete, DeleteDefault );
1133 #elif defined(VGO_freebsd)
1134 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete, DeleteDefault );
1135 DELETE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete, DeleteDefault );
1136 DELETE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete, DeleteDefault );
1138 #elif defined(VGO_darwin)
1139 // operator delete(void*)
1140 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete, DeleteDefault );
1141 DELETE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete, DeleteDefault );
1142 DELETE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete, DeleteDefault );
1144 #elif defined(VGO_solaris)
1145 // operator delete(void*)
1146 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete, DeleteDefault );
1147 DELETE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete, DeleteDefault );
1149 #endif
1151 /*------------------- C++14 delete sized -------------------*/
1153 #define DELETE_SIZED(soname, fnname, vg_replacement, tag) \
1155 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size); \
1156 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size) \
1158 struct AlignedAllocInfo aligned_alloc_info = { .size=size, .mem=p, .alloc_kind=AllocKind##tag }; \
1160 DO_INIT; \
1161 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)size); \
1162 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1163 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1164 if (p == NULL) \
1165 return; \
1166 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1169 #if defined(VGO_linux)
1170 // operator delete(void*, unsigned int)
1171 #if __SIZEOF_SIZE_T__ == 4
1172 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete, DeleteSized );
1173 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete, DeleteSized );
1174 DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdlPvj, __builtin_delete, DeleteSized );
1175 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete, DeleteSized );
1176 // operator delete(void*, unsigned long)
1177 #elif __SIZEOF_SIZE_T__ == 8
1178 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete, DeleteSized );
1179 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete, DeleteSized );
1180 DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdlPvm, __builtin_delete, DeleteSized );
1181 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete, DeleteSized );
1182 #endif
1184 #elif defined(VGO_freebsd)
1185 // operator delete(void*, unsigned int)
1186 #if __SIZEOF_SIZE_T__ == 4
1187 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete, DeleteSized );
1188 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete, DeleteSized );
1189 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete, DeleteSized );
1190 #elif __SIZEOF_SIZE_T__ == 8
1191 // operator delete(void*, unsigned long)
1192 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete, DeleteSized );
1193 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete, DeleteSized );
1194 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete, DeleteSized );
1195 #endif
1197 #elif defined(VGO_darwin)
1198 // operator delete(void*, unsigned int)
1199 #if __SIZEOF_SIZE_T__ == 4
1200 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete, DeleteSized );
1201 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete, DeleteSized );
1202 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete, DeleteSized );
1203 #elif __SIZEOF_SIZE_T__ == 8
1204 // operator delete(void*, unsigned long)
1205 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete, DeleteSized );
1206 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete, DeleteSized );
1207 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete, DeleteSized );
1208 #endif
1210 #elif defined(VGO_solaris)
1211 // operator delete(void*, unsigned long)
1212 #if __SIZEOF_SIZE_T__ == 4
1213 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete, DeleteSized );
1214 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete, DeleteSized );
1215 #elif __SIZEOF_SIZE_T__ == 8
1216 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete, DeleteSized );
1217 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete, DeleteSized );
1218 #endif
1220 #endif
1222 /*------------------- C++17 delete aligned -------------------*/
1224 /* No need to check the alignment
1225 * either the alignment matches the alloc
1226 * or the alloc would have failed */
1228 #define DELETE_ALIGNED(soname, fnname, vg_replacement, tag ) \
1230 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT alignment); \
1231 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT alignment) \
1233 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .mem=p, .alloc_kind=AllocKind##tag }; \
1235 DO_INIT; \
1236 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)alignment); \
1237 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1238 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1239 if (p == NULL) \
1240 return; \
1241 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1244 #define DELETE_SIZED_ALIGNED(soname, fnname, vg_replacement, tag ) \
1246 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size, SizeT alignment); \
1247 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size, SizeT alignment) \
1249 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .size=size, .mem=p, .alloc_kind=AllocKind##tag }; \
1251 DO_INIT; \
1252 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)size); \
1253 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)alignment); \
1254 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1255 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1256 if (p == NULL) \
1257 return; \
1258 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1261 #if defined(VGO_linux)
1262 // operator delete(void*, std::align_val_t)
1263 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1264 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1265 DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1266 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1268 // operator delete(void*, unsigned int, std::align_val_t)
1269 #if __SIZEOF_SIZE_T__ == 4
1270 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1271 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1272 DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1273 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1274 // operator delete(void*, unsigned long, std::align_val_t)
1275 #elif __SIZEOF_SIZE_T__ == 8
1276 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1277 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1278 DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1279 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1280 #endif
1282 #elif defined(VGO_freebsd)
1283 // operator delete(void*, std::align_val_t)
1284 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1285 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1286 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1288 // operator delete(void*, unsigned int, std::align_val_t)
1289 #if __SIZEOF_SIZE_T__ == 4
1290 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1291 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1292 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1293 // operator delete(void*, unsigned long, std::align_val_t)
1294 #elif __SIZEOF_SIZE_T__ == 8
1295 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1296 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1297 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1298 #endif
1300 #elif defined(VGO_darwin)
1302 // operator delete(void*, std::align_val_t)
1303 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1304 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1305 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1307 // operator delete(void*, unsigned int, std::align_val_t)
1308 #if __SIZEOF_SIZE_T__ == 4
1309 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1310 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1311 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1312 // operator delete(void*, unsigned long, std::align_val_t)
1313 #elif __SIZEOF_SIZE_T__ == 8
1314 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1315 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1316 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1317 #endif
1319 #elif defined(VGO_solaris)
1321 // operator delete(void*, std::align_val_t)
1322 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1323 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned, DeleteAligned );
1325 // operator delete(void*, unsigned int, std::align_val_t)
1326 #if __SIZEOF_SIZE_T__ == 4
1327 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1328 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1329 // operator delete(void*, unsigned long, std::align_val_t)
1330 #elif __SIZEOF_SIZE_T__ == 8
1331 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1332 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned, DeleteSizedAligned );
1333 #endif
1335 #endif
1337 /*---------------------- delete nothrow ----------------------*/
1339 #if defined(VGO_linux)
1340 // operator delete(void*, std::nothrow_t const&)
1341 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1342 DELETE(VG_Z_LIBCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1343 DELETE(VG_Z_LIBC_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1344 DELETE(SO_SYN_MALLOC, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1346 #elif defined(VGO_freebsd)
1347 // operator delete(void*, std::nothrow_t const&)
1348 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1349 DELETE(VG_Z_LIBCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1350 DELETE(SO_SYN_MALLOC, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1352 #elif defined(VGO_darwin)
1353 // operator delete(void*, std::nothrow_t const&)
1354 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1355 DELETE(VG_Z_LIBCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1356 DELETE(SO_SYN_MALLOC, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1358 #elif defined(VGO_solaris)
1359 // operator delete(void*, std::nothrow_t const&)
1360 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1361 DELETE(SO_SYN_MALLOC, _ZdlPvRKSt9nothrow_t, __builtin_delete, DeleteDefault );
1363 #endif
1365 /*---------------------- C++17 delete aligned nothrow ----------------------*/
1367 #if defined(VGO_linux)
1368 // operator delete(void*, std::align_val_t, std::nothrow_t const&)
1369 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1370 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1371 DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1372 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1374 // no sized version of this operator
1376 #elif defined(VGO_freebsd)
1377 // operator delete(void*, std::align_val_t, std::nothrow_t const&)
1378 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1379 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1380 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1382 #elif defined(VGO_darwin)
1384 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1385 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1386 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1388 #elif defined(VGO_solaris)
1389 // operator delete(void*, std::align_val_t, std::nothrow_t const&)
1390 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1391 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned, DeleteAligned );
1393 // no sized version of this operator
1395 #endif
1398 /*---------------------- delete [] ----------------------*/
1402 #if defined(VGO_linux)
1403 // operator delete[](void*), not mangled (for gcc 2.96)
1404 DELETE(VG_Z_LIBSTDCXX_SONAME, __builtin_vec_delete, __builtin_vec_delete, VecDeleteDefault );
1405 DELETE(VG_Z_LIBC_SONAME, __builtin_vec_delete, __builtin_vec_delete, VecDeleteDefault );
1406 // operator delete[](void*)
1407 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1408 DELETE(VG_Z_LIBCXX_SONAME, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1409 DELETE(VG_Z_LIBC_SONAME, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1410 DELETE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1412 #elif defined(VGO_freebsd)
1413 // operator delete[](void*)
1414 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1415 DELETE(VG_Z_LIBCXX_SONAME, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1416 DELETE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1418 #elif defined(VGO_darwin)
1419 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1420 DELETE(VG_Z_LIBCXX_SONAME, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1421 DELETE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1423 #elif defined(VGO_solaris)
1424 // operator delete[](void*)
1425 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1426 DELETE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete, VecDeleteDefault );
1428 #endif
1430 /*---------------------- C++14 delete sized [] ----------------------*/
1432 #if defined(VGO_linux)
1433 // operator delete[](void*, unsigned int)
1434 #if __SIZEOF_SIZE_T__ == 4
1435 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1436 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1437 DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1438 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1440 #elif __SIZEOF_SIZE_T__ == 8
1441 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1442 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1443 DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1444 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1445 #endif
1447 #elif defined(VGO_freebsd)
1448 // operator delete[](void*, unsigned int)
1449 #if __SIZEOF_SIZE_T__ == 4
1450 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1451 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1452 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1453 #elif __SIZEOF_SIZE_T__ == 8
1454 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1455 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1456 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1457 #endif
1459 #elif defined(VGO_darwin)
1461 #if __SIZEOF_SIZE_T__ == 4
1462 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1463 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1464 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1465 #elif __SIZEOF_SIZE_T__ == 8
1466 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1467 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1468 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1469 #endif
1471 #elif defined(VGO_solaris)
1472 // operator delete[](void*, unsigned int)
1473 #if __SIZEOF_SIZE_T__ == 4
1474 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1475 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete, VecDeleteSized );
1476 // operator delete[](void*, unsigned long)
1477 #elif __SIZEOF_SIZE_T__ == 8
1478 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1479 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete, VecDeleteSized );
1480 #endif
1482 #endif
1484 /*---------------------- C++17 delete aligned [] ----------------------*/
1486 #if defined(VGO_linux)
1487 // operator delete[](void*, std::align_val_t)
1488 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1489 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1490 DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1491 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1493 // operator delete[](void*, unsigned int, std::align_val_t)
1494 #if __SIZEOF_SIZE_T__ == 4
1495 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1496 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1497 DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1498 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1499 // operator delete[](void*, unsigned long, std::align_val_t)
1500 #elif __SIZEOF_SIZE_T__ == 8
1501 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1502 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1503 DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1504 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1505 #endif
1507 #elif defined(VGO_freebsd)
1508 // operator delete[](void*, std::align_val_t)
1509 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1510 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1511 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1513 // operator delete[](void*, unsigned int, std::align_val_t)
1514 #if __SIZEOF_SIZE_T__ == 4
1515 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1516 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1517 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1518 // operator delete[](void*, unsigned long, std::align_val_t)
1519 #elif __SIZEOF_SIZE_T__ == 8
1520 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1521 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1522 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1523 #endif
1525 #elif defined(VGO_darwin)
1527 // operator delete[](void*, std::align_val_t)
1528 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1529 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1530 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1532 // operator delete[](void*, unsigned int, std::align_val_t)
1533 #if __SIZEOF_SIZE_T__ == 4
1534 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1535 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1536 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1537 // operator delete[](void*, unsigned long, std::align_val_t)
1538 #elif __SIZEOF_SIZE_T__ == 8
1539 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1540 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1541 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1542 #endif
1545 #elif defined(VGO_solaris)
1546 // operator delete[](void*, std::align_val_t), GNU mangling
1547 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1548 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1550 // operator delete[](void*, unsigned int, std::align_val_t)
1551 #if __SIZEOF_SIZE_T__ == 4
1552 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1553 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1554 // operator delete[](void*, unsigned long)
1555 #elif __SIZEOF_SIZE_T__ == 8
1556 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1557 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned, VecDeleteSizedAligned );
1558 #endif
1560 #endif
1562 /*---------------------- delete [] nothrow ----------------------*/
1564 #if defined(VGO_linux)
1565 // operator delete[](void*, std::nothrow_t const&)
1566 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1567 DELETE(VG_Z_LIBCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1568 DELETE(VG_Z_LIBC_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1569 DELETE(SO_SYN_MALLOC, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1571 #elif defined(VGO_freebsd)
1572 // operator delete[](void*, std::nothrow_t const&)
1573 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1574 DELETE(VG_Z_LIBCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1575 DELETE(SO_SYN_MALLOC, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1577 #elif defined(VGO_darwin)
1578 // operator delete[](void*, std::nothrow_t const&)
1579 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1580 DELETE(VG_Z_LIBCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1581 DELETE(VG_Z_LIBC_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1583 #elif defined(VGO_solaris)
1584 // operator delete[](void*, std::nothrow_t const&)
1585 DELETE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1586 DELETE(SO_SYN_MALLOC, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete, VecDeleteDefault );
1588 #endif
1590 /*---------------------- C+17 delete aligned [] nothrow ----------------------*/
1592 #if defined(VGO_linux)
1593 // operator delete[](void*, std::align_val_t, std::nothrow_t const&)
1594 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1595 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1596 DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1597 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1599 // no sized version of this operator
1601 #elif defined(VGO_freebsd)
1602 // operator delete[](void*, std::align_val_t, std::nothrow_t const&)
1603 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1604 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1605 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1607 #elif defined(VGO_darwin)
1609 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1610 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1611 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1613 #elif defined(VGO_solaris)
1614 // operator delete[](void*, std::align_val_t, std::nothrow_t const&)
1615 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1616 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned, VecDeleteAligned );
1618 // no sized version of this operator
1620 #endif
1623 /*---------------------- calloc ----------------------*/
1625 #define ZONECALLOC(soname, fnname) \
1627 void* VG_REPLACE_FUNCTION_EZU(10060,soname,fnname) \
1628 ( void *zone, SizeT nmemb, SizeT size ); \
1629 void* VG_REPLACE_FUNCTION_EZU(10060,soname,fnname) \
1630 ( void *zone, SizeT nmemb, SizeT size ) \
1632 void* v; \
1634 DO_INIT; \
1635 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone); \
1636 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(nmemb); \
1637 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
1638 MALLOC_TRACE("zone_calloc(%p, %llu,%llu)", zone, (ULong)nmemb, (ULong)size ); \
1640 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_calloc, nmemb, size ); \
1641 MALLOC_TRACE(" = %p\n", v ); \
1642 return v; \
1645 #define CALLOC(soname, fnname) \
1647 void* VG_REPLACE_FUNCTION_EZU(10070,soname,fnname) \
1648 ( SizeT nmemb, SizeT size ); \
1649 void* VG_REPLACE_FUNCTION_EZU(10070,soname,fnname) \
1650 ( SizeT nmemb, SizeT size ) \
1652 void* v; \
1654 DO_INIT; \
1655 MALLOC_TRACE("calloc(%llu,%llu)", (ULong)nmemb, (ULong)size ); \
1657 /* Protect against overflow. See bug 24078. (that bug number is
1658 invalid. Which one really?) */ \
1659 /* But don't use division, since that produces an external symbol
1660 reference on ARM, in the form of a call to __aeabi_uidiv. It's
1661 normally OK, because ld.so manages to resolve it to something in the
1662 executable, or one of its shared objects. But that isn't guaranteed
1663 to be the case, and it has been observed to fail in rare cases, eg:
1664 echo x | valgrind /bin/sed -n "s/.*-\>\ //p"
1665 So instead compute the high word of the product and check it is zero. */ \
1666 if (umulHW(size, nmemb) != 0) return NULL; \
1667 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_calloc, nmemb, size ); \
1668 MALLOC_TRACE(" = %p\n", v ); \
1669 if (!v) SET_ERRNO_ENOMEM; \
1670 return v; \
1673 #if defined(VGO_linux)
1674 CALLOC(VG_Z_LIBC_SONAME, calloc);
1675 CALLOC(SO_SYN_MALLOC, calloc);
1677 #elif defined(VGO_freebsd)
1678 CALLOC(VG_Z_LIBC_SONAME, calloc);
1679 CALLOC(SO_SYN_MALLOC, calloc);
1681 #elif defined(VGO_darwin)
1682 CALLOC(VG_Z_LIBC_SONAME, calloc);
1683 CALLOC(SO_SYN_MALLOC, calloc);
1684 ZONECALLOC(VG_Z_LIBC_SONAME, malloc_zone_calloc);
1685 ZONECALLOC(SO_SYN_MALLOC, malloc_zone_calloc);
1687 #elif defined(VGO_solaris)
1688 CALLOC(VG_Z_LIBC_SONAME, calloc);
1689 CALLOC(VG_Z_LIBUMEM_SO_1, calloc);
1690 CALLOC(SO_SYN_MALLOC, calloc);
1692 #endif
1695 /*---------------------- realloc ----------------------*/
1697 #define ZONEREALLOC(soname, fnname) \
1699 void* VG_REPLACE_FUNCTION_EZU(10080,soname,fnname) \
1700 ( void *zone, void* ptrV, SizeT new_size ); \
1701 void* VG_REPLACE_FUNCTION_EZU(10080,soname,fnname) \
1702 ( void *zone, void* ptrV, SizeT new_size ) \
1704 void* v; \
1706 DO_INIT; \
1707 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \
1708 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \
1709 MALLOC_TRACE("zone_realloc(%p,%p,%llu)", zone, ptrV, (ULong)new_size ); \
1710 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
1711 MALLOC_TRACE(" = %p\n", v ); \
1712 if (v == NULL) { \
1713 if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\
1714 SET_ERRNO_ENOMEM; \
1717 return v; \
1720 #define REALLOC(soname, fnname) \
1722 void* VG_REPLACE_FUNCTION_EZU(10090,soname,fnname) \
1723 ( void* ptrV, SizeT new_size );\
1724 void* VG_REPLACE_FUNCTION_EZU(10090,soname,fnname) \
1725 ( void* ptrV, SizeT new_size ) \
1727 void* v; \
1729 DO_INIT; \
1730 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \
1731 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \
1732 MALLOC_TRACE("realloc(%p,%llu)", ptrV, (ULong)new_size ); \
1733 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
1734 MALLOC_TRACE(" = %p\n", v ); \
1735 if (v == NULL) { \
1736 if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\
1737 SET_ERRNO_ENOMEM; \
1740 return v; \
1743 #define REALLOCF(soname, fnname) \
1745 void* VG_REPLACE_FUNCTION_EZU(10091,soname,fnname) \
1746 ( void* ptrV, SizeT new_size );\
1747 void* VG_REPLACE_FUNCTION_EZU(10091,soname,fnname) \
1748 ( void* ptrV, SizeT new_size ) \
1750 void* v; \
1752 DO_INIT; \
1753 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \
1754 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \
1755 MALLOC_TRACE("reallocf(%p,%llu)", ptrV, (ULong)new_size ); \
1756 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
1757 MALLOC_TRACE(" = %p\n", v ); \
1758 if (v == NULL) { \
1759 if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\
1760 VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \
1761 SET_ERRNO_ENOMEM; \
1764 MALLOC_TRACE(" = %p\n", v ); \
1765 return v; \
1768 #define REALLOCARRAY(soname, fnname) \
1770 void* VG_REPLACE_FUNCTION_EZU(10092,soname,fnname) \
1771 ( void* ptrV, SizeT nmemb, SizeT size );\
1772 void* VG_REPLACE_FUNCTION_EZU(10092,soname,fnname) \
1773 ( void* ptrV, SizeT nmemb, SizeT size ) \
1775 void* v; \
1777 DO_INIT; \
1778 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \
1779 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(nmemb); \
1780 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
1781 MALLOC_TRACE("reallocarray(%p,%llu,%llu)", ptrV, (ULong)nmemb, (ULong)size ); \
1782 if (nmemb > 0 && (SizeT)-1 / nmemb < size) { \
1783 SET_ERRNO_ENOMEM; \
1784 MALLOC_TRACE(" = 0\n"); \
1785 return NULL; \
1787 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, nmemb*size ); \
1788 MALLOC_TRACE(" = %p\n", v ); \
1789 if (v == NULL) { \
1790 if (!(size*nmemb == 0U && info.clo_realloc_zero_bytes_frees == True)) {\
1791 VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \
1792 SET_ERRNO_ENOMEM; \
1795 MALLOC_TRACE(" = %p\n", v ); \
1796 return v; \
1799 #if defined(VGO_linux)
1800 REALLOC(VG_Z_LIBC_SONAME, realloc);
1801 REALLOC(SO_SYN_MALLOC, realloc);
1802 REALLOCARRAY(VG_Z_LIBC_SONAME, reallocarray);
1803 REALLOCARRAY(SO_SYN_MALLOC, reallocarray);
1805 #elif defined(VGO_freebsd)
1806 REALLOC(VG_Z_LIBC_SONAME, realloc);
1807 REALLOC(SO_SYN_MALLOC, realloc);
1808 REALLOCF(VG_Z_LIBC_SONAME, reallocf);
1809 REALLOCF(SO_SYN_MALLOC, reallocf);
1810 REALLOCARRAY(VG_Z_LIBC_SONAME, reallocarray);
1811 REALLOCARRAY(SO_SYN_MALLOC, reallocarray);
1813 #elif defined(VGO_darwin)
1814 REALLOC(VG_Z_LIBC_SONAME, realloc);
1815 REALLOC(SO_SYN_MALLOC, realloc);
1816 REALLOCF(VG_Z_LIBC_SONAME, reallocf);
1817 REALLOCF(SO_SYN_MALLOC, reallocf);
1818 ZONEREALLOC(VG_Z_LIBC_SONAME, malloc_zone_realloc);
1819 ZONEREALLOC(SO_SYN_MALLOC, malloc_zone_realloc);
1821 #elif defined(VGO_solaris)
1822 REALLOC(VG_Z_LIBC_SONAME, realloc);
1823 REALLOC(VG_Z_LIBUMEM_SO_1, realloc);
1824 REALLOC(SO_SYN_MALLOC, realloc);
1825 REALLOCARRAY(VG_Z_LIBC_SONAME, reallocarray);
1826 REALLOCARRAY(SO_SYN_MALLOC, reallocarray);
1827 #endif
1830 /*---------------------- memalign ----------------------*/
1833 * memalign is rather old and deprecated
1834 * Linux glibc will fixup the alignment
1835 * (unless it is greater than SIZE_MAX / 2 + 1
1836 * in which case it returns EINVAL)
1838 * musl libc just calls aligned_alloc
1840 * FreeBSD, undocumented, just calls aligned_alloc
1841 * with size rounded up to a multiple
1842 * of aligment
1844 * jemalloc mininum alignment is 1, must be a power of 2
1845 * it looks like excessively large alignment causes ENOMEM
1847 * Illumos does not allow an alignment of zero
1848 * Nor a size of zero
1849 * And the alignment must be a multiple of 4
1850 * (though the man page says that the alignment
1851 * must be a power of 2 at least the size of a word)
1853 * Does not exist on Darwin
1855 * tcmalloc seems to behave like glibc and we have
1856 * no way to switch at runtime
1860 /* Probably in the wrong place, this is the function
1861 called by posix_memalign, at least on macOS 10.13 */
1862 #define ZONEMEMALIGN(soname, fnname) \
1864 void* VG_REPLACE_FUNCTION_EZU(10100, soname, fnname)( \
1865 void* zone, SizeT alignment, SizeT n); \
1866 void* VG_REPLACE_FUNCTION_EZU(10100, soname, \
1867 fnname)(void* zone, SizeT alignment, SizeT n) \
1869 void* v; \
1870 SizeT orig_alignment = alignment; \
1871 struct AlignedAllocInfo aligned_alloc_info = { \
1872 .orig_alignment = alignment, \
1873 .size = n, \
1874 .alloc_kind = AllocKindPosixMemalign}; \
1876 DO_INIT; \
1877 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1878 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)zone); \
1879 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
1880 MALLOC_TRACE("zone_memalign(%p, al %llu, size %llu)", zone, \
1881 (ULong)alignment, (ULong)n); \
1883 if (alignment == 0 || alignment % sizeof(void*) != 0 || \
1884 (alignment & (alignment - 1)) != 0) { \
1885 SET_ERRNO_EINVAL; \
1886 return NULL; \
1888 /* Round up to minimum alignment if necessary. */ \
1889 if (alignment < VG_MIN_MALLOC_SZB) \
1890 alignment = VG_MIN_MALLOC_SZB; \
1892 /* Round up to nearest power-of-two if necessary (like glibc). */ \
1893 while (0 != (alignment & (alignment - 1))) \
1894 alignment++; \
1896 v = (void*)VALGRIND_NON_SIMD_CALL3(info.tl_memalign, alignment, \
1897 orig_alignment, n); \
1898 MALLOC_TRACE(" = %p\n", v); \
1899 if (!v) \
1900 SET_ERRNO_ENOMEM; \
1901 return v; \
1904 #if defined(VGO_freebsd)
1905 #define VG_MEMALIGN_MAKE_SIZE_MULTIPLE_ALIGN 1
1906 #else
1907 #define VG_MEMALIGN_MAKE_SIZE_MULTIPLE_ALIGN 0
1908 #endif
1910 #if defined(VGO_solaris)
1911 #define VG_MEMALIGN_ALIGN_POWER_TWO 0
1912 #define VG_MEMALIGN_NO_ALIGN_ZERO 1
1913 #else
1914 #define VG_MEMALIGN_ALIGN_POWER_TWO 1
1915 #define VG_MEMALIGN_NO_ALIGN_ZERO 0
1916 #endif
1918 #if defined(VGO_solaris)
1919 #define VG_MEMALIGN_ALIGN_FACTOR_FOUR 1
1920 #define VG_MEMALIGN_NO_ALIGN_ZERO 1
1921 #else
1922 #define VG_MEMALIGN_ALIGN_FACTOR_FOUR 0
1923 #define VG_MEMALIGN_NO_ALIGN_ZERO 0
1924 #endif
1926 #if defined(MUSL_LIBC)
1927 #define VG_MEMALIGN_NO_SIZE_ZERO 0
1928 #else
1929 #define VG_MEMALIGN_NO_SIZE_ZERO 1
1930 #endif
1933 #if defined(VGO_linux) && !defined(MUSL_LIBC)
1935 #define MEMALIGN(soname, fnname) \
1937 void* VG_REPLACE_FUNCTION_EZU(10110,soname,fnname) \
1938 ( SizeT alignment, SizeT n ); \
1939 void* VG_REPLACE_FUNCTION_EZU(10110,soname,fnname) \
1940 ( SizeT alignment, SizeT n ) \
1942 void* v; \
1943 SizeT orig_alignment = alignment; \
1944 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .size=n, .alloc_kind=AllocKindMemalign}; \
1946 DO_INIT; \
1947 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
1948 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1949 MALLOC_TRACE("memalign(al %llu, size %llu)", \
1950 (ULong)alignment, (ULong)n ); \
1952 /* Round up to minimum alignment if necessary. */ \
1953 if (alignment < VG_MIN_MALLOC_SZB) \
1954 alignment = VG_MIN_MALLOC_SZB; \
1956 /* Round up to nearest power-of-two if necessary (like glibc). */ \
1957 while (0 != (alignment & (alignment - 1))) alignment++; \
1959 v = (void*)VALGRIND_NON_SIMD_CALL3( info.tl_memalign, alignment, orig_alignment, n ); \
1960 MALLOC_TRACE(" = %p\n", v ); \
1961 if (!v) SET_ERRNO_ENOMEM; \
1962 return v; \
1965 #else
1967 #define MEMALIGN(soname, fnname) \
1969 void* VG_REPLACE_FUNCTION_EZU(10110, soname, fnname)(SizeT alignment, \
1970 SizeT size); \
1971 void* VG_REPLACE_FUNCTION_EZU(10110, soname, fnname)(SizeT alignment, \
1972 SizeT size) \
1974 void* mem; \
1975 SizeT orig_alignment = alignment; \
1976 struct AlignedAllocInfo aligned_alloc_info = { \
1977 .orig_alignment = alignment, \
1978 .size = size, \
1979 .alloc_kind = AllocKindMemalign}; \
1981 DO_INIT; \
1982 VERIFY_ALIGNMENT(&aligned_alloc_info); \
1983 MALLOC_TRACE("memalign(alignment %llu, size %llu)", (ULong)alignment, \
1984 (ULong)size); \
1985 if ((VG_MEMALIGN_NO_SIZE_ZERO && (size == 0)) || \
1986 (VG_MEMALIGN_NO_ALIGN_ZERO && (alignment == 0)) || \
1987 (VG_MEMALIGN_ALIGN_POWER_TWO && \
1988 (alignment & (alignment - 1)) != 0) || \
1989 (VG_MEMALIGN_ALIGN_FACTOR_FOUR && (alignment % 4 != 0))) { \
1990 SET_ERRNO_EINVAL; \
1991 MALLOC_TRACE(" = 0\n"); \
1992 return 0; \
1994 /* Round up to minimum alignment if necessary. */ \
1995 if (alignment < VG_MIN_MALLOC_SZB) \
1996 alignment = VG_MIN_MALLOC_SZB; \
1997 /* Solaris allows non-power of 2 alignment but not Valgrind. */ \
1998 while (0 != (alignment & (alignment - 1))) \
1999 alignment++; \
2001 if (VG_MEMALIGN_MAKE_SIZE_MULTIPLE_ALIGN) { \
2002 size = ((size + alignment - 1) / alignment) * alignment; \
2005 mem = (void*)VALGRIND_NON_SIMD_CALL3(info.tl_memalign, alignment, \
2006 orig_alignment, size); \
2008 if (!mem) \
2009 SET_ERRNO_ENOMEM; \
2011 MALLOC_TRACE(" = %p\n", mem); \
2013 return mem; \
2016 #endif
2018 #if defined(VGO_linux)
2019 MEMALIGN(VG_Z_LIBC_SONAME, memalign);
2020 MEMALIGN(SO_SYN_MALLOC, memalign);
2022 #elif defined(VGO_freebsd)
2023 MEMALIGN(VG_Z_LIBC_SONAME, memalign);
2024 MEMALIGN(SO_SYN_MALLOC, memalign);
2026 #elif defined(VGO_darwin)
2027 ZONEMEMALIGN(VG_Z_LIBC_SONAME, malloc_zone_memalign);
2028 ZONEMEMALIGN(SO_SYN_MALLOC, malloc_zone_memalign);
2030 #elif defined(VGO_solaris)
2031 MEMALIGN(VG_Z_LIBC_SONAME, memalign);
2032 MEMALIGN(VG_Z_LIBUMEM_SO_1, memalign);
2033 MEMALIGN(SO_SYN_MALLOC, memalign);
2035 #endif
2038 /*---------------------- valloc ----------------------*/
2040 #define VALLOC(soname, fnname) \
2042 void* VG_REPLACE_FUNCTION_EZU(10120,soname,fnname) ( SizeT size ); \
2043 void* VG_REPLACE_FUNCTION_EZU(10120,soname,fnname) ( SizeT size ) \
2045 void *mem; \
2046 static int pszB = 0; \
2047 if (pszB == 0) \
2048 pszB = my_getpagesize(); \
2049 DO_INIT; \
2050 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
2051 mem = (void*)VALGRIND_NON_SIMD_CALL3( info.tl_memalign, \
2052 pszB, pszB, size ); \
2054 if (!mem) SET_ERRNO_ENOMEM; \
2056 MALLOC_TRACE(" = %p\n", mem); \
2058 return mem; \
2061 #define ZONEVALLOC(soname, fnname) \
2063 void* VG_REPLACE_FUNCTION_EZU(10130,soname,fnname) \
2064 ( void *zone, SizeT size ); \
2065 void* VG_REPLACE_FUNCTION_EZU(10130,soname,fnname) \
2066 ( void *zone, SizeT size ) \
2068 static int pszB = 0; \
2069 if (pszB == 0) \
2070 pszB = my_getpagesize(); \
2071 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone); \
2072 return (void*)VALGRIND_NON_SIMD_CALL3( info.tl_memalign, \
2073 pszB, pszB, size); \
2076 #if defined(VGO_linux)
2077 VALLOC(VG_Z_LIBC_SONAME, valloc);
2078 VALLOC(SO_SYN_MALLOC, valloc);
2080 #elif defined(VGO_freebsd)
2081 VALLOC(VG_Z_LIBC_SONAME, valloc);
2082 VALLOC(SO_SYN_MALLOC, valloc);
2084 #elif defined(VGO_darwin)
2085 VALLOC(VG_Z_LIBC_SONAME, valloc);
2086 VALLOC(SO_SYN_MALLOC, valloc);
2087 ZONEVALLOC(VG_Z_LIBC_SONAME, malloc_zone_valloc);
2088 ZONEVALLOC(SO_SYN_MALLOC, malloc_zone_valloc);
2090 #elif defined(VGO_solaris)
2091 VALLOC(VG_Z_LIBC_SONAME, valloc);
2092 VALLOC(VG_Z_LIBUMEM_SO_1, valloc);
2093 VALLOC(SO_SYN_MALLOC, valloc);
2095 #endif
2098 /*---------------------- mallopt ----------------------*/
2100 /* Various compatibility wrapper functions, for glibc and libstdc++. */
2102 #define MALLOPT(soname, fnname) \
2104 int VG_REPLACE_FUNCTION_EZU(10140,soname,fnname) ( int cmd, int value ); \
2105 int VG_REPLACE_FUNCTION_EZU(10140,soname,fnname) ( int cmd, int value ) \
2107 /* In glibc-2.2.4, 1 denotes a successful return value for \
2108 mallopt */ \
2109 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(cmd); \
2110 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(value); \
2111 return 1; \
2114 #if defined(VGO_linux)
2115 MALLOPT(VG_Z_LIBC_SONAME, mallopt);
2116 MALLOPT(SO_SYN_MALLOC, mallopt);
2118 #elif defined(VGO_darwin)
2119 //MALLOPT(VG_Z_LIBC_SONAME, mallopt);
2121 #endif
2124 /*---------------------- malloc_trim ----------------------*/
2125 // Documentation says:
2126 // malloc_trim(size_t pad);
2128 // If possible, gives memory back to the system (via negative arguments to
2129 // sbrk) if there is unused memory at the `high' end of the malloc pool.
2130 // You can call this after freeing large blocks of memory to potentially
2131 // reduce the system-level memory requirements of a program. However, it
2132 // cannot guarantee to reduce memory. Under some allocation patterns,
2133 // some large free blocks of memory will be locked between two used
2134 // chunks, so they cannot be given back to the system.
2136 // The `pad' argument to malloc_trim represents the amount of free
2137 // trailing space to leave untrimmed. If this argument is zero, only the
2138 // minimum amount of memory to maintain internal data structures will be
2139 // left (one page or less). Non-zero arguments can be supplied to maintain
2140 // enough trailing space to service future expected allocations without
2141 // having to re-obtain memory from the system.
2143 // Malloc_trim returns 1 if it actually released any memory, else 0. On
2144 // systems that do not support "negative sbrks", it will always return 0.
2146 // For simplicity, we always return 0.
2147 #define MALLOC_TRIM(soname, fnname) \
2149 int VG_REPLACE_FUNCTION_EZU(10150,soname,fnname) ( SizeT pad ); \
2150 int VG_REPLACE_FUNCTION_EZU(10150,soname,fnname) ( SizeT pad ) \
2152 /* 0 denotes that malloc_trim() either wasn't able \
2153 to do anything, or was not implemented */ \
2154 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(pad); \
2155 return 0; \
2158 #if defined(VGO_linux)
2159 MALLOC_TRIM(VG_Z_LIBC_SONAME, malloc_trim);
2160 MALLOC_TRIM(SO_SYN_MALLOC, malloc_trim);
2162 #elif defined(VGO_darwin)
2163 //MALLOC_TRIM(VG_Z_LIBC_SONAME, malloc_trim);
2165 #endif
2168 /*---------------------- posix_memalign ----------------------*/
2170 #if defined(VGO_solaris)
2171 #define VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL 1
2172 #else
2173 #define VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL 0
2174 #endif
2176 #define POSIX_MEMALIGN(soname, fnname) \
2178 int VG_REPLACE_FUNCTION_EZU(10160,soname,fnname) \
2179 ( void **memptr, SizeT alignment, SizeT size ); \
2180 int VG_REPLACE_FUNCTION_EZU(10160,soname,fnname) \
2181 ( void **memptr, SizeT alignment, SizeT size ) \
2183 void *mem; \
2184 SizeT orig_alignment = alignment; \
2185 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .size=size, .alloc_kind=AllocKindPosixMemalign}; \
2187 DO_INIT; \
2188 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
2189 VERIFY_ALIGNMENT(&aligned_alloc_info); \
2190 MALLOC_TRACE("posix_memalign(al %llu, size %llu)\n", \
2191 (ULong)alignment, (ULong)size ); \
2192 /* Test whether the alignment argument is valid. It must be \
2193 a power of two multiple of sizeof (void *). */ \
2194 if (alignment == 0 \
2195 || alignment % sizeof (void *) != 0 \
2196 || (alignment & (alignment - 1)) != 0) { \
2197 MALLOC_TRACE(" = 0\n"); \
2198 return VKI_EINVAL; \
2200 if (VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL && \
2201 size == 0U) { \
2202 /* no allocation for zero size on Solaris/Illumos */ \
2203 *memptr = NULL; \
2204 MALLOC_TRACE(" = 0\n"); \
2205 return 0; \
2207 /* Round up to minimum alignment if necessary. */ \
2208 if (alignment < VG_MIN_MALLOC_SZB) \
2209 alignment = VG_MIN_MALLOC_SZB; \
2211 mem = (void*)VALGRIND_NON_SIMD_CALL3( info.tl_memalign, \
2212 alignment, orig_alignment, size ); \
2214 MALLOC_TRACE(" = %p\n", mem); \
2216 if (mem != NULL) { \
2217 *memptr = mem; \
2218 return 0; \
2221 return VKI_ENOMEM; \
2224 #if defined(VGO_linux)
2225 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
2226 POSIX_MEMALIGN(SO_SYN_MALLOC, posix_memalign);
2228 #elif defined(VGO_freebsd)
2229 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
2230 POSIX_MEMALIGN(SO_SYN_MALLOC, posix_memalign);
2232 #elif defined(VGO_darwin)
2233 #if (DARWIN_VERSIO >= DARWIN_10_6)
2234 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
2235 #endif
2237 #elif defined(VGO_solaris)
2238 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
2239 POSIX_MEMALIGN(SO_SYN_MALLOC, posix_memalign);
2241 #endif
2243 /*---------------------- aligned_alloc ----------------------*/
2246 * No OS does things the same way.
2248 * The C standard says "If the value of _alignment_ is not a valid
2249 * alignment supported by the implementation the function shall
2250 * fail by returning a null pointer".
2252 * Linux glibc. The man page claims that the alignment must be
2253 * a power of two and that size should be a multiple of alignment.
2254 * However the only case that returns EINVAL (glibc 2.34)
2255 * is if the alignement is > SIZE_MAX / 2 + 1
2256 * Also this is just a weak alias for memalign so this wrapper
2257 * has no effect on Linux glibc.
2259 * Linux musl. The alignment must be a power of 2 else
2260 * returns einval. The value of the alignment is clamped
2261 * to a minumum of UNIT (16).
2263 * FreeBSD. the man page claims alignment must be a power of 2.
2264 * UB if size is not an integral multiple of alignment.
2265 * The code checks that the alignment is a power of
2266 * 2 and not less than the minumum alignment (1)
2268 * Solaris. Doesn't seem to exist on 11.3
2269 * Illumos. Invalid if the size is 0, the alignment is 0, the
2270 * alignment is not a multiple of 4 (no power of 2
2271 * requirement even though the manpage claims is) or the
2272 * alignment is greater than MAX_ALIGN (whatever that is).
2273 * Wrapper function that just calls memalign
2275 * Darwin. Does enforce size being an integer multiple of
2276 * alignment.
2280 #if defined(VGO_darwin)
2281 #define VG_ALIGNED_ALLOC_SIZE_MULTIPLE_ALIGN 1
2282 #else
2283 #define VG_ALIGNED_ALLOC_SIZE_MULTIPLE_ALIGN 0
2284 #endif
2286 #if defined(VGO_solaris)
2287 #define VG_ALIGNED_ALLOC_ALIGN_POWER_TWO 0
2288 #else
2289 #define VG_ALIGNED_ALLOC_ALIGN_POWER_TWO 1
2290 #endif
2292 #if defined(VGO_solaris)
2293 #define VG_ALIGNED_ALLOC_ALIGN_FACTOR_FOUR 1
2294 #else
2295 #define VG_ALIGNED_ALLOC_ALIGN_FACTOR_FOUR 0
2296 #endif
2298 #if defined(MUSL_LIBC)
2299 #define VG_ALIGNED_ALLOC_NO_SIZE_ZERO 0
2300 #else
2301 #define VG_ALIGNED_ALLOC_NO_SIZE_ZERO 1
2302 #endif
2304 #if defined (VGO_linux) && !defined(MUSL_LIBC) && !defined(HAVE_GNU_LIBC_C17_ALIGNED_ALLOC)
2307 * Normally for GNU libc <= 2.37 aligned_alloc is a weak alias for memalign
2308 * so this redir is not used.
2309 * For libc 2.38 and later it is a separate function but then HAVE_GNU_LIBC_C17_ALIGNED_ALLOC
2310 * should be true and this version doesn't get compiled.
2311 * Leaving it here to be on the safe side.
2314 #define ALIGNED_ALLOC(soname, fnname) \
2316 void* VG_REPLACE_FUNCTION_EZU(10170,soname,fnname) \
2317 ( SizeT alignment, SizeT size ); \
2318 void* VG_REPLACE_FUNCTION_EZU(10170,soname,fnname) \
2319 ( SizeT alignment, SizeT size ) \
2321 void *mem; \
2322 SizeT orig_alignment = alignment; \
2323 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .size=size, .alloc_kind=AllocKindAlignedAlloc}; \
2325 DO_INIT; \
2326 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
2327 VERIFY_ALIGNMENT(&aligned_alloc_info); \
2328 MALLOC_TRACE("aligned_alloc(al %llu, size %llu)", \
2329 (ULong)alignment, (ULong)size ); \
2331 /* Round up to minimum alignment if necessary. */ \
2332 if (alignment < VG_MIN_MALLOC_SZB) \
2333 alignment = VG_MIN_MALLOC_SZB; \
2335 /* Round up to nearest power-of-two if necessary (like glibc). */ \
2336 while (0 != (alignment & (alignment - 1))) alignment++; \
2338 mem = (void*)VALGRIND_NON_SIMD_CALL3( info.tl_memalign, \
2339 alignment, orig_alignment, size ); \
2341 MALLOC_TRACE(" = %p\n", mem); \
2343 return mem; \
2346 #else
2348 #define ALIGNED_ALLOC(soname, fnname) \
2350 void* VG_REPLACE_FUNCTION_EZU(10170,soname,fnname) \
2351 ( SizeT alignment, SizeT size ); \
2352 void* VG_REPLACE_FUNCTION_EZU(10170,soname,fnname) \
2353 ( SizeT alignment, SizeT size ) \
2355 void *mem; \
2356 SizeT orig_alignment = alignment; \
2357 struct AlignedAllocInfo aligned_alloc_info = { .orig_alignment=alignment, .size=size, .alloc_kind=AllocKindAlignedAlloc}; \
2359 DO_INIT; \
2360 VERIFY_ALIGNMENT(&aligned_alloc_info); \
2361 MALLOC_TRACE("aligned_alloc(al %llu, size %llu)", \
2362 (ULong)alignment, (ULong)size ); \
2363 if ((VG_ALIGNED_ALLOC_NO_SIZE_ZERO && (alignment == 0)) \
2364 || (VG_ALIGNED_ALLOC_SIZE_MULTIPLE_ALIGN && (size % alignment != 0)) \
2365 || (VG_ALIGNED_ALLOC_ALIGN_POWER_TWO && (alignment & (alignment - 1)) != 0) \
2366 || (VG_ALIGNED_ALLOC_ALIGN_FACTOR_FOUR && (alignment % 4 != 0))) { \
2367 SET_ERRNO_EINVAL; \
2368 MALLOC_TRACE(" = 0\n"); \
2369 return 0; \
2372 /* Round up to minimum alignment if necessary. */ \
2373 if (alignment < VG_MIN_MALLOC_SZB) \
2374 alignment = VG_MIN_MALLOC_SZB; \
2375 /* Solaris allows non-power of 2 alignment but not Valgrind. */ \
2376 while (0 != (alignment & (alignment - 1))) alignment++; \
2378 mem = (void*)VALGRIND_NON_SIMD_CALL3( info.tl_memalign, \
2379 alignment, orig_alignment, size ); \
2381 if (!mem) SET_ERRNO_ENOMEM; \
2383 MALLOC_TRACE(" = %p\n", mem); \
2385 return mem; \
2387 #endif
2389 #if defined(VGO_linux)
2390 ALIGNED_ALLOC(VG_Z_LIBC_SONAME, aligned_alloc);
2391 ALIGNED_ALLOC(SO_SYN_MALLOC, aligned_alloc);
2393 #elif defined(VGO_freebsd)
2394 ALIGNED_ALLOC(G_Z_LIBC_SONAME, aligned_alloc);
2395 ALIGNED_ALLOC(SO_SYN_MALLOC, aligned_alloc);
2397 #elif defined(VGO_darwin)
2398 //ALIGNED_ALLOC(VG_Z_LIBC_SONAME, aligned_alloc);
2400 #elif defined(VGO_solaris)
2401 ALIGNED_ALLOC(VG_Z_LIBC_SONAME, aligned_alloc);
2402 ALIGNED_ALLOC(SO_SYN_MALLOC, aligned_alloc);
2404 #endif
2406 /*---------------------- malloc_usable_size ----------------------*/
2408 #define MALLOC_USABLE_SIZE(soname, fnname) \
2410 SizeT VG_REPLACE_FUNCTION_EZU(10180,soname,fnname) ( void* p ); \
2411 SizeT VG_REPLACE_FUNCTION_EZU(10180,soname,fnname) ( void* p ) \
2413 SizeT pszB; \
2415 DO_INIT; \
2416 MALLOC_TRACE("malloc_usable_size(%p)", p ); \
2417 if (NULL == p) \
2418 return 0; \
2420 pszB = (SizeT)VALGRIND_NON_SIMD_CALL1( info.tl_malloc_usable_size, p ); \
2421 MALLOC_TRACE(" = %llu\n", (ULong)pszB ); \
2423 return pszB; \
2426 #if defined(VGO_linux)
2427 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
2428 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, malloc_usable_size);
2429 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
2430 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, malloc_size);
2431 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
2432 || defined(VGPV_mips32_linux_android)
2433 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, dlmalloc_usable_size);
2434 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, dlmalloc_usable_size);
2435 # endif
2437 #elif defined(VGO_freebsd)
2438 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
2439 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, malloc_usable_size);
2441 #elif defined(VGO_darwin)
2442 //MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
2443 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
2444 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, malloc_size);
2446 #endif
2449 /*---------------------- (unimplemented) ----------------------*/
2451 /* Bomb out if we get any of these. */
2453 static void panic(const char *str) __attribute__((unused));
2454 static void panic(const char *str)
2456 VALGRIND_PRINTF_BACKTRACE("Program aborting because of call to %s\n", str);
2457 my_exit(1);
2460 #define PANIC(soname, fnname) \
2462 void VG_REPLACE_FUNCTION_EZU(10190,soname,fnname) ( void ); \
2463 void VG_REPLACE_FUNCTION_EZU(10190,soname,fnname) ( void ) \
2465 panic(#fnname); \
2468 #if defined(VGO_linux)
2469 PANIC(VG_Z_LIBC_SONAME, pvalloc);
2470 PANIC(VG_Z_LIBC_SONAME, malloc_get_state);
2471 PANIC(VG_Z_LIBC_SONAME, malloc_set_state);
2473 #elif defined(VGO_darwin)
2474 PANIC(VG_Z_LIBC_SONAME, pvalloc);
2475 PANIC(VG_Z_LIBC_SONAME, malloc_get_state);
2476 PANIC(VG_Z_LIBC_SONAME, malloc_set_state);
2478 #endif
2481 #define MALLOC_STATS(soname, fnname) \
2483 void VG_REPLACE_FUNCTION_EZU(10200,soname,fnname) ( void ); \
2484 void VG_REPLACE_FUNCTION_EZU(10200,soname,fnname) ( void ) \
2486 /* Valgrind's malloc_stats implementation does nothing. */ \
2489 #if defined(VGO_linux)
2490 MALLOC_STATS(VG_Z_LIBC_SONAME, malloc_stats);
2491 MALLOC_STATS(SO_SYN_MALLOC, malloc_stats);
2493 #elif defined(VGO_darwin)
2494 //MALLOC_STATS(VG_Z_LIBC_SONAME, malloc_stats);
2496 #endif
2499 /*---------------------- mallinfo ----------------------*/
2501 // mi must be static; if it is auto then Memcheck thinks it is
2502 // uninitialised when used by the caller of this function, because Memcheck
2503 // doesn't know that the call to mallinfo fills in mi.
2504 #define MALLINFO(soname, fnname) \
2506 struct vg_mallinfo VG_REPLACE_FUNCTION_EZU(10210,soname,fnname) ( void ); \
2507 struct vg_mallinfo VG_REPLACE_FUNCTION_EZU(10210,soname,fnname) ( void ) \
2509 static struct vg_mallinfo mi; \
2510 DO_INIT; \
2511 MALLOC_TRACE("mallinfo()\n"); \
2512 (void)VALGRIND_NON_SIMD_CALL1( info.mallinfo, &mi ); \
2513 return mi; \
2516 #if defined(VGO_linux)
2517 MALLINFO(VG_Z_LIBC_SONAME, mallinfo);
2518 MALLINFO(SO_SYN_MALLOC, mallinfo);
2520 #elif defined(VGO_darwin)
2521 //MALLINFO(VG_Z_LIBC_SONAME, mallinfo);
2523 #endif
2526 /*------------------ Darwin zone stuff ------------------*/
2528 #if defined(VGO_darwin)
2530 static size_t my_malloc_size ( void* zone, void* ptr )
2532 /* Implement "malloc_size" by handing the request through to the
2533 tool's .tl_usable_size method. */
2534 DO_INIT;
2535 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone);
2536 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) ptr);
2537 size_t res = (size_t)VALGRIND_NON_SIMD_CALL1(
2538 info.tl_malloc_usable_size, ptr);
2539 return res;
2542 /* Note that the (void*) casts below are a kludge which stops
2543 compilers complaining about the fact that the replacement
2544 functions aren't really of the right type. */
2545 static vki_malloc_zone_t vg_default_zone = {
2546 NULL, // reserved1
2547 NULL, // reserved2
2548 (void*)my_malloc_size, // JRS fixme: is this right?
2549 (void*)VG_REPLACE_FUNCTION_EZU(10020,VG_Z_LIBC_SONAME,malloc_zone_malloc),
2550 (void*)VG_REPLACE_FUNCTION_EZU(10060,VG_Z_LIBC_SONAME,malloc_zone_calloc),
2551 (void*)VG_REPLACE_FUNCTION_EZU(10130,VG_Z_LIBC_SONAME,malloc_zone_valloc),
2552 (void*)VG_REPLACE_FUNCTION_EZU(10040,VG_Z_LIBC_SONAME,malloc_zone_free),
2553 (void*)VG_REPLACE_FUNCTION_EZU(10080,VG_Z_LIBC_SONAME,malloc_zone_realloc),
2554 NULL, // GrP fixme: destroy
2555 "ValgrindMallocZone",
2556 NULL, // batch_malloc
2557 NULL, // batch_free
2558 NULL, // GrP fixme: introspect
2559 2, // version (GrP fixme 3?)
2560 (void*)VG_REPLACE_FUNCTION_EZU(10100,VG_Z_LIBC_SONAME,malloc_zone_memalign), // DDD: this field exists in Mac OS 10.6+
2561 NULL, /* free_definite_size */
2562 NULL, /* pressure_relief */
2566 #define DEFAULT_ZONE(soname, fnname) \
2568 void *VG_REPLACE_FUNCTION_EZU(10220,soname,fnname) ( void ); \
2569 void *VG_REPLACE_FUNCTION_EZU(10220,soname,fnname) ( void ) \
2571 return &vg_default_zone; \
2574 DEFAULT_ZONE(VG_Z_LIBC_SONAME, malloc_default_zone);
2575 DEFAULT_ZONE(SO_SYN_MALLOC, malloc_default_zone);
2576 DEFAULT_ZONE(VG_Z_LIBC_SONAME, malloc_default_purgeable_zone);
2577 DEFAULT_ZONE(SO_SYN_MALLOC, malloc_default_purgeable_zone);
2580 #define CREATE_ZONE(soname, fnname) \
2582 void *VG_REPLACE_FUNCTION_EZU(10230,soname,fnname)(size_t sz, unsigned fl); \
2583 void *VG_REPLACE_FUNCTION_EZU(10230,soname,fnname)(size_t sz, unsigned fl) \
2585 return &vg_default_zone; \
2587 CREATE_ZONE(VG_Z_LIBC_SONAME, malloc_create_zone);
2590 #define ZONE_FROM_PTR(soname, fnname) \
2592 void *VG_REPLACE_FUNCTION_EZU(10240,soname,fnname) ( void* ptr ); \
2593 void *VG_REPLACE_FUNCTION_EZU(10240,soname,fnname) ( void* ptr ) \
2595 return &vg_default_zone; \
2598 ZONE_FROM_PTR(VG_Z_LIBC_SONAME, malloc_zone_from_ptr);
2599 ZONE_FROM_PTR(SO_SYN_MALLOC, malloc_zone_from_ptr);
2602 // GrP fixme bypass libc's use of zone->introspect->check
2603 #define ZONE_CHECK(soname, fnname) \
2605 int VG_REPLACE_FUNCTION_EZU(10250,soname,fnname)(void* zone); \
2606 int VG_REPLACE_FUNCTION_EZU(10250,soname,fnname)(void* zone) \
2608 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2609 panic(#fnname); \
2610 return 1; \
2613 ZONE_CHECK(VG_Z_LIBC_SONAME, malloc_zone_check);
2614 ZONE_CHECK(SO_SYN_MALLOC, malloc_zone_check);
2617 #define ZONE_REGISTER(soname, fnname) \
2619 void VG_REPLACE_FUNCTION_EZU(10260,soname,fnname)(void* zone); \
2620 void VG_REPLACE_FUNCTION_EZU(10260,soname,fnname)(void* zone) \
2622 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2625 ZONE_REGISTER(VG_Z_LIBC_SONAME, malloc_zone_register);
2626 ZONE_REGISTER(SO_SYN_MALLOC, malloc_zone_register);
2629 #define ZONE_UNREGISTER(soname, fnname) \
2631 void VG_REPLACE_FUNCTION_EZU(10270,soname,fnname)(void* zone); \
2632 void VG_REPLACE_FUNCTION_EZU(10270,soname,fnname)(void* zone) \
2634 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2637 ZONE_UNREGISTER(VG_Z_LIBC_SONAME, malloc_zone_unregister);
2638 ZONE_UNREGISTER(SO_SYN_MALLOC, malloc_zone_unregister);
2641 #define ZONE_SET_NAME(soname, fnname) \
2643 void VG_REPLACE_FUNCTION_EZU(10280,soname,fnname)(void* zone, char* nm); \
2644 void VG_REPLACE_FUNCTION_EZU(10280,soname,fnname)(void* zone, char* nm) \
2646 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2649 ZONE_SET_NAME(VG_Z_LIBC_SONAME, malloc_set_zone_name);
2650 ZONE_SET_NAME(SO_SYN_MALLOC, malloc_set_zone_name);
2653 #define ZONE_GET_NAME(soname, fnname) \
2655 const char* VG_REPLACE_FUNCTION_EZU(10290,soname,fnname)(void* zone); \
2656 const char* VG_REPLACE_FUNCTION_EZU(10290,soname,fnname)(void* zone) \
2658 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2659 return vg_default_zone.zone_name; \
2662 ZONE_GET_NAME(VG_Z_LIBC_SONAME, malloc_get_zone_name);
2663 ZONE_GET_NAME(SO_SYN_MALLOC, malloc_get_zone_name);
2665 #endif /* defined(VGO_darwin) */
2668 /*------------------ (startup related) ------------------*/
2670 /* All the code in here is unused until this function is called */
2672 __attribute__((constructor))
2673 static void init(void)
2675 // This doesn't look thread-safe, but it should be ok... Bart says:
2677 // Every program I know of calls malloc() at least once before calling
2678 // pthread_create(). So init_done gets initialized before any thread is
2679 // created, and is only read when multiple threads are active
2680 // simultaneously. Such an access pattern is safe.
2682 // If the assignment to the variable init_done would be triggering a race
2683 // condition, both DRD and Helgrind would report this race.
2685 // By the way, although the init() function in
2686 // coregrind/m_replacemalloc/vg_replace_malloc.c has been declared
2687 // __attribute__((constructor)), it is not safe to remove the variable
2688 // init_done. This is because it is possible that malloc() and hence
2689 // init() gets called before shared library initialization finished.
2691 if (init_done)
2692 return;
2694 init_done = 1;
2696 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__GET_MALLOCFUNCS, &info,
2697 0, 0, 0, 0);
2700 /*--------------------------------------------------------------------*/
2701 /*--- end ---*/
2702 /*--------------------------------------------------------------------*/