summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/score
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-03-27 11:15:43 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-03-27 18:05:05 +0100
commite0aba8cb9edd3630be3b81e1f1c3e8bdaf728d1e (patch)
treef2d7d3f04eb1b6cadb8047323a6e319fd8a1a01c /cpukit/include/rtems/score
parentpwdgrp.c: Change to simply ignore return value from mkdir(/etc) (diff)
downloadrtems-e0aba8cb9edd3630be3b81e1f1c3e8bdaf728d1e.tar.bz2
score: Fix task stack initialization
Do not adjust the stack area begin address since this may confuse the stack allocator and result in failed stack frees. Account for the alignment overhead in the stack space size estimate. Check that the stack size is in the expected interval.
Diffstat (limited to 'cpukit/include/rtems/score')
-rw-r--r--cpukit/include/rtems/score/stackimpl.h14
1 files changed, 6 insertions, 8 deletions
diff --git a/cpukit/include/rtems/score/stackimpl.h b/cpukit/include/rtems/score/stackimpl.h
index c15206002c..c261f8bd4f 100644
--- a/cpukit/include/rtems/score/stackimpl.h
+++ b/cpukit/include/rtems/score/stackimpl.h
@@ -135,7 +135,7 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
)
{
size_t extra_size;
- size_t alignment_overhead;
+ size_t allocator_overhead;
extra_size = _TLS_Get_allocation_size();
@@ -153,18 +153,16 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
* can be allocated for the stack, we have to align it up to the next stack
* boundary.
*/
- alignment_overhead = CPU_STACK_ALIGNMENT - 1;
+ extra_size += 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
+ allocator_overhead = CPU_STACK_ALIGNMENT - CPU_HEAP_ALIGNMENT;
- if ( stack_size > SIZE_MAX - extra_size - alignment_overhead ) {
+ if ( stack_size > SIZE_MAX - extra_size - allocator_overhead ) {
/*
* In case of an unsigned integer overflow, saturate at the maximum value.
*/
@@ -172,9 +170,9 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
}
stack_size += extra_size;
- stack_size = RTEMS_ALIGN_UP( stack_size, CPU_STACK_ALIGNMENT );
+ stack_size = RTEMS_ALIGN_DOWN( stack_size, CPU_STACK_ALIGNMENT );
- return stack_size;
+ return stack_size + allocator_overhead;
}
/**