@@ -60,11 +60,6 @@ typedef intptr_t ssize_t;
60
60
#include <sys/ktrace.h>
61
61
#endif
62
62
63
- #ifdef JEMALLOC_VALGRIND
64
- #include <valgrind/valgrind.h>
65
- #include <valgrind/memcheck.h>
66
- #endif
67
-
68
63
#define JEMALLOC_NO_DEMANGLE
69
64
#ifdef JEMALLOC_JET
70
65
# define JEMALLOC_N (n ) jet_##n
@@ -362,81 +357,7 @@ static const bool config_ivsalloc =
362
357
# define VARIABLE_ARRAY (type , name , count ) type name[count]
363
358
#endif
364
359
365
- #ifdef JEMALLOC_VALGRIND
366
- /*
367
- * The JEMALLOC_VALGRIND_*() macros must be macros rather than functions
368
- * so that when Valgrind reports errors, there are no extra stack frames
369
- * in the backtraces.
370
- *
371
- * The size that is reported to valgrind must be consistent through a chain of
372
- * malloc..realloc..realloc calls. Request size isn't recorded anywhere in
373
- * jemalloc, so it is critical that all callers of these macros provide usize
374
- * rather than request size. As a result, buffer overflow detection is
375
- * technically weakened for the standard API, though it is generally accepted
376
- * practice to consider any extra bytes reported by malloc_usable_size() as
377
- * usable space.
378
- */
379
- #define JEMALLOC_VALGRIND_MALLOC (cond , ptr , usize , zero ) do { \
380
- if (config_valgrind && in_valgrind && cond) \
381
- VALGRIND_MALLOCLIKE_BLOCK(ptr, usize, p2rz(ptr), zero); \
382
- } while (0)
383
- #define JEMALLOC_VALGRIND_REALLOC (ptr , usize , old_ptr , old_usize , \
384
- old_rzsize , zero ) do { \
385
- if (config_valgrind && in_valgrind) { \
386
- size_t rzsize = p2rz(ptr); \
387
- \
388
- if (ptr == old_ptr) { \
389
- VALGRIND_RESIZEINPLACE_BLOCK(ptr, old_usize, \
390
- usize, rzsize); \
391
- if (zero && old_usize < usize) { \
392
- VALGRIND_MAKE_MEM_DEFINED( \
393
- (void *)((uintptr_t)ptr + \
394
- old_usize), usize - old_usize); \
395
- } \
396
- } else { \
397
- if (old_ptr != NULL) { \
398
- VALGRIND_FREELIKE_BLOCK(old_ptr, \
399
- old_rzsize); \
400
- } \
401
- if (ptr != NULL) { \
402
- size_t copy_size = (old_usize < usize) \
403
- ? old_usize : usize; \
404
- size_t tail_size = usize - copy_size; \
405
- VALGRIND_MALLOCLIKE_BLOCK(ptr, usize, \
406
- rzsize, false); \
407
- if (copy_size > 0) { \
408
- VALGRIND_MAKE_MEM_DEFINED(ptr, \
409
- copy_size); \
410
- } \
411
- if (zero && tail_size > 0) { \
412
- VALGRIND_MAKE_MEM_DEFINED( \
413
- (void *)((uintptr_t)ptr + \
414
- copy_size), tail_size); \
415
- } \
416
- } \
417
- } \
418
- } \
419
- } while (0)
420
- #define JEMALLOC_VALGRIND_FREE (ptr , rzsize ) do { \
421
- if (config_valgrind && in_valgrind) \
422
- VALGRIND_FREELIKE_BLOCK(ptr, rzsize); \
423
- } while (0)
424
- #else
425
- #define RUNNING_ON_VALGRIND ((unsigned)0)
426
- #define VALGRIND_MALLOCLIKE_BLOCK (addr , sizeB , rzB , is_zeroed ) \
427
- do {} while (0)
428
- #define VALGRIND_RESIZEINPLACE_BLOCK (addr , oldSizeB , newSizeB , rzB ) \
429
- do {} while (0)
430
- #define VALGRIND_FREELIKE_BLOCK (addr , rzB ) do {} while (0)
431
- #define VALGRIND_MAKE_MEM_NOACCESS (_qzz_addr , _qzz_len ) do {} while (0)
432
- #define VALGRIND_MAKE_MEM_UNDEFINED (_qzz_addr , _qzz_len ) do {} while (0)
433
- #define VALGRIND_MAKE_MEM_DEFINED (_qzz_addr , _qzz_len ) do {} while (0)
434
- #define JEMALLOC_VALGRIND_MALLOC (cond , ptr , usize , zero ) do {} while (0)
435
- #define JEMALLOC_VALGRIND_REALLOC (ptr , usize , old_ptr , old_usize , \
436
- old_rzsize , zero ) do {} while (0)
437
- #define JEMALLOC_VALGRIND_FREE (ptr , rzsize ) do {} while (0)
438
- #endif
439
-
360
+ #include "jemalloc/internal/valgrind.h"
440
361
#include "jemalloc/internal/util.h"
441
362
#include "jemalloc/internal/atomic.h"
442
363
#include "jemalloc/internal/prng.h"
@@ -463,6 +384,7 @@ static const bool config_ivsalloc =
463
384
/******************************************************************************/
464
385
#define JEMALLOC_H_STRUCTS
465
386
387
+ #include "jemalloc/internal/valgrind.h"
466
388
#include "jemalloc/internal/util.h"
467
389
#include "jemalloc/internal/atomic.h"
468
390
#include "jemalloc/internal/prng.h"
@@ -534,6 +456,7 @@ void jemalloc_prefork(void);
534
456
void jemalloc_postfork_parent (void );
535
457
void jemalloc_postfork_child (void );
536
458
459
+ #include "jemalloc/internal/valgrind.h"
537
460
#include "jemalloc/internal/util.h"
538
461
#include "jemalloc/internal/atomic.h"
539
462
#include "jemalloc/internal/prng.h"
@@ -560,6 +483,7 @@ void jemalloc_postfork_child(void);
560
483
/******************************************************************************/
561
484
#define JEMALLOC_H_INLINES
562
485
486
+ #include "jemalloc/internal/valgrind.h"
563
487
#include "jemalloc/internal/util.h"
564
488
#include "jemalloc/internal/atomic.h"
565
489
#include "jemalloc/internal/prng.h"
0 commit comments