RTEMS 6.1-rc7
Loading...
Searching...
No Matches
memory.h
Go to the documentation of this file.
1
10/*
11 * SPDX-License-Identifier: BSD-2-Clause
12 *
13 * Copyright (C) 2019, 2022 embedded brains GmbH & Co. KG
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_SCORE_MEMORY_H
38#define _RTEMS_SCORE_MEMORY_H
39
41#include <rtems/score/assert.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif /* __cplusplus */
46
63typedef struct {
67 const void *begin;
68
72 void *free;
73
77 const void *end;
79
83typedef struct {
87 size_t count;
88
94
100#define MEMORY_INFORMATION_INITIALIZER( areas ) \
101 { RTEMS_ARRAY_SIZE( areas ), ( areas ) }
102
109#define MEMORY_INITIALIZER( begin, end ) { ( begin ), ( begin ), ( end ) }
110
118static inline size_t _Memory_Get_count(
119 const Memory_Information *information
120)
121{
122 return information->count;
123}
124
133static inline Memory_Area *_Memory_Get_area(
134 const Memory_Information *information,
135 size_t index
136)
137{
138 _Assert( index < _Memory_Get_count( information ) );
139 return &information->areas[ index ];
140}
141
149static inline void _Memory_Initialize(
150 Memory_Area *area,
151 void *begin,
152 void *end
153)
154{
155 area->begin = begin;
156 area->free = begin;
157 area->end = end;
158}
159
167static inline void _Memory_Initialize_by_size(
168 Memory_Area *area,
169 void *begin,
170 uintptr_t size
171)
172{
173 area->begin = begin;
174 area->free = begin;
175 area->end = (char *) begin + size;
176}
177
185static inline const void *_Memory_Get_begin( const Memory_Area *area )
186{
187 return area->begin;
188}
189
196static inline void _Memory_Set_begin(
197 Memory_Area *area,
198 const void *begin
199)
200{
201 area->begin = begin;
202}
203
211static inline const void *_Memory_Get_end( const Memory_Area *area )
212{
213 return area->end;
214}
215
222static inline void _Memory_Set_end(
223 Memory_Area *area,
224 const void *end
225)
226{
227 area->end = end;
228}
229
237static inline uintptr_t _Memory_Get_size( const Memory_Area *area )
238{
239 return (uintptr_t) area->end - (uintptr_t) area->begin;
240}
241
249static inline void *_Memory_Get_free_begin( const Memory_Area *area )
250{
251 return area->free;
252}
253
260static inline void _Memory_Set_free_begin(
261 Memory_Area *area,
262 void *begin
263)
264{
265 area->free = begin;
266}
267
275static inline uintptr_t _Memory_Get_free_size( const Memory_Area *area )
276{
277 return (uintptr_t) area->end - (uintptr_t) area->free;
278}
279
288static inline void _Memory_Consume(
289 Memory_Area *area,
290 uintptr_t consume
291)
292{
293 area->free = (char *) area->free + consume;
294}
295
307const Memory_Information *_Memory_Get( void );
308
322void *_Memory_Allocate(
323 const Memory_Information *information,
324 uintptr_t size,
325 uintptr_t alignment
326);
327
335void _Memory_Fill( const Memory_Information *information, int c );
336
343extern const bool _Memory_Zero_before_use;
344
348void _Memory_Zero_free_areas( void );
349
353void _Memory_Dirty_free_areas( void );
354
359extern char _Memory_Noinit_begin[];
360
365extern char _Memory_Noinit_end[];
366
369#ifdef __cplusplus
370}
371#endif /* __cplusplus */
372
373#endif /* _RTEMS_SCORE_MEMORY_H */
This header file provides the interfaces of the Assert Handler.
This header file provides basic definitions used by the API and the implementation.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
char _Memory_Noinit_end[]
This symbol marks the end of the non-initialized section used by RTEMS.
const Memory_Information * _Memory_Get(void)
Return the memory information of this platform.
Definition: bspgetworkarea.c:227
const bool _Memory_Zero_before_use
Indicates if the memory is zeroed during system initialization.
Definition: memoryzerobeforeuse.c:43
void _Memory_Dirty_free_areas(void)
Dirty all free memory areas of the system.
Definition: memorydirtyfreeareas.c:45
void * _Memory_Allocate(const Memory_Information *information, uintptr_t size, uintptr_t alignment)
Allocate a memory area from the memory information.
Definition: memoryallocate.c:43
void _Memory_Zero_free_areas(void)
Zeros all free memory areas of the system.
Definition: memoryzerofreeareas.c:45
void _Memory_Fill(const Memory_Information *information, int c)
Fill all free memory areas of the memory information with a constant byte.
Definition: memoryfill.c:45
char _Memory_Noinit_begin[]
This symbol marks the begin of the non-initialized section used by RTEMS.
The memory area description.
Definition: memory.h:63
const void * end
A pointer to the end of the memory area.
Definition: memory.h:77
const void * begin
A pointer to the begin of the memory area.
Definition: memory.h:67
void * free
A pointer to the begin of the free area of the memory area.
Definition: memory.h:72
The memory information.
Definition: memory.h:83
Memory_Area * areas
The memory area table.
Definition: memory.h:92
size_t count
The count of memory areas.
Definition: memory.h:87