|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * This file is part of usrt.lib (but not ksrt.lib). |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 extern "C" { |
|
22 |
|
23 typedef void (DTOR)(void *); |
|
24 |
|
25 struct dtd |
|
26 { |
|
27 void * obj; |
|
28 DTOR * dtor; |
|
29 }; |
|
30 |
|
31 |
|
32 #define MAX_DTOR_RECORDS 256 |
|
33 dtd dtor_rec[MAX_DTOR_RECORDS]; |
|
34 |
|
35 typedef dtd** dso_handle; |
|
36 dtd * __dso_handle = &dtor_rec[MAX_DTOR_RECORDS]; |
|
37 |
|
38 |
|
39 // This is called by compiler generated code to record needed destructions of |
|
40 // dynamically initialized (ctor) top level (BSS) data. |
|
41 // I guess this is more efficient for the compiler than __cxa_atexit, since |
|
42 // it takes the object that needs dtoring as its first arg, which means its in |
|
43 // the right register when the ctor returns. |
|
44 void __aeabi_atexit(void *aObject, void (*aDtor)(void *), dso_handle aHandle) |
|
45 { |
|
46 dtd * drec = *aHandle; |
|
47 drec--; |
|
48 |
|
49 if (drec < &dtor_rec[0]) |
|
50 return; // Need to decide what to do here |
|
51 |
|
52 drec->dtor = aDtor; |
|
53 drec->obj = aObject; |
|
54 |
|
55 *aHandle = drec; |
|
56 } |
|
57 |
|
58 int __cxa_atexit( void (*aDtor)(void *), void *aObject, dso_handle aHandle ) |
|
59 { |
|
60 __aeabi_atexit(aObject, aDtor, aHandle); |
|
61 |
|
62 // This is what the C++ GABI spec says to do!! |
|
63 if (*aHandle < &dtor_rec[0]) |
|
64 return -1; |
|
65 |
|
66 return 0; |
|
67 } |
|
68 |
|
69 void __cxa_finalize(dso_handle d) |
|
70 { |
|
71 dtd * drec = * d; |
|
72 dtd * lim = &dtor_rec[MAX_DTOR_RECORDS]; |
|
73 |
|
74 while (drec < lim) |
|
75 { |
|
76 drec->dtor(drec->obj); |
|
77 drec++; |
|
78 } |
|
79 |
|
80 *d = drec; |
|
81 } |
|
82 |
|
83 void run_static_dtors() |
|
84 { |
|
85 __cxa_finalize(&__dso_handle); |
|
86 } |
|
87 |
|
88 |
|
89 } // extern "C" |