libctru  v2.3.1
errf.h
Go to the documentation of this file.
1 /**
2  * @file errf.h
3  * @brief Error Display API
4  */
5 
6 #pragma once
7 
8 #include <3ds/types.h>
9 
10 /// Types of errors that can be thrown by err:f.
11 typedef enum {
12  ERRF_ERRTYPE_GENERIC = 0, ///< Generic fatal error. Shows miscellaneous info, including the address of the caller
13  ERRF_ERRTYPE_NAND_DAMAGED = 1, ///< Damaged NAND (CC_ERROR after reading CSR)
14  ERRF_ERRTYPE_CARD_REMOVED = 2, ///< Game content storage medium (cartridge and/or SD card) ejected. Not logged
15  ERRF_ERRTYPE_EXCEPTION = 3, ///< CPU or VFP exception
16  ERRF_ERRTYPE_FAILURE = 4, ///< Fatal error with a message instead of the caller's address
17  ERRF_ERRTYPE_LOG_ONLY = 5, ///< Log-level failure. Does not display the exception and does not force the system to reboot
18 } ERRF_ErrType;
19 
20 /// Types of 'Exceptions' thrown for ERRF_ERRTYPE_EXCEPTION
21 typedef enum {
22  ERRF_EXCEPTION_PREFETCH_ABORT = 0, ///< Prefetch Abort
23  ERRF_EXCEPTION_DATA_ABORT = 1, ///< Data abort
24  ERRF_EXCEPTION_UNDEFINED = 2, ///< Undefined instruction
25  ERRF_EXCEPTION_VFP = 3, ///< VFP (floating point) exception.
27 
28 typedef struct {
29  ERRF_ExceptionType type; ///< Type of the exception. One of the ERRF_EXCEPTION_* values.
30  u8 reserved[3];
31  u32 fsr; ///< ifsr (prefetch abort) / dfsr (data abort)
32  u32 far; ///< pc = ifar (prefetch abort) / dfar (data abort)
33  u32 fpexc;
34  u32 fpinst;
35  u32 fpinst2;
37 
38 typedef struct {
39  ERRF_ExceptionInfo excep; ///< Exception info struct
40  CpuRegisters regs; ///< CPU register dump.
42 
43 typedef struct {
44  ERRF_ErrType type; ///< Type, one of the ERRF_ERRTYPE_* enum
45  u8 revHigh; ///< High revison ID
46  u16 revLow; ///< Low revision ID
47  u32 resCode; ///< Result code
48  u32 pcAddr; ///< PC address at exception
49  u32 procId; ///< Process ID of the caller
50  u64 titleId; ///< Title ID of the caller
51  u64 appTitleId; ///< Title ID of the running application
52  union {
53  ERRF_ExceptionData exception_data; ///< Data for when type is ERRF_ERRTYPE_EXCEPTION
54  char failure_mesg[0x60]; ///< String for when type is ERRF_ERRTYPE_FAILURE
55  } data; ///< The different types of data for errors.
57 
58 /// Initializes ERR:f. Unless you plan to call ERRF_Throw yourself, do not use this.
60 
61 /// Exits ERR:f. Unless you plan to call ERRF_Throw yourself, do not use this.
62 void errfExit(void);
63 
64 /**
65  * @brief Gets the current err:f API session handle.
66  * @return The current err:f API session handle.
67  */
69 
70 /**
71  * @brief Throws a system error and possibly logs it.
72  * @param[in] error Error to throw.
73  *
74  * ErrDisp may convert the error info to \ref ERRF_ERRTYPE_NAND_DAMAGED or \ref ERRF_ERRTYPE_CARD_REMOVED
75  * depending on the error code.
76  *
77  * Except with \ref ERRF_ERRTYPE_LOG_ONLY, the system will panic and will need to be rebooted.
78  * Fatal error information will also be logged into a file, unless the type either \ref ERRF_ERRTYPE_NAND_DAMAGED
79  * or \ref ERRF_ERRTYPE_CARD_REMOVED.
80  *
81  * No error will be shown if the system is asleep.
82  *
83  * On retail units with vanilla firmware, no detailed information will be displayed on screen.
84  *
85  * You may wish to use ERRF_ThrowResult() or ERRF_ThrowResultWithMessage() instead of
86  * constructing the ERRF_FatalErrInfo struct yourself.
87  */
89 
90 /**
91  * @brief Throws (and logs) a system error with the given Result code.
92  * @param[in] failure Result code to throw.
93  *
94  * This calls \ref ERRF_Throw with error type \ref ERRF_ERRTYPE_GENERIC and fills in the required data.
95  *
96  * This function \em does fill in the address where this function was called from.
97  */
99 
100 /**
101  * @brief Logs a system error with the given Result code.
102  * @param[in] failure Result code to log.
103  *
104  * Similar to \ref ERRF_Throw, except that it does not display anything on the screen,
105  * nor does it force the system to reboot.
106  *
107  * This function \em does fill in the address where this function was called from.
108  */
110 
111 /**
112  * @brief Throws a system error with the given Result code and message.
113  * @param[in] failure Result code to throw.
114  * @param[in] message The message to display.
115  *
116  * This calls \ref ERRF_Throw with error type \ref ERRF_ERRTYPE_FAILURE and fills in the required data.
117  *
118  * This function does \em not fill in the address where this function was called from because it
119  * would not be displayed.
120  */
121 Result ERRF_ThrowResultWithMessage(Result failure, const char* message);
122 
123 /**
124  * @brief Specify an additional user string to use for error reporting.
125  * @param[in] user_string User string (up to 256 bytes, not including NUL byte)
126  */
127 Result ERRF_SetUserString(const char* user_string);
128 
129 /**
130  * @brief Handles an exception using ErrDisp.
131  * @param excep Exception information
132  * @param regs CPU registers
133  *
134  * You might want to clear ENVINFO's bit0 to be able to see any debugging information.
135  * @sa threadOnException
136  */
Result ERRF_ThrowResult(Result failure)
Throws (and logs) a system error with the given Result code.
Result ERRF_SetUserString(const char *user_string)
Specify an additional user string to use for error reporting.
void ERRF_ExceptionHandler(ERRF_ExceptionInfo *excep, CpuRegisters *regs) __attribute__((noreturn))
Handles an exception using ErrDisp.
ERRF_ErrType
Types of errors that can be thrown by err:f.
Definition: errf.h:11
@ ERRF_ERRTYPE_LOG_ONLY
Log-level failure. Does not display the exception and does not force the system to reboot.
Definition: errf.h:17
@ ERRF_ERRTYPE_CARD_REMOVED
Game content storage medium (cartridge and/or SD card) ejected. Not logged.
Definition: errf.h:14
@ ERRF_ERRTYPE_EXCEPTION
CPU or VFP exception.
Definition: errf.h:15
@ ERRF_ERRTYPE_GENERIC
Generic fatal error. Shows miscellaneous info, including the address of the caller.
Definition: errf.h:12
@ ERRF_ERRTYPE_NAND_DAMAGED
Damaged NAND (CC_ERROR after reading CSR)
Definition: errf.h:13
@ ERRF_ERRTYPE_FAILURE
Fatal error with a message instead of the caller's address.
Definition: errf.h:16
void errfExit(void)
Exits ERR:f. Unless you plan to call ERRF_Throw yourself, do not use this.
Result ERRF_ThrowResultWithMessage(Result failure, const char *message)
Throws a system error with the given Result code and message.
Result ERRF_LogResult(Result failure)
Logs a system error with the given Result code.
Handle * errfGetSessionHandle(void)
Gets the current err:f API session handle.
ERRF_ExceptionType
Types of 'Exceptions' thrown for ERRF_ERRTYPE_EXCEPTION.
Definition: errf.h:21
@ ERRF_EXCEPTION_UNDEFINED
Undefined instruction.
Definition: errf.h:24
@ ERRF_EXCEPTION_PREFETCH_ABORT
Prefetch Abort.
Definition: errf.h:22
@ ERRF_EXCEPTION_DATA_ABORT
Data abort.
Definition: errf.h:23
@ ERRF_EXCEPTION_VFP
VFP (floating point) exception.
Definition: errf.h:25
Result ERRF_Throw(const ERRF_FatalErrInfo *error)
Throws a system error and possibly logs it.
Result errfInit(void)
Initializes ERR:f. Unless you plan to call ERRF_Throw yourself, do not use this.
__attribute__((warn_unused_result)) rbtree_node_t *rbtree_insert(rbtree_t *tree
Inserts a node into an rbtree.
Structure representing CPU registers.
Definition: types.h:63
Definition: errf.h:38
CpuRegisters regs
CPU register dump.
Definition: errf.h:40
ERRF_ExceptionInfo excep
Exception info struct.
Definition: errf.h:39
Definition: errf.h:28
ERRF_ExceptionType type
Type of the exception. One of the ERRF_EXCEPTION_* values.
Definition: errf.h:29
u32 fsr
ifsr (prefetch abort) / dfsr (data abort)
Definition: errf.h:31
u32 far
pc = ifar (prefetch abort) / dfar (data abort)
Definition: errf.h:32
Definition: errf.h:43
u32 resCode
Result code.
Definition: errf.h:47
u8 revHigh
High revison ID.
Definition: errf.h:45
u64 appTitleId
Title ID of the running application.
Definition: errf.h:51
u16 revLow
Low revision ID.
Definition: errf.h:46
ERRF_ErrType type
Type, one of the ERRF_ERRTYPE_* enum.
Definition: errf.h:44
u32 pcAddr
PC address at exception.
Definition: errf.h:48
u32 procId
Process ID of the caller.
Definition: errf.h:49
ERRF_ExceptionData exception_data
Data for when type is ERRF_ERRTYPE_EXCEPTION.
Definition: errf.h:53
u64 titleId
Title ID of the caller.
Definition: errf.h:50
Various system types.
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
u32 Handle
Resource handle.
Definition: types.h:41
s32 Result
Function result.
Definition: types.h:42
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
uint32_t u32
32-bit unsigned integer
Definition: types.h:23