|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "ARM EABI LICENCE.txt" |
|
5 // which accompanies this distribution, and is available |
|
6 // in kernel/eka/compsupp. |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // toplevel destruction routines for 'user side' code compiled |
|
15 // with the ARMEDG compiler. |
|
16 // |
|
17 // |
|
18 |
|
19 #include "cppinit.h" |
|
20 |
|
21 extern "C" { |
|
22 |
|
23 #define MAX_DTOR_RECORDS 256 |
|
24 static dtd dtor_rec[MAX_DTOR_RECORDS]; |
|
25 |
|
26 typedef dtd **dso_handle; |
|
27 dtd * __dso_handle = &dtor_rec[MAX_DTOR_RECORDS]; |
|
28 |
|
29 void __cxa_finalize ( dso_handle d ); |
|
30 |
|
31 // Need to decide what this should do we run out of dtor space. |
|
32 // Probably need to run __cxa_finalize then do some kind of panic. |
|
33 void CppBSSInitializationError() |
|
34 { |
|
35 // __cxa_finalize(&dtor_rec[0]); |
|
36 }; |
|
37 |
|
38 // This is called by compiler generated code to record needed destructions of |
|
39 // dynamically initialized (ctor) top level (BSS) data. |
|
40 // I guess this is more efficient for the compiler than __cxa_atexit, since |
|
41 // it takes the object that needs dtoring as its first arg, which means its in |
|
42 // the right register when the ctor returns. |
|
43 void __aeabi_atexit(void *aObject, void (*aDtor)(void *), dso_handle aHandle) |
|
44 { |
|
45 dtd * drec = *aHandle; |
|
46 drec--; |
|
47 |
|
48 if (drec < &dtor_rec[0]) |
|
49 // Need to decide what to do here |
|
50 return CppBSSInitializationError(); |
|
51 |
|
52 drec->dtor = aDtor; |
|
53 drec->obj = aObject; |
|
54 *aHandle = drec; |
|
55 } |
|
56 |
|
57 int __cxa_atexit ( void (*aDtor)(void *), void *aObject, dso_handle aHandle ) |
|
58 { |
|
59 __aeabi_atexit(aObject, aDtor, aHandle); |
|
60 |
|
61 // This is what the C++ GABI spec says to do!! |
|
62 if (*aHandle < &dtor_rec[0]) |
|
63 return -1; |
|
64 return 0; |
|
65 } |
|
66 |
|
67 void __cxa_finalize ( dso_handle d ) |
|
68 { |
|
69 dtd * drec = * d; |
|
70 dtd * lim = &dtor_rec[MAX_DTOR_RECORDS]; |
|
71 while (drec < lim) |
|
72 { |
|
73 drec->dtor(drec->obj); |
|
74 drec++; |
|
75 } |
|
76 *d = drec; |
|
77 } |
|
78 |
|
79 void run_static_dtors (void) |
|
80 { |
|
81 __cxa_finalize(&__dso_handle); |
|
82 } |
|
83 } |
|
84 |