Usermode/libc++ - Debug in cxa code, list emplace and iterators, general STL fixes
[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
10 extern "C" int SoMain()
11 {
12         //extern void _init();
13         //_init();
14         // nope
15         return 0;
16 }
17
18 extern "C" void __cxa_pure_virtual()
19 {
20         // dunno
21 }
22
23 extern "C" void __gxx_personality_v0()
24 {
25         // TODO: Handle __gxx_personality_v0 somehow
26 }
27
28
29 // DSO Support 
30 #define MAX_ATEXIT      32
31 static struct {
32         void (*destructor) (void *);
33         void    *arg;
34         void    *dso_handle;
35 } __cxa_atexit_funcs[MAX_ATEXIT];
36 static int      __cxa_atexit_func_count;
37
38 extern "C" int __cxa_atexit(void (*destructor) (void *), void *arg, void *dso_handle)
39 {
40         if( __cxa_atexit_func_count == MAX_ATEXIT )
41         {
42                 return 1;
43         }
44         
45         __cxa_atexit_funcs[__cxa_atexit_func_count].destructor = destructor;
46         __cxa_atexit_funcs[__cxa_atexit_func_count].arg = arg;
47         __cxa_atexit_funcs[__cxa_atexit_func_count].dso_handle = dso_handle;
48         __cxa_atexit_func_count ++;
49         return 0;
50 }
51
52 extern "C" void __cxa_finalize(void *f)
53 {
54         if( f == 0 )
55         {
56                 for( int i = __cxa_atexit_func_count; i --; )
57                 {
58                         if( __cxa_atexit_funcs[i].dso_handle == f )
59                         {
60                                 __cxa_atexit_funcs[i].destructor(__cxa_atexit_funcs[i].arg);
61                                 memmove(
62                                         &__cxa_atexit_funcs[i],
63                                         &__cxa_atexit_funcs[i+1],
64                                         (__cxa_atexit_func_count-i)*sizeof(__cxa_atexit_funcs[0])
65                                         );
66                                 i ++;
67                                 __cxa_atexit_func_count --;
68                         }
69                 }
70         }
71         else
72         {
73                 for( int i = __cxa_atexit_func_count; i --; )
74                 {
75                         __cxa_atexit_funcs[i].destructor(__cxa_atexit_funcs[i].arg);
76                 }
77                 __cxa_atexit_func_count = 0;
78         }
79 }
80

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