source: rtems/cpukit/libcsupport/src/malloc_initialize.c @ 8a024240

4.104.115
Last change on this file since 8a024240 was 8a024240, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/15/09 at 08:34:45

2009-04-15 Wei-Tsun Sun <wsun013@…>

  • libcsupport/src/malloc_initialize.c: Add dummy RTEMS_Malloc_Initialize.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 *  RTEMS Malloc Family Implementation --Initialization
3 *
4 *
5 *  COPYRIGHT (c) 1989-2007.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems.h>
20#include <rtems/malloc.h>
21#include <rtems/score/wkspace.h>
22#include "malloc_p.h"
23
24/* FIXME: Dummy function */
25#ifndef RTEMS_NEWLIB
26void RTEMS_Malloc_Initialize(
27  void   *start,
28  size_t  length,
29  size_t  sbrk_amount
30)
31{
32}
33#else
34rtems_malloc_statistics_t rtems_malloc_statistics;
35extern bool rtems_unified_work_area;
36
37void RTEMS_Malloc_Initialize(
38  void   *start,
39  size_t  length,
40  size_t  sbrk_amount
41)
42{
43  uint32_t      status;
44  void         *starting_address;
45
46  #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
47    /*
48     *  If configured, initialize the boundary support
49     */
50    if (rtems_malloc_boundary_helpers)
51      (*rtems_malloc_boundary_helpers->initialize)();
52  #endif
53
54  /*
55   *  If configured, initialize the statistics support
56   */
57  if ( rtems_malloc_statistics_helpers )
58    (*rtems_malloc_statistics_helpers->initialize)();
59
60  /*
61   *  Initialize the garbage collection list to start with nothing on it.
62   */
63  malloc_deferred_frees_initialize();
64
65  starting_address = start;
66
67  /*
68   *  Initialize the optional sbrk support for extending the heap
69   */
70  if (rtems_malloc_sbrk_helpers) {
71    starting_address = (*rtems_malloc_sbrk_helpers->initialize)(
72      start,
73      sbrk_amount
74    );
75  }
76
77  /*
78   *  If this system is configured to use the same heap for
79   *  the RTEMS Workspace and C Program Heap, then we need to
80   *  be very very careful about destroying the initialization
81   *  that has already been done.
82   */
83   
84  /*
85   *  If the BSP is not clearing out the workspace, then it is most likely
86   *  not clearing out the initial memory for the heap.  There is no
87   *  standard supporting zeroing out the heap memory.  But much code
88   *  with UNIX history seems to assume that memory malloc'ed during
89   *  initialization (before any free's) is zero'ed.  This is true most
90   *  of the time under UNIX because zero'ing memory when it is first
91   *  given to a process eliminates the chance of a process seeing data
92   *  left over from another process.  This would be a security violation.
93   */
94
95  if ( !rtems_unified_work_area &&
96       rtems_configuration_get_do_zero_of_workspace() )
97     memset( starting_address, 0, length );
98
99  /*
100   *  Unfortunately we cannot use assert if this fails because if this
101   *  has failed we do not have a heap and if we do not have a heap
102   *  STDIO cannot work because there will be no buffers.
103   */
104
105  if ( !rtems_unified_work_area ) {
106    status = _Protected_heap_Initialize(
107      RTEMS_Malloc_Heap,
108      starting_address,
109      length,
110      CPU_HEAP_ALIGNMENT
111    );
112    if ( !status )
113      rtems_fatal_error_occurred( status );
114
115  }
116
117  MSBUMP( space_available, _Protected_heap_Get_size(RTEMS_Malloc_Heap) );
118
119  #if defined(RTEMS_HEAP_DEBUG)
120    if ( _Protected_heap_Walk( RTEMS_Malloc_Heap, 0, false ) ) {
121      printk( "Malloc heap not initialized correctly\n" );
122      rtems_print_buffer( start, 32 );
123      printk( "\n" );
124      rtems_print_buffer( (start + length) - 48, 48 );
125      rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
126    }
127  #endif
128}
129#endif
Note: See TracBrowser for help on using the repository browser.