mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-08-24 20:59:48 +08:00
2008-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/src/free.c, libcsupport/src/malloc.c, libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h, libcsupport/src/malloc_sbrk_helpers.c, libcsupport/src/malloc_statistics_helpers.c, libcsupport/src/malloc_walk.c, libcsupport/src/mallocfreespace.c, libcsupport/src/mallocinfo.c, libcsupport/src/realloc.c, libcsupport/src/rtems_memalign.c, sapi/include/confdefs.h, score/inline/rtems/score/thread.inl: Add support for optionally having a unified work area. In other words, the RTEMS Workspace and C Program Heap are the same pool of memory.
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
2008-09-17 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||
|
||||
* libcsupport/src/free.c, libcsupport/src/malloc.c,
|
||||
libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h,
|
||||
libcsupport/src/malloc_sbrk_helpers.c,
|
||||
libcsupport/src/malloc_statistics_helpers.c,
|
||||
libcsupport/src/malloc_walk.c, libcsupport/src/mallocfreespace.c,
|
||||
libcsupport/src/mallocinfo.c, libcsupport/src/realloc.c,
|
||||
libcsupport/src/rtems_memalign.c, sapi/include/confdefs.h,
|
||||
score/inline/rtems/score/thread.inl: Add support for optionally
|
||||
having a unified work area. In other words, the RTEMS Workspace and C
|
||||
Program Heap are the same pool of memory.
|
||||
|
||||
2008-09-17 Miao Yan <yanmiaobest@gmail.com>
|
||||
|
||||
* Makefile.am, preinstall.am, libcsupport/Makefile.am,
|
||||
|
||||
@@ -29,7 +29,7 @@ void free(
|
||||
return;
|
||||
|
||||
#if defined(RTEMS_HEAP_DEBUG)
|
||||
_Protected_heap_Walk( &RTEMS_Malloc_Heap, 0, false );
|
||||
_Protected_heap_Walk( RTEMS_Malloc_Heap, 0, false );
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -56,11 +56,11 @@ void free(
|
||||
if ( rtems_malloc_statistics_helpers )
|
||||
(*rtems_malloc_statistics_helpers->at_free)(ptr);
|
||||
|
||||
if ( !_Protected_heap_Free( &RTEMS_Malloc_Heap, ptr ) ) {
|
||||
if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) {
|
||||
printk( "Program heap: free of bad pointer %p -- range %p - %p \n",
|
||||
ptr,
|
||||
RTEMS_Malloc_Heap.start,
|
||||
RTEMS_Malloc_Heap.end
|
||||
RTEMS_Malloc_Heap->start,
|
||||
RTEMS_Malloc_Heap->end
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ void *malloc(
|
||||
* Walk the heap and verify its integrity
|
||||
*/
|
||||
#if defined(RTEMS_HEAP_DEBUG)
|
||||
_Protected_heap_Walk( &RTEMS_Malloc_Heap, 0, false );
|
||||
_Protected_heap_Walk( RTEMS_Malloc_Heap, 0, false );
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
@@ -70,7 +70,7 @@ void *malloc(
|
||||
* If this fails then return a NULL pointer.
|
||||
*/
|
||||
|
||||
return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
|
||||
return_this = _Protected_heap_Allocate( RTEMS_Malloc_Heap, size );
|
||||
|
||||
if ( !return_this ) {
|
||||
if (rtems_malloc_sbrk_helpers)
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/malloc.h>
|
||||
#include <rtems/score/wkspace.h>
|
||||
#include "malloc_p.h"
|
||||
|
||||
Heap_Control RTEMS_Malloc_Heap;
|
||||
rtems_malloc_statistics_t rtems_malloc_statistics;
|
||||
extern bool rtems_unified_work_area;
|
||||
|
||||
void RTEMS_Malloc_Initialize(
|
||||
void *start,
|
||||
@@ -62,6 +63,13 @@ void RTEMS_Malloc_Initialize(
|
||||
sbrk_amount
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* If this system is configured to use the same heap for
|
||||
* the RTEMS Workspace and C Program Heap, then we need to
|
||||
* be very very careful about destroying the initialization
|
||||
* that has already been done.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If the BSP is not clearing out the workspace, then it is most likely
|
||||
@@ -74,7 +82,8 @@ void RTEMS_Malloc_Initialize(
|
||||
* left over from another process. This would be a security violation.
|
||||
*/
|
||||
|
||||
if ( rtems_configuration_get_do_zero_of_workspace() )
|
||||
if ( !rtems_unified_work_area &&
|
||||
rtems_configuration_get_do_zero_of_workspace() )
|
||||
memset( starting_address, 0, length );
|
||||
|
||||
/*
|
||||
@@ -83,17 +92,19 @@ void RTEMS_Malloc_Initialize(
|
||||
* STDIO cannot work because there will be no buffers.
|
||||
*/
|
||||
|
||||
status = _Protected_heap_Initialize(
|
||||
&RTEMS_Malloc_Heap,
|
||||
starting_address,
|
||||
length,
|
||||
CPU_HEAP_ALIGNMENT
|
||||
);
|
||||
if ( !status )
|
||||
rtems_fatal_error_occurred( status );
|
||||
if ( !rtems_unified_work_area ) {
|
||||
status = _Protected_heap_Initialize(
|
||||
RTEMS_Malloc_Heap,
|
||||
starting_address,
|
||||
length,
|
||||
CPU_HEAP_ALIGNMENT
|
||||
);
|
||||
if ( !status )
|
||||
rtems_fatal_error_occurred( status );
|
||||
}
|
||||
|
||||
#if defined(RTEMS_HEAP_DEBUG)
|
||||
if ( _Protected_heap_Walk( &RTEMS_Malloc_Heap, 0, false ) ) {
|
||||
if ( _Protected_heap_Walk( RTEMS_Malloc_Heap, 0, false ) ) {
|
||||
printk( "Malloc heap not initialized correctly\n" );
|
||||
rtems_print_buffer( start, 32 );
|
||||
printk( "\n" );
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
/*
|
||||
* Basic management data
|
||||
*/
|
||||
extern Heap_Control RTEMS_Malloc_Heap;
|
||||
extern Heap_Control *RTEMS_Malloc_Heap;
|
||||
|
||||
/*
|
||||
* Malloc Statistics Structure
|
||||
|
||||
@@ -89,7 +89,7 @@ void *malloc_sbrk_extend_and_allocate(
|
||||
return (void *) 0;
|
||||
|
||||
if ( !_Protected_heap_Extend(
|
||||
&RTEMS_Malloc_Heap, starting_address, the_size) ) {
|
||||
RTEMS_Malloc_Heap, starting_address, the_size) ) {
|
||||
sbrk(-the_size);
|
||||
errno = ENOMEM;
|
||||
return (void *) 0;
|
||||
@@ -97,7 +97,7 @@ void *malloc_sbrk_extend_and_allocate(
|
||||
|
||||
MSBUMP(space_available, the_size);
|
||||
|
||||
return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
|
||||
return_this = _Protected_heap_Allocate( RTEMS_Malloc_Heap, size );
|
||||
return return_this;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ void rtems_malloc_statistics_at_malloc(
|
||||
if ( !pointer )
|
||||
return;
|
||||
|
||||
_Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, pointer, &actual_size);
|
||||
_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &actual_size);
|
||||
|
||||
MSBUMP(lifetime_allocated, actual_size);
|
||||
|
||||
@@ -61,7 +61,7 @@ void rtems_malloc_statistics_at_free(
|
||||
{
|
||||
size_t size;
|
||||
|
||||
if (_Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, pointer, &size) ) {
|
||||
if (_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &size) ) {
|
||||
MSBUMP(lifetime_freed, size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
void malloc_walk(size_t source, size_t printf_enabled)
|
||||
{
|
||||
_Protected_heap_Walk( &RTEMS_Malloc_Heap, source, printf_enabled );
|
||||
_Protected_heap_Walk( RTEMS_Malloc_Heap, source, printf_enabled );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
extern Heap_Control RTEMS_Malloc_Heap;
|
||||
#include "malloc_p.h"
|
||||
|
||||
/*
|
||||
* Find amount of free heap remaining
|
||||
@@ -38,6 +38,6 @@ size_t malloc_free_space( void )
|
||||
{
|
||||
Heap_Information info;
|
||||
|
||||
_Protected_heap_Get_free_information( &RTEMS_Malloc_Heap, &info );
|
||||
_Protected_heap_Get_free_information( RTEMS_Malloc_Heap, &info );
|
||||
return (size_t) info.largest;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <rtems/libcsupport.h>
|
||||
#include <rtems/score/protectedheap.h>
|
||||
|
||||
extern Heap_Control RTEMS_Malloc_Heap;
|
||||
extern Heap_Control *RTEMS_Malloc_Heap;
|
||||
|
||||
/*
|
||||
* Find amount of free heap remaining
|
||||
@@ -34,6 +34,6 @@ int malloc_info(
|
||||
if ( !the_info )
|
||||
return -1;
|
||||
|
||||
_Protected_heap_Get_information( &RTEMS_Malloc_Heap, the_info );
|
||||
_Protected_heap_Get_information( RTEMS_Malloc_Heap, the_info );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ void *realloc(
|
||||
return (void *) 0;
|
||||
}
|
||||
|
||||
if ( !_Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &old_size) ) {
|
||||
if ( !_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, ptr, &old_size) ) {
|
||||
errno = EINVAL;
|
||||
return (void *) 0;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ void *realloc(
|
||||
resize += (*rtems_malloc_boundary_helpers->overhead)();
|
||||
#endif
|
||||
|
||||
if ( _Protected_heap_Resize_block( &RTEMS_Malloc_Heap, ptr, resize ) ) {
|
||||
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.
|
||||
|
||||
@@ -64,7 +64,7 @@ int rtems_memalign(
|
||||
*/
|
||||
|
||||
return_this = _Protected_heap_Allocate_aligned(
|
||||
&RTEMS_Malloc_Heap,
|
||||
RTEMS_Malloc_Heap,
|
||||
size,
|
||||
alignment
|
||||
);
|
||||
|
||||
@@ -374,6 +374,24 @@ rtems_fs_init_functions_t rtems_fs_init_helper =
|
||||
|
||||
#include <rtems/malloc.h>
|
||||
|
||||
#ifdef CONFIGURE_INIT
|
||||
/**
|
||||
* By default, RTEMS uses separate heaps for the RTEMS Workspace and
|
||||
* the C Program Heap. On many BSPs, these can be optionally
|
||||
* combined provided one larger memory pool. This is particularly
|
||||
* useful in combination with the unlimited objects configuration.
|
||||
*/
|
||||
#ifdef CONFIGURE_UNIFIED_WORK_AREAS
|
||||
#include <rtems/score/wkspace.h>
|
||||
Heap_Control *RTEMS_Malloc_Heap = &_Workspace_Area;
|
||||
bool rtems_unified_work_area = true;
|
||||
#else
|
||||
Heap_Control RTEMS_Malloc_Area;
|
||||
Heap_Control *RTEMS_Malloc_Heap = &RTEMS_Malloc_Area;
|
||||
bool rtems_unified_work_area = false;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIGURE_INIT
|
||||
/**
|
||||
* This configures the malloc family statistics to be available.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* COPYRIGHT (c) 1989-2008.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -162,7 +162,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void )
|
||||
* This is currently not defined in any .h file, so we have to
|
||||
* extern it here.
|
||||
*/
|
||||
extern Heap_Control RTEMS_Malloc_Heap;
|
||||
extern Heap_Control *RTEMS_Malloc_Heap;
|
||||
#endif
|
||||
|
||||
RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
|
||||
@@ -192,7 +192,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
|
||||
*/
|
||||
#if defined(RTEMS_HEAVY_MALLOC_DEBUG)
|
||||
if ( _Thread_Dispatch_disable_level == 1 ) {
|
||||
_Heap_Walk( &RTEMS_Malloc_Heap,99, FALSE );
|
||||
_Heap_Walk( RTEMS_Malloc_Heap,99, FALSE );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user