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