casaroli commented on code in PR #21331:
URL: https://github.com/apache/nuttx/pull/21331#discussion_r4437722692


##########
mm/tlsf/mm_tlsf.c:
##########
@@ -317,13 +317,15 @@ static void memdump_backtrace(FAR struct mm_heap_s *heap,
                               FAR struct memdump_backtrace_s *buf)
 {
 #  if CONFIG_MM_BACKTRACE > 0
-  FAR struct tcb_s *tcb;
+  FAR struct tcb_s *tcb = NULL;
 #  endif
 
   buf->pid = _SCHED_GETTID();
   MM_INCSEQNO(buf);
 #  if CONFIG_MM_BACKTRACE > 0
+#    if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
   tcb = nxsched_get_tcb(buf->pid);
+#    endif
   if (heap->mm_procfs.backtrace ||
       (tcb && tcb->flags & TCB_FLAG_HEAP_DUMP))

Review Comment:
   With this patch ported to master (master has no CONFIG_MM_RECORD_STACK, so 
the flag test went into MM_ADD_BACKTRACE()), qemu-armv8a:knsh with 
CONFIG_MM_BACKTRACE=8 gets a data abort in the kernel mm_malloc() when nsh 
starts the first program: it reads tl_flags at tls_get_info() of the caller 
(0xc0018009, a user address of nsh), while the loader has the address 
environment of the new program selected.



##########
include/nuttx/mm/mm.h:
##########
@@ -153,9 +157,15 @@
 #  endif
 #  define MM_DUMP_ASSIGN(dump, node) \
     ((node) != NULL && (dump)->pid == (node)->pid)
-#  define MM_DUMP_LEAK(dump, node) \
+#  if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+#    define MM_DUMP_LEAK(dump, node) \
     ((node) != NULL && (dump)->pid == PID_MM_LEAK && (node)->pid >= 0 && \
      nxsched_get_tcb((node)->pid) == NULL)
+#  else
+#    define MM_DUMP_LEAK(dump, node) \
+    ((node) != NULL && (dump)->pid == PID_MM_LEAK && (node)->pid >= 0 && \
+     kill((node)->pid, 0) != 0)

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to