kernel/eka/euser/epoc/up_lib.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1996-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\euser\epoc\up_lib.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "up_std.h"
       
    19 #include <e32uid.h>
       
    20 #include "u32std.h"
       
    21 #include <e32svr.h>
       
    22 #include <e32panic.h>
       
    23 
       
    24 //#define __DEBUG_IMAGE__ 1
       
    25 
       
    26 #if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
       
    27 #include "e32svr.h" 
       
    28 
       
    29 extern RDebug debug;
       
    30 #define __IF_DEBUG(t) {debug.t;}
       
    31 #else
       
    32 #define __IF_DEBUG(t)
       
    33 #endif
       
    34 
       
    35 #if defined(_UNICODE)
       
    36 #define __SIZE(len) ((len)<<1)
       
    37 #else
       
    38 #define __SIZE(len) (len)
       
    39 #endif
       
    40 
       
    41 
       
    42 
       
    43 
       
    44 /**
       
    45 @internalComponent
       
    46 */
       
    47 EXPORT_C TInt RLibrary::LoadRomLibrary(const TDesC& aFileName, const TDesC& aPath)
       
    48 	{
       
    49 	return Load(aFileName,aPath);
       
    50 	}
       
    51 
       
    52 
       
    53 
       
    54 
       
    55 /**
       
    56 Loads the named DLL which matches the specified UID type.
       
    57 
       
    58 If successful, the function increments the usage count by one.
       
    59 No additional search paths can be specified with this function.
       
    60 
       
    61 @param aFileName A descriptor containing the name of the DLL to be loaded.
       
    62                  The length of the file name must not be greater than KMaxFileName.
       
    63 @param aType     A UID type (a triplet of UIDs) which the DLL must match.
       
    64                  Individual UIDs can contain the KNullUid wild card. 
       
    65 
       
    66 @return KErrNone, if successful;
       
    67         KErrBadName, if the length of aFileName is greater than KMaxFileName;
       
    68         otherwise one of the other system wide error codes.
       
    69 */
       
    70 EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TUidType& aType)
       
    71 	{
       
    72 
       
    73 	return Load(aFileName, KNullDesC, aType);
       
    74 	}
       
    75 
       
    76 
       
    77 
       
    78 
       
    79 /**
       
    80 Loads the named DLL.
       
    81 
       
    82 If successful, the function increments the usage count by one.
       
    83 
       
    84 @param aFileName A descriptor containing the name of the DLL to be loaded.
       
    85                  The length of the file name must not be greater than KMaxFileName.
       
    86 @param aPath     A descriptor containing a list of path names, each separated by
       
    87                  a semicolon. When specified, these paths are searched for the DLL
       
    88                  before the standard search locations. By default,
       
    89                  no pathnames are specified. 
       
    90 
       
    91 @return KErrNone, if successful;
       
    92         KErrBadName, if the length of aFileName is greater than KMaxFileName;
       
    93         otherwise one of the other system wide error codes.
       
    94 */
       
    95 EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath)
       
    96 	{
       
    97 
       
    98 	return Load(aFileName, aPath, TUidType());
       
    99 	}
       
   100 
       
   101 
       
   102 
       
   103 
       
   104 /**
       
   105 Loads the named DLL that matches the specified UID type.
       
   106 
       
   107 If successful, the function increments the usage count by one.
       
   108 
       
   109 @param  aFileName A descriptor containing the name of the DLL to be loaded.
       
   110                   The length of the file name must not be greater than KMaxFileName.
       
   111 @param aPath      A descriptor containing a list of path names, each separated by
       
   112                   a semicolon. When specified, these paths are searched for the DLL
       
   113                   before the standard search locations.
       
   114 @param aType      A UID type (a triplet of UIDs) that the DLL must match. Individual UIDs
       
   115                   can contain the KNullUid wild card. 
       
   116 
       
   117 @return KErrNone, if successful;
       
   118         KErrBadName, if the length of aFileName is greater than KMaxFileName;
       
   119         otherwise one of the other system wide error codes.
       
   120 */
       
   121 EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath, const TUidType& aType)
       
   122 	{
       
   123 	return Load(aFileName, aPath, aType, KModuleVersionWild);
       
   124 	}
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 /**
       
   130 Loads the named DLL that matches the specified UID type and version.
       
   131 
       
   132 If successful, the function increments the usage count by one.
       
   133 
       
   134 @param aFileName      A descriptor containing the name of the DLL to be loaded.
       
   135                       The length of the file name must not be greater
       
   136                       than KMaxFileName.
       
   137 @param aPath          A descriptor containing a list of path names, each
       
   138                       separated by a semicolon. When specified, these paths
       
   139                       are searched for the DLL before the standard search locations.
       
   140 @param aType          A UID type (a triplet of UIDs) that the DLL must match.
       
   141                       Individual UIDs can contain the KNullUid wild card. 
       
   142 @param aModuleVersion A version specification that the DLL must match. Major
       
   143                       version must match exactly and minor version must be >= the 
       
   144                       specified minor version.
       
   145 
       
   146 @return KErrNone, if successful;
       
   147         KErrBadName, if the length of aFileName is greater than KMaxFileName;
       
   148         otherwise one of the other system wide error codes.
       
   149 */
       
   150 EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath, const TUidType& aType, TUint32 aModuleVersion)
       
   151 	{
       
   152 
       
   153 	__IF_DEBUG(Print(_L("RLibrary::Load ##")));
       
   154 
       
   155 	RLoader loader;
       
   156 	TInt r=loader.Connect();
       
   157 	if (r!=KErrNone)
       
   158 		return r;
       
   159 
       
   160 	r=loader.LoadLibrary(iHandle, aFileName, aPath, aType, aModuleVersion);
       
   161 	loader.Close();
       
   162 	if (r==KErrNone)
       
   163 		r=Init();
       
   164 	return r;
       
   165 	}
       
   166 
       
   167 
       
   168 
       
   169 
       
   170 /**
       
   171 Gets information about the specified DLL.
       
   172 
       
   173 @param aFileName A descriptor containing the name of the DLL to be checked.
       
   174                  The length of the file name must not be greater than KMaxFileName.
       
   175 @param aInfoBuf  On return, contains information about the DLL (RLibrary::TInfo)
       
   176 
       
   177 @return KErrNone, if successful;
       
   178         KErrBadName, if the length of aFileName is greater than KMaxFileName;
       
   179         otherwise one of the other system wide error codes.
       
   180 */
       
   181 EXPORT_C TInt RLibrary::GetInfo(const TDesC& aFileName, TDes8& aInfoBuf)
       
   182 	{
       
   183 	__IF_DEBUG(Print(_L("RLibrary::GetInfo ##")));
       
   184 	RLoader loader;
       
   185 	TInt r=loader.Connect();
       
   186 	if (r!=KErrNone)
       
   187 		return r;
       
   188 	r=loader.GetInfo(aFileName, aInfoBuf);
       
   189 	loader.Close();
       
   190 	return r;
       
   191 	}
       
   192 
       
   193 
       
   194 
       
   195 
       
   196 /**
       
   197 Gets information about an executable binary, (DLL or EXE), based on header data
       
   198 from that binaries image.
       
   199 
       
   200 @param aHeader	A descriptor containing the data from the start of the binaries image.
       
   201 				This data should be of size RLibrary::KRequiredImageHeaderSize or the
       
   202 				total length of the binary image, whichever is smallest.
       
   203 @param aInfoBuf	A descriptor which will be filled with the extracted information.
       
   204 				This information will be in the form of a RLibrary::TInfo structure.
       
   205 				This should usually be an object of type RLibrary::TInfoBuf.
       
   206 
       
   207 @return KErrNone, if successful;
       
   208 		KErrUnderflow, if the size of aHeader is too small;
       
   209 		KErrCorrupt, if the data in aHeader isn't a valid executable image header;
       
   210 		Otherwise one of the other system wide error codes.
       
   211 
       
   212 @internalTechnology
       
   213 */
       
   214 EXPORT_C TInt RLibrary::GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf)
       
   215 	{
       
   216 	RLoader loader;
       
   217 	TInt r=loader.Connect();
       
   218 	if (r!=KErrNone)
       
   219 		return r;
       
   220 	r=loader.GetInfoFromHeader(aHeader, aInfoBuf);
       
   221 	loader.Close();
       
   222 	return r;
       
   223 	}
       
   224 
       
   225 
       
   226 
       
   227 
       
   228 TInt RLibrary::InitL()
       
   229 //
       
   230 // Initialise any static data following a DLL load
       
   231 //
       
   232 	{
       
   233 	TLinAddr ep[KMaxLibraryEntryPoints];
       
   234 	TInt numEps=KMaxLibraryEntryPoints;
       
   235 	E32Loader::LibraryAttach(iHandle, numEps, ep);
       
   236 	if (numEps==0)
       
   237 		return KErrNone;
       
   238 	TInt i;
       
   239 	for (i=0; i<numEps; ++i)
       
   240 		{
       
   241 		TLibraryEntry f=(TLibraryEntry)ep[i];
       
   242 		TInt r = (*f)(KModuleEntryReasonProcessAttach);
       
   243 		if (r != KErrNone)
       
   244 			return r;
       
   245 		}
       
   246 	return E32Loader::LibraryAttached(iHandle);
       
   247 	}
       
   248 
       
   249 
       
   250 
       
   251 
       
   252 GLREF_C void Panic(TCdtPanic aPanic);
       
   253 
       
   254 
       
   255 
       
   256 
       
   257 /**
       
   258 @internalComponent
       
   259 */ 
       
   260 EXPORT_C TInt RLibrary::Init()
       
   261 	{
       
   262 	TInt r=KErrNone;
       
   263 	TRAPD(s,r=InitL());	// catch attempts to leave from constructors
       
   264 	__ASSERT_ALWAYS(s==KErrNone, Panic(EDllStaticConstructorLeave));
       
   265 	return r;
       
   266 	}
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 /**
       
   272 Closes the DLL.
       
   273 
       
   274 The function decrements the usage count by one.
       
   275 
       
   276 This handle must have been used to load the DLL using
       
   277 one of the Load() functions.
       
   278 */
       
   279 EXPORT_C void RLibrary::Close()
       
   280 
       
   281 	{
       
   282 
       
   283 	RHandleBase::Close();
       
   284 	}
       
   285