sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\euser\epoc\up_lib.cpp sl@0: // sl@0: // sl@0: sl@0: #include "up_std.h" sl@0: #include sl@0: #include "u32std.h" sl@0: #include sl@0: #include sl@0: sl@0: //#define __DEBUG_IMAGE__ 1 sl@0: sl@0: #if defined(__DEBUG_IMAGE__) && defined (__EPOC32__) sl@0: #include "e32svr.h" sl@0: sl@0: extern RDebug debug; sl@0: #define __IF_DEBUG(t) {debug.t;} sl@0: #else sl@0: #define __IF_DEBUG(t) sl@0: #endif sl@0: sl@0: #if defined(_UNICODE) sl@0: #define __SIZE(len) ((len)<<1) sl@0: #else sl@0: #define __SIZE(len) (len) sl@0: #endif sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: EXPORT_C TInt RLibrary::LoadRomLibrary(const TDesC& aFileName, const TDesC& aPath) sl@0: { sl@0: return Load(aFileName,aPath); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Loads the named DLL which matches the specified UID type. sl@0: sl@0: If successful, the function increments the usage count by one. sl@0: No additional search paths can be specified with this function. sl@0: sl@0: @param aFileName A descriptor containing the name of the DLL to be loaded. sl@0: The length of the file name must not be greater than KMaxFileName. sl@0: @param aType A UID type (a triplet of UIDs) which the DLL must match. sl@0: Individual UIDs can contain the KNullUid wild card. sl@0: sl@0: @return KErrNone, if successful; sl@0: KErrBadName, if the length of aFileName is greater than KMaxFileName; sl@0: otherwise one of the other system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TUidType& aType) sl@0: { sl@0: sl@0: return Load(aFileName, KNullDesC, aType); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Loads the named DLL. sl@0: sl@0: If successful, the function increments the usage count by one. sl@0: sl@0: @param aFileName A descriptor containing the name of the DLL to be loaded. sl@0: The length of the file name must not be greater than KMaxFileName. sl@0: @param aPath A descriptor containing a list of path names, each separated by sl@0: a semicolon. When specified, these paths are searched for the DLL sl@0: before the standard search locations. By default, sl@0: no pathnames are specified. sl@0: sl@0: @return KErrNone, if successful; sl@0: KErrBadName, if the length of aFileName is greater than KMaxFileName; sl@0: otherwise one of the other system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath) sl@0: { sl@0: sl@0: return Load(aFileName, aPath, TUidType()); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Loads the named DLL that matches the specified UID type. sl@0: sl@0: If successful, the function increments the usage count by one. sl@0: sl@0: @param aFileName A descriptor containing the name of the DLL to be loaded. sl@0: The length of the file name must not be greater than KMaxFileName. sl@0: @param aPath A descriptor containing a list of path names, each separated by sl@0: a semicolon. When specified, these paths are searched for the DLL sl@0: before the standard search locations. sl@0: @param aType A UID type (a triplet of UIDs) that the DLL must match. Individual UIDs sl@0: can contain the KNullUid wild card. sl@0: sl@0: @return KErrNone, if successful; sl@0: KErrBadName, if the length of aFileName is greater than KMaxFileName; sl@0: otherwise one of the other system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath, const TUidType& aType) sl@0: { sl@0: return Load(aFileName, aPath, aType, KModuleVersionWild); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Loads the named DLL that matches the specified UID type and version. sl@0: sl@0: If successful, the function increments the usage count by one. sl@0: sl@0: @param aFileName A descriptor containing the name of the DLL to be loaded. sl@0: The length of the file name must not be greater sl@0: than KMaxFileName. sl@0: @param aPath A descriptor containing a list of path names, each sl@0: separated by a semicolon. When specified, these paths sl@0: are searched for the DLL before the standard search locations. sl@0: @param aType A UID type (a triplet of UIDs) that the DLL must match. sl@0: Individual UIDs can contain the KNullUid wild card. sl@0: @param aModuleVersion A version specification that the DLL must match. Major sl@0: version must match exactly and minor version must be >= the sl@0: specified minor version. sl@0: sl@0: @return KErrNone, if successful; sl@0: KErrBadName, if the length of aFileName is greater than KMaxFileName; sl@0: otherwise one of the other system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath, const TUidType& aType, TUint32 aModuleVersion) sl@0: { sl@0: sl@0: __IF_DEBUG(Print(_L("RLibrary::Load ##"))); sl@0: sl@0: RLoader loader; sl@0: TInt r=loader.Connect(); sl@0: if (r!=KErrNone) sl@0: return r; sl@0: sl@0: r=loader.LoadLibrary(iHandle, aFileName, aPath, aType, aModuleVersion); sl@0: loader.Close(); sl@0: if (r==KErrNone) sl@0: r=Init(); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets information about the specified DLL. sl@0: sl@0: @param aFileName A descriptor containing the name of the DLL to be checked. sl@0: The length of the file name must not be greater than KMaxFileName. sl@0: @param aInfoBuf On return, contains information about the DLL (RLibrary::TInfo) sl@0: sl@0: @return KErrNone, if successful; sl@0: KErrBadName, if the length of aFileName is greater than KMaxFileName; sl@0: otherwise one of the other system wide error codes. sl@0: */ sl@0: EXPORT_C TInt RLibrary::GetInfo(const TDesC& aFileName, TDes8& aInfoBuf) sl@0: { sl@0: __IF_DEBUG(Print(_L("RLibrary::GetInfo ##"))); sl@0: RLoader loader; sl@0: TInt r=loader.Connect(); sl@0: if (r!=KErrNone) sl@0: return r; sl@0: r=loader.GetInfo(aFileName, aInfoBuf); sl@0: loader.Close(); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets information about an executable binary, (DLL or EXE), based on header data sl@0: from that binaries image. sl@0: sl@0: @param aHeader A descriptor containing the data from the start of the binaries image. sl@0: This data should be of size RLibrary::KRequiredImageHeaderSize or the sl@0: total length of the binary image, whichever is smallest. sl@0: @param aInfoBuf A descriptor which will be filled with the extracted information. sl@0: This information will be in the form of a RLibrary::TInfo structure. sl@0: This should usually be an object of type RLibrary::TInfoBuf. sl@0: sl@0: @return KErrNone, if successful; sl@0: KErrUnderflow, if the size of aHeader is too small; sl@0: KErrCorrupt, if the data in aHeader isn't a valid executable image header; sl@0: Otherwise one of the other system wide error codes. sl@0: sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C TInt RLibrary::GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf) sl@0: { sl@0: RLoader loader; sl@0: TInt r=loader.Connect(); sl@0: if (r!=KErrNone) sl@0: return r; sl@0: r=loader.GetInfoFromHeader(aHeader, aInfoBuf); sl@0: loader.Close(); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: TInt RLibrary::InitL() sl@0: // sl@0: // Initialise any static data following a DLL load sl@0: // sl@0: { sl@0: TLinAddr ep[KMaxLibraryEntryPoints]; sl@0: TInt numEps=KMaxLibraryEntryPoints; sl@0: E32Loader::LibraryAttach(iHandle, numEps, ep); sl@0: if (numEps==0) sl@0: return KErrNone; sl@0: TInt i; sl@0: for (i=0; i