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 | #ifdef 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 | |
---|
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 | ); |
---|
38 | |
---|
39 | #ifdef RTEMS_NEWLIB |
---|
40 | static Heap_Control _Malloc_Heap; |
---|
41 | |
---|
42 | void 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 |
---|
84 | void RTEMS_Malloc_Initialize( |
---|
85 | const Memory_Information *mem, |
---|
86 | Heap_Initialization_or_extend_handler extend |
---|
87 | ) |
---|
88 | { |
---|
89 | /* FIXME: Dummy function */ |
---|
90 | } |
---|
91 | #endif |
---|