malloc: Move mcheck block after includes

Move the CONFIG_MCHECK_HEAP_PROTECTION block after the standard
includes so that size_t and string functions are available for
the inline MALLOC_ZERO and MALLOC_COPY functions.

Add the <string.h> and <linux/types.h> includes needed for mcheck.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-12-02 09:34:08 +00:00
parent 331063acd0
commit 22c435d21b

View File

@@ -572,21 +572,6 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP
#define DEBUG 1
#endif
#if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION)
#define STATIC_IF_MCHECK static
#undef MALLOC_COPY
#undef MALLOC_ZERO
static inline void MALLOC_ZERO(void *p, size_t sz) { memset(p, 0, sz); }
static inline void MALLOC_COPY(void *dest, const void *src, size_t sz) { memcpy(dest, src, sz); }
#else
#define STATIC_IF_MCHECK
#define dlmalloc_impl dlmalloc
#define dlfree_impl dlfree
#define dlrealloc_impl dlrealloc
#define dlmemalign_impl dlmemalign
#define dlcalloc_impl dlcalloc
#endif
#define LACKS_FCNTL_H
#define LACKS_UNISTD_H
#define LACKS_SYS_PARAM_H
@@ -633,12 +618,29 @@ static inline void MALLOC_COPY(void *dest, const void *src, size_t sz) { memcpy(
#include <log.h>
#include <malloc.h>
#include <mapmem.h>
#include <string.h>
#include <vsprintf.h>
#include <asm/global_data.h>
#include <linux/types.h>
#include <valgrind/memcheck.h>
DECLARE_GLOBAL_DATA_PTR;
#if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION)
#define STATIC_IF_MCHECK static
#undef MALLOC_COPY
#undef MALLOC_ZERO
static inline void MALLOC_ZERO(void *p, size_t sz) { memset(p, 0, sz); }
static inline void MALLOC_COPY(void *dest, const void *src, size_t sz) { memcpy(dest, src, sz); }
#else
#define STATIC_IF_MCHECK
#define dlmalloc_impl dlmalloc
#define dlfree_impl dlfree
#define dlrealloc_impl dlrealloc
#define dlmemalign_impl dlmemalign
#define dlcalloc_impl dlcalloc
#endif
static bool malloc_testing; /* enable test mode */
static int malloc_max_allocs; /* return NULL after this many calls to malloc() */