1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/e32ldr.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,403 @@
1.4 +// Copyright (c) 1995-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 "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.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\include\e32ldr.h
1.18 +//
1.19 +//
1.20 +
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalTechnology
1.26 +*/
1.27 +
1.28 +#ifndef __E32LDR_H__
1.29 +#define __E32LDR_H__
1.30 +#include <e32cmn.h>
1.31 +
1.32 +const TInt KMaxLibraryEntryPoints=0x100;
1.33 +
1.34 +//
1.35 +// Loader version number.
1.36 +//
1.37 +const TInt KLoaderMajorVersionNumber=1;
1.38 +const TInt KLoaderMinorVersionNumber=0;
1.39 +
1.40 +//
1.41 +// IPC messages to the loader
1.42 +//
1.43 +enum TLoaderMsg
1.44 + {
1.45 + ELoadProcess=1,
1.46 + ELoadLibrary=2,
1.47 + ELoadLogicalDevice=3,
1.48 + ELoadPhysicalDevice=4,
1.49 + ELoadLocale=5,
1.50 + ELoadFileSystem=6,
1.51 + EGetInfo=7,
1.52 + ELoaderDebugFunction=8,
1.53 + ELoadFSExtension=9,
1.54 + EGetInfoFromHeader=10,
1.55 + ELoadFSPlugin=11,
1.56 + ELoaderCancelLazyDllUnload=12,
1.57 + ELdrDelete=13,
1.58 + ECheckLibraryHash=14,
1.59 +
1.60 + EMaxLoaderMsg
1.61 + };
1.62 +//
1.63 +// Loader message arguments:
1.64 +// 0 = TLdrInfo
1.65 +// 1 = Filename
1.66 +// 2 = Command line (process) or path (library)
1.67 +//
1.68 +class TLdrInfo
1.69 + {
1.70 +public:
1.71 + IMPORT_C TLdrInfo(); // for BC
1.72 +public:
1.73 + TUidType iRequestedUids;
1.74 + TOwnerType iOwnerType;
1.75 + TInt iHandle;
1.76 + TUint32 iSecureId;
1.77 + TUint32 iRequestedVersion;
1.78 + TInt iMinStackSize; // CR0885
1.79 + };
1.80 +
1.81 +
1.82 +#ifndef __KERNEL_MODE__
1.83 +#include <e32std.h>
1.84 +//
1.85 +// Loader client class
1.86 +//
1.87 +class RLoader : public RSessionBase
1.88 + {
1.89 +public:
1.90 + IMPORT_C TInt Connect();
1.91 + TVersion Version() const;
1.92 + TInt LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TOwnerType aType);
1.93 + IMPORT_C TInt LoadLibrary(TInt& aHandle, const TDesC& aFileName, const TDesC& aPath, const TUidType& aType, TUint32 aModuleVersion);
1.94 + IMPORT_C TInt GetInfo(const TDesC& aFileName, TDes8& aInfoBuf);
1.95 + TInt LoadDeviceDriver(const TDesC& aFileName, TInt aDeviceType);
1.96 + IMPORT_C TInt DebugFunction(TInt aFunction, TInt a1, TInt a2, TInt a3);
1.97 + TInt LoadLocale(const TDesC& aLocaleDllName, TLibraryFunction* aExportList);
1.98 + TInt GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf);
1.99 + IMPORT_C TInt CancelLazyDllUnload();
1.100 + IMPORT_C TInt Delete(const TDesC& aFileName);
1.101 + IMPORT_C TInt CheckLibraryHash(const TDesC& aFileName, TBool aValidateHash=EFalse);
1.102 + TInt LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TInt aMinStackSize, TOwnerType aType);
1.103 +public:
1.104 +#ifdef __ARMCC__
1.105 + // workaround for possible EDG bug (!!)
1.106 + inline TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
1.107 + { return RSessionBase::SendReceive(aFunction, aArgs); }
1.108 +#else
1.109 + using RSessionBase::SendReceive;
1.110 +#endif
1.111 + };
1.112 +#endif
1.113 +
1.114 +//
1.115 +// Information required to create a new code segment
1.116 +//
1.117 +enum TCodeSegAttributes
1.118 + {
1.119 + ECodeSegAttKernel =0x00000001,
1.120 + ECodeSegAttGlobal =0x00000002,
1.121 + ECodeSegAttFixed =0x00000004,
1.122 + ECodeSegAttABIMask =0x00000018, // same values as in image header
1.123 + ECodeSegAttPaged =0x00000200, // the code seg is demand paged
1.124 + ECodeSegAttHDll =(TInt)0x80000000,// Emulator host file type: 1=DLL, 0=EXE
1.125 + ECodeSegAttExpVer =0x40000000, // Filename is explicitly versioned
1.126 + ECodeSegAttNmdExpData=0x20000000 // Named symbol export data in code seg
1.127 + };
1.128 +
1.129 +class TBlockMapEntryBase
1.130 +/**
1.131 + Where sections of a file are located on the media.
1.132 + The kernel uses this to load in parts of a demand paged file.
1.133 + */
1.134 + {
1.135 +public:
1.136 + TUint iNumberOfBlocks; // Number of contiguous blocks in map.
1.137 + TUint iStartBlock; // Number for first block in the map.
1.138 + };
1.139 +
1.140 +struct SBlockMapInfoBase
1.141 +/**
1.142 + Describes context for TBlockMapEntryBase objects.
1.143 + */
1.144 + {
1.145 + TUint iBlockGranularity; // Size of a block in bytes.
1.146 + TUint iBlockStartOffset; // Offset to start of the file or requested file position within a block.
1.147 + TInt64 iStartBlockAddress; // Address of the first block of the partition.
1.148 + TInt iLocalDriveNumber; // Local drive number of where the file lies on.
1.149 + };
1.150 +
1.151 +// forward declarations from file server
1.152 +class RFile;
1.153 +class RFs;
1.154 +
1.155 +/**
1.156 +A Handle used to identify a file on storage media.
1.157 +@internalTechnology
1.158 +*/
1.159 +class RFileClamp
1.160 + {
1.161 +public:
1.162 + inline RFileClamp()
1.163 + {
1.164 + iCookie[0] = 0;
1.165 + iCookie[1] = 0;
1.166 + }
1.167 + IMPORT_C TInt Clamp(RFile& aFile);
1.168 + IMPORT_C TInt Close(RFs& aFs);
1.169 +
1.170 +public:
1.171 + TInt64 iCookie[2];
1.172 + };
1.173 +
1.174 +
1.175 +class TCodeSegCreateInfo
1.176 + {
1.177 +public:
1.178 + TBuf8<KMaxFileName> iFileName; // not including {MMMMmmmm} version info
1.179 + TUidType iUids; // uid1 indicates EXE or DLL
1.180 + TUint32 iAttr;
1.181 + TInt iCodeSize;
1.182 + TInt iTextSize;
1.183 + TInt iDataSize;
1.184 + TInt iBssSize;
1.185 + TInt iTotalDataSize;
1.186 + TUint32 iEntryPtVeneer; // address of first instruction to be called
1.187 + TUint32 iFileEntryPoint; // address of entry point within this code segment
1.188 + TInt iDepCount;
1.189 + TUint32 iExportDir;
1.190 + TInt iExportDirCount;
1.191 + TUint32 iCodeLoadAddress; // 0 for RAM loaded code, else pointer to TRomImageHeader
1.192 + TUint32 iCodeRunAddress;
1.193 + TUint32 iDataLoadAddress;
1.194 + TUint32 iDataRunAddress;
1.195 + TUint32 iExceptionDescriptor;
1.196 + TInt iRootNameOffset;
1.197 + TInt iRootNameLength;
1.198 + TInt iExtOffset;
1.199 + TUint32 iModuleVersion;
1.200 + SSecurityInfo iS;
1.201 + TAny* iHandle; // pointer to kernel-side DCodeSeg object
1.202 + TInt iClientProcessHandle; // handle to client process for user DLL loads
1.203 + /** Code relocation information stored on loader heap. */
1.204 + TUint32* iCodeRelocTable;
1.205 + /** Size of code relocation table in bytes. */
1.206 + TInt iCodeRelocTableSize;
1.207 + /** Import fixup information stored on loader heap. */
1.208 + TUint32* iImportFixupTable;
1.209 + /** Size of import fixup table in bytes. */
1.210 + TInt iImportFixupTableSize;
1.211 + /** Offset to apply to each code address in the image when it is fixed up. */
1.212 + TUint32 iCodeDelta;
1.213 + /** Offset to apply to each data address in the image when it is fixed up. */
1.214 + TUint32 iDataDelta;
1.215 + /**
1.216 + Whether the code is paged. If this is set, then
1.217 + TCodeSegCreateInfo::iCodeRelocTable[Size] and
1.218 + TCodeSegCreateInfo::iImportFixupTable[Size] contain fixup information
1.219 + which the kernel uses to fix up each page.
1.220 + (They may be null if the binary has no imports or no code section.)
1.221 + */
1.222 + TBool iUseCodePaging;
1.223 + /** The UID of the compression scheme in use. */
1.224 + TUint32 iCompressionType;
1.225 + /**
1.226 + Start of compressed pages within the file. The kernel uses
1.227 + this to load compressed pages from byte-pair files when demand
1.228 + paging.
1.229 + */
1.230 + TInt32* iCodePageOffsets;
1.231 + /** Where (possibly compressed) object code starts in iFile. */
1.232 + TInt iCodeStartInFile;
1.233 + /** Length of (possibly compressed) object code in iFile. */
1.234 + TInt iCodeLengthInFile;
1.235 + /** Information about block map entries in iCodeBlockMapEntries. */
1.236 + SBlockMapInfoBase iCodeBlockMapCommon;
1.237 + /** Where object code is located on the media. */
1.238 + TBlockMapEntryBase* iCodeBlockMapEntries;
1.239 + /** Size of block map entry array in bytes. */
1.240 + TInt iCodeBlockMapEntriesSize;
1.241 + /**
1.242 + File clamp cookie, used to delete the file when the
1.243 + codeseg is destroyed.
1.244 + */
1.245 + RFileClamp iFileClamp;
1.246 +public:
1.247 + IMPORT_C TPtrC8 RootName() const;
1.248 + };
1.249 +
1.250 +//
1.251 +// Information required to create a new process
1.252 +//
1.253 +class TProcessCreateInfo : public TCodeSegCreateInfo
1.254 + {
1.255 +public:
1.256 + TInt iHeapSizeMin;
1.257 + TInt iHeapSizeMax;
1.258 + TInt iStackSize;
1.259 + TInt iClientHandle; // handle to loader's client
1.260 + TInt iProcessHandle; // handle to new DProcess
1.261 + TInt iFinalHandle; // handle from loader client to new process
1.262 + TOwnerType iOwnerType;
1.263 + TProcessPriority iPriority;
1.264 + TUint iSecurityZone;
1.265 + enum TDebugAttributes // must be the same as RLibrary::TInfoV2::TDebugAttributes
1.266 + {
1.267 + EDebugAllowed = 1<<0, ///< Flags set if executable may be debugged.
1.268 + ETraceAllowed = 1<<1 ///< Flags set if executable may be traced.
1.269 + };
1.270 + TUint iDebugAttributes;
1.271 + TRequestStatus* iDestructStat;
1.272 +
1.273 + };
1.274 +
1.275 +const TUint KSecurityZoneUnique = 0u;
1.276 +const TUint KSecurityZoneLegacyCode = ~0u;
1.277 +
1.278 +//
1.279 +// Information required to attach a code segment to a process
1.280 +// in the form of a library.
1.281 +//
1.282 +class TLibraryCreateInfo
1.283 + {
1.284 +public:
1.285 + TAny* iCodeSegHandle; // pointer to kernel-side DCodeSeg object
1.286 + TInt iClientHandle; // handle to loader's client
1.287 + TInt iLibraryHandle; // handle to new DLibrary
1.288 + TOwnerType iOwnerType;
1.289 + };
1.290 +
1.291 +//
1.292 +// Information required to find an existing code segment
1.293 +//
1.294 +class TFindCodeSeg
1.295 + {
1.296 +public:
1.297 + TUidType iUids; // required UIDs
1.298 + const TAny* iRomImgHdr; // ROM image header if ROM code required, NULL otherwise
1.299 + TUint32 iAttrMask; // mask for attributes
1.300 + TUint32 iAttrVal; // required value for masked attributes
1.301 + TInt iProcess; // handle to process in which code is required to operate
1.302 + // not used if kernel only specified
1.303 + SSecurityInfo iS; // required capabilities/SID
1.304 + TUint32 iModuleVersion; // required version
1.305 + TBuf8<KMaxLibraryName> iName; // name to look for - zero length means any
1.306 + };
1.307 +
1.308 +//
1.309 +// Information required to by the reaper from the codeseg.
1.310 +//
1.311 +struct TCodeSegLoaderCookie
1.312 + {
1.313 + RFileClamp iFileClamp;
1.314 + TInt64 iStartAddress;
1.315 + TInt iDriveNumber;
1.316 + };
1.317 +
1.318 +//
1.319 +// Loader magic executive functions
1.320 +//
1.321 +class E32Loader
1.322 + {
1.323 +public:
1.324 + // used by loader only
1.325 + IMPORT_C static TInt CodeSegCreate(TCodeSegCreateInfo& aInfo);
1.326 + IMPORT_C static TInt CodeSegLoaded(TCodeSegCreateInfo& aInfo);
1.327 + IMPORT_C static TInt LibraryCreate(TLibraryCreateInfo& aInfo);
1.328 + IMPORT_C static TInt CodeSegOpen(TAny* aHandle, TInt aClientProcessHandle);
1.329 + IMPORT_C static void CodeSegClose(TAny* aHandle);
1.330 + IMPORT_C static void CodeSegNext(TAny*& aHandle, const TFindCodeSeg& aFind);
1.331 + IMPORT_C static void CodeSegInfo(TAny* aHandle, TCodeSegCreateInfo& aInfo);
1.332 + IMPORT_C static TInt CodeSegAddDependency(TAny* aImporter, TAny* aExporter);
1.333 + IMPORT_C static void CodeSegDeferDeletes();
1.334 + IMPORT_C static void CodeSegEndDeferDeletes();
1.335 + IMPORT_C static TInt ProcessCreate(TProcessCreateInfo& aInfo, const TDesC8* aCommandLine);
1.336 + IMPORT_C static TInt ProcessLoaded(TProcessCreateInfo& aInfo);
1.337 + IMPORT_C static TInt CheckClientState(TInt aClientHandle);
1.338 + IMPORT_C static TInt DeviceLoad(TAny* aHandle, TInt aType);
1.339 + IMPORT_C static TAny* ThreadProcessCodeSeg(TInt aHandle);
1.340 + IMPORT_C static void ReadExportDir(TAny* aHandle, TUint32* aDest);
1.341 + IMPORT_C static TInt LocaleExports(TAny* aHandle, TLibraryFunction* aExportsList);
1.342 +
1.343 +#ifdef __MARM__
1.344 + IMPORT_C static void GetV7StubAddresses(TLinAddr& aExe, TLinAddr& aDll);
1.345 + static TInt V7ExeEntryStub();
1.346 + static TInt V7DllEntryStub(TInt aReason);
1.347 +#endif
1.348 +
1.349 + IMPORT_C static TUint32 PagingPolicy();
1.350 +
1.351 + IMPORT_C static TInt NotifyIfCodeSegDestroyed(TRequestStatus& aStatus);
1.352 + IMPORT_C static TInt GetDestroyedCodeSegInfo(TCodeSegLoaderCookie& aCookie);
1.353 +
1.354 +public:
1.355 + // used by client side
1.356 + static TInt WaitDllLock();
1.357 + static TInt ReleaseDllLock();
1.358 + static TInt LibraryAttach(TInt aHandle, TInt& aNumEps, TLinAddr* aEpList);
1.359 + static TInt LibraryAttached(TInt aHandle);
1.360 + static TInt StaticCallList(TInt& aNumEps, TLinAddr* aEpList);
1.361 + static TInt LibraryDetach(TInt& aNumEps, TLinAddr* aEpList);
1.362 + static TInt LibraryDetached();
1.363 + };
1.364 +
1.365 +typedef TInt (*TSupervisorFunction)(TAny*);
1.366 +
1.367 +// Relocation types
1.368 +/**
1.369 +@internalTechnology
1.370 +@released
1.371 +*/
1.372 +const TUint16 KReservedRelocType = (TUint16)0x0000;
1.373 +/**
1.374 +@internalTechnology
1.375 +@released
1.376 +*/
1.377 +const TUint16 KTextRelocType = (TUint16)0x1000;
1.378 +/**
1.379 +@internalTechnology
1.380 +@released
1.381 +*/
1.382 +const TUint16 KDataRelocType = (TUint16)0x2000;
1.383 +/**
1.384 +@internalTechnology
1.385 +@released
1.386 +*/
1.387 +const TUint16 KInferredRelocType = (TUint16)0x3000;
1.388 +
1.389 +// Compression types
1.390 +
1.391 +/**
1.392 +@internalTechnology
1.393 +@released
1.394 +*/
1.395 +const TUint KFormatNotCompressed=0;
1.396 +/**
1.397 +@internalTechnology
1.398 +@released
1.399 +*/
1.400 +const TUint KUidCompressionDeflate=0x101F7AFC;
1.401 +
1.402 +
1.403 +const TUint KUidCompressionBytePair=0x102822AA;
1.404 +
1.405 +
1.406 +#endif