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