source: rtems/cpukit/libcsupport/src/malloc_initialize.c @ 4088d01d

4.104.114.9
Last change on this file since 4088d01d was 4088d01d, checked in by Ralf Corsepius <ralf.corsepius@…>, on Sep 1, 2008 at 11:42:19 AM

Convert using "bool".

  • Property mode set to 100644
File size: 2.8 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 "malloc_p.h"
22
23Heap_Control              RTEMS_Malloc_Heap;
24rtems_malloc_statistics_t rtems_malloc_statistics;
25
26void RTEMS_Malloc_Initialize(
27  void   *start,
28  size_t  length,
29  size_t  sbrk_amount
30)
31{
32  uint32_t      status;
33  void         *starting_address;
34
35  #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
36    /*
37     *  If configured, initialize the boundary support
38     */
39    if (rtems_malloc_boundary_helpers)
40      (*rtems_malloc_boundary_helpers->initialize)();
41  #endif
42
43  /*
44   *  If configured, initialize the statistics support
45   */
46  if ( rtems_malloc_statistics_helpers )
47    (*rtems_malloc_statistics_helpers->initialize)();
48
49  /*
50   *  Initialize the garbage collection list to start with nothing on it.
51   */
52  malloc_deferred_frees_initialize();
53
54  starting_address = start;
55
56  /*
57   *  Initialize the optional sbrk support for extending the heap
58   */
59  if (rtems_malloc_sbrk_helpers) {
60    starting_address = (*rtems_malloc_sbrk_helpers->initialize)(
61      start,
62      sbrk_amount
63    );
64  }
65   
66  /*
67   *  If the BSP is not clearing out the workspace, then it is most likely
68   *  not clearing out the initial memory for the heap.  There is no
69   *  standard supporting zeroing out the heap memory.  But much code
70   *  with UNIX history seems to assume that memory malloc'ed during
71   *  initialization (before any free's) is zero'ed.  This is true most
72   *  of the time under UNIX because zero'ing memory when it is first
73   *  given to a process eliminates the chance of a process seeing data
74   *  left over from another process.  This would be a security violation.
75   */
76
77  if ( rtems_configuration_get_do_zero_of_workspace() )
78     memset( starting_address, 0, length );
79
80  /*
81   *  Unfortunately we cannot use assert if this fails because if this
82   *  has failed we do not have a heap and if we do not have a heap
83   *  STDIO cannot work because there will be no buffers.
84   */
85
86  status = _Protected_heap_Initialize( 
87    &RTEMS_Malloc_Heap,
88    starting_address,
89    length,
90    CPU_HEAP_ALIGNMENT
91  );
92  if ( !status )
93    rtems_fatal_error_occurred( status );
94
95  #if defined(RTEMS_HEAP_DEBUG)
96    if ( _Protected_heap_Walk( &RTEMS_Malloc_Heap, 0, false ) ) {
97      printk( "Malloc heap not initialized correctly\n" );
98      rtems_print_buffer( start, 32 );
99      printk( "\n" );
100      rtems_print_buffer( (start + length) - 48, 48 );
101      rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
102    }
103  #endif
104
105  MSBUMP(space_available, length);
106}
Note: See TracBrowser for help on using the repository browser.