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

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

commit cc4a2169b0d6c811cdbd6e021eb7c805b7d0439b
Author: wangmingrong1 <[email protected]>
AuthorDate: Mon Nov 2 19:00:08 2026 +0800

    sim/umm: Fix the problem that lasan cannot detect
    
    Independent implementation of sim umm list, flip the high 5 bits of the 
address, so that the memory address will not be recorded in the global 
variable, otherwise Lasan cannot detect the leak
    
    Signed-off-by: wangmingrong1 <[email protected]>
---
 arch/sim/src/sim/sim_ummheap.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/arch/sim/src/sim/sim_ummheap.c b/arch/sim/src/sim/sim_ummheap.c
index c3a1b52253c..65e5e562790 100644
--- a/arch/sim/src/sim/sim_ummheap.c
+++ b/arch/sim/src/sim/sim_ummheap.c
@@ -129,6 +129,48 @@ struct mm_heap_s
   atomic_t usmblks;
 };
 
+/* Independent implementation of sim umm list,
+ * xor the address,
+ * so that the memory address will not be recorded in the global variable,
+ * otherwise Lasan cannot detect the leak
+ * */
+
+#define xor_addr(addr) \
+  ((FAR struct list_node *)((uintptr_t)(addr) ^ ~0ul))
+
+#undef list_initialize
+#define list_initialize(list)                         \
+  do                                                  \
+    {                                                 \
+      FAR struct list_node *__list = (list);          \
+      __list->prev = __list->next = xor_addr(__list); \
+    }                                                 \
+  while(0)
+
+#undef list_add_tail
+#define list_add_tail(list, item)                      \
+  do                                                   \
+    {                                                  \
+      FAR struct list_node *__list = (list);           \
+      FAR struct list_node *__item = (item);           \
+      __item->prev       = __list->prev;               \
+      __item->next       = xor_addr(__list);           \
+      xor_addr(__list->prev)->next = xor_addr(__item); \
+      __list->prev       = xor_addr(__item);           \
+    }                                                  \
+  while (0)
+
+#undef list_delete
+#define list_delete(item)                          \
+  do                                               \
+    {                                              \
+      FAR struct list_node *__item = (item);       \
+      xor_addr(__item->next)->prev = __item->prev; \
+      xor_addr(__item->prev)->next = __item->next; \
+      __item->prev = __item->next = NULL;          \
+    }                                              \
+  while (0)
+
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/

Reply via email to