solaris: aligned allocation issues
[valgrind.git] / coregrind / m_replacemalloc / vg_replace_malloc.c
bloba71aa4b5b26f4a2f2c00175ff57b2596cfd38fdc
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"
71 #define VG_ALIGN_ROUNDUP(size, alignment) (((size) + (alignment) - 1) & ~((alignment) - 1))
73 /* Assignment of behavioural equivalence class tags: 1NNNP is intended
74 to be reserved for the Valgrind core. Current usage:
76 10010 ALLOC_or_NULL
77 10020 ZONEALLOC_or_NULL
78 10030 ALLOC_or_BOMB
79 10040 ZONEFREE
80 10050 FREE
81 10060 ZONECALLOC
82 10070 CALLOC
83 10080 ZONEREALLOC
84 10090 REALLOC
85 10100 ZONEMEMALIGN
86 10110 MEMALIGN
87 10120 VALLOC
88 10130 ZONEVALLOC
89 10140 MALLOPT
90 10150 MALLOC_TRIM
91 10160 POSIX_MEMALIGN
92 10170 ALIGNED_ALL0C
93 10180 MALLOC_USABLE_SIZE
94 10190 PANIC
95 10200 MALLOC_STATS
96 10210 MALLINFO
97 10220 DEFAULT_ZONE
98 10230 CREATE_ZONE
99 10240 ZONE_FROM_PTR
100 10250 ZONE_CHECK
101 10260 ZONE_REGISTER
102 10270 ZONE_UNREGISTER
103 10280 ZONE_SET_NAME
104 10290 ZONE_GET_NAME
107 /* 2 Apr 05: the Portland Group compiler, which uses cfront/ARM style
108 mangling, could be supported properly by the redirects in this
109 module. Except we can't because it doesn't put its allocation
110 functions in libpgc.so but instead hardwires them into the
111 compilation unit holding main(), which makes them impossible to
112 intercept directly. Fortunately those fns seem to route everything
113 through to malloc/free.
115 mid-06: could be improved, since we can now intercept in the main
116 executable too.
118 2023-03:
120 There seem to be an ever increasing number of C++ new and delete
121 oveloads.
124 https://en.cppreference.com/w/cpp/memory/new/operator_new
125 https://en.cppreference.com/w/cpp/memory/new/operator_delete
127 We need to redirect the "replaceable" versions.
129 Anything "user-defined" or "class-specific" we can't know
130 about and the user needs to use memory pool annotation.
132 "non-alocating placement" as the name implies does not
133 allocate. Placement deletes are no-ops.
138 /* Call here to exit if we can't continue. On Android we can't call
139 _exit for some reason, so we have to blunt-instrument it. */
140 __attribute__ ((__noreturn__))
141 static inline void my_exit ( int x )
143 # if defined(VGPV_arm_linux_android) || defined(VGPV_mips32_linux_android) \
144 || defined(VGPV_arm64_linux_android)
145 __asm__ __volatile__(".word 0xFFFFFFFF");
146 while (1) {}
147 # elif defined(VGPV_x86_linux_android)
148 __asm__ __volatile__("ud2");
149 while (1) {}
150 # else
151 extern __attribute__ ((__noreturn__)) void _exit(int status);
152 _exit(x);
153 # endif
156 /* Same problem with getpagesize. */
157 static inline int my_getpagesize ( void )
159 # if defined(VGPV_arm_linux_android) \
160 || defined(VGPV_x86_linux_android) \
161 || defined(VGPV_mips32_linux_android) \
162 || defined(VGPV_arm64_linux_android)
163 return 4096; /* kludge - link failure on Android, for some reason */
164 # else
165 extern int getpagesize (void);
166 return getpagesize();
167 # endif
171 /* Compute the high word of the double-length unsigned product of U
172 and V. This is for calloc argument overflow checking; see comments
173 below. Algorithm as described in Hacker's Delight, chapter 8. */
174 static UWord umulHW ( UWord u, UWord v )
176 UWord u0, v0, w0, rHi;
177 UWord u1, v1, w1,w2,t;
178 UWord halfMask = sizeof(UWord)==4 ? (UWord)0xFFFF
179 : (UWord)0xFFFFFFFFULL;
180 UWord halfShift = sizeof(UWord)==4 ? 16 : 32;
181 u0 = u & halfMask;
182 u1 = u >> halfShift;
183 v0 = v & halfMask;
184 v1 = v >> halfShift;
185 w0 = u0 * v0;
186 t = u1 * v0 + (w0 >> halfShift);
187 w1 = t & halfMask;
188 w2 = t >> halfShift;
189 w1 = u0 * v1 + w1;
190 rHi = u1 * v1 + w2 + (w1 >> halfShift);
191 return rHi;
195 /*------------------------------------------------------------*/
196 /*--- Replacing malloc() et al ---*/
197 /*------------------------------------------------------------*/
199 /* This struct is initially empty. Before the first use of any of
200 these functions, we make a client request which fills in the
201 fields.
203 static struct vg_mallocfunc_info info;
204 static int init_done;
205 #define DO_INIT if (UNLIKELY(!init_done)) init()
207 /* Startup hook - called as init section */
208 __attribute__((constructor))
209 static void init(void);
211 #define MALLOC_TRACE(format, args...) \
212 if (info.clo_trace_malloc) { \
213 VALGRIND_INTERNAL_PRINTF(format, ## args ); }
215 // @todo PJF this mechanism doesn't work for MUSL C
216 // not sure why
217 // source here https://elixir.bootlin.com/musl/latest/source/src/errno/__errno_location.c#L4
219 /* Tries to set ERRNO to ENOMEM/EINVAL if possible. */
220 #if defined(VGO_linux)
221 extern int *__errno_location (void) __attribute__((weak));
222 #define SET_ERRNO_ENOMEM if (__errno_location) \
223 (*__errno_location ()) = VKI_ENOMEM;
224 #define SET_ERRNO_EINVAL {}
225 #elif defined(VGO_freebsd)
226 extern int *__error (void) __attribute__((weak));
227 #define SET_ERRNO_ENOMEM if (__error) \
228 (*__error ()) = VKI_ENOMEM;
229 #define SET_ERRNO_EINVAL if (__error) \
230 (*__error ()) = VKI_EINVAL;
231 #elif defined(VGO_solaris)
232 extern int *___errno (void) __attribute__((weak));
233 #define SET_ERRNO_ENOMEM if (___errno) \
234 (*___errno ()) = VKI_ENOMEM;
235 #define SET_ERRNO_EINVAL if (___errno) \
236 (*___errno ()) = VKI_EINVAL;
237 #elif defined(VGO_darwin)
238 extern int * __error(void) __attribute__((weak));
239 #define SET_ERRNO_ENOMEM if (__error) \
240 (*__error ()) = VKI_ENOMEM;
241 #define SET_ERRNO_EINVAL if (__error) \
242 (*__error ()) = VKI_EINVAL;
244 #else
245 #define SET_ERRNO_ENOMEM {}
246 #define SET_ERRNO_EINVAL {}
247 #endif
249 /* Below are new versions of malloc, __builtin_new, free,
250 __builtin_delete, calloc, realloc, memalign, and friends.
252 None of these functions are called directly - they are not meant to
253 be found by the dynamic linker. But ALL client calls to malloc()
254 and friends wind up here eventually. They get called because
255 vg_replace_malloc installs a bunch of code redirects which causes
256 Valgrind to use these functions rather than the ones they're
257 replacing.
260 /* The replacement functions are running on the simulated CPU.
261 The code on the simulated CPU does not necessarily use
262 all arguments. E.g. args can be ignored and/or only given
263 to a NON SIMD call.
264 The definedness of such 'unused' arguments will not be verified
265 by memcheck.
266 The macro 'TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED' allows
267 memcheck to detect such errors for the otherwise unused args.
268 Apart of allowing memcheck to detect an error, the macro
269 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED has no effect and
270 has a minimal cost for other tools replacing malloc functions.
272 Creating an "artificial" use of _x that works reliably is not entirely
273 straightforward. Simply comparing it against zero often produces no
274 warning if _x contains at least one nonzero bit is defined, because
275 Memcheck knows that the result of the comparison will be defined (cf
276 expensiveCmpEQorNE).
278 Really we want to PCast _x, so as to create a value which is entirely
279 undefined if any bit of _x is undefined. But there's no portable way to do
280 that.
282 #define TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(_x) \
283 if ((UWord)(_x) == 0) __asm__ __volatile__( "" ::: "memory" )
285 /*---------------------- malloc ----------------------*/
287 /* Generate a replacement for 'fnname' in object 'soname', which calls
288 'vg_replacement' to allocate memory. If that fails, return NULL.
290 #define ALLOC_or_NULL(soname, fnname, vg_replacement) \
292 void* VG_REPLACE_FUNCTION_EZU(10010,soname,fnname) (SizeT n); \
293 void* VG_REPLACE_FUNCTION_EZU(10010,soname,fnname) (SizeT n) \
295 void* v; \
297 DO_INIT; \
298 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
299 MALLOC_TRACE(#fnname "(%llu)", (ULong)n ); \
301 v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
302 MALLOC_TRACE(" = %p\n", v ); \
303 if (!v) SET_ERRNO_ENOMEM; \
304 return v; \
307 /* Generate a replacement for 'fnname' in object 'soname', which calls
308 'vg_replacement' to allocate aligned memory. If that fails, return NULL.
310 #define ALLOC_or_NULL_ALIGNED(soname, fnname, vg_replacement) \
312 void* VG_REPLACE_FUNCTION_EZU(10010,soname,fnname) (SizeT n, SizeT alignment); \
313 void* VG_REPLACE_FUNCTION_EZU(10010,soname,fnname) (SizeT n, SizeT alignment) \
315 void* v; \
317 DO_INIT; \
318 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
319 MALLOC_TRACE(#fnname "(size %llu, al %llu)", (ULong)n, (ULong)alignment ); \
321 if ((alignment == 0) \
322 || ((alignment & (alignment - 1)) != 0)) { \
323 return 0; \
326 /* Round up to minimum alignment if necessary. */ \
327 if (alignment < VG_MIN_MALLOC_SZB) \
328 alignment = VG_MIN_MALLOC_SZB; \
330 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_##vg_replacement, n, alignment ); \
331 MALLOC_TRACE(" = %p\n", v ); \
332 if (!v) SET_ERRNO_ENOMEM; \
333 return v; \
336 #define ZONEALLOC_or_NULL(soname, fnname, vg_replacement) \
338 void* VG_REPLACE_FUNCTION_EZU(10020,soname,fnname) (void *zone, SizeT n); \
339 void* VG_REPLACE_FUNCTION_EZU(10020,soname,fnname) (void *zone, SizeT n) \
341 void* v; \
343 DO_INIT; \
344 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone); \
345 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
346 MALLOC_TRACE(#fnname "(%p, %llu)", zone, (ULong)n ); \
348 v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
349 MALLOC_TRACE(" = %p\n", v ); \
350 return v; \
354 /* Generate a replacement for 'fnname' in object 'soname', which calls
355 'vg_replacement' to allocate memory. If that fails, it bombs the
356 system.
358 #define ALLOC_or_BOMB(soname, fnname, vg_replacement) \
360 void* VG_REPLACE_FUNCTION_EZU(10030,soname,fnname) (SizeT n); \
361 void* VG_REPLACE_FUNCTION_EZU(10030,soname,fnname) (SizeT n) \
363 void* v; \
365 DO_INIT; \
366 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
367 MALLOC_TRACE(#fnname "(%llu)", (ULong)n ); \
369 v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
370 MALLOC_TRACE(" = %p\n", v ); \
371 if (NULL == v) { \
372 VALGRIND_PRINTF( \
373 "new/new[] failed and should throw an exception, but Valgrind\n"); \
374 VALGRIND_PRINTF_BACKTRACE( \
375 " cannot throw exceptions and so is aborting instead. Sorry.\n"); \
376 my_exit(1); \
378 return v; \
381 /* Generate a replacement for 'fnname' in object 'soname', which calls
382 'vg_replacement' to allocate aligned memory. If that fails, it bombs the
383 system.
385 #define ALLOC_or_BOMB_ALIGNED(soname, fnname, vg_replacement) \
387 void* VG_REPLACE_FUNCTION_EZU(10030,soname,fnname) (SizeT n, SizeT alignment); \
388 void* VG_REPLACE_FUNCTION_EZU(10030,soname,fnname) (SizeT n, SizeT alignment) \
390 void* v; \
392 DO_INIT; \
393 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
394 MALLOC_TRACE(#fnname "(size %llu, al %llu)", (ULong)n, (ULong)alignment ); \
396 if ((alignment == 0) \
397 || ((alignment & (alignment - 1)) != 0)) { \
398 VALGRIND_PRINTF( \
399 "new/new[] aligned failed and should throw an exception, but Valgrind\n"); \
400 VALGRIND_PRINTF_BACKTRACE( \
401 " cannot throw exceptions and so is aborting instead. Sorry.\n"); \
402 my_exit(1); \
405 /* Round up to minimum alignment if necessary. */ \
406 if (alignment < VG_MIN_MALLOC_SZB) \
407 alignment = VG_MIN_MALLOC_SZB; \
409 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_##vg_replacement, n, alignment ); \
410 MALLOC_TRACE(" = %p\n", v ); \
411 if (NULL == v) { \
412 VALGRIND_PRINTF( \
413 "new/new[] aligned failed and should throw an exception, but Valgrind\n"); \
414 VALGRIND_PRINTF_BACKTRACE( \
415 " cannot throw exceptions and so is aborting instead. Sorry.\n"); \
416 my_exit(1); \
418 return v; \
421 // Each of these lines generates a replacement function:
422 // (from_so, from_fn, v's replacement)
423 // For some lines, we will also define a replacement function
424 // whose only purpose is to be a soname synonym place holder
425 // that can be replaced using --soname-synonyms.
427 // malloc
428 #if defined(VGO_linux)
429 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, malloc, malloc);
430 ALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc, malloc);
431 ALLOC_or_NULL(SO_SYN_MALLOC, malloc, malloc);
433 #elif defined(VGO_freebsd)
434 ALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc, malloc);
435 ALLOC_or_NULL(SO_SYN_MALLOC, malloc, malloc);
437 #elif defined(VGO_darwin)
438 ALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc, malloc);
439 ALLOC_or_NULL(SO_SYN_MALLOC, malloc, malloc);
440 ZONEALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc_zone_malloc, malloc);
441 ZONEALLOC_or_NULL(SO_SYN_MALLOC, malloc_zone_malloc, malloc);
443 #elif defined(VGO_solaris)
444 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, malloc, malloc);
445 ALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc, malloc);
446 ALLOC_or_NULL(VG_Z_LIBUMEM_SO_1, malloc, malloc);
447 ALLOC_or_NULL(SO_SYN_MALLOC, malloc, malloc);
449 #endif
452 /*---------------------- new ----------------------*/
454 #if defined(VGO_linux)
455 // operator new(unsigned int), not mangled (for gcc 2.96)
456 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, builtin_new, __builtin_new);
457 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, builtin_new, __builtin_new);
458 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, __builtin_new, __builtin_new);
459 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, __builtin_new, __builtin_new);
460 // operator new(unsigned int)
461 #if VG_WORDSIZE == 4
462 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj, __builtin_new);
463 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwj, __builtin_new);
464 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znwj, __builtin_new);
465 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwj, __builtin_new);
466 #endif
467 // operator new(unsigned long)
468 #if VG_WORDSIZE == 8
469 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm, __builtin_new);
470 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwm, __builtin_new);
471 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znwm, __builtin_new);
472 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwm, __builtin_new);
473 #endif
475 #elif defined(VGO_freebsd)
476 // operator new(unsigned int)
477 #if VG_WORDSIZE == 4
478 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj, __builtin_new);
479 ALLOC_or_BOMB(VG_Z_LIBCXX_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(SO_SYN_MALLOC, _Znwm, __builtin_new);
487 #endif
489 #elif defined(VGO_darwin)
490 // operator new(unsigned int)
491 #if VG_WORDSIZE == 4
492 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj, __builtin_new);
493 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwj, __builtin_new);
494 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znwj, __builtin_new);
495 #endif
496 // operator new(unsigned long)
497 #if VG_WORDSIZE == 8
498 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm, __builtin_new);
499 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znwm, __builtin_new);
500 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwm, __builtin_new);
501 #endif
503 #elif defined(VGO_solaris)
504 // operator new(unsigned int)
505 #if VG_WORDSIZE == 4
506 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj, __builtin_new);
507 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwj, __builtin_new);
508 #endif
509 // operator new(unsigned long)
510 #if VG_WORDSIZE == 8
511 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm, __builtin_new);
512 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znwm, __builtin_new);
513 #endif
515 #endif
517 /*------------------- C++17 new aligned -------------------*/
519 #if defined(VGO_linux)
520 // operator new(unsigned int, std::align_val_t)
521 #if VG_WORDSIZE == 4
522 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned);
523 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned);
524 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBC_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned);
525 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_t, __builtin_new_aligned);
526 #endif
527 // operator new(unsigned long, std::align_val_t)
528 #if VG_WORDSIZE == 8
529 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned);
530 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned);
531 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBC_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned);
532 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_t, __builtin_new_aligned);
533 #endif
535 #elif defined(VGO_freebsd)
536 // operator new(unsigned int)
537 #if VG_WORDSIZE == 4
538 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned);
539 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned);
540 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_t, __builtin_new_aligned);
541 #endif
542 // operator new(unsigned long)
543 #if VG_WORDSIZE == 8
544 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned);
545 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned);
546 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_t, __builtin_new_aligned);
547 #endif
549 #elif defined(VGO_darwin)
550 #if VG_WORDSIZE == 4
551 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned);
552 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned);
553 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_t, __builtin_new_aligned);
554 #endif
555 #if VG_WORDSIZE == 8
556 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned);
557 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned);
558 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_t, __builtin_new_aligned);
559 #endif
561 #elif defined(VGO_solaris)
562 // operator new(unsigned int, std::align_val_t)
563 #if VG_WORDSIZE == 4
564 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_t, __builtin_new_aligned);
565 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_t, __builtin_new_aligned);
566 #endif
567 // operator new(unsigned long, std::align_val_t)
568 #if VG_WORDSIZE == 8
569 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_t, __builtin_new_aligned);
570 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_t, __builtin_new_aligned);
572 #endif
574 #endif
577 /*---------------------- new nothrow ----------------------*/
579 #if defined(VGO_linux)
580 // operator new(unsigned, std::nothrow_t const&)
581 #if VG_WORDSIZE == 4
582 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
583 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
584 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
585 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwjRKSt9nothrow_t, __builtin_new);
586 #endif
587 // operator new(unsigned long, std::nothrow_t const&)
588 #if VG_WORDSIZE == 8
589 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
590 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
591 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
592 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwmRKSt9nothrow_t, __builtin_new);
593 #endif
595 #elif defined(VGO_freebsd)
596 // operator new(unsigned, std::nothrow_t const&)
597 #if VG_WORDSIZE == 4
598 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
599 ALLOC_or_BOMB(VG_Z_LIBCXX_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(SO_SYN_MALLOC, _ZnwmRKSt9nothrow_t, __builtin_new);
607 #endif
609 #elif defined(VGO_darwin)
610 // operator new(unsigned, std::nothrow_t const&)
611 #if VG_WORDSIZE == 4
612 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
613 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
614 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
615 #endif
616 // operator new(unsigned long, std::nothrow_t const&)
617 #if VG_WORDSIZE == 8
618 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
619 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
620 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwmRKSt9nothrow_t, __builtin_new);
621 #endif
623 #elif defined(VGO_solaris)
624 // operator new(unsigned, std::nothrow_t const&)
625 #if VG_WORDSIZE == 4
626 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t, __builtin_new);
627 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwjRKSt9nothrow_t, __builtin_new);
628 #endif
629 // operator new(unsigned long, std::nothrow_t const&)
630 #if VG_WORDSIZE == 8
631 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t, __builtin_new);
632 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnwmRKSt9nothrow_t, __builtin_new);
633 #endif
635 #endif
637 /*----------------- C++17 new aligned nothrow -----------------*/
639 #if defined(VGO_linux)
640 // operator new(unsigned int, std::align_val_t, std::nothrow_t const&)
641 #if VG_WORDSIZE == 4
642 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
643 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
644 ALLOC_or_NULL_ALIGNED(VG_Z_LIBC_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
645 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
646 #endif
647 // operator new(unsigned long, std::align_val_t, std::nothrow_t const&)
648 #if VG_WORDSIZE == 8
649 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
650 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
651 ALLOC_or_NULL_ALIGNED(VG_Z_LIBC_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
652 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
653 #endif
655 #elif defined(VGO_freebsd)
656 // operator new(unsigned int, std::align_val_t, std::nothrow_t const&)
657 #if VG_WORDSIZE == 4
658 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
659 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
660 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
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);
665 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
666 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
667 #endif
669 #elif defined(VGO_darwin)
670 #if VG_WORDSIZE == 4
671 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
672 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
673 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
674 #endif
675 #if VG_WORDSIZE == 8
676 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
677 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
678 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
679 #endif
681 #elif defined(VGO_solaris)
682 // operator new(unsigned, std::align_val_t, std::nothrow_t const&)
683 #if VG_WORDSIZE == 4
684 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, __ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
685 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, __ZnwjSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
686 #endif
687 // operator new(unsigned long, std::align_val_t, std::nothrow_t const&)
688 #if VG_WORDSIZE == 8
689 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
690 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnwmSt11align_val_tRKSt9nothrow_t, __builtin_new_aligned);
691 #endif
693 #endif
696 /*---------------------- new [] ----------------------*/
698 #if defined(VGO_linux)
699 // operator new[](unsigned int), not mangled (for gcc 2.96)
700 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, __builtin_vec_new, __builtin_vec_new );
701 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, __builtin_vec_new, __builtin_vec_new );
702 // operator new[](unsigned int)
703 #if VG_WORDSIZE == 4
704 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj, __builtin_vec_new );
705 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znaj, __builtin_vec_new );
706 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znaj, __builtin_vec_new );
707 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znaj, __builtin_vec_new );
708 #endif
709 // operator new[](unsigned long),
710 #if VG_WORDSIZE == 8
711 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam, __builtin_vec_new );
712 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znam, __builtin_vec_new );
713 ALLOC_or_BOMB(VG_Z_LIBC_SONAME, _Znam, __builtin_vec_new );
714 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znam, __builtin_vec_new );
715 #endif
717 #elif defined(VGO_freebsd)
718 // operator new[](unsigned int)
719 #if VG_WORDSIZE == 4
720 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj, __builtin_vec_new );
721 ALLOC_or_BOMB(VG_Z_LIBCXX_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(SO_SYN_MALLOC, _Znam, __builtin_vec_new );
729 #endif
731 #elif defined(VGO_darwin)
732 // operator new[](unsigned int)
733 #if VG_WORDSIZE == 4
734 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj, __builtin_vec_new );
735 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znaj, __builtin_vec_new );
736 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znaj, __builtin_vec_new );
737 #endif
738 // operator new[](unsigned long)
739 #if VG_WORDSIZE == 8
740 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam, __builtin_vec_new );
741 ALLOC_or_BOMB(VG_Z_LIBCXX_SONAME, _Znam, __builtin_vec_new );
742 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znam, __builtin_vec_new );
743 #endif
745 #elif defined(VGO_solaris)
746 // operator new[](unsigned int)
747 #if VG_WORDSIZE == 4
748 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj, __builtin_vec_new );
749 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znaj, __builtin_vec_new );
750 #endif
751 // operator new[](unsigned long)
752 #if VG_WORDSIZE == 8
753 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam, __builtin_vec_new );
754 ALLOC_or_BOMB(SO_SYN_MALLOC, _Znam, __builtin_vec_new );
755 #endif
757 #endif
759 /*------------------ C++ 17 new aligned [] ------------------*/
761 #if defined(VGO_linux)
762 // operator new[](unsigned int, std::align_val_t)
763 #if VG_WORDSIZE == 4
764 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
765 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
766 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBC_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
767 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
768 #endif
769 // operator new[](unsigned long, std::align_val_t)
770 #if VG_WORDSIZE == 8
771 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
772 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
773 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBC_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
774 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
775 #endif
777 #elif defined(VGO_freebsd)
778 // operator new[](unsigned int, std::align_val_t)
779 #if VG_WORDSIZE == 4
780 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
781 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
782 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
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 );
787 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
788 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
789 #endif
791 #elif defined(VGO_darwin)
793 #if VG_WORDSIZE == 4
794 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
795 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
796 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
797 #endif
798 // operator new[](unsigned long, std::align_val_t)
799 #if VG_WORDSIZE == 8
800 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
801 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
802 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
803 #endif
805 #elif defined(VGO_solaris)
806 // operator new[](unsigned int, std::align_val_t)
807 #if VG_WORDSIZE == 4
808 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
809 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_t, __builtin_vec_new_aligned );
810 #endif
811 // operator new[](unsigned long, std::align_val_t)
812 #if VG_WORDSIZE == 8
813 ALLOC_or_BOMB_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
814 ALLOC_or_BOMB_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_t, __builtin_vec_new_aligned );
815 #endif
817 #endif
820 /*---------------------- new [] nothrow ----------------------*/
822 #if defined(VGO_linux)
823 // operator new[](unsigned, std::nothrow_t const&)
824 #if VG_WORDSIZE == 4
825 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
826 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
827 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
828 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnajRKSt9nothrow_t, __builtin_vec_new );
829 #endif
830 // operator new[](unsigned long, std::nothrow_t const&)
831 #if VG_WORDSIZE == 8
832 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
833 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
834 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
835 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnamRKSt9nothrow_t, __builtin_vec_new );
836 #endif
838 #elif defined(VGO_freebsd)
839 // operator new[](unsigned, std::nothrow_t const&)
840 #if VG_WORDSIZE == 4
841 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
842 ALLOC_or_NULL(VG_Z_LIBCXX_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(SO_SYN_MALLOC, _ZnamRKSt9nothrow_t, __builtin_vec_new );
850 #endif
852 #elif defined(VGO_darwin)
853 // operator new[](unsigned, std::nothrow_t const&)
854 #if VG_WORDSIZE == 4
855 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
856 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
857 ALLOC_or_NULL(VG_Z_LIBC_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
858 #endif
859 // operator new[](unsigned long, std::nothrow_t const&)
860 #if VG_WORDSIZE == 8
861 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
862 ALLOC_or_NULL(VG_Z_LIBCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
863 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnamRKSt9nothrow_t, __builtin_vec_new );
864 #endif
866 #elif defined(VGO_solaris)
867 // operator new[](unsigned, std::nothrow_t const&)
868 #if VG_WORDSIZE == 4
869 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
870 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnajRKSt9nothrow_t, __builtin_vec_new );
871 #endif
872 // operator new[](unsigned long, std::nothrow_t const&)
873 #if VG_WORDSIZE == 8
874 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
875 ALLOC_or_NULL(SO_SYN_MALLOC, _ZnamRKSt9nothrow_t, __builtin_vec_new );
876 #endif
878 #endif
880 /*----------------- C++17 new aligned [] nothrow -----------------*/
882 #if defined(VGO_linux)
883 // operator new[](unsigned int, std::align_val_t, std::nothrow_t const&)
884 #if VG_WORDSIZE == 4
885 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
886 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
887 ALLOC_or_NULL_ALIGNED(VG_Z_LIBC_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
888 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
889 #endif
890 // operator new[](unsigned long, std::align_val_t, std::nothrow_t const&)
891 #if VG_WORDSIZE == 8
892 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
893 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
894 ALLOC_or_NULL_ALIGNED(VG_Z_LIBC_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
895 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
896 #endif
898 #elif defined(VGO_freebsd)
899 // operator new[](unsigned int, std::align_val_t, std::nothrow_t const&)
900 #if VG_WORDSIZE == 4
901 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
902 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
903 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
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 );
908 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
909 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
910 #endif
912 #elif defined(VGO_darwin)
914 #if VG_WORDSIZE == 4
915 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
916 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
917 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
918 #endif
919 // operator new[](unsigned long, std::align_val_t, std::nothrow_t const&)
920 #if VG_WORDSIZE == 8
921 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
922 ALLOC_or_NULL_ALIGNED(VG_Z_LIBCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
923 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
924 #endif
926 #elif defined(VGO_solaris)
927 // operator new[](unsigned int, std::align_val_t, std::nothrow_t const&)
928 #if VG_WORDSIZE == 4
929 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
930 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnajSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
931 #endif
932 // operator new[](unsigned long, std::align_val_t, std::nothrow_t const&)
933 #if VG_WORDSIZE == 8
934 ALLOC_or_NULL_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
935 ALLOC_or_NULL_ALIGNED(SO_SYN_MALLOC, _ZnamSt11align_val_tRKSt9nothrow_t, __builtin_vec_new_aligned );
936 #endif
938 #endif
940 /*---------------------- free ----------------------*/
942 /* Generate a replacement for 'fnname' in object 'soname', which calls
943 'vg_replacement' to free previously allocated memory.
945 #define ZONEFREE(soname, fnname, vg_replacement) \
947 void VG_REPLACE_FUNCTION_EZU(10040,soname,fnname) (void *zone, void *p); \
948 void VG_REPLACE_FUNCTION_EZU(10040,soname,fnname) (void *zone, void *p) \
950 DO_INIT; \
951 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)zone ^ (UWord)p); \
952 MALLOC_TRACE(#fnname "(%p, %p)\n", zone, p ); \
953 if (p == NULL) \
954 return; \
955 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
958 #define FREE(soname, fnname, vg_replacement) \
960 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p); \
961 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p) \
963 DO_INIT; \
964 MALLOC_TRACE(#fnname "(%p)\n", p ); \
965 if (p == NULL) \
966 return; \
967 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
971 #if defined(VGO_linux)
972 FREE(VG_Z_LIBSTDCXX_SONAME, free, free );
973 FREE(VG_Z_LIBC_SONAME, free, free );
974 FREE(SO_SYN_MALLOC, free, free );
976 #elif defined(VGO_freebsd)
977 FREE(VG_Z_LIBC_SONAME, free, free );
978 FREE(SO_SYN_MALLOC, free, free );
980 #elif defined(VGO_darwin)
981 FREE(VG_Z_LIBC_SONAME, free, free );
982 FREE(SO_SYN_MALLOC, free, free );
983 ZONEFREE(VG_Z_LIBC_SONAME, malloc_zone_free, free );
984 ZONEFREE(SO_SYN_MALLOC, malloc_zone_free, free );
986 #elif defined(VGO_solaris)
987 FREE(VG_Z_LIBC_SONAME, free, free );
988 FREE(VG_Z_LIBUMEM_SO_1, free, free );
989 FREE(SO_SYN_MALLOC, free, free );
991 #endif
994 /*---------------------- cfree ----------------------*/
996 // cfree
997 #if defined(VGO_linux)
998 FREE(VG_Z_LIBSTDCXX_SONAME, cfree, free );
999 FREE(VG_Z_LIBC_SONAME, cfree, free );
1000 FREE(SO_SYN_MALLOC, cfree, free );
1002 #elif defined(VGO_darwin)
1003 //FREE(VG_Z_LIBSTDCXX_SONAME, cfree, free );
1004 //FREE(VG_Z_LIBC_SONAME, cfree, free );
1006 #elif defined(VGO_solaris)
1007 FREE(VG_Z_LIBC_SONAME, cfree, free );
1008 /* libumem does not implement cfree(). */
1009 //FREE(VG_Z_LIBUMEM_SO_1, cfree, free );
1010 FREE(SO_SYN_MALLOC, cfree, free );
1012 #endif
1015 /*---------------------- delete ----------------------*/
1017 #if defined(VGO_linux)
1018 // operator delete(void*), not mangled (for gcc 2.96)
1019 FREE(VG_Z_LIBSTDCXX_SONAME, __builtin_delete, __builtin_delete );
1020 FREE(VG_Z_LIBC_SONAME, __builtin_delete, __builtin_delete );
1021 // operator delete(void*)
1022 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete );
1023 FREE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete );
1024 FREE(VG_Z_LIBC_SONAME, _ZdlPv, __builtin_delete );
1025 FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete );
1027 #elif defined(VGO_freebsd)
1028 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete );
1029 FREE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete );
1030 FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete );
1032 #elif defined(VGO_darwin)
1033 // operator delete(void*)
1034 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete );
1035 FREE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete );
1036 FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete );
1038 #elif defined(VGO_solaris)
1039 // operator delete(void*)
1040 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete );
1041 FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete );
1043 #endif
1045 /*------------------- C++14 delete sized -------------------*/
1047 #define DELETE_SIZED(soname, fnname, vg_replacement) \
1049 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size); \
1050 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size) \
1052 DO_INIT; \
1053 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)size); \
1054 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1055 if (p == NULL) \
1056 return; \
1057 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1060 #if defined(VGO_linux)
1061 // operator delete(void*, unsigned int)
1062 #if __SIZEOF_SIZE_T__ == 4
1063 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete );
1064 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete );
1065 DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdlPvj, __builtin_delete );
1066 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete );
1067 // operator delete(void*, unsigned long)
1068 #elif __SIZEOF_SIZE_T__ == 8
1069 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete );
1070 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete );
1071 DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdlPvm, __builtin_delete );
1072 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete );
1073 #endif
1075 #elif defined(VGO_freebsd)
1076 // operator delete(void*, unsigned int)
1077 #if __SIZEOF_SIZE_T__ == 4
1078 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete );
1079 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete );
1080 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete );
1081 #elif __SIZEOF_SIZE_T__ == 8
1082 // operator delete(void*, unsigned long)
1083 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete );
1084 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete );
1085 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete );
1086 #endif
1088 #elif defined(VGO_darwin)
1089 // operator delete(void*, unsigned int)
1090 #if __SIZEOF_SIZE_T__ == 4
1091 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete );
1092 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete );
1093 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete );
1094 #elif __SIZEOF_SIZE_T__ == 8
1095 // operator delete(void*, unsigned long)
1096 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete );
1097 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete );
1098 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete );
1099 #endif
1101 #elif defined(VGO_solaris)
1102 // operator delete(void*, unsigned long)
1103 #if __SIZEOF_SIZE_T__ == 4
1104 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete );
1105 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete );
1106 #elif __SIZEOF_SIZE_T__ == 8
1107 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete );
1108 DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete );
1109 #endif
1111 #endif
1113 /*------------------- C++17 delete aligned -------------------*/
1115 #define DELETE_ALIGNED(soname, fnname, vg_replacement) \
1117 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT alignment); \
1118 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT alignment) \
1120 DO_INIT; \
1121 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)alignment); \
1122 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1123 if (p == NULL) \
1124 return; \
1125 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1128 #define DELETE_SIZED_ALIGNED(soname, fnname, vg_replacement) \
1130 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size, SizeT alignment); \
1131 void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size, SizeT alignment) \
1133 DO_INIT; \
1134 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)size); \
1135 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)alignment); \
1136 MALLOC_TRACE(#fnname "(%p)\n", p ); \
1137 if (p == NULL) \
1138 return; \
1139 (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
1142 #if defined(VGO_linux)
1143 // operator delete(void*, std::align_val_t)
1144 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1145 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1146 DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1147 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1149 // operator delete(void*, unsigned int, std::align_val_t)
1150 #if __SIZEOF_SIZE_T__ == 4
1151 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1152 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1153 DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1154 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1155 // operator delete(void*, unsigned long, std::align_val_t)
1156 #elif __SIZEOF_SIZE_T__ == 8
1157 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1158 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1159 DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1160 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1161 #endif
1163 #elif defined(VGO_freebsd)
1164 // operator delete(void*, std::align_val_t)
1165 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1166 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1167 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1169 // operator delete(void*, unsigned int, std::align_val_t)
1170 #if __SIZEOF_SIZE_T__ == 4
1171 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1172 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1173 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1174 // operator delete(void*, unsigned long, std::align_val_t)
1175 #elif __SIZEOF_SIZE_T__ == 8
1176 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1177 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1178 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1179 #endif
1181 #elif defined(VGO_darwin)
1183 // operator delete(void*, std::align_val_t)
1184 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1185 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1186 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1188 // operator delete(void*, unsigned int, std::align_val_t)
1189 #if __SIZEOF_SIZE_T__ == 4
1190 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1191 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1192 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1193 // operator delete(void*, unsigned long, std::align_val_t)
1194 #elif __SIZEOF_SIZE_T__ == 8
1195 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1196 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1197 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1198 #endif
1200 #elif defined(VGO_solaris)
1202 // operator delete(void*, std::align_val_t)
1203 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1204 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned );
1206 // operator delete(void*, unsigned int, std::align_val_t)
1207 #if __SIZEOF_SIZE_T__ == 4
1208 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1209 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned );
1210 // operator delete(void*, unsigned long, std::align_val_t)
1211 #elif __SIZEOF_SIZE_T__ == 8
1212 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1213 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned );
1214 #endif
1216 #endif
1218 /*---------------------- delete nothrow ----------------------*/
1220 #if defined(VGO_linux)
1221 // operator delete(void*, std::nothrow_t const&)
1222 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1223 FREE(VG_Z_LIBCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1224 FREE(VG_Z_LIBC_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1225 FREE(SO_SYN_MALLOC, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1227 #elif defined(VGO_freebsd)
1228 // operator delete(void*, std::nothrow_t const&)
1229 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1230 FREE(VG_Z_LIBCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1231 FREE(SO_SYN_MALLOC, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1233 #elif defined(VGO_darwin)
1234 // operator delete(void*, std::nothrow_t const&)
1235 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1236 FREE(VG_Z_LIBCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1237 FREE(SO_SYN_MALLOC, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1239 #elif defined(VGO_solaris)
1240 // operator delete(void*, std::nothrow_t const&)
1241 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1242 FREE(SO_SYN_MALLOC, _ZdlPvRKSt9nothrow_t, __builtin_delete );
1244 #endif
1246 /*---------------------- C++17 delete aligned nothrow ----------------------*/
1248 #if defined(VGO_linux)
1249 // operator delete(void*, std::align_val_t, std::nothrow_t const&)
1250 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1251 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1252 DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1253 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1255 // no sized version of this operator
1257 #elif defined(VGO_freebsd)
1258 // operator delete(void*, std::align_val_t, std::nothrow_t const&)
1259 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1260 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1261 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1263 #elif defined(VGO_darwin)
1265 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1266 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1267 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1269 #elif defined(VGO_solaris)
1270 // operator delete(void*, std::align_val_t, std::nothrow_t const&)
1271 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1272 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned );
1274 // no sized version of this operator
1276 #endif
1279 /*---------------------- delete [] ----------------------*/
1281 #if defined(VGO_linux)
1282 // operator delete[](void*), not mangled (for gcc 2.96)
1283 FREE(VG_Z_LIBSTDCXX_SONAME, __builtin_vec_delete, __builtin_vec_delete );
1284 FREE(VG_Z_LIBC_SONAME, __builtin_vec_delete, __builtin_vec_delete );
1285 // operator delete[](void*)
1286 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete );
1287 FREE(VG_Z_LIBCXX_SONAME, _ZdaPv, __builtin_vec_delete );
1288 FREE(VG_Z_LIBC_SONAME, _ZdaPv, __builtin_vec_delete );
1289 FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete );
1291 #elif defined(VGO_freebsd)
1292 // operator delete[](void*)
1293 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete );
1294 FREE(VG_Z_LIBCXX_SONAME, _ZdaPv, __builtin_vec_delete );
1295 FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete );
1297 #elif defined(VGO_darwin)
1298 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete );
1299 FREE(VG_Z_LIBCXX_SONAME, _ZdaPv, __builtin_vec_delete );
1300 FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete );
1302 #elif defined(VGO_solaris)
1303 // operator delete[](void*)
1304 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete );
1305 FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete );
1307 #endif
1309 /*---------------------- C++14 delete sized [] ----------------------*/
1311 #if defined(VGO_linux)
1312 // operator delete[](void*, unsigned int)
1313 #if __SIZEOF_SIZE_T__ == 4
1314 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete );
1315 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete );
1316 DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdaPvj, __builtin_vec_delete );
1317 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete );
1319 #elif __SIZEOF_SIZE_T__ == 8
1320 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete );
1321 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete );
1322 DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdaPvm, __builtin_vec_delete );
1323 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete );
1324 #endif
1326 #elif defined(VGO_freebsd)
1327 // operator delete[](void*, unsigned int)
1328 #if __SIZEOF_SIZE_T__ == 4
1329 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete );
1330 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete );
1331 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete );
1332 #elif __SIZEOF_SIZE_T__ == 8
1333 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete );
1334 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete );
1335 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete );
1336 #endif
1338 #elif defined(VGO_darwin)
1340 #if __SIZEOF_SIZE_T__ == 4
1341 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete );
1342 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete );
1343 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete );
1344 #elif __SIZEOF_SIZE_T__ == 8
1345 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete );
1346 DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete );
1347 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete );
1348 #endif
1350 #elif defined(VGO_solaris)
1351 // operator delete[](void*, unsigned int)
1352 #if __SIZEOF_SIZE_T__ == 4
1353 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete );
1354 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete );
1355 // operator delete[](void*, unsigned long)
1356 #elif __SIZEOF_SIZE_T__ == 8
1357 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete );
1358 DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete );
1359 #endif
1361 #endif
1363 /*---------------------- C++17 delete aligned [] ----------------------*/
1365 #if defined(VGO_linux)
1366 // operator delete[](void*, std::align_val_t)
1367 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1368 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1369 DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1370 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1372 // operator delete[](void*, unsigned int, std::align_val_t)
1373 #if __SIZEOF_SIZE_T__ == 4
1374 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1375 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1376 DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1377 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1378 // operator delete[](void*, unsigned long, std::align_val_t)
1379 #elif __SIZEOF_SIZE_T__ == 8
1380 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1381 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1382 DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1383 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1384 #endif
1386 #elif defined(VGO_freebsd)
1387 // operator delete[](void*, std::align_val_t)
1388 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1389 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1390 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1392 // operator delete[](void*, unsigned int, std::align_val_t)
1393 #if __SIZEOF_SIZE_T__ == 4
1394 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1395 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1396 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1397 // operator delete[](void*, unsigned long, std::align_val_t)
1398 #elif __SIZEOF_SIZE_T__ == 8
1399 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1400 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1401 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1402 #endif
1404 #elif defined(VGO_darwin)
1406 // operator delete[](void*, std::align_val_t)
1407 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1408 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1409 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1411 // operator delete[](void*, unsigned int, std::align_val_t)
1412 #if __SIZEOF_SIZE_T__ == 4
1413 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1414 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1415 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1416 // operator delete[](void*, unsigned long, std::align_val_t)
1417 #elif __SIZEOF_SIZE_T__ == 8
1418 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1419 DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1420 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1421 #endif
1424 #elif defined(VGO_solaris)
1425 // operator delete[](void*, std::align_val_t)
1426 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1427 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned );
1429 // operator delete[](void*, unsigned int, std::align_val_t)
1430 #if __SIZEOF_SIZE_T__ == 4
1431 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1432 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned );
1433 // operator delete[](void*, unsigned long)
1434 #elif __SIZEOF_SIZE_T__ == 8
1435 DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1436 DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned );
1437 #endif
1439 #endif
1441 /*---------------------- delete [] nothrow ----------------------*/
1443 #if defined(VGO_linux)
1444 // operator delete[](void*, std::nothrow_t const&)
1445 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1446 FREE(VG_Z_LIBCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1447 FREE(VG_Z_LIBC_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1448 FREE(SO_SYN_MALLOC, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1450 #elif defined(VGO_freebsd)
1451 // operator delete[](void*, std::nothrow_t const&)
1452 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1453 FREE(VG_Z_LIBCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1454 FREE(SO_SYN_MALLOC, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1456 #elif defined(VGO_darwin)
1457 // operator delete[](void*, std::nothrow_t const&)
1458 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1459 FREE(VG_Z_LIBCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1460 FREE(VG_Z_LIBC_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1462 #elif defined(VGO_solaris)
1463 // operator delete[](void*, std::nothrow_t const&)
1464 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1465 FREE(SO_SYN_MALLOC, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
1467 #endif
1469 /*---------------------- C+17 delete aligned [] nothrow ----------------------*/
1471 #if defined(VGO_linux)
1472 // operator delete[](void*, std::align_val_t, std::nothrow_t const&)
1473 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1474 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1475 DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1476 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1478 // no sized version of this operator
1480 #elif defined(VGO_freebsd)
1481 // operator delete[](void*, std::align_val_t, std::nothrow_t const&)
1482 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1483 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1484 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1486 #elif defined(VGO_darwin)
1488 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1489 DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1490 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1492 #elif defined(VGO_solaris)
1493 // operator delete[](void*, std::align_val_t, std::nothrow_t const&)
1494 DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1495 DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned );
1497 // no sized version of this operator
1499 #endif
1502 /*---------------------- calloc ----------------------*/
1504 #define ZONECALLOC(soname, fnname) \
1506 void* VG_REPLACE_FUNCTION_EZU(10060,soname,fnname) \
1507 ( void *zone, SizeT nmemb, SizeT size ); \
1508 void* VG_REPLACE_FUNCTION_EZU(10060,soname,fnname) \
1509 ( void *zone, SizeT nmemb, SizeT size ) \
1511 void* v; \
1513 DO_INIT; \
1514 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone); \
1515 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(nmemb); \
1516 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
1517 MALLOC_TRACE("zone_calloc(%p, %llu,%llu)", zone, (ULong)nmemb, (ULong)size ); \
1519 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_calloc, nmemb, size ); \
1520 MALLOC_TRACE(" = %p\n", v ); \
1521 return v; \
1524 #define CALLOC(soname, fnname) \
1526 void* VG_REPLACE_FUNCTION_EZU(10070,soname,fnname) \
1527 ( SizeT nmemb, SizeT size ); \
1528 void* VG_REPLACE_FUNCTION_EZU(10070,soname,fnname) \
1529 ( SizeT nmemb, SizeT size ) \
1531 void* v; \
1533 DO_INIT; \
1534 MALLOC_TRACE("calloc(%llu,%llu)", (ULong)nmemb, (ULong)size ); \
1536 /* Protect against overflow. See bug 24078. (that bug number is
1537 invalid. Which one really?) */ \
1538 /* But don't use division, since that produces an external symbol
1539 reference on ARM, in the form of a call to __aeabi_uidiv. It's
1540 normally OK, because ld.so manages to resolve it to something in the
1541 executable, or one of its shared objects. But that isn't guaranteed
1542 to be the case, and it has been observed to fail in rare cases, eg:
1543 echo x | valgrind /bin/sed -n "s/.*-\>\ //p"
1544 So instead compute the high word of the product and check it is zero. */ \
1545 if (umulHW(size, nmemb) != 0) return NULL; \
1546 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_calloc, nmemb, size ); \
1547 MALLOC_TRACE(" = %p\n", v ); \
1548 if (!v) SET_ERRNO_ENOMEM; \
1549 return v; \
1552 #if defined(VGO_linux)
1553 CALLOC(VG_Z_LIBC_SONAME, calloc);
1554 CALLOC(SO_SYN_MALLOC, calloc);
1556 #elif defined(VGO_freebsd)
1557 CALLOC(VG_Z_LIBC_SONAME, calloc);
1558 CALLOC(SO_SYN_MALLOC, calloc);
1560 #elif defined(VGO_darwin)
1561 CALLOC(VG_Z_LIBC_SONAME, calloc);
1562 CALLOC(SO_SYN_MALLOC, calloc);
1563 ZONECALLOC(VG_Z_LIBC_SONAME, malloc_zone_calloc);
1564 ZONECALLOC(SO_SYN_MALLOC, malloc_zone_calloc);
1566 #elif defined(VGO_solaris)
1567 CALLOC(VG_Z_LIBC_SONAME, calloc);
1568 CALLOC(VG_Z_LIBUMEM_SO_1, calloc);
1569 CALLOC(SO_SYN_MALLOC, calloc);
1571 #endif
1574 /*---------------------- realloc ----------------------*/
1576 #define ZONEREALLOC(soname, fnname) \
1578 void* VG_REPLACE_FUNCTION_EZU(10080,soname,fnname) \
1579 ( void *zone, void* ptrV, SizeT new_size ); \
1580 void* VG_REPLACE_FUNCTION_EZU(10080,soname,fnname) \
1581 ( void *zone, void* ptrV, SizeT new_size ) \
1583 void* v; \
1585 DO_INIT; \
1586 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \
1587 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \
1588 MALLOC_TRACE("zone_realloc(%p,%p,%llu)", zone, ptrV, (ULong)new_size ); \
1589 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
1590 MALLOC_TRACE(" = %p\n", v ); \
1591 if (v == NULL) { \
1592 if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\
1593 SET_ERRNO_ENOMEM; \
1596 return v; \
1599 #define REALLOC(soname, fnname) \
1601 void* VG_REPLACE_FUNCTION_EZU(10090,soname,fnname) \
1602 ( void* ptrV, SizeT new_size );\
1603 void* VG_REPLACE_FUNCTION_EZU(10090,soname,fnname) \
1604 ( void* ptrV, SizeT new_size ) \
1606 void* v; \
1608 DO_INIT; \
1609 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \
1610 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \
1611 MALLOC_TRACE("realloc(%p,%llu)", ptrV, (ULong)new_size ); \
1612 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
1613 MALLOC_TRACE(" = %p\n", v ); \
1614 if (v == NULL) { \
1615 if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\
1616 SET_ERRNO_ENOMEM; \
1619 return v; \
1622 #define REALLOCF(soname, fnname) \
1624 void* VG_REPLACE_FUNCTION_EZU(10091,soname,fnname) \
1625 ( void* ptrV, SizeT new_size );\
1626 void* VG_REPLACE_FUNCTION_EZU(10091,soname,fnname) \
1627 ( void* ptrV, SizeT new_size ) \
1629 void* v; \
1631 DO_INIT; \
1632 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \
1633 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \
1634 MALLOC_TRACE("reallocf(%p,%llu)", ptrV, (ULong)new_size ); \
1635 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
1636 MALLOC_TRACE(" = %p\n", v ); \
1637 if (v == NULL) { \
1638 if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\
1639 VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \
1640 SET_ERRNO_ENOMEM; \
1643 MALLOC_TRACE(" = %p\n", v ); \
1644 return v; \
1647 #if defined(VGO_linux)
1648 REALLOC(VG_Z_LIBC_SONAME, realloc);
1649 REALLOC(SO_SYN_MALLOC, realloc);
1651 #elif defined(VGO_freebsd)
1652 REALLOC(VG_Z_LIBC_SONAME, realloc);
1653 REALLOC(SO_SYN_MALLOC, realloc);
1654 REALLOCF(VG_Z_LIBC_SONAME, reallocf);
1655 REALLOCF(SO_SYN_MALLOC, reallocf);
1657 #elif defined(VGO_darwin)
1658 REALLOC(VG_Z_LIBC_SONAME, realloc);
1659 REALLOC(SO_SYN_MALLOC, realloc);
1660 ZONEREALLOC(VG_Z_LIBC_SONAME, malloc_zone_realloc);
1661 ZONEREALLOC(SO_SYN_MALLOC, malloc_zone_realloc);
1663 #elif defined(VGO_solaris)
1664 REALLOC(VG_Z_LIBC_SONAME, realloc);
1665 REALLOC(VG_Z_LIBUMEM_SO_1, realloc);
1666 REALLOC(SO_SYN_MALLOC, realloc);
1668 #endif
1671 /*---------------------- memalign ----------------------*/
1674 * memalign is rather old and deprecated
1675 * Linux glibc will fixup the alignment
1676 * (unless it is greater than SIZE_MAX / 2 + 1
1677 * in which case it returns EINVAL)
1679 * musl libc just calls aligned_alloc
1681 * FreeBSD, undocumented, just calls aligned_alloc
1682 * with size rounded up to a multiple
1683 * of aligment
1685 * jemalloc mininum alignment is 1, must be a power of 2
1686 * it looks like excessively large alignment causes ENOMEM
1688 * Illumos does not allow an alignment of zero
1689 * Nor a size of zero
1690 * And the alignment must be a multiple of 4
1691 * (though the man page says that the alignment
1692 * must be a power of 2 at least the size of a word)
1694 * Does not exist on Darwin
1696 * tcmalloc seems to behave like glibc and we have
1697 * no way to switch at runtime
1701 /* Probably in the wrong place, this is the function
1702 called by posix_memalign, at least on macOS 10.13 */
1703 #define ZONEMEMALIGN(soname, fnname) \
1705 void* VG_REPLACE_FUNCTION_EZU(10100,soname,fnname) \
1706 ( void *zone, SizeT alignment, SizeT n ); \
1707 void* VG_REPLACE_FUNCTION_EZU(10100,soname,fnname) \
1708 ( void *zone, SizeT alignment, SizeT n ) \
1710 void* v; \
1712 DO_INIT; \
1713 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone); \
1714 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
1715 MALLOC_TRACE("zone_memalign(%p, al %llu, size %llu)", \
1716 zone, (ULong)alignment, (ULong)n ); \
1718 if (alignment == 0 \
1719 || alignment % sizeof (void *) != 0 \
1720 || (alignment & (alignment - 1)) != 0) { \
1721 SET_ERRNO_EINVAL; \
1722 return NULL; \
1724 /* Round up to minimum alignment if necessary. */ \
1725 if (alignment < VG_MIN_MALLOC_SZB) \
1726 alignment = VG_MIN_MALLOC_SZB; \
1728 /* Round up to nearest power-of-two if necessary (like glibc). */ \
1729 while (0 != (alignment & (alignment - 1))) alignment++; \
1731 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, alignment, n ); \
1732 MALLOC_TRACE(" = %p\n", v ); \
1733 if (!v) SET_ERRNO_ENOMEM; \
1734 return v; \
1737 #if defined(VGO_freebsd)
1738 #define VG_MEMALIGN_MAKE_SIZE_MULTIPLE_ALIGN 1
1739 #else
1740 #define VG_MEMALIGN_MAKE_SIZE_MULTIPLE_ALIGN 0
1741 #endif
1743 #if defined(VGO_solaris)
1744 #define VG_MEMALIGN_ALIGN_POWER_TWO 0
1745 #define VG_MEMALIGN_NO_ALIGN_ZERO 1
1746 #else
1747 #define VG_MEMALIGN_ALIGN_POWER_TWO 1
1748 #define VG_MEMALIGN_NO_ALIGN_ZERO 0
1749 #endif
1751 #if defined(VGO_solaris)
1752 #define VG_MEMALIGN_ALIGN_FACTOR_FOUR 1
1753 #else
1754 #define VG_MEMALIGN_ALIGN_FACTOR_FOUR 0
1755 #endif
1757 #if defined(MUSL_LIBC)
1758 #define VG_MEMALIGN_NO_SIZE_ZERO 0
1759 #else
1760 #define VG_MEMALIGN_NO_SIZE_ZERO 1
1761 #endif
1764 #if defined(VGO_linux) && !defined(MUSL_LIBC)
1766 #define MEMALIGN(soname, fnname) \
1768 void* VG_REPLACE_FUNCTION_EZU(10110,soname,fnname) \
1769 ( SizeT alignment, SizeT n ); \
1770 void* VG_REPLACE_FUNCTION_EZU(10110,soname,fnname) \
1771 ( SizeT alignment, SizeT n ) \
1773 void* v; \
1775 DO_INIT; \
1776 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \
1777 MALLOC_TRACE("memalign(al %llu, size %llu)", \
1778 (ULong)alignment, (ULong)n ); \
1780 /* Round up to minimum alignment if necessary. */ \
1781 if (alignment < VG_MIN_MALLOC_SZB) \
1782 alignment = VG_MIN_MALLOC_SZB; \
1784 /* Round up to nearest power-of-two if necessary (like glibc). */ \
1785 while (0 != (alignment & (alignment - 1))) alignment++; \
1787 v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, alignment, n ); \
1788 MALLOC_TRACE(" = %p\n", v ); \
1789 if (!v) SET_ERRNO_ENOMEM; \
1790 return v; \
1793 #else
1795 #define MEMALIGN(soname, fnname) \
1797 void* VG_REPLACE_FUNCTION_EZU(10110,soname,fnname) \
1798 ( SizeT alignment, SizeT size ); \
1799 void* VG_REPLACE_FUNCTION_EZU(10110,soname,fnname) \
1800 ( SizeT alignment, SizeT size ) \
1802 void *mem; \
1804 DO_INIT; \
1805 MALLOC_TRACE("memalign(alignment %llu, size %llu)", \
1806 (ULong)alignment, (ULong)size ); \
1807 if ((VG_MEMALIGN_NO_SIZE_ZERO && (size == 0)) \
1808 || (VG_MEMALIGN_NO_ALIGN_ZERO && (alignment == 0)) \
1809 || (VG_MEMALIGN_ALIGN_POWER_TWO && (alignment & (alignment - 1)) != 0) \
1810 || (VG_MEMALIGN_ALIGN_FACTOR_FOUR && (alignment % 4 != 0))) { \
1811 SET_ERRNO_EINVAL; \
1812 return 0; \
1814 /* Round up to minimum alignment if necessary. */ \
1815 if (alignment < VG_MIN_MALLOC_SZB) \
1816 alignment = VG_MIN_MALLOC_SZB; \
1817 /* Solaris allows non-power of 2 alignment but not Valgrind. */ \
1818 while (0 != (alignment & (alignment - 1))) alignment++; \
1820 if (VG_MEMALIGN_MAKE_SIZE_MULTIPLE_ALIGN) { \
1821 size = ((size + alignment - 1)/alignment)*alignment; \
1824 mem = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, alignment, size ); \
1826 if (!mem) SET_ERRNO_ENOMEM; \
1828 return mem; \
1831 #endif
1833 #if defined(VGO_linux)
1834 MEMALIGN(VG_Z_LIBC_SONAME, memalign);
1835 MEMALIGN(SO_SYN_MALLOC, memalign);
1837 #elif defined(VGO_freebsd)
1838 MEMALIGN(VG_Z_LIBC_SONAME, memalign);
1839 MEMALIGN(SO_SYN_MALLOC, memalign);
1841 #elif defined(VGO_darwin)
1842 ZONEMEMALIGN(VG_Z_LIBC_SONAME, malloc_zone_memalign);
1843 ZONEMEMALIGN(SO_SYN_MALLOC, malloc_zone_memalign);
1845 #elif defined(VGO_solaris)
1846 MEMALIGN(VG_Z_LIBC_SONAME, memalign);
1847 MEMALIGN(VG_Z_LIBUMEM_SO_1, memalign);
1848 MEMALIGN(SO_SYN_MALLOC, memalign);
1850 #endif
1853 /*---------------------- valloc ----------------------*/
1855 #define VALLOC(soname, fnname) \
1857 void* VG_REPLACE_FUNCTION_EZU(10120,soname,fnname) ( SizeT size ); \
1858 void* VG_REPLACE_FUNCTION_EZU(10120,soname,fnname) ( SizeT size ) \
1860 void *mem; \
1861 static int pszB = 0; \
1862 if (pszB == 0) \
1863 pszB = my_getpagesize(); \
1864 DO_INIT; \
1865 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
1866 mem = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, \
1867 pszB, size ); \
1869 if (!mem) SET_ERRNO_ENOMEM; \
1871 return mem; \
1874 #define ZONEVALLOC(soname, fnname) \
1876 void* VG_REPLACE_FUNCTION_EZU(10130,soname,fnname) \
1877 ( void *zone, SizeT size ); \
1878 void* VG_REPLACE_FUNCTION_EZU(10130,soname,fnname) \
1879 ( void *zone, SizeT size ) \
1881 static int pszB = 0; \
1882 if (pszB == 0) \
1883 pszB = my_getpagesize(); \
1884 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone); \
1885 return (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, \
1886 pszB, size ); \
1889 #if defined(VGO_linux)
1890 VALLOC(VG_Z_LIBC_SONAME, valloc);
1891 VALLOC(SO_SYN_MALLOC, valloc);
1893 #elif defined(VGO_freebsd)
1894 VALLOC(VG_Z_LIBC_SONAME, valloc);
1895 VALLOC(SO_SYN_MALLOC, valloc);
1897 #elif defined(VGO_darwin)
1898 VALLOC(VG_Z_LIBC_SONAME, valloc);
1899 VALLOC(SO_SYN_MALLOC, valloc);
1900 ZONEVALLOC(VG_Z_LIBC_SONAME, malloc_zone_valloc);
1901 ZONEVALLOC(SO_SYN_MALLOC, malloc_zone_valloc);
1903 #elif defined(VGO_solaris)
1904 VALLOC(VG_Z_LIBC_SONAME, valloc);
1905 VALLOC(VG_Z_LIBUMEM_SO_1, valloc);
1906 VALLOC(SO_SYN_MALLOC, valloc);
1908 #endif
1911 /*---------------------- mallopt ----------------------*/
1913 /* Various compatibility wrapper functions, for glibc and libstdc++. */
1915 #define MALLOPT(soname, fnname) \
1917 int VG_REPLACE_FUNCTION_EZU(10140,soname,fnname) ( int cmd, int value ); \
1918 int VG_REPLACE_FUNCTION_EZU(10140,soname,fnname) ( int cmd, int value ) \
1920 /* In glibc-2.2.4, 1 denotes a successful return value for \
1921 mallopt */ \
1922 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(cmd); \
1923 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(value); \
1924 return 1; \
1927 #if defined(VGO_linux)
1928 MALLOPT(VG_Z_LIBC_SONAME, mallopt);
1929 MALLOPT(SO_SYN_MALLOC, mallopt);
1931 #elif defined(VGO_darwin)
1932 //MALLOPT(VG_Z_LIBC_SONAME, mallopt);
1934 #endif
1937 /*---------------------- malloc_trim ----------------------*/
1938 // Documentation says:
1939 // malloc_trim(size_t pad);
1941 // If possible, gives memory back to the system (via negative arguments to
1942 // sbrk) if there is unused memory at the `high' end of the malloc pool.
1943 // You can call this after freeing large blocks of memory to potentially
1944 // reduce the system-level memory requirements of a program. However, it
1945 // cannot guarantee to reduce memory. Under some allocation patterns,
1946 // some large free blocks of memory will be locked between two used
1947 // chunks, so they cannot be given back to the system.
1949 // The `pad' argument to malloc_trim represents the amount of free
1950 // trailing space to leave untrimmed. If this argument is zero, only the
1951 // minimum amount of memory to maintain internal data structures will be
1952 // left (one page or less). Non-zero arguments can be supplied to maintain
1953 // enough trailing space to service future expected allocations without
1954 // having to re-obtain memory from the system.
1956 // Malloc_trim returns 1 if it actually released any memory, else 0. On
1957 // systems that do not support "negative sbrks", it will always return 0.
1959 // For simplicity, we always return 0.
1960 #define MALLOC_TRIM(soname, fnname) \
1962 int VG_REPLACE_FUNCTION_EZU(10150,soname,fnname) ( SizeT pad ); \
1963 int VG_REPLACE_FUNCTION_EZU(10150,soname,fnname) ( SizeT pad ) \
1965 /* 0 denotes that malloc_trim() either wasn't able \
1966 to do anything, or was not implemented */ \
1967 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(pad); \
1968 return 0; \
1971 #if defined(VGO_linux)
1972 MALLOC_TRIM(VG_Z_LIBC_SONAME, malloc_trim);
1973 MALLOC_TRIM(SO_SYN_MALLOC, malloc_trim);
1975 #elif defined(VGO_darwin)
1976 //MALLOC_TRIM(VG_Z_LIBC_SONAME, malloc_trim);
1978 #endif
1981 /*---------------------- posix_memalign ----------------------*/
1983 #if defined(VGO_solaris)
1984 #define VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL 1
1985 #else
1986 #define VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL 0
1987 #endif
1989 #define POSIX_MEMALIGN(soname, fnname) \
1991 int VG_REPLACE_FUNCTION_EZU(10160,soname,fnname) \
1992 ( void **memptr, SizeT alignment, SizeT size ); \
1993 int VG_REPLACE_FUNCTION_EZU(10160,soname,fnname) \
1994 ( void **memptr, SizeT alignment, SizeT size ) \
1996 void *mem; \
1998 DO_INIT; \
1999 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
2000 MALLOC_TRACE("posix_memalign(al %llu, size %llu)\n", \
2001 (ULong)alignment, (ULong)size ); \
2002 /* Test whether the alignment argument is valid. It must be \
2003 a power of two multiple of sizeof (void *). */ \
2004 if (alignment == 0 \
2005 || alignment % sizeof (void *) != 0 \
2006 || (alignment & (alignment - 1)) != 0) { \
2007 return VKI_EINVAL; \
2009 if (VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL && \
2010 size == 0U) { \
2011 /* no allocation for zero size on Solaris/Illumos */ \
2012 *memptr = NULL; \
2013 return 0; \
2015 /* Round up to minimum alignment if necessary. */ \
2016 if (alignment < VG_MIN_MALLOC_SZB) \
2017 alignment = VG_MIN_MALLOC_SZB; \
2019 mem = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, \
2020 alignment, size ); \
2022 if (mem != NULL) { \
2023 *memptr = mem; \
2024 return 0; \
2027 return VKI_ENOMEM; \
2030 #if defined(VGO_linux)
2031 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
2032 POSIX_MEMALIGN(SO_SYN_MALLOC, posix_memalign);
2034 #elif defined(VGO_freebsd)
2035 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
2036 POSIX_MEMALIGN(SO_SYN_MALLOC, posix_memalign);
2038 #elif defined(VGO_darwin)
2039 #if (DARWIN_VERSIO >= DARWIN_10_6)
2040 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
2041 #endif
2043 #elif defined(VGO_solaris)
2044 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
2045 POSIX_MEMALIGN(SO_SYN_MALLOC, posix_memalign);
2047 #endif
2049 /*---------------------- aligned_alloc ----------------------*/
2052 * No OS does things the same way.
2054 * The C standard says "If the value of _alignment_ is not a valid
2055 * alignment supported by the implementation the function shall
2056 * fail by returning a null pointer".
2058 * Linux glibc. The man page claims that the alignment must be
2059 * a power of two and that size should be a multiple of alignment.
2060 * However the only case that returns EINVAL (glibc 2.34)
2061 * is if the alignement is > SIZE_MAX / 2 + 1
2062 * Also this is just a weak alias for memalign so this wrapper
2063 * has no effect on Linux glibc.
2065 * Linux musl. The alignment must be a power of 2 else
2066 * returns einval. The value of the alignment is clamped
2067 * to a minumum of UNIT (16).
2069 * FreeBSD. the man page claims alignment must be a power of 2.
2070 * UB if size is not an integral multiple of alignment.
2071 * The code checks that the alignment is a power of
2072 * 2 and not less than the minumum alignment (1)
2074 * Solaris. Doesn't seem to exist on 11.3
2075 * Illumos. Invalid if the size is 0, the alignment is 0, the
2076 * alignment is not a multiple of 4 (no power of 2
2077 * requirement even though the manpage claims is) or the
2078 * alignment is greater than MAX_ALIGN (whatever that is).
2079 * Wrapper function that just calls memalign
2081 * Darwin. Does enforce size being an integer multiple of
2082 * alignment.
2086 #if defined(VGO_darwin)
2087 #define VG_ALIGNED_ALLOC_SIZE_MULTIPLE_ALIGN 1
2088 #else
2089 #define VG_ALIGNED_ALLOC_SIZE_MULTIPLE_ALIGN 0
2090 #endif
2092 #if defined(VGO_solaris)
2093 #define VG_ALIGNED_ALLOC_ALIGN_POWER_TWO 0
2094 #else
2095 #define VG_ALIGNED_ALLOC_ALIGN_POWER_TWO 1
2096 #endif
2098 #if defined(VGO_solaris)
2099 #define VG_ALIGNED_ALLOC_ALIGN_FACTOR_FOUR 1
2100 #else
2101 #define VG_ALIGNED_ALLOC_ALIGN_FACTOR_FOUR 0
2102 #endif
2104 #if defined(MUSL_LIBC)
2105 #define VG_ALIGNED_ALLOC_NO_SIZE_ZERO 0
2106 #else
2107 #define VG_ALIGNED_ALLOC_NO_SIZE_ZERO 1
2108 #endif
2110 #if defined (VGO_linux) && !defined(MUSL_LIBC)
2112 #define ALIGNED_ALLOC(soname, fnname) \
2114 void* VG_REPLACE_FUNCTION_EZU(10170,soname,fnname) \
2115 ( SizeT alignment, SizeT size ); \
2116 void* VG_REPLACE_FUNCTION_EZU(10170,soname,fnname) \
2117 ( SizeT alignment, SizeT size ) \
2119 void *mem; \
2121 DO_INIT; \
2122 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(size); \
2123 MALLOC_TRACE("aligned_alloc(al %llu, size %llu)", \
2124 (ULong)alignment, (ULong)size ); \
2125 /* Test whether the alignment argument is valid. It must be \
2126 a power of two multiple of sizeof (void *). */ \
2127 if (alignment == 0 \
2128 || alignment % sizeof (void *) != 0 \
2129 || (alignment & (alignment - 1)) != 0) \
2130 return 0; \
2132 mem = VG_REPLACE_FUNCTION_EZU(10110,VG_Z_LIBC_SONAME,memalign) \
2133 (alignment, size); \
2135 return mem; \
2138 #else
2140 #define ALIGNED_ALLOC(soname, fnname) \
2142 void* VG_REPLACE_FUNCTION_EZU(10170,soname,fnname) \
2143 ( SizeT alignment, SizeT size ); \
2144 void* VG_REPLACE_FUNCTION_EZU(10170,soname,fnname) \
2145 ( SizeT alignment, SizeT size ) \
2147 void *mem; \
2149 DO_INIT; \
2150 MALLOC_TRACE("aligned_alloc(al %llu, size %llu)", \
2151 (ULong)alignment, (ULong)size ); \
2152 if ((VG_ALIGNED_ALLOC_NO_SIZE_ZERO && (alignment == 0)) \
2153 || (VG_ALIGNED_ALLOC_SIZE_MULTIPLE_ALIGN && (size % alignment != 0)) \
2154 || (VG_ALIGNED_ALLOC_ALIGN_POWER_TWO && (alignment & (alignment - 1)) != 0) \
2155 || (VG_ALIGNED_ALLOC_ALIGN_FACTOR_FOUR && (alignment % 4 != 0))) { \
2156 SET_ERRNO_EINVAL; \
2157 return 0; \
2160 /* Round up to minimum alignment if necessary. */ \
2161 if (alignment < VG_MIN_MALLOC_SZB) \
2162 alignment = VG_MIN_MALLOC_SZB; \
2163 /* Solaris allows non-power of 2 alignment but not Valgrind. */ \
2164 while (0 != (alignment & (alignment - 1))) alignment++; \
2166 mem = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, \
2167 alignment, size ); \
2169 if (!mem) SET_ERRNO_ENOMEM; \
2171 return mem; \
2173 #endif
2175 #if defined(VGO_linux)
2176 ALIGNED_ALLOC(VG_Z_LIBC_SONAME, aligned_alloc);
2177 ALIGNED_ALLOC(SO_SYN_MALLOC, aligned_alloc);
2179 #elif defined(VGO_freebsd)
2180 ALIGNED_ALLOC(G_Z_LIBC_SONAME, aligned_alloc);
2181 ALIGNED_ALLOC(SO_SYN_MALLOC, aligned_alloc);
2183 #elif defined(VGO_darwin)
2184 //ALIGNED_ALLOC(VG_Z_LIBC_SONAME, aligned_alloc);
2186 #elif defined(VGO_solaris)
2187 ALIGNED_ALLOC(VG_Z_LIBC_SONAME, aligned_alloc);
2188 ALIGNED_ALLOC(SO_SYN_MALLOC, aligned_alloc);
2190 #endif
2192 /*---------------------- malloc_usable_size ----------------------*/
2194 #define MALLOC_USABLE_SIZE(soname, fnname) \
2196 SizeT VG_REPLACE_FUNCTION_EZU(10180,soname,fnname) ( void* p ); \
2197 SizeT VG_REPLACE_FUNCTION_EZU(10180,soname,fnname) ( void* p ) \
2199 SizeT pszB; \
2201 DO_INIT; \
2202 MALLOC_TRACE("malloc_usable_size(%p)", p ); \
2203 if (NULL == p) \
2204 return 0; \
2206 pszB = (SizeT)VALGRIND_NON_SIMD_CALL1( info.tl_malloc_usable_size, p ); \
2207 MALLOC_TRACE(" = %llu\n", (ULong)pszB ); \
2209 return pszB; \
2212 #if defined(VGO_linux)
2213 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
2214 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, malloc_usable_size);
2215 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
2216 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, malloc_size);
2217 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
2218 || defined(VGPV_mips32_linux_android)
2219 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, dlmalloc_usable_size);
2220 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, dlmalloc_usable_size);
2221 # endif
2223 #elif defined(VGO_freebsd)
2224 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
2225 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, malloc_usable_size);
2227 #elif defined(VGO_darwin)
2228 //MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
2229 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
2230 MALLOC_USABLE_SIZE(SO_SYN_MALLOC, malloc_size);
2232 #endif
2235 /*---------------------- (unimplemented) ----------------------*/
2237 /* Bomb out if we get any of these. */
2239 static void panic(const char *str) __attribute__((unused));
2240 static void panic(const char *str)
2242 VALGRIND_PRINTF_BACKTRACE("Program aborting because of call to %s\n", str);
2243 my_exit(1);
2246 #define PANIC(soname, fnname) \
2248 void VG_REPLACE_FUNCTION_EZU(10190,soname,fnname) ( void ); \
2249 void VG_REPLACE_FUNCTION_EZU(10190,soname,fnname) ( void ) \
2251 panic(#fnname); \
2254 #if defined(VGO_linux)
2255 PANIC(VG_Z_LIBC_SONAME, pvalloc);
2256 PANIC(VG_Z_LIBC_SONAME, malloc_get_state);
2257 PANIC(VG_Z_LIBC_SONAME, malloc_set_state);
2259 #elif defined(VGO_darwin)
2260 PANIC(VG_Z_LIBC_SONAME, pvalloc);
2261 PANIC(VG_Z_LIBC_SONAME, malloc_get_state);
2262 PANIC(VG_Z_LIBC_SONAME, malloc_set_state);
2264 #endif
2267 #define MALLOC_STATS(soname, fnname) \
2269 void VG_REPLACE_FUNCTION_EZU(10200,soname,fnname) ( void ); \
2270 void VG_REPLACE_FUNCTION_EZU(10200,soname,fnname) ( void ) \
2272 /* Valgrind's malloc_stats implementation does nothing. */ \
2275 #if defined(VGO_linux)
2276 MALLOC_STATS(VG_Z_LIBC_SONAME, malloc_stats);
2277 MALLOC_STATS(SO_SYN_MALLOC, malloc_stats);
2279 #elif defined(VGO_darwin)
2280 //MALLOC_STATS(VG_Z_LIBC_SONAME, malloc_stats);
2282 #endif
2285 /*---------------------- mallinfo ----------------------*/
2287 // mi must be static; if it is auto then Memcheck thinks it is
2288 // uninitialised when used by the caller of this function, because Memcheck
2289 // doesn't know that the call to mallinfo fills in mi.
2290 #define MALLINFO(soname, fnname) \
2292 struct vg_mallinfo VG_REPLACE_FUNCTION_EZU(10210,soname,fnname) ( void ); \
2293 struct vg_mallinfo VG_REPLACE_FUNCTION_EZU(10210,soname,fnname) ( void ) \
2295 static struct vg_mallinfo mi; \
2296 DO_INIT; \
2297 MALLOC_TRACE("mallinfo()\n"); \
2298 (void)VALGRIND_NON_SIMD_CALL1( info.mallinfo, &mi ); \
2299 return mi; \
2302 #if defined(VGO_linux)
2303 MALLINFO(VG_Z_LIBC_SONAME, mallinfo);
2304 MALLINFO(SO_SYN_MALLOC, mallinfo);
2306 #elif defined(VGO_darwin)
2307 //MALLINFO(VG_Z_LIBC_SONAME, mallinfo);
2309 #endif
2312 /*------------------ Darwin zone stuff ------------------*/
2314 #if defined(VGO_darwin)
2316 static size_t my_malloc_size ( void* zone, void* ptr )
2318 /* Implement "malloc_size" by handing the request through to the
2319 tool's .tl_usable_size method. */
2320 DO_INIT;
2321 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone);
2322 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) ptr);
2323 size_t res = (size_t)VALGRIND_NON_SIMD_CALL1(
2324 info.tl_malloc_usable_size, ptr);
2325 return res;
2328 /* Note that the (void*) casts below are a kludge which stops
2329 compilers complaining about the fact that the replacement
2330 functions aren't really of the right type. */
2331 static vki_malloc_zone_t vg_default_zone = {
2332 NULL, // reserved1
2333 NULL, // reserved2
2334 (void*)my_malloc_size, // JRS fixme: is this right?
2335 (void*)VG_REPLACE_FUNCTION_EZU(10020,VG_Z_LIBC_SONAME,malloc_zone_malloc),
2336 (void*)VG_REPLACE_FUNCTION_EZU(10060,VG_Z_LIBC_SONAME,malloc_zone_calloc),
2337 (void*)VG_REPLACE_FUNCTION_EZU(10130,VG_Z_LIBC_SONAME,malloc_zone_valloc),
2338 (void*)VG_REPLACE_FUNCTION_EZU(10040,VG_Z_LIBC_SONAME,malloc_zone_free),
2339 (void*)VG_REPLACE_FUNCTION_EZU(10080,VG_Z_LIBC_SONAME,malloc_zone_realloc),
2340 NULL, // GrP fixme: destroy
2341 "ValgrindMallocZone",
2342 NULL, // batch_malloc
2343 NULL, // batch_free
2344 NULL, // GrP fixme: introspect
2345 2, // version (GrP fixme 3?)
2346 (void*)VG_REPLACE_FUNCTION_EZU(10100,VG_Z_LIBC_SONAME,malloc_zone_memalign), // DDD: this field exists in Mac OS 10.6+
2347 NULL, /* free_definite_size */
2348 NULL, /* pressure_relief */
2352 #define DEFAULT_ZONE(soname, fnname) \
2354 void *VG_REPLACE_FUNCTION_EZU(10220,soname,fnname) ( void ); \
2355 void *VG_REPLACE_FUNCTION_EZU(10220,soname,fnname) ( void ) \
2357 return &vg_default_zone; \
2360 DEFAULT_ZONE(VG_Z_LIBC_SONAME, malloc_default_zone);
2361 DEFAULT_ZONE(SO_SYN_MALLOC, malloc_default_zone);
2362 DEFAULT_ZONE(VG_Z_LIBC_SONAME, malloc_default_purgeable_zone);
2363 DEFAULT_ZONE(SO_SYN_MALLOC, malloc_default_purgeable_zone);
2366 #define CREATE_ZONE(soname, fnname) \
2368 void *VG_REPLACE_FUNCTION_EZU(10230,soname,fnname)(size_t sz, unsigned fl); \
2369 void *VG_REPLACE_FUNCTION_EZU(10230,soname,fnname)(size_t sz, unsigned fl) \
2371 return &vg_default_zone; \
2373 CREATE_ZONE(VG_Z_LIBC_SONAME, malloc_create_zone);
2376 #define ZONE_FROM_PTR(soname, fnname) \
2378 void *VG_REPLACE_FUNCTION_EZU(10240,soname,fnname) ( void* ptr ); \
2379 void *VG_REPLACE_FUNCTION_EZU(10240,soname,fnname) ( void* ptr ) \
2381 return &vg_default_zone; \
2384 ZONE_FROM_PTR(VG_Z_LIBC_SONAME, malloc_zone_from_ptr);
2385 ZONE_FROM_PTR(SO_SYN_MALLOC, malloc_zone_from_ptr);
2388 // GrP fixme bypass libc's use of zone->introspect->check
2389 #define ZONE_CHECK(soname, fnname) \
2391 int VG_REPLACE_FUNCTION_EZU(10250,soname,fnname)(void* zone); \
2392 int VG_REPLACE_FUNCTION_EZU(10250,soname,fnname)(void* zone) \
2394 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2395 panic(#fnname); \
2396 return 1; \
2399 ZONE_CHECK(VG_Z_LIBC_SONAME, malloc_zone_check);
2400 ZONE_CHECK(SO_SYN_MALLOC, malloc_zone_check);
2403 #define ZONE_REGISTER(soname, fnname) \
2405 void VG_REPLACE_FUNCTION_EZU(10260,soname,fnname)(void* zone); \
2406 void VG_REPLACE_FUNCTION_EZU(10260,soname,fnname)(void* zone) \
2408 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2411 ZONE_REGISTER(VG_Z_LIBC_SONAME, malloc_zone_register);
2412 ZONE_REGISTER(SO_SYN_MALLOC, malloc_zone_register);
2415 #define ZONE_UNREGISTER(soname, fnname) \
2417 void VG_REPLACE_FUNCTION_EZU(10270,soname,fnname)(void* zone); \
2418 void VG_REPLACE_FUNCTION_EZU(10270,soname,fnname)(void* zone) \
2420 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2423 ZONE_UNREGISTER(VG_Z_LIBC_SONAME, malloc_zone_unregister);
2424 ZONE_UNREGISTER(SO_SYN_MALLOC, malloc_zone_unregister);
2427 #define ZONE_SET_NAME(soname, fnname) \
2429 void VG_REPLACE_FUNCTION_EZU(10280,soname,fnname)(void* zone, char* nm); \
2430 void VG_REPLACE_FUNCTION_EZU(10280,soname,fnname)(void* zone, char* nm) \
2432 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2435 ZONE_SET_NAME(VG_Z_LIBC_SONAME, malloc_set_zone_name);
2436 ZONE_SET_NAME(SO_SYN_MALLOC, malloc_set_zone_name);
2439 #define ZONE_GET_NAME(soname, fnname) \
2441 const char* VG_REPLACE_FUNCTION_EZU(10290,soname,fnname)(void* zone); \
2442 const char* VG_REPLACE_FUNCTION_EZU(10290,soname,fnname)(void* zone) \
2444 TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(zone); \
2445 return vg_default_zone.zone_name; \
2448 ZONE_GET_NAME(VG_Z_LIBC_SONAME, malloc_get_zone_name);
2449 ZONE_GET_NAME(SO_SYN_MALLOC, malloc_get_zone_name);
2451 #endif /* defined(VGO_darwin) */
2454 /*------------------ (startup related) ------------------*/
2456 /* All the code in here is unused until this function is called */
2458 __attribute__((constructor))
2459 static void init(void)
2461 // This doesn't look thread-safe, but it should be ok... Bart says:
2463 // Every program I know of calls malloc() at least once before calling
2464 // pthread_create(). So init_done gets initialized before any thread is
2465 // created, and is only read when multiple threads are active
2466 // simultaneously. Such an access pattern is safe.
2468 // If the assignment to the variable init_done would be triggering a race
2469 // condition, both DRD and Helgrind would report this race.
2471 // By the way, although the init() function in
2472 // coregrind/m_replacemalloc/vg_replace_malloc.c has been declared
2473 // __attribute__((constructor)), it is not safe to remove the variable
2474 // init_done. This is because it is possible that malloc() and hence
2475 // init() gets called before shared library initialization finished.
2477 if (init_done)
2478 return;
2480 init_done = 1;
2482 VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__GET_MALLOCFUNCS, &info,
2483 0, 0, 0, 0);
2486 /*--------------------------------------------------------------------*/
2487 /*--- end ---*/
2488 /*--------------------------------------------------------------------*/