source: rtems/cpukit/include/rtems/score/protectedheap.h @ a660e9dc

Last change on this file since a660e9dc was a660e9dc, checked in by Sebastian Huber <sebastian.huber@…>, on 09/08/22 at 08:37:05

Do not use RTEMS_INLINE_ROUTINE

Directly use "static inline" which is available in C99 and later. This brings
the RTEMS implementation closer to standard C.

Close #3935.

  • Property mode set to 100644
File size: 10.1 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreProtHeap
7 *
8 * @brief This header file provides the interfaces of the
9 *   @ref RTEMSScoreProtHeap.
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2007.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 *    notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _RTEMS_SCORE_PROTECTED_HEAP_H
39#define _RTEMS_SCORE_PROTECTED_HEAP_H
40
41#include <rtems/score/heapimpl.h>
42#include <rtems/score/apimutex.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/**
49 * @defgroup RTEMSScoreProtHeap Protected Heap Handler
50 *
51 * @ingroup RTEMSScoreHeap
52 *
53 * @brief This group contains the Protected Heap Handler implementation.
54 *
55 * The @ref ScoreAllocatorMutex is used to protect the heap accesses.
56 *
57 * @{
58 */
59
60/**
61 * @brief Initializes the protected heap.
62 *
63 * @param[out] heap The heap to initialize.
64 * @param area_begin The starting address of the heap area.
65 * @param area_size The size of the heap area.
66 * @param page_size The page size for the heap.
67 */
68static inline uintptr_t _Protected_heap_Initialize(
69  Heap_Control *heap,
70  void *area_begin,
71  uintptr_t area_size,
72  uintptr_t page_size
73)
74{
75  return _Heap_Initialize( heap, area_begin, area_size, page_size );
76}
77
78/**
79 * @brief Extends the protected heap.
80 *
81 * @param[in, out] heap The heap to extend.
82 * @param area_begin The starting addres of the area to extend @a heap with.
83 * @param area_size The size of the heap area.
84 *
85 * @retval true The operation succeeded.
86 * @retval false The operation failed.
87 */
88bool _Protected_heap_Extend(
89  Heap_Control *heap,
90  void *area_begin,
91  uintptr_t area_size
92);
93
94/**
95 * @brief Allocates an aligned memory area with boundary constraint for the protected heap.
96 *
97 * A size value of zero will return a unique address which may be freed with
98 * _Heap_Free().  This method first locks the allocator and after the allocation of the memory
99 * area, unlocks it again.
100 *
101 * @param[in, out] heap The heap to allocate a memory are from.
102 * @param size The size of the desired memory are in bytes.
103 * @param alignment The allocated memory area will begin at an address aligned by this value.
104 * @param boundary The allocated memory area will fulfill a boundary constraint,
105 *      if this value is not equal to zero.  The boundary value specifies
106 *      the set of addresses which are aligned by the boundary value.  The
107 *      interior of the allocated memory area will not contain an element of this
108 *      set.  The begin or end address of the area may be a member of the set.
109 *
110 * @retval pointer The starting address of the allocated memory area.
111 * @retval NULL No memory is available of the parameters are inconsistent.
112 */
113void *_Protected_heap_Allocate_aligned_with_boundary(
114  Heap_Control *heap,
115  uintptr_t size,
116  uintptr_t alignment,
117  uintptr_t boundary
118);
119
120/**
121 * @brief Allocates an aligned memory area.
122 *
123 * A size value of zero will return a unique address which may be freed with
124 * _Heap_Free().  This method first locks the allocator and after the allocation of the memory
125 * area, unlocks it again.
126 *
127 * @param[in, out] heap The heap to allocate a memory are from.
128 * @param size The size of the desired memory are in bytes.
129 * @param alignment The allocated memory area will begin at an address aligned by this value.
130 *
131 * @retval pointer The starting address of the allocated memory area.
132 * @retval NULL No memory is available of the parameters are inconsistent.
133 */
134static inline void *_Protected_heap_Allocate_aligned(
135  Heap_Control *heap,
136  uintptr_t size,
137  uintptr_t alignment
138)
139{
140  return
141    _Protected_heap_Allocate_aligned_with_boundary( heap, size, alignment, 0 );
142}
143
144/**
145 * @brief Allocates a memory area.
146 *
147 * A size value of zero will return a unique address which may be freed with
148 * _Heap_Free().  This method first locks the allocator and after the allocation of the memory
149 * area, unlocks it again.
150 *
151 * @param[in, out] heap The heap to allocate a memory are from.
152 * @param size The size of the desired memory are in bytes.
153 *
154 * @retval pointer The starting address of the allocated memory area.
155 * @retval NULL No memory is available of the parameters are inconsistent.
156 */
157static inline void *_Protected_heap_Allocate(
158  Heap_Control *heap,
159  uintptr_t size
160)
161{
162  return _Protected_heap_Allocate_aligned_with_boundary( heap, size, 0, 0 );
163}
164
165/**
166 * @brief Returns the size of the allocatable memory area.
167 *
168 * The size value may be greater than the initially requested size in
169 * _Heap_Allocate_aligned_with_boundary().
170 *
171 * Inappropriate values for @a addr will not corrupt the heap, but may yield
172 * invalid size values.
173 *
174 * This method first locks the allocator and after the operation, unlocks it again.
175 *
176 * @param heap The heap to operate upon.
177 * @param addr The starting address of the allocatable memory area.
178 * @param[out] size Stores the size of the allocatable memory area after the method call.
179 *
180 * @retval true The operation was successful.
181 * @retval false The operation was not successful.
182 */
183bool _Protected_heap_Get_block_size(
184  Heap_Control *heap,
185  void *addr,
186  uintptr_t *size
187);
188
189/**
190 * @brief Resizes the block of the allocated memory area.
191 *
192 * Inappropriate values for @a addr may corrupt the heap.
193 *
194 * This method first locks the allocator and after the resize, unlocks it again.
195 *
196 * @param[in, out] heap The heap to operate upon.
197 * @param addr The starting address of the allocated memory area to be resized.
198 * @param size The least possible size for the new memory area.  Resize may be
199 *      impossible and depends on the current heap usage.
200 * @param[out] old_size Stores the size available for allocation in the current
201 *      block before the resize after the method call.
202 * @param[out] new_size Stores the size available for allocation in the resized
203 *      block after the method call.  In the case of an unsuccessful resize,
204 *      zero is returned in this parameter
205 *
206 * @retval HEAP_RESIZE_SUCCESSFUL The resize was successful.
207 * @retval HEAP_RESIZE_UNSATISFIED The least possible size @a size was too big.
208 *      Resize not possible.
209 * @retval HEAP_RESIZE_FATAL_ERROR The block starting at @a addr is not part of
210 *      the heap.
211 */
212bool _Protected_heap_Resize_block(
213  Heap_Control *heap,
214  void *addr,
215  uintptr_t size
216);
217
218/**
219 * @brief Frees the allocated memory area.
220 *
221 * Inappropriate values for @a addr may corrupt the heap.  This method first locks
222 * the allocator and after the free operation, unlocks it again.
223 *
224 * @param[in, out] heap The heap of the allocated memory area.
225 * @param addr The starting address of the memory area to be freed.
226 *
227 * @retval true The allocated memory area was successfully freed.
228 * @retval false The method failed.
229 */
230bool _Protected_heap_Free( Heap_Control *heap, void *addr );
231
232/**
233 * @brief Verifies the integrity of the heap.
234 *
235 * Walks the heap to verify its integrity.  This method first locks
236 * the allocator and after the operation, unlocks it again, if the thread dispatch is enabled.
237 *
238 * @param heap The heap whose integrity is to be verified.
239 * @param source If @a dump is @c true, this is used to mark the output lines.
240 * @param dump Indicates whether diagnostic messages will be printed to standard output.
241 *
242 * @retval true No errors occurred, the heapÂŽs integrity is not violated.
243 * @retval false The heap is corrupt.
244 */
245bool _Protected_heap_Walk( Heap_Control *heap, int source, bool dump );
246
247/**
248 * @brief Iterates over all blocks of the heap.
249 *
250 * This method first locks the allocator and after the operation, unlocks it again.
251 *
252 * @param[in, out] heap The heap to iterate over.
253 * @param visitor This will be called for each heap block with
254 *      the argument @a visitor_arg.
255 * @param[in, out] visitor_arg The argument for all calls of @a visitor.
256 */
257void _Protected_heap_Iterate(
258  Heap_Control *heap,
259  Heap_Block_visitor visitor,
260  void *visitor_arg
261);
262
263/**
264 * @brief Returns information about used and free blocks for the heap.
265 *
266 * This method first locks the allocator and after the operation, unlocks it again.
267 *
268 * @param heap The heap to get the information from.
269 * @param[out] info Stores the information of the @a heap after the method call.
270 */
271bool _Protected_heap_Get_information(
272  Heap_Control *heap,
273  Heap_Information_block *info
274);
275
276/**
277 * @brief Returns information about free blocks for the heap.
278 *
279 * This method first locks the allocator and after the operation, unlocks it again.
280 *
281 * @param heap The heap to get the information from.
282 * @param[out] info Stores the information about free blocks of @a heap after the
283 *      method call.
284 */
285bool _Protected_heap_Get_free_information(
286  Heap_Control *heap,
287  Heap_Information *info
288);
289
290/**
291 * @brief Returns the size of the allocatable area in bytes.
292 *
293 * This value is an integral multiple of the page size.
294 *
295 * @param heap The heap to get the allocatable area from.
296 *
297 * @return The size of the allocatable area in @a heap in bytes.
298 */
299uintptr_t _Protected_heap_Get_size( Heap_Control *heap );
300
301/** @} */
302
303#ifdef __cplusplus
304}
305#endif
306
307#endif
308/* end of include file */
Note: See TracBrowser for help on using the repository browser.