sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "ARM EABI LICENCE.txt" sl@0: // which accompanies this distribution, and is available sl@0: // in kernel/eka/compsupp. sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // This file is part of usrt.lib (but not ksrt.lib). sl@0: // sl@0: // sl@0: sl@0: sl@0: extern "C" { sl@0: sl@0: typedef void (DTOR)(void *); sl@0: sl@0: struct dtd sl@0: { sl@0: void * obj; sl@0: DTOR * dtor; sl@0: }; sl@0: sl@0: sl@0: #define MAX_DTOR_RECORDS 256 sl@0: dtd dtor_rec[MAX_DTOR_RECORDS]; sl@0: sl@0: typedef dtd** dso_handle; sl@0: dtd * __dso_handle = &dtor_rec[MAX_DTOR_RECORDS]; sl@0: sl@0: sl@0: // This is called by compiler generated code to record needed destructions of sl@0: // dynamically initialized (ctor) top level (BSS) data. sl@0: // I guess this is more efficient for the compiler than __cxa_atexit, since sl@0: // it takes the object that needs dtoring as its first arg, which means its in sl@0: // the right register when the ctor returns. sl@0: void __aeabi_atexit(void *aObject, void (*aDtor)(void *), dso_handle aHandle) sl@0: { sl@0: dtd * drec = *aHandle; sl@0: drec--; sl@0: sl@0: if (drec < &dtor_rec[0]) sl@0: return; // Need to decide what to do here sl@0: sl@0: drec->dtor = aDtor; sl@0: drec->obj = aObject; sl@0: sl@0: *aHandle = drec; sl@0: } sl@0: sl@0: int __cxa_atexit( void (*aDtor)(void *), void *aObject, dso_handle aHandle ) sl@0: { sl@0: __aeabi_atexit(aObject, aDtor, aHandle); sl@0: sl@0: // This is what the C++ GABI spec says to do!! sl@0: if (*aHandle < &dtor_rec[0]) sl@0: return -1; sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: void __cxa_finalize(dso_handle d) sl@0: { sl@0: dtd * drec = * d; sl@0: dtd * lim = &dtor_rec[MAX_DTOR_RECORDS]; sl@0: sl@0: while (drec < lim) sl@0: { sl@0: drec->dtor(drec->obj); sl@0: drec++; sl@0: } sl@0: sl@0: *d = drec; sl@0: } sl@0: sl@0: void run_static_dtors() sl@0: { sl@0: __cxa_finalize(&__dso_handle); sl@0: } sl@0: sl@0: sl@0: } // extern "C"