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