summaryrefslogtreecommitdiff
path: root/common/src/tx_thread_stack_analyze.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/tx_thread_stack_analyze.c')
-rw-r--r--common/src/tx_thread_stack_analyze.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/common/src/tx_thread_stack_analyze.c b/common/src/tx_thread_stack_analyze.c
index 080d0052..e3023f13 100644
--- a/common/src/tx_thread_stack_analyze.c
+++ b/common/src/tx_thread_stack_analyze.c
@@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Some portions generated by Copilot (Opus 5).
+
/**************************************************************************/
/**************************************************************************/
@@ -70,6 +72,9 @@ TX_INTERRUPT_SAVE_AREA
ULONG *stack_ptr;
ULONG *stack_lowest;
ULONG *stack_highest;
+ULONG *probe_ptr;
+ULONG probe_count;
+UINT fill_present;
ULONG size;
@@ -110,8 +115,49 @@ ULONG size;
size = (ULONG) (TX_ULONG_POINTER_DIF(stack_highest, stack_lowest))/((ULONG) 2);
stack_ptr = TX_ULONG_POINTER_ADD(stack_lowest, size);
- /* Determine if the pattern is still there. */
- if (*stack_ptr != TX_STACK_FILL)
+ /* Determine if the pattern is still there. To avoid stopping on an
+ unwritten hole inside an otherwise used region, require several
+ consecutive fill words, working towards the lowest address. The scan
+ stops at the lowest known fill location, since everything at or below
+ that point is already known to hold the fill pattern. */
+ fill_present = TX_TRUE;
+ probe_ptr = stack_ptr;
+ probe_count = TX_THREAD_STACK_ANALYZE_FILL_WORDS;
+ while (probe_count != ((ULONG) 0))
+ {
+
+ /* Determine if this word still holds the fill pattern. */
+ if (*probe_ptr != TX_STACK_FILL)
+ {
+
+ /* No, the probe location is in use. */
+ fill_present = TX_FALSE;
+ probe_count = ((ULONG) 0);
+ }
+ else
+ {
+
+ /* Yes, account for this word. */
+ probe_count--;
+
+ /* Determine if the lowest known fill location has been reached. */
+ if (probe_ptr <= stack_lowest)
+ {
+
+ /* Yes, nothing further to check. */
+ probe_count = ((ULONG) 0);
+ }
+ else
+ {
+
+ /* Position to the previous word in the stack. */
+ probe_ptr = TX_ULONG_POINTER_SUB(probe_ptr, 1);
+ }
+ }
+ }
+
+ /* Determine if the probe location is in use. */
+ if (fill_present == TX_FALSE)
{
/* Update the stack highest, since we need to look in the upper half now. */