os/kernelhwsrv/kernel/eka/euser/epoc/up_lib.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/euser/epoc/up_lib.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,285 @@
     1.4 +// Copyright (c) 1996-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_lib.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "up_std.h"
    1.22 +#include <e32uid.h>
    1.23 +#include "u32std.h"
    1.24 +#include <e32svr.h>
    1.25 +#include <e32panic.h>
    1.26 +
    1.27 +//#define __DEBUG_IMAGE__ 1
    1.28 +
    1.29 +#if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
    1.30 +#include "e32svr.h" 
    1.31 +
    1.32 +extern RDebug debug;
    1.33 +#define __IF_DEBUG(t) {debug.t;}
    1.34 +#else
    1.35 +#define __IF_DEBUG(t)
    1.36 +#endif
    1.37 +
    1.38 +#if defined(_UNICODE)
    1.39 +#define __SIZE(len) ((len)<<1)
    1.40 +#else
    1.41 +#define __SIZE(len) (len)
    1.42 +#endif
    1.43 +
    1.44 +
    1.45 +
    1.46 +
    1.47 +/**
    1.48 +@internalComponent
    1.49 +*/
    1.50 +EXPORT_C TInt RLibrary::LoadRomLibrary(const TDesC& aFileName, const TDesC& aPath)
    1.51 +	{
    1.52 +	return Load(aFileName,aPath);
    1.53 +	}
    1.54 +
    1.55 +
    1.56 +
    1.57 +
    1.58 +/**
    1.59 +Loads the named DLL which matches the specified UID type.
    1.60 +
    1.61 +If successful, the function increments the usage count by one.
    1.62 +No additional search paths can be specified with this function.
    1.63 +
    1.64 +@param aFileName A descriptor containing the name of the DLL to be loaded.
    1.65 +                 The length of the file name must not be greater than KMaxFileName.
    1.66 +@param aType     A UID type (a triplet of UIDs) which the DLL must match.
    1.67 +                 Individual UIDs can contain the KNullUid wild card. 
    1.68 +
    1.69 +@return KErrNone, if successful;
    1.70 +        KErrBadName, if the length of aFileName is greater than KMaxFileName;
    1.71 +        otherwise one of the other system wide error codes.
    1.72 +*/
    1.73 +EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TUidType& aType)
    1.74 +	{
    1.75 +
    1.76 +	return Load(aFileName, KNullDesC, aType);
    1.77 +	}
    1.78 +
    1.79 +
    1.80 +
    1.81 +
    1.82 +/**
    1.83 +Loads the named DLL.
    1.84 +
    1.85 +If successful, the function increments the usage count by one.
    1.86 +
    1.87 +@param aFileName A descriptor containing the name of the DLL to be loaded.
    1.88 +                 The length of the file name must not be greater than KMaxFileName.
    1.89 +@param aPath     A descriptor containing a list of path names, each separated by
    1.90 +                 a semicolon. When specified, these paths are searched for the DLL
    1.91 +                 before the standard search locations. By default,
    1.92 +                 no pathnames are specified. 
    1.93 +
    1.94 +@return KErrNone, if successful;
    1.95 +        KErrBadName, if the length of aFileName is greater than KMaxFileName;
    1.96 +        otherwise one of the other system wide error codes.
    1.97 +*/
    1.98 +EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath)
    1.99 +	{
   1.100 +
   1.101 +	return Load(aFileName, aPath, TUidType());
   1.102 +	}
   1.103 +
   1.104 +
   1.105 +
   1.106 +
   1.107 +/**
   1.108 +Loads the named DLL that matches the specified UID type.
   1.109 +
   1.110 +If successful, the function increments the usage count by one.
   1.111 +
   1.112 +@param  aFileName A descriptor containing the name of the DLL to be loaded.
   1.113 +                  The length of the file name must not be greater than KMaxFileName.
   1.114 +@param aPath      A descriptor containing a list of path names, each separated by
   1.115 +                  a semicolon. When specified, these paths are searched for the DLL
   1.116 +                  before the standard search locations.
   1.117 +@param aType      A UID type (a triplet of UIDs) that the DLL must match. Individual UIDs
   1.118 +                  can contain the KNullUid wild card. 
   1.119 +
   1.120 +@return KErrNone, if successful;
   1.121 +        KErrBadName, if the length of aFileName is greater than KMaxFileName;
   1.122 +        otherwise one of the other system wide error codes.
   1.123 +*/
   1.124 +EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath, const TUidType& aType)
   1.125 +	{
   1.126 +	return Load(aFileName, aPath, aType, KModuleVersionWild);
   1.127 +	}
   1.128 +
   1.129 +
   1.130 +
   1.131 +
   1.132 +/**
   1.133 +Loads the named DLL that matches the specified UID type and version.
   1.134 +
   1.135 +If successful, the function increments the usage count by one.
   1.136 +
   1.137 +@param aFileName      A descriptor containing the name of the DLL to be loaded.
   1.138 +                      The length of the file name must not be greater
   1.139 +                      than KMaxFileName.
   1.140 +@param aPath          A descriptor containing a list of path names, each
   1.141 +                      separated by a semicolon. When specified, these paths
   1.142 +                      are searched for the DLL before the standard search locations.
   1.143 +@param aType          A UID type (a triplet of UIDs) that the DLL must match.
   1.144 +                      Individual UIDs can contain the KNullUid wild card. 
   1.145 +@param aModuleVersion A version specification that the DLL must match. Major
   1.146 +                      version must match exactly and minor version must be >= the 
   1.147 +                      specified minor version.
   1.148 +
   1.149 +@return KErrNone, if successful;
   1.150 +        KErrBadName, if the length of aFileName is greater than KMaxFileName;
   1.151 +        otherwise one of the other system wide error codes.
   1.152 +*/
   1.153 +EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath, const TUidType& aType, TUint32 aModuleVersion)
   1.154 +	{
   1.155 +
   1.156 +	__IF_DEBUG(Print(_L("RLibrary::Load ##")));
   1.157 +
   1.158 +	RLoader loader;
   1.159 +	TInt r=loader.Connect();
   1.160 +	if (r!=KErrNone)
   1.161 +		return r;
   1.162 +
   1.163 +	r=loader.LoadLibrary(iHandle, aFileName, aPath, aType, aModuleVersion);
   1.164 +	loader.Close();
   1.165 +	if (r==KErrNone)
   1.166 +		r=Init();
   1.167 +	return r;
   1.168 +	}
   1.169 +
   1.170 +
   1.171 +
   1.172 +
   1.173 +/**
   1.174 +Gets information about the specified DLL.
   1.175 +
   1.176 +@param aFileName A descriptor containing the name of the DLL to be checked.
   1.177 +                 The length of the file name must not be greater than KMaxFileName.
   1.178 +@param aInfoBuf  On return, contains information about the DLL (RLibrary::TInfo)
   1.179 +
   1.180 +@return KErrNone, if successful;
   1.181 +        KErrBadName, if the length of aFileName is greater than KMaxFileName;
   1.182 +        otherwise one of the other system wide error codes.
   1.183 +*/
   1.184 +EXPORT_C TInt RLibrary::GetInfo(const TDesC& aFileName, TDes8& aInfoBuf)
   1.185 +	{
   1.186 +	__IF_DEBUG(Print(_L("RLibrary::GetInfo ##")));
   1.187 +	RLoader loader;
   1.188 +	TInt r=loader.Connect();
   1.189 +	if (r!=KErrNone)
   1.190 +		return r;
   1.191 +	r=loader.GetInfo(aFileName, aInfoBuf);
   1.192 +	loader.Close();
   1.193 +	return r;
   1.194 +	}
   1.195 +
   1.196 +
   1.197 +
   1.198 +
   1.199 +/**
   1.200 +Gets information about an executable binary, (DLL or EXE), based on header data
   1.201 +from that binaries image.
   1.202 +
   1.203 +@param aHeader	A descriptor containing the data from the start of the binaries image.
   1.204 +				This data should be of size RLibrary::KRequiredImageHeaderSize or the
   1.205 +				total length of the binary image, whichever is smallest.
   1.206 +@param aInfoBuf	A descriptor which will be filled with the extracted information.
   1.207 +				This information will be in the form of a RLibrary::TInfo structure.
   1.208 +				This should usually be an object of type RLibrary::TInfoBuf.
   1.209 +
   1.210 +@return KErrNone, if successful;
   1.211 +		KErrUnderflow, if the size of aHeader is too small;
   1.212 +		KErrCorrupt, if the data in aHeader isn't a valid executable image header;
   1.213 +		Otherwise one of the other system wide error codes.
   1.214 +
   1.215 +@internalTechnology
   1.216 +*/
   1.217 +EXPORT_C TInt RLibrary::GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf)
   1.218 +	{
   1.219 +	RLoader loader;
   1.220 +	TInt r=loader.Connect();
   1.221 +	if (r!=KErrNone)
   1.222 +		return r;
   1.223 +	r=loader.GetInfoFromHeader(aHeader, aInfoBuf);
   1.224 +	loader.Close();
   1.225 +	return r;
   1.226 +	}
   1.227 +
   1.228 +
   1.229 +
   1.230 +
   1.231 +TInt RLibrary::InitL()
   1.232 +//
   1.233 +// Initialise any static data following a DLL load
   1.234 +//
   1.235 +	{
   1.236 +	TLinAddr ep[KMaxLibraryEntryPoints];
   1.237 +	TInt numEps=KMaxLibraryEntryPoints;
   1.238 +	E32Loader::LibraryAttach(iHandle, numEps, ep);
   1.239 +	if (numEps==0)
   1.240 +		return KErrNone;
   1.241 +	TInt i;
   1.242 +	for (i=0; i<numEps; ++i)
   1.243 +		{
   1.244 +		TLibraryEntry f=(TLibraryEntry)ep[i];
   1.245 +		TInt r = (*f)(KModuleEntryReasonProcessAttach);
   1.246 +		if (r != KErrNone)
   1.247 +			return r;
   1.248 +		}
   1.249 +	return E32Loader::LibraryAttached(iHandle);
   1.250 +	}
   1.251 +
   1.252 +
   1.253 +
   1.254 +
   1.255 +GLREF_C void Panic(TCdtPanic aPanic);
   1.256 +
   1.257 +
   1.258 +
   1.259 +
   1.260 +/**
   1.261 +@internalComponent
   1.262 +*/ 
   1.263 +EXPORT_C TInt RLibrary::Init()
   1.264 +	{
   1.265 +	TInt r=KErrNone;
   1.266 +	TRAPD(s,r=InitL());	// catch attempts to leave from constructors
   1.267 +	__ASSERT_ALWAYS(s==KErrNone, Panic(EDllStaticConstructorLeave));
   1.268 +	return r;
   1.269 +	}
   1.270 +
   1.271 +
   1.272 +
   1.273 +
   1.274 +/**
   1.275 +Closes the DLL.
   1.276 +
   1.277 +The function decrements the usage count by one.
   1.278 +
   1.279 +This handle must have been used to load the DLL using
   1.280 +one of the Load() functions.
   1.281 +*/
   1.282 +EXPORT_C void RLibrary::Close()
   1.283 +
   1.284 +	{
   1.285 +
   1.286 +	RHandleBase::Close();
   1.287 +	}
   1.288 +