summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/score/stackimpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/include/rtems/score/stackimpl.h')
-rw-r--r--cpukit/include/rtems/score/stackimpl.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/cpukit/include/rtems/score/stackimpl.h b/cpukit/include/rtems/score/stackimpl.h
index 43b7c8151e..c15206002c 100644
--- a/cpukit/include/rtems/score/stackimpl.h
+++ b/cpukit/include/rtems/score/stackimpl.h
@@ -135,6 +135,7 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
)
{
size_t extra_size;
+ size_t alignment_overhead;
extra_size = _TLS_Get_allocation_size();
@@ -147,15 +148,32 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
(void) is_fp;
#endif
- stack_size += extra_size;
+ /*
+ * In order to make sure that a user-provided stack size is the minimum which
+ * can be allocated for the stack, we have to align it up to the next stack
+ * boundary.
+ */
+ alignment_overhead = CPU_STACK_ALIGNMENT - 1;
+
+#if CPU_STACK_ALIGNMENT > CPU_HEAP_ALIGNMENT
+ /*
+ * If the heap allocator does not meet the stack alignment requirement, then
+ * we have to do the stack alignment manually in _Thread_Initialize() and
+ * need to allocate extra space for this.
+ */
+ alignment_overhead += CPU_STACK_ALIGNMENT - CPU_HEAP_ALIGNMENT;
+#endif
- if ( stack_size < extra_size ) {
+ if ( stack_size > SIZE_MAX - extra_size - alignment_overhead ) {
/*
* In case of an unsigned integer overflow, saturate at the maximum value.
*/
- stack_size = SIZE_MAX;
+ return SIZE_MAX;
}
+ stack_size += extra_size;
+ stack_size = RTEMS_ALIGN_UP( stack_size, CPU_STACK_ALIGNMENT );
+
return stack_size;
}