-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a stack pointer bounds check when configCHECK_FOR_STACK_OVERFLOW is set to 2. #1216
Conversation
Hi @jiladahe1997, Thank you for bringing this to our attention and for the PR. Code looks fine. You may have to fix up the formatting and unit tests. I will check back here in a bit. Best, Jason Carroll |
044d5b2
to
abef464
Compare
Hi @jasonpcarroll, Thanks for your reply. I noticed a format-check error in the GitHub CI, but it seems there were no unit test errors. I have fixed the format issue. Please review it again. |
I will re-run to confirm formatting and approve and then will get someone else to take a look. Thanks! |
Appreciate the follow-up! Let me know if there’s anything else to address. Looking forward to the other reviewer’s feedback. |
Signed-off-by: Gaurav Aggarwal <[email protected]>
Signed-off-by: Gaurav Aggarwal <[email protected]>
|
@jiladahe1997 Thank you for your contribution! |
Add a stack pointer bounds check when configCHECK_FOR_STACK_OVERFLOW is set to 2.
Description
I'm working on a small STM32F4 project using FreeRTOS. I've encountered a problem with stack overflow checks:
I am unsure how many bytes I need for my shell thread, so I set the stack size to 1024 bytes.
As documented in FreeRTOS-Kernel/include/stack_macros.h:
And as it says, setting configCHECK_FOR_STACK_OVERFLOW = 2 "will also" check the last few stack bytes. This suggests it should check both the stack bounds and the last few bytes.
However, here’s the problem I encountered:
In this scenario, the FreeRTOS kernel crashes, and the MCU enters a hard fault. The stack overflow check fails to detect the issue because configCHECK_FOR_STACK_OVERFLOW = 2 only verifies whether the last few stack bytes have been overwritten. However, in the above scenario, the stack has overflowed without overwriting the monitored bytes.
This patch fixes the issue by adding a stack pointer bounds check when configCHECK_FOR_STACK_OVERFLOW is set to 2. This improves the reliability of stack overflow detection and also aligns with the behavior described in stack_macros.h.
*Side Effects
Adding the stack pointer bounds check introduces extra overhead during the stack overflow detection process, which may slightly reduce performance.
Test Steps
Checklist:
Related Issue
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.