1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: Malloc function. 15 */ 16 17 #include <stddef.h> 18 #ifdef _DEBUG_HEAP_MEM_MGR 19 #include "dbg_heap_memory.h" 20 #endif 21 #include "malloc.h" 22 #include "malloc_porting.h" 23 malloc_port(uint32_t size,uint32_t caller)24static void *malloc_port(uint32_t size, uint32_t caller) 25 { 26 unused(caller); 27 return malloc(size); 28 } 29 malloc_port_init(void)30void malloc_port_init(void) 31 { 32 malloc_funcs malloc_funcs = { 0 }; 33 malloc_funcs.init = malloc_init; 34 malloc_funcs.free = free; 35 malloc_funcs.malloc = malloc_port; 36 malloc_register_funcs(&malloc_funcs); 37 malloc_init((uintptr_t)(&g_intheap_begin), (uintptr_t)(&g_intheap_begin) + (uintptr_t)(&g_intheap_size)); 38 39 #ifdef _DEBUG_HEAP_MEM_MGR 40 heap_mem_tab_init(); 41 malloc_funcs.free = heap_mem_free; 42 malloc_funcs.malloc = heap_mem_malloc; 43 malloc_register_funcs(&malloc_funcs); 44 #endif 45 }