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