score: Work area initialization API change

The work areas (RTEMS work space and C program heap) will be initialized
now in a separate step and are no longer part of
rtems_initialize_data_structures().  Initialization is performed with
tables of Heap_Area entries.  This allows usage of scattered memory
areas present on various small scale micro-controllers.

The sbrk() support API changes also.  The bsp_sbrk_init() must now deal
with a minimum size for the first memory chunk to take the configured
work space size into account.
This commit is contained in:
Sebastian Huber
2012-08-09 16:48:00 +02:00
parent e4278f2050
commit 47a3cd8f73
51 changed files with 545 additions and 906 deletions

View File

@@ -30,14 +30,20 @@
#include <rtems/confdefs.h>
/* end of configuration */
#ifndef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
void *rtems_heap_null_extend(
Heap_Control *heap,
size_t alloc_size
)
{
return rtems_heap_extend_via_sbrk( heap, alloc_size );
}
#endif
char Malloc_Heap[ 128 ] CPU_STRUCTURE_ALIGNMENT;
int sbrk_count;
Heap_Control Heap_Holder;
Heap_Control TempHeap;
/* Heap variables we need to peek and poke at */
extern size_t RTEMS_Malloc_Sbrk_amount;
size_t offset;
void * sbrk(ptrdiff_t incr)
@@ -66,7 +72,8 @@ rtems_task Init(
rtems_task_argument argument
)
{
Heap_Control *TempHeap;
Heap_Control *real_heap;
Heap_Area area;
sbrk_count = 0;
offset = 0;
@@ -74,21 +81,26 @@ rtems_task Init(
puts( "\n\n*** TEST MALLOC 04 ***" );
/* Safe information on real heap */
TempHeap = malloc_get_heap_pointer();
Heap_Holder = *TempHeap;
rtems_malloc_sbrk_helpers = &rtems_malloc_sbrk_helpers_table;
real_heap = malloc_get_heap_pointer();
malloc_set_heap_pointer( &TempHeap );
rtems_heap_set_sbrk_amount( 64 );
puts( "Initialize heap with some memory" );
offset = 64;
sbrk_count = 0;
RTEMS_Malloc_Initialize( Malloc_Heap, 64, 64 );
area.begin = &Malloc_Heap [0];
area.size = 64;
RTEMS_Malloc_Initialize( &area, 1, NULL );
p1 = malloc(64);
p2 = malloc(64);
p3 = malloc(48);
p4 = malloc(48);
puts( "Initialize heap with some memory - return address out of heap" );
RTEMS_Malloc_Initialize( &Malloc_Heap[1], 64, 64 );
area.begin = &Malloc_Heap [1];
area.size = 64;
RTEMS_Malloc_Initialize( &area, 1, NULL );
offset = 64;
sbrk_count = -1;
p1 = malloc( 127 );
@@ -96,18 +108,21 @@ rtems_task Init(
rtems_test_assert( errno == ENOMEM );
RTEMS_Malloc_Initialize( Malloc_Heap, 64, 64 );
area.begin = &Malloc_Heap [0];
area.size = 64;
RTEMS_Malloc_Initialize( &area, 1, NULL );
puts( "Initialize heap with some unaligned memory" );
offset = 65;
sbrk_count = 0;
RTEMS_Malloc_Initialize( &Malloc_Heap[1], 64, 64 );
area.begin = &Malloc_Heap [1];
area.size = 64;
RTEMS_Malloc_Initialize( &area, 1, NULL );
p1 = malloc(64);
p2 = malloc(64);
p3 = malloc(48);
/* Restore information on real heap */
malloc_set_heap_pointer( TempHeap );
rtems_malloc_sbrk_helpers = NULL;
malloc_set_heap_pointer( real_heap );
puts( "*** END OF TEST MALLOC 04 ***" );

View File

@@ -87,13 +87,18 @@ char *Errors_Core[] = {
"INTERNAL_ERROR_BAD_ATTRIBUTES",
"INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY",
"INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL",
"INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE"
"INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE",
"INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0",
"INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP",
"INTERNAL_ERROR_GXX_KEY_ADD_FAILED",
"INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED",
"INTERNAL_ERROR_NO_MEMORY_FOR_HEAP"
};
void Put_Error( uint32_t source, uint32_t error )
{
if ( source == INTERNAL_ERROR_CORE ) {
if ( error > INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE )
if ( error > INTERNAL_ERROR_NO_MEMORY_FOR_HEAP )
printk("Unknown Internal Core Error (%d)", error);
else
printk( Errors_Core[ error ] );

View File

@@ -17,7 +17,7 @@ SUBDIRS = \
sperror01 sperror02 sperror03 \
spfatal01 spfatal02 spfatal03 spfatal04 spfatal05 spfatal06 spfatal07 \
spfatal08 spfatal09 spfatal10 spfatal11 spfatal12 spfatal13 spfatal14 \
spfatal15 spfatal16 spfatal17 spfatal18 spfatal19 spfatal20 spfatal21 \
spfatal15 spfatal16 spfatal17 spfatal18 spfatal19 spfatal20 \
spfatal22 spfatal23 spfatal24 spfatal25 \
spfifo01 spfifo02 spfifo03 spfifo04 spfifo05 \
spintrcritical01 spintrcritical02 spintrcritical03 spintrcritical04 \

View File

@@ -139,7 +139,6 @@ spfatal17/Makefile
spfatal18/Makefile
spfatal19/Makefile
spfatal20/Makefile
spfatal21/Makefile
spfatal22/Makefile
spfatal23/Makefile
spfatal24/Makefile

View File

@@ -38,6 +38,10 @@ rtems_initialization_tasks_table Initialization_tasks[] = {
void *New_stack_allocate_hook(size_t unused);
#define CONFIGURE_TASK_STACK_ALLOCATOR New_stack_allocate_hook
#define CONFIGURE_TASK_STACK_DEALLOCATOR NULL
void *New_stack_allocate_hook(size_t unused)
{
return NULL;
@@ -45,12 +49,5 @@ void *New_stack_allocate_hook(size_t unused)
void force_error()
{
if (Configuration.stack_free_hook != NULL)
Configuration.stack_allocate_hook = NULL;
else
Configuration.stack_allocate_hook = New_stack_allocate_hook;
rtems_initialize_data_structures();
/* we will not run this far */
}

View File

@@ -37,11 +37,15 @@ rtems_initialization_tasks_table Initialization_tasks[] = {
#define FATAL_ERROR_EXPECTED_ERROR \
INTERNAL_ERROR_INTERRUPT_STACK_TOO_SMALL
#if CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE
#define CONFIGURE_MEMORY_OVERHEAD (sizeof(ISR_Handler_entry) * ISR_NUMBER_OF_VECTORS)
#endif
void force_error()
{
#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
Configuration.interrupt_stack_size = (STACK_MINIMUM_SIZE-1);
rtems_initialize_data_structures();
_ISR_Handler_initialization();
#else
printk(
"WARNING - Test not applicable on this target architecture.\n"

View File

@@ -9,6 +9,8 @@
* http://www.rtems.com/license/LICENSE.
*/
#include <rtems/score/wkspace.h>
/*
* Way too much stack space. Should generate a fatal error
* on the init task create.
@@ -39,10 +41,16 @@ char Workspace[ 256 ] CPU_STRUCTURE_ALIGNMENT;
void force_error()
{
rtems_configuration_set_work_space_start( Workspace );
rtems_configuration_set_work_space_size( sizeof(Workspace) );
Heap_Area area = {
.begin = Workspace,
.size = sizeof( Workspace )
};
rtems_configuration_set_work_space_size( 0 );
rtems_configuration_set_stack_space_size( 0 );
rtems_initialize_data_structures();;
_Workspace_Handler_initialization( &area, 1, NULL );
_Workspace_Allocate_or_fatal_error( 2 * sizeof( Workspace ) );
/* we will not run this far */
}

View File

@@ -14,15 +14,12 @@
#define FATAL_ERROR_TEST_NAME "9"
#define FATAL_ERROR_DESCRIPTION "Bad heap address to malloc"
#define FATAL_ERROR_EXPECTED_SOURCE INTERNAL_ERROR_RTEMS_API
#define FATAL_ERROR_EXPECTED_IS_INTERNAL FALSE
#define FATAL_ERROR_EXPECTED_ERROR RTEMS_NO_MEMORY
char Malloc_Heap[ 1 ] CPU_STRUCTURE_ALIGNMENT;
#define FATAL_ERROR_EXPECTED_SOURCE INTERNAL_ERROR_CORE
#define FATAL_ERROR_EXPECTED_IS_INTERNAL TRUE
#define FATAL_ERROR_EXPECTED_ERROR INTERNAL_ERROR_NO_MEMORY_FOR_HEAP
void force_error()
{
RTEMS_Malloc_Initialize( Malloc_Heap, sizeof(Malloc_Heap), 0 );
RTEMS_Malloc_Initialize( NULL, 0, NULL );
/* we will not run this far */
}

View File

@@ -17,9 +17,8 @@
void force_error()
{
rtems_configuration_set_work_space_size( sizeof(void *) );
rtems_configuration_set_stack_space_size( 0 );
rtems_initialize_data_structures();
Heap_Area area = { .begin = NULL, .size = 0 };
_Workspace_Handler_initialization( &area, 1, NULL );
/* we will not run this far */
}

View File

@@ -1,21 +0,0 @@
rtems_tests_PROGRAMS = spfatal21
spfatal21_SOURCES = ../spfatal_support/init.c \
../spfatal_support/system.h ../../support/src/test_support.c testcase.h
dist_rtems_tests_DATA = spfatal21.scn
dist_rtems_tests_DATA += spfatal21.doc
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
include $(top_srcdir)/../automake/compile.am
include $(top_srcdir)/../automake/leaf.am
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
LINK_OBJS = $(spfatal21_OBJECTS)
LINK_LIBS = $(spfatal21_LDLIBS)
spfatal21$(EXEEXT): $(spfatal21_OBJECTS) $(spfatal21_DEPENDENCIES)
@rm -f spfatal21$(EXEEXT)
$(make-exe)
include $(top_srcdir)/../automake/local.am

View File

@@ -1,19 +0,0 @@
# COPYRIGHT (c) 1989-2010.
# 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.
#
This file describes the directives and concepts tested by this test set.
test set name: spfatal21
directives:
malloc_sbrk_initialize
concepts:
+ exercise fatal error when sbrk fails to extend memory on the initial call.

View File

@@ -1,3 +0,0 @@
*** TEST FATAL FATAL 21 ***
Fatal error (sbrk during init fails) hit
*** END OF TEST FATAL 21 ***

View File

@@ -1,34 +0,0 @@
/*
* COPYRIGHT (c) 1989-2012.
* 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.
*/
#define FATAL_ERROR_TEST_NAME "FATAL 21"
#define FATAL_ERROR_DESCRIPTION "sbrk during init fails"
#define FATAL_ERROR_EXPECTED_SOURCE INTERNAL_ERROR_RTEMS_API
#define FATAL_ERROR_EXPECTED_IS_INTERNAL FALSE
#define FATAL_ERROR_EXPECTED_ERROR RTEMS_NO_MEMORY
#include <rtems/libcsupport.h>
#include <rtems/malloc.h>
#include <unistd.h>
/* Safe information on real heap */
extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers;
extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table;
void * sbrk(ptrdiff_t incr)
{
return (void *) -1;
}
void force_error()
{
rtems_malloc_sbrk_helpers = &rtems_malloc_sbrk_helpers_table;
RTEMS_Malloc_Initialize( NULL, 0, 64 );
}

View File

@@ -88,13 +88,18 @@ char *Errors_Core[] = {
"INTERNAL_ERROR_BAD_ATTRIBUTES",
"INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY",
"INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL",
"INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE"
"INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE",
"INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0",
"INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP",
"INTERNAL_ERROR_GXX_KEY_ADD_FAILED",
"INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED",
"INTERNAL_ERROR_NO_MEMORY_FOR_HEAP"
};
void Put_Error( uint32_t source, uint32_t error )
{
if ( source == INTERNAL_ERROR_CORE ) {
if ( error > INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE )
if ( error > INTERNAL_ERROR_NO_MEMORY_FOR_HEAP )
printk("Unknown Internal Core Error (%d)", error);
else
printk( Errors_Core[ error ] );