X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fdlmalloc.c;h=b5bb05191c240a46d0fb944356418c45f3f8ea4e;hb=d09e401b439859cf9435bfe363265b4322e93cd9;hp=d1cd561cb85544009cf71536137e051393dce0e5;hpb=d93041a4ca0e421dd2a5683563de10e4694e6394;p=u-boot diff --git a/common/dlmalloc.c b/common/dlmalloc.c index d1cd561cb8..b5bb05191c 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1,5 +1,9 @@ #include +#ifdef CONFIG_SANDBOX +#define DEBUG +#endif + #if 0 /* Moved to malloc.h */ /* ---------- To make a malloc.h, start cutting here ------------ */ @@ -930,6 +934,8 @@ struct mallinfo mALLINFo(); #endif /* 0 */ /* Moved to malloc.h */ #include +#include + #ifdef DEBUG #if __STD_C static void malloc_update_mallinfo (void); @@ -1527,8 +1533,11 @@ 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(); } @@ -2174,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 */ @@ -2437,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; @@ -2588,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); @@ -2921,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); @@ -2933,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 */ @@ -2944,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); @@ -3224,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: