source: rtems/cpukit/libcsupport/src/malloc_initialize.c @ 64d6f19

4.115
Last change on this file since 64d6f19 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 2.9 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 garbage collection list to start with nothing on it.
53   */
54  malloc_deferred_frees_initialize();
55
56  /*
57   *  Initialize the optional sbrk support for extending the heap
58   */
59  if ( rtems_malloc_sbrk_helpers != NULL ) {
60    void *new_heap_begin = (*rtems_malloc_sbrk_helpers->initialize)(
61      heap_begin,
62      sbrk_amount
63    );
64
65    heap_size -= (uintptr_t) new_heap_begin - (uintptr_t) heap_begin;
66    heap_begin = new_heap_begin;
67  }
68
69  /*
70   *  If this system is configured to use the same heap for
71   *  the RTEMS Workspace and C Program Heap, then we need to
72   *  be very very careful about destroying the initialization
73   *  that has already been done.
74   */
75
76  /*
77   *  If the BSP is not clearing out the workspace, then it is most likely
78   *  not clearing out the initial memory for the heap.  There is no
79   *  standard supporting zeroing out the heap memory.  But much code
80   *  with UNIX history seems to assume that memory malloc'ed during
81   *  initialization (before any free's) is zero'ed.  This is true most
82   *  of the time under UNIX because zero'ing memory when it is first
83   *  given to a process eliminates the chance of a process seeing data
84   *  left over from another process.  This would be a security violation.
85   */
86
87  if ( separate_areas && rtems_configuration_get_do_zero_of_workspace() ) {
88     memset( heap_begin, 0, heap_size );
89  }
90
91  /*
92   *  Unfortunately we cannot use assert if this fails because if this
93   *  has failed we do not have a heap and if we do not have a heap
94   *  STDIO cannot work because there will be no buffers.
95   */
96
97  if ( separate_areas ) {
98    uintptr_t status = _Protected_heap_Initialize(
99      RTEMS_Malloc_Heap,
100      heap_begin,
101      heap_size,
102      CPU_HEAP_ALIGNMENT
103    );
104    if ( status == 0 ) {
105      rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
106    }
107  }
108
109  MSBUMP( space_available, _Protected_heap_Get_size(RTEMS_Malloc_Heap) );
110}
111#endif
Note: See TracBrowser for help on using the repository browser.