sl@0
|
1 |
// Copyright (c) 1995-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\up_utl.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <u32exec.h>
|
sl@0
|
19 |
#include "up_std.h"
|
sl@0
|
20 |
#include <e32svr.h>
|
sl@0
|
21 |
#include <e32uid.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
#ifdef __EPOC32__
|
sl@0
|
24 |
#include <e32rom.h>
|
sl@0
|
25 |
#endif
|
sl@0
|
26 |
|
sl@0
|
27 |
#include <e32atomics.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
//#define __DEBUG_IMAGE__ 1
|
sl@0
|
30 |
#if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
|
sl@0
|
31 |
extern RDebug debug;
|
sl@0
|
32 |
#define __IF_DEBUG(t) {debug.t;}
|
sl@0
|
33 |
#else
|
sl@0
|
34 |
#define __IF_DEBUG(t)
|
sl@0
|
35 |
#endif
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
/**
|
sl@0
|
39 |
Atomically (i.e. in a manner which is safe against concurrent access by other
|
sl@0
|
40 |
threads) increments a TInt value by 1.
|
sl@0
|
41 |
|
sl@0
|
42 |
As an example of its use, the function is used in the implementation of
|
sl@0
|
43 |
critical sections.
|
sl@0
|
44 |
|
sl@0
|
45 |
@param aValue A reference to an integer whose value is to be incremented.
|
sl@0
|
46 |
On return contains the incremented value.
|
sl@0
|
47 |
|
sl@0
|
48 |
@return The value of aValue before it is incremented.
|
sl@0
|
49 |
|
sl@0
|
50 |
@see User::LockedDec
|
sl@0
|
51 |
@see RCrticalSection
|
sl@0
|
52 |
*/
|
sl@0
|
53 |
EXPORT_C TInt User::LockedInc(TInt& aValue)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
return (TInt)__e32_atomic_add_ord32(&aValue, 1);
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
|
sl@0
|
59 |
/**
|
sl@0
|
60 |
Atomically (i.e. in a manner which is safe against concurrent access by other
|
sl@0
|
61 |
threads) decrements a TInt value by 1.
|
sl@0
|
62 |
|
sl@0
|
63 |
As an example of its use, the function is used in the implementation of
|
sl@0
|
64 |
critical sections.
|
sl@0
|
65 |
|
sl@0
|
66 |
@param aValue A reference to an integer whose value is to be decremented.
|
sl@0
|
67 |
On return contains the decremented value.
|
sl@0
|
68 |
|
sl@0
|
69 |
@return The value of aValue before it is decremented.
|
sl@0
|
70 |
|
sl@0
|
71 |
@see User::LockedInc
|
sl@0
|
72 |
@see RCrticalSection
|
sl@0
|
73 |
*/
|
sl@0
|
74 |
EXPORT_C TInt User::LockedDec(TInt& aValue)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
return (TInt)__e32_atomic_add_ord32(&aValue, 0xFFFFFFFF);
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
EXPORT_C TInt User::SafeInc(TInt& aValue)
|
sl@0
|
83 |
/**
|
sl@0
|
84 |
Atomically increments the specified value by 1, if the value is > 0.
|
sl@0
|
85 |
|
sl@0
|
86 |
@param aValue The value to be incremented; on return the incremented value.
|
sl@0
|
87 |
|
sl@0
|
88 |
@return The original value of aValue
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
{
|
sl@0
|
91 |
return __e32_atomic_tas_ord32(&aValue, 1, 1, 0);
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
|
sl@0
|
95 |
|
sl@0
|
96 |
|
sl@0
|
97 |
EXPORT_C TInt User::SafeDec(TInt &aValue)
|
sl@0
|
98 |
/**
|
sl@0
|
99 |
Atomically decrements the specified value by 1, if the value is > 0.
|
sl@0
|
100 |
|
sl@0
|
101 |
@param aValue The value to be decremented; on return the decremented value.
|
sl@0
|
102 |
|
sl@0
|
103 |
@return The original value of aValue
|
sl@0
|
104 |
*/
|
sl@0
|
105 |
{
|
sl@0
|
106 |
return __e32_atomic_tas_ord32(&aValue, 1, -1, 0);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
|
sl@0
|
110 |
EXPORT_C void UserSvr::WsRegisterThread()
|
sl@0
|
111 |
//
|
sl@0
|
112 |
// Register the window server thread.
|
sl@0
|
113 |
//
|
sl@0
|
114 |
{
|
sl@0
|
115 |
|
sl@0
|
116 |
Exec::WsRegisterThread();
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
EXPORT_C void UserSvr::FsRegisterThread()
|
sl@0
|
120 |
//
|
sl@0
|
121 |
// Register the file server thread.
|
sl@0
|
122 |
//
|
sl@0
|
123 |
{
|
sl@0
|
124 |
Exec::FsRegisterThread();
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
EXPORT_C void UserSvr::RegisterTrustedChunk(TInt aHandle)
|
sl@0
|
128 |
/**
|
sl@0
|
129 |
Registers file server's chunk intended for DMA transfer.
|
sl@0
|
130 |
@internalComponent
|
sl@0
|
131 |
@released
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
{
|
sl@0
|
134 |
Exec::RegisterTrustedChunk(aHandle);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
EXPORT_C TInt UserHeap::SetupThreadHeap(TBool, SStdEpocThreadCreateInfo& aInfo)
|
sl@0
|
138 |
/**
|
sl@0
|
139 |
@internalComponent
|
sl@0
|
140 |
*/
|
sl@0
|
141 |
{
|
sl@0
|
142 |
TInt r = KErrNone;
|
sl@0
|
143 |
if (!aInfo.iAllocator && aInfo.iHeapInitialSize>0)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
// new heap required
|
sl@0
|
146 |
RHeap* pH = NULL;
|
sl@0
|
147 |
r = CreateThreadHeap(aInfo, pH);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
else if (aInfo.iAllocator)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
// sharing a heap
|
sl@0
|
152 |
RAllocator* pA = aInfo.iAllocator;
|
sl@0
|
153 |
pA->Open();
|
sl@0
|
154 |
User::SwitchAllocator(pA);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
return r;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
|
sl@0
|
160 |
|
sl@0
|
161 |
|
sl@0
|
162 |
EXPORT_C void User::HandleException(TAny* aInfo)
|
sl@0
|
163 |
/**
|
sl@0
|
164 |
Enables the current thread to handle an exception.
|
sl@0
|
165 |
|
sl@0
|
166 |
The function is called by the kernel.
|
sl@0
|
167 |
|
sl@0
|
168 |
@param aInfo A pointer to a TExcType type containing the exception information.
|
sl@0
|
169 |
|
sl@0
|
170 |
@see TExcType
|
sl@0
|
171 |
*/
|
sl@0
|
172 |
{
|
sl@0
|
173 |
|
sl@0
|
174 |
const TUint32* p = (const TUint32*)aInfo;
|
sl@0
|
175 |
TUint32 excType = p[0];
|
sl@0
|
176 |
TExceptionHandler f = Exec::ExceptionHandler(KCurrentThreadHandle);
|
sl@0
|
177 |
TRAPD(r, (*f)(TExcType(excType)) );
|
sl@0
|
178 |
Exec::ThreadSetFlags(KCurrentThreadHandle,KThreadFlagLastChance,0);
|
sl@0
|
179 |
if (r!=KErrNone)
|
sl@0
|
180 |
User::Leave(r);
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
|
sl@0
|
184 |
|
sl@0
|
185 |
|
sl@0
|
186 |
#ifdef __EPOC32__
|
sl@0
|
187 |
EXPORT_C TInt User::IsRomAddress(TBool &aBool, TAny *aPtr)
|
sl@0
|
188 |
/**
|
sl@0
|
189 |
Tests whether the specified address is in the ROM.
|
sl@0
|
190 |
|
sl@0
|
191 |
@param aBool True, if the address at aPtr is within the ROM; false,
|
sl@0
|
192 |
otherwise.
|
sl@0
|
193 |
@param aPtr The address to be tested.
|
sl@0
|
194 |
|
sl@0
|
195 |
@return Always KErrNone.
|
sl@0
|
196 |
*/
|
sl@0
|
197 |
{
|
sl@0
|
198 |
|
sl@0
|
199 |
TUint a = (TUint)aPtr;
|
sl@0
|
200 |
TUint main_start = UserSvr::RomHeaderAddress();
|
sl@0
|
201 |
TUint main_end = main_start + ((TRomHeader*)main_start)->iUncompressedSize;
|
sl@0
|
202 |
aBool = (a>=main_start && a<main_end);
|
sl@0
|
203 |
if (aBool)
|
sl@0
|
204 |
return KErrNone; // address is in main ROM
|
sl@0
|
205 |
|
sl@0
|
206 |
TUint rda = UserSvr::RomRootDirectoryAddress();
|
sl@0
|
207 |
|
sl@0
|
208 |
// We assume here, the primary rom starts a multiple of 4k.
|
sl@0
|
209 |
if (rda > main_end)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
// ASSUMPTIONS HERE
|
sl@0
|
212 |
// 1. root directory is past the end of the main ROM so there must be an extension ROM
|
sl@0
|
213 |
// 2. the ROM file system in the extension ROM is at the beginning of the ROM (similar to the
|
sl@0
|
214 |
// main ROM)
|
sl@0
|
215 |
// 3. the extension ROM is mapped starting at a megabyte boundary
|
sl@0
|
216 |
// Thus the address of the extension ROM header may be obtained by rounding the root directory
|
sl@0
|
217 |
// address down to the next megabyte boundary.
|
sl@0
|
218 |
|
sl@0
|
219 |
TUint ext_start = rda &~ 0x000fffffu;
|
sl@0
|
220 |
TUint ext_base = ((TExtensionRomHeader*)ext_start)->iRomBase;
|
sl@0
|
221 |
TUint ext_end = ext_start + ((TExtensionRomHeader*)ext_start)->iUncompressedSize;
|
sl@0
|
222 |
aBool = (ext_base==ext_start && a>=ext_start && a<ext_end);
|
sl@0
|
223 |
} return KErrNone;
|
sl@0
|
224 |
}
|
sl@0
|
225 |
#endif
|
sl@0
|
226 |
|
sl@0
|
227 |
|
sl@0
|
228 |
#ifdef __MARM__
|
sl@0
|
229 |
EXPORT_C void E32Loader::GetV7StubAddresses(TLinAddr& aExe, TLinAddr& aDll)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
// Only need V7 support on ARM platforms
|
sl@0
|
232 |
aExe = (TLinAddr)&E32Loader::V7ExeEntryStub;
|
sl@0
|
233 |
aDll = (TLinAddr)&E32Loader::V7DllEntryStub;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
#endif
|
sl@0
|
236 |
|
sl@0
|
237 |
#ifdef __MARM__
|
sl@0
|
238 |
// Only need V7 support on ARM platforms
|
sl@0
|
239 |
|
sl@0
|
240 |
_LIT(KEka1EntryStubName, "eka1_entry_stub.dll");
|
sl@0
|
241 |
extern "C" TLinAddr GetEka1ExeEntryPoint()
|
sl@0
|
242 |
{
|
sl@0
|
243 |
TLinAddr a = 0;
|
sl@0
|
244 |
RLibrary l;
|
sl@0
|
245 |
TInt r = l.Load(KEka1EntryStubName, KNullDesC, TUidType(KDynamicLibraryUid, KEka1EntryStubUid));
|
sl@0
|
246 |
if (r == KErrNone)
|
sl@0
|
247 |
r = l.Duplicate(RThread(), EOwnerProcess);
|
sl@0
|
248 |
if (r == KErrNone)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
a = (TLinAddr)l.Lookup(1);
|
sl@0
|
251 |
if (!a)
|
sl@0
|
252 |
r = KErrNotSupported;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
if (r != KErrNone)
|
sl@0
|
255 |
RThread().Kill(r);
|
sl@0
|
256 |
Exec::SetReentryPoint(a);
|
sl@0
|
257 |
return a;
|
sl@0
|
258 |
}
|
sl@0
|
259 |
#endif
|