1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/euser/epoc/win32/uc_cwhelp.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,86 @@
1.4 +// Copyright (c) 2007-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 "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\euser\epoc\win32\uc_cwhelp.cpp
1.18 +// This file contains the CodeWarrior specific helper code common to eexe and edll
1.19 +//
1.20 +//
1.21 +
1.22 +#include <e32std.h>
1.23 +#include <e32std_private.h>
1.24 +
1.25 +// Define LAZY_INIT to allow the runtime to construct itself only when necessary. This uses less
1.26 +// TLS indicies, but is a more fragile approach.
1.27 +//
1.28 +#define LAZY_INIT
1.29 +
1.30 +extern "C" {
1.31 +
1.32 +//
1.33 +// Dummy versions of CodeWarrior runtime functions.
1.34 +//
1.35 +// These are only called when we are linked against the DLL version of the runtime, or if these
1.36 +// functions aren't present in the static runtime.
1.37 +//
1.38 +// The original functions are defined in:
1.39 +// c:/apps/Metrowerks/OEM3.1/Symbian_Support/MSL/MSL_C/MSL_Win32/Src/ThreadLocalData.c
1.40 +// c:/apps/Metrowerks/OEM3.1/Symbian_Support/MSL/MSL_C/MSL_Win32/Src/startup.win32.c
1.41 +//
1.42 +
1.43 +#ifdef LAZY_INIT
1.44 +
1.45 +extern int _InitializeThreadDataIndex(void);
1.46 +extern int *__get_MSL_init_count(void);
1.47 +
1.48 +__declspec(weak) int *__get_MSL_init_count(void)
1.49 + {
1.50 + return NULL;
1.51 + }
1.52 +
1.53 +#else
1.54 +
1.55 +extern int _CRTStartup();
1.56 +
1.57 +#endif
1.58 +
1.59 +extern void _CleanUpMSL(void);
1.60 +
1.61 +}
1.62 +
1.63 +TBool InitCWRuntime()
1.64 + {
1.65 +#ifdef LAZY_INIT
1.66 + return ETrue;
1.67 +#else
1.68 + return _CRTStartup();
1.69 +#endif
1.70 + }
1.71 +
1.72 +TBool CleanupCWRuntime()
1.73 + {
1.74 +#ifdef LAZY_INIT
1.75 + int* init_count_ptr = __get_MSL_init_count();
1.76 + if (!init_count_ptr) // if we couldn't link this function, don't attempt cleanup
1.77 + return ETrue;
1.78 + if (!_InitializeThreadDataIndex()) // make sure runtime is initialised to known state
1.79 + return EFalse;
1.80 + if (++(*init_count_ptr) != 1) // make it look like _CRTStartup was called
1.81 + return EFalse;
1.82 +#else
1.83 + if (*__get_MSL_init_count() < 1) // _CRTStartup should have been called at least once
1.84 + return EFalse;
1.85 + *__get_MSL_init_count() = 1; // reset to one so _CleanUpMSL runs
1.86 +#endif
1.87 + _CleanUpMSL(); // call into runtime to do cleanup
1.88 + return ETrue;
1.89 + }