Changeset cedfd802 in rtems


Ignore:
Timestamp:
Jul 30, 2009, 12:14:26 AM (11 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
8b40e27
Parents:
e63b79d
Message:

2009-07-29 Joel Sherrill <joel.sherrill@…>

  • score/src/threadinitialize.c: Rework so there is only one error exit path. This required setting every variable that contains memory allocated from the workspace to NULL early and using that assumption in the one failed exit path.
Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    re63b79d rcedfd802  
     12009-07-29      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * score/src/threadinitialize.c: Rework so there is only one error exit
     4        path. This required setting every variable that contains memory
     5        allocated from the workspace to NULL early and using that assumption
     6        in the one failed exit path.
     7
    182009-07-29      Joel Sherrill <joel.sherrill@oarcorp.com>
    29
  • cpukit/score/src/threadinitialize.c

    re63b79d rcedfd802  
    5858  size_t               actual_stack_size = 0;
    5959  void                *stack = NULL;
    60 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    61   void                *fp_area;
    62 #endif
     60  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
     61    void              *fp_area;
     62  #endif
    6363  void                *extensions_area;
    6464  bool                 extension_status;
    65 
    66 #if __RTEMS_ADA__
     65  int                  i;
     66
    6767  /*
    6868   *  Initialize the Ada self pointer
    6969   */
    70 
    71   the_thread->rtems_ada_self = NULL;
    72 #endif
     70  #if __RTEMS_ADA__
     71    the_thread->rtems_ada_self = NULL;
     72  #endif
     73
     74  /*
     75   *  Zero out all the allocated memory fields
     76   */
     77  for ( i=0 ; i <= THREAD_API_LAST ; i++ )
     78    the_thread->API_Extensions[i] = NULL;
     79
     80  extensions_area = NULL;
     81  the_thread->libc_reent = NULL;
     82
     83  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
     84    fp_area = NULL;
     85  #endif
    7386
    7487  /*
    7588   *  Allocate and Initialize the stack for this thread.
    7689   */
    77 
    78 
    7990  if ( !stack_area ) {
    80 
    8191    actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size );
    82 
    8392    if ( !actual_stack_size || actual_stack_size < stack_size )
    8493      return false;                     /* stack allocation failed */
     
    101110   *  Allocate the floating point area for this thread
    102111   */
    103 
    104 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    105   if ( is_fp ) {
    106 
    107     fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
    108     if ( !fp_area ) {
    109       _Thread_Stack_Free( the_thread );
    110       return false;
     112  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
     113    if ( is_fp ) {
     114      fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
     115      if ( !fp_area )
     116        goto failed;
     117      fp_area = _Context_Fp_start( fp_area, 0 );
    111118    }
    112     fp_area = _Context_Fp_start( fp_area, 0 );
    113 
    114   } else
    115     fp_area = NULL;
    116 
    117   the_thread->fp_context       = fp_area;
    118   the_thread->Start.fp_context = fp_area;
    119 #endif
     119    the_thread->fp_context       = fp_area;
     120    the_thread->Start.fp_context = fp_area;
     121  #endif
    120122
    121123  /*
     
    124126  _Watchdog_Initialize( &the_thread->Timer, NULL, 0, NULL );
    125127
    126 #ifdef __RTEMS_STRICT_ORDER_MUTEX__
    127   /*Initialize the head of chain of mutex */
    128   _Chain_Initialize_empty(&the_thread->lock_mutex);
    129 #endif
    130 
    131   /*
    132    * Clear the libc reent hook.
    133    */
    134 
    135   the_thread->libc_reent = NULL;
     128  #ifdef __RTEMS_STRICT_ORDER_MUTEX__
     129    /* Initialize the head of chain of held mutexes */
     130    _Chain_Initialize_empty(&the_thread->lock_mutex);
     131  #endif
    136132
    137133  /*
    138134   *  Allocate the extensions area for this thread
    139135   */
    140 
    141136  if ( _Thread_Maximum_extensions ) {
    142137    extensions_area = _Workspace_Allocate(
    143138      (_Thread_Maximum_extensions + 1) * sizeof( void * )
    144139    );
    145 
    146     if ( !extensions_area ) {
    147 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    148       if ( fp_area )
    149         (void) _Workspace_Free( fp_area );
    150 #endif
    151 
    152       _Thread_Stack_Free( the_thread );
    153 
    154       return false;
    155     }
    156   } else
    157     extensions_area = NULL;
    158 
     140    if ( !extensions_area )
     141      goto failed;
     142  }
    159143  the_thread->extensions = (void **) extensions_area;
    160144
     
    166150   * call.
    167151   */
    168 
    169152  if ( the_thread->extensions ) {
    170     uint32_t i;
    171     for ( i = 0; i < (_Thread_Maximum_extensions + 1); i++ )
     153    for ( i = 0; i <= _Thread_Maximum_extensions ; i++ )
    172154      the_thread->extensions[i] = NULL;
    173155  }
     
    207189   *  Initialize the CPU usage statistics
    208190   */
    209 
    210191  #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
    211192    _Timestamp_Set_to_zero( &the_thread->cpu_time_used );
     
    217198   *  Open the object
    218199   */
    219 
    220200  _Objects_Open( information, &the_thread->Object, name );
    221201
     
    228208   */
    229209  extension_status = _User_extensions_Thread_create( the_thread );
    230 
    231   if ( !extension_status ) {
    232 
    233     if ( extensions_area )
    234       (void) _Workspace_Free( extensions_area );
    235 
    236 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
     210  if ( extension_status )
     211    return true;
     212
     213failed:
     214  if ( the_thread->libc_reent )
     215    _Workspace_Free( the_thread->libc_reent );
     216
     217  for ( i=0 ; i <= THREAD_API_LAST ; i++ )
     218    if ( the_thread->API_Extensions[i] )
     219      _Workspace_Free( the_thread->API_Extensions[i] );
     220 
     221  if ( extensions_area )
     222    (void) _Workspace_Free( extensions_area );
     223
     224  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    237225    if ( fp_area )
    238226      (void) _Workspace_Free( fp_area );
    239 #endif
    240 
    241     _Thread_Stack_Free( the_thread );
    242 
    243     return false;
    244   }
    245 
    246   return true;
     227  #endif
     228
     229   _Thread_Stack_Free( the_thread );
     230  return false;
     231
    247232
    248233}
Note: See TracChangeset for help on using the changeset viewer.