Changeset f2185d10 in rtems


Ignore:
Timestamp:
Sep 30, 2020, 9:31:58 AM (4 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
6a31ae63
Parents:
71689a07
git-author:
Sebastian Huber <sebastian.huber@…> (09/30/20 09:31:58)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/01/20 17:05:33)
Message:

Decouple the C Program Heap initialization

Before this patch RTEMS_Malloc_Initialize() had a fixed dependency on
_Workspace_Area. Introduce _Workspace_Malloc_initializer to have this
dependency only if CONFIGURE_UNIFIED_WORK_AREAS is defined by the
application configuration.

Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • cpukit/Makefile.am

    r71689a07 rf2185d10  
    177177librtemscpu_a_SOURCES += libcsupport/src/mallocfreespace.c
    178178librtemscpu_a_SOURCES += libcsupport/src/mallocgetheapptr.c
     179librtemscpu_a_SOURCES += libcsupport/src/mallocheap.c
    179180librtemscpu_a_SOURCES += libcsupport/src/mallocinfo.c
    180181librtemscpu_a_SOURCES += libcsupport/src/malloc_initialize.c
     
    10261027librtemscpu_a_SOURCES += score/src/wkspace.c
    10271028librtemscpu_a_SOURCES += score/src/wkspaceisunifieddefault.c
     1029librtemscpu_a_SOURCES += score/src/wkspacemallocinitdefault.c
     1030librtemscpu_a_SOURCES += score/src/wkspacemallocinitunified.c
    10281031librtemscpu_a_SOURCES += score/src/wkstringduplicate.c
    10291032librtemscpu_a_SOURCES += score/src/iobase64.c
  • cpukit/include/rtems/confdefs/wkspace.h

    r71689a07 rf2185d10  
    127127#ifdef CONFIGURE_UNIFIED_WORK_AREAS
    128128  const bool _Workspace_Is_unified = true;
     129
     130  struct Heap_Control *( * const _Workspace_Malloc_initializer )( void ) =
     131    _Workspace_Malloc_initialize_unified;
    129132#endif
    130133
  • cpukit/include/rtems/malloc.h

    r71689a07 rf2185d10  
    4444extern Heap_Control *RTEMS_Malloc_Heap;
    4545
    46 void RTEMS_Malloc_Initialize(
     46Heap_Control *RTEMS_Malloc_Initialize(
    4747  const Memory_Information              *mem,
    4848  Heap_Initialization_or_extend_handler  extend
  • cpukit/include/rtems/score/wkspacedata.h

    r71689a07 rf2185d10  
    4444#endif
    4545
     46struct Heap_Control;
     47
    4648/**
    4749 * @addtogroup RTEMSScoreWorkspace
     
    6668extern const bool _Workspace_Is_unified;
    6769
     70/**
     71 * @brief Initializes the C Program Heap separated from the RTEMS Workspace.
     72 *
     73 * @return Returns the heap control used for the C Program Heap.
     74 */
     75struct Heap_Control *_Workspace_Malloc_initialize_separate( void );
     76
     77/**
     78 * @brief Initializes the C Program Heap so that it is unified with the RTEMS
     79 * Workspace.
     80 *
     81 * @return Returns the heap control used for the C Program Heap.
     82 */
     83struct Heap_Control *_Workspace_Malloc_initialize_unified( void );
     84
     85/**
     86 * @brief This constant provides the C Program Heap initialization handler.
     87 *
     88 * This constant is defined by the application configuration option
     89 * #CONFIGURE_UNIFIED_WORK_AREAS via <rtems/confdefs.h> or a default
     90 * configuration.
     91 */
     92extern struct Heap_Control *( * const _Workspace_Malloc_initializer )( void );
     93
    6894/** @} */
    6995
  • cpukit/libcsupport/src/malloc_initialize.c

    r71689a07 rf2185d10  
    2020#include <rtems/malloc.h>
    2121#include <rtems/score/wkspace.h>
    22 #include <rtems/sysinit.h>
    2322
    2423#include "malloc_p.h"
    25 
    26 Heap_Control *RTEMS_Malloc_Heap;
    27 
    28 static void _Malloc_Initialize( void )
    29 {
    30   RTEMS_Malloc_Initialize( _Memory_Get(), _Heap_Extend );
    31 }
    32 
    33 RTEMS_SYSINIT_ITEM(
    34   _Malloc_Initialize,
    35   RTEMS_SYSINIT_MALLOC,
    36   RTEMS_SYSINIT_ORDER_MIDDLE
    37 );
    3824
    3925#ifdef RTEMS_NEWLIB
    4026static Heap_Control _Malloc_Heap;
    4127
    42 void RTEMS_Malloc_Initialize(
     28Heap_Control *RTEMS_Malloc_Initialize(
    4329  const Memory_Information              *mem,
    4430  Heap_Initialization_or_extend_handler  extend
    4531)
    4632{
    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;
     33  Heap_Control                          *heap;
     34  Heap_Initialization_or_extend_handler  init_or_extend;
     35  uintptr_t                              page_size;
     36  size_t                                 i;
    5437
    55     heap = &_Malloc_Heap;
    56     RTEMS_Malloc_Heap = heap;
    57     init_or_extend = _Heap_Initialize;
    58     page_size = CPU_HEAP_ALIGNMENT;
     38  heap = &_Malloc_Heap;
     39  RTEMS_Malloc_Heap = heap;
     40  init_or_extend = _Heap_Initialize;
     41  page_size = CPU_HEAP_ALIGNMENT;
    5942
    60     for (i = 0; i < _Memory_Get_count( mem ); ++i) {
    61       Memory_Area *area;
    62       uintptr_t    space_available;
     43  for (i = 0; i < _Memory_Get_count( mem ); ++i) {
     44    Memory_Area *area;
     45    uintptr_t    space_available;
    6346
    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       );
     47    area = _Memory_Get_area( mem, i );
     48    space_available = ( *init_or_extend )(
     49      heap,
     50      _Memory_Get_free_begin( area ),
     51      _Memory_Get_free_size( area ),
     52      page_size
     53    );
    7154
    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 );
     55    if ( space_available > 0 ) {
     56      _Memory_Consume( area, _Memory_Get_free_size( area ) );
     57      init_or_extend = extend;
    8058    }
    8159  }
     60
     61  if ( init_or_extend == _Heap_Initialize ) {
     62    _Internal_error( INTERNAL_ERROR_NO_MEMORY_FOR_HEAP );
     63  }
     64
     65  return heap;
    8266}
    8367#else
    84 void RTEMS_Malloc_Initialize(
     68Heap_Control *RTEMS_Malloc_Initialize(
    8569  const Memory_Information              *mem,
    8670  Heap_Initialization_or_extend_handler  extend
     
    8872{
    8973  /* FIXME: Dummy function */
     74  return NULL;
    9075}
    9176#endif
     77
     78Heap_Control *_Workspace_Malloc_initialize_separate( void )
     79{
     80  return RTEMS_Malloc_Initialize( _Memory_Get(), _Heap_Extend );
     81}
  • spec/build/cpukit/librtemscpu.yml

    r71689a07 rf2185d10  
    670670- cpukit/libcsupport/src/mallocfreespace.c
    671671- cpukit/libcsupport/src/mallocgetheapptr.c
     672- cpukit/libcsupport/src/mallocheap.c
    672673- cpukit/libcsupport/src/mallocinfo.c
    673674- cpukit/libcsupport/src/malloc_initialize.c
     
    15761577- cpukit/score/src/wkspace.c
    15771578- cpukit/score/src/wkspaceisunifieddefault.c
     1579- cpukit/score/src/wkspacemallocinitdefault.c
     1580- cpukit/score/src/wkspacemallocinitunified.c
    15781581- cpukit/score/src/wkstringduplicate.c
    15791582target: rtemscpu
Note: See TracChangeset for help on using the changeset viewer.