| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2019 Jaroslav Jindrak
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #include <cassert>
|
|---|
| 8 | #include <cstdint>
|
|---|
| 9 | #include <cstdlib>
|
|---|
| 10 |
|
|---|
| 11 | namespace __cxxabiv1
|
|---|
| 12 | {
|
|---|
| 13 | /**
|
|---|
| 14 | * Stack unwinding functionality - Level 1.
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | enum _Unwind_Reason_Code
|
|---|
| 18 | {
|
|---|
| 19 | _URC_NO_REASON = 0,
|
|---|
| 20 | _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
|
|---|
| 21 | _URC_FATAL_PHASE2_ERROR = 2,
|
|---|
| 22 | _URC_FATAL_PHASE1_ERROR = 3,
|
|---|
| 23 | _URC_NORMAL_STOP = 4,
|
|---|
| 24 | _URC_END_OF_STACK = 5,
|
|---|
| 25 | _URC_HANDLER_FOUND = 6,
|
|---|
| 26 | _URC_INSTALL_CONTEXT = 7,
|
|---|
| 27 | _URC_CONTINUE_UNWIND = 8
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| 30 | struct _Unwind_Exception;
|
|---|
| 31 | using _Unwind_Exception_Cleanup_Fn = void (*)(_Unwind_Reason_Code, _Unwind_Exception*);
|
|---|
| 32 |
|
|---|
| 33 | struct _Unwind_Exception
|
|---|
| 34 | {
|
|---|
| 35 | std::uint64_t exception_class;
|
|---|
| 36 | _Unwind_Exception_Cleanup_Fn exception_cleanup;
|
|---|
| 37 | std::uint64_t private_1;
|
|---|
| 38 | std::uint64_t private_2;
|
|---|
| 39 | };
|
|---|
| 40 |
|
|---|
| 41 | /* Opaque structure. */
|
|---|
| 42 | struct _Unwind_Context;
|
|---|
| 43 |
|
|---|
| 44 | using _Unwind_Action = int;
|
|---|
| 45 | namespace
|
|---|
| 46 | {
|
|---|
| 47 | const _Unwind_Action _UA_SEARCH_PHASE = 1;
|
|---|
| 48 | const _Unwind_Action _UA_CLEANUP_PHASE = 2;
|
|---|
| 49 | const _Unwind_Action _UA_HANDLER_FRAME = 4;
|
|---|
| 50 | const _Unwind_Action _UA_FORCE_HANDLER = 8;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | /**
|
|---|
| 54 | * TODO: Explain parameter semantics.
|
|---|
| 55 | */
|
|---|
| 56 | using _Unwind_Stop_Fn = _Unwind_Reason_Code(*)(
|
|---|
| 57 | int, _Unwind_Action, std::uint64_t, _Unwind_Exception*,
|
|---|
| 58 | _Unwind_Context*, void*
|
|---|
| 59 | );
|
|---|
| 60 |
|
|---|
| 61 | extern "C" _Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception*, _Unwind_Stop_Fn, void*)
|
|---|
| 62 | {
|
|---|
| 63 | // TODO: implement
|
|---|
| 64 | return _URC_NO_REASON;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | extern "C" void _Unwind_Resume(_Unwind_Exception*)
|
|---|
| 68 | {
|
|---|
| 69 | // TODO: implement
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | extern "C" void _Unwind_DeleteException(_Unwind_Exception*)
|
|---|
| 73 | {
|
|---|
| 74 | // TODO: implement
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | extern "C" std::uint64_t _Unwind_GetGR(_Unwind_Context*, int)
|
|---|
| 78 | {
|
|---|
| 79 | // TODO: implement
|
|---|
| 80 | return 0;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | extern "C" void _Unwind_SetGR(_Unwind_Context*, int, std::uint64_t)
|
|---|
| 84 | {
|
|---|
| 85 | // TODO: implement
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | extern "C" std::uint64_t _Unwind_GetIP(_Unwind_Context*)
|
|---|
| 89 | {
|
|---|
| 90 | // TODO: implement
|
|---|
| 91 | return 0;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | extern "C" void _Unwind_SetIP(_Unwind_Context*, std::uint64_t)
|
|---|
| 95 | {
|
|---|
| 96 | // TODO: implement
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | extern "C" std::uint64_t _Unwind_GetLanguageSpecificData(_Unwind_Context*)
|
|---|
| 100 | {
|
|---|
| 101 | // TODO: implement
|
|---|
| 102 | return 0;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | extern "C" std::uint64_t _Unwind_GetRegionStart(_Unwind_Context*)
|
|---|
| 106 | {
|
|---|
| 107 | // TODO: implement
|
|---|
| 108 | return 0;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | /**
|
|---|
| 112 | * TODO: Explain parameter semantics.
|
|---|
| 113 | */
|
|---|
| 114 | using __personality_routine = _Unwind_Reason_Code(*)(
|
|---|
| 115 | int, _Unwind_Action, std::uint64_t, _Unwind_Exception*,
|
|---|
| 116 | _Unwind_Context*, void*
|
|---|
| 117 | );
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * Stack unwinding functionality - Level 2.
|
|---|
| 121 | */
|
|---|
| 122 | struct __cxa_exception
|
|---|
| 123 | {
|
|---|
| 124 | std::type_info* exceptionType;
|
|---|
| 125 | void (*exceptionDestructor)(void*);
|
|---|
| 126 | // TODO: Add handler types to <exception>.
|
|---|
| 127 | /* std::unexpected_handler unexpectedHandler; */
|
|---|
| 128 | void (*unexpectedHandler)();
|
|---|
| 129 | /* std::terminate_handler terminateHandler; */
|
|---|
| 130 | void (*terminateHandler)();
|
|---|
| 131 | __cxa_exception* nextException;
|
|---|
| 132 |
|
|---|
| 133 | int handlerCount;
|
|---|
| 134 | int handlerSwitchValue;
|
|---|
| 135 | const char* actionRecord;
|
|---|
| 136 | const char* languageSpecificData;
|
|---|
| 137 | void* catchTemp;
|
|---|
| 138 | void* adjujstedPtr;
|
|---|
| 139 |
|
|---|
| 140 | _Unwind_Exception unwindHeader;
|
|---|
| 141 | };
|
|---|
| 142 |
|
|---|
| 143 | struct __cxa_eh_globals
|
|---|
| 144 | {
|
|---|
| 145 | __cxa_exception* caughtExceptions;
|
|---|
| 146 | unsigned int uncaughtExceptions;
|
|---|
| 147 | };
|
|---|
| 148 |
|
|---|
| 149 | extern "C" __cxa_eh_globals* __cxa_get_globals();
|
|---|
| 150 |
|
|---|
| 151 | extern "C" __cxa_eh_globals* __cxa_get_globals_fast();
|
|---|
| 152 |
|
|---|
| 153 | extern "C" void* __cxa_allocate_exception(std::size_t thrown_size)
|
|---|
| 154 | {
|
|---|
| 155 | // TODO: implement
|
|---|
| 156 | __unimplemented();
|
|---|
| 157 | return nullptr;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | extern "C" void __cxa_free_exception(void* thrown_exception)
|
|---|
| 161 | {
|
|---|
| 162 | // TODO: implement
|
|---|
| 163 | __unimplemented();
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | extern "C" void __cxa_throw(void* thrown_exception, std::type_info* tinfo, void (*dest)(void*))
|
|---|
| 167 | {
|
|---|
| 168 | // TODO: implement
|
|---|
| 169 | __unimplemented();
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | extern "C" void* __cxa_get_exception_ptr(void* exception_object)
|
|---|
| 173 | {
|
|---|
| 174 | // TODO: implement
|
|---|
| 175 | __unimplemented();
|
|---|
| 176 | return nullptr;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | extern "C" void* __cxa_begin_catch(void* exception_object)
|
|---|
| 180 | {
|
|---|
| 181 | // TODO: implement
|
|---|
| 182 | __unimplemented();
|
|---|
| 183 | return nullptr;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | extern "C" void __cxa_end_catch()
|
|---|
| 187 | {
|
|---|
| 188 | // TODO: implement
|
|---|
| 189 | __unimplemented();
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | extern "C" void __cxa_rethrow()
|
|---|
| 193 | {
|
|---|
| 194 | // TODO: implement
|
|---|
| 195 | __unimplemented();
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | extern "C" void __cxa_bad_cast()
|
|---|
| 199 | {
|
|---|
| 200 | // TODO: implement
|
|---|
| 201 | __unimplemented();
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | extern "C" void __cxa_bad_typeid()
|
|---|
| 205 | {
|
|---|
| 206 | // TODO: implement
|
|---|
| 207 | __unimplemented();
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | extern "C" void __cxa_throw_bad_array_new_length()
|
|---|
| 211 | {
|
|---|
| 212 | // TODO: implement
|
|---|
| 213 | __unimplemented();
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | extern "C" _Unwind_Reason_Code __gxx_personality_v0(
|
|---|
| 217 | int, _Unwind_Action, unsigned,
|
|---|
| 218 | struct _Unwind_Exception*, struct _Unwind_Context*
|
|---|
| 219 | )
|
|---|
| 220 | {
|
|---|
| 221 | // TODO: implement
|
|---|
| 222 | __unimplemented();
|
|---|
| 223 | return _URC_NO_REASON;
|
|---|
| 224 | }
|
|---|
| 225 | }
|
|---|