source: rtems/cpukit/libcsupport/src/malloc_initialize.c @ 3b978e19

4.11
Last change on this file since 3b978e19 was 3b978e19, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 9, 2012 at 8:36:25 AM

libcsupport: malloc_deferred_frees_initialize()

Remove this function and statically initialize RTEMS_Malloc_GC_list.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief Malloc initialization implementation.
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2007.
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.com/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems.h>
21#include <rtems/malloc.h>
22#include <rtems/score/wkspace.h>
23#include "malloc_p.h"
24
25/* FIXME: Dummy function */
26#ifndef RTEMS_NEWLIB
27void RTEMS_Malloc_Initialize(
28  void *heap_begin,
29  uintptr_t heap_size,
30  size_t sbrk_amount
31)
32{
33}
34#else
35rtems_malloc_statistics_t rtems_malloc_statistics;
36
37void RTEMS_Malloc_Initialize(
38  void *heap_begin,
39  uintptr_t heap_size,
40  size_t sbrk_amount
41)
42{
43  bool separate_areas = !rtems_configuration_get_unified_work_area();
44  /*
45   *  If configured, initialize the statistics support
46   */
47  if ( rtems_malloc_statistics_helpers != NULL ) {
48    (*rtems_malloc_statistics_helpers->initialize)();
49  }
50
51  /*
52   *  Initialize the optional sbrk support for extending the heap
53   */
54  if ( rtems_malloc_sbrk_helpers != NULL ) {
55    void *new_heap_begin = (*rtems_malloc_sbrk_helpers->initialize)(
56      heap_begin,
57      sbrk_amount
58    );
59
60    heap_size -= (uintptr_t) new_heap_begin - (uintptr_t) heap_begin;
61    heap_begin = new_heap_begin;
62  }
63
64  /*
65   *  If this system is configured to use the same heap for
66   *  the RTEMS Workspace and C Program Heap, then we need to
67   *  be very very careful about destroying the initialization
68   *  that has already been done.
69   */
70
71  /*
72   *  If the BSP is not clearing out the workspace, then it is most likely
73   *  not clearing out the initial memory for the heap.  There is no
74   *  standard supporting zeroing out the heap memory.  But much code
75   *  with UNIX history seems to assume that memory malloc'ed during
76   *  initialization (before any free's) is zero'ed.  This is true most
77   *  of the time under UNIX because zero'ing memory when it is first
78   *  given to a process eliminates the chance of a process seeing data
79   *  left over from another process.  This would be a security violation.
80   */
81
82  if ( separate_areas && rtems_configuration_get_do_zero_of_workspace() ) {
83     memset( heap_begin, 0, heap_size );
84  }
85
86  /*
87   *  Unfortunately we cannot use assert if this fails because if this
88   *  has failed we do not have a heap and if we do not have a heap
89   *  STDIO cannot work because there will be no buffers.
90   */
91
92  if ( separate_areas ) {
93    uintptr_t status = _Protected_heap_Initialize(
94      RTEMS_Malloc_Heap,
95      heap_begin,
96      heap_size,
97      CPU_HEAP_ALIGNMENT
98    );
99    if ( status == 0 ) {
100      rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
101    }
102  }
103
104  MSBUMP( space_available, _Protected_heap_Get_size(RTEMS_Malloc_Heap) );
105}
106#endif
Note: See TracBrowser for help on using the repository browser.