1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** ThreadX Component                                                     */
16 /**                                                                       */
17 /**   Thread                                                              */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define TX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "tx_api.h"
28 #if defined(TX_MISRA_ENABLE) || defined(TX_ENABLE_STACK_CHECKING)
29 #include "tx_thread.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _tx_thread_stack_error_handler                      PORTABLE C      */
37 /*                                                           6.1.1        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    William E. Lamie, Microsoft Corporation                             */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function processes stack errors detected during run-time. The  */
45 /*    processing currently consists of a spin loop.                       */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    thread_ptr                            Thread control block pointer  */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    ThreadX internal code                                               */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  09-30-2020     William E. Lamie         Initial Version 6.1           */
68 /*  10-16-2020     William E. Lamie         Modified comment(s),          */
69 /*                                            fixed link issue,           */
70 /*                                            resulting in version 6.1.1  */
71 /*                                                                        */
72 /**************************************************************************/
_tx_thread_stack_error_handler(TX_THREAD * thread_ptr)73 VOID  _tx_thread_stack_error_handler(TX_THREAD *thread_ptr)
74 {
75 
76 TX_INTERRUPT_SAVE_AREA
77 
78 #ifdef TX_ENABLE_STACK_CHECKING
79 
80     /* Disable interrupts.  */
81     TX_DISABLE
82 
83     /* Determine if the application has registered an error handler.  */
84     if (_tx_thread_application_stack_error_handler != TX_NULL)
85     {
86 
87         /* Yes, an error handler is present, simply call the application error handler.  */
88         (_tx_thread_application_stack_error_handler)(thread_ptr);
89     }
90 
91     /* Restore interrupts.  */
92     TX_RESTORE
93 
94 #else
95 
96     /* Access input argument just for the sake of lint, MISRA, etc.  */
97     if (thread_ptr != TX_NULL)
98     {
99 
100         /* Disable interrupts.  */
101         TX_DISABLE
102 
103         /* Restore interrupts.  */
104         TX_RESTORE
105     }
106 #endif
107 }
108 #endif /* TX_MISRA_ENABLE */
109 
110