This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 8ebf9c92cf244116d9c9cd6e12b4427771ea9ec0 Author: Xiang Xiao <xiaoxi...@xiaomi.com> AuthorDate: Sun Jun 27 04:10:56 2021 +0800 arch/sim: Implement malloc_size for the custom heap Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com> --- arch/sim/src/nuttx-names.in | 5 +++-- arch/sim/src/sim/up_heap.c | 9 +++++++++ arch/sim/src/sim/up_hostmemory.c | 15 +++++++++++++++ arch/sim/src/sim/up_internal.h | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/arch/sim/src/nuttx-names.in b/arch/sim/src/nuttx-names.in index 66b0903..9d405fd 100644 --- a/arch/sim/src/nuttx-names.in +++ b/arch/sim/src/nuttx-names.in @@ -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) diff --git a/arch/sim/src/sim/up_heap.c b/arch/sim/src/sim/up_heap.c index 1963952..b1ccc11 100644 --- a/arch/sim/src/sim/up_heap.c +++ b/arch/sim/src/sim/up_heap.c @@ -447,6 +447,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 * * Description: diff --git a/arch/sim/src/sim/up_hostmemory.c b/arch/sim/src/sim/up_hostmemory.c index 88bc3d1..f444011 100644 --- a/arch/sim/src/sim/up_hostmemory.c +++ b/arch/sim/src/sim/up_hostmemory.c @@ -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; diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h index 4ad4d0f..43c8913 100644 --- a/arch/sim/src/sim/up_internal.h +++ b/arch/sim/src/sim/up_internal.h @@ -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);