source: rtems/cpukit/score/include/rtems/score/protectedheap.h @ 4423e62a

4.104.115
Last change on this file since 4423e62a was 4423e62a, checked in by Joel Sherrill <joel.sherrill@…>, on 05/13/09 at 16:48:08

2009-05-13 Joel Sherrill <joel.sherrill@…>

PR 1411/cpukit

  • rtems/src/workspace.c, score/include/rtems/score/protectedheap.h, score/src/pheapgetfreeinfo.c, score/src/pheapgetinfo.c: Improve workspace wrapper methods.
  • Property mode set to 100644
File size: 7.0 KB
Line 
1/**
2 *  @file  rtems/score/protectedheap.h
3 *
4 *  This include file contains the information pertaining to the
5 *  Protected Heap Handler.
6 *
7 *  COPYRIGHT (c) 1989-2007.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 *  $Id$
15 */
16
17#ifndef _RTEMS_SCORE_PROTECTED_HEAP_H
18#define _RTEMS_SCORE_PROTECTED_HEAP_H
19
20#include <rtems/score/heap.h>
21#include <rtems/score/apimutex.h>
22
23/**
24 *  @defgroup ScoreProtHeap Protected Heap Handler
25 *
26 *  This handler encapsulates functionality which provides the foundation
27 *  Protected Heap services.
28 *
29 *  It is a simple wrapper for the help with the addition of the
30 *  allocation mutex being used for protection.
31 */
32/**@{*/
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/**
39 *  This routine initializes @a the_heap record to manage the
40 *  contiguous heap of @a size bytes which starts at @a starting_address.
41 *  Blocks of memory are allocated from the heap in multiples of
42 *  @a page_size byte units. If @a page_size is 0 or is not multiple of
43 *  CPU_ALIGNMENT, it's aligned up to the nearest CPU_ALIGNMENT boundary.
44 *
45 *  @param[in] the_heap is the heap to operate upon
46 *  @param[in] starting_address is the starting address of the memory for
47 *         the heap
48 *  @param[in] size is the size in bytes of the memory area for the heap
49 *  @param[in] page_size is the size in bytes of the allocation unit
50 *
51 *  @return This method returns the maximum memory available.  If
52 *          unsuccessful, 0 will be returned.
53 */
54static inline uint32_t _Protected_heap_Initialize(
55  Heap_Control *the_heap,
56  void         *starting_address,
57  intptr_t      size,
58  uint32_t      page_size
59)
60{
61  return _Heap_Initialize( the_heap, starting_address, size, page_size );
62}
63
64/**
65 *  This routine grows @a the_heap memory area using the size bytes which
66 *  begin at @a starting_address.
67 *
68 *  @param[in] the_heap is the heap to operate upon
69 *  @param[in] starting_address is the starting address of the memory
70 *         to add to the heap
71 *  @param[in] size is the size in bytes of the memory area to add
72 *  @return a status indicating success or the reason for failure
73 */
74bool _Protected_heap_Extend(
75  Heap_Control *the_heap,
76  void         *starting_address,
77  intptr_t      size
78);
79
80/**
81 *  This function attempts to allocate a block of @a size bytes from
82 *  @a the_heap.  If insufficient memory is free in @a the_heap to allocate
83 *  a block of the requested size, then NULL is returned.
84 *
85 *  @param[in] the_heap is the heap to operate upon
86 *  @param[in] size is the amount of memory to allocate in bytes
87 *  @return NULL if unsuccessful and a pointer to the block if successful
88 */
89void *_Protected_heap_Allocate(
90  Heap_Control *the_heap,
91  intptr_t      size
92);
93
94/**
95 *  This function attempts to allocate a memory block of @a size bytes from
96 *  @a the_heap so that the start of the user memory is aligned on the
97 *  @a alignment boundary. If @a alignment is 0, it is set to CPU_ALIGNMENT.
98 *  Any other value of @a alignment is taken "as is", i.e., even odd
99 *  alignments are possible.
100 *  Returns pointer to the start of the memory block if success, NULL if
101 *  failure.
102 *
103 *  @param[in] the_heap is the heap to operate upon
104 *  @param[in] size is the amount of memory to allocate in bytes
105 *  @param[in] alignment the required alignment
106 *  @return NULL if unsuccessful and a pointer to the block if successful
107 */
108void *_Protected_heap_Allocate_aligned(
109  Heap_Control *the_heap,
110  intptr_t      size,
111  uint32_t      alignment
112);
113
114/**
115 *  This function sets @a *size to the size of the block of user memory
116 *  which begins at @a starting_address. The size returned in @a *size could
117 *  be greater than the size requested for allocation.
118 *  Returns true if the @a starting_address is in the heap, and false
119 *  otherwise.
120 *
121 *  @param[in] the_heap is the heap to operate upon
122 *  @param[in] starting_address is the starting address of the user block
123 *         to obtain the size of
124 *  @param[in] size points to a user area to return the size in
125 *  @return true if successfully able to determine the size, false otherwise
126 *  @return *size filled in with the size of the user area for this block
127 */
128bool _Protected_heap_Get_block_size(
129  Heap_Control        *the_heap,
130  void                *starting_address,
131  intptr_t            *size
132);
133
134/**
135 *  This function tries to resize in place the block that is pointed to by the
136 *  @a starting_address to the new @a size.
137 *
138 *  @param[in] the_heap is the heap to operate upon
139 *  @param[in] starting_address is the starting address of the user block
140 *         to be resized
141 *  @param[in] size is the new size
142 *
143 *  @return true if successfully able to resize the block.
144 *          false if the block can't be resized in place.
145 */
146bool _Protected_heap_Resize_block(
147  Heap_Control *the_heap,
148  void         *starting_address,
149  intptr_t      size
150);
151
152/**
153 *  This routine returns the block of memory which begins
154 *  at @a starting_address to @a the_heap.  Any coalescing which is
155 *  possible with the freeing of this routine is performed.
156 *
157 *  @param[in] the_heap is the heap to operate upon
158 *  @param[in] start_address is the starting address of the user block
159 *         to free
160 *  @return true if successfully freed, false otherwise
161 */
162bool _Protected_heap_Free(
163  Heap_Control *the_heap,
164  void         *start_address
165);
166
167/**
168 *  This routine walks the heap to verify its integrity.
169 *
170 *  @param[in] the_heap is the heap to operate upon
171 *  @param[in] source is a user specified integer which may be used to
172 *         indicate where in the application this was invoked from
173 *  @param[in] do_dump is set to true if errors should be printed
174 *  @return true if the test passed fine, false otherwise.
175 */
176bool _Protected_heap_Walk(
177  Heap_Control *the_heap,
178  int           source,
179  bool          do_dump
180);
181
182/**
183 *  This routine walks the heap and tots up the free and allocated
184 *  sizes.
185 *
186 *  @param[in] the_heap pointer to heap header
187 *  @param[in] the_info pointer to a status information area
188 *
189 *  @return true if successfully able to return information
190 */
191bool _Protected_heap_Get_information(
192  Heap_Control            *the_heap,
193  Heap_Information_block  *the_info
194);
195
196/**
197 *  This heap routine returns information about the free blocks
198 *  in the specified heap.
199 *
200 *  @param[in] the_heap pointer to heap header.
201 *  @param[in] info pointer to the free block information.
202 *
203 *  @return free block information filled in.
204 */
205bool _Protected_heap_Get_free_information(
206  Heap_Control        *the_heap,
207  Heap_Information    *info
208);
209
210/**
211 *  This function returns the maximum size of the protected heap.
212 *
213 *  @param[in] the_heap points to the heap being operated upon
214 *
215 *  @return This method returns the total amount of memory
216 *          allocated to the heap.
217 */
218uint32_t _Protected_heap_Get_size(
219  Heap_Control        *the_heap
220);
221
222#ifdef __cplusplus
223}
224#endif
225
226/**@}*/
227
228#endif
229/* end of include file */
Note: See TracBrowser for help on using the repository browser.