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

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

commit a5f610ea49aa6fd5e92679ea961296773a72991a
Author: wangshaoxin <[email protected]>
AuthorDate: Tue May 26 16:32:10 2026 +0800

    sched/misc/coredump: add coredump_remove_memory_region()
    
    Memory regions added with coredump_add_memory_region() could never be
    taken out again, so a region that goes away at run time, for example
    the memory of a remote core that is stopped, stayed in the coredump
    list and would be dumped from an invalid address.
    
    Add coredump_remove_memory_region(), which drops the region with exactly
    the given start and size. A region that was merged into a larger one
    when it was added is not found and -ENOENT is returned.
    
    Signed-off-by: wangshaoxin <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 include/nuttx/coredump.h | 10 ++++++++++
 sched/misc/coredump.c    | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/include/nuttx/coredump.h b/include/nuttx/coredump.h
index 2cd687d7860..bf89fd53f4a 100644
--- a/include/nuttx/coredump.h
+++ b/include/nuttx/coredump.h
@@ -70,6 +70,16 @@ struct coredump_info_s
 int coredump_add_memory_region(FAR const void *ptr, size_t size,
                                uint32_t flags);
 
+/****************************************************************************
+ * Name: coredump_remove_memory_region
+ *
+ * Description:
+ *   Remove a previously registered memory region from the coredump list.
+ *
+ ****************************************************************************/
+
+int coredump_remove_memory_region(FAR const void *ptr, size_t size);
+
 /****************************************************************************
  * Name: coredump
  *
diff --git a/sched/misc/coredump.c b/sched/misc/coredump.c
index d919ae47588..3710e8e6c14 100644
--- a/sched/misc/coredump.c
+++ b/sched/misc/coredump.c
@@ -968,6 +968,46 @@ int coredump_add_memory_region(FAR const void *ptr, size_t 
size,
   return 0;
 }
 
+/****************************************************************************
+ * Name: coredump_remove_memory_region
+ *
+ * Description:
+ *   Remove a previously registered memory region from the coredump list.
+ *
+ ****************************************************************************/
+
+int coredump_remove_memory_region(FAR const void *ptr, size_t size)
+{
+  FAR struct memory_region_s *region;
+  size_t i;
+
+  if (g_regions == NULL)
+    {
+      return -ENOENT;
+    }
+
+  region = (FAR struct memory_region_s *)g_regions;
+
+  for (i = 0; region[i].start < region[i].end; i++)
+    {
+      if (region[i].start == (uintptr_t)ptr &&
+          region[i].end == (uintptr_t)ptr + size)
+        {
+          /* Copy each subsequent entry forward, including terminator */
+
+          do
+            {
+              region[i] = region[i + 1];
+            }
+          while (region[i++].start != 0);
+
+          return 0;
+        }
+    }
+
+  return -ENOENT;
+}
+
 /****************************************************************************
  * Name: coredump_initialize
  *

Reply via email to