You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
4 months ago
|
/*
|
||
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||
|
* Description: malloc function : First-fit allocation policies
|
||
|
* Author: SmartMedia_BSP
|
||
|
* Create: 2020-06-16
|
||
|
*/
|
||
|
|
||
|
#include <td_type.h>
|
||
|
#include <hlist.h>
|
||
|
#include "memlib.h"
|
||
|
|
||
|
static struct list g_malloc_list = {0};
|
||
|
|
||
|
void malloc_init(unsigned int base, unsigned int size)
|
||
|
{
|
||
|
if ((g_malloc_list.base.next != NULL) && (g_malloc_list.base.prev != NULL)) {
|
||
|
return;
|
||
|
}
|
||
|
memlib_init(&g_malloc_list, base, size);
|
||
|
}
|
||
|
|
||
|
void *malloc(uint32 bytes)
|
||
|
{
|
||
|
if ((g_malloc_list.base.next == NULL) || (g_malloc_list.base.prev == NULL)) {
|
||
|
return NULL;
|
||
|
}
|
||
|
return memlib_malloc(&g_malloc_list, bytes);
|
||
|
}
|
||
|
|
||
|
void *memalign(uint32 alignment, uint32 bytes)
|
||
|
{
|
||
|
if ((g_malloc_list.base.next == NULL) || (g_malloc_list.base.prev == NULL)) {
|
||
|
return NULL;
|
||
|
}
|
||
|
return memlib_memalign(&g_malloc_list, alignment, bytes);
|
||
|
}
|
||
|
|
||
|
void free(void *ptr)
|
||
|
{
|
||
|
if ((g_malloc_list.base.next == NULL) || (g_malloc_list.base.prev == NULL)) {
|
||
|
return;
|
||
|
}
|
||
|
memlib_free(&g_malloc_list, ptr);
|
||
|
}
|
||
|
|
||
|
void show_memnode(unsigned int cnt)
|
||
|
{
|
||
|
if ((g_malloc_list.base.next == NULL) || (g_malloc_list.base.prev == NULL)) {
|
||
|
return;
|
||
|
}
|
||
|
memlib_show_memnode(&g_malloc_list, cnt);
|
||
|
}
|