You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/07/04 21:53:52 UTC

[incubator-nuttx] branch master updated (f4a374b -> b3f568c)

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from f4a374b  boards/sim: Add instrumentation config to notelog driver
     new 97216c2  mm: Support malloc_size function
     new f240b2e  arch/sim: Remove host_malloc and host_calloc
     new 8ebf9c9  arch/sim: Implement malloc_size for the custom heap
     new 4589c36  arch/sim: Implement mm_mallinfo for the custom heap
     new b3f568c  boards/sim: Add asan config to test the custom heap

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/sim/src/nuttx-names.in                        |  5 +-
 arch/sim/src/sim/up_heap.c                         | 39 ++++++----
 arch/sim/src/sim/up_hostmemory.c                   | 89 ++++++++++++++++++----
 arch/sim/src/sim/up_internal.h                     |  7 +-
 arch/xtensa/src/esp32/esp32_wifi_adapter.c         |  2 +-
 .../sim/sim/sim/configs/{note => asan}/defconfig   | 11 +--
 include/malloc.h                                   |  6 +-
 mm/mm_heap/Make.defs                               |  6 +-
 .../{mm_malloc_usable_size.c => mm_malloc_size.c}  |  4 +-
 9 files changed, 120 insertions(+), 49 deletions(-)
 copy boards/sim/sim/sim/configs/{note => asan}/defconfig (72%)
 rename mm/mm_heap/{mm_malloc_usable_size.c => mm_malloc_size.c} (95%)

[incubator-nuttx] 03/05: arch/sim: Implement malloc_size for the custom heap

Posted by ac...@apache.org.
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 <xi...@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 <xi...@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);

[incubator-nuttx] 04/05: arch/sim: Implement mm_mallinfo for the custom heap

Posted by ac...@apache.org.
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 4589c369becbd0e7ab9ade912745a932b8e322c2
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 27 04:57:54 2021 +0800

    arch/sim: Implement mm_mallinfo for the custom heap
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/sim/up_heap.c       |  1 +
 arch/sim/src/sim/up_hostmemory.c | 54 +++++++++++++++++++++++++++++++++++++++-
 arch/sim/src/sim/up_internal.h   |  1 +
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/arch/sim/src/sim/up_heap.c b/arch/sim/src/sim/up_heap.c
index b1ccc11..cd61de4 100644
--- a/arch/sim/src/sim/up_heap.c
+++ b/arch/sim/src/sim/up_heap.c
@@ -427,6 +427,7 @@ void mm_extend(FAR struct mm_heap_s *heap, FAR void *mem, size_t size,
 int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
 {
   memset(info, 0, sizeof(struct mallinfo));
+  host_mallinfo(&info->aordblks, &info->uordblks);
   return 0;
 }
 
diff --git a/arch/sim/src/sim/up_hostmemory.c b/arch/sim/src/sim/up_hostmemory.c
index f444011..07cad25 100644
--- a/arch/sim/src/sim/up_hostmemory.c
+++ b/arch/sim/src/sim/up_hostmemory.c
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdatomic.h>
 
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -40,6 +41,13 @@
 #include "up_internal.h"
 
 /****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static atomic_int g_aordblks;
+static atomic_int g_uordblks;
+
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -144,15 +152,59 @@ void *host_memalign(size_t alignment, size_t size)
       return NULL;
     }
 
+  size = host_malloc_size(p);
+  g_aordblks += 1;
+  g_uordblks += size;
+
   return p;
 }
 
 void host_free(void *mem)
 {
+  size_t size;
+
+  if (mem == NULL)
+    {
+      return;
+    }
+
+  size = host_malloc_size(mem);
+  g_aordblks -= 1;
+  g_uordblks -= size;
   free(mem);
 }
 
 void *host_realloc(void *oldmem, size_t size)
 {
-  return realloc(oldmem, size);
+  size_t oldsize;
+  void *mem;
+
+  if (size == 0)
+    {
+      host_free(oldmem);
+      return NULL;
+    }
+  else if (oldmem == NULL)
+    {
+      return host_memalign(sizeof(void *), size);
+    }
+
+  oldsize = host_malloc_size(oldmem);
+  mem = realloc(oldmem, size);
+  if (mem == NULL)
+    {
+      return NULL;
+    }
+
+  size = host_malloc_size(mem);
+  g_uordblks -= oldsize;
+  g_uordblks += size;
+
+  return mem;
+}
+
+void host_mallinfo(int *aordblks, int *uordblks)
+{
+  *aordblks = g_aordblks;
+  *uordblks = g_uordblks;
 }
diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index 43c8913..307d7aa 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -148,6 +148,7 @@ 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);
+void host_mallinfo(int *aordblks, int *uordblks);
 
 /* up_hosttime.c ************************************************************/
 

[incubator-nuttx] 05/05: boards/sim: Add asan config to test the custom heap

Posted by ac...@apache.org.
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 b3f568c216f7be766dccda538b444fc5cad2ab9b
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 27 11:41:41 2021 +0800

    boards/sim: Add asan config to test the custom heap
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/sim/up_heap.c                | 10 ++++++----
 boards/sim/sim/sim/configs/asan/defconfig | 32 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/arch/sim/src/sim/up_heap.c b/arch/sim/src/sim/up_heap.c
index cd61de4..9af5a8f 100644
--- a/arch/sim/src/sim/up_heap.c
+++ b/arch/sim/src/sim/up_heap.c
@@ -24,11 +24,13 @@
 
 #include <nuttx/config.h>
 
+#include <assert.h>
 #include <string.h>
 #include <malloc.h>
 #include <stdbool.h>
 
 #include <nuttx/arch.h>
+#include <nuttx/fs/procfs.h>
 #include <nuttx/mm/mm.h>
 
 #include "up_internal.h"
@@ -151,10 +153,10 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name,
   heap->mm_impl = impl;
 
 #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
-  heap_impl->mm_procfs.name = name;
-  heap_impl->mm_procfs.mallinfo = (FAR void *)mm_mallinfo;
-  heap_impl->mm_procfs.user_data = heap;
-  procfs_register_meminfo(&heap_impl->mm_procfs);
+  impl->mm_procfs.name = name;
+  impl->mm_procfs.mallinfo = (FAR void *)mm_mallinfo;
+  impl->mm_procfs.user_data = heap;
+  procfs_register_meminfo(&impl->mm_procfs);
 #endif
 }
 
diff --git a/boards/sim/sim/sim/configs/asan/defconfig b/boards/sim/sim/sim/configs/asan/defconfig
new file mode 100644
index 0000000..f656a29
--- /dev/null
+++ b/boards/sim/sim/sim/configs/asan/defconfig
@@ -0,0 +1,32 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed .config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that includes your
+# modifications.
+#
+CONFIG_ARCH="sim"
+CONFIG_ARCH_BOARD="sim"
+CONFIG_ARCH_BOARD_SIM=y
+CONFIG_ARCH_CHIP="sim"
+CONFIG_ARCH_SIM=y
+CONFIG_BOARDCTL_POWEROFF=y
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DEV_LOOP=y
+CONFIG_DEV_ZERO=y
+CONFIG_EXAMPLES_HELLO=y
+CONFIG_FS_BINFS=y
+CONFIG_FS_PROCFS=y
+CONFIG_MM_CUSTOMIZE_MANAGER=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_READLINE=y
+CONFIG_READLINE_TABCOMPLETION=y
+CONFIG_SCHED_HAVE_PARENT=y
+CONFIG_SCHED_ONEXIT=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_SIM_SANITIZE=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TESTING_OSTEST=y
+CONFIG_USER_ENTRYPOINT="nsh_main"

[incubator-nuttx] 01/05: mm: Support malloc_size function

Posted by ac...@apache.org.
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 97216c220be4ca3c7518228c502b5def868d79ce
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 27 03:57:56 2021 +0800

    mm: Support malloc_size function
    
    and rename malloc_usable_size to malloc_size
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/xtensa/src/esp32/esp32_wifi_adapter.c               | 2 +-
 include/malloc.h                                         | 6 +++++-
 mm/mm_heap/Make.defs                                     | 6 +++---
 mm/mm_heap/{mm_malloc_usable_size.c => mm_malloc_size.c} | 4 ++--
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c
index fe79707..87e5819 100644
--- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c
+++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c
@@ -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);
diff --git a/include/malloc.h b/include/malloc.h
index a4bc6c4..0854174 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -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)
 }
diff --git a/mm/mm_heap/Make.defs b/mm/mm_heap/Make.defs
index b44f988..678c52c 100644
--- a/mm/mm_heap/Make.defs
+++ b/mm/mm_heap/Make.defs
@@ -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
diff --git a/mm/mm_heap/mm_malloc_usable_size.c b/mm/mm_heap/mm_malloc_size.c
similarity index 95%
rename from mm/mm_heap/mm_malloc_usable_size.c
rename to mm/mm_heap/mm_malloc_size.c
index b4df717..40bc7b2 100644
--- a/mm/mm_heap/mm_malloc_usable_size.c
+++ b/mm/mm_heap/mm_malloc_size.c
@@ -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;
 

[incubator-nuttx] 02/05: arch/sim: Remove host_malloc and host_calloc

Posted by ac...@apache.org.
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 f240b2e63182eaab3e50166478235824081a423f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 27 02:43:04 2021 +0800

    arch/sim: Remove host_malloc and host_calloc
    
    use host_realloc instead
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/sim/up_heap.c       | 19 ++++++++++---------
 arch/sim/src/sim/up_hostmemory.c | 30 ++++++++++--------------------
 arch/sim/src/sim/up_internal.h   |  5 ++---
 3 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/arch/sim/src/sim/up_heap.c b/arch/sim/src/sim/up_heap.c
index 5d3da3e..1963952 100644
--- a/arch/sim/src/sim/up_heap.c
+++ b/arch/sim/src/sim/up_heap.c
@@ -144,7 +144,7 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name,
 {
   FAR struct mm_heap_impl_s *impl;
 
-  impl = host_malloc(sizeof(struct mm_heap_impl_s));
+  impl = host_memalign(sizeof(FAR void *), sizeof(*impl));
   DEBUGASSERT(impl);
 
   memset(impl, 0, sizeof(struct mm_heap_impl_s));
@@ -194,10 +194,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
 
 FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
 {
-  /* Firstly, free mm_delaylist */
-
-  mm_free_delaylist(heap);
-  return host_malloc(size);
+  return mm_realloc(heap, NULL, size);
 }
 
 /****************************************************************************
@@ -236,8 +233,6 @@ FAR void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
     {
       host_free(mem);
     }
-
-  return;
 }
 
 /****************************************************************************
@@ -280,8 +275,14 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
 
 FAR void *mm_calloc(FAR struct mm_heap_s *heap, size_t n, size_t elem_size)
 {
-  mm_free_delaylist(heap);
-  return host_calloc(n, elem_size);
+  size_t size = n * elem_size;
+
+  if (size < elem_size)
+    {
+      return NULL;
+    }
+
+  return mm_zalloc(heap, size);
 }
 
 /****************************************************************************
diff --git a/arch/sim/src/sim/up_hostmemory.c b/arch/sim/src/sim/up_hostmemory.c
index 03537be..88bc3d1 100644
--- a/arch/sim/src/sim/up_hostmemory.c
+++ b/arch/sim/src/sim/up_hostmemory.c
@@ -118,26 +118,6 @@ void host_free_shmem(void *mem)
   munmap(mem, 0);
 }
 
-void *host_malloc(size_t size)
-{
-  return malloc(size);
-}
-
-void host_free(void *mem)
-{
-  free(mem);
-}
-
-void *host_realloc(void *oldmem, size_t size)
-{
-  return realloc(oldmem, size);
-}
-
-void *host_calloc(size_t n, size_t elem_size)
-{
-  return calloc(n , elem_size);
-}
-
 void *host_memalign(size_t alignment, size_t size)
 {
   void *p;
@@ -151,3 +131,13 @@ void *host_memalign(size_t alignment, size_t size)
 
   return p;
 }
+
+void host_free(void *mem)
+{
+  free(mem);
+}
+
+void *host_realloc(void *oldmem, size_t size)
+{
+  return realloc(oldmem, size);
+}
diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index 43dbede..4ad4d0f 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -143,11 +143,10 @@ void host_abort(int status);
 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);
-void *host_malloc(size_t size);
+
+void *host_memalign(size_t alignment, size_t size);
 void host_free(void *mem);
 void *host_realloc(void *oldmem, size_t size);
-void *host_calloc(size_t n, size_t elem_size);
-void *host_memalign(size_t alignment, size_t size);
 
 /* up_hosttime.c ************************************************************/