Update contrib.
1 // Copyright (c) 1995-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\epoc\up_utl.cpp
27 #include <e32atomics.h>
29 //#define __DEBUG_IMAGE__ 1
30 #if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
32 #define __IF_DEBUG(t) {debug.t;}
39 Atomically (i.e. in a manner which is safe against concurrent access by other
40 threads) increments a TInt value by 1.
42 As an example of its use, the function is used in the implementation of
45 @param aValue A reference to an integer whose value is to be incremented.
46 On return contains the incremented value.
48 @return The value of aValue before it is incremented.
53 EXPORT_C TInt User::LockedInc(TInt& aValue)
55 return (TInt)__e32_atomic_add_ord32(&aValue, 1);
60 Atomically (i.e. in a manner which is safe against concurrent access by other
61 threads) decrements a TInt value by 1.
63 As an example of its use, the function is used in the implementation of
66 @param aValue A reference to an integer whose value is to be decremented.
67 On return contains the decremented value.
69 @return The value of aValue before it is decremented.
74 EXPORT_C TInt User::LockedDec(TInt& aValue)
76 return (TInt)__e32_atomic_add_ord32(&aValue, 0xFFFFFFFF);
82 EXPORT_C TInt User::SafeInc(TInt& aValue)
84 Atomically increments the specified value by 1, if the value is > 0.
86 @param aValue The value to be incremented; on return the incremented value.
88 @return The original value of aValue
91 return __e32_atomic_tas_ord32(&aValue, 1, 1, 0);
97 EXPORT_C TInt User::SafeDec(TInt &aValue)
99 Atomically decrements the specified value by 1, if the value is > 0.
101 @param aValue The value to be decremented; on return the decremented value.
103 @return The original value of aValue
106 return __e32_atomic_tas_ord32(&aValue, 1, -1, 0);
110 EXPORT_C void UserSvr::WsRegisterThread()
112 // Register the window server thread.
116 Exec::WsRegisterThread();
119 EXPORT_C void UserSvr::FsRegisterThread()
121 // Register the file server thread.
124 Exec::FsRegisterThread();
127 EXPORT_C void UserSvr::RegisterTrustedChunk(TInt aHandle)
129 Registers file server's chunk intended for DMA transfer.
134 Exec::RegisterTrustedChunk(aHandle);
137 EXPORT_C TInt UserHeap::SetupThreadHeap(TBool, SStdEpocThreadCreateInfo& aInfo)
143 if (!aInfo.iAllocator && aInfo.iHeapInitialSize>0)
147 r = CreateThreadHeap(aInfo, pH);
149 else if (aInfo.iAllocator)
152 RAllocator* pA = aInfo.iAllocator;
154 User::SwitchAllocator(pA);
162 EXPORT_C void User::HandleException(TAny* aInfo)
164 Enables the current thread to handle an exception.
166 The function is called by the kernel.
168 @param aInfo A pointer to a TExcType type containing the exception information.
174 const TUint32* p = (const TUint32*)aInfo;
175 TUint32 excType = p[0];
176 TExceptionHandler f = Exec::ExceptionHandler(KCurrentThreadHandle);
177 TRAPD(r, (*f)(TExcType(excType)) );
178 Exec::ThreadSetFlags(KCurrentThreadHandle,KThreadFlagLastChance,0);
187 EXPORT_C TInt User::IsRomAddress(TBool &aBool, TAny *aPtr)
189 Tests whether the specified address is in the ROM.
191 @param aBool True, if the address at aPtr is within the ROM; false,
193 @param aPtr The address to be tested.
195 @return Always KErrNone.
199 TUint a = (TUint)aPtr;
200 TUint main_start = UserSvr::RomHeaderAddress();
201 TUint main_end = main_start + ((TRomHeader*)main_start)->iUncompressedSize;
202 aBool = (a>=main_start && a<main_end);
204 return KErrNone; // address is in main ROM
206 TUint rda = UserSvr::RomRootDirectoryAddress();
208 // We assume here, the primary rom starts a multiple of 4k.
212 // 1. root directory is past the end of the main ROM so there must be an extension ROM
213 // 2. the ROM file system in the extension ROM is at the beginning of the ROM (similar to the
215 // 3. the extension ROM is mapped starting at a megabyte boundary
216 // Thus the address of the extension ROM header may be obtained by rounding the root directory
217 // address down to the next megabyte boundary.
219 TUint ext_start = rda &~ 0x000fffffu;
220 TUint ext_base = ((TExtensionRomHeader*)ext_start)->iRomBase;
221 TUint ext_end = ext_start + ((TExtensionRomHeader*)ext_start)->iUncompressedSize;
222 aBool = (ext_base==ext_start && a>=ext_start && a<ext_end);
229 EXPORT_C void E32Loader::GetV7StubAddresses(TLinAddr& aExe, TLinAddr& aDll)
231 // Only need V7 support on ARM platforms
232 aExe = (TLinAddr)&E32Loader::V7ExeEntryStub;
233 aDll = (TLinAddr)&E32Loader::V7DllEntryStub;
238 // Only need V7 support on ARM platforms
240 _LIT(KEka1EntryStubName, "eka1_entry_stub.dll");
241 extern "C" TLinAddr GetEka1ExeEntryPoint()
245 TInt r = l.Load(KEka1EntryStubName, KNullDesC, TUidType(KDynamicLibraryUid, KEka1EntryStubUid));
247 r = l.Duplicate(RThread(), EOwnerProcess);
250 a = (TLinAddr)l.Lookup(1);
252 r = KErrNotSupported;
256 Exec::SetReentryPoint(a);