[ef9d0988] | 1 | /*
|
---|
[ad40b74b] | 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 |
|
---|
[ad40b74b] | 29 | #include <cassert>
|
---|
[858a51f] | 30 | #include <cstdint>
|
---|
[e2b55ac9] | 31 | #include <cstdlib>
|
---|
[858a51f] | 32 |
|
---|
[ef9d0988] | 33 | namespace __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 |
|
---|
[858a51f] | 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 |
|
---|
[ef9d0988] | 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 |
|
---|
[00d9778] | 83 | extern "C" _Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception*, _Unwind_Stop_Fn, void*)
|
---|
[ef9d0988] | 84 | {
|
---|
| 85 | // TODO: implement
|
---|
[e2b55ac9] | 86 | return _URC_NO_REASON;
|
---|
[ef9d0988] | 87 | }
|
---|
| 88 |
|
---|
[00d9778] | 89 | extern "C" void _Unwind_Resume(_Unwind_Exception*)
|
---|
[ef9d0988] | 90 | {
|
---|
| 91 | // TODO: implement
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[00d9778] | 94 | extern "C" void _Unwind_DeleteException(_Unwind_Exception*)
|
---|
[ef9d0988] | 95 | {
|
---|
| 96 | // TODO: implement
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[00d9778] | 99 | extern "C" std::uint64_t _Unwind_GetGR(_Unwind_Context*, int)
|
---|
[ef9d0988] | 100 | {
|
---|
| 101 | // TODO: implement
|
---|
[e2b55ac9] | 102 | return 0;
|
---|
[ef9d0988] | 103 | }
|
---|
| 104 |
|
---|
[00d9778] | 105 | extern "C" void _Unwind_SetGR(_Unwind_Context*, int, std::uint64_t)
|
---|
[ef9d0988] | 106 | {
|
---|
| 107 | // TODO: implement
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[00d9778] | 110 | extern "C" std::uint64_t _Unwind_GetIP(_Unwind_Context*)
|
---|
[ef9d0988] | 111 | {
|
---|
| 112 | // TODO: implement
|
---|
[e2b55ac9] | 113 | return 0;
|
---|
[ef9d0988] | 114 | }
|
---|
| 115 |
|
---|
[00d9778] | 116 | extern "C" void _Unwind_SetIP(_Unwind_Context*, std::uint64_t)
|
---|
[ef9d0988] | 117 | {
|
---|
| 118 | // TODO: implement
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[00d9778] | 121 | extern "C" std::uint64_t _Unwind_GetLanguageSpecificData(_Unwind_Context*)
|
---|
[ef9d0988] | 122 | {
|
---|
| 123 | // TODO: implement
|
---|
[e2b55ac9] | 124 | return 0;
|
---|
[ef9d0988] | 125 | }
|
---|
| 126 |
|
---|
[00d9778] | 127 | extern "C" std::uint64_t _Unwind_GetRegionStart(_Unwind_Context*)
|
---|
[ef9d0988] | 128 | {
|
---|
| 129 | // TODO: implement
|
---|
[e2b55ac9] | 130 | return 0;
|
---|
[ef9d0988] | 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 | */
|
---|
[e2b55ac9] | 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
|
---|
[ad40b74b] | 178 | __unimplemented();
|
---|
[e2b55ac9] | 179 | return nullptr;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | extern "C" void __cxa_free_exception(void* thrown_exception)
|
---|
| 183 | {
|
---|
| 184 | // TODO: implement
|
---|
[ad40b74b] | 185 | __unimplemented();
|
---|
[e2b55ac9] | 186 | }
|
---|
| 187 |
|
---|
| 188 | extern "C" void __cxa_throw(void* thrown_exception, std::type_info* tinfo, void (*dest)(void*))
|
---|
| 189 | {
|
---|
| 190 | // TODO: implement
|
---|
[ad40b74b] | 191 | __unimplemented();
|
---|
[e2b55ac9] | 192 | }
|
---|
| 193 |
|
---|
| 194 | extern "C" void* __cxa_get_exception_ptr(void* exception_object)
|
---|
| 195 | {
|
---|
| 196 | // TODO: implement
|
---|
[ad40b74b] | 197 | __unimplemented();
|
---|
[e2b55ac9] | 198 | return nullptr;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | extern "C" void* __cxa_begin_catch(void* exception_object)
|
---|
| 202 | {
|
---|
| 203 | // TODO: implement
|
---|
[ad40b74b] | 204 | __unimplemented();
|
---|
[e2b55ac9] | 205 | return nullptr;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | extern "C" void __cxa_end_catch()
|
---|
| 209 | {
|
---|
| 210 | // TODO: implement
|
---|
[ad40b74b] | 211 | __unimplemented();
|
---|
[e2b55ac9] | 212 | }
|
---|
| 213 |
|
---|
| 214 | extern "C" void __cxa_rethrow()
|
---|
| 215 | {
|
---|
| 216 | // TODO: implement
|
---|
[ad40b74b] | 217 | __unimplemented();
|
---|
[e2b55ac9] | 218 | }
|
---|
| 219 |
|
---|
| 220 | extern "C" void __cxa_bad_cast()
|
---|
| 221 | {
|
---|
| 222 | // TODO: implement
|
---|
[ad40b74b] | 223 | __unimplemented();
|
---|
[e2b55ac9] | 224 | }
|
---|
| 225 |
|
---|
| 226 | extern "C" void __cxa_bad_typeid()
|
---|
| 227 | {
|
---|
| 228 | // TODO: implement
|
---|
[ad40b74b] | 229 | __unimplemented();
|
---|
[e2b55ac9] | 230 | }
|
---|
[c4049e6] | 231 |
|
---|
| 232 | extern "C" void __cxa_throw_bad_array_new_length()
|
---|
| 233 | {
|
---|
| 234 | // TODO: implement
|
---|
[ad40b74b] | 235 | __unimplemented();
|
---|
[c4049e6] | 236 | }
|
---|
[2e328c3] | 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
|
---|
[ad40b74b] | 244 | __unimplemented();
|
---|
[2e328c3] | 245 | return _URC_NO_REASON;
|
---|
| 246 | }
|
---|
[ef9d0988] | 247 | }
|
---|