Usermode/libc++ - Exception handling in progress (build broken)
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / exception_handling.cc
1 /*
2  */
3 #include <typeinfo>
4 #include <cstdint>
5
6 typedef void *(unexpected_handler)(void);
7 typedef void *(terminate_handler)(void);
8
9 struct _Unwind_Context;
10
11 typedef enum {
12         _URC_NO_REASON = 0,
13         _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
14         _URC_FATAL_PHASE2_ERROR = 2,
15         _URC_FATAL_PHASE1_ERROR = 3,
16         _URC_NORMAL_STOP = 4,
17         _URC_END_OF_STACK = 5,
18         _URC_HANDLER_FOUND = 6,
19         _URC_INSTALL_CONTEXT = 7,
20         _URC_CONTINUE_UNWIND = 8
21 } _Unwind_Reason_Code;
22
23 typedef void    (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code reason, struct _Unwind_Exception *exc);
24
25 struct _Unwind_Exception
26 {
27         uint64_t        exception_class;
28         _Unwind_Exception_Cleanup_Fn    exception_cleanup;
29         uint64_t        private_1;
30         uint64_t        private_2;
31 };
32
33 struct __cxa_exception
34 {
35         std::type_info* exceptionType;
36         void (*exceptionDestructor)(void *);
37         unexpected_handler      unexpectedHandler;
38         terminate_handler       terminateHandler;
39         __cxa_exception*        nextException;
40         
41         int     handlerCount;
42         
43         int     handlerSwitchValue;
44         const char*     actionRecord;
45         const char*     languageSpecificData;
46         void*   catchTemp;
47         void*   adjustedPtr;
48         
49         _Unwind_Exception       unwindHeader;
50 };
51
52  int    uncaught_exception_count;
53 __cxa_exception *uncaught_exception_top;
54
55 extern "C" void __cxa_call_unexpected(void *)
56 {
57         // An unexpected exception was thrown from a function that lists its possible exceptions
58         for(;;);
59 }
60
61 extern "C" void *__cxa_begin_catch(void *exceptionObject)
62 {
63         struct __cxa_exception  *except = static_cast<__cxa_exception*>( exceptionObject );
64         except --;
65         
66         except->handlerCount ++;
67         
68         except->nextException = uncaught_exception_top;
69         uncaught_exception_top = except;
70         
71         uncaught_exception_count --;
72         
73         return except;
74 }
75
76 extern "C" void __cxa_end_catch()
77 {
78         struct __cxa_exception  *except = uncaught_exception_top;
79         except->handlerCount --;
80         uncaught_exception_top = except->nextException;
81         
82         if( except->handlerCount == 0 ) {
83                 //__cxa_free_exception(except+1);
84         }
85 }
86

UCC git Repository :: git.ucc.asn.au