sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\euser\epoc\win32\uc_cwhelp.cpp sl@0: // This file contains the CodeWarrior specific helper code common to eexe and edll sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: // Define LAZY_INIT to allow the runtime to construct itself only when necessary. This uses less sl@0: // TLS indicies, but is a more fragile approach. sl@0: // sl@0: #define LAZY_INIT sl@0: sl@0: extern "C" { sl@0: sl@0: // sl@0: // Dummy versions of CodeWarrior runtime functions. sl@0: // sl@0: // These are only called when we are linked against the DLL version of the runtime, or if these sl@0: // functions aren't present in the static runtime. sl@0: // sl@0: // The original functions are defined in: sl@0: // c:/apps/Metrowerks/OEM3.1/Symbian_Support/MSL/MSL_C/MSL_Win32/Src/ThreadLocalData.c sl@0: // c:/apps/Metrowerks/OEM3.1/Symbian_Support/MSL/MSL_C/MSL_Win32/Src/startup.win32.c sl@0: // sl@0: sl@0: #ifdef LAZY_INIT sl@0: sl@0: extern int _InitializeThreadDataIndex(void); sl@0: extern int *__get_MSL_init_count(void); sl@0: sl@0: __declspec(weak) int *__get_MSL_init_count(void) sl@0: { sl@0: return NULL; sl@0: } sl@0: sl@0: #else sl@0: sl@0: extern int _CRTStartup(); sl@0: sl@0: #endif sl@0: sl@0: extern void _CleanUpMSL(void); sl@0: sl@0: } sl@0: sl@0: TBool InitCWRuntime() sl@0: { sl@0: #ifdef LAZY_INIT sl@0: return ETrue; sl@0: #else sl@0: return _CRTStartup(); sl@0: #endif sl@0: } sl@0: sl@0: TBool CleanupCWRuntime() sl@0: { sl@0: #ifdef LAZY_INIT sl@0: int* init_count_ptr = __get_MSL_init_count(); sl@0: if (!init_count_ptr) // if we couldn't link this function, don't attempt cleanup sl@0: return ETrue; sl@0: if (!_InitializeThreadDataIndex()) // make sure runtime is initialised to known state sl@0: return EFalse; sl@0: if (++(*init_count_ptr) != 1) // make it look like _CRTStartup was called sl@0: return EFalse; sl@0: #else sl@0: if (*__get_MSL_init_count() < 1) // _CRTStartup should have been called at least once sl@0: return EFalse; sl@0: *__get_MSL_init_count() = 1; // reset to one so _CleanUpMSL runs sl@0: #endif sl@0: _CleanUpMSL(); // call into runtime to do cleanup sl@0: return ETrue; sl@0: }