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

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e941b18e290192a61629f7d77bc321553110c163
Author: ganjing <[email protected]>
AuthorDate: Mon Jan 26 13:57:19 2026 +0800

    mm/umm: Allow customizing the implementation of umm heap
    
    and migrate arch/sim from the customized mm_heap to
    umm_heap, so the default mm_heap implementation can
    still be used(e.g. shared memory in OpenAMP).
    
    Signed-off-by: ganjing <[email protected]>
---
 arch/sim/Kconfig                               |   2 +-
 arch/sim/src/Makefile                          |   2 +-
 arch/sim/src/sim/CMakeLists.txt                |   2 +-
 arch/sim/src/sim/{sim_heap.c => sim_ummheap.c} | 354 +++++++++----------------
 boards/sim/sim/sim/configs/asan/defconfig      |   2 +-
 boards/sim/sim/sim/configs/mnemofs/defconfig   |   2 +-
 boards/sim/sim/sim/configs/nand/defconfig      |   2 +-
 mm/Kconfig                                     |   7 +
 mm/umm_heap/CMakeLists.txt                     |  48 ++--
 mm/umm_heap/Make.defs                          |   2 +
 10 files changed, 166 insertions(+), 257 deletions(-)

diff --git a/arch/sim/Kconfig b/arch/sim/Kconfig
index c545404454a..e70425c7862 100644
--- a/arch/sim/Kconfig
+++ b/arch/sim/Kconfig
@@ -81,7 +81,7 @@ config SIM_CYGWIN_DECORATED
 config SIM_ASAN
        bool "Address Sanitizer"
        default n
-       depends on !MM_KASAN && MM_CUSTOMIZE_MANAGER && FRAME_POINTER
+       depends on !MM_KASAN && MM_UMM_CUSTOMIZE_MANAGER && FRAME_POINTER
        ---help---
                AddressSanitizer (ASan) is a fast compiler-based tool for 
detecting memory
                bugs in native code.
diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile
index fb4df643296..8d7bac1f348 100644
--- a/arch/sim/src/Makefile
+++ b/arch/sim/src/Makefile
@@ -81,7 +81,7 @@ AOBJS = $(ASRCS:.S=$(OBJEXT))
 
 CSRCS  = sim_initialize.c sim_idle.c sim_doirq.c sim_initialstate.c
 CSRCS += sim_createstack.c sim_usestack.c sim_releasestack.c sim_stackframe.c
-CSRCS += sim_exit.c sim_switchcontext.c sim_heap.c
+CSRCS += sim_exit.c sim_switchcontext.c sim_ummheap.c
 CSRCS += sim_uart.c sim_copyfullstate.c sim_tcbinfo.c sim_cpuinfo.c
 CSRCS += sim_registerdump.c sim_saveusercontext.c sim_sectionheap.c
 CSRCS += sim_checkhostfstypes.c
diff --git a/arch/sim/src/sim/CMakeLists.txt b/arch/sim/src/sim/CMakeLists.txt
index d1974959e05..b9f4c637e22 100644
--- a/arch/sim/src/sim/CMakeLists.txt
+++ b/arch/sim/src/sim/CMakeLists.txt
@@ -51,7 +51,7 @@ list(
   sim_stackframe.c
   sim_exit.c
   sim_switchcontext.c
-  sim_heap.c
+  sim_ummheap.c
   sim_uart.c
   sim_copyfullstate.c
   sim_registerdump.c
diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_ummheap.c
similarity index 70%
rename from arch/sim/src/sim/sim_heap.c
rename to arch/sim/src/sim/sim_ummheap.c
index 66bd183dde7..6a70b9372c8 100644
--- a/arch/sim/src/sim/sim_heap.c
+++ b/arch/sim/src/sim/sim_ummheap.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * arch/sim/src/sim/sim_heap.c
+ * arch/sim/src/sim/sim_ummheap.c
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -33,13 +33,12 @@
 
 #include <nuttx/arch.h>
 #include <nuttx/atomic.h>
-#include <nuttx/fs/procfs.h>
 #include <nuttx/mm/mm.h>
 #include <nuttx/sched_note.h>
 
 #include "sim_internal.h"
 
-#ifdef CONFIG_MM_CUSTOMIZE_MANAGER
+#ifdef CONFIG_MM_UMM_CUSTOMIZE_MANAGER
 
 /****************************************************************************
  * Private Types
@@ -54,34 +53,41 @@ struct mm_delaynode_s
 
 struct mm_heap_s
 {
-  struct mm_delaynode_s *mm_delaylist[CONFIG_SMP_NCPUS];
+  struct mm_delaynode_s *delaylist[CONFIG_SMP_NCPUS];
 
 #if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
-  size_t mm_delaycount[CONFIG_SMP_NCPUS];
+  size_t delaycount[CONFIG_SMP_NCPUS];
 #endif
 
   atomic_t aordblks;
   atomic_t uordblks;
   atomic_t usmblks;
-
-#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
-  struct procfs_meminfo_entry_s mm_procfs;
-#endif
 };
 
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
 
-static void mm_delayfree(struct mm_heap_s *heap, void *mem, bool delay);
+static void delay_free(struct mm_heap_s *heap, void *mem, bool delay);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct mm_heap_s g_heap;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct mm_heap_s *g_mmheap = &g_heap;
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
-static void mm_add_delaylist(struct mm_heap_s *heap, void *mem)
+static void add_delaylist(struct mm_heap_s *heap, void *mem)
 {
-#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
   struct mm_delaynode_s *tmp = mem;
   irqstate_t flags;
 
@@ -89,21 +95,19 @@ static void mm_add_delaylist(struct mm_heap_s *heap, void 
*mem)
 
   flags = up_irq_save();
 
-  tmp->flink = heap->mm_delaylist[this_cpu()];
-  heap->mm_delaylist[this_cpu()] = tmp;
+  tmp->flink = heap->delaylist[this_cpu()];
+  heap->delaylist[this_cpu()] = tmp;
 
 #if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
-  heap->mm_delaycount[this_cpu()]++;
+  heap->delaycount[this_cpu()]++;
 #endif
 
   up_irq_restore(flags);
-#endif
 }
 
 static bool free_delaylist(struct mm_heap_s *heap, bool force)
 {
   bool ret = false;
-#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
   struct mm_delaynode_s *tmp;
   irqstate_t flags;
 
@@ -111,26 +115,26 @@ static bool free_delaylist(struct mm_heap_s *heap, bool 
force)
 
   flags = up_irq_save();
 
-  tmp = heap->mm_delaylist[this_cpu()];
+  tmp = heap->delaylist[this_cpu()];
 
 #if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
   if (tmp == NULL ||
       (!force &&
-        heap->mm_delaycount[this_cpu()] < CONFIG_MM_FREE_DELAYCOUNT_MAX))
+        heap->delaycount[this_cpu()] < CONFIG_MM_FREE_DELAYCOUNT_MAX))
     {
       up_irq_restore(flags);
       return false;
     }
 
-  heap->mm_delaycount[this_cpu()] = 0;
+  heap->delaycount[this_cpu()] = 0;
 #endif
-  heap->mm_delaylist[this_cpu()] = NULL;
+  heap->delaylist[this_cpu()] = NULL;
 
   up_irq_restore(flags);
 
   /* Test if the delayed is empty */
 
-  ret = tmp != NULL;
+  ret = (tmp != NULL);
 
   while (tmp)
     {
@@ -145,43 +149,38 @@ static bool free_delaylist(struct mm_heap_s *heap, bool 
force)
        * 'while' condition above.
        */
 
-      mm_delayfree(heap, address, false);
+      delay_free(heap, address, false);
     }
 
-#endif
   return ret;
 }
 
 /****************************************************************************
- * Name: mm_delayfree
+ * Name: delay_free
  *
  * Description:
  *   Delay free memory if `delay` is true, otherwise free it immediately.
  *
  ****************************************************************************/
 
-static void mm_delayfree(struct mm_heap_s *heap, void *mem, bool delay)
+static void delay_free(struct mm_heap_s *heap, void *mem, bool delay)
 {
-#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
   /* Check current environment */
 
   if (up_interrupt_context())
     {
       /* We are in ISR, add to the delay list */
 
-      mm_add_delaylist(heap, mem);
+      add_delaylist(heap, mem);
     }
-  else
-#endif
-
-  if (nxsched_gettid() < 0 || delay)
+  else if (nxsched_gettid() < 0 || delay)
     {
       /* nxsched_gettid() return -ESRCH, means we are in situations
        * during context switching(See nxsched_gettid's comment).
        * Then add to the delay list.
        */
 
-      mm_add_delaylist(heap, mem);
+      add_delaylist(heap, mem);
     }
   else
     {
@@ -193,97 +192,71 @@ static void mm_delayfree(struct mm_heap_s *heap, void 
*mem, bool delay)
     }
 }
 
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: mm_initialize_heap
- *
- * Description:
- *   Initialize the selected heap data structures, providing the initial
- *   heap region.
- *
- * Input Parameters:
- *   config - The heap config structure
- *
- * Returned Value:
- *   Return the address of a new heap instance.
- *
- * Assumptions:
- *
- ****************************************************************************/
-
-struct mm_heap_s *mm_initialize_heap(const struct mm_heap_config_s *config)
+static void *reallocate(void *oldmem, size_t size)
 {
-  struct mm_heap_s *heap = config->heap;
-  const char *name = config->name;
-  void *heap_start = config->start;
-  size_t heap_size = config->size;
+  struct mm_heap_s *heap = g_mmheap;
+  void *mem;
+  int uordblks;
+  int usmblks;
+  int newsize;
+  int oldsize;
 
-  if (heap == NULL)
+  free_delaylist(heap, false);
+
+  if (size == 0)
     {
-      heap = host_memalign(sizeof(void *), sizeof(*heap));
+      size = 1;
     }
-  else
+
+  oldsize = host_mallocsize(oldmem);
+  atomic_fetch_sub(&heap->uordblks, oldsize);
+  mem = host_realloc(oldmem, size);
+
+  atomic_fetch_add(&heap->aordblks, oldmem == NULL && mem != NULL);
+  newsize = host_mallocsize(mem ? mem : oldmem);
+  atomic_fetch_add(&heap->uordblks, newsize);
+  usmblks = atomic_read(&heap->usmblks);
+  if (mem != NULL)
     {
-      heap = mm_memalign(heap, MM_ALIGN, sizeof(struct mm_heap_s));
+      if (oldmem != NULL)
+        {
+          sched_note_heap(NOTE_HEAP_FREE, heap, oldmem, oldsize, 0);
+        }
+
+      sched_note_heap(NOTE_HEAP_ALLOC, heap, mem, newsize, 0);
     }
 
-  if (heap == NULL)
+  do
     {
-      return NULL;
+      uordblks = atomic_read(&heap->uordblks);
+      if (uordblks <= usmblks)
+        {
+          break;
+        }
     }
+  while (atomic_try_cmpxchg(&heap->usmblks, &usmblks, uordblks));
 
-  memset(heap, 0, sizeof(struct mm_heap_s));
-
-#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
-  heap->mm_procfs.name = name;
-  heap->mm_procfs.heap = heap;
-  procfs_register_meminfo(&heap->mm_procfs);
+#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
+  if (mem == NULL && free_delaylist(heap, true))
+    {
+      return reallocate(oldmem, size);
+    }
 #endif
 
-  sched_note_heap(NOTE_HEAP_ADD, heap, heap_start, heap_size, 0);
-  UNUSED(heap_start);
-  UNUSED(heap_size);
-  return heap;
+  return mem;
 }
 
 /****************************************************************************
- * Name: mm_uninitialize
- *
- * Description:
- *   Uninitialize the selected heap data structures
- *
- * Input Parameters:
- *   heap      - The selected heap
- *
- * Returned Value:
- *   None
- *
- * Assumptions:
- *
+ * Public Functions
  ****************************************************************************/
 
-void mm_uninitialize(struct mm_heap_s *heap)
-{
-  sched_note_heap(NOTE_HEAP_REMOVE, heap, NULL, 0, 0);
-
-#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
-  procfs_unregister_meminfo(&heap->mm_procfs);
-#endif
-  mm_free_delaylist(heap);
-  host_free(heap);
-}
-
 /****************************************************************************
- * Name: mm_addregion
+ * Name: umm_addregion
  *
  * Description:
  *   This function adds a region of contiguous memory to the selected heap.
  *
  * Input Parameters:
- *   heap      - The selected heap
  *   heapstart - Start of the heap region
  *   heapsize  - Size of the heap region
  *
@@ -294,13 +267,12 @@ void mm_uninitialize(struct mm_heap_s *heap)
  *
  ****************************************************************************/
 
-void mm_addregion(struct mm_heap_s *heap, void *heapstart,
-                  size_t heapsize)
+void umm_addregion(void *heapstart, size_t heapsize)
 {
 }
 
 /****************************************************************************
- * Name: mm_malloc
+ * Name: malloc
  *
  * Description:
  *  Find the smallest chunk that satisfies the request. Take the memory from
@@ -310,13 +282,13 @@ void mm_addregion(struct mm_heap_s *heap, void *heapstart,
  *
  ****************************************************************************/
 
-void *mm_malloc(struct mm_heap_s *heap, size_t size)
+void *malloc(size_t size)
 {
-  return mm_realloc(heap, NULL, size);
+  return reallocate(NULL, size);
 }
 
 /****************************************************************************
- * Name: mm_free
+ * Name: free
  *
  * Description:
  *   Returns a chunk of memory to the list of free nodes,  merging with
@@ -324,10 +296,8 @@ void *mm_malloc(struct mm_heap_s *heap, size_t size)
  *
  ****************************************************************************/
 
-void mm_free(struct mm_heap_s *heap, void *mem)
+void free(void *mem)
 {
-  minfo("Freeing %p\n", mem);
-
   /* Protect against attempts to free a NULL reference */
 
   if (mem == NULL)
@@ -335,27 +305,11 @@ void mm_free(struct mm_heap_s *heap, void *mem)
       return;
     }
 
-  mm_delayfree(heap, mem, CONFIG_MM_FREE_DELAYCOUNT_MAX > 0);
-}
-
-/****************************************************************************
- * Name: mm_free_delaylist
- *
- * Description:
- *   force freeing the delaylist of this heap.
- *
- ****************************************************************************/
-
-void mm_free_delaylist(struct mm_heap_s *heap)
-{
-  if (heap)
-    {
-       free_delaylist(heap, true);
-    }
+  delay_free(g_mmheap, mem, CONFIG_MM_FREE_DELAYCOUNT_MAX > 0);
 }
 
 /****************************************************************************
- * Name: mm_realloc
+ * Name: realloc
  *
  * Description:
  *   If the reallocation is for less space, then:
@@ -377,69 +331,20 @@ void mm_free_delaylist(struct mm_heap_s *heap)
  *
  ****************************************************************************/
 
-void *mm_realloc(struct mm_heap_s *heap, void *oldmem,
-                 size_t size)
+void *realloc(void *oldmem, size_t size)
 {
-  void *mem;
-  int uordblks;
-  int usmblks;
-  int newsize;
-  int oldsize;
-
-  free_delaylist(heap, false);
-
-  if (size == 0)
-    {
-      size = 1;
-    }
-
-  oldsize = host_mallocsize(oldmem);
-  atomic_fetch_sub(&heap->uordblks, oldsize);
-  mem = host_realloc(oldmem, size);
-
-  atomic_fetch_add(&heap->aordblks, oldmem == NULL && mem != NULL);
-  newsize = host_mallocsize(mem ? mem : oldmem);
-  atomic_fetch_add(&heap->uordblks, newsize);
-  usmblks = atomic_read(&heap->usmblks);
-  if (mem != NULL)
-    {
-      if (oldmem != NULL)
-        {
-          sched_note_heap(NOTE_HEAP_FREE, heap, oldmem, oldsize, 0);
-        }
-
-      sched_note_heap(NOTE_HEAP_ALLOC, heap, mem, newsize, 0);
-    }
-
-  do
-    {
-      uordblks = atomic_read(&heap->uordblks);
-      if (uordblks <= usmblks)
-        {
-          break;
-        }
-    }
-  while (atomic_try_cmpxchg(&heap->usmblks, &usmblks, uordblks));
-
-#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
-  if (mem == NULL && free_delaylist(heap, true))
-    {
-      return mm_realloc(heap, oldmem, size);
-    }
-#endif
-
-  return mem;
+  return reallocate(oldmem, size);
 }
 
 /****************************************************************************
- * Name: mm_calloc
+ * Name: calloc
  *
  * Descriptor:
- *   mm_calloc() calculates the size of the allocation and calls mm_zalloc()
+ *   calloc() calculates the size of the allocation and calls zalloc()
  *
  ****************************************************************************/
 
-void *mm_calloc(struct mm_heap_s *heap, size_t n, size_t elem_size)
+void *calloc(size_t n, size_t elem_size)
 {
   size_t size = n * elem_size;
 
@@ -448,22 +353,22 @@ void *mm_calloc(struct mm_heap_s *heap, size_t n, size_t 
elem_size)
       return NULL;
     }
 
-  return mm_zalloc(heap, size);
+  return zalloc(size);
 }
 
 /****************************************************************************
- * Name: mm_zalloc
+ * Name: zalloc
  *
  * Description:
- *   mm_zalloc calls mm_malloc, then zeroes out the allocated chunk.
+ *   zalloc calls malloc, then zeroes out the allocated chunk.
  *
  ****************************************************************************/
 
-void *mm_zalloc(struct mm_heap_s *heap, size_t size)
+void *zalloc(size_t size)
 {
   void *ptr;
 
-  ptr = mm_malloc(heap, size);
+  ptr = malloc(size);
   if (ptr != NULL)
     {
       memset(ptr, 0, size);
@@ -473,7 +378,7 @@ void *mm_zalloc(struct mm_heap_s *heap, size_t size)
 }
 
 /****************************************************************************
- * Name: mm_memalign
+ * Name: memalign
  *
  * Description:
  *   memalign requests more than enough space from malloc, finds a region
@@ -485,8 +390,9 @@ void *mm_zalloc(struct mm_heap_s *heap, size_t size)
  *
  ****************************************************************************/
 
-void *mm_memalign(struct mm_heap_s *heap, size_t alignment, size_t size)
+void *memalign(size_t alignment, size_t size)
 {
+  struct mm_heap_s *heap = g_mmheap;
   void *mem;
   int uordblks;
   int usmblks;
@@ -518,7 +424,7 @@ void *mm_memalign(struct mm_heap_s *heap, size_t alignment, 
size_t size)
 #if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
   if (mem == NULL && free_delaylist(heap, true))
     {
-      return mm_memalign(heap, alignment, size);
+      return memalign(alignment, size);
     }
 #endif
 
@@ -526,7 +432,7 @@ void *mm_memalign(struct mm_heap_s *heap, size_t alignment, 
size_t size)
 }
 
 /****************************************************************************
- * Name: mm_heapmember
+ * Name: umm_heapmember
  *
  * Description:
  *   Check if an address lies in the heap.
@@ -542,13 +448,13 @@ void *mm_memalign(struct mm_heap_s *heap, size_t 
alignment, size_t size)
  *
  ****************************************************************************/
 
-bool mm_heapmember(struct mm_heap_s *heap, void *mem)
+bool umm_heapmember(void *mem)
 {
   return true;
 }
 
 /****************************************************************************
- * Name: mm_brkaddr
+ * Name: umm_brkaddr
  *
  * Description:
  *   Return the break address of a heap region.  Zero is returned if the
@@ -556,13 +462,13 @@ bool mm_heapmember(struct mm_heap_s *heap, void *mem)
  *
  ****************************************************************************/
 
-void *mm_brkaddr(struct mm_heap_s *heap, int region)
+void *umm_brkaddr(int region)
 {
   return NULL;
 }
 
 /****************************************************************************
- * Name: mm_extend
+ * Name: umm_extend
  *
  * Description:
  *   Extend a heap region by add a block of (virtually) contiguous memory
@@ -570,40 +476,42 @@ void *mm_brkaddr(struct mm_heap_s *heap, int region)
  *
  ****************************************************************************/
 
-void mm_extend(struct mm_heap_s *heap, void *mem, size_t size,
-               int region)
+void umm_extend(void *mem, size_t size, int region)
 {
 }
 
 /****************************************************************************
- * Name: mm_mallinfo
+ * Name: mallinfo
  *
  * Description:
  *   mallinfo returns a copy of updated current heap information.
  *
  ****************************************************************************/
 
-struct mallinfo mm_mallinfo(struct mm_heap_s *heap)
+struct mallinfo mallinfo(void)
 {
+  struct mm_heap_s *heap = g_mmheap;
   struct mallinfo info;
 
   memset(&info, 0, sizeof(struct mallinfo));
   info.aordblks = atomic_read(&heap->aordblks);
   info.uordblks = atomic_read(&heap->uordblks);
   info.usmblks  = atomic_read(&heap->usmblks);
+  info.arena    = SIM_HEAP_SIZE;
+  info.fordblks = SIM_HEAP_SIZE - info.uordblks;
+  info.mxordblk = info.fordblks;
   return info;
 }
 
 /****************************************************************************
- * Name: mm_mallinfo_task
+ * Name: mallinfo_task
  *
  * Description:
  *   mallinfo_task returns a copy of updated current task's heap information.
  *
  ****************************************************************************/
 
-struct mallinfo_task mm_mallinfo_task(struct mm_heap_s *heap,
-                                      const struct malltask *task)
+struct mallinfo_task mallinfo_task(const struct malltask *task)
 {
   struct mallinfo_task info =
     {
@@ -614,28 +522,28 @@ struct mallinfo_task mm_mallinfo_task(struct mm_heap_s 
*heap,
 }
 
 /****************************************************************************
- * Name: mm_memdump
+ * Name: umm_memdump
  *
  * Description:
- *   mm_memdump returns a memory info about specified pid of task/thread.
+ *   umm_memdump returns a memory info about specified pid of task/thread.
  *
  ****************************************************************************/
 
-void mm_memdump(struct mm_heap_s *heap, const struct mm_memdump_s *dump)
+void umm_memdump(const struct mm_memdump_s *dump)
 {
 }
 
 #ifdef CONFIG_DEBUG_MM
 
 /****************************************************************************
- * Name: mm_checkcorruption
+ * Name:umm_checkcorruption
  *
  * Description:
- *   mm_checkcorruption is used to check whether memory heap is normal.
+ *   umm_checkcorruption is used to check whether memory heap is normal.
  *
  ****************************************************************************/
 
-void mm_checkcorruption(struct mm_heap_s *heap)
+void umm_checkcorruption(void)
 {
 }
 
@@ -645,7 +553,7 @@ void mm_checkcorruption(struct mm_heap_s *heap)
  * Name: malloc_size
  ****************************************************************************/
 
-size_t mm_malloc_size(struct mm_heap_s *heap, void *mem)
+size_t malloc_size(void *mem)
 {
   return host_mallocsize(mem);
 }
@@ -668,32 +576,22 @@ void up_allocate_heap(void **heap_start, size_t 
*heap_size)
 }
 
 /****************************************************************************
- * Name: mm_heapfree
- *
- * Description:
- *   Return the total free size (in bytes) in the heap
- *
- ****************************************************************************/
-
-size_t mm_heapfree(struct mm_heap_s *heap)
-{
-  return SIZE_MAX;
-}
-
-/****************************************************************************
- * Name: mm_heapfree_largest
+ * Name: umm_initialize
  *
  * Description:
- *   Return the largest chunk of contiguous memory in the heap
+ *   Initialize the selected heap data structures, providing the initial
+ *   heap region.
  *
  ****************************************************************************/
 
-size_t mm_heapfree_largest(struct mm_heap_s *heap)
+void umm_initialize(void *heap_start, size_t heap_size)
 {
-  return SIZE_MAX;
+  sched_note_heap(NOTE_HEAP_ADD, g_mmheap, heap_start, heap_size, 0);
+  UNUSED(heap_start);
+  UNUSED(heap_size);
 }
 
-#else /* CONFIG_MM_CUSTOMIZE_MANAGER */
+#else /* CONFIG_MM_UMM_CUSTOMIZE_MANAGER */
 
 void up_allocate_heap(void **heap_start, size_t *heap_size)
 {
@@ -701,4 +599,4 @@ void up_allocate_heap(void **heap_start, size_t *heap_size)
   *heap_size  = SIM_HEAP_SIZE;
 }
 
-#endif /* CONFIG_MM_CUSTOMIZE_MANAGER */
+#endif /* CONFIG_MM_UMM_CUSTOMIZE_MANAGER */
diff --git a/boards/sim/sim/sim/configs/asan/defconfig 
b/boards/sim/sim/sim/configs/asan/defconfig
index 9a8be136141..03927d542ce 100644
--- a/boards/sim/sim/sim/configs/asan/defconfig
+++ b/boards/sim/sim/sim/configs/asan/defconfig
@@ -25,7 +25,7 @@ CONFIG_FS_PROCFS=y
 CONFIG_INIT_ARGS="\"-c\", \"ostest;poweroff\""
 CONFIG_INIT_ENTRYPOINT="nsh_main"
 CONFIG_LIBC_MAX_EXITFUNS=1
-CONFIG_MM_CUSTOMIZE_MANAGER=y
+CONFIG_MM_UMM_CUSTOMIZE_MANAGER=y
 CONFIG_NSH_ARCHINIT=y
 CONFIG_NSH_BUILTIN_APPS=y
 CONFIG_NSH_READLINE=y
diff --git a/boards/sim/sim/sim/configs/mnemofs/defconfig 
b/boards/sim/sim/sim/configs/mnemofs/defconfig
index f02f30a96e3..58254c78170 100644
--- a/boards/sim/sim/sim/configs/mnemofs/defconfig
+++ b/boards/sim/sim/sim/configs/mnemofs/defconfig
@@ -48,7 +48,7 @@ CONFIG_LIBC_LOCALE_CATALOG=y
 CONFIG_LIBC_LOCALE_GETTEXT=y
 CONFIG_LIBC_MAX_EXITFUNS=1
 CONFIG_LIBC_NUMBERED_ARGS=y
-CONFIG_MM_CUSTOMIZE_MANAGER=y
+CONFIG_MM_UMM_CUSTOMIZE_MANAGER=y
 CONFIG_MTD=y
 CONFIG_MTD_NAND=y
 CONFIG_MTD_NAND_RAM=y
diff --git a/boards/sim/sim/sim/configs/nand/defconfig 
b/boards/sim/sim/sim/configs/nand/defconfig
index f3d17da6b92..060c5faf4ab 100644
--- a/boards/sim/sim/sim/configs/nand/defconfig
+++ b/boards/sim/sim/sim/configs/nand/defconfig
@@ -47,7 +47,7 @@ CONFIG_LIBC_LOCALE_CATALOG=y
 CONFIG_LIBC_LOCALE_GETTEXT=y
 CONFIG_LIBC_MAX_EXITFUNS=1
 CONFIG_LIBC_NUMBERED_ARGS=y
-CONFIG_MM_CUSTOMIZE_MANAGER=y
+CONFIG_MM_UMM_CUSTOMIZE_MANAGER=y
 CONFIG_MTD=y
 CONFIG_MTD_NAND=y
 CONFIG_MTD_NAND_RAM=y
diff --git a/mm/Kconfig b/mm/Kconfig
index 873dfb75c0b..a5904dd19b2 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -25,6 +25,13 @@ config MM_CUSTOMIZE_MANAGER
 
 endchoice
 
+config MM_UMM_CUSTOMIZE_MANAGER
+       bool "Customized heap manager"
+       default n
+       ---help---
+               Customized memory manager policy. The build will fail
+               if the umm heap module not defined by customer.
+
 config MM_KERNEL_HEAP
        bool "Kernel dedicated heap"
        default BUILD_PROTECTED || BUILD_KERNEL
diff --git a/mm/umm_heap/CMakeLists.txt b/mm/umm_heap/CMakeLists.txt
index 5eced744308..76027e6e74d 100644
--- a/mm/umm_heap/CMakeLists.txt
+++ b/mm/umm_heap/CMakeLists.txt
@@ -22,29 +22,31 @@
 
 # User heap allocator
 
-set(SRCS
-    umm_globals.c
-    umm_initialize.c
-    umm_addregion.c
-    umm_malloc_size.c
-    umm_brkaddr.c
-    umm_calloc.c
-    umm_extend.c
-    umm_free.c
-    umm_mallinfo.c
-    umm_malloc.c
-    umm_memalign.c
-    umm_realloc.c
-    umm_zalloc.c
-    umm_heapmember.c
-    umm_memdump.c)
+if(NOT CONFIG_MM_UMM_CUSTOMIZE_MANAGER)
+  set(SRCS
+      umm_globals.c
+      umm_initialize.c
+      umm_addregion.c
+      umm_malloc_size.c
+      umm_brkaddr.c
+      umm_calloc.c
+      umm_extend.c
+      umm_free.c
+      umm_mallinfo.c
+      umm_malloc.c
+      umm_memalign.c
+      umm_realloc.c
+      umm_zalloc.c
+      umm_heapmember.c
+      umm_memdump.c)
 
-if(CONFIG_BUILD_KERNEL)
-  list(APPEND SRCS umm_sbrk.c)
-endif()
+  if(CONFIG_BUILD_KERNEL)
+    list(APPEND SRCS umm_sbrk.c)
+  endif()
 
-if(CONFIG_DEBUG_MM)
-  list(APPEND SRCS umm_checkcorruption.c)
-endif()
+  if(CONFIG_DEBUG_MM)
+    list(APPEND SRCS umm_checkcorruption.c)
+  endif()
 
-target_sources(mm PRIVATE ${SRCS})
+  target_sources(mm PRIVATE ${SRCS})
+endif()
diff --git a/mm/umm_heap/Make.defs b/mm/umm_heap/Make.defs
index 5eb2af2a9f4..8bb51a7d68a 100644
--- a/mm/umm_heap/Make.defs
+++ b/mm/umm_heap/Make.defs
@@ -22,6 +22,7 @@
 
 # User heap allocator
 
+ifeq ($(CONFIG_MM_UMM_CUSTOMIZE_MANAGER),)
 CSRCS += umm_globals.c umm_initialize.c umm_addregion.c umm_malloc_size.c
 CSRCS += umm_brkaddr.c umm_calloc.c umm_extend.c umm_free.c umm_mallinfo.c
 CSRCS += umm_malloc.c umm_memalign.c umm_realloc.c umm_zalloc.c 
umm_heapmember.c
@@ -39,3 +40,4 @@ endif
 
 DEPPATH += --dep-path umm_heap
 VPATH += :umm_heap
+endif

Reply via email to