|
1 // Copyright (c) 2008-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 // This file is part of usrt.lib (but not ksrt.lib). |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 extern "C" { |
|
20 |
|
21 typedef void (DTOR)(void *); |
|
22 |
|
23 struct dtd |
|
24 { |
|
25 void * obj; |
|
26 DTOR * dtor; |
|
27 }; |
|
28 |
|
29 |
|
30 #define MAX_DTOR_RECORDS 256 |
|
31 dtd dtor_rec[MAX_DTOR_RECORDS]; |
|
32 |
|
33 typedef dtd** dso_handle; |
|
34 dtd * __dso_handle = &dtor_rec[MAX_DTOR_RECORDS]; |
|
35 |
|
36 |
|
37 // This is called by compiler generated code to record needed destructions of |
|
38 // dynamically initialized (ctor) top level (BSS) data. |
|
39 // I guess this is more efficient for the compiler than __cxa_atexit, since |
|
40 // it takes the object that needs dtoring as its first arg, which means its in |
|
41 // the right register when the ctor returns. |
|
42 void __aeabi_atexit(void *aObject, void (*aDtor)(void *), dso_handle aHandle) |
|
43 { |
|
44 dtd * drec = *aHandle; |
|
45 drec--; |
|
46 |
|
47 if (drec < &dtor_rec[0]) |
|
48 return; // Need to decide what to do here |
|
49 |
|
50 drec->dtor = aDtor; |
|
51 drec->obj = aObject; |
|
52 |
|
53 *aHandle = drec; |
|
54 } |
|
55 |
|
56 int __cxa_atexit( void (*aDtor)(void *), void *aObject, dso_handle aHandle ) |
|
57 { |
|
58 __aeabi_atexit(aObject, aDtor, aHandle); |
|
59 |
|
60 // This is what the C++ GABI spec says to do!! |
|
61 if (*aHandle < &dtor_rec[0]) |
|
62 return -1; |
|
63 |
|
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 |
|
72 while (drec < lim) |
|
73 { |
|
74 drec->dtor(drec->obj); |
|
75 drec++; |
|
76 } |
|
77 |
|
78 *d = drec; |
|
79 } |
|
80 |
|
81 void run_static_dtors() |
|
82 { |
|
83 __cxa_finalize(&__dso_handle); |
|
84 } |
|
85 |
|
86 |
|
87 } // extern "C" |