1 /*
2 * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include <cstdlib>
7 #include <cstdio>
8 #include <exception>
9 #include <bits/functexcept.h>
10 #include <sdkconfig.h>
11
12 #ifndef CONFIG_COMPILER_CXX_EXCEPTIONS
13
abort_expect_void(const void * context)14 extern "C" void abort_expect_void(const void *context)
15 {
16 abort();
17 }
18
abort_expect_void_and_return(const void * context)19 extern "C" void *abort_expect_void_and_return(const void *context)
20 {
21 abort();
22 return nullptr;
23 }
24
forward_abort_uw_ctx(struct _Unwind_Context * context)25 extern "C" void *forward_abort_uw_ctx(struct _Unwind_Context *context)
26 {
27 return abort_expect_void_and_return((void*) context);
28 }
29
30 template<typename T>
abort_return()31 static T abort_return()
32 {
33 abort();
34 return static_cast<T>(0);
35 }
36
37 // unwind-dw2-fde.o
__wrap__Unwind_SetEnableExceptionFdeSorting(unsigned char enable)38 extern "C" void __wrap__Unwind_SetEnableExceptionFdeSorting(unsigned char enable)
39 {
40 abort();
41 }
42
__wrap___register_frame_info_bases(const void * begin,struct object * ob,void * tbase,void * dbase)43 extern "C" void __wrap___register_frame_info_bases (const void *begin, struct object *ob, void *tbase, void *dbase)
44 {
45 abort();
46 }
47
__wrap___register_frame_info(const void * begin,struct object * ob)48 extern "C" void __wrap___register_frame_info (const void *begin, struct object *ob)
49 {
50 abort();
51 }
52
__wrap___register_frame_info_table_bases(void * begin,struct object * ob,void * tbase,void * dbase)53 extern "C" void __wrap___register_frame_info_table_bases (void *begin, struct object *ob, void *tbase, void *dbase)
54 {
55 abort();
56 }
57
__wrap___register_frame_info_table(void * begin,struct object * ob)58 extern "C" void __wrap___register_frame_info_table (void *begin, struct object *ob)
59 {
60 abort();
61 }
62
63
64 extern "C" void __wrap___register_frame (void *begin)
65 __attribute__((alias("abort_expect_void")));
66
67 extern "C" void __wrap___register_frame_table (void *begin)
68 __attribute__((alias("abort_expect_void")));
69
70 extern "C" void *__wrap___deregister_frame_info_bases (const void *begin)
71 __attribute__((alias("abort_expect_void_and_return")));
72
73 extern "C" void *__wrap___deregister_frame_info (const void *begin)
74 __attribute__((alias("abort_expect_void_and_return")));
75
76 extern "C" void __wrap___deregister_frame (void *begin)
77 __attribute__((alias("abort_expect_void")));
78
79 typedef void* fde;
80
__wrap__Unwind_Find_FDE(void * pc,struct dwarf_eh_bases * bases)81 extern "C" const fde * __wrap__Unwind_Find_FDE (void *pc, struct dwarf_eh_bases *bases)
82 {
83 return abort_return<fde*>();
84 }
85
86 // unwind-dw2.o (riscv), unwind-dw2-xtensa.o (xtensa)
87 typedef void* _Unwind_Ptr;
88 typedef int _Unwind_Word;
89
__wrap__Unwind_GetGR(struct _Unwind_Context * context,int index)90 extern "C" _Unwind_Word __wrap__Unwind_GetGR (struct _Unwind_Context *context, int index)
91 {
92 return abort_return<_Unwind_Word>();
93 }
94
__wrap__Unwind_GetCFA(struct _Unwind_Context * context)95 extern "C" _Unwind_Word __wrap__Unwind_GetCFA (struct _Unwind_Context *context)
96 {
97 return abort_return<_Unwind_Word>();
98 }
99
__wrap__Unwind_SetIP(struct _Unwind_Context * context,_Unwind_Ptr val)100 extern "C" void __wrap__Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
101 {
102 abort();
103 }
104
__wrap__Unwind_SetGR(struct _Unwind_Context * context,int index,_Unwind_Word val)105 extern "C" void __wrap__Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
106 {
107 abort();
108 }
109
__wrap__Unwind_GetIPInfo(struct _Unwind_Context * context,int * ip_before_insn)110 extern "C" _Unwind_Ptr __wrap__Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
111 {
112 return abort_return<_Unwind_Ptr>();
113 }
114
115 extern "C" _Unwind_Ptr __wrap__Unwind_GetIP (struct _Unwind_Context *context)
116 __attribute__((alias("forward_abort_uw_ctx")));
117
118 extern "C" _Unwind_Ptr __wrap__Unwind_GetRegionStart (struct _Unwind_Context *context)
119 __attribute__((alias("forward_abort_uw_ctx")));
120
121 extern "C" _Unwind_Ptr __wrap__Unwind_GetDataRelBase (struct _Unwind_Context *context)
122 __attribute__((alias("forward_abort_uw_ctx")));
123
124 extern "C" _Unwind_Ptr __wrap__Unwind_GetTextRelBase (struct _Unwind_Context *context)
125 __attribute__((alias("forward_abort_uw_ctx")));
126
127 extern "C" void *__wrap__Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
128 __attribute__((alias("forward_abort_uw_ctx")));
129
130 extern "C" void *__wrap__Unwind_FindEnclosingFunction (void *pc)
131 __attribute__((alias("abort_expect_void_and_return")));
132
__frame_state_for(void * pc_target,struct frame_state * state_in)133 struct frame_state *__frame_state_for (void *pc_target, struct frame_state *state_in)
134 {
135 return abort_return<struct frame_state *>();
136 }
137
138 // unwind.inc
139 typedef int _Unwind_Reason_Code;
140 typedef int _Unwind_Action;
141 typedef int _Unwind_Exception_Class;
142 typedef int* _Unwind_Trace_Fn;
143 typedef int* _Unwind_Stop_Fn;
144
__wrap__Unwind_Resume(struct _Unwind_Exception * exc)145 extern "C" void __wrap__Unwind_Resume (struct _Unwind_Exception *exc)
146 {
147 abort();
148 }
149
__wrap__Unwind_DeleteException(struct _Unwind_Exception * exc)150 extern "C" void __wrap__Unwind_DeleteException (struct _Unwind_Exception *exc)
151 {
152 abort();
153 }
154
155
__wrap__Unwind_RaiseException(struct _Unwind_Exception * exc)156 extern "C" _Unwind_Reason_Code __wrap__Unwind_RaiseException(struct _Unwind_Exception *exc)
157 {
158 return abort_return<_Unwind_Reason_Code>();
159 }
160
161 extern "C" _Unwind_Reason_Code __wrap__Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc)
162 __attribute__((alias("__wrap__Unwind_RaiseException")));
163
__wrap__Unwind_ForcedUnwind(struct _Unwind_Exception * exc,_Unwind_Stop_Fn stop,void * stop_argument)164 extern "C" _Unwind_Reason_Code __wrap__Unwind_ForcedUnwind (struct _Unwind_Exception *exc,
165 _Unwind_Stop_Fn stop, void * stop_argument)
166 {
167 return abort_return<_Unwind_Reason_Code>();
168 }
169
__wrap__Unwind_Backtrace(_Unwind_Trace_Fn trace,void * trace_argument)170 extern "C" _Unwind_Reason_Code __wrap__Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument)
171 {
172 return abort_return<_Unwind_Reason_Code>();
173 }
174
175 // eh_personality.o
176 extern "C" void __wrap___cxa_call_unexpected (void *exc_obj_in)
177 __attribute__((alias("abort_expect_void")));
178
__wrap___gxx_personality_v0(int version,_Unwind_Action actions,_Unwind_Exception_Class exception_class,struct _Unwind_Exception * ue_header,struct _Unwind_Context * context)179 extern "C" _Unwind_Reason_Code __wrap___gxx_personality_v0 (int version,
180 _Unwind_Action actions,
181 _Unwind_Exception_Class exception_class,
182 struct _Unwind_Exception *ue_header,
183 struct _Unwind_Context *context)
184 {
185 return abort_return<_Unwind_Reason_Code>();
186 }
187
188 #endif // CONFIG_COMPILER_CXX_EXCEPTIONS
189