source: mainline/uspace/lib/cpp/src/__bits/unwind.cpp@ 7dcce0a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7dcce0a was 7dcce0a, checked in by jxsvoboda <5887334+jxsvoboda@…>, 6 years ago

cpp: abort and report when an unimplemented function is called

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Copyright (c) 2019 Jaroslav Jindrak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <cassert>
30#include <cstdint>
31#include <cstdlib>
32
33namespace __cxxabiv1
34{
35 /**
36 * Stack unwinding functionality - Level 1.
37 */
38
39 enum _Unwind_Reason_Code
40 {
41 _URC_NO_REASON = 0,
42 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
43 _URC_FATAL_PHASE2_ERROR = 2,
44 _URC_FATAL_PHASE1_ERROR = 3,
45 _URC_NORMAL_STOP = 4,
46 _URC_END_OF_STACK = 5,
47 _URC_HANDLER_FOUND = 6,
48 _URC_INSTALL_CONTEXT = 7,
49 _URC_CONTINUE_UNWIND = 8
50 };
51
52 struct _Unwind_Exception;
53 using _Unwind_Exception_Cleanup_Fn = void (*)(_Unwind_Reason_Code, _Unwind_Exception*);
54
55 struct _Unwind_Exception
56 {
57 std::uint64_t exception_class;
58 _Unwind_Exception_Cleanup_Fn exception_cleanup;
59 std::uint64_t private_1;
60 std::uint64_t private_2;
61 };
62
63 /* Opaque structure. */
64 struct _Unwind_Context;
65
66 using _Unwind_Action = int;
67 namespace
68 {
69 const _Unwind_Action _UA_SEARCH_PHASE = 1;
70 const _Unwind_Action _UA_CLEANUP_PHASE = 2;
71 const _Unwind_Action _UA_HANDLER_FRAME = 4;
72 const _Unwind_Action _UA_FORCE_HANDLER = 8;
73 }
74
75 /**
76 * TODO: Explain parameter semantics.
77 */
78 using _Unwind_Stop_Fn = _Unwind_Reason_Code(*)(
79 int, _Unwind_Action, std::uint64_t, _Unwind_Exception*,
80 _Unwind_Context*, void*
81 );
82
83 extern "C" _Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception*, _Unwind_Stop_Fn, void*)
84 {
85 // TODO: implement
86 return _URC_NO_REASON;
87 }
88
89 extern "C" void _Unwind_Resume(_Unwind_Exception*)
90 {
91 // TODO: implement
92 }
93
94 extern "C" void _Unwind_DeleteException(_Unwind_Exception*)
95 {
96 // TODO: implement
97 }
98
99 extern "C" std::uint64_t _Unwind_GetGR(_Unwind_Context*, int)
100 {
101 // TODO: implement
102 return 0;
103 }
104
105 extern "C" void _Unwind_SetGR(_Unwind_Context*, int, std::uint64_t)
106 {
107 // TODO: implement
108 }
109
110 extern "C" std::uint64_t _Unwind_GetIP(_Unwind_Context*)
111 {
112 // TODO: implement
113 return 0;
114 }
115
116 extern "C" void _Unwind_SetIP(_Unwind_Context*, std::uint64_t)
117 {
118 // TODO: implement
119 }
120
121 extern "C" std::uint64_t _Unwind_GetLanguageSpecificData(_Unwind_Context*)
122 {
123 // TODO: implement
124 return 0;
125 }
126
127 extern "C" std::uint64_t _Unwind_GetRegionStart(_Unwind_Context*)
128 {
129 // TODO: implement
130 return 0;
131 }
132
133 /**
134 * TODO: Explain parameter semantics.
135 */
136 using __personality_routine = _Unwind_Reason_Code(*)(
137 int, _Unwind_Action, std::uint64_t, _Unwind_Exception*,
138 _Unwind_Context*, void*
139 );
140
141 /**
142 * Stack unwinding functionality - Level 2.
143 */
144 struct __cxa_exception
145 {
146 std::type_info* exceptionType;
147 void (*exceptionDestructor)(void*);
148 // TODO: Add handler types to <exception>.
149 /* std::unexpected_handler unexpectedHandler; */
150 void (*unexpectedHandler)();
151 /* std::terminate_handler terminateHandler; */
152 void (*terminateHandler)();
153 __cxa_exception* nextException;
154
155 int handlerCount;
156 int handlerSwitchValue;
157 const char* actionRecord;
158 const char* languageSpecificData;
159 void* catchTemp;
160 void* adjujstedPtr;
161
162 _Unwind_Exception unwindHeader;
163 };
164
165 struct __cxa_eh_globals
166 {
167 __cxa_exception* caughtExceptions;
168 unsigned int uncaughtExceptions;
169 };
170
171 extern "C" __cxa_eh_globals* __cxa_get_globals();
172
173 extern "C" __cxa_eh_globals* __cxa_get_globals_fast();
174
175 extern "C" void* __cxa_allocate_exception(std::size_t thrown_size)
176 {
177 // TODO: implement
178 __unimplemented();
179 return nullptr;
180 }
181
182 extern "C" void __cxa_free_exception(void* thrown_exception)
183 {
184 // TODO: implement
185 __unimplemented();
186 }
187
188 extern "C" void __cxa_throw(void* thrown_exception, std::type_info* tinfo, void (*dest)(void*))
189 {
190 // TODO: implement
191 __unimplemented();
192 }
193
194 extern "C" void* __cxa_get_exception_ptr(void* exception_object)
195 {
196 // TODO: implement
197 __unimplemented();
198 return nullptr;
199 }
200
201 extern "C" void* __cxa_begin_catch(void* exception_object)
202 {
203 // TODO: implement
204 __unimplemented();
205 return nullptr;
206 }
207
208 extern "C" void __cxa_end_catch()
209 {
210 // TODO: implement
211 __unimplemented();
212 }
213
214 extern "C" void __cxa_rethrow()
215 {
216 // TODO: implement
217 __unimplemented();
218 }
219
220 extern "C" void __cxa_bad_cast()
221 {
222 // TODO: implement
223 __unimplemented();
224 }
225
226 extern "C" void __cxa_bad_typeid()
227 {
228 // TODO: implement
229 __unimplemented();
230 }
231
232 extern "C" void __cxa_throw_bad_array_new_length()
233 {
234 // TODO: implement
235 __unimplemented();
236 }
237
238 extern "C" _Unwind_Reason_Code __gxx_personality_v0(
239 int, _Unwind_Action, unsigned,
240 struct _Unwind_Exception*, struct _Unwind_Context*
241 )
242 {
243 // TODO: implement
244 __unimplemented();
245 return _URC_NO_REASON;
246 }
247}
Note: See TracBrowser for help on using the repository browser.