kernel/eka/compsupp/rvct2_2/ucppfini.cpp
changeset 9 96e5fb8b040d
child 10 36bfc973b146
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     1 /*
       
     2 * Copyright (c) 2002-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 * toplevel destruction routines for 'user side' code compiled 
       
    16 * with the ARMEDG compiler.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include "cppinit.h"
       
    22 
       
    23 extern "C" {
       
    24 
       
    25 #define MAX_DTOR_RECORDS 256
       
    26 static dtd dtor_rec[MAX_DTOR_RECORDS];
       
    27 
       
    28 typedef dtd **dso_handle;
       
    29 dtd * __dso_handle = &dtor_rec[MAX_DTOR_RECORDS];
       
    30 
       
    31 void __cxa_finalize ( dso_handle d );
       
    32 
       
    33 // Need to decide what this should do we run out of dtor space.
       
    34 // Probably need to run __cxa_finalize then do some kind of panic.
       
    35 void CppBSSInitializationError()
       
    36     {
       
    37 //  __cxa_finalize(&dtor_rec[0]);
       
    38     };
       
    39 
       
    40 // This is called by compiler generated code to record needed destructions of
       
    41 // dynamically initialized (ctor) top level (BSS) data. 
       
    42 // I guess this is more efficient for the compiler than __cxa_atexit, since 
       
    43 // it takes the object that needs dtoring as its first arg, which means its in
       
    44 // the right register when the ctor returns.
       
    45 void __aeabi_atexit(void *aObject, void (*aDtor)(void *), dso_handle aHandle)
       
    46     {
       
    47     dtd * drec = *aHandle;
       
    48     drec--;
       
    49 
       
    50     if (drec < &dtor_rec[0])
       
    51       // Need to decide what to do here
       
    52       return CppBSSInitializationError();
       
    53 
       
    54     drec->dtor = aDtor;
       
    55     drec->obj = aObject;
       
    56     *aHandle = drec;
       
    57     }
       
    58 
       
    59 int __cxa_atexit ( void (*aDtor)(void *), void *aObject, dso_handle aHandle )
       
    60     {
       
    61       __aeabi_atexit(aObject, aDtor, aHandle);
       
    62 
       
    63     // This is what the C++ GABI spec says to do!!
       
    64     if (*aHandle < &dtor_rec[0]) 
       
    65       return -1;
       
    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     while (drec < lim) 
       
    74         {
       
    75 	drec->dtor(drec->obj);
       
    76 	drec++;
       
    77         }
       
    78     *d = drec;
       
    79     }
       
    80 
       
    81 void run_static_dtors (void)
       
    82     {
       
    83     __cxa_finalize(&__dso_handle);
       
    84     }
       
    85 }
       
    86