mm: Support malloc_size function

and rename malloc_usable_size to malloc_size

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-06-27 03:57:56 +08:00 committed by Alan Carvalho de Assis
parent f4a374b6d9
commit 97216c220b
4 changed files with 11 additions and 7 deletions

View File

@ -3674,7 +3674,7 @@ static void *esp_realloc_internal(void *ptr, size_t size)
return NULL;
}
old_size = malloc_usable_size(old_ptr);
old_size = malloc_size(old_ptr);
DEBUGASSERT(old_size > 0);
memcpy(new_ptr, old_ptr, MIN(old_size, size));
kmm_free(old_ptr);

View File

@ -31,6 +31,10 @@
* Pre-processor Definitions
****************************************************************************/
/* For Linux and MacOS compatibility */
#define malloc_usable_size malloc_size
/****************************************************************************
* Public Type Definitions
****************************************************************************/
@ -58,7 +62,7 @@ extern "C"
#endif
struct mallinfo mallinfo(void);
size_t malloc_usable_size(FAR void *ptr);
size_t malloc_size(FAR void *ptr);
#if defined(__cplusplus)
}

View File

@ -23,9 +23,9 @@
ifeq ($(CONFIG_MM_DEFAULT_MANAGER),y)
CSRCS += mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c
CSRCS += mm_malloc_usable_size.c mm_shrinkchunk.c
CSRCS += mm_brkaddr.c mm_calloc.c mm_extend.c mm_free.c mm_mallinfo.c
CSRCS += mm_malloc.c mm_memalign.c mm_realloc.c mm_zalloc.c mm_heapmember.c
CSRCS += mm_malloc_size.c mm_shrinkchunk.c mm_brkaddr.c mm_calloc.c
CSRCS += mm_extend.c mm_free.c mm_mallinfo.c mm_malloc.c
CSRCS += mm_memalign.c mm_realloc.c mm_zalloc.c mm_heapmember.c
ifeq ($(CONFIG_BUILD_KERNEL),y)
CSRCS += mm_sbrk.c

View File

@ -1,5 +1,5 @@
/****************************************************************************
* mm/mm_heap/mm_malloc_usable_size.c
* mm/mm_heap/mm_malloc_size.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -36,7 +36,7 @@
* Public Functions
****************************************************************************/
size_t malloc_usable_size(FAR void *mem)
size_t malloc_size(FAR void *mem)
{
FAR struct mm_freenode_s *node;