Usermode/libc++ - Exception handling implemented (partially)
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / misc.cc
1 /*
2  * Acess2 C++ Library
3  * - By John Hodge (thePowersGang)
4  *
5  * misc.cc
6  * - Miscelanious functions
7  */
8 #include <string.h>
9 #include <acess/sys.h>
10 #include <exception>
11
12 extern "C" int SoMain()
13 {
14         //extern void _init();
15         //_init();
16         // nope
17         return 0;
18 }
19
20 extern "C" void __cxa_pure_virtual()
21 {
22         // dunno
23         ::_SysDebug("__cxa_pure_virtual by %p", __builtin_return_address(0));
24         ::std::terminate();
25 }
26
27
28 // DSO Support 
29 #define MAX_ATEXIT      32
30 static struct {
31         void (*destructor) (void *);
32         void    *arg;
33         void    *dso_handle;
34 } __cxa_atexit_funcs[MAX_ATEXIT];
35 static int      __cxa_atexit_func_count;
36
37 extern "C" int __cxa_atexit(void (*destructor) (void *), void *arg, void *dso_handle)
38 {
39         if( __cxa_atexit_func_count == MAX_ATEXIT )
40         {
41                 return 1;
42         }
43         
44         __cxa_atexit_funcs[__cxa_atexit_func_count].destructor = destructor;
45         __cxa_atexit_funcs[__cxa_atexit_func_count].arg = arg;
46         __cxa_atexit_funcs[__cxa_atexit_func_count].dso_handle = dso_handle;
47         __cxa_atexit_func_count ++;
48         return 0;
49 }
50
51 extern "C" void __cxa_finalize(void *f)
52 {
53         if( f == 0 )
54         {
55                 for( int i = __cxa_atexit_func_count; i --; )
56                 {
57                         if( __cxa_atexit_funcs[i].dso_handle == f )
58                         {
59                                 __cxa_atexit_funcs[i].destructor(__cxa_atexit_funcs[i].arg);
60                                 memmove(
61                                         &__cxa_atexit_funcs[i],
62                                         &__cxa_atexit_funcs[i+1],
63                                         (__cxa_atexit_func_count-i)*sizeof(__cxa_atexit_funcs[0])
64                                         );
65                                 i ++;
66                                 __cxa_atexit_func_count --;
67                         }
68                 }
69         }
70         else
71         {
72                 for( int i = __cxa_atexit_func_count; i --; )
73                 {
74                         __cxa_atexit_funcs[i].destructor(__cxa_atexit_funcs[i].arg);
75                 }
76                 __cxa_atexit_func_count = 0;
77         }
78 }
79

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