source: rtems-docs/c_user/fatal_error.rst @ 8ef6ea8

4.115
Last change on this file since 8ef6ea8 was 8ef6ea8, checked in by Chris Johns <chrisj@…>, on 01/27/16 at 06:50:19

Clean ups.

  • Property mode set to 100644
File size: 7.4 KB
Line 
1.. COMMENT: COPYRIGHT (c) 1988-2008.
2.. COMMENT: On-Line Applications Research Corporation (OAR).
3.. COMMENT: All rights reserved.
4
5Fatal Error Manager
6###################
7
8.. index:: fatal errors
9
10Introduction
11============
12
13The fatal error manager processes all fatal or irrecoverable errors and other
14sources of system termination (for example after ``exit()``).  The directives
15provided by the fatal error manager are:
16
17- rtems_fatal_error_occurred_ - Invoke the fatal error handler
18
19- rtems_fatal_ - Invoke the fatal error handler with error source
20
21- rtems_exception_frame_print_ - Print the CPU exception frame
22
23- rtems_fatal_source_text_ - Return the falet source text
24
25- rtems_internal_error_text_ - Return the error code text
26
27Background
28==========
29.. index:: fatal error detection
30.. index:: fatal error processing
31.. index:: fatal error user extension
32
33The fatal error manager is called upon detection of an irrecoverable error
34condition by either RTEMS or the application software.  Fatal errors can be
35detected from three sources:
36
37- the executive (RTEMS)
38
39- user system code
40
41- user application code
42
43RTEMS automatically invokes the fatal error manager upon detection of an error
44it considers to be fatal.  Similarly, the user should invoke the fatal error
45manager upon detection of a fatal error.
46
47Each static or dynamic user extension set may include a fatal error handler.
48The fatal error handler in the static extension set can be used to provide
49access to debuggers and monitors which may be present on the target hardware.
50If any user-supplied fatal error handlers are installed, the fatal error
51manager will invoke them.  If no user handlers are configured or if all the
52user handler return control to the fatal error manager, then the RTEMS default
53fatal error handler is invoked.  If the default fatal error handler is invoked,
54then the system state is marked as failed.
55
56Although the precise behavior of the default fatal error handler is processor
57specific, in general, it will disable all maskable interrupts, place the error
58code in a known processor dependent place (generally either on the stack or in
59a register), and halt the processor.  The precise actions of the RTEMS fatal
60error are discussed in the Default Fatal Error Processing chapter of the
61Applications Supplement document for a specific target processor.
62
63Operations
64==========
65
66Announcing a Fatal Error
67------------------------
68.. index:: _Internal_errors_What_happened
69
70The ``rtems_fatal_error_occurred`` directive is invoked when a fatal error is
71detected.  Before invoking any user-supplied fatal error handlers or the RTEMS
72fatal error handler, the ``rtems_fatal_error_occurred`` directive stores useful
73information in the variable ``_Internal_errors_What_happened``.  This structure
74contains three pieces of information:
75
76- the source of the error (API or executive core),
77
78- whether the error was generated internally by the executive, and a
79
80- a numeric code to indicate the error type.
81
82The error type indicator is dependent on the source of the error and whether or
83not the error was internally generated by the executive.  If the error was
84generated from an API, then the error code will be of that API's error or
85status codes.  The status codes for the RTEMS API are in
86cpukit/rtems/include/rtems/rtems/status.h.  Those for the POSIX API can be
87found in <errno.h>.
88
89The ``rtems_fatal_error_occurred`` directive is responsible for invoking an
90optional user-supplied fatal error handler and/or the RTEMS fatal error
91handler.  All fatal error handlers are passed an error code to describe the
92error detected.
93
94Occasionally, an application requires more sophisticated fatal error processing
95such as passing control to a debugger.  For these cases, a user-supplied fatal
96error handler can be specified in the RTEMS configuration table.  The User
97Extension Table field fatal contains the address of the fatal error handler to
98be executed when the ``rtems_fatal_error_occurred`` directive is called.  If
99the field is set to NULL or if the configured fatal error handler returns to
100the executive, then the default handler provided by RTEMS is executed.  This
101default handler will halt execution on the processor where the error occurred.
102
103Directives
104==========
105
106This section details the fatal error manager's directives.  A subsection is
107dedicated to each of this manager's directives and describes the calling
108sequence, related constants, usage, and status codes.
109
110.. _rtems_fatal_error_occurred:
111
112FATAL_ERROR_OCCURRED - Invoke the fatal error handler
113-----------------------------------------------------
114.. index:: announce fatal error
115.. index:: fatal error, announce
116
117**CALLING SEQUENCE:**
118
119.. index:: rtems_fatal_error_occurred
120
121.. code:: c
122
123    void rtems_fatal_error_occurred(
124        uint32_t  the_error
125    );
126
127**DIRECTIVE STATUS CODES**
128
129NONE
130
131**DESCRIPTION:**
132
133This directive processes fatal errors.  If the FATAL error extension is defined
134in the configuration table, then the user-defined error extension is called.
135If configured and the provided FATAL error extension returns, then the RTEMS
136default error handler is invoked.  This directive can be invoked by RTEMS or by
137the user's application code including initialization tasks, other tasks, and
138ISRs.
139
140**NOTES:**
141
142This directive supports local operations only.
143
144Unless the user-defined error extension takes special actions such as
145restarting the calling task, this directive WILL NOT RETURN to the caller.
146
147The user-defined extension for this directive may wish to initiate a global
148shutdown.
149
150.. _rtems_fatal:
151
152FATAL - Invoke the fatal error handler with error source
153--------------------------------------------------------
154.. index:: announce fatal error
155.. index:: fatal error, announce
156
157**CALLING SEQUENCE:**
158
159.. index:: rtems_fatal
160
161.. code:: c
162
163    void rtems_fatal(
164       rtems_fatal_source source,
165       rtems_fatal_code   error
166    );
167
168**DIRECTIVE STATUS CODES**
169
170NONE
171
172**DESCRIPTION:**
173
174This directive invokes the internal error handler with is internal set to
175false.  See also ``rtems_fatal_error_occurred``.
176
177.. _rtems_exception_frame_print:
178
179EXCEPTION_FRAME_PRINT - Prints the exception frame
180--------------------------------------------------
181.. index:: exception frame
182
183**CALLING SEQUENCE:**
184
185.. index:: rtems_exception_frame_print
186
187.. code:: c
188
189    void rtems_exception_frame_print(
190        const rtems_exception_frame *frame
191    );
192
193**DIRECTIVE STATUS CODES**
194
195NONE
196
197**DESCRIPTION:**
198
199Prints the exception frame via ``printk()``.
200
201.. _rtems_fatal_source_text:
202
203FATAL_SOURCE_TEXT - Returns a text for a fatal source
204-----------------------------------------------------
205.. index:: fatal error
206
207**CALLING SEQUENCE:**
208
209.. index:: rtems_fatal_source_text
210
211.. code:: c
212
213    const char *rtems_fatal_source_text(
214        rtems_fatal_source source
215    );
216
217**DIRECTIVE STATUS CODES**
218
219The fatal source text or "?" in case the passed fatal source is invalid.
220
221**DESCRIPTION:**
222
223Returns a text for a fatal source.  The text for fatal source is the enumerator
224constant.
225
226.. _rtems_internal_error_text:
227
228INTERNAL_ERROR_TEXT - Returns a text for an internal error code
229---------------------------------------------------------------
230.. index:: fatal error
231
232**CALLING SEQUENCE:**
233
234.. index:: rtems_internal_error_text
235
236.. code:: c
237
238    const char *rtems_internal_error_text(
239        rtems_fatal_code error
240    );
241
242**DIRECTIVE STATUS CODES**
243
244The error code text or "?" in case the passed error code is invalid.
245
246**DESCRIPTION:**
247
248Returns a text for an internal error code.  The text for each internal error
249code is the enumerator constant.
Note: See TracBrowser for help on using the repository browser.