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

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