Hi

Jennifer has been working on a network driver and had some odd failures in
libbsd. I suggested turning on rtems debug and that caused a number of
libbsd tests to fail. She pointed me in the right direction and I found
that the following patch resulted in the stack address being freed
including an "align up" adjustment in some cases. This looks to be from
something Sebastian committed early this month.

https://git.rtems.org/rtems/commit/cpukit/score/src/threadinitialize.c?id=524839568d8df72bb3d62d64cb1b927bc8dbbbf1

I am not sure how that wasn't noticed since about 40 tests were failing on
psim due to that.

I have attached a straightforward patch to address this issue.

Unfortunately, even with this patch and using the RTEMS hash just before
this patch program01 and syscalls01 in libbsd fail. I debugged into
syscalls01 enough to find that there are 7 blocks at the beginning of one
of the tests and 5 after. There is another leak and I tried using the has
before Sebastian's change above but it is still leaking.

On top of that, psxconfig01 and spconfig01 are failing on psim which
appears to be independent. I am not sure what these are but it is something
about minimum stack size not matching. Since I was looking for stack memory
issues, I started to investigate these but decided they were not
allocation/free issues.

Help really appreciated in addressing these leaks.

Thanks.

--joel
From b617122b4c8999284800c2f1a89954edf8e2cd14 Mon Sep 17 00:00:00 2001
From: Joel Sherrill <j...@rtems.org>
Date: Thu, 25 Mar 2021 18:08:23 -0500
Subject: [PATCH 2/2] cpukit stack: Keep and free correct stack address

---
 cpukit/include/rtems/score/stack.h     | 2 ++
 cpukit/include/rtems/score/stackimpl.h | 7 +++++--
 cpukit/score/src/threadinitialize.c    | 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/cpukit/include/rtems/score/stack.h b/cpukit/include/rtems/score/stack.h
index 23421cf..5498145 100644
--- a/cpukit/include/rtems/score/stack.h
+++ b/cpukit/include/rtems/score/stack.h
@@ -52,6 +52,8 @@ extern "C" {
 typedef struct {
   /** This is the stack size. */
   size_t      size;
+  /** This is the allocated address of stack and must be the one freed. */
+  void       *address_to_free;
   /** This is the low memory address of stack. */
   void       *area;
 }   Stack_Control;
diff --git a/cpukit/include/rtems/score/stackimpl.h b/cpukit/include/rtems/score/stackimpl.h
index c152060..92d08e9 100644
--- a/cpukit/include/rtems/score/stackimpl.h
+++ b/cpukit/include/rtems/score/stackimpl.h
@@ -41,17 +41,20 @@ extern "C" {
  * reserved for a stack.
  *
  * @param[out] the_stack The stack to initialize.
+ * @param address_to_free The address allocated which must be freed.
  * @param starting_address The starting_address for the new stack.
  * @param size The size of the stack in bytes.
  */
 RTEMS_INLINE_ROUTINE void _Stack_Initialize (
   Stack_Control *the_stack,
+  void          *address_to_free,
   void          *starting_address,
   size_t         size
 )
 {
-  the_stack->area = starting_address;
-  the_stack->size = size;
+  the_stack->address_to_free = address_to_free;
+  the_stack->area            = starting_address;
+  the_stack->size            = size;
 }
 
 /**
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index 18c98c6..c12436d 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -83,7 +83,7 @@ void _Thread_Free(
    *  Free the rest of the memory associated with this task
    *  and set the associated pointers to NULL for safety.
    */
-  ( *the_thread->Start.stack_free )( the_thread->Start.Initial_stack.area );
+  ( *the_thread->Start.stack_free )( the_thread->Start.Initial_stack.address_to_free );
 
 #if defined(RTEMS_SMP)
   _ISR_lock_Destroy( &the_thread->Scheduler.Lock );
@@ -158,6 +158,7 @@ static bool _Thread_Try_initialize(
 
   _Stack_Initialize(
     &the_thread->Start.Initial_stack,
+    config->stack_area,
     stack_begin,
     stack_end - stack_begin
   );
-- 
1.8.3.1

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to