Changeset 3859cd63 in rtems


Ignore:
Timestamp:
Oct 25, 2019, 1:19:01 PM (6 weeks ago)
Author:
sebastian.huber <sebastian.huber@…>
Branches:
master
Children:
5630008
Parents:
f9648ba
git-author:
sebastian.huber <sebastian.huber@…> (10/25/19 13:19:01)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/05/19 06:29:00)
Message:

rtems-5: Improve heap fatal error information

Update #3806.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/score/heap.h

    rf9648ba r3859cd63  
    135135typedef struct Heap_Block Heap_Block;
    136136
     137/**
     138 * @brief The heap error reason.
     139 *
     140 * @see _Heap_Protection_block_error().
     141 */
     142typedef enum {
     143  /**
     144   * @brief There is an unexpected value in the heap block protector area.
     145   */
     146  HEAP_ERROR_BROKEN_PROTECTOR,
     147
     148  /**
     149   * @brief There is an unexpected value in the free pattern of a free heap
     150   * block.
     151   */
     152  HEAP_ERROR_FREE_PATTERN,
     153
     154  /**
     155   * @brief There is was an attempt to free the same block twice.
     156   */
     157  HEAP_ERROR_DOUBLE_FREE,
     158
     159  /**
     160   * @brief The next block of a supposed to be used block does not indicate that
     161   * the block is used.
     162   */
     163  HEAP_ERROR_BAD_USED_BLOCK,
     164
     165  /**
     166   * @brief A supposed to be free block is not inside the heap memory area.
     167   */
     168  HEAP_ERROR_BAD_FREE_BLOCK
     169} Heap_Error_reason;
     170
     171/**
     172 * @brief Context of a heap error.
     173 *
     174 * @see _Heap_Protection_block_error().
     175 */
     176typedef struct {
     177  /**
     178   * @brief The heap of the block.
     179   */
     180  Heap_Control *heap;
     181
     182  /**
     183   * @brief The heap block causing the error.
     184   */
     185  Heap_Block *block;
     186
     187  /**
     188   * @brief The heap error reason.
     189   */
     190  Heap_Error_reason reason;
     191} Heap_Error_context;
     192
    137193#ifndef HEAP_PROTECTION
    138194  #define HEAP_PROTECTION_HEADER_SIZE 0
     
    154210  );
    155211
     212  typedef void (*_Heap_Protection_error_handler)(
     213     Heap_Control *heap,
     214     Heap_Block *block,
     215     Heap_Error_reason reason
     216  );
     217
    156218  typedef struct {
    157219    _Heap_Protection_handler block_initialize;
    158220    _Heap_Protection_handler block_check;
    159     _Heap_Protection_handler block_error;
     221    _Heap_Protection_error_handler block_error;
    160222    void *handler_data;
    161223    Heap_Block *first_delayed_free_block;
  • cpukit/include/rtems/score/heapimpl.h

    rf9648ba r3859cd63  
    380380  #define _Heap_Protection_block_initialize( heap, block ) ((void) 0)
    381381  #define _Heap_Protection_block_check( heap, block ) ((void) 0)
    382   #define _Heap_Protection_block_error( heap, block ) ((void) 0)
     382  #define _Heap_Protection_block_error( heap, block, reason ) ((void) 0)
    383383  #define _Heap_Protection_free_all_delayed_blocks( heap ) ((void) 0)
    384384#else
     
    401401  static inline void _Heap_Protection_block_error(
    402402    Heap_Control *heap,
    403     Heap_Block *block
     403    Heap_Block *block,
     404    Heap_Error_reason reason
    404405  )
    405406  {
    406     (*heap->Protection.block_error)( heap, block );
     407    (*heap->Protection.block_error)( heap, block, reason );
    407408  }
    408409
  • cpukit/include/rtems/score/interr.h

    rf9648ba r3859cd63  
    139139   */
    140140  RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE = 12,
     141
     142  /**
     143   * @brief Fatal source for heap errors.
     144   *
     145   * The fatal code is the address to a heap error context (Heap_Error_context).
     146   */
     147  RTEMS_FATAL_SOURCE_HEAP = 13,
    141148
    142149  /**
  • cpukit/sapi/src/fatalsrctext.c

    rf9648ba r3859cd63  
    88
    99/*
    10  * Copyright (c) 2013, 2018 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2013, 2019 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
     
    4040  "RTEMS_FATAL_SOURCE_SMP",
    4141  "RTEMS_FATAL_SOURCE_PANIC",
    42   "RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE"
     42  "RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE",
     43  "RTEMS_FATAL_SOURCE_HEAP"
    4344};
    4445
  • cpukit/score/src/heap.c

    rf9648ba r3859cd63  
    148148        || block->Protection_end.protector [1] != HEAP_END_PROTECTOR_1
    149149    ) {
    150       _Heap_Protection_block_error( heap, block );
     150      _Heap_Protection_block_error( heap, block, HEAP_ERROR_BROKEN_PROTECTOR );
    151151    }
    152152  }
     
    154154  static void _Heap_Protection_block_error_default(
    155155    Heap_Control *heap,
    156     Heap_Block *block
     156    Heap_Block *block,
     157    Heap_Error_reason reason
    157158  )
    158159  {
    159     /* FIXME */
    160     _Terminate( INTERNAL_ERROR_CORE, 0xdeadbeef );
     160    Heap_Error_context error_context = {
     161      .heap = heap,
     162      .block = block,
     163      .reason = reason
     164    };
     165
     166    _Terminate( RTEMS_FATAL_SOURCE_HEAP, (uintptr_t) &error_context );
    161167  }
    162168#endif
  • cpukit/score/src/heapallocate.c

    rf9648ba r3859cd63  
    4646
    4747        if ( !_Heap_Is_block_in_heap( heap, block_to_free ) ) {
    48           _Heap_Protection_block_error( heap, block_to_free );
     48          _Heap_Protection_block_error(
     49            heap,
     50            block_to_free,
     51            HEAP_ERROR_BAD_FREE_BLOCK
     52          );
    4953        }
    5054
  • cpukit/score/src/heapfree.c

    rf9648ba r3859cd63  
    7070    for ( current = pattern_begin; current != pattern_end; ++current ) {
    7171      if ( *current != HEAP_FREE_PATTERN ) {
    72         _Heap_Protection_block_error( heap, block );
     72        _Heap_Protection_block_error( heap, block, HEAP_ERROR_FREE_PATTERN );
    7373        break;
    7474      }
     
    9090      _Heap_Protection_check_free_block( heap, block );
    9191    } else {
    92       _Heap_Protection_block_error( heap, block );
     92      _Heap_Protection_block_error( heap, block, HEAP_ERROR_DOUBLE_FREE );
    9393    }
    9494
     
    135135
    136136  if ( !_Heap_Is_prev_used( next_block ) ) {
    137     _Heap_Protection_block_error( heap, block );
     137    _Heap_Protection_block_error( heap, block, HEAP_ERROR_BAD_USED_BLOCK );
    138138    return false;
    139139  }
  • testsuites/sptests/spinternalerror02/init.c

    rf9648ba r3859cd63  
    5454  } while ( text != text_last );
    5555
    56   rtems_test_assert( source - 3 == RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE );
     56  rtems_test_assert( source - 3 == RTEMS_FATAL_SOURCE_HEAP );
    5757}
    5858
  • testsuites/sptests/spinternalerror02/spinternalerror02.scn

    rf9648ba r3859cd63  
    6060RTEMS_FATAL_SOURCE_PANIC
    6161RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE
     62RTEMS_FATAL_SOURCE_HEAP
    6263?
    6364?
Note: See TracChangeset for help on using the changeset viewer.