2 #ifdef JEMALLOC_H_TYPES
4 #ifdef JEMALLOC_VALGRIND
5 #include <valgrind/valgrind.h>
16 #define JEMALLOC_VALGRIND_MAKE_MEM_NOACCESS(ptr, usize) do { \
17 if (unlikely(in_valgrind)) \
18 valgrind_make_mem_noaccess(ptr, usize); \
20 #define JEMALLOC_VALGRIND_MAKE_MEM_UNDEFINED(ptr, usize) do { \
21 if (unlikely(in_valgrind)) \
22 valgrind_make_mem_undefined(ptr, usize); \
24 #define JEMALLOC_VALGRIND_MAKE_MEM_DEFINED(ptr, usize) do { \
25 if (unlikely(in_valgrind)) \
26 valgrind_make_mem_defined(ptr, usize); \
33 #define JEMALLOC_VALGRIND_MALLOC(cond, tsdn, ptr, usize, zero) do { \
34 if (unlikely(in_valgrind && cond)) { \
35 VALGRIND_MALLOCLIKE_BLOCK(ptr, usize, p2rz(tsdn, ptr), \
39 #define JEMALLOC_VALGRIND_REALLOC_MOVED_no(ptr, old_ptr) \
41 #define JEMALLOC_VALGRIND_REALLOC_MOVED_maybe(ptr, old_ptr) \
43 #define JEMALLOC_VALGRIND_REALLOC_PTR_NULL_no(ptr) \
45 #define JEMALLOC_VALGRIND_REALLOC_PTR_NULL_maybe(ptr) \
47 #define JEMALLOC_VALGRIND_REALLOC_OLD_PTR_NULL_no(old_ptr) \
49 #define JEMALLOC_VALGRIND_REALLOC_OLD_PTR_NULL_maybe(old_ptr) \
51 #define JEMALLOC_VALGRIND_REALLOC(moved, tsdn, ptr, usize, ptr_null, \
52 old_ptr, old_usize, old_rzsize, old_ptr_null, zero) do { \
53 if (unlikely(in_valgrind)) { \
54 size_t rzsize = p2rz(tsdn, ptr); \
56 if (!JEMALLOC_VALGRIND_REALLOC_MOVED_##moved(ptr, \
58 VALGRIND_RESIZEINPLACE_BLOCK(ptr, old_usize, \
60 if (zero && old_usize < usize) { \
61 valgrind_make_mem_defined( \
62 (void *)((uintptr_t)ptr + \
63 old_usize), usize - old_usize); \
66 if (!JEMALLOC_VALGRIND_REALLOC_OLD_PTR_NULL_## \
67 old_ptr_null(old_ptr)) { \
68 valgrind_freelike_block(old_ptr, \
71 if (!JEMALLOC_VALGRIND_REALLOC_PTR_NULL_## \
73 size_t copy_size = (old_usize < usize) \
74 ? old_usize : usize; \
75 size_t tail_size = usize - copy_size; \
76 VALGRIND_MALLOCLIKE_BLOCK(ptr, usize, \
78 if (copy_size > 0) { \
79 valgrind_make_mem_defined(ptr, \
82 if (zero && tail_size > 0) { \
83 valgrind_make_mem_defined( \
84 (void *)((uintptr_t)ptr + \
85 copy_size), tail_size); \
91 #define JEMALLOC_VALGRIND_FREE(ptr, rzsize) do { \
92 if (unlikely(in_valgrind)) \
93 valgrind_freelike_block(ptr, rzsize); \
96 #define RUNNING_ON_VALGRIND ((unsigned)0)
97 #define JEMALLOC_VALGRIND_MAKE_MEM_NOACCESS(ptr, usize) do {} while (0)
98 #define JEMALLOC_VALGRIND_MAKE_MEM_UNDEFINED(ptr, usize) do {} while (0)
99 #define JEMALLOC_VALGRIND_MAKE_MEM_DEFINED(ptr, usize) do {} while (0)
100 #define JEMALLOC_VALGRIND_MALLOC(cond, tsdn, ptr, usize, zero) do {} while (0)
101 #define JEMALLOC_VALGRIND_REALLOC(maybe_moved, tsdn, ptr, usize, \
102 ptr_maybe_null, old_ptr, old_usize, old_rzsize, old_ptr_maybe_null, \
103 zero) do {} while (0)
104 #define JEMALLOC_VALGRIND_FREE(ptr, rzsize) do {} while (0)
109 #ifdef JEMALLOC_H_STRUCTS
113 #ifdef JEMALLOC_H_EXTERNS
115 #ifdef JEMALLOC_VALGRIND
124 #ifdef JEMALLOC_H_INLINES
#define valgrind_freelike_block
#define valgrind_make_mem_undefined
#define valgrind_make_mem_noaccess
#define valgrind_make_mem_defined