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