source: rtems/cpukit/score/src/heapextend.c @ 05279b84

4.104.114.84.95
Last change on this file since 05279b84 was 05279b84, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/17/04 at 13:32:13

Remove stray white spaces.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  Heap Handler
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14
15#include <rtems/system.h>
16#include <rtems/score/sysstate.h>
17#include <rtems/score/heap.h>
18
19/*PAGE
20 *
21 *  _Heap_Extend
22 *
23 *  This routine grows the_heap memory area using the size bytes which
24 *  begin at starting_address.
25 *
26 *  Input parameters:
27 *    the_heap          - pointer to heap header.
28 *    starting_address  - pointer to the memory area.
29 *    size              - size in bytes of the memory block to allocate.
30 *
31 *  Output parameters:
32 *    *amount_extended  - amount of memory added to the_heap
33 */
34
35Heap_Extend_status _Heap_Extend(
36  Heap_Control        *the_heap,
37  void                *starting_address,
38  uint32_t             size,
39  uint32_t            *amount_extended
40)
41{
42  Heap_Block        *the_block;
43  uint32_t          *p;
44
45  /*
46   *  The overhead was taken from the original heap memory.
47   */
48
49  Heap_Block  *old_final;
50  Heap_Block  *new_final;
51
52  /*
53   *  There are five possibilities for the location of starting
54   *  address:
55   *
56   *    1. non-contiguous lower address     (NOT SUPPORTED)
57   *    2. contiguous lower address         (NOT SUPPORTED)
58   *    3. in the heap                      (ERROR)
59   *    4. contiguous higher address        (SUPPORTED)
60   *    5. non-contiguous higher address    (NOT SUPPORTED)
61   *
62   *  As noted, this code only supports (4).
63   */
64
65  if ( starting_address >= (void *) the_heap->start &&        /* case 3 */
66       starting_address <= (void *) the_heap->final
67     )
68    return HEAP_EXTEND_ERROR;
69
70  if ( starting_address < (void *) the_heap->start ) {  /* cases 1 and 2 */
71
72      return HEAP_EXTEND_NOT_IMPLEMENTED;               /* cases 1 and 2 */
73
74  } else {                                              /* cases 4 and 5 */
75
76    the_block = (Heap_Block *)
77       _Addresses_Subtract_offset( starting_address, HEAP_OVERHEAD );
78    if ( the_block != the_heap->final )
79      return HEAP_EXTEND_NOT_IMPLEMENTED;                   /* case 5 */
80  }
81
82  /*
83   *  Currently only case 4 should make it to this point.
84   *  The basic trick is to make the extend area look like a used
85   *  block and free it.
86   */
87
88  *amount_extended = size;
89
90  old_final = the_heap->final;
91  new_final = _Addresses_Add_offset( old_final, size );
92  /* SAME AS: _Addresses_Add_offset( starting_address, size-HEAP_OVERHEAD ); */
93
94  the_heap->final = new_final;
95
96  old_final->front_flag =
97  new_final->back_flag  = _Heap_Build_flag( size, HEAP_BLOCK_USED );
98  new_final->front_flag = HEAP_DUMMY_FLAG;
99
100  /*
101   *  Must pass in address of "user" area
102   *  So add in the offset field.
103   */
104
105  p = (uint32_t   *) &old_final->next;
106  *p = sizeof(uint32_t  );
107  p++;
108  _Heap_Free( the_heap, p );
109
110  return HEAP_EXTEND_SUCCESSFUL;
111}
Note: See TracBrowser for help on using the repository browser.