Skip to content

Commit 4bdcc53

Browse files
M-Moawadcfriedt
authored andcommitted
tests: stackprot: add guard area to ensure portable overflow behavior
The stackprot test currently depends on compiler-generated stack frame layouts, which can vary between toolchains and optimization levels. This makes the overflow check fragile and may cause unintended faults. Add a small guard buffer in alternate_thread so the intentional overflow is always contained within the thread stack. This ensures the test behaves consistently across toolchains, architectures, and optimization settings. Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
1 parent 03a5860 commit 4bdcc53

File tree

1 file changed

+7
-0
lines changed
  • tests/kernel/mem_protect/stackprot/src

1 file changed

+7
-0
lines changed

tests/kernel/mem_protect/stackprot/src/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ void alternate_thread(void *p1, void *p2, void *p3)
8484
ARG_UNUSED(p1);
8585
ARG_UNUSED(p2);
8686
ARG_UNUSED(p3);
87+
/*
88+
* Padding buffer to absorb the intentional overflow inside the thread stack.
89+
* This prevents writes from crossing the thread stack boundary into the next
90+
* MPU-protected region. Required to make the test independent of compiler-
91+
* specific stack frame layouts.
92+
*/
93+
volatile __unused char overflow_guard_area[32] = "Forcing Initialization!";
8794

8895
TC_PRINT("Starts %s\n", __func__);
8996
check_input(__func__,

0 commit comments

Comments
 (0)