Ticket #1472: pr1472.diff
File pr1472.diff, 13.4 KB (added by Joel Sherrill, on Jun 30, 2010 at 2:36:06 PM) |
---|
-
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
89 89 src/_realloc_r.c src/__brk.c src/__sbrk.c src/mallocfreespace.c \ 90 90 src/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \ 91 91 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 96 95 97 96 PASSWORD_GROUP_C_FILES = src/getpwent.c 98 97 -
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
56 56 extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers; 57 57 58 58 /* 59 * Malloc boundary support plugin60 */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 /*73 59 * Malloc Heap Extension (sbrk) plugin 74 60 */ 75 61 typedef 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
35 35 /* 36 36 * Do not attempt to free memory if in a critical section or ISR. 37 37 */ 38 39 38 if ( _System_state_Is_up(_System_state_Get()) && 40 39 !malloc_is_system_state_OK() ) { 41 40 malloc_deferred_free(ptr); 42 41 return; 43 42 } 44 43 45 #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)46 /*47 * If configured, check the boundary area48 */49 if ( rtems_malloc_boundary_helpers )50 (*rtems_malloc_boundary_helpers->at_free)(ptr);51 #endif52 53 44 /* 54 45 * If configured, update the statistics 55 46 */ -
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
55 55 _Protected_heap_Walk( RTEMS_Malloc_Heap, 0, false ); 56 56 #endif 57 57 58 #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)59 /*60 * If the support for a boundary area at the end of the heap61 * block allocated is turned on, then adjust the size.62 */63 if (rtems_malloc_boundary_helpers)64 size += (*rtems_malloc_boundary_helpers->overhead)();65 #endif66 67 58 /* 68 59 * Try to give a segment in the current heap if there is not 69 60 * enough space then try to grow the heap. … … 93 84 if ( rtems_malloc_statistics_helpers ) 94 85 (*rtems_malloc_statistics_helpers->at_malloc)(return_this); 95 86 96 #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)97 /*98 * If configured, set the boundary area99 */100 if (rtems_malloc_boundary_helpers)101 (*rtems_malloc_boundary_helpers->at_malloc)(return_this, size);102 #endif103 104 87 return return_this; 105 88 } 106 89 -
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 Checker3 *4 * WARNING!!! WARNING!!! WARNING!!! WARNING!!!5 * WARNING!!! WARNING!!! WARNING!!! WARNING!!!6 *7 * This file is built but never called. It is a first8 * 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 version11 * that should be able to be configured as a plugin BUT12 * it has not been tested recently. When it has been13 * tested again, please remove this comment.14 *15 * JOEL: I have not analyzed this code in terms of16 * the heap changes post 4.6. It is possible17 * that that way the boundary area is carved18 * 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 be27 * found in the file LICENSE in this distribution or at28 * 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_H34 #include "config.h"35 #endif36 37 #include "malloc_p.h"38 39 #include <stdio.h>40 41 /* only supported on newlib targets */42 #ifdef RTEMS_NEWLIB43 /* not completely implemented so not included in coverage analysis */44 #ifndef RTEMS_COVERAGE45 46 #define SENTINELSIZE 1247 #define SENTINEL "\xD1\xAC\xB2\xF1" "BITE ME"48 #define CALLCHAINSIZE 549 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 size74 )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 *pointer107 )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 plugin141 */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 UNUSED183 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 #endif198 199 #endif200 #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
43 43 size_t sbrk_amount 44 44 ) 45 45 { 46 #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)47 /*48 * If configured, initialize the boundary support49 */50 if ( rtems_malloc_boundary_helpers != NULL ) {51 (*rtems_malloc_boundary_helpers->initialize)();52 }53 #endif54 55 46 /* 56 47 * If configured, initialize the statistics support 57 48 */ -
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
27 27 { 28 28 uintptr_t old_size; 29 29 char *new_area; 30 uintptr_t resize;31 30 32 31 MSBUMP(realloc_calls, 1); 33 32 … … 60 59 } 61 60 62 61 /* 63 * If block boundary integrity checking is enabled, then 64 * we need to account for the boundary memory again. 62 * Now resize it. 65 63 */ 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 ) ) { 80 65 return ptr; 81 66 } 82 67 -
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
45 45 return EINVAL; 46 46 47 47 /* 48 *49 48 * If some free's have been deferred, then do them now. 50 49 */ 51 50 malloc_deferred_frees_process(); 52 51 53 #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)54 /*55 * If the support for a boundary area at the end of the heap56 * block allocated is turned on, then adjust the size.57 */58 if (rtems_malloc_boundary_helpers)59 size += (*rtems_malloc_boundary_helpers->overhead)();60 #endif61 62 52 /* 63 53 * Perform the aligned allocation requested 64 54 */ 65 66 55 return_this = _Protected_heap_Allocate_aligned( 67 56 RTEMS_Malloc_Heap, 68 57 size,