]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/dlmalloc.c
m68k: cache: add an empty stub functions for invalidate/flush dcache
[karo-tx-uboot.git] / common / dlmalloc.c
index b2f0a1ad52e2e97694a9008fed300c9470fd0823..b5bb05191c240a46d0fb944356418c45f3f8ea4e 100644 (file)
@@ -1,5 +1,9 @@
 #include <common.h>
 
+#ifdef CONFIG_SANDBOX
+#define DEBUG
+#endif
+
 #if 0  /* Moved to malloc.h */
 /* ---------- To make a malloc.h, start cutting here ------------ */
 
   MORECORE_FAILURE          (default: -1)
      The value returned upon failure of MORECORE.
   MORECORE_CLEARS           (default 1)
-     True (1) if the routine mapped to MORECORE zeroes out memory (which
+     true (1) if the routine mapped to MORECORE zeroes out memory (which
      holds for sbrk).
   DEFAULT_TRIM_THRESHOLD
   DEFAULT_TOP_PAD
 
 */
 
-\f
+
 
 /* Preliminaries */
 
@@ -930,6 +934,8 @@ struct mallinfo mALLINFo();
 #endif /* 0 */                 /* Moved to malloc.h */
 
 #include <malloc.h>
+#include <asm/io.h>
+
 #ifdef DEBUG
 #if __STD_C
 static void malloc_update_mallinfo (void);
@@ -1132,7 +1138,7 @@ gAllocatedSize))
 
 #endif
 
-\f
+
 
 /*
   Type declarations
@@ -1272,7 +1278,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        serviced via calls to mmap, and then later released via munmap.
 
 */
-\f
+
 /*  sizes, alignments */
 
 #define SIZE_SZ                (sizeof(INTERNAL_SIZE_T))
@@ -1297,7 +1303,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 #define aligned_OK(m)    (((unsigned long)((m)) & (MALLOC_ALIGN_MASK)) == 0)
 
 
-\f
+
 
 /*
   Physical chunk operations
@@ -1332,7 +1338,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 #define chunk_at_offset(p, s)  ((mchunkptr)(((char*)(p)) + (s)))
 
 
-\f
+
 
 /*
   Dealing with use bits
@@ -1371,7 +1377,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  (((mchunkptr)(((char*)(p)) + (s)))->size &= ~(PREV_INUSE))
 
 
-\f
+
 
 /*
   Dealing with size fields
@@ -1394,7 +1400,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 #define set_foot(p, s)   (((mchunkptr)((char*)(p) + (s)))->prev_size = (s))
 
 
-\f
+
 
 
 /*
@@ -1485,7 +1491,7 @@ static mbinptr av_[NAV * 2 + 2] = {
 };
 
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
-void malloc_bin_reloc (void)
+static void malloc_bin_reloc(void)
 {
        mbinptr *p = &av_[2];
        size_t i;
@@ -1493,6 +1499,8 @@ void malloc_bin_reloc (void)
        for (i = 2; i < ARRAY_SIZE(av_); ++i, ++p)
                *p = (mbinptr)((ulong)*p + gd->reloc_off);
 }
+#else
+static inline void malloc_bin_reloc(void) {}
 #endif
 
 ulong mem_malloc_start = 0;
@@ -1525,7 +1533,12 @@ void mem_malloc_init(ulong start, ulong size)
        mem_malloc_end = start + size;
        mem_malloc_brk = start;
 
-       memset((void *)mem_malloc_start, 0, size);
+       debug("using memory %#lx-%#lx for malloc()\n", mem_malloc_start,
+             mem_malloc_end);
+#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT
+       memset((void *)mem_malloc_start, 0x0, size);
+#endif
+       malloc_bin_reloc();
 }
 
 /* field-extraction macros */
@@ -1562,7 +1575,7 @@ void mem_malloc_init(ulong start, ulong size)
 
 #define is_small_request(nb) (nb < MAX_SMALLBIN_SIZE - SMALLBIN_WIDTH)
 
-\f
+
 
 /*
     To help compensate for the large number of bins, a one-level index
@@ -1586,7 +1599,7 @@ void mem_malloc_init(ulong start, ulong size)
 #define clear_binblock(ii)  (binblocks_w = (mbinptr)(binblocks_r & ~(idx2binblock(ii))))
 
 
-\f
+
 
 
 /*  Other static bookkeeping data */
@@ -1624,7 +1637,7 @@ static unsigned int max_n_mmaps = 0;
 static unsigned long max_mmapped_mem = 0;
 #endif
 
-\f
+
 
 /*
   Debugging support
@@ -1765,7 +1778,7 @@ static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s;
 #define check_malloced_chunk(P,N)
 #endif
 
-\f
+
 
 /*
   Macro-based internal utilities
@@ -1837,7 +1850,7 @@ static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s;
   (last_remainder->fd = last_remainder->bk = last_remainder)
 
 
-\f
+
 
 
 /* Routines dealing with mmap(). */
@@ -1968,7 +1981,7 @@ static mchunkptr mremap_chunk(p, new_size) mchunkptr p; size_t new_size;
 #endif /* HAVE_MMAP */
 
 
-\f
+
 
 /*
   Extend the top-most chunk by obtaining memory from system.
@@ -2085,7 +2098,7 @@ static void malloc_extend_top(nb) INTERNAL_SIZE_T nb;
 }
 
 
-\f
+
 
 /* Main public routines */
 
@@ -2170,6 +2183,11 @@ Void_t* mALLOc(bytes) size_t bytes;
 
   INTERNAL_SIZE_T nb;
 
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+       if (gd && !(gd->flags & GD_FLG_FULL_MALLOC_INIT))
+               return malloc_simple(bytes);
+#endif
+
   /* check if mem_malloc_init() was run */
   if ((mem_malloc_start == 0) && (mem_malloc_end == 0)) {
     /* not initialized yet */
@@ -2392,7 +2410,7 @@ Void_t* mALLOc(bytes) size_t bytes;
 }
 
 
-\f
+
 
 /*
 
@@ -2433,6 +2451,12 @@ void fREe(mem) Void_t* mem;
   mchunkptr fwd;       /* misc temp for linking */
   int       islr;      /* track whether merging with last_remainder */
 
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+       /* free() is a no-op - all the memory will be freed on relocation */
+       if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT))
+               return;
+#endif
+
   if (mem == NULL)                              /* free(0) has no effect */
     return;
 
@@ -2509,7 +2533,7 @@ void fREe(mem) Void_t* mem;
 }
 
 
-\f
+
 
 
 /*
@@ -2584,6 +2608,13 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;
   /* realloc of null is supposed to be same as malloc */
   if (oldmem == NULL) return mALLOc(bytes);
 
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+       if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) {
+               /* This is harder to support and should not be needed */
+               panic("pre-reloc realloc() is not supported");
+       }
+#endif
+
   newp    = oldp    = mem2chunk(oldmem);
   newsize = oldsize = chunksize(oldp);
 
@@ -2746,7 +2777,7 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;
 }
 
 
-\f
+
 
 /*
 
@@ -2864,7 +2895,7 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
 
 }
 
-\f
+
 
 
 /*
@@ -2917,9 +2948,11 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size;
 
 
   /* check if expand_top called, in which case don't need to clear */
+#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT
 #if MORECORE_CLEARS
   mchunkptr oldtop = top;
   INTERNAL_SIZE_T oldtopsize = chunksize(top);
+#endif
 #endif
   Void_t* mem = mALLOc (sz);
 
@@ -2929,6 +2962,12 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size;
     return NULL;
   else
   {
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+       if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) {
+               MALLOC_ZERO(mem, sz);
+               return mem;
+       }
+#endif
     p = mem2chunk(mem);
 
     /* Two optional cases in which clearing not necessary */
@@ -2940,12 +2979,14 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size;
 
     csz = chunksize(p);
 
+#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT
 #if MORECORE_CLEARS
     if (p == oldtop && csz > oldtopsize)
     {
       /* clear only the bytes from non-freshly-sbrked memory */
       csz = oldtopsize;
     }
+#endif
 #endif
 
     MALLOC_ZERO(mem, csz - SIZE_SZ);
@@ -2971,7 +3012,7 @@ void cfree(mem) Void_t *mem;
 }
 #endif
 
-\f
+
 
 /*
 
@@ -3052,7 +3093,7 @@ int malloc_trim(pad) size_t pad;
   }
 }
 
-\f
+
 
 /*
   malloc_usable_size:
@@ -3088,7 +3129,7 @@ size_t malloc_usable_size(mem) Void_t* mem;
 }
 
 
-\f
+
 
 /* Utility to update current_mallinfo for malloc_stats and mallinfo() */
 
@@ -3132,7 +3173,7 @@ static void malloc_update_mallinfo()
 }
 #endif /* DEBUG */
 
-\f
+
 
 /*
 
@@ -3179,7 +3220,7 @@ struct mallinfo mALLINFo()
 #endif /* DEBUG */
 
 
-\f
+
 
 /*
   mallopt:
@@ -3220,6 +3261,17 @@ int mALLOPt(param_number, value) int param_number; int value;
   }
 }
 
+int initf_malloc(void)
+{
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+       assert(gd->malloc_base);        /* Set up by crt0.S */
+       gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;
+       gd->malloc_ptr = 0;
+#endif
+
+       return 0;
+}
+
 /*
 
 History: