RTEMS 6.1-rc1
mallocinitone.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2012, 2020 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_MALLOCINITONE_H
38#define _RTEMS_MALLOCINITONE_H
39
40#include <rtems/malloc.h>
41#include <rtems/score/assert.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
57static inline Heap_Control *_Malloc_Initialize_for_one_area(
58 Heap_Control *heap
59)
60{
61 const Memory_Information *mem;
62 Memory_Area *area;
63 uintptr_t space_available;
64
65 mem = _Memory_Get();
66 _Assert( _Memory_Get_count( mem ) == 1 );
67
68 RTEMS_Malloc_Heap = heap;
69 area = _Memory_Get_area( mem, 0 );
70 space_available = _Heap_Initialize(
71 heap,
72 _Memory_Get_free_begin( area ),
73 _Memory_Get_free_size( area ),
74 CPU_HEAP_ALIGNMENT
75 );
76
77 if ( space_available > 0 ) {
78 _Memory_Consume( area, _Memory_Get_free_size( area ) );
79 } else {
80 _Internal_error( INTERNAL_ERROR_NO_MEMORY_FOR_HEAP );
81 }
82
83 return heap;
84}
85
86#ifdef __cplusplus
87}
88#endif
89
90#endif /* _RTEMS_MALLOCINITONE_H */
This header file provides the interfaces of the Assert Handler.
Heap_Control * RTEMS_Malloc_Heap
C program heap control.
Definition: mallocheap.c:45
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
uintptr_t _Heap_Initialize(Heap_Control *heap, void *area_begin, uintptr_t area_size, uintptr_t page_size)
Initializes the heap control block.
Definition: heap.c:225
RTEMS_NO_RETURN void _Internal_error(Internal_errors_Core_list core_error)
Terminates the system with an INTERNAL_ERROR_CORE fatal source and the specified core error code.
Definition: interr.c:61
const Memory_Information * _Memory_Get(void)
Return the memory information of this platform.
Definition: bspgetworkarea.c:227
This header file provides interfaces of the Barrier Handler which are only used by the implementation...
This header file defines interfaces to support and use dynamic memory allocation.
Control block used to manage a heap.
Definition: heap.h:339
The memory area description.
Definition: memory.h:63
The memory information.
Definition: memory.h:83