source: rtems/cpukit/libcsupport/src/malloc_initialize.c @ 98b785e

4.115
Last change on this file since 98b785e was 7c658fe, checked in by Joel Sherrill <joel.sherrill@…>, on 06/30/10 at 15:36:48

2010-06-30 Joel Sherrill <joel.sherrilL@…>

PR 1472/cpukit

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