Hello,

all preparations to use the __getreent() based approach for Newlib reentrancy are now complete. With the attached patches we could enable it. This breaks binary compatibility with previous RTEMS version and it is necessary to update the tool chain for the RTEMS 4.11 branch. Since the GCC 4.8.1 will be released in the next couple of days I think the timing for this change is good.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : [email protected]
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
>From 834038f4bfc073186e8bda40caa75756ec642df9 Mon Sep 17 00:00:00 2001
From: Sebastian Huber <[email protected]>
Date: Thu, 25 Apr 2013 10:48:16 +0200
Subject: [PATCH 1/2] libcsupport: Use _reclaim_reent()

---
 cpukit/libcsupport/src/newlibc_reent.c |   29 +----------------------------
 1 files changed, 1 insertions(+), 28 deletions(-)

diff --git a/cpukit/libcsupport/src/newlibc_reent.c b/cpukit/libcsupport/src/newlibc_reent.c
index 364ef8b..972248f 100644
--- a/cpukit/libcsupport/src/newlibc_reent.c
+++ b/cpukit/libcsupport/src/newlibc_reent.c
@@ -25,12 +25,9 @@
 
 #include <sys/reent.h>
 #include <stdlib.h>
-#include <stdio.h>
 
 #include <rtems/libcsupport.h>
 
-int _fwalk(struct _reent *ptr, int (*function) (FILE *) );
-
 bool newlib_create_hook(
   rtems_tcb *current_task __attribute__((unused)),
   rtems_tcb *creating_task
@@ -60,26 +57,6 @@ bool newlib_create_hook(
   return ok;
 }
 
-static int newlib_free_buffers(
-  FILE *fp
-)
-{
-  switch ( fileno(fp) ) {
-    case 0:
-    case 1:
-    case 2:
-      if (fp->_flags & __SMBF) {
-        free( fp->_bf._base );
-        fp->_flags &= ~__SMBF;
-        fp->_bf._base = fp->_p = (unsigned char *) NULL;
-      }
-      break;
-    default:
-     fclose(fp);
-  }
-  return 0;
-}
-
 void newlib_delete_hook(
   rtems_tcb *current_task,
   rtems_tcb *deleted_task
@@ -90,11 +67,7 @@ void newlib_delete_hook(
   ptr = deleted_task->libc_reent;
   deleted_task->libc_reent = NULL;
 
-  /*
-   *  Just in case there are some buffers lying around.
-   */
-  _fwalk(ptr, newlib_free_buffers);
-
+  _reclaim_reent(ptr);
   _Workspace_Free(ptr);
 }
 
-- 
1.7.7

>From 5ba549235382dcc11d5366146dcf4615ef7575fc Mon Sep 17 00:00:00 2001
From: Sebastian Huber <[email protected]>
Date: Wed, 24 Apr 2013 09:11:27 +0200
Subject: [PATCH 2/2] score: Changes due to Newlib __DYNAMIC_REENT__

Delete _Thread_libc_reent and add __getreent() instead.
---
 cpukit/libcsupport/src/newlibc_reent.c     |    7 -------
 cpukit/sapi/include/confdefs.h             |   16 ++++++++++++++--
 cpukit/score/include/rtems/score/thread.h  |    7 -------
 cpukit/score/inline/rtems/score/thread.inl |   20 --------------------
 cpukit/score/src/threaddispatch.c          |    8 --------
 5 files changed, 14 insertions(+), 44 deletions(-)

diff --git a/cpukit/libcsupport/src/newlibc_reent.c b/cpukit/libcsupport/src/newlibc_reent.c
index 972248f..8640089 100644
--- a/cpukit/libcsupport/src/newlibc_reent.c
+++ b/cpukit/libcsupport/src/newlibc_reent.c
@@ -36,13 +36,6 @@ bool newlib_create_hook(
   struct _reent *ptr;
   bool ok;
 
-  if (_Thread_libc_reent == 0)
-  {
-    _REENT = _GLOBAL_REENT;
-
-    _Thread_Set_libc_reent (&_REENT);
-  }
-
   /* It is OK to allocate from the workspace because these
    * hooks run with thread dispatching disabled.
    */
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index c15c8a3..f4b9232 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -61,6 +61,10 @@
   #include <bsp.h>
 #endif
 
+#ifdef RTEMS_NEWLIB
+  #include <sys/reent.h>
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -1650,6 +1654,16 @@ const rtems_libio_helper rtems_fs_init_helper =
   #define CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS 0
 #endif
 
+#ifdef RTEMS_NEWLIB
+  struct _reent *__getreent(void)
+  {
+    #ifdef CONFIGURE_DISABLE_NEWLIB_REENTRANCY
+      return _GLOBAL_REENT;
+    #else
+      return _Thread_Executing->libc_reent;
+    #endif
+  }
+#endif
 
 #endif
 
@@ -1939,8 +1953,6 @@ const rtems_libio_helper rtems_fs_init_helper =
  */
 
 #if (defined(RTEMS_NEWLIB) && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY))
-  #include <reent.h>
-
   #define CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB \
     _Configure_From_workspace(sizeof(struct _reent))
 #else
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index 248be62..655bff3 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -498,13 +498,6 @@ SCORE_EXTERN Thread_Control *_Thread_Allocated_fp;
 #endif
 
 /**
- * The C library re-enter-rant global pointer. Some C library implementations
- * such as newlib have a single global pointer that changed during a context
- * switch. The pointer points to that global pointer. The Thread control block
- * holds a pointer to the task specific data.
- */
-SCORE_EXTERN struct _reent **_Thread_libc_reent;
-/**
  *  @brief Initialize thread handler.
  *
  *  This routine performs the initialization necessary for this handler.
diff --git a/cpukit/score/inline/rtems/score/thread.inl b/cpukit/score/inline/rtems/score/thread.inl
index 681cfcc..28c036d 100644
--- a/cpukit/score/inline/rtems/score/thread.inl
+++ b/cpukit/score/inline/rtems/score/thread.inl
@@ -345,26 +345,6 @@ RTEMS_INLINE_ROUTINE void _Thread_Internal_free (
 }
 
 /**
- * This routine returns the C library re-enterant pointer.
- */
-
-RTEMS_INLINE_ROUTINE struct _reent **_Thread_Get_libc_reent( void )
-{
-  return _Thread_libc_reent;
-}
-
-/**
- * This routine set the C library re-enterant pointer.
- */
-
-RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent (
-  struct _reent **libc_reent
-)
-{
-  _Thread_libc_reent = libc_reent;
-}
-
-/**
  * This routine evaluates the current scheduling information for the
  * system and determines if a context switch is required.  This
  * is usually called after changing an execution mode such as preemptability
diff --git a/cpukit/score/src/threaddispatch.c b/cpukit/score/src/threaddispatch.c
index 66c7bdc..558ebbb 100644
--- a/cpukit/score/src/threaddispatch.c
+++ b/cpukit/score/src/threaddispatch.c
@@ -139,14 +139,6 @@ void _Thread_Dispatch( void )
       }
     #endif
 
-    /*
-     * Switch libc's task specific data.
-     */
-    if ( _Thread_libc_reent ) {
-      executing->libc_reent = *_Thread_libc_reent;
-      *_Thread_libc_reent = heir->libc_reent;
-    }
-
     _User_extensions_Thread_switch( executing, heir );
 
     /*
-- 
1.7.7

>From 6af3a9d2b4c0bb7713870b4be303ab35b28452cb Mon Sep 17 00:00:00 2001
From: Sebastian Huber <[email protected]>
Date: Mon, 13 May 2013 10:06:40 +0200
Subject: [PATCH] Define __DYNAMIC_REENT__ for RTEMS

This helps to get rid of the global _Thread_libc_reent pointer in RTEMS
which is unsuitable for SMP configurations.  It simplifies also
thread dispatching in RTEMS.

newlib/ChangeLog
2013-05-13  Sebastian Huber <[email protected]>

	* libc/include/sys/config.h (__DYNAMIC_REENT__): Define for
	RTEMS.
---
 newlib/libc/include/sys/config.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index b26017b..c5c7ec0 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -217,6 +217,7 @@
 #if defined(__rtems__)
 #define __FILENAME_MAX__ 255
 #define _READ_WRITE_RETURN_TYPE _ssize_t
+#define __DYNAMIC_REENT__
 #define _REENT_GLOBAL_ATEXIT
 #endif
 
-- 
1.7.7

_______________________________________________
rtems-devel mailing list
[email protected]
http://www.rtems.org/mailman/listinfo/rtems-devel

Reply via email to