source: rtems/cpukit/score/include/rtems/score/protectedheap.h @ 7ff6115

4.104.115
Last change on this file since 7ff6115 was 7ff6115, checked in by Joel Sherrill <joel.sherrill@…>, on 11/20/08 at 20:01:13

2008-11-20 Joel Sherrill <joel.sherrill@…>

  • score/include/rtems/score/heap.h, score/include/rtems/score/protectedheap.h, score/include/rtems/score/wkspace.h, score/src/heap.c, score/src/heapallocate.c, score/src/heapallocatealigned.c, score/src/heapextend.c, score/src/heapresizeblock.c, score/src/heapsizeofuserarea.c, score/src/pheapgetblocksize.c, score/src/wkspace.c: Revert use of ssize_t. This type is not guaranteed to be able to represent a positive number greater than the size of a single allocatable object. We needed a type that is able to represent the size of a pool of multiple allocatable objects or potentially nearly all memory.
  • Property mode set to 100644
File size: 6.6 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  size_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  size_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  size_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  size_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  size_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  size_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 */
189void _Protected_heap_Get_information(
190  Heap_Control            *the_heap,
191  Heap_Information_block  *the_info
192);
193
194/**
195 *  This heap routine returns information about the free blocks
196 *  in the specified heap.
197 *
198 *  @param[in] the_heap pointer to heap header.
199 *  @param[in] info pointer to the free block information.
200 *
201 *  @return free block information filled in.
202 */
203void _Protected_heap_Get_free_information(
204  Heap_Control        *the_heap,
205  Heap_Information    *info
206);
207
208#ifdef __cplusplus
209}
210#endif
211
212/**@}*/
213
214#endif
215/* end of include file */
Note: See TracBrowser for help on using the repository browser.