+/* SPDX-License-Identifier: GPL-2.0+ */
/*
- A version of malloc/free/realloc written by Doug Lea and released to the
- public domain. Send questions/comments/complaints/performance data
+ This code is based on a version of malloc/free/realloc written by Doug Lea and
+ released to the public domain. Send questions/comments/complaints/performance
* VERSION 2.6.6 Sun Mar 5 19:10:03 2000 Doug Lea (dl at gee)
Note: There may be an updated version of this malloc obtainable at
- ftp://g.oswego.edu/pub/misc/malloc.c
+ http://g.oswego.edu/pub/misc/malloc.c
Check before installing!
* Why use this malloc?
quickly avoid procedure declaration conflicts and linker symbol
conflicts with existing memory allocation routines.
-
*/
\f
#include <stdio.h> /* needed for malloc_stats */
#endif
-
/*
Compile-time options
*/
-
/*
Debugging:
returns a unique pointer for malloc(0), so does realloc(p, 0).
*/
-
/* #define REALLOC_ZERO_BYTES_FREES */
-
/*
WIN32 causes an emulation of sbrk to be compiled in
mmap-based options are not currently supported in WIN32.
#include <windows.h>
#endif
-
/*
HAVE_MEMCPY should be defined if you are not otherwise using
ANSI STD C, but still have memcpy and memset in your C library
#if (__STD_C || defined(HAVE_MEMCPY))
#if __STD_C
+/* U-Boot defines memset() and memcpy in /include/linux/string.h
void* memset(void*, int, size_t);
void* memcpy(void*, const void*, size_t);
+*/
+#include <linux/string.h>
#else
#ifdef WIN32
/* On Win32 platforms, 'memset()' and 'memcpy()' are already declared in */
#endif
-
/*
Define HAVE_MMAP to optionally make malloc() use mmap() to
allocate very large blocks. These will be returned to the
# endif
#endif
-
/*
This version of malloc supports the standard SVID/XPG mallinfo
#define M_MMAP_THRESHOLD -3
#define M_MMAP_MAX -4
-
#ifndef DEFAULT_TRIM_THRESHOLD
#define DEFAULT_TRIM_THRESHOLD (128 * 1024)
#endif
It must be greater than page size to have any useful effect. To
disable trimming completely, you can set to (unsigned long)(-1);
-
*/
-
#ifndef DEFAULT_TOP_PAD
#define DEFAULT_TOP_PAD (0)
#endif
*/
-
#ifndef DEFAULT_MMAP_THRESHOLD
#define DEFAULT_MMAP_THRESHOLD (128 * 1024)
#endif
All together, these considerations should lead you to use mmap
only for relatively large requests.
-
*/
-
#ifndef DEFAULT_MMAP_MAX
#ifdef HAVE_MMAP
#define DEFAULT_MMAP_MAX (64)
in mallopt will fail.
*/
-
/*
USE_DL_PREFIX will prefix all public routines with the string 'dl'.
Useful to quickly avoid procedure declaration conflicts and linker
*/
-
#ifdef INTERNAL_LINUX_C_LIB
#if __STD_C
#else
+void malloc_simple_info(void);
+
+/**
+ * malloc_enable_testing() - Put malloc() into test mode
+ *
+ * This only works if UNIT_TESTING is enabled
+ *
+ * @max_allocs: return -ENOMEM after max_allocs calls to malloc()
+ */
+void malloc_enable_testing(int max_allocs);
+
+/** malloc_disable_testing() - Put malloc() into normal mode */
+void malloc_disable_testing(void);
+
#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
#define malloc malloc_simple
#define realloc realloc_simple
#define memalign memalign_simple
+#if IS_ENABLED(CONFIG_VALGRIND)
+#define free free_simple
+#else
static inline void free(void *ptr) {}
+#endif
void *calloc(size_t nmemb, size_t size);
void *realloc_simple(void *ptr, size_t size);
-void malloc_simple_info(void);
#else
# ifdef USE_DL_PREFIX
extern ulong mem_malloc_end;
extern ulong mem_malloc_brk;
+/**
+ * mem_malloc_init() - Set up the malloc() pool
+ *
+ * Sets the region of memory to be used for all future calls to malloc(), etc.
+ *
+ * @start: Start address
+ * @size: Size in bytes
+ */
void mem_malloc_init(ulong start, ulong size);
#ifdef __cplusplus