mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-25 21:15:53 +08:00
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:
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Malloc initialization implementation.
|
||||
* @brief RTEMS_Malloc_Initialize() implementation.
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* COPYRIGHT (c) 1989-2012.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -14,33 +14,52 @@
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/malloc.h>
|
||||
#include <rtems/score/wkspace.h>
|
||||
|
||||
#include "malloc_p.h"
|
||||
|
||||
/* FIXME: Dummy function */
|
||||
#ifndef RTEMS_NEWLIB
|
||||
void RTEMS_Malloc_Initialize(
|
||||
void *heap_begin,
|
||||
uintptr_t heap_size,
|
||||
size_t sbrk_amount
|
||||
)
|
||||
{
|
||||
}
|
||||
#else
|
||||
#ifdef RTEMS_NEWLIB
|
||||
rtems_malloc_statistics_t rtems_malloc_statistics;
|
||||
|
||||
void RTEMS_Malloc_Initialize(
|
||||
void *heap_begin,
|
||||
uintptr_t heap_size,
|
||||
size_t sbrk_amount
|
||||
const Heap_Area *areas,
|
||||
size_t area_count,
|
||||
Heap_Initialization_or_extend_handler extend
|
||||
)
|
||||
{
|
||||
bool separate_areas = !rtems_configuration_get_unified_work_area();
|
||||
Heap_Control *heap = RTEMS_Malloc_Heap;
|
||||
|
||||
if ( !rtems_configuration_get_unified_work_area() ) {
|
||||
Heap_Initialization_or_extend_handler init_or_extend = _Heap_Initialize;
|
||||
uintptr_t page_size = CPU_HEAP_ALIGNMENT;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < area_count; ++i) {
|
||||
const Heap_Area *area = &areas [i];
|
||||
uintptr_t space_available = (*init_or_extend)(
|
||||
heap,
|
||||
area->begin,
|
||||
area->size,
|
||||
page_size
|
||||
);
|
||||
|
||||
if ( space_available > 0 ) {
|
||||
init_or_extend = extend;
|
||||
}
|
||||
}
|
||||
|
||||
if ( init_or_extend == _Heap_Initialize ) {
|
||||
_Internal_error_Occurred(
|
||||
INTERNAL_ERROR_CORE,
|
||||
true,
|
||||
INTERNAL_ERROR_NO_MEMORY_FOR_HEAP
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If configured, initialize the statistics support
|
||||
*/
|
||||
@@ -48,59 +67,15 @@ void RTEMS_Malloc_Initialize(
|
||||
(*rtems_malloc_statistics_helpers->initialize)();
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the optional sbrk support for extending the heap
|
||||
*/
|
||||
if ( rtems_malloc_sbrk_helpers != NULL ) {
|
||||
void *new_heap_begin = (*rtems_malloc_sbrk_helpers->initialize)(
|
||||
heap_begin,
|
||||
sbrk_amount
|
||||
);
|
||||
|
||||
heap_size -= (uintptr_t) new_heap_begin - (uintptr_t) heap_begin;
|
||||
heap_begin = new_heap_begin;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
* not clearing out the initial memory for the heap. There is no
|
||||
* standard supporting zeroing out the heap memory. But much code
|
||||
* with UNIX history seems to assume that memory malloc'ed during
|
||||
* initialization (before any free's) is zero'ed. This is true most
|
||||
* of the time under UNIX because zero'ing memory when it is first
|
||||
* given to a process eliminates the chance of a process seeing data
|
||||
* left over from another process. This would be a security violation.
|
||||
*/
|
||||
|
||||
if ( separate_areas && rtems_configuration_get_do_zero_of_workspace() ) {
|
||||
memset( heap_begin, 0, heap_size );
|
||||
}
|
||||
|
||||
/*
|
||||
* Unfortunately we cannot use assert if this fails because if this
|
||||
* has failed we do not have a heap and if we do not have a heap
|
||||
* STDIO cannot work because there will be no buffers.
|
||||
*/
|
||||
|
||||
if ( separate_areas ) {
|
||||
uintptr_t status = _Protected_heap_Initialize(
|
||||
RTEMS_Malloc_Heap,
|
||||
heap_begin,
|
||||
heap_size,
|
||||
CPU_HEAP_ALIGNMENT
|
||||
);
|
||||
if ( status == 0 ) {
|
||||
rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
|
||||
}
|
||||
}
|
||||
|
||||
MSBUMP( space_available, _Protected_heap_Get_size(RTEMS_Malloc_Heap) );
|
||||
MSBUMP( space_available, _Protected_heap_Get_size( heap ) );
|
||||
}
|
||||
#else
|
||||
void RTEMS_Malloc_Initialize(
|
||||
Heap_Area *areas,
|
||||
size_t area_count,
|
||||
Heap_Initialization_or_extend_handler extend
|
||||
)
|
||||
{
|
||||
/* FIXME: Dummy function */
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user