diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-09-17 18:37:55 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-09-17 18:37:55 +0000 |
commit | bd5984deb79025a5ade18826ecdeb7eb05c3ccb4 (patch) | |
tree | 36e4cefb28300a8a42e85a55c4687c63693616c6 /cpukit | |
parent | 2008-09-17 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-bd5984deb79025a5ade18826ecdeb7eb05c3ccb4.tar.bz2 |
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.
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/ChangeLog | 13 | ||||
-rw-r--r-- | cpukit/libcsupport/src/free.c | 8 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc.c | 4 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc_initialize.c | 33 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc_p.h | 2 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc_sbrk_helpers.c | 4 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc_statistics_helpers.c | 4 | ||||
-rw-r--r-- | cpukit/libcsupport/src/malloc_walk.c | 2 | ||||
-rw-r--r-- | cpukit/libcsupport/src/mallocfreespace.c | 4 | ||||
-rw-r--r-- | cpukit/libcsupport/src/mallocinfo.c | 4 | ||||
-rw-r--r-- | cpukit/libcsupport/src/realloc.c | 4 | ||||
-rw-r--r-- | cpukit/libcsupport/src/rtems_memalign.c | 2 | ||||
-rw-r--r-- | cpukit/sapi/include/confdefs.h | 18 | ||||
-rw-r--r-- | cpukit/score/inline/rtems/score/thread.inl | 6 |
14 files changed, 75 insertions, 33 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 49437b8323..fff546a519 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -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, diff --git a/cpukit/libcsupport/src/free.c b/cpukit/libcsupport/src/free.c index e7d92dd1aa..8929bd0d80 100644 --- a/cpukit/libcsupport/src/free.c +++ b/cpukit/libcsupport/src/free.c @@ -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 ); } diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c index fad15520bc..8338e06fb3 100644 --- a/cpukit/libcsupport/src/malloc.c +++ b/cpukit/libcsupport/src/malloc.c @@ -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) diff --git a/cpukit/libcsupport/src/malloc_initialize.c b/cpukit/libcsupport/src/malloc_initialize.c index 6c466b6955..1105724a67 100644 --- a/cpukit/libcsupport/src/malloc_initialize.c +++ b/cpukit/libcsupport/src/malloc_initialize.c @@ -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" ); diff --git a/cpukit/libcsupport/src/malloc_p.h b/cpukit/libcsupport/src/malloc_p.h index 961acc4e80..853275d6d3 100644 --- a/cpukit/libcsupport/src/malloc_p.h +++ b/cpukit/libcsupport/src/malloc_p.h @@ -37,7 +37,7 @@ /* * Basic management data */ -extern Heap_Control RTEMS_Malloc_Heap; +extern Heap_Control *RTEMS_Malloc_Heap; /* * Malloc Statistics Structure diff --git a/cpukit/libcsupport/src/malloc_sbrk_helpers.c b/cpukit/libcsupport/src/malloc_sbrk_helpers.c index bbc6faf519..f630b2b137 100644 --- a/cpukit/libcsupport/src/malloc_sbrk_helpers.c +++ b/cpukit/libcsupport/src/malloc_sbrk_helpers.c @@ -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; } diff --git a/cpukit/libcsupport/src/malloc_statistics_helpers.c b/cpukit/libcsupport/src/malloc_statistics_helpers.c index a574bfb762..5d02f8b822 100644 --- a/cpukit/libcsupport/src/malloc_statistics_helpers.c +++ b/cpukit/libcsupport/src/malloc_statistics_helpers.c @@ -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); } } diff --git a/cpukit/libcsupport/src/malloc_walk.c b/cpukit/libcsupport/src/malloc_walk.c index a0d7d3213c..9f78a26716 100644 --- a/cpukit/libcsupport/src/malloc_walk.c +++ b/cpukit/libcsupport/src/malloc_walk.c @@ -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 diff --git a/cpukit/libcsupport/src/mallocfreespace.c b/cpukit/libcsupport/src/mallocfreespace.c index aaf1016194..9b0898c31a 100644 --- a/cpukit/libcsupport/src/mallocfreespace.c +++ b/cpukit/libcsupport/src/mallocfreespace.c @@ -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; } diff --git a/cpukit/libcsupport/src/mallocinfo.c b/cpukit/libcsupport/src/mallocinfo.c index d5ecd03db3..d1c3266aeb 100644 --- a/cpukit/libcsupport/src/mallocinfo.c +++ b/cpukit/libcsupport/src/mallocinfo.c @@ -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; } diff --git a/cpukit/libcsupport/src/realloc.c b/cpukit/libcsupport/src/realloc.c index 745568c49d..9e96948994 100644 --- a/cpukit/libcsupport/src/realloc.c +++ b/cpukit/libcsupport/src/realloc.c @@ -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. diff --git a/cpukit/libcsupport/src/rtems_memalign.c b/cpukit/libcsupport/src/rtems_memalign.c index 679d8c7af7..563f23cd4c 100644 --- a/cpukit/libcsupport/src/rtems_memalign.c +++ b/cpukit/libcsupport/src/rtems_memalign.c @@ -64,7 +64,7 @@ int rtems_memalign( */ return_this = _Protected_heap_Allocate_aligned( - &RTEMS_Malloc_Heap, + RTEMS_Malloc_Heap, size, alignment ); diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h index aeb149fc6a..1facb44dd7 100644 --- a/cpukit/sapi/include/confdefs.h +++ b/cpukit/sapi/include/confdefs.h @@ -376,6 +376,24 @@ rtems_fs_init_functions_t rtems_fs_init_helper = #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. * By default only function call counts are kept. */ diff --git a/cpukit/score/inline/rtems/score/thread.inl b/cpukit/score/inline/rtems/score/thread.inl index d70d5330b3..6dd409d0a6 100644 --- a/cpukit/score/inline/rtems/score/thread.inl +++ b/cpukit/score/inline/rtems/score/thread.inl @@ -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 } |