projects
/
oweals
/
u-boot.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
x86: pci: Do not assign irq 0 to pci device
[oweals/u-boot.git]
/
common
/
dlmalloc.c
diff --git
a/common/dlmalloc.c
b/common/dlmalloc.c
index 2a9d169f92da78f291e46f9731012135e34b6c4b..b5bb05191c240a46d0fb944356418c45f3f8ea4e 100644
(file)
--- a/
common/dlmalloc.c
+++ b/
common/dlmalloc.c
@@
-1,5
+1,9
@@
#include <common.h>
#include <common.h>
+#ifdef CONFIG_SANDBOX
+#define DEBUG
+#endif
+
#if 0 /* Moved to malloc.h */
/* ---------- To make a malloc.h, start cutting here ------------ */
#if 0 /* Moved to malloc.h */
/* ---------- To make a malloc.h, start cutting here ------------ */
@@
-201,7
+205,7
@@
MORECORE_FAILURE (default: -1)
The value returned upon failure of MORECORE.
MORECORE_CLEARS (default 1)
MORECORE_FAILURE (default: -1)
The value returned upon failure of MORECORE.
MORECORE_CLEARS (default 1)
-
T
rue (1) if the routine mapped to MORECORE zeroes out memory (which
+
t
rue (1) if the routine mapped to MORECORE zeroes out memory (which
holds for sbrk).
DEFAULT_TRIM_THRESHOLD
DEFAULT_TOP_PAD
holds for sbrk).
DEFAULT_TRIM_THRESHOLD
DEFAULT_TOP_PAD
@@
-220,7
+224,7
@@
*/
*/
-
\f
+
/* Preliminaries */
/* Preliminaries */
@@
-930,6
+934,8
@@
struct mallinfo mALLINFo();
#endif /* 0 */ /* Moved to malloc.h */
#include <malloc.h>
#endif /* 0 */ /* Moved to malloc.h */
#include <malloc.h>
+#include <asm/io.h>
+
#ifdef DEBUG
#if __STD_C
static void malloc_update_mallinfo (void);
#ifdef DEBUG
#if __STD_C
static void malloc_update_mallinfo (void);
@@
-1132,7
+1138,7
@@
gAllocatedSize))
#endif
#endif
-
\f
+
/*
Type declarations
/*
Type declarations
@@
-1272,7
+1278,7
@@
nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
serviced via calls to mmap, and then later released via munmap.
*/
serviced via calls to mmap, and then later released via munmap.
*/
-
\f
+
/* sizes, alignments */
#define SIZE_SZ (sizeof(INTERNAL_SIZE_T))
/* 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)
#define aligned_OK(m) (((unsigned long)((m)) & (MALLOC_ALIGN_MASK)) == 0)
-
\f
+
/*
Physical chunk operations
/*
Physical chunk operations
@@
-1332,7
+1338,7
@@
nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#define chunk_at_offset(p, s) ((mchunkptr)(((char*)(p)) + (s)))
#define chunk_at_offset(p, s) ((mchunkptr)(((char*)(p)) + (s)))
-
\f
+
/*
Dealing with use bits
/*
Dealing with use bits
@@
-1371,7
+1377,7
@@
nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
(((mchunkptr)(((char*)(p)) + (s)))->size &= ~(PREV_INUSE))
(((mchunkptr)(((char*)(p)) + (s)))->size &= ~(PREV_INUSE))
-
\f
+
/*
Dealing with size fields
/*
Dealing with size fields
@@
-1394,7
+1400,7
@@
nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_size = (s))
#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_size = (s))
-
\f
+
/*
/*
@@
-1527,8
+1533,11
@@
void mem_malloc_init(ulong start, ulong size)
mem_malloc_end = start + size;
mem_malloc_brk = start;
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();
}
malloc_bin_reloc();
}
@@
-1566,7
+1575,7
@@
void mem_malloc_init(ulong start, ulong size)
#define is_small_request(nb) (nb < MAX_SMALLBIN_SIZE - SMALLBIN_WIDTH)
#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
/*
To help compensate for the large number of bins, a one-level index
@@
-1590,7
+1599,7
@@
void mem_malloc_init(ulong start, ulong size)
#define clear_binblock(ii) (binblocks_w = (mbinptr)(binblocks_r & ~(idx2binblock(ii))))
#define clear_binblock(ii) (binblocks_w = (mbinptr)(binblocks_r & ~(idx2binblock(ii))))
-
\f
+
/* Other static bookkeeping data */
/* Other static bookkeeping data */
@@
-1628,7
+1637,7
@@
static unsigned int max_n_mmaps = 0;
static unsigned long max_mmapped_mem = 0;
#endif
static unsigned long max_mmapped_mem = 0;
#endif
-
\f
+
/*
Debugging support
/*
Debugging support
@@
-1769,7
+1778,7
@@
static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s;
#define check_malloced_chunk(P,N)
#endif
#define check_malloced_chunk(P,N)
#endif
-
\f
+
/*
Macro-based internal utilities
/*
Macro-based internal utilities
@@
-1841,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)
(last_remainder->fd = last_remainder->bk = last_remainder)
-
\f
+
/* Routines dealing with mmap(). */
/* Routines dealing with mmap(). */
@@
-1972,7
+1981,7
@@
static mchunkptr mremap_chunk(p, new_size) mchunkptr p; size_t new_size;
#endif /* HAVE_MMAP */
#endif /* HAVE_MMAP */
-
\f
+
/*
Extend the top-most chunk by obtaining memory from system.
/*
Extend the top-most chunk by obtaining memory from system.
@@
-2089,7
+2098,7
@@
static void malloc_extend_top(nb) INTERNAL_SIZE_T nb;
}
}
-
\f
+
/* Main public routines */
/* Main public routines */
@@
-2174,6
+2183,11
@@
Void_t* mALLOc(bytes) size_t bytes;
INTERNAL_SIZE_T nb;
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 */
/* check if mem_malloc_init() was run */
if ((mem_malloc_start == 0) && (mem_malloc_end == 0)) {
/* not initialized yet */
@@
-2396,7
+2410,7
@@
Void_t* mALLOc(bytes) size_t bytes;
}
}
-
\f
+
/*
/*
@@
-2437,6
+2451,12
@@
void fREe(mem) Void_t* mem;
mchunkptr fwd; /* misc temp for linking */
int islr; /* track whether merging with last_remainder */
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;
if (mem == NULL) /* free(0) has no effect */
return;
@@
-2513,7
+2533,7
@@
void fREe(mem) Void_t* mem;
}
}
-
\f
+
/*
/*
@@
-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);
/* 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);
newp = oldp = mem2chunk(oldmem);
newsize = oldsize = chunksize(oldp);
@@
-2750,7
+2777,7
@@
Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;
}
}
-
\f
+
/*
/*
@@
-2868,7
+2895,7
@@
Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
}
}
-
\f
+
/*
/*
@@
-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 */
/* 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);
#if MORECORE_CLEARS
mchunkptr oldtop = top;
INTERNAL_SIZE_T oldtopsize = chunksize(top);
+#endif
#endif
Void_t* mem = mALLOc (sz);
#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
{
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 */
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);
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;
}
#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);
#endif
MALLOC_ZERO(mem, csz - SIZE_SZ);
@@
-2975,7
+3012,7
@@
void cfree(mem) Void_t *mem;
}
#endif
}
#endif
-
\f
+
/*
/*
@@
-3056,7
+3093,7
@@
int malloc_trim(pad) size_t pad;
}
}
}
}
-
\f
+
/*
malloc_usable_size:
/*
malloc_usable_size:
@@
-3092,7
+3129,7
@@
size_t malloc_usable_size(mem) Void_t* mem;
}
}
-
\f
+
/* Utility to update current_mallinfo for malloc_stats and mallinfo() */
/* Utility to update current_mallinfo for malloc_stats and mallinfo() */
@@
-3136,7
+3173,7
@@
static void malloc_update_mallinfo()
}
#endif /* DEBUG */
}
#endif /* DEBUG */
-
\f
+
/*
/*
@@
-3183,7
+3220,7
@@
struct mallinfo mALLINFo()
#endif /* DEBUG */
#endif /* DEBUG */
-
\f
+
/*
mallopt:
/*
mallopt:
@@
-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:
/*
History: