symport/e32/include/e32ldr.h
changeset 1 0a7b44b10206
child 2 806186ab5e14
equal deleted inserted replaced
0:c55016431358 1:0a7b44b10206
       
     1 // Copyright (c) 1995-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 "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\include\e32ldr.h
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 #ifndef __E32LDR_H__
       
    24 #define __E32LDR_H__
       
    25 #include <e32cmn.h>
       
    26 
       
    27 const TInt KMaxLibraryEntryPoints=0x100;
       
    28 
       
    29 //
       
    30 // Loader version number.
       
    31 //
       
    32 const TInt KLoaderMajorVersionNumber=1;
       
    33 const TInt KLoaderMinorVersionNumber=0;
       
    34 
       
    35 //
       
    36 // IPC messages to the loader
       
    37 //
       
    38 enum TLoaderMsg
       
    39 	{
       
    40 	ELoadProcess=1,
       
    41 	ELoadLibrary=2,
       
    42 	ELoadLogicalDevice=3,
       
    43 	ELoadPhysicalDevice=4,
       
    44 	ELoadLocale=5,
       
    45 	ELoadFileSystem=6,
       
    46 	EGetInfo=7,
       
    47 	ELoaderDebugFunction=8,
       
    48 	ELoadFSExtension=9,
       
    49 	EGetInfoFromHeader=10,
       
    50 	ELoadFSPlugin=11,
       
    51 	ELoaderCancelLazyDllUnload=12,
       
    52 	ELdrDelete=13,
       
    53 	ECheckLibraryHash=14, 
       
    54 	ELoadFSProxyDrive=15,
       
    55     
       
    56     EMaxLoaderMsg
       
    57 	};
       
    58 //
       
    59 // Loader message arguments:
       
    60 //		0 = TLdrInfo
       
    61 //		1 = Filename
       
    62 //		2 = Command line (process) or path (library)
       
    63 //
       
    64 class TLdrInfo
       
    65 	{
       
    66 public:
       
    67 	IMPORT_C TLdrInfo();		// for BC
       
    68 public:
       
    69 	TUidType iRequestedUids;
       
    70 	TOwnerType iOwnerType;
       
    71 	TInt iHandle;
       
    72 	TUint32 iSecureId;
       
    73 	TUint32 iRequestedVersion;
       
    74 	TInt iMinStackSize;			// Size of new process stack 
       
    75 	};
       
    76 	
       
    77 
       
    78 #ifndef __KERNEL_MODE__
       
    79 #include <e32std.h>
       
    80 //
       
    81 // Loader client class
       
    82 //
       
    83 class RLoader : public RSessionBase
       
    84 	{
       
    85 public:
       
    86 	IMPORT_C TInt Connect();
       
    87 	TVersion Version() const;
       
    88 	TInt LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TOwnerType aType);
       
    89 	IMPORT_C TInt LoadLibrary(TInt& aHandle, const TDesC& aFileName, const TDesC& aPath, const TUidType& aType, TUint32 aModuleVersion);
       
    90 	IMPORT_C TInt GetInfo(const TDesC& aFileName, TDes8& aInfoBuf);
       
    91 	TInt LoadDeviceDriver(const TDesC& aFileName, TInt aDeviceType);
       
    92 	IMPORT_C TInt DebugFunction(TInt aFunction, TInt a1, TInt a2, TInt a3);
       
    93 	TInt LoadLocale(const TDesC& aLocaleDllName, TLibraryFunction* aExportList);
       
    94 	TInt GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf);
       
    95 	IMPORT_C TInt CancelLazyDllUnload();
       
    96 	IMPORT_C TInt Delete(const TDesC& aFileName);
       
    97     IMPORT_C TInt CheckLibraryHash(const TDesC& aFileName, TBool aValidateHash=EFalse);
       
    98 	TInt LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TInt aMinStackSize, TOwnerType aType);
       
    99 public:
       
   100 #ifdef __ARMCC__
       
   101 	// workaround for possible EDG bug (!!)
       
   102 	inline TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
       
   103 	  { return RSessionBase::SendReceive(aFunction, aArgs); }
       
   104 #else
       
   105 	using RSessionBase::SendReceive;
       
   106 #endif
       
   107 
       
   108 #ifdef __TOOLS2__
       
   109 public:
       
   110 	void Free();
       
   111 private:
       
   112 	TAny* iHandle;
       
   113 #endif
       
   114 	};
       
   115 #endif
       
   116 
       
   117 //
       
   118 // Information required to create a new code segment
       
   119 //
       
   120 enum TCodeSegAttributes
       
   121 	{
       
   122 	ECodeSegAttKernel	=0x00000001,
       
   123 	ECodeSegAttGlobal	=0x00000002,
       
   124 	ECodeSegAttFixed	=0x00000004,
       
   125 	ECodeSegAttABIMask	=0x00000018,	  // same values as in image header
       
   126 	ECodeSegAttPaged	=0x00000200,	  // the code seg is demand paged
       
   127 	ECodeSegAttHDll		=(TInt)0x80000000,// Emulator host file type: 1=DLL, 0=EXE
       
   128 	ECodeSegAttExpVer	=0x40000000,	  // Filename is explicitly versioned
       
   129 	ECodeSegAttNmdExpData=0x20000000	  // Named symbol export data in code seg
       
   130 	};
       
   131 
       
   132 class TBlockMapEntryBase
       
   133 /**
       
   134 	Where sections of a file are located on the media.
       
   135 	The kernel uses this to load in parts of a demand paged file.
       
   136  */
       
   137 	{
       
   138 public:
       
   139 	TUint iNumberOfBlocks;  // Number of contiguous blocks in map.
       
   140 	TUint iStartBlock;		// Number for first block in the map.
       
   141 	};
       
   142 
       
   143 struct SBlockMapInfoBase
       
   144 /**
       
   145 	Describes context for TBlockMapEntryBase objects.
       
   146  */
       
   147 	{
       
   148 	TUint iBlockGranularity;	// Size of a block in bytes.
       
   149 	TUint iBlockStartOffset;	// Offset to start of the file or requested file position within a block.
       
   150 	TInt64 iStartBlockAddress;	// Address of the first block of the partition.
       
   151 	TInt iLocalDriveNumber;		// Local drive number of where the file lies on.
       
   152 	};
       
   153 
       
   154 // forward declarations from file server
       
   155 class RFile;
       
   156 class RFs;
       
   157 
       
   158 /**
       
   159 A Handle used to identify a file on storage media.
       
   160 @internalTechnology
       
   161 */
       
   162 class RFileClamp
       
   163 	{
       
   164 public:
       
   165 	inline RFileClamp()
       
   166 		{
       
   167 		iCookie[0] = 0;
       
   168 		iCookie[1] = 0;
       
   169 		}
       
   170 	IMPORT_C TInt Clamp(RFile& aFile);
       
   171 	IMPORT_C TInt Close(RFs& aFs);
       
   172 
       
   173 public:
       
   174 	TInt64 iCookie[2];
       
   175 	};
       
   176 
       
   177 
       
   178 class TCodeSegCreateInfo
       
   179 	{
       
   180 public:
       
   181 	TBuf8<KMaxFileName> iFileName;		// not including {MMMMmmmm} version info
       
   182 	TUidType iUids;				// uid1 indicates EXE or DLL
       
   183 	TUint32 iAttr;
       
   184 	TInt iCodeSize;
       
   185 	TInt iTextSize;
       
   186 	TInt iDataSize;
       
   187 	TInt iBssSize;
       
   188 	TInt iTotalDataSize;
       
   189 	TUint32 iEntryPtVeneer;		// address of first instruction to be called
       
   190 	TUint32 iFileEntryPoint;	// address of entry point within this code segment
       
   191 	TInt iDepCount;
       
   192 	TUint32 iExportDir;
       
   193 	TInt iExportDirCount;
       
   194 	TUint32 iCodeLoadAddress;	// 0 for RAM loaded code, else pointer to TRomImageHeader
       
   195 	TUint32 iCodeRunAddress;
       
   196 	TUint32 iDataLoadAddress;
       
   197 	TUint32 iDataRunAddress;
       
   198 	TUint32 iExceptionDescriptor;
       
   199 	TInt iRootNameOffset;
       
   200 	TInt iRootNameLength;
       
   201 	TInt iExtOffset;
       
   202 	TUint32 iModuleVersion;
       
   203 	SSecurityInfo iS;
       
   204 	TAny* iHandle;				// pointer to kernel-side DCodeSeg object
       
   205 	TInt iClientProcessHandle;	// handle to client process for user DLL loads
       
   206 	/** Code relocation information stored on loader heap. */
       
   207 	TUint32* iCodeRelocTable;
       
   208 	/** Size of code relocation table in bytes. */
       
   209 	TInt iCodeRelocTableSize;
       
   210 	/** Import fixup information stored on loader heap. */
       
   211 	TUint32* iImportFixupTable;
       
   212 	/** Size of import fixup table in bytes. */
       
   213 	TInt iImportFixupTableSize;
       
   214 	/** Offset to apply to each code address in the image when it is fixed up. */
       
   215 	TUint32 iCodeDelta;
       
   216 	/** Offset to apply to each data address in the image when it is fixed up. */
       
   217 	TUint32 iDataDelta;
       
   218 	/**
       
   219 		Whether the code is paged.  If this is set, then
       
   220 		TCodeSegCreateInfo::iCodeRelocTable[Size] and
       
   221 		TCodeSegCreateInfo::iImportFixupTable[Size] contain fixup information
       
   222 		which the kernel uses to fix up each page.
       
   223 		(They may be null if the binary has no imports or no code section.)
       
   224 	 */
       
   225 	TBool iUseCodePaging;
       
   226 	/** The UID of the compression scheme in use. */
       
   227 	TUint32 iCompressionType;
       
   228 	/**
       
   229 		Start of compressed pages within the file.  The kernel uses
       
   230 		this to load compressed pages from byte-pair files when demand
       
   231 		paging.
       
   232 	 */
       
   233 	TInt32* iCodePageOffsets;
       
   234 	/** Where (possibly compressed) object code starts in iFile. */
       
   235 	TInt iCodeStartInFile;
       
   236 	/** Length of (possibly compressed) object code in iFile. */
       
   237 	TInt iCodeLengthInFile;
       
   238 	/** Information about block map entries in iCodeBlockMapEntries. */
       
   239 	SBlockMapInfoBase iCodeBlockMapCommon;
       
   240 	/** Where object code is located on the media. */
       
   241 	TBlockMapEntryBase* iCodeBlockMapEntries;
       
   242 	/** Size of block map entry array in bytes. */
       
   243 	TInt iCodeBlockMapEntriesSize;
       
   244 	/**
       
   245 		File clamp cookie, used to delete the file when the
       
   246 		codeseg is destroyed.
       
   247 	 */
       
   248 	RFileClamp iFileClamp;
       
   249 public:
       
   250 	IMPORT_C TPtrC8 RootName() const;
       
   251 	};
       
   252 
       
   253 //
       
   254 // Information required to create a new process
       
   255 //
       
   256 class TProcessCreateInfo : public TCodeSegCreateInfo
       
   257 	{
       
   258 public:
       
   259 	TInt iHeapSizeMin;
       
   260 	TInt iHeapSizeMax;
       
   261 	TInt iStackSize;
       
   262 	TInt iClientHandle;			// handle to loader's client
       
   263 	TInt iProcessHandle;		// handle to new DProcess
       
   264 	TInt iFinalHandle;			// handle from loader client to new process
       
   265 	TOwnerType iOwnerType;
       
   266 	TProcessPriority iPriority;
       
   267 	TUint iSecurityZone;
       
   268 	enum TDebugAttributes	// must be the same as RLibrary::TInfoV2::TDebugAttributes
       
   269 		{
       
   270 		EDebugAllowed = 1<<0, ///< Flags set if executable may be debugged.
       
   271 		ETraceAllowed = 1<<1 ///< Flags set if executable may be traced.
       
   272 		};
       
   273 	TUint iDebugAttributes;
       
   274 	TRequestStatus* iDestructStat;
       
   275 
       
   276 	};
       
   277 
       
   278 const TUint KSecurityZoneUnique = 0u;
       
   279 const TUint KSecurityZoneLegacyCode = ~0u;
       
   280 
       
   281 //
       
   282 // Information required to attach a code segment to a process
       
   283 // in the form of a library.
       
   284 //
       
   285 class TLibraryCreateInfo
       
   286 	{
       
   287 public:
       
   288 	TAny* iCodeSegHandle;		// pointer to kernel-side DCodeSeg object
       
   289 	TInt iClientHandle;			// handle to loader's client
       
   290 	TInt iLibraryHandle;		// handle to new DLibrary
       
   291 	TOwnerType iOwnerType;
       
   292 	};
       
   293 
       
   294 //
       
   295 // Information required to find an existing code segment
       
   296 //
       
   297 class TFindCodeSeg
       
   298 	{
       
   299 public:
       
   300 	TUidType iUids;				// required UIDs
       
   301 	const TAny* iRomImgHdr;		// ROM image header if ROM code required, NULL otherwise
       
   302 	TUint32 iAttrMask;			// mask for attributes
       
   303 	TUint32 iAttrVal;			// required value for masked attributes
       
   304 	TInt iProcess;				// handle to process in which code is required to operate
       
   305 								// not used if kernel only specified
       
   306 	SSecurityInfo iS;			// required capabilities/SID
       
   307 	TUint32 iModuleVersion;		// required version
       
   308 	TBuf8<KMaxLibraryName> iName;	// name to look for - zero length means any
       
   309 	};
       
   310 
       
   311 //
       
   312 // Information required to by the reaper from the codeseg.
       
   313 //
       
   314 struct TCodeSegLoaderCookie
       
   315 	{
       
   316 	RFileClamp iFileClamp;
       
   317 	TInt64 iStartAddress;
       
   318 	TInt iDriveNumber;
       
   319 	};
       
   320 
       
   321 //
       
   322 // Loader magic executive functions
       
   323 //
       
   324 class E32Loader
       
   325 	{
       
   326 public:
       
   327 	// used by loader only
       
   328 	IMPORT_C static TInt CodeSegCreate(TCodeSegCreateInfo& aInfo);
       
   329 	IMPORT_C static TInt CodeSegLoaded(TCodeSegCreateInfo& aInfo);
       
   330 	IMPORT_C static TInt LibraryCreate(TLibraryCreateInfo& aInfo);
       
   331 	IMPORT_C static TInt CodeSegOpen(TAny* aHandle, TInt aClientProcessHandle);
       
   332 	IMPORT_C static void CodeSegClose(TAny* aHandle);
       
   333 	IMPORT_C static void CodeSegNext(TAny*& aHandle, const TFindCodeSeg& aFind);
       
   334 	IMPORT_C static void CodeSegInfo(TAny* aHandle, TCodeSegCreateInfo& aInfo);
       
   335 	IMPORT_C static TInt CodeSegAddDependency(TAny* aImporter, TAny* aExporter);
       
   336 	IMPORT_C static void CodeSegDeferDeletes();
       
   337 	IMPORT_C static void CodeSegEndDeferDeletes();
       
   338 	IMPORT_C static TInt ProcessCreate(TProcessCreateInfo& aInfo, const TDesC8* aCommandLine);
       
   339 	IMPORT_C static TInt ProcessLoaded(TProcessCreateInfo& aInfo);
       
   340 	IMPORT_C static TInt CheckClientState(TInt aClientHandle);
       
   341 	IMPORT_C static TInt DeviceLoad(TAny* aHandle, TInt aType);
       
   342 	IMPORT_C static TAny* ThreadProcessCodeSeg(TInt aHandle);
       
   343 	IMPORT_C static void ReadExportDir(TAny* aHandle, TUint32* aDest);
       
   344 	IMPORT_C static TInt LocaleExports(TAny* aHandle, TLibraryFunction* aExportsList);
       
   345 
       
   346 #ifdef __MARM__
       
   347 	IMPORT_C static void GetV7StubAddresses(TLinAddr& aExe, TLinAddr& aDll);
       
   348 	static TInt V7ExeEntryStub();
       
   349 	static TInt V7DllEntryStub(TInt aReason);
       
   350 #endif
       
   351 
       
   352 	IMPORT_C static TUint32 PagingPolicy();
       
   353 	
       
   354 	IMPORT_C static TInt NotifyIfCodeSegDestroyed(TRequestStatus& aStatus);
       
   355 	IMPORT_C static TInt GetDestroyedCodeSegInfo(TCodeSegLoaderCookie& aCookie);
       
   356 
       
   357 public:
       
   358 	// used by client side
       
   359 	static TInt WaitDllLock();
       
   360 	static TInt ReleaseDllLock();
       
   361 	static TInt LibraryAttach(TInt aHandle, TInt& aNumEps, TLinAddr* aEpList);
       
   362 	static TInt LibraryAttached(TInt aHandle);
       
   363 	static TInt StaticCallList(TInt& aNumEps, TLinAddr* aEpList);
       
   364 	static TInt LibraryDetach(TInt& aNumEps, TLinAddr* aEpList);
       
   365 	static TInt LibraryDetached();
       
   366 	};
       
   367 
       
   368 typedef TInt (*TSupervisorFunction)(TAny*);
       
   369 
       
   370 // Relocation types
       
   371 /**
       
   372 @internalTechnology
       
   373 @released
       
   374 */
       
   375 const TUint16 KReservedRelocType        = (TUint16)0x0000;
       
   376 /**
       
   377 @internalTechnology
       
   378 @released
       
   379 */
       
   380 const TUint16 KTextRelocType            = (TUint16)0x1000;
       
   381 /**
       
   382 @internalTechnology
       
   383 @released
       
   384 */
       
   385 const TUint16 KDataRelocType            = (TUint16)0x2000;
       
   386 /**
       
   387 @internalTechnology
       
   388 @released
       
   389 */
       
   390 const TUint16 KInferredRelocType        = (TUint16)0x3000;
       
   391 
       
   392 // Compression types
       
   393 
       
   394 /**
       
   395 @internalTechnology
       
   396 @released
       
   397 */
       
   398 const TUint KFormatNotCompressed=0;
       
   399 /**
       
   400 @internalTechnology
       
   401 @released
       
   402 */
       
   403 const TUint KUidCompressionDeflate=0x101F7AFC;
       
   404 
       
   405 
       
   406 const TUint KUidCompressionBytePair=0x102822AA;
       
   407 
       
   408 
       
   409 #endif
       
   410