Ticket #1472: pr1472.diff

File pr1472.diff, 13.4 KB (added by Joel Sherrill, on Jun 30, 2010 at 2:36:06 PM)

Remove Malloc Boundary Code

  • cpukit/libcsupport/Makefile.am

    ? cpukit/libcsupport/src/.rtems_memalign.c.swp
    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/Makefile.am,v
    retrieving revision 1.122
    diff -u -r1.122 Makefile.am
     
    8989    src/_realloc_r.c src/__brk.c src/__sbrk.c src/mallocfreespace.c \
    9090    src/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \
    9191    src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \
    92     src/malloc_statistics_helpers.c src/malloc_boundary.c \
    93     src/posix_memalign.c src/rtems_memalign.c src/malloc_deferred.c \
    94     src/malloc_sbrk_helpers.c src/malloc_dirtier.c src/malloc_p.h \
    95     src/rtems_malloc.c
     92    src/malloc_statistics_helpers.c src/posix_memalign.c \
     93    src/rtems_memalign.c src/malloc_deferred.c src/malloc_sbrk_helpers.c \
     94    src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c
    9695
    9796PASSWORD_GROUP_C_FILES = src/getpwent.c
    9897
  • cpukit/libcsupport/include/rtems/malloc.h

    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/include/rtems/malloc.h,v
    retrieving revision 1.10
    diff -u -r1.10 malloc.h
     
    5656extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
    5757
    5858/*
    59  *  Malloc boundary support plugin
    60  */
    61 typedef struct {
    62   void     (*initialize)(void);
    63   uint32_t (*overhead)(void);
    64   void     (*at_malloc)(void *, size_t);
    65   void     (*at_free)(void *);
    66   void     (*at_realloc)(void *, size_t);
    67 } rtems_malloc_boundary_functions_t;
    68 
    69 extern rtems_malloc_boundary_functions_t rtems_malloc_boundary_helpers_table;
    70 extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers;
    71 
    72 /*
    7359 *  Malloc Heap Extension (sbrk) plugin
    7460 */
    7561typedef struct {
  • cpukit/libcsupport/src/free.c

    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/src/free.c,v
    retrieving revision 1.8
    diff -u -r1.8 free.c
     
    3535  /*
    3636   *  Do not attempt to free memory if in a critical section or ISR.
    3737   */
    38 
    3938  if ( _System_state_Is_up(_System_state_Get()) &&
    4039       !malloc_is_system_state_OK() ) {
    4140      malloc_deferred_free(ptr);
    4241      return;
    4342  }
    4443
    45   #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
    46     /*
    47      *  If configured, check the boundary area
    48      */
    49     if ( rtems_malloc_boundary_helpers )
    50       (*rtems_malloc_boundary_helpers->at_free)(ptr);
    51   #endif
    52 
    5344  /*
    5445   *  If configured, update the statistics
    5546   */
  • cpukit/libcsupport/src/malloc.c

    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/src/malloc.c,v
    retrieving revision 1.58
    diff -u -r1.58 malloc.c
     
    5555    _Protected_heap_Walk( RTEMS_Malloc_Heap, 0, false );
    5656  #endif
    5757
    58   #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
    59     /*
    60      *  If the support for a boundary area at the end of the heap
    61      *  block allocated is turned on, then adjust the size.
    62      */
    63     if (rtems_malloc_boundary_helpers)
    64       size += (*rtems_malloc_boundary_helpers->overhead)();
    65   #endif
    66 
    6758  /*
    6859   * Try to give a segment in the current heap if there is not
    6960   * enough space then try to grow the heap.
     
    9384  if ( rtems_malloc_statistics_helpers )
    9485    (*rtems_malloc_statistics_helpers->at_malloc)(return_this);
    9586
    96   #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
    97     /*
    98      * If configured, set the boundary area
    99      */
    100     if (rtems_malloc_boundary_helpers)
    101       (*rtems_malloc_boundary_helpers->at_malloc)(return_this, size);
    102   #endif
    103 
    10487  return return_this;
    10588}
    10689
  • deleted file cpukit/libcsupport/src/malloc_boundary.c

    RCS file: cpukit/libcsupport/src/malloc_boundary.c
    diff -N cpukit/libcsupport/src/malloc_boundary.c
    + -  
    1 /*
    2  *  RTEMS Malloc Block Boundary Integrity Checker
    3  *
    4  *  WARNING!!!  WARNING!!!  WARNING!!!  WARNING!!!
    5  *  WARNING!!!  WARNING!!!  WARNING!!!  WARNING!!!
    6  *
    7  *  This file is built but never called.  It is a first
    8  *  step in reintegrating this functionality.
    9  *  This code was disabled for a LONG time in malloc.c.
    10  *  This is a restructured and slightly modified version
    11  *  that should be able to be configured as a plugin BUT
    12  *  it has not been tested recently.  When it has been
    13  *  tested again, please remove this comment.
    14  *
    15  *  JOEL: I have not analyzed this code in terms of
    16  *        the heap changes post 4.6.  It is possible
    17  *        that that way the boundary area is carved
    18  *        off breaks the alignment.
    19  *
    20  *  WARNING!!!  WARNING!!!  WARNING!!!  WARNING!!!
    21  *  WARNING!!!  WARNING!!!  WARNING!!!  WARNING!!!
    22  *
    23  *  COPYRIGHT (c) 1989-2007.
    24  *  On-Line Applications Research Corporation (OAR).
    25  *
    26  *  The license and distribution terms for this file may be
    27  *  found in the file LICENSE in this distribution or at
    28  *  http://www.rtems.com/license/LICENSE.
    29  *
    30  *  $Id: malloc_boundary.c,v 1.9 2010/05/23 06:30:23 ralf Exp $
    31  */
    32 
    33 #if HAVE_CONFIG_H
    34 #include "config.h"
    35 #endif
    36 
    37 #include "malloc_p.h"
    38 
    39 #include <stdio.h>
    40 
    41 /* only supported on newlib targets */
    42 #ifdef RTEMS_NEWLIB
    43 /* not completely implemented so not included in coverage analysis */
    44 #ifndef RTEMS_COVERAGE
    45 
    46 #define SENTINELSIZE    12
    47 #define SENTINEL       "\xD1\xAC\xB2\xF1" "BITE ME"
    48 #define CALLCHAINSIZE 5
    49 
    50 struct mallocNode {
    51   struct mallocNode *back;
    52   struct mallocNode *forw;
    53   int                callChain[CALLCHAINSIZE];
    54   size_t             size;
    55   void              *memory;
    56 };
    57 
    58 struct mallocNode mallocNodeHead;
    59 
    60 static void rtems_malloc_boundary_initialize(void)
    61 {
    62   mallocNodeHead.back = &mallocNodeHead;
    63   mallocNodeHead.forw = &mallocNodeHead;
    64 }
    65 
    66 static uint32_t rtems_malloc_boundary_overhead(void)
    67 {
    68   return sizeof(struct mallocNode) + SENTINELSIZE;
    69 }
    70 
    71 static void rtems_malloc_boundary_at_malloc(
    72   void     *pointer,
    73   size_t    size
    74 )
    75 {
    76   void *return_this;
    77   struct mallocNode *mp = (struct mallocNode *)pointer;
    78   intptr_t *fp, *nfp;
    79   int i;
    80 
    81   _RTEMS_Lock_allocator();
    82     mp->memory = mp + 1;
    83     return_this = mp->memory;
    84     mp->size = size - (sizeof(struct mallocNode) + SENTINELSIZE);
    85     fp = (intptr_t *)&size - 2;
    86     for (i = 0 ; i < CALLCHAINSIZE ; i++) {
    87       mp->callChain[i] = fp[1];
    88       nfp = (intptr_t *)(fp[0]);
    89       if((nfp <= fp) || (nfp > (intptr_t *)(INT32_C(0x1000000) /* 1 << 24 */)))
    90        break;
    91       fp = nfp;
    92     }
    93     while (i < CALLCHAINSIZE)
    94       mp->callChain[i++] = 0;
    95     memcpy((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE);
    96     mp->forw = mallocNodeHead.forw;
    97     mp->back = &mallocNodeHead;
    98     mallocNodeHead.forw->back = mp;
    99     mallocNodeHead.forw = mp;
    100   _RTEMS_Unlock_allocator();
    101 }
    102 
    103 static void reportMallocError(const char *msg, struct mallocNode *mp);
    104 
    105 static void rtems_malloc_boundary_at_free(
    106   void     *pointer
    107 )
    108 {
    109   struct mallocNode *mp = (struct mallocNode *)pointer - 1;
    110   struct mallocNode *mp1;
    111 
    112   _RTEMS_Lock_allocator();
    113     if ((mp->memory != (mp + 1)) ||
    114         (memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0))
    115       reportMallocError("Freeing with inconsistent pointer/sentinel", mp);
    116     mp1 = mallocNodeHead.forw;
    117     while (mp1 != &mallocNodeHead) {
    118       if (mp1 == mp)
    119         break;
    120       mp1 = mp1->forw;
    121     }
    122     if (mp1 != mp)
    123       reportMallocError("Freeing, but not on allocated list", mp);
    124     mp->forw->back = mp->back;
    125     mp->back->forw = mp->forw;
    126     mp->back = mp->forw = NULL;
    127     pointer = mp;
    128   _RTEMS_Unlock_allocator();
    129 }
    130 
    131 static void rtems_malloc_boundary_at_realloc(
    132   void     *pointer __attribute__((unused)),
    133   size_t    size __attribute__((unused))
    134 )
    135 {
    136   /* this needs to be implemented */
    137 }
    138 
    139 /*
    140  *  Malloc boundary support plugin
    141  */
    142 rtems_malloc_boundary_functions_t rtems_malloc_boundary_functions_table = {
    143   rtems_malloc_boundary_initialize,
    144   rtems_malloc_boundary_overhead,
    145   rtems_malloc_boundary_at_malloc,
    146   rtems_malloc_boundary_at_free,
    147   rtems_malloc_boundary_at_realloc,
    148 };
    149 
    150 rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers = NULL;
    151 /*   &rtems_malloc_boundary_functions_table; */
    152 
    153 static void reportMallocError(const char *msg, struct mallocNode *mp)
    154 {
    155     unsigned char *sp = (unsigned char *)mp->memory + mp->size;
    156     int i, ind = 0;
    157     static char cbuf[500];
    158     ind += sprintf(cbuf+ind, "Malloc Error: %s\n", msg);
    159     if ((mp->forw->back != mp) || (mp->back->forw != mp))
    160         ind += sprintf(cbuf+ind,
    161             "mp:%p  mp->forw:%p  mp->forw->back:%p  "
    162             "mp->back:%p  mp->back->forw:%p\n",
    163             mp, mp->forw, mp->forw->back, mp->back, mp->back->forw);
    164     if (mp->memory != (mp + 1))
    165         ind += sprintf(cbuf+ind, "mp+1:%p  ", mp + 1);
    166     ind += sprintf(cbuf+ind, "mp->memory:%p  mp->size:%zi\n", mp->memory, mp->size);
    167     if (memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0) {
    168         ind += sprintf(cbuf+ind, "mp->sentinel: ");
    169         for (i = 0 ; i < SENTINELSIZE ; i++)
    170             ind += sprintf(cbuf+ind, " 0x%x", sp[i]);
    171         ind += sprintf(cbuf+ind, "\n");
    172     }
    173     ind += sprintf(cbuf+ind, "Call chain:");
    174     for (i = 0 ; i < CALLCHAINSIZE ; i++) {
    175         if (mp->callChain[i] == 0)
    176             break;
    177         ind += sprintf(cbuf+ind, " 0x%x", mp->callChain[i]);
    178     }
    179     printk("\n\n%s\n\n", cbuf);
    180 }
    181 
    182 #if UNUSED
    183 static void checkMallocArena(void)
    184 {
    185   struct mallocNode *mp;
    186 
    187   _RTEMS_Lock_allocator();
    188     for ( mp = mallocNodeHead.forw; mp != &mallocNodeHead ; mp = mp->forw ) {
    189       if ((mp->forw->back != mp) || (mp->back->forw != mp))
    190         reportMallocError("Pointers mangled", mp);
    191       if ((mp->memory != (mp + 1)) ||
    192           (memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0))
    193         reportMallocError("Inconsistent pointer/sentinel", mp);
    194     }
    195   _RTEMS_Unlock_allocator();
    196 }
    197 #endif
    198 
    199 #endif
    200 #endif
  • cpukit/libcsupport/src/malloc_initialize.c

    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/src/malloc_initialize.c,v
    retrieving revision 1.11
    diff -u -r1.11 malloc_initialize.c
     
    4343  size_t sbrk_amount
    4444)
    4545{
    46   #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
    47     /*
    48      *  If configured, initialize the boundary support
    49      */
    50     if ( rtems_malloc_boundary_helpers != NULL ) {
    51       (*rtems_malloc_boundary_helpers->initialize)();
    52     }
    53   #endif
    54 
    5546  /*
    5647   *  If configured, initialize the statistics support
    5748   */
  • cpukit/libcsupport/src/realloc.c

    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/src/realloc.c,v
    retrieving revision 1.6
    diff -u -r1.6 realloc.c
     
    2727{
    2828  uintptr_t old_size;
    2929  char    *new_area;
    30   uintptr_t resize;
    3130
    3231  MSBUMP(realloc_calls, 1);
    3332
     
    6059  }
    6160
    6261  /*
    63    *  If block boundary integrity checking is enabled, then
    64    *  we need to account for the boundary memory again.
     62   *  Now resize it.
    6563   */
    66   resize = size;
    67   #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
    68     if (rtems_malloc_boundary_helpers)
    69       resize += (*rtems_malloc_boundary_helpers->overhead)();
    70   #endif
    71 
    72   if ( _Protected_heap_Resize_block( RTEMS_Malloc_Heap, ptr, resize ) ) {
    73     #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
    74       /*
    75        *  Successful resize.  Update the boundary on the same block.
    76        */
    77       if (rtems_malloc_boundary_helpers)
    78         (*rtems_malloc_boundary_helpers->at_realloc)(ptr, resize);
    79     #endif
     64  if ( _Protected_heap_Resize_block( RTEMS_Malloc_Heap, ptr, size ) ) {
    8065    return ptr;
    8166  }
    8267
  • cpukit/libcsupport/src/rtems_memalign.c

    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/src/rtems_memalign.c,v
    retrieving revision 1.3
    diff -u -r1.3 rtems_memalign.c
     
    4545    return EINVAL;
    4646
    4747  /*
    48    *
    4948   *  If some free's have been deferred, then do them now.
    5049   */
    5150  malloc_deferred_frees_process();
    5251
    53   #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
    54     /*
    55      *  If the support for a boundary area at the end of the heap
    56      *  block allocated is turned on, then adjust the size.
    57      */
    58     if (rtems_malloc_boundary_helpers)
    59       size += (*rtems_malloc_boundary_helpers->overhead)();
    60   #endif
    61 
    6252  /*
    6353   *  Perform the aligned allocation requested
    6454   */
    65 
    6655  return_this = _Protected_heap_Allocate_aligned(
    6756    RTEMS_Malloc_Heap,
    6857    size,