1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/euser/epoc/up_utl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,259 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\euser\epoc\up_utl.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <u32exec.h>
1.22 +#include "up_std.h"
1.23 +#include <e32svr.h>
1.24 +#include <e32uid.h>
1.25 +
1.26 +#ifdef __EPOC32__
1.27 +#include <e32rom.h>
1.28 +#endif
1.29 +
1.30 +#include <e32atomics.h>
1.31 +
1.32 +//#define __DEBUG_IMAGE__ 1
1.33 +#if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
1.34 +extern RDebug debug;
1.35 +#define __IF_DEBUG(t) {debug.t;}
1.36 +#else
1.37 +#define __IF_DEBUG(t)
1.38 +#endif
1.39 +
1.40 +
1.41 +/**
1.42 +Atomically (i.e. in a manner which is safe against concurrent access by other
1.43 +threads) increments a TInt value by 1.
1.44 +
1.45 +As an example of its use, the function is used in the implementation of
1.46 +critical sections.
1.47 +
1.48 +@param aValue A reference to an integer whose value is to be incremented.
1.49 + On return contains the incremented value.
1.50 +
1.51 +@return The value of aValue before it is incremented.
1.52 +
1.53 +@see User::LockedDec
1.54 +@see RCrticalSection
1.55 +*/
1.56 +EXPORT_C TInt User::LockedInc(TInt& aValue)
1.57 + {
1.58 + return (TInt)__e32_atomic_add_ord32(&aValue, 1);
1.59 + }
1.60 +
1.61 +
1.62 +/**
1.63 +Atomically (i.e. in a manner which is safe against concurrent access by other
1.64 +threads) decrements a TInt value by 1.
1.65 +
1.66 +As an example of its use, the function is used in the implementation of
1.67 +critical sections.
1.68 +
1.69 +@param aValue A reference to an integer whose value is to be decremented.
1.70 + On return contains the decremented value.
1.71 +
1.72 +@return The value of aValue before it is decremented.
1.73 +
1.74 +@see User::LockedInc
1.75 +@see RCrticalSection
1.76 +*/
1.77 +EXPORT_C TInt User::LockedDec(TInt& aValue)
1.78 + {
1.79 + return (TInt)__e32_atomic_add_ord32(&aValue, 0xFFFFFFFF);
1.80 + }
1.81 +
1.82 +
1.83 +
1.84 +
1.85 +EXPORT_C TInt User::SafeInc(TInt& aValue)
1.86 +/**
1.87 +Atomically increments the specified value by 1, if the value is > 0.
1.88 +
1.89 +@param aValue The value to be incremented; on return the incremented value.
1.90 +
1.91 +@return The original value of aValue
1.92 +*/
1.93 + {
1.94 + return __e32_atomic_tas_ord32(&aValue, 1, 1, 0);
1.95 + }
1.96 +
1.97 +
1.98 +
1.99 +
1.100 +EXPORT_C TInt User::SafeDec(TInt &aValue)
1.101 +/**
1.102 +Atomically decrements the specified value by 1, if the value is > 0.
1.103 +
1.104 +@param aValue The value to be decremented; on return the decremented value.
1.105 +
1.106 +@return The original value of aValue
1.107 +*/
1.108 + {
1.109 + return __e32_atomic_tas_ord32(&aValue, 1, -1, 0);
1.110 + }
1.111 +
1.112 +
1.113 +EXPORT_C void UserSvr::WsRegisterThread()
1.114 +//
1.115 +// Register the window server thread.
1.116 +//
1.117 + {
1.118 +
1.119 + Exec::WsRegisterThread();
1.120 + }
1.121 +
1.122 +EXPORT_C void UserSvr::FsRegisterThread()
1.123 +//
1.124 +// Register the file server thread.
1.125 +//
1.126 + {
1.127 + Exec::FsRegisterThread();
1.128 + }
1.129 +
1.130 +EXPORT_C void UserSvr::RegisterTrustedChunk(TInt aHandle)
1.131 +/**
1.132 +Registers file server's chunk intended for DMA transfer.
1.133 +@internalComponent
1.134 +@released
1.135 + */
1.136 + {
1.137 + Exec::RegisterTrustedChunk(aHandle);
1.138 + }
1.139 +
1.140 +EXPORT_C TInt UserHeap::SetupThreadHeap(TBool, SStdEpocThreadCreateInfo& aInfo)
1.141 +/**
1.142 +@internalComponent
1.143 +*/
1.144 + {
1.145 + TInt r = KErrNone;
1.146 + if (!aInfo.iAllocator && aInfo.iHeapInitialSize>0)
1.147 + {
1.148 + // new heap required
1.149 + RHeap* pH = NULL;
1.150 + r = CreateThreadHeap(aInfo, pH);
1.151 + }
1.152 + else if (aInfo.iAllocator)
1.153 + {
1.154 + // sharing a heap
1.155 + RAllocator* pA = aInfo.iAllocator;
1.156 + pA->Open();
1.157 + User::SwitchAllocator(pA);
1.158 + }
1.159 + return r;
1.160 + }
1.161 +
1.162 +
1.163 +
1.164 +
1.165 +EXPORT_C void User::HandleException(TAny* aInfo)
1.166 +/**
1.167 +Enables the current thread to handle an exception.
1.168 +
1.169 +The function is called by the kernel.
1.170 +
1.171 +@param aInfo A pointer to a TExcType type containing the exception information.
1.172 +
1.173 +@see TExcType
1.174 +*/
1.175 + {
1.176 +
1.177 + const TUint32* p = (const TUint32*)aInfo;
1.178 + TUint32 excType = p[0];
1.179 + TExceptionHandler f = Exec::ExceptionHandler(KCurrentThreadHandle);
1.180 + TRAPD(r, (*f)(TExcType(excType)) );
1.181 + Exec::ThreadSetFlags(KCurrentThreadHandle,KThreadFlagLastChance,0);
1.182 + if (r!=KErrNone)
1.183 + User::Leave(r);
1.184 + }
1.185 +
1.186 +
1.187 +
1.188 +
1.189 +#ifdef __EPOC32__
1.190 +EXPORT_C TInt User::IsRomAddress(TBool &aBool, TAny *aPtr)
1.191 +/**
1.192 +Tests whether the specified address is in the ROM.
1.193 +
1.194 +@param aBool True, if the address at aPtr is within the ROM; false,
1.195 + otherwise.
1.196 +@param aPtr The address to be tested.
1.197 +
1.198 +@return Always KErrNone.
1.199 +*/
1.200 + {
1.201 +
1.202 + TUint a = (TUint)aPtr;
1.203 + TUint main_start = UserSvr::RomHeaderAddress();
1.204 + TUint main_end = main_start + ((TRomHeader*)main_start)->iUncompressedSize;
1.205 + aBool = (a>=main_start && a<main_end);
1.206 + if (aBool)
1.207 + return KErrNone; // address is in main ROM
1.208 +
1.209 + TUint rda = UserSvr::RomRootDirectoryAddress();
1.210 +
1.211 + // We assume here, the primary rom starts a multiple of 4k.
1.212 + if (rda > main_end)
1.213 + {
1.214 + // ASSUMPTIONS HERE
1.215 + // 1. root directory is past the end of the main ROM so there must be an extension ROM
1.216 + // 2. the ROM file system in the extension ROM is at the beginning of the ROM (similar to the
1.217 + // main ROM)
1.218 + // 3. the extension ROM is mapped starting at a megabyte boundary
1.219 + // Thus the address of the extension ROM header may be obtained by rounding the root directory
1.220 + // address down to the next megabyte boundary.
1.221 +
1.222 + TUint ext_start = rda &~ 0x000fffffu;
1.223 + TUint ext_base = ((TExtensionRomHeader*)ext_start)->iRomBase;
1.224 + TUint ext_end = ext_start + ((TExtensionRomHeader*)ext_start)->iUncompressedSize;
1.225 + aBool = (ext_base==ext_start && a>=ext_start && a<ext_end);
1.226 + } return KErrNone;
1.227 + }
1.228 +#endif
1.229 +
1.230 +
1.231 +#ifdef __MARM__
1.232 +EXPORT_C void E32Loader::GetV7StubAddresses(TLinAddr& aExe, TLinAddr& aDll)
1.233 + {
1.234 + // Only need V7 support on ARM platforms
1.235 + aExe = (TLinAddr)&E32Loader::V7ExeEntryStub;
1.236 + aDll = (TLinAddr)&E32Loader::V7DllEntryStub;
1.237 + }
1.238 +#endif
1.239 +
1.240 +#ifdef __MARM__
1.241 +// Only need V7 support on ARM platforms
1.242 +
1.243 +_LIT(KEka1EntryStubName, "eka1_entry_stub.dll");
1.244 +extern "C" TLinAddr GetEka1ExeEntryPoint()
1.245 + {
1.246 + TLinAddr a = 0;
1.247 + RLibrary l;
1.248 + TInt r = l.Load(KEka1EntryStubName, KNullDesC, TUidType(KDynamicLibraryUid, KEka1EntryStubUid));
1.249 + if (r == KErrNone)
1.250 + r = l.Duplicate(RThread(), EOwnerProcess);
1.251 + if (r == KErrNone)
1.252 + {
1.253 + a = (TLinAddr)l.Lookup(1);
1.254 + if (!a)
1.255 + r = KErrNotSupported;
1.256 + }
1.257 + if (r != KErrNone)
1.258 + RThread().Kill(r);
1.259 + Exec::SetReentryPoint(a);
1.260 + return a;
1.261 + }
1.262 +#endif