arch/sim: Implement malloc_size for the custom heap

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-06-27 04:10:56 +08:00 committed by Alan Carvalho de Assis
parent f240b2e631
commit 8ebf9c92cf
4 changed files with 28 additions and 2 deletions

View File

@ -50,8 +50,8 @@ NXSYMBOLS(ioctl)
NXSYMBOLS(longjmp)
NXSYMBOLS(lseek)
NXSYMBOLS(malloc)
NXSYMBOLS(mallinfo)
NXSYMBOLS(memalign)
NXSYMBOLS(malloc_size)
NXSYMBOLS(malloc_usable_size)
NXSYMBOLS(memcpy)
NXSYMBOLS(mkdir)
NXSYMBOLS(mmap)
@ -60,6 +60,7 @@ NXSYMBOLS(open)
NXSYMBOLS(opendir)
NXSYMBOLS(perror)
NXSYMBOLS(poll)
NXSYMBOLS(posix_memalign)
NXSYMBOLS(pthread_cond_destroy)
NXSYMBOLS(pthread_cond_init)
NXSYMBOLS(pthread_cond_signal)

View File

@ -446,6 +446,15 @@ void mm_checkcorruption(FAR struct mm_heap_s *heap)
#endif /* CONFIG_DEBUG_MM */
/****************************************************************************
* Name: malloc_size
****************************************************************************/
size_t malloc_size(FAR void *mem)
{
return host_malloc_size(mem);
}
/****************************************************************************
* Name: up_allocate_heap
*

View File

@ -31,6 +31,12 @@
#include <sys/mman.h>
#include <sys/stat.h>
#ifdef __APPLE__
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include "up_internal.h"
/****************************************************************************
@ -118,6 +124,15 @@ void host_free_shmem(void *mem)
munmap(mem, 0);
}
size_t host_malloc_size(void *mem)
{
#ifdef __APPLE__
return malloc_size(mem);
#else
return malloc_usable_size(mem);
#endif
}
void *host_memalign(size_t alignment, size_t size)
{
void *p;

View File

@ -144,6 +144,7 @@ void *host_alloc_heap(size_t sz);
void *host_alloc_shmem(const char *name, size_t size, int master);
void host_free_shmem(void *mem);
size_t host_malloc_size(void *mem);
void *host_memalign(size_t alignment, size_t size);
void host_free(void *mem);
void *host_realloc(void *oldmem, size_t size);