summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/clock.c2
-rw-r--r--src/mem.c15
-rw-r--r--src/slab.c5
3 files changed, 17 insertions, 5 deletions
diff --git a/src/clock.c b/src/clock.c
index f34d09e32f..ac45d4fad7 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -96,7 +96,7 @@ void rt_tick_increase()
rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms)
{
/* return the calculated tick */
- return (RT_TICK_PER_SECOND * ms) / 1000 + (RT_TICK_PER_SECOND * ms) % 1000 ? 1:0;
+ return (RT_TICK_PER_SECOND * ms+999) / 1000;
}
/*@}*/
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);
diff --git a/src/slab.c b/src/slab.c
index 216ee19500..dc904230f2 100644
--- a/src/slab.c
+++ b/src/slab.c
@@ -329,6 +329,11 @@ void rt_system_heap_init(void *begin_addr, void* end_addr)
heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
heap_end = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE);
+ if(heap_start >= heap_end) {
+ rt_kprintf("rt_system_heap_init, error begin address 0x%x, and end address 0x%x\n", (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);
+ return;
+ }
+
limsize = heap_end - heap_start;
npages = limsize / RT_MM_PAGE_SIZE;