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