RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
memory.h
Go to the documentation of this file.
1
9/*
10 * SPDX-License-Identifier: BSD-2-Clause
11 *
12 * Copyright (C) 2019 embedded brains GmbH
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_SCORE_MEMORY_H
37#define _RTEMS_SCORE_MEMORY_H
38
40#include <rtems/score/assert.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif /* __cplusplus */
45
60typedef struct {
64 const void *begin;
65
69 void *free;
70
74 const void *end;
76
80typedef struct {
84 size_t count;
85
91
97#define MEMORY_INFORMATION_INITIALIZER( areas ) \
98 { RTEMS_ARRAY_SIZE( areas ), ( areas ) }
99
106#define MEMORY_INITIALIZER( begin, end ) { ( begin ), ( begin ), ( end ) }
107
116 const Memory_Information *information
117)
118{
119 return information->count;
120}
121
131 const Memory_Information *information,
132 size_t index
133)
134{
135 _Assert( index < _Memory_Get_count( information ) );
136 return &information->areas[ index ];
137}
138
147 Memory_Area *area,
148 void *begin,
149 void *end
150)
151{
152 area->begin = begin;
153 area->free = begin;
154 area->end = end;
155}
156
165 Memory_Area *area,
166 void *begin,
167 uintptr_t size
168)
169{
170 area->begin = begin;
171 area->free = begin;
172 area->end = (char *) begin + size;
173}
174
183{
184 return area->begin;
185}
186
194 Memory_Area *area,
195 const void *begin
196)
197{
198 area->begin = begin;
199}
200
209{
210 return area->end;
211}
212
220 Memory_Area *area,
221 const void *end
222)
223{
224 area->end = end;
225}
226
235{
236 return (uintptr_t) area->end - (uintptr_t) area->begin;
237}
238
247{
248 return area->free;
249}
250
258 Memory_Area *area,
259 void *begin
260)
261{
262 area->free = begin;
263}
264
273{
274 return (uintptr_t) area->end - (uintptr_t) area->free;
275}
276
286 Memory_Area *area,
287 uintptr_t consume
288)
289{
290 area->free = (char *) area->free + consume;
291}
292
304const Memory_Information *_Memory_Get( void );
305
319void *_Memory_Allocate(
320 const Memory_Information *information,
321 uintptr_t size,
322 uintptr_t alignment
323);
324
332void _Memory_Fill( const Memory_Information *information, int c );
333
340extern const bool _Memory_Zero_before_use;
341
345void _Memory_Zero_free_areas( void );
346
350void _Memory_Dirty_free_areas( void );
351
354#ifdef __cplusplus
355}
356#endif /* __cplusplus */
357
358#endif /* _RTEMS_SCORE_MEMORY_H */
Information for the Assert Handler.
Basic Definitions.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
RTEMS_INLINE_ROUTINE void _Memory_Initialize(Memory_Area *area, void *begin, void *end)
Initialize the memory area.
Definition: memory.h:146
RTEMS_INLINE_ROUTINE Memory_Area * _Memory_Get_area(const Memory_Information *information, size_t index)
Get a memory area by index.
Definition: memory.h:130
RTEMS_INLINE_ROUTINE const void * _Memory_Get_end(const Memory_Area *area)
Get the memory area end.
Definition: memory.h:208
RTEMS_INLINE_ROUTINE void _Memory_Initialize_by_size(Memory_Area *area, void *begin, uintptr_t size)
Initialize the memory area by size.
Definition: memory.h:164
RTEMS_INLINE_ROUTINE size_t _Memory_Get_count(const Memory_Information *information)
Get the memory area count.
Definition: memory.h:115
RTEMS_INLINE_ROUTINE void * _Memory_Get_free_begin(const Memory_Area *area)
Get the begin of the free area of the memory area.
Definition: memory.h:246
const Memory_Information * _Memory_Get(void)
Return the memory information of this platform.
Definition: bspgetworkarea.c:203
RTEMS_INLINE_ROUTINE void _Memory_Set_begin(Memory_Area *area, const void *begin)
Set the memory area begin.
Definition: memory.h:193
RTEMS_INLINE_ROUTINE uintptr_t _Memory_Get_free_size(const Memory_Area *area)
Get the size of the free memory area of the memory area.
Definition: memory.h:272
const bool _Memory_Zero_before_use
Indicates if the memory is zeroed during system initialization.
Definition: memoryzerobeforeuse.c:34
RTEMS_INLINE_ROUTINE void _Memory_Consume(Memory_Area *area, uintptr_t consume)
Consume the specified size from the free memory area of the memory area.
Definition: memory.h:285
RTEMS_INLINE_ROUTINE uintptr_t _Memory_Get_size(const Memory_Area *area)
Get the memory area size.
Definition: memory.h:234
void _Memory_Dirty_free_areas(void)
Dirty all free memory areas of the system.
Definition: memorydirtyfreeareas.c:34
void * _Memory_Allocate(const Memory_Information *information, uintptr_t size, uintptr_t alignment)
Allocate a memory area from the memory information.
Definition: memoryallocate.c:34
RTEMS_INLINE_ROUTINE void _Memory_Set_end(Memory_Area *area, const void *end)
Set the memory area end.
Definition: memory.h:219
RTEMS_INLINE_ROUTINE void _Memory_Set_free_begin(Memory_Area *area, void *begin)
Set the begin of the free area of the memory area.
Definition: memory.h:257
void _Memory_Zero_free_areas(void)
Zeros all free memory areas of the system.
Definition: memoryzerofreeareas.c:34
RTEMS_INLINE_ROUTINE const void * _Memory_Get_begin(const Memory_Area *area)
Get the memory area begin.
Definition: memory.h:182
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:36
The memory area description.
Definition: memory.h:60
const void * end
A pointer to the end of the memory area.
Definition: memory.h:74
const void * begin
A pointer to the begin of the memory area.
Definition: memory.h:64
void * free
A pointer to the begin of the free area of the memory area.
Definition: memory.h:69
The memory information.
Definition: memory.h:80
Memory_Area * areas
The memory area table.
Definition: memory.h:89
size_t count
The count of memory areas.
Definition: memory.h:84
unsigned size
Definition: tte.h:1