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 | |
---|
22 | #include "malloc_p.h" |
---|
23 | |
---|
24 | #ifdef RTEMS_NEWLIB |
---|
25 | rtems_malloc_statistics_t rtems_malloc_statistics; |
---|
26 | |
---|
27 | void RTEMS_Malloc_Initialize( |
---|
28 | const Heap_Area *areas, |
---|
29 | size_t area_count, |
---|
30 | Heap_Initialization_or_extend_handler extend |
---|
31 | ) |
---|
32 | { |
---|
33 | Heap_Control *heap = RTEMS_Malloc_Heap; |
---|
34 | |
---|
35 | if ( !rtems_configuration_get_unified_work_area() ) { |
---|
36 | Heap_Initialization_or_extend_handler init_or_extend = _Heap_Initialize; |
---|
37 | uintptr_t page_size = CPU_HEAP_ALIGNMENT; |
---|
38 | size_t i; |
---|
39 | |
---|
40 | for (i = 0; i < area_count; ++i) { |
---|
41 | const Heap_Area *area = &areas [i]; |
---|
42 | uintptr_t space_available = (*init_or_extend)( |
---|
43 | heap, |
---|
44 | area->begin, |
---|
45 | area->size, |
---|
46 | page_size |
---|
47 | ); |
---|
48 | |
---|
49 | if ( space_available > 0 ) { |
---|
50 | init_or_extend = extend; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | if ( init_or_extend == _Heap_Initialize ) { |
---|
55 | _Terminate( |
---|
56 | INTERNAL_ERROR_CORE, |
---|
57 | true, |
---|
58 | INTERNAL_ERROR_NO_MEMORY_FOR_HEAP |
---|
59 | ); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | /* |
---|
64 | * If configured, initialize the statistics support |
---|
65 | */ |
---|
66 | if ( rtems_malloc_statistics_helpers != NULL ) { |
---|
67 | (*rtems_malloc_statistics_helpers->initialize)(); |
---|
68 | } |
---|
69 | |
---|
70 | MSBUMP( space_available, _Protected_heap_Get_size( heap ) ); |
---|
71 | } |
---|
72 | #else |
---|
73 | void RTEMS_Malloc_Initialize( |
---|
74 | Heap_Area *areas, |
---|
75 | size_t area_count, |
---|
76 | Heap_Initialization_or_extend_handler extend |
---|
77 | ) |
---|
78 | { |
---|
79 | /* FIXME: Dummy function */ |
---|
80 | } |
---|
81 | #endif |
---|