source: rtems/cpukit/libcsupport/src/malloc_initialize.c @ bd5984de

4.104.115
Last change on this file since bd5984de was bd5984de, checked in by Joel Sherrill <joel.sherrill@…>, on 09/17/08 at 18:37:55

2008-09-17 Joel Sherrill <joel.sherrill@…>

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