source: rtems/cpukit/libcsupport/src/malloc_initialize.c @ eea21eac

5
Last change on this file since eea21eac was eea21eac, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 13, 2019 at 5:18:36 AM

bsps: Rework work area initialization

The work area initialization was done by the BSP through
bsp_work_area_initialize(). This approach predated the system
initialization through the system initialization linker set. The
workspace and C program heap were unconditionally initialized. The aim
is to support RTEMS application configurations which do not need the
workspace and C program heap. In these configurations, the workspace
and C prgram heap should not get initialized.

Change all bsp_work_area_initialize() to implement _Memory_Get()
instead. Move the dirty memory, sbrk(), per-CPU data, workspace, and
malloc() heap initialization into separate system initialization steps.
This makes it also easier to test the individual initialization steps.

This change adds a dependency to _Heap_Extend() to all BSPs. This
dependency will be removed in a follow up change.

Update #3838.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS_Malloc_Initialize() implementation.
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2012.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17  #include "config.h"
18#endif
19
20#include <rtems/malloc.h>
21#include <rtems/score/wkspace.h>
22#include <rtems/sysinit.h>
23
24#include "malloc_p.h"
25
26Heap_Control *RTEMS_Malloc_Heap;
27
28static void _Malloc_Initialize( void )
29{
30  RTEMS_Malloc_Initialize( _Memory_Get(), _Heap_Extend );
31}
32
33RTEMS_SYSINIT_ITEM(
34  _Malloc_Initialize,
35  RTEMS_SYSINIT_MALLOC,
36  RTEMS_SYSINIT_ORDER_MIDDLE
37);
38
39#ifdef RTEMS_NEWLIB
40static Heap_Control _Malloc_Heap;
41
42void RTEMS_Malloc_Initialize(
43  const Memory_Information              *mem,
44  Heap_Initialization_or_extend_handler  extend
45)
46{
47  if ( rtems_configuration_get_unified_work_area() ) {
48    RTEMS_Malloc_Heap = &_Workspace_Area;
49  } else {
50    Heap_Control                          *heap;
51    Heap_Initialization_or_extend_handler  init_or_extend;
52    uintptr_t                              page_size;
53    size_t                                 i;
54
55    heap = &_Malloc_Heap;
56    RTEMS_Malloc_Heap = heap;
57    init_or_extend = _Heap_Initialize;
58    page_size = CPU_HEAP_ALIGNMENT;
59
60    for (i = 0; i < _Memory_Get_count( mem ); ++i) {
61      Memory_Area *area;
62      uintptr_t    space_available;
63
64      area = _Memory_Get_area( mem, i );
65      space_available = ( *init_or_extend )(
66        heap,
67        _Memory_Get_free_begin( area ),
68        _Memory_Get_free_size( area ),
69        page_size
70      );
71
72      if ( space_available > 0 ) {
73        _Memory_Consume( area, _Memory_Get_free_size( area ) );
74        init_or_extend = extend;
75      }
76    }
77
78    if ( init_or_extend == _Heap_Initialize ) {
79      _Internal_error( INTERNAL_ERROR_NO_MEMORY_FOR_HEAP );
80    }
81  }
82}
83#else
84void RTEMS_Malloc_Initialize(
85  const Memory_Information              *mem,
86  Heap_Initialization_or_extend_handler  extend
87)
88{
89  /* FIXME: Dummy function */
90}
91#endif
Note: See TracBrowser for help on using the repository browser.