[En-Nut-Discussion] Can a thread determine its stack space?
Ulrich Prinz
uprinz2 at netscape.net
Thu Sep 23 19:38:08 CEST 2010
Hi Pedro,
that is mostly what is already present in Nut/OS. You can find it in
thread.c if either NUTDEBUG_CHECK_STACKMIN or NUTDEBUG_CHECK_STACK is
enabled. May be it is from you?
(Small explanation for the other readers:)
The stack area of a thread is initialized with 0xdeadbeef. While running
tha thread occupies stack from top to bottom and therefore overwrites
the tokens. For checking the maximum stack used, yust count the
remaining 0xdeadbeef from bottom to top.
If neither of the defines above are set, only the last four words are
initialized with 0xdeadbeef. This can be used to check if the stack has
run into / over that area.
Afaik NutStackAvail() is switched depending on the defines above.
If one of the defines is active it reports the number of tokens found
and therefore the real stack size. If the defines are inactive, it
reports 32 what is the number of tokens in the small checking.
What was my problem?
I asked because I expected two things:
1) A location where these defines could be set.
2) Stack checking in the Non-Debug condition.
As this wasn't available I implemented it in the STM32 branch for testing.
1) Stack checking can be enabled in nutconf.
2) It works without performance impact (besides some us while creating a
thread) in Non-Debug applications.
If it passes the next days without a flew I will put it into the trunk.
What I didn't track was, if the simple stack checking rises a NUTPANIC.
On the first reading I didn't see any call to this.
Best regards
Ulrich
More information about the En-Nut-Discussion
mailing list