forked from Imagelibrary/rtems
2010-06-30 Joel Sherrill <joel.sherrilL@OARcorp.com>
PR 1472/cpukit * libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h, libcsupport/src/free.c, libcsupport/src/malloc.c, libcsupport/src/malloc_initialize.c, libcsupport/src/realloc.c, libcsupport/src/rtems_memalign.c: Remove malloc boundary code. It has not been used since before 4.6 and is bitrotted. * libcsupport/src/malloc_boundary.c: Removed.
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
2010-06-30 Joel Sherrill <joel.sherrilL@OARcorp.com>
|
||||
|
||||
PR 1472/cpukit
|
||||
* libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h,
|
||||
libcsupport/src/free.c, libcsupport/src/malloc.c,
|
||||
libcsupport/src/malloc_initialize.c, libcsupport/src/realloc.c,
|
||||
libcsupport/src/rtems_memalign.c: Remove malloc boundary code. It has
|
||||
not been used since before 4.6 and is bitrotted.
|
||||
* libcsupport/src/malloc_boundary.c: Removed.
|
||||
|
||||
2010-06-30 Jennifer.Averett <Jennifer.Averett@OARcorp.com>
|
||||
|
||||
* libcsupport/include/rtems/libio.h, libfs/Makefile.am: Added
|
||||
|
||||
@@ -89,10 +89,9 @@ MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \
|
||||
src/_realloc_r.c src/__brk.c src/__sbrk.c src/mallocfreespace.c \
|
||||
src/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \
|
||||
src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \
|
||||
src/malloc_statistics_helpers.c src/malloc_boundary.c \
|
||||
src/posix_memalign.c src/rtems_memalign.c src/malloc_deferred.c \
|
||||
src/malloc_sbrk_helpers.c src/malloc_dirtier.c src/malloc_p.h \
|
||||
src/rtems_malloc.c
|
||||
src/malloc_statistics_helpers.c src/posix_memalign.c \
|
||||
src/rtems_memalign.c src/malloc_deferred.c src/malloc_sbrk_helpers.c \
|
||||
src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c
|
||||
|
||||
PASSWORD_GROUP_C_FILES = src/getpwent.c
|
||||
|
||||
|
||||
@@ -55,20 +55,6 @@ extern rtems_malloc_statistics_functions_t
|
||||
rtems_malloc_statistics_helpers_table;
|
||||
extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
|
||||
|
||||
/*
|
||||
* Malloc boundary support plugin
|
||||
*/
|
||||
typedef struct {
|
||||
void (*initialize)(void);
|
||||
uint32_t (*overhead)(void);
|
||||
void (*at_malloc)(void *, size_t);
|
||||
void (*at_free)(void *);
|
||||
void (*at_realloc)(void *, size_t);
|
||||
} rtems_malloc_boundary_functions_t;
|
||||
|
||||
extern rtems_malloc_boundary_functions_t rtems_malloc_boundary_helpers_table;
|
||||
extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers;
|
||||
|
||||
/*
|
||||
* Malloc Heap Extension (sbrk) plugin
|
||||
*/
|
||||
|
||||
@@ -35,21 +35,12 @@ void free(
|
||||
/*
|
||||
* Do not attempt to free memory if in a critical section or ISR.
|
||||
*/
|
||||
|
||||
if ( _System_state_Is_up(_System_state_Get()) &&
|
||||
!malloc_is_system_state_OK() ) {
|
||||
malloc_deferred_free(ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If configured, check the boundary area
|
||||
*/
|
||||
if ( rtems_malloc_boundary_helpers )
|
||||
(*rtems_malloc_boundary_helpers->at_free)(ptr);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If configured, update the statistics
|
||||
*/
|
||||
|
||||
@@ -55,15 +55,6 @@ void *malloc(
|
||||
_Protected_heap_Walk( RTEMS_Malloc_Heap, 0, false );
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If the support for a boundary area at the end of the heap
|
||||
* block allocated is turned on, then adjust the size.
|
||||
*/
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
size += (*rtems_malloc_boundary_helpers->overhead)();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Try to give a segment in the current heap if there is not
|
||||
* enough space then try to grow the heap.
|
||||
@@ -93,14 +84,6 @@ void *malloc(
|
||||
if ( rtems_malloc_statistics_helpers )
|
||||
(*rtems_malloc_statistics_helpers->at_malloc)(return_this);
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If configured, set the boundary area
|
||||
*/
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
(*rtems_malloc_boundary_helpers->at_malloc)(return_this, size);
|
||||
#endif
|
||||
|
||||
return return_this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* RTEMS Malloc Block Boundary Integrity Checker
|
||||
*
|
||||
* WARNING!!! WARNING!!! WARNING!!! WARNING!!!
|
||||
* WARNING!!! WARNING!!! WARNING!!! WARNING!!!
|
||||
*
|
||||
* This file is built but never called. It is a first
|
||||
* step in reintegrating this functionality.
|
||||
* This code was disabled for a LONG time in malloc.c.
|
||||
* This is a restructured and slightly modified version
|
||||
* that should be able to be configured as a plugin BUT
|
||||
* it has not been tested recently. When it has been
|
||||
* tested again, please remove this comment.
|
||||
*
|
||||
* JOEL: I have not analyzed this code in terms of
|
||||
* the heap changes post 4.6. It is possible
|
||||
* that that way the boundary area is carved
|
||||
* off breaks the alignment.
|
||||
*
|
||||
* WARNING!!! WARNING!!! WARNING!!! WARNING!!!
|
||||
* WARNING!!! WARNING!!! WARNING!!! WARNING!!!
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "malloc_p.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* only supported on newlib targets */
|
||||
#ifdef RTEMS_NEWLIB
|
||||
/* not completely implemented so not included in coverage analysis */
|
||||
#ifndef RTEMS_COVERAGE
|
||||
|
||||
#define SENTINELSIZE 12
|
||||
#define SENTINEL "\xD1\xAC\xB2\xF1" "BITE ME"
|
||||
#define CALLCHAINSIZE 5
|
||||
|
||||
struct mallocNode {
|
||||
struct mallocNode *back;
|
||||
struct mallocNode *forw;
|
||||
int callChain[CALLCHAINSIZE];
|
||||
size_t size;
|
||||
void *memory;
|
||||
};
|
||||
|
||||
struct mallocNode mallocNodeHead;
|
||||
|
||||
static void rtems_malloc_boundary_initialize(void)
|
||||
{
|
||||
mallocNodeHead.back = &mallocNodeHead;
|
||||
mallocNodeHead.forw = &mallocNodeHead;
|
||||
}
|
||||
|
||||
static uint32_t rtems_malloc_boundary_overhead(void)
|
||||
{
|
||||
return sizeof(struct mallocNode) + SENTINELSIZE;
|
||||
}
|
||||
|
||||
static void rtems_malloc_boundary_at_malloc(
|
||||
void *pointer,
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
void *return_this;
|
||||
struct mallocNode *mp = (struct mallocNode *)pointer;
|
||||
intptr_t *fp, *nfp;
|
||||
int i;
|
||||
|
||||
_RTEMS_Lock_allocator();
|
||||
mp->memory = mp + 1;
|
||||
return_this = mp->memory;
|
||||
mp->size = size - (sizeof(struct mallocNode) + SENTINELSIZE);
|
||||
fp = (intptr_t *)&size - 2;
|
||||
for (i = 0 ; i < CALLCHAINSIZE ; i++) {
|
||||
mp->callChain[i] = fp[1];
|
||||
nfp = (intptr_t *)(fp[0]);
|
||||
if((nfp <= fp) || (nfp > (intptr_t *)(INT32_C(0x1000000) /* 1 << 24 */)))
|
||||
break;
|
||||
fp = nfp;
|
||||
}
|
||||
while (i < CALLCHAINSIZE)
|
||||
mp->callChain[i++] = 0;
|
||||
memcpy((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE);
|
||||
mp->forw = mallocNodeHead.forw;
|
||||
mp->back = &mallocNodeHead;
|
||||
mallocNodeHead.forw->back = mp;
|
||||
mallocNodeHead.forw = mp;
|
||||
_RTEMS_Unlock_allocator();
|
||||
}
|
||||
|
||||
static void reportMallocError(const char *msg, struct mallocNode *mp);
|
||||
|
||||
static void rtems_malloc_boundary_at_free(
|
||||
void *pointer
|
||||
)
|
||||
{
|
||||
struct mallocNode *mp = (struct mallocNode *)pointer - 1;
|
||||
struct mallocNode *mp1;
|
||||
|
||||
_RTEMS_Lock_allocator();
|
||||
if ((mp->memory != (mp + 1)) ||
|
||||
(memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0))
|
||||
reportMallocError("Freeing with inconsistent pointer/sentinel", mp);
|
||||
mp1 = mallocNodeHead.forw;
|
||||
while (mp1 != &mallocNodeHead) {
|
||||
if (mp1 == mp)
|
||||
break;
|
||||
mp1 = mp1->forw;
|
||||
}
|
||||
if (mp1 != mp)
|
||||
reportMallocError("Freeing, but not on allocated list", mp);
|
||||
mp->forw->back = mp->back;
|
||||
mp->back->forw = mp->forw;
|
||||
mp->back = mp->forw = NULL;
|
||||
pointer = mp;
|
||||
_RTEMS_Unlock_allocator();
|
||||
}
|
||||
|
||||
static void rtems_malloc_boundary_at_realloc(
|
||||
void *pointer __attribute__((unused)),
|
||||
size_t size __attribute__((unused))
|
||||
)
|
||||
{
|
||||
/* this needs to be implemented */
|
||||
}
|
||||
|
||||
/*
|
||||
* Malloc boundary support plugin
|
||||
*/
|
||||
rtems_malloc_boundary_functions_t rtems_malloc_boundary_functions_table = {
|
||||
rtems_malloc_boundary_initialize,
|
||||
rtems_malloc_boundary_overhead,
|
||||
rtems_malloc_boundary_at_malloc,
|
||||
rtems_malloc_boundary_at_free,
|
||||
rtems_malloc_boundary_at_realloc,
|
||||
};
|
||||
|
||||
rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers = NULL;
|
||||
/* &rtems_malloc_boundary_functions_table; */
|
||||
|
||||
static void reportMallocError(const char *msg, struct mallocNode *mp)
|
||||
{
|
||||
unsigned char *sp = (unsigned char *)mp->memory + mp->size;
|
||||
int i, ind = 0;
|
||||
static char cbuf[500];
|
||||
ind += sprintf(cbuf+ind, "Malloc Error: %s\n", msg);
|
||||
if ((mp->forw->back != mp) || (mp->back->forw != mp))
|
||||
ind += sprintf(cbuf+ind,
|
||||
"mp:%p mp->forw:%p mp->forw->back:%p "
|
||||
"mp->back:%p mp->back->forw:%p\n",
|
||||
mp, mp->forw, mp->forw->back, mp->back, mp->back->forw);
|
||||
if (mp->memory != (mp + 1))
|
||||
ind += sprintf(cbuf+ind, "mp+1:%p ", mp + 1);
|
||||
ind += sprintf(cbuf+ind, "mp->memory:%p mp->size:%zi\n", mp->memory, mp->size);
|
||||
if (memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0) {
|
||||
ind += sprintf(cbuf+ind, "mp->sentinel: ");
|
||||
for (i = 0 ; i < SENTINELSIZE ; i++)
|
||||
ind += sprintf(cbuf+ind, " 0x%x", sp[i]);
|
||||
ind += sprintf(cbuf+ind, "\n");
|
||||
}
|
||||
ind += sprintf(cbuf+ind, "Call chain:");
|
||||
for (i = 0 ; i < CALLCHAINSIZE ; i++) {
|
||||
if (mp->callChain[i] == 0)
|
||||
break;
|
||||
ind += sprintf(cbuf+ind, " 0x%x", mp->callChain[i]);
|
||||
}
|
||||
printk("\n\n%s\n\n", cbuf);
|
||||
}
|
||||
|
||||
#if UNUSED
|
||||
static void checkMallocArena(void)
|
||||
{
|
||||
struct mallocNode *mp;
|
||||
|
||||
_RTEMS_Lock_allocator();
|
||||
for ( mp = mallocNodeHead.forw; mp != &mallocNodeHead ; mp = mp->forw ) {
|
||||
if ((mp->forw->back != mp) || (mp->back->forw != mp))
|
||||
reportMallocError("Pointers mangled", mp);
|
||||
if ((mp->memory != (mp + 1)) ||
|
||||
(memcmp((char *)mp->memory + mp->size, SENTINEL, SENTINELSIZE) != 0))
|
||||
reportMallocError("Inconsistent pointer/sentinel", mp);
|
||||
}
|
||||
_RTEMS_Unlock_allocator();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -43,15 +43,6 @@ void RTEMS_Malloc_Initialize(
|
||||
size_t sbrk_amount
|
||||
)
|
||||
{
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If configured, initialize the boundary support
|
||||
*/
|
||||
if ( rtems_malloc_boundary_helpers != NULL ) {
|
||||
(*rtems_malloc_boundary_helpers->initialize)();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If configured, initialize the statistics support
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,6 @@ void *realloc(
|
||||
{
|
||||
uintptr_t old_size;
|
||||
char *new_area;
|
||||
uintptr_t resize;
|
||||
|
||||
MSBUMP(realloc_calls, 1);
|
||||
|
||||
@@ -60,23 +59,9 @@ void *realloc(
|
||||
}
|
||||
|
||||
/*
|
||||
* If block boundary integrity checking is enabled, then
|
||||
* we need to account for the boundary memory again.
|
||||
* Now resize it.
|
||||
*/
|
||||
resize = size;
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
resize += (*rtems_malloc_boundary_helpers->overhead)();
|
||||
#endif
|
||||
|
||||
if ( _Protected_heap_Resize_block( RTEMS_Malloc_Heap, ptr, resize ) ) {
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* Successful resize. Update the boundary on the same block.
|
||||
*/
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
(*rtems_malloc_boundary_helpers->at_realloc)(ptr, resize);
|
||||
#endif
|
||||
if ( _Protected_heap_Resize_block( RTEMS_Malloc_Heap, ptr, size ) ) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,24 +45,13 @@ int rtems_memalign(
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
*
|
||||
* If some free's have been deferred, then do them now.
|
||||
*/
|
||||
malloc_deferred_frees_process();
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If the support for a boundary area at the end of the heap
|
||||
* block allocated is turned on, then adjust the size.
|
||||
*/
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
size += (*rtems_malloc_boundary_helpers->overhead)();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Perform the aligned allocation requested
|
||||
*/
|
||||
|
||||
return_this = _Protected_heap_Allocate_aligned(
|
||||
RTEMS_Malloc_Heap,
|
||||
size,
|
||||
|
||||
Reference in New Issue
Block a user