libnx  v4.8.0
fatal.h
Go to the documentation of this file.
1 /**
2  * @file fatal.h
3  * @brief Fatal error (fatal:u) service IPC wrapper.
4  * @author plutoo
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 
10 /// Type of thrown fatal error.
11 typedef enum {
12  FatalPolicy_ErrorReportAndErrorScreen = 0,
13  FatalPolicy_ErrorReport = 1,
14  FatalPolicy_ErrorScreen = 2 ///< Only available with [3.0.0+]. If specified, FatalPolicy_ErrorReportAndErrorScreen will be used instead on pre-3.0.0.
16 
17 /// Struct for fatal Cpu context, 64-bit.
18 typedef struct {
19  union {
20  u64 x[32];
21  struct {
22  u64 _x[29];
23  u64 fp;
24  u64 lr;
25  u64 sp;
26  u64 pc;
27  };
28  };
29  u64 pstate;
30  u64 afsr0;
31  u64 afsr1;
32  u64 esr;
33  u64 far;
34 
35  u64 stack_trace[32];
36  u64 start_address; ///< Address of first NSO loaded (generally, process entrypoint).
37  u64 register_set_flags; ///< Bitmask, bit i indicates GPR i has a value.
38  u32 stack_trace_size;
40 
41 /// Struct for fatal Cpu context, 32-bit.
42 typedef struct {
43  union {
44  u32 r[16];
45  struct {
46  u32 _r[11];
47  u32 fp;
48  u32 ip;
49  u32 sp;
50  u32 lr;
51  u32 pc;
52  };
53  };
54  u32 pstate;
55  u32 afsr0;
56  u32 afsr1;
57  u32 esr;
58  u32 far;
59 
60  u32 stack_trace[32];
61  u32 stack_trace_size;
62  u32 start_address; ///< Address of first NSO loaded (generally, process entrypoint).
63  u32 register_set_flags; ///< Bitmask, bit i indicates GPR i has a value.
65 
66 typedef struct {
67  union {
68  FatalAarch64Context aarch64_ctx;
69  FatalAarch32Context aarch32_ctx;
70  };
71 
72  bool is_aarch32;
73  u32 type;
75 
76 /**
77  * @brief Triggers a system fatal error.
78  * @param[in] err Result code to throw.
79  * @note This function does not return.
80  * @note This uses \ref fatalThrowWithPolicy with \ref FatalPolicy_ErrorScreen internally.
81  */
83 
84 /**
85  * @brief Triggers a system fatal error with a custom \ref FatalPolicy.
86  * @param[in] err Result code to throw.
87  * @param[in] type Type of fatal error to throw.
88  * @note This function may not return, depending on \ref FatalPolicy.
89  */
91 
92 /**
93  * @brief Triggers a system fatal error with a custom \ref FatalPolicy and \ref FatalCpuContext.
94  * @param[in] err Result code to throw.
95  * @param[in] type Type of fatal error to throw.
96  * @param[in] ctx Cpu context for fatal error to throw.
97  * @note This function may not return, depending on \ref FatalPolicy.
98  */
void fatalThrow(Result err)
Triggers a system fatal error.
FatalPolicy
Type of thrown fatal error.
Definition: fatal.h:11
@ FatalPolicy_ErrorScreen
Only available with [3.0.0+]. If specified, FatalPolicy_ErrorReportAndErrorScreen will be used instea...
Definition: fatal.h:14
void fatalThrowWithPolicy(Result err, FatalPolicy type)
Triggers a system fatal error with a custom FatalPolicy.
void fatalThrowWithContext(Result err, FatalPolicy type, FatalCpuContext *ctx)
Triggers a system fatal error with a custom FatalPolicy and FatalCpuContext.
Struct for fatal Cpu context, 32-bit.
Definition: fatal.h:42
u32 start_address
Address of first NSO loaded (generally, process entrypoint).
Definition: fatal.h:62
u32 register_set_flags
Bitmask, bit i indicates GPR i has a value.
Definition: fatal.h:63
Struct for fatal Cpu context, 64-bit.
Definition: fatal.h:18
u64 register_set_flags
Bitmask, bit i indicates GPR i has a value.
Definition: fatal.h:37
u64 start_address
Address of first NSO loaded (generally, process entrypoint).
Definition: fatal.h:36
Definition: fatal.h:66
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
u32 Result
Function error code result type.
Definition: types.h:44
#define NX_NORETURN
Marks a function as not returning, for the purposes of compiler optimization.
Definition: types.h:68
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21