RTEMS 6.1-rc2
Loading...
Searching...
No Matches
stackimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (c) 1989-2006.
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_STACKIMPL_H
39#define _RTEMS_SCORE_STACKIMPL_H
40
41#include <rtems/score/stack.h>
42#include <rtems/score/context.h>
43#include <rtems/score/tls.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
66static inline void _Stack_Initialize (
67 Stack_Control *the_stack,
68 void *starting_address,
69 size_t size
70)
71{
72 the_stack->area = starting_address;
73 the_stack->size = size;
74}
75
84static inline uint32_t _Stack_Minimum (void)
85{
87}
88
101static inline bool _Stack_Is_enough(
102 size_t size,
103 bool is_fp
104)
105{
106 size_t minimum;
107
108 minimum = _TLS_Get_allocation_size();
109 minimum += _Stack_Minimum();
110
111#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
112 if ( is_fp ) {
113 minimum += CONTEXT_FP_SIZE;
114 }
115#endif
116
117 return ( size >= minimum );
118}
119
131static inline size_t _Stack_Ensure_minimum (
132 size_t size
133)
134{
135 if ( size >= _Stack_Minimum() )
136 return size;
137 return _Stack_Minimum();
138}
139
151static inline size_t _Stack_Extend_size(
152 size_t stack_size,
153 bool is_fp
154)
155{
156 size_t extra_size;
157 size_t allocator_overhead;
158
159 extra_size = _TLS_Get_allocation_size();
160
161#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
162 if ( is_fp ) {
163 /* This addition cannot overflow since the TLS size cannot be that large */
164 extra_size += CONTEXT_FP_SIZE;
165 }
166#else
167 (void) is_fp;
168#endif
169
170 /*
171 * In order to make sure that a user-provided stack size is the minimum which
172 * can be allocated for the stack, we have to align it up to the next stack
173 * boundary.
174 */
175 extra_size += CPU_STACK_ALIGNMENT - 1;
176
177 /*
178 * If the heap allocator does not meet the stack alignment requirement, then
179 * we have to do the stack alignment manually in _Thread_Initialize() and
180 * need to allocate extra space for this.
181 */
182 allocator_overhead = CPU_STACK_ALIGNMENT - CPU_HEAP_ALIGNMENT;
183
184 if ( stack_size > SIZE_MAX - extra_size - allocator_overhead ) {
185 /*
186 * In case of an unsigned integer overflow, saturate at the maximum value.
187 */
188 return SIZE_MAX;
189 }
190
191 stack_size += extra_size;
192 stack_size = RTEMS_ALIGN_DOWN( stack_size, CPU_STACK_ALIGNMENT );
193
194 return stack_size + allocator_overhead;
195}
196
205void *_Stack_Allocate( size_t stack_size );
206
214void _Stack_Free( void *stack_area );
215
218#ifdef __cplusplus
219}
220#endif
221
222#endif
223/* end of include file */
This header file provides the interfaces of the Context Handler.
This header file provides interfaces of the Stack Handler which are used by the implementation and th...
#define RTEMS_ALIGN_DOWN(_value, _alignment)
Aligns down the value to the alignment.
Definition: basedefs.h:123
#define CONTEXT_FP_SIZE
Size of floating point context area.
Definition: context.h:70
void _Stack_Free(void *stack_area)
Free the stack area allocated by _Stack_Allocate().
Definition: threadstackfree.c:45
void * _Stack_Allocate(size_t stack_size)
Allocate the requested stack space.
Definition: threadstackallocate.c:45
uint32_t rtems_minimum_stack_size
The minimum stack size.
uintptr_t _TLS_Get_allocation_size(void)
Gets the allocation size of the thread-local storage area in bytes.
Definition: tlsallocsize.c:78
Definition: stack.h:71
size_t size
Definition: stack.h:73
void * area
Definition: stack.h:75
This header file provides the interfaces of the Thread-Local Storage (TLS).