RTEMS
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 
39 #include <rtems/score/basedefs.h>
40 #include <rtems/score/assert.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif /* __cplusplus */
45 
60 typedef struct {
64  const void *begin;
65 
69  void *free;
70 
74  const void *end;
75 } Memory_Area;
76 
80 typedef 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 
304 const Memory_Information *_Memory_Get( void );
305 
319 void *_Memory_Allocate(
320  const Memory_Information *information,
321  uintptr_t size,
322  uintptr_t alignment
323 );
324 
332 void _Memory_Fill( const Memory_Information *information, int c );
333 
340 extern const bool _Memory_Zero_before_use;
341 
345 void _Memory_Zero_free_areas( void );
346 
350 void _Memory_Dirty_free_areas( void );
351 
354 #ifdef __cplusplus
355 }
356 #endif /* __cplusplus */
357 
358 #endif /* _RTEMS_SCORE_MEMORY_H */
static __inline__ size_t _Memory_Get_count(const Memory_Information *information)
Get the memory area count.
Definition: memory.h:115
const bool _Memory_Zero_before_use
Indicates if the memory is zeroed during system initialization.
static __inline__ void _Memory_Set_begin(Memory_Area *area, const void *begin)
Set the memory area begin.
Definition: memory.h:193
static __inline__ Memory_Area * _Memory_Get_area(const Memory_Information *information, size_t index)
Get a memory area by index.
Definition: memory.h:130
void * free
A pointer to the begin of the free area of the memory area.
Definition: memory.h:69
void _Memory_Fill(const Memory_Information *information, int c)
Fill all free memory areas of the memory information with a constant byte.
Memory_Area * areas
The memory area table.
Definition: memory.h:89
size_t count
The count of memory areas.
Definition: memory.h:84
The memory information.
Definition: memory.h:80
static __inline__ 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
Information for the Assert Handler.
static __inline__ void _Memory_Initialize(Memory_Area *area, void *begin, void *end)
Initialize the memory area.
Definition: memory.h:146
The memory area description.
Definition: memory.h:60
void _Memory_Zero_free_areas(void)
Zeros all free memory areas of the system.
static __inline__ void _Memory_Initialize_by_size(Memory_Area *area, void *begin, uintptr_t size)
Initialize the memory area by size.
Definition: memory.h:164
static __inline__ uintptr_t _Memory_Get_size(const Memory_Area *area)
Get the memory area size.
Definition: memory.h:234
const void * end
A pointer to the end of the memory area.
Definition: memory.h:74
static __inline__ const void * _Memory_Get_begin(const Memory_Area *area)
Get the memory area begin.
Definition: memory.h:182
static __inline__ void _Memory_Set_end(Memory_Area *area, const void *end)
Set the memory area end.
Definition: memory.h:219
const void * begin
A pointer to the begin of the memory area.
Definition: memory.h:64
static __inline__ 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
static __inline__ void * _Memory_Get_free_begin(const Memory_Area *area)
Get the begin of the free area of the memory area.
Definition: memory.h:246
void * _Memory_Allocate(const Memory_Information *information, uintptr_t size, uintptr_t alignment)
Allocate a memory area from the memory information.
static __inline__ 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
This header file provides basic definitions used by the API and the implementation.
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
const Memory_Information * _Memory_Get(void)
Return the memory information of this platform.
void _Memory_Dirty_free_areas(void)
Dirty all free memory areas of the system.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
static __inline__ const void * _Memory_Get_end(const Memory_Area *area)
Get the memory area end.
Definition: memory.h:208