1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/compsupp/rvct2_1/ucppfini.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,84 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "ARM EABI LICENCE.txt"
1.8 +// which accompanies this distribution, and is available
1.9 +// in kernel/eka/compsupp.
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// toplevel destruction routines for 'user side' code compiled
1.18 +// with the ARMEDG compiler.
1.19 +//
1.20 +//
1.21 +
1.22 +#include "cppinit.h"
1.23 +
1.24 +extern "C" {
1.25 +
1.26 +#define MAX_DTOR_RECORDS 256
1.27 +static dtd dtor_rec[MAX_DTOR_RECORDS];
1.28 +
1.29 +typedef dtd **dso_handle;
1.30 +dtd * __dso_handle = &dtor_rec[MAX_DTOR_RECORDS];
1.31 +
1.32 +void __cxa_finalize ( dso_handle d );
1.33 +
1.34 +// Need to decide what this should do we run out of dtor space.
1.35 +// Probably need to run __cxa_finalize then do some kind of panic.
1.36 +void CppBSSInitializationError()
1.37 + {
1.38 +// __cxa_finalize(&dtor_rec[0]);
1.39 + };
1.40 +
1.41 +// This is called by compiler generated code to record needed destructions of
1.42 +// dynamically initialized (ctor) top level (BSS) data.
1.43 +// I guess this is more efficient for the compiler than __cxa_atexit, since
1.44 +// it takes the object that needs dtoring as its first arg, which means its in
1.45 +// the right register when the ctor returns.
1.46 +void __aeabi_atexit(void *aObject, void (*aDtor)(void *), dso_handle aHandle)
1.47 + {
1.48 + dtd * drec = *aHandle;
1.49 + drec--;
1.50 +
1.51 + if (drec < &dtor_rec[0])
1.52 + // Need to decide what to do here
1.53 + return CppBSSInitializationError();
1.54 +
1.55 + drec->dtor = aDtor;
1.56 + drec->obj = aObject;
1.57 + *aHandle = drec;
1.58 + }
1.59 +
1.60 +int __cxa_atexit ( void (*aDtor)(void *), void *aObject, dso_handle aHandle )
1.61 + {
1.62 + __aeabi_atexit(aObject, aDtor, aHandle);
1.63 +
1.64 + // This is what the C++ GABI spec says to do!!
1.65 + if (*aHandle < &dtor_rec[0])
1.66 + return -1;
1.67 + return 0;
1.68 + }
1.69 +
1.70 +void __cxa_finalize ( dso_handle d )
1.71 + {
1.72 + dtd * drec = * d;
1.73 + dtd * lim = &dtor_rec[MAX_DTOR_RECORDS];
1.74 + while (drec < lim)
1.75 + {
1.76 + drec->dtor(drec->obj);
1.77 + drec++;
1.78 + }
1.79 + *d = drec;
1.80 + }
1.81 +
1.82 +void run_static_dtors (void)
1.83 + {
1.84 + __cxa_finalize(&__dso_handle);
1.85 + }
1.86 +}
1.87 +