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