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