On 23/01/2021 07:27, Utkarsh Rai wrote:

The issue that remains is of User extension iterators, in particular of nested iterators. My idea is to disable memory protection in places during iteration where inter-stack access takes place.  The problem is determining the region for which memory protection needs to be disabled. One way to get around this would be by disabling memory protection for all the stacks, in a blanket-based manner.

I used this approach for a Nios II system with a thread stack protection. We trust the operating system, so this approach should be fine.

diff --git a/cpukit/score/src/userextiterate.c b/cpukit/score/src/userextiterate.c
index a25a4ad768..3e56c3a39d 100644
--- a/cpukit/score/src/userextiterate.c
+++ b/cpukit/score/src/userextiterate.c
@@ -34,6 +34,10 @@

 #include <rtems/score/userextimpl.h>

+#ifdef BSP_NIOS2_USE_MPU
+#include <rtems/score/nios2-utility.h>
+#endif
+
 #include <pthread.h>

 User_extensions_List _User_extensions_List = {
@@ -188,6 +192,9 @@ void _User_extensions_Iterate(
   }

   _User_extensions_Acquire( &lock_context );
+#ifdef BSP_NIOS2_USE_MPU
+  uint32_t config = _Nios2_MPU_Disable();
+#endif

   _Chain_Iterator_initialize(
     &_User_extensions_List.Active,
@@ -206,12 +213,18 @@ void _User_extensions_Iterate(

     _Chain_Iterator_set_position( &iter.Iterator, node );

+#ifdef BSP_NIOS2_USE_MPU
+    _Nios2_MPU_Restore( config );
+#endif
     _User_extensions_Release( &lock_context );

     extension = (const User_extensions_Control *) node;
     ( *visitor )( executing, arg, &extension->Callouts );

     _User_extensions_Acquire( &lock_context );
+#ifdef BSP_NIOS2_USE_MPU
+    config = _Nios2_MPU_Disable();
+#endif
   }

   if ( executing != NULL ) {
@@ -220,6 +233,9 @@ void _User_extensions_Iterate(

   _Chain_Iterator_destroy( &iter.Iterator );

+#ifdef BSP_NIOS2_USE_MPU
+  _Nios2_MPU_Restore( config );
+#endif
   _User_extensions_Release( &lock_context );

   if ( direction == CHAIN_ITERATOR_BACKWARD ) {

The other possibility is to access the last blocked thread and disable memory protection just for the stack of this thread (as inter-stack access of the previously blocked thread takes place during iteration). How to get access to the queue of blocked threads? And is this method feasible?
The system doesn't know the last blocked thread currently. I am not sure if knowing the last blocked thread helps you here.

--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

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

Reply via email to