sl@0
|
1 |
// Copyright (c) 2007-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 "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
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 |
// e32\euser\epoc\win32\uc_cwhelp.cpp
|
sl@0
|
15 |
// This file contains the CodeWarrior specific helper code common to eexe and edll
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32std.h>
|
sl@0
|
20 |
#include <e32std_private.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
// Define LAZY_INIT to allow the runtime to construct itself only when necessary. This uses less
|
sl@0
|
23 |
// TLS indicies, but is a more fragile approach.
|
sl@0
|
24 |
//
|
sl@0
|
25 |
#define LAZY_INIT
|
sl@0
|
26 |
|
sl@0
|
27 |
extern "C" {
|
sl@0
|
28 |
|
sl@0
|
29 |
//
|
sl@0
|
30 |
// Dummy versions of CodeWarrior runtime functions.
|
sl@0
|
31 |
//
|
sl@0
|
32 |
// These are only called when we are linked against the DLL version of the runtime, or if these
|
sl@0
|
33 |
// functions aren't present in the static runtime.
|
sl@0
|
34 |
//
|
sl@0
|
35 |
// The original functions are defined in:
|
sl@0
|
36 |
// c:/apps/Metrowerks/OEM3.1/Symbian_Support/MSL/MSL_C/MSL_Win32/Src/ThreadLocalData.c
|
sl@0
|
37 |
// c:/apps/Metrowerks/OEM3.1/Symbian_Support/MSL/MSL_C/MSL_Win32/Src/startup.win32.c
|
sl@0
|
38 |
//
|
sl@0
|
39 |
|
sl@0
|
40 |
#ifdef LAZY_INIT
|
sl@0
|
41 |
|
sl@0
|
42 |
extern int _InitializeThreadDataIndex(void);
|
sl@0
|
43 |
extern int *__get_MSL_init_count(void);
|
sl@0
|
44 |
|
sl@0
|
45 |
__declspec(weak) int *__get_MSL_init_count(void)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
return NULL;
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
#else
|
sl@0
|
51 |
|
sl@0
|
52 |
extern int _CRTStartup();
|
sl@0
|
53 |
|
sl@0
|
54 |
#endif
|
sl@0
|
55 |
|
sl@0
|
56 |
extern void _CleanUpMSL(void);
|
sl@0
|
57 |
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
TBool InitCWRuntime()
|
sl@0
|
61 |
{
|
sl@0
|
62 |
#ifdef LAZY_INIT
|
sl@0
|
63 |
return ETrue;
|
sl@0
|
64 |
#else
|
sl@0
|
65 |
return _CRTStartup();
|
sl@0
|
66 |
#endif
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
TBool CleanupCWRuntime()
|
sl@0
|
70 |
{
|
sl@0
|
71 |
#ifdef LAZY_INIT
|
sl@0
|
72 |
int* init_count_ptr = __get_MSL_init_count();
|
sl@0
|
73 |
if (!init_count_ptr) // if we couldn't link this function, don't attempt cleanup
|
sl@0
|
74 |
return ETrue;
|
sl@0
|
75 |
if (!_InitializeThreadDataIndex()) // make sure runtime is initialised to known state
|
sl@0
|
76 |
return EFalse;
|
sl@0
|
77 |
if (++(*init_count_ptr) != 1) // make it look like _CRTStartup was called
|
sl@0
|
78 |
return EFalse;
|
sl@0
|
79 |
#else
|
sl@0
|
80 |
if (*__get_MSL_init_count() < 1) // _CRTStartup should have been called at least once
|
sl@0
|
81 |
return EFalse;
|
sl@0
|
82 |
*__get_MSL_init_count() = 1; // reset to one so _CleanUpMSL runs
|
sl@0
|
83 |
#endif
|
sl@0
|
84 |
_CleanUpMSL(); // call into runtime to do cleanup
|
sl@0
|
85 |
return ETrue;
|
sl@0
|
86 |
}
|