|
@@ -11,6 +11,7 @@
|
|
|
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
|
|
|
* 2010-10-14 Bernard fix rt_realloc issue when realloc a NULL pointer.
|
|
|
* 2017-07-14 armink fix rt_realloc issue when new size is 0
|
|
|
+ * 2018-10-02 Bernard Add 64bit support
|
|
|
*/
|
|
|
|
|
|
/*
|
|
@@ -97,12 +98,19 @@ struct heap_mem
|
|
|
/* magic and used flag */
|
|
|
rt_uint16_t magic;
|
|
|
rt_uint16_t used;
|
|
|
+#ifdef ARCH_CPU_64BIT
|
|
|
+ rt_uint32_t resv;
|
|
|
+#endif
|
|
|
|
|
|
rt_size_t next, prev;
|
|
|
|
|
|
#ifdef RT_USING_MEMTRACE
|
|
|
+#ifdef ARCH_CPU_64BIT
|
|
|
+ rt_uint8_t thread[8];
|
|
|
+#else
|
|
|
rt_uint8_t thread[4]; /* thread name */
|
|
|
#endif
|
|
|
+#endif
|
|
|
};
|
|
|
|
|
|
/** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */
|
|
@@ -111,7 +119,12 @@ static rt_uint8_t *heap_ptr;
|
|
|
/** the last entry, always unused! */
|
|
|
static struct heap_mem *heap_end;
|
|
|
|
|
|
+#ifdef ARCH_CPU_64BIT
|
|
|
+#define MIN_SIZE 24
|
|
|
+#else
|
|
|
#define MIN_SIZE 12
|
|
|
+#endif
|
|
|
+
|
|
|
#define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE)
|
|
|
#define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE)
|
|
|
|
|
@@ -191,8 +204,8 @@ 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);
|
|
|
+ rt_ubase_t begin_align = RT_ALIGN((rt_ubase_t)begin_addr, RT_ALIGN_SIZE);
|
|
|
+ rt_ubase_t end_align = RT_ALIGN_DOWN((rt_ubase_t)end_addr, RT_ALIGN_SIZE);
|
|
|
|
|
|
RT_DEBUG_NOT_IN_INTERRUPT;
|
|
|
|
|
@@ -206,7 +219,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
|
|
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);
|
|
|
+ (rt_ubase_t)begin_addr, (rt_ubase_t)end_addr);
|
|
|
|
|
|
return;
|
|
|
}
|
|
@@ -215,7 +228,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
|
|
|
heap_ptr = (rt_uint8_t *)begin_align;
|
|
|
|
|
|
RT_DEBUG_LOG(RT_DEBUG_MEM, ("mem init, heap begin address 0x%x, size %d\n",
|
|
|
- (rt_uint32_t)heap_ptr, mem_size_aligned));
|
|
|
+ (rt_ubase_t)heap_ptr, mem_size_aligned));
|
|
|
|
|
|
/* initialize the start of the heap */
|
|
|
mem = (struct heap_mem *)heap_ptr;
|
|
@@ -374,14 +387,14 @@ void *rt_malloc(rt_size_t size)
|
|
|
}
|
|
|
|
|
|
rt_sem_release(&heap_sem);
|
|
|
- RT_ASSERT((rt_uint32_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_uint32_t)heap_end);
|
|
|
- RT_ASSERT((rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
|
|
|
- RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE - 1)) == 0);
|
|
|
+ RT_ASSERT((rt_ubase_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_ubase_t)heap_end);
|
|
|
+ RT_ASSERT((rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
|
|
|
+ RT_ASSERT((((rt_ubase_t)mem) & (RT_ALIGN_SIZE - 1)) == 0);
|
|
|
|
|
|
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
|
|
("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))));
|
|
|
+ (rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM),
|
|
|
+ (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
|
|
|
|
|
RT_OBJECT_HOOK_CALL(rt_malloc_hook,
|
|
|
(((void *)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM)), size));
|
|
@@ -539,7 +552,7 @@ void rt_free(void *rmem)
|
|
|
|
|
|
RT_DEBUG_NOT_IN_INTERRUPT;
|
|
|
|
|
|
- RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0);
|
|
|
+ RT_ASSERT((((rt_ubase_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);
|
|
|
|
|
@@ -558,8 +571,8 @@ void rt_free(void *rmem)
|
|
|
|
|
|
RT_DEBUG_LOG(RT_DEBUG_MEM,
|
|
|
("release memory 0x%x, size: %d\n",
|
|
|
- (rt_uint32_t)rmem,
|
|
|
- (rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
|
|
+ (rt_ubase_t)rmem,
|
|
|
+ (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
|
|
|
|
|
|
|
|
|
/* protect the heap from concurrent access */
|
|
@@ -624,12 +637,12 @@ FINSH_FUNCTION_EXPORT(list_mem, list memory usage information)
|
|
|
int memcheck(void)
|
|
|
{
|
|
|
int position;
|
|
|
- rt_uint32_t level;
|
|
|
+ rt_ubase_t level;
|
|
|
struct heap_mem *mem;
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next])
|
|
|
{
|
|
|
- position = (rt_uint32_t)mem - (rt_uint32_t)heap_ptr;
|
|
|
+ position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr;
|
|
|
if (position < 0) goto __exit;
|
|
|
if (position > mem_size_aligned) goto __exit;
|
|
|
if (mem->magic != HEAP_MAGIC) goto __exit;
|
|
@@ -664,7 +677,7 @@ int memtrace(int argc, char **argv)
|
|
|
rt_kprintf("\n--memory item information --\n");
|
|
|
for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next])
|
|
|
{
|
|
|
- int position = (rt_uint32_t)mem - (rt_uint32_t)heap_ptr;
|
|
|
+ int position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr;
|
|
|
int size;
|
|
|
|
|
|
rt_kprintf("[0x%08x - ", mem);
|