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