提交 8dbcab1c 编写于 作者: B bernard.xiong

update more debug information.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1338 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 e9148ab6
...@@ -233,7 +233,7 @@ void *rt_malloc(rt_size_t size) ...@@ -233,7 +233,7 @@ void *rt_malloc(rt_size_t size)
rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE)); rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE));
else else
rt_kprintf("malloc size %d\n", size); rt_kprintf("malloc size %d\n", size);
#endif #endif
/* alignment size */ /* alignment size */
size = RT_ALIGN(size, RT_ALIGN_SIZE); size = RT_ALIGN(size, RT_ALIGN_SIZE);
...@@ -327,7 +327,9 @@ void *rt_malloc(rt_size_t size) ...@@ -327,7 +327,9 @@ void *rt_malloc(rt_size_t size)
RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE-1)) == 0); RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE-1)) == 0);
#ifdef RT_MEM_DEBUG #ifdef RT_MEM_DEBUG
rt_kprintf("allocate memory at 0x%x\n", (rt_uint32_t)((rt_uint8_t*)mem + SIZEOF_STRUCT_MEM)); rt_kprintf("allocate memory at 0x%x, size: %d\n",
(rt_uint32_t)((rt_uint8_t*)mem + SIZEOF_STRUCT_MEM),
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr)));
#endif #endif
#ifdef RT_USING_HOOK #ifdef RT_USING_HOOK
...@@ -467,37 +469,39 @@ void rt_free(void *rmem) ...@@ -467,37 +469,39 @@ void rt_free(void *rmem)
if (rmem == RT_NULL) return; if (rmem == RT_NULL) return;
RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE-1)) == 0); RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE-1)) == 0);
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
#ifdef RT_USING_HOOK #ifdef RT_USING_HOOK
if (rt_free_hook != RT_NULL) rt_free_hook(rmem); if (rt_free_hook != RT_NULL) rt_free_hook(rmem);
#endif #endif
#ifdef RT_MEM_DEBUG
rt_kprintf("release memory 0x%x\n", (rt_uint32_t)rmem);
#endif
/* protect the heap from concurrent access */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr || (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end) if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr || (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end)
{ {
#ifdef RT_MEM_DEBUG #ifdef RT_MEM_DEBUG
rt_kprintf("illegal memory\n"); rt_kprintf("illegal memory\n");
#endif #endif
/* illegal memory */
rt_sem_release(&heap_sem);
return; return;
} }
/* Get the corresponding struct heap_mem ... */ /* Get the corresponding struct heap_mem ... */
mem = (struct heap_mem *)((rt_uint8_t *)rmem - SIZEOF_STRUCT_MEM); mem = (struct heap_mem *)((rt_uint8_t *)rmem - SIZEOF_STRUCT_MEM);
#ifdef RT_MEM_DEBUG
rt_kprintf("release memory 0x%x, size: %d\n",
(rt_uint32_t)rmem,
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr)));
#endif
/* protect the heap from concurrent access */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
/* ... which has to be in a used state ... */ /* ... which has to be in a used state ... */
RT_ASSERT(mem->used); RT_ASSERT(mem->used);
RT_ASSERT(mem->magic != HEAP_MAGIC);
/* ... and is now unused. */ /* ... and is now unused. */
mem->used = 0; mem->used = 0;
mem->magic = 0;
if (mem < lfree) if (mem < lfree)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册