kernel/eka/compsupp/gcce/ucppfini.cpp
author William Roberts <williamr@symbian.org>
Thu, 29 Jul 2010 23:52:13 +0100
branchGCC_SURGE
changeset 237 2604c9de91e0
permissions -rw-r--r--
Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359 Remove the older fix which added ksrt4_0.lib as a static library in lots of places
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
237
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     1
// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     2
// All rights reserved.
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     3
// This component and the accompanying materials are made available
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     4
// under the terms of the License "ARM EABI LICENCE.txt"
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     5
// which accompanies this distribution, and is available
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     6
// in kernel/eka/compsupp.
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     7
//
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     8
// Initial Contributors:
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    10
//
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    11
// Contributors:
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    12
//
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    13
// Description:
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    14
// This file is now part of ksrt.lib, to allow for writeable static data in kernel-side executables
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    15
// 
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    16
//
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    17
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    18
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    19
extern "C" {
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    20
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    21
typedef void (DTOR)(void *);
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    22
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    23
struct dtd 
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    24
{ 
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    25
    void * obj;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    26
    DTOR * dtor; 
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    27
};
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    28
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    29
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    30
#define MAX_DTOR_RECORDS 256
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    31
dtd dtor_rec[MAX_DTOR_RECORDS];
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    32
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    33
typedef dtd** dso_handle;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    34
dtd * __dso_handle = &dtor_rec[MAX_DTOR_RECORDS];
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    35
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    36
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    37
// This is called by compiler generated code to record needed destructions of
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    38
// dynamically initialized (ctor) top level (BSS) data. 
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    39
// I guess this is more efficient for the compiler than __cxa_atexit, since 
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    40
// it takes the object that needs dtoring as its first arg, which means its in
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    41
// the right register when the ctor returns.
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    42
void __aeabi_atexit(void *aObject, void (*aDtor)(void *), dso_handle aHandle)
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    43
    {
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    44
    dtd * drec = *aHandle;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    45
    drec--;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    46
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    47
    if (drec < &dtor_rec[0])
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    48
        return; // Need to decide what to do here
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    49
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    50
    drec->dtor = aDtor;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    51
    drec->obj  = aObject;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    52
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    53
    *aHandle = drec;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    54
    }
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    55
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    56
int __cxa_atexit( void (*aDtor)(void *), void *aObject, dso_handle aHandle )
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    57
    {
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    58
    __aeabi_atexit(aObject, aDtor, aHandle);
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    59
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    60
    // This is what the C++ GABI spec says to do!!
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    61
    if (*aHandle < &dtor_rec[0]) 
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    62
        return -1;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    63
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    64
    return 0;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    65
    }
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    66
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    67
void __cxa_finalize(dso_handle d)
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    68
    {
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    69
    dtd * drec = * d;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    70
    dtd * lim  = &dtor_rec[MAX_DTOR_RECORDS];
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    71
    
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    72
    while (drec < lim) 
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    73
        {
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    74
        drec->dtor(drec->obj);
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    75
        drec++;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    76
        }
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    77
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    78
    *d = drec;
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    79
    }
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    80
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    81
void run_static_dtors()
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    82
    {
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    83
    __cxa_finalize(&__dso_handle);
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    84
    }
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    85
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    86
2604c9de91e0 Add ksrt_gcce.lib with ucppini.cpp and ucppfini.cpp, as new fix for bug 3359
William Roberts <williamr@symbian.org>
parents:
diff changeset
    87
} // extern "C"