Changeset 55d7626 in rtems


Ignore:
Timestamp:
Jul 11, 2007, 8:56:10 PM (12 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
9190d236
Parents:
68b9f58
Message:

2007-07-11 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/malloc.c: Clean up Malloc debug code.
  • score/include/rtems/score/heap.h: Spacing.
  • score/inline/rtems/score/thread.inl:
  • score/src/heapfree.c. Clean up and add explicit check of the address being freed actually being in the heap.
  • score/src/heapwalk.c: Switch to printk and do not call abort.
Location:
cpukit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r68b9f58 r55d7626  
     12007-07-11      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * libcsupport/src/malloc.c: Clean up Malloc debug code.
     4        * score/include/rtems/score/heap.h: Spacing.
     5        * score/inline/rtems/score/thread.inl:
     6        * score/src/heapfree.c. Clean up and add explicit check of the address
     7        being freed actually being in the heap.
     8        * score/src/heapwalk.c: Switch to printk and do not call abort.
     9
    1102007-07-06      Joel Sherrill <joel.sherrill@oarcorp.com>
    211
  • cpukit/libcsupport/src/malloc.c

    r68b9f58 r55d7626  
    9595#define MALLOC_STATS
    9696#define MALLOC_DIRTY
     97/*#define MALLOC_ARENA_CHECK
     98void checkMallocArena(void); */
    9799#endif
    98100
     
    283285      size_t     actual_size = 0;
    284286      uint32_t   current_depth;
    285       Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &actual_size);
     287      void      *ptr = return_this;
     288      _Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &actual_size);
    286289      MSBUMP(lifetime_allocated, actual_size);
    287290      current_depth = rtems_malloc_stats.lifetime_allocated -
     
    465468  {
    466469    size_t size;
    467     if (Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &size) ) {
     470    if (_Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &size) ) {
    468471      MSBUMP(lifetime_freed, size);
    469472    }
  • cpukit/score/include/rtems/score/heap.h

    r68b9f58 r55d7626  
    498498#define _HAssert(cond_) \
    499499  do { \
    500     if(the_heap->stats.instance && !(cond_)) \
     500    if (the_heap->stats.instance && !(cond_)) \
    501501      __assert(__FILE__, __LINE__, #cond_);  \
    502502  } while(0)
  • cpukit/score/inline/rtems/score/thread.inl

    r68b9f58 r55d7626  
    77
    88/*
    9  *  COPYRIGHT (c) 1989-2006.
     9 *  COPYRIGHT (c) 1989-2007.
    1010 *  On-Line Applications Research Corporation (OAR).
    1111 *
     
    140140 */
    141141
     142#if defined(RTEMS_HEAVY_STACK_DEBUG) || defined(RTEMS_HEAVY_MALLOC_DEBUG)
     143  #include <rtems/bspIo.h>
     144  #include <rtems/fatal.h>
     145  #include <rtems/score/sysstate.h>
     146  #include <rtems/score/heap.h>
     147#endif
     148
    142149RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
    143150{
     151  extern boolean rtems_stack_checker_is_blown( void );
     152  extern void malloc_walk(size_t, size_t);
     153
     154  /*
     155   *  This check is very brutal to system performance but is very helpful
     156   *  at finding blown stack problems.  If you have a stack problem and
     157   *  need help finding it, then uncomment this code.  Every system
     158   *  call will check the stack and since mutexes are used frequently
     159   *  in most systems, you might get lucky.
     160   */
     161  #if defined(RTEMS_HEAVY_STACK_DEBUG)
     162    if (_System_state_Is_up(_System_state_Get()) && (_ISR_Nest_level == 0)) {
     163      if ( rtems_stack_checker_is_blown() ) {
     164        printk( "Stack blown!!\n" );
     165        rtems_fatal_error_occurred( 99 );
     166      }
     167    }
     168  #endif
     169
    144170  _Thread_Dispatch_disable_level += 1;
    145171  RTEMS_COMPILER_MEMORY_BARRIER();
     172
     173  /*
     174   * This check is even more brutal than the other one.  This enables
     175   * malloc heap integrity checking upon entry to every system call.
     176   */
     177  #if defined(RTEMS_HEAVY_MALLOC_DEBUG)
     178    if ( _Thread_Dispatch_disable_level == 1 ) {
     179      extern Heap_Control  RTEMS_Malloc_Heap;
     180      _Heap_Walk( &RTEMS_Malloc_Heap,99, FALSE );
     181    }
     182  #endif
    146183}
    147184
  • cpukit/score/src/heapfree.c

    r68b9f58 r55d7626  
    22 *  Heap Handler
    33 *
    4  *  COPYRIGHT (c) 1989-1999.
     4 *  COPYRIGHT (c) 1989-2007.
    55 *  On-Line Applications Research Corporation (OAR).
    66 *
     
    4141)
    4242{
    43   Heap_Block        *the_block;
    44   Heap_Block        *next_block;
     43  Heap_Block      *the_block;
     44  Heap_Block      *next_block;
    4545  uint32_t         the_size;
    4646  uint32_t         next_size;
    4747  Heap_Statistics *const stats = &the_heap->stats;
    48   boolean            next_is_free;
     48  boolean          next_is_free;
     49
     50  if ( !_Addresses_Is_in_range(
     51       starting_address, (void *)the_heap->start, (void *)the_heap->final ) ) {
     52    _HAssert(starting_address != NULL);
     53    return( FALSE );
     54  }
    4955
    5056  _Heap_Start_of_block( the_heap, starting_address, &the_block );
    5157
    5258  if ( !_Heap_Is_block_in( the_heap, the_block ) ) {
    53     _HAssert(starting_address == NULL);
    54     _HAssert(FALSE);
     59    _HAssert( FALSE );
    5560    return( FALSE );
    5661  }
     
    6065
    6166  if ( !_Heap_Is_block_in( the_heap, next_block ) ) {
    62     _HAssert(FALSE);
     67    _HAssert( FALSE );
    6368    return( FALSE );
    6469  }
    6570
    6671  if ( !_Heap_Is_prev_used( next_block ) ) {
    67     _HAssert(FALSE);
     72    _HAssert( FALSE );
    6873    return( FALSE );
    6974  }
     
    7883
    7984    if ( !_Heap_Is_block_in( the_heap, prev_block ) ) {
    80       _HAssert(FALSE);
     85      _HAssert( FALSE );
    8186      return( FALSE );
    8287    }
     
    8590       must have been used. */
    8691    if ( !_Heap_Is_prev_used ( prev_block) ) {
    87       _HAssert(FALSE);
     92      _HAssert( FALSE );
    8893      return( FALSE );
    8994    }
  • cpukit/score/src/heapwalk.c

    r68b9f58 r55d7626  
    22 *  Heap Handler
    33 *
    4  *  COPYRIGHT (c) 1989-1999.
     4 *  COPYRIGHT (c) 1989-2007.
    55 *  On-Line Applications Research Corporation (OAR).
    66 *
     
    2121#include <rtems/score/sysstate.h>
    2222#include <rtems/score/heap.h>
     23#include <rtems/score/interr.h>
     24#include <rtems/bspIo.h>
    2325
    2426/*PAGE
     
    6365  int passes = 0;
    6466
     67  do_dump = FALSE;
    6568  /*
    6669   * We don't want to allow walking the heap until we have
     
    6972   */
    7073
     74/*
    7175  if ( !_System_state_Is_up( _System_state_Get() ) )
    72     return FALSE;
     76    return TRUE;
     77*/
    7378
    7479  if (source < 0)
     
    7681
    7782  if (do_dump == TRUE)
    78     printf("\nPASS: %d start %p final %p first %p last %p begin %p end %p\n",
     83    printk("\nPASS: %d start %p final %p first %p last %p begin %p end %p\n",
    7984      source, the_block, end,
    8085      _Heap_First(the_heap), _Heap_Last(the_heap),
     
    8691
    8792  if (!_Heap_Is_prev_used(the_block)) {
    88     printf("PASS: %d !HEAP_PREV_USED flag of 1st block isn't set\n", source);
     93    printk("PASS: %d !HEAP_PREV_USED flag of 1st block isn't set\n", source);
    8994    error = 1;
    9095  }
    9196
    9297  if (the_block->prev_size != the_heap->page_size) {
    93     printf("PASS: %d !prev_size of 1st block isn't page_size\n", source);
     98    printk("PASS: %d !prev_size of 1st block isn't page_size\n", source);
    9499    error = 1;
    95100  }
     
    101106
    102107    if (do_dump) {
    103       printf("PASS: %d block %p size %d(%c)",
     108      printk("PASS: %d block %p size %d(%c)",
    104109        source, the_block, the_size, (prev_used ? 'U' : 'F'));
    105110      if (prev_used)
    106         printf(" prev_size %d", the_block->prev_size);
     111        printk(" prev_size %d", the_block->prev_size);
    107112      else
    108         printf(" (prev_size) %d", the_block->prev_size);
     113        printk(" (prev_size) %d", the_block->prev_size);
    109114    }
    110115
    111116    if (!_Heap_Is_block_in(the_heap, next_block)) {
    112       if (do_dump) printf("\n");
    113       printf("PASS: %d !block %p is out of heap\n", source, next_block);
     117      if (do_dump) printk("\n");
     118      printk("PASS: %d !block %p is out of heap\n", source, next_block);
    114119      error = 1;
    115120      break;
     
    118123    if (!_Heap_Is_prev_used(next_block)) {
    119124      if (do_dump)
    120         printf( " prev %p next %p", the_block->prev, the_block->next);
     125        printk( " prev %p next %p", the_block->prev, the_block->next);
    121126      if (_Heap_Block_size(the_block) != next_block->prev_size) {
    122         if (do_dump) printf("\n");
    123         printf("PASS: %d !front and back sizes don't match", source);
     127        if (do_dump) printk("\n");
     128        printk("PASS: %d !front and back sizes don't match", source);
    124129        error = 1;
    125130      }
    126131      if (!prev_used) {
    127         if (do_dump || error) printf("\n");
    128         printf("PASS: %d !two consecutive blocks are free", source);
     132        if (do_dump || error) printk("\n");
     133        printk("PASS: %d !two consecutive blocks are free", source);
    129134        error = 1;
    130135      }
     
    135140          block = block->next;
    136141        if(block != the_block) {
    137           if (do_dump || error) printf("\n");
    138           printf("PASS: %d !the_block not in the free list", source);
     142          if (do_dump || error) printk("\n");
     143          printk("PASS: %d !the_block not in the free list", source);
    139144          error = 1;
    140145        }
     
    142147
    143148    }
    144     if (do_dump || error) printf("\n");
     149    if (do_dump || error) printk("\n");
    145150
    146151    if (the_size < the_heap->min_block_size) {
    147       printf("PASS: %d !block size is too small\n", source);
     152      printk("PASS: %d !block size is too small\n", source);
    148153      error = 1;
    149154      break;
    150155    }
    151156    if (!_Heap_Is_aligned( the_size, the_heap->page_size)) {
    152       printf("PASS: %d !block size is misaligned\n", source);
     157      printk("PASS: %d !block size is misaligned\n", source);
    153158      error = 1;
    154159    }
     
    161166
    162167  if (the_block != end) {
    163     printf("PASS: %d !last block address isn't equal to 'final'\n", source);
     168    printk("PASS: %d !last block address isn't equal to 'final'\n", source);
    164169    error = 1;
    165170  }
    166171
    167172  if (_Heap_Block_size(the_block) != the_heap->page_size) {
    168     printf("PASS: %d !last block's size isn't page_size\n", source);
     173    printk("PASS: %d !last block's size isn't page_size\n", source);
    169174    error = 1;
    170175  }
    171176
    172177  if(do_dump && error)
    173     abort();
     178    _Internal_error_Occurred( INTERNAL_ERROR_CORE, TRUE, 0xffff0000 );
    174179
    175   return error == 0;
     180  return error;
    176181
    177182}
Note: See TracChangeset for help on using the changeset viewer.