Merge branch 'master_sh/gen4/mmcfix' of https://source.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / common / dlmalloc.c
index f48cd2a..0f9b726 100644 (file)
@@ -80,7 +80,7 @@ GmListElement* makeGmListElement (void* bas)
        return this;
 }
 
-void gcleanup ()
+void gcleanup (void)
 {
        BOOL rval;
        assert ( (head == NULL) || (head->base == (void*)gAddressBase));
@@ -596,6 +596,9 @@ ulong mem_malloc_start = 0;
 ulong mem_malloc_end = 0;
 ulong mem_malloc_brk = 0;
 
+static bool malloc_testing;    /* enable test mode */
+static int malloc_max_allocs;  /* return NULL after this many calls to malloc() */
+
 void *sbrk(ptrdiff_t increment)
 {
        ulong old = mem_malloc_brk;
@@ -1307,6 +1310,11 @@ Void_t* mALLOc(bytes) size_t bytes;
                return malloc_simple(bytes);
 #endif
 
+  if (CONFIG_IS_ENABLED(UNIT_TEST) && malloc_testing) {
+    if (--malloc_max_allocs < 0)
+      return NULL;
+  }
+
   /* check if mem_malloc_init() was run */
   if ((mem_malloc_start == 0) && (mem_malloc_end == 0)) {
     /* not initialized yet */
@@ -2332,7 +2340,7 @@ size_t malloc_usable_size(mem) Void_t* mem;
 /* Utility to update current_mallinfo for malloc_stats and mallinfo() */
 
 #ifdef DEBUG
-static void malloc_update_mallinfo()
+static void malloc_update_mallinfo(void)
 {
   int i;
   mbinptr b;
@@ -2389,7 +2397,7 @@ static void malloc_update_mallinfo()
 */
 
 #ifdef DEBUG
-void malloc_stats()
+void malloc_stats(void)
 {
   malloc_update_mallinfo();
   printf("max system bytes = %10u\n",
@@ -2410,7 +2418,7 @@ void malloc_stats()
 */
 
 #ifdef DEBUG
-struct mallinfo mALLINFo()
+struct mallinfo mALLINFo(void)
 {
   malloc_update_mallinfo();
   return current_mallinfo;
@@ -2470,6 +2478,17 @@ int initf_malloc(void)
        return 0;
 }
 
+void malloc_enable_testing(int max_allocs)
+{
+       malloc_testing = true;
+       malloc_max_allocs = max_allocs;
+}
+
+void malloc_disable_testing(void)
+{
+       malloc_testing = false;
+}
+
 /*
 
 History: