summaryrefslogtreecommitdiff
path: root/src/mem.c
diff options
context:
space:
mode:
authorbernard.xiong <[email protected]>2010-07-22 02:54:19 +0000
committerbernard.xiong <[email protected]>2010-07-22 02:54:19 +0000
commit0a64bac9d9a1d0b522e46ea58e8a07c59e567c6a (patch)
treed0719666e8a0e6821118f267b9db0217c3fc1333 /src/mem.c
parentf834265044a0bcd6f0c7099de96e38e47324f28a (diff)
apply kuronca patch for heap initialization check.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@811 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'src/mem.c')
-rw-r--r--src/mem.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/mem.c b/src/mem.c
index ac091c6f76..22921253ea 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -166,15 +166,22 @@ static void plug_holes(struct heap_mem *mem)
void rt_system_heap_init(void* begin_addr, void* end_addr)
{
struct heap_mem *mem;
+ rt_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
+ rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE);
/* alignment addr */
- begin_addr = (void*)RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
-
+ if((end_align > (2 * SIZEOF_STRUCT_MEM) ) &&
+ ((end_align - 2 * SIZEOF_STRUCT_MEM) >= begin_align )) {
/* calculate the aligned memory size */
- mem_size_aligned = RT_ALIGN_DOWN((rt_uint32_t)end_addr - (rt_uint32_t)begin_addr, RT_ALIGN_SIZE) - 2 * SIZEOF_STRUCT_MEM;
+ mem_size_aligned = end_align - begin_align - 2 * SIZEOF_STRUCT_MEM;
+ }
+ else {
+ rt_kprintf("mem init, error begin address 0x%x, and end address 0x%x\n", (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);
+ return;
+ }
/* point to begin address of heap */
- heap_ptr = begin_addr;
+ heap_ptr = (rt_uint8_t *)begin_align;
#ifdef RT_MEM_DEBUG
rt_kprintf("mem init, heap begin address 0x%x, size %d\n", (rt_uint32_t)heap_ptr, mem_size_aligned);