]> Git Repo - J-u-boot.git/blobdiff - include/malloc.h
Merge patch series "PLL Sequencing update"
[J-u-boot.git] / include / malloc.h
index f66c2e86176c3bda6eba8359d2c5d4ac15baf115..9e0be482416efc970dd52874a9de114493325f18 100644 (file)
@@ -1,12 +1,13 @@
+/* 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
+  data to [email protected]
 
 * 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
@@ -255,12 +255,10 @@ extern "C" {
 #include <stdio.h>     /* needed for malloc_stats */
 #endif
 
-
 /*
   Compile-time options
 */
 
-
 /*
     Debugging:
 
@@ -305,10 +303,8 @@ extern "C" {
   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.
@@ -334,7 +330,6 @@ extern "C" {
 #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
@@ -361,8 +356,11 @@ extern "C" {
 #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 */
@@ -456,7 +454,6 @@ do {                                                                          \
 
 #endif
 
-
 /*
   Define HAVE_MMAP to optionally make malloc() use mmap() to
   allocate very large blocks.  These will be returned to the
@@ -559,7 +556,6 @@ do {                                                                          \
 #  endif
 #endif
 
-
 /*
 
   This version of malloc supports the standard SVID/XPG mallinfo
@@ -622,7 +618,6 @@ struct mallinfo {
 #define M_MMAP_THRESHOLD    -3
 #define M_MMAP_MAX          -4
 
-
 #ifndef DEFAULT_TRIM_THRESHOLD
 #define DEFAULT_TRIM_THRESHOLD (128 * 1024)
 #endif
@@ -673,10 +668,8 @@ struct mallinfo {
       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
@@ -709,7 +702,6 @@ struct mallinfo {
 
 */
 
-
 #ifndef DEFAULT_MMAP_THRESHOLD
 #define DEFAULT_MMAP_THRESHOLD (128 * 1024)
 #endif
@@ -749,10 +741,8 @@ struct mallinfo {
       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)
@@ -780,7 +770,6 @@ struct mallinfo {
       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
@@ -811,7 +800,6 @@ struct mallinfo {
 
 */
 
-
 #ifdef INTERNAL_LINUX_C_LIB
 
 #if __STD_C
@@ -877,14 +865,31 @@ extern Void_t*     sbrk();
 
 #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
@@ -976,6 +981,14 @@ extern ulong mem_malloc_start;
 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
This page took 0.030597 seconds and 4 git commands to generate.