RTEMS 7.0-rc1
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#else
116 (void) is_fp;
117#endif
118
119 return ( size >= minimum );
120}
121
133static inline size_t _Stack_Ensure_minimum (
134 size_t size
135)
136{
137 if ( size >= _Stack_Minimum() )
138 return size;
139 return _Stack_Minimum();
140}
141
153static inline size_t _Stack_Extend_size(
154 size_t stack_size,
155 bool is_fp
156)
157{
158 size_t extra_size;
159 size_t allocator_overhead;
160
161 extra_size = _TLS_Get_allocation_size();
162
163#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
164 if ( is_fp ) {
165 /* This addition cannot overflow since the TLS size cannot be that large */
166 extra_size += CONTEXT_FP_SIZE;
167 }
168#else
169 (void) is_fp;
170#endif
171
172 /*
173 * In order to make sure that a user-provided stack size is the minimum which
174 * can be allocated for the stack, we have to align it up to the next stack
175 * boundary.
176 */
177 extra_size += CPU_STACK_ALIGNMENT - 1;
178
179 /*
180 * If the heap allocator does not meet the stack alignment requirement, then
181 * we have to do the stack alignment manually in _Thread_Initialize() and
182 * need to allocate extra space for this.
183 */
184 allocator_overhead = CPU_STACK_ALIGNMENT - CPU_HEAP_ALIGNMENT;
185
186 if ( stack_size > SIZE_MAX - extra_size - allocator_overhead ) {
187 /*
188 * In case of an unsigned integer overflow, saturate at the maximum value.
189 */
190 return SIZE_MAX;
191 }
192
193 stack_size += extra_size;
194 stack_size = RTEMS_ALIGN_DOWN( stack_size, CPU_STACK_ALIGNMENT );
195
196 return stack_size + allocator_overhead;
197}
198
207void *_Stack_Allocate( size_t stack_size );
208
216void _Stack_Free( void *stack_area );
217
220#ifdef __cplusplus
221}
222#endif
223
224#endif
225/* end of include file */
This header file provides the interfaces of the Context Handler.
#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
This header file provides interfaces of the Stack Handler which are used by the implementation and th...
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).