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