sl@0: // Copyright (c) 1995-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\include\e32ldr_private.h sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #ifndef __E32LDR_PRIVATE_H__ sl@0: #define __E32LDR_PRIVATE_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: sl@0: const TInt KMaxLibraryEntryPoints=0x100; sl@0: sl@0: // sl@0: // Loader version number. sl@0: // sl@0: const TInt KLoaderMajorVersionNumber=1; sl@0: const TInt KLoaderMinorVersionNumber=0; sl@0: sl@0: // sl@0: // IPC messages to the loader sl@0: // sl@0: enum TLoaderMsg sl@0: { sl@0: ELoadProcess=1, sl@0: ELoadLibrary=2, sl@0: ELoadLogicalDevice=3, sl@0: ELoadPhysicalDevice=4, sl@0: ELoadLocale=5, sl@0: ELoadFileSystem=6, sl@0: EGetInfo=7, sl@0: ELoaderDebugFunction=8, sl@0: ELoadFSExtension=9, sl@0: EGetInfoFromHeader=10, sl@0: ELoadFSPlugin=11, sl@0: ELoaderCancelLazyDllUnload=12, sl@0: ELdrDelete=13, sl@0: ECheckLibraryHash=14, sl@0: ELoadFSProxyDrive=15, sl@0: ELoadCodePage=16, sl@0: EMaxLoaderMsg sl@0: }; sl@0: // sl@0: // Loader message arguments: sl@0: // 0 = TLdrInfo sl@0: // 1 = Filename sl@0: // 2 = Command line (process) or path (library) sl@0: // sl@0: class TLdrInfo sl@0: { sl@0: public: sl@0: IMPORT_C TLdrInfo(); // for BC sl@0: public: sl@0: TUidType iRequestedUids; sl@0: TOwnerType iOwnerType; sl@0: TInt iHandle; sl@0: TUint32 iSecureId; sl@0: TUint32 iRequestedVersion; sl@0: TInt iMinStackSize; // Size of new process stack sl@0: }; sl@0: sl@0: sl@0: #ifndef __KERNEL_MODE__ sl@0: #include sl@0: // sl@0: // Loader client class sl@0: // sl@0: class RLoader : public RSessionBase sl@0: { sl@0: public: sl@0: IMPORT_C TInt Connect(); sl@0: TVersion Version() const; sl@0: TInt LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TOwnerType aType); sl@0: IMPORT_C TInt LoadLibrary(TInt& aHandle, const TDesC& aFileName, const TDesC& aPath, const TUidType& aType, TUint32 aModuleVersion); sl@0: IMPORT_C TInt GetInfo(const TDesC& aFileName, TDes8& aInfoBuf); sl@0: TInt LoadDeviceDriver(const TDesC& aFileName, TInt aDeviceType); sl@0: IMPORT_C TInt DebugFunction(TInt aFunction, TInt a1, TInt a2, TInt a3); sl@0: TInt LoadLocale(const TDesC& aLocaleDllName, TLibraryFunction* aExportList); sl@0: TInt GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf); sl@0: IMPORT_C TInt CancelLazyDllUnload(); sl@0: IMPORT_C TInt Delete(const TDesC& aFileName); sl@0: IMPORT_C TInt CheckLibraryHash(const TDesC& aFileName, TBool aValidateHash=EFalse); sl@0: TInt LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TInt aMinStackSize, TOwnerType aType); sl@0: public: sl@0: #ifdef __ARMCC__ sl@0: // workaround for possible EDG bug (!!) sl@0: inline TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const sl@0: { return RSessionBase::SendReceive(aFunction, aArgs); } sl@0: #else sl@0: using RSessionBase::SendReceive; sl@0: #endif sl@0: }; sl@0: #endif sl@0: sl@0: // sl@0: // Information required to create a new code segment sl@0: // sl@0: enum TCodeSegAttributes sl@0: { sl@0: ECodeSegAttKernel =0x00000001, sl@0: ECodeSegAttGlobal =0x00000002, sl@0: ECodeSegAttFixed =0x00000004, sl@0: ECodeSegAttABIMask =0x00000018, // same values as in image header sl@0: ECodeSegAttCodePaged =0x00000200, // the code seg is demand paged sl@0: ECodeSegAttDataPaged =0x00002000, // the code seg static data is demand paged sl@0: ECodeSegAttHDll =(TInt)0x80000000,// Emulator host file type: 1=DLL, 0=EXE sl@0: ECodeSegAttExpVer =0x40000000, // Filename is explicitly versioned sl@0: ECodeSegAttNmdExpData =0x20000000, // Named symbol export data in code seg sl@0: ECodeSegAttSMPSafe =0x10000000, // code seg and its static dependencies are SMP safe sl@0: ECodeSegAttAddrNotUnique =0x08000000, // run address not globally unique (may overlap other codesegs) sl@0: }; sl@0: sl@0: // forward declarations from file server sl@0: class RFile; sl@0: class RFs; sl@0: sl@0: /** sl@0: A Handle used to identify a file on storage media. sl@0: @internalTechnology sl@0: */ sl@0: class RFileClamp sl@0: { sl@0: public: sl@0: inline RFileClamp() sl@0: { sl@0: iCookie[0] = 0; sl@0: iCookie[1] = 0; sl@0: } sl@0: IMPORT_C TInt Clamp(RFile& aFile); sl@0: IMPORT_C TInt Close(RFs& aFs); sl@0: sl@0: public: sl@0: TInt64 iCookie[2]; sl@0: }; sl@0: sl@0: sl@0: class TCodeSegCreateInfo sl@0: { sl@0: public: sl@0: TBuf8 iFileName; // not including {MMMMmmmm} version info sl@0: TUidType iUids; // uid1 indicates EXE or DLL sl@0: TUint32 iAttr; sl@0: TInt iCodeSize; sl@0: TInt iTextSize; sl@0: TInt iDataSize; sl@0: TInt iBssSize; sl@0: TInt iTotalDataSize; sl@0: TUint32 iEntryPtVeneer; // address of first instruction to be called sl@0: TUint32 iFileEntryPoint; // address of entry point within this code segment sl@0: TInt iDepCount; sl@0: TUint32 iExportDir; sl@0: TInt iExportDirCount; sl@0: TUint32 iCodeLoadAddress; // 0 for RAM loaded code, else pointer to TRomImageHeader sl@0: TUint32 iCodeRunAddress; sl@0: TUint32 iDataLoadAddress; sl@0: TUint32 iDataRunAddress; sl@0: TUint32 iExceptionDescriptor; sl@0: TInt iRootNameOffset; sl@0: TInt iRootNameLength; sl@0: TInt iExtOffset; sl@0: TUint32 iModuleVersion; sl@0: SSecurityInfo iS; sl@0: TAny* iHandle; // pointer to kernel-side DCodeSeg object sl@0: TInt iClientProcessHandle; // handle to client process for user DLL loads sl@0: /** Code relocation information stored on loader heap. */ sl@0: TUint32* iCodeRelocTable; sl@0: /** Size of code relocation table in bytes. */ sl@0: TInt iCodeRelocTableSize; sl@0: /** Import fixup information stored on loader heap. */ sl@0: TUint32* iImportFixupTable; sl@0: /** Size of import fixup table in bytes. */ sl@0: TInt iImportFixupTableSize; sl@0: /** Offset to apply to each code address in the image when it is fixed up. */ sl@0: TUint32 iCodeDelta; sl@0: /** Offset to apply to each data address in the image when it is fixed up. */ sl@0: TUint32 iDataDelta; sl@0: /** sl@0: Whether the code is paged. If this is set, then sl@0: TCodeSegCreateInfo::iCodeRelocTable[Size] and sl@0: TCodeSegCreateInfo::iImportFixupTable[Size] contain fixup information sl@0: which the kernel uses to fix up each page. sl@0: (They may be null if the binary has no imports or no code section.) sl@0: */ sl@0: TBool iUseCodePaging; sl@0: /** The UID of the compression scheme in use. */ sl@0: TUint32 iCompressionType; sl@0: /** sl@0: Start of compressed pages within the file. The kernel uses sl@0: this to load compressed pages from byte-pair files when demand sl@0: paging. sl@0: */ sl@0: TInt32* iCodePageOffsets; sl@0: /** Where (possibly compressed) object code starts in iFile. */ sl@0: TInt iCodeStartInFile; sl@0: /** Length of (possibly compressed) object code in iFile. */ sl@0: TInt iCodeLengthInFile; sl@0: /** Information about block map entries in iCodeBlockMapEntries. */ sl@0: SBlockMapInfoBase iCodeBlockMapCommon; sl@0: /** Where object code is located on the media. */ sl@0: TBlockMapEntryBase* iCodeBlockMapEntries; sl@0: /** Size of block map entry array in bytes. */ sl@0: TInt iCodeBlockMapEntriesSize; sl@0: /** sl@0: File clamp cookie, used to delete the file when the sl@0: codeseg is destroyed. sl@0: */ sl@0: RFileClamp iFileClamp; sl@0: public: sl@0: IMPORT_C TPtrC8 RootName() const; sl@0: }; sl@0: sl@0: // sl@0: // Information required to create a new process sl@0: // sl@0: class TProcessCreateInfo : public TCodeSegCreateInfo sl@0: { sl@0: public: sl@0: enum TDebugAttributes // must be the same as RLibrary::TInfoV2::TDebugAttributes sl@0: { sl@0: EDebugAllowed = 1<<0, ///< Flags set if executable may be debugged. sl@0: ETraceAllowed = 1<<1 ///< Flags set if executable may be traced. sl@0: }; sl@0: /** sl@0: The flags for process's creation. Will be set by the loader from the images sl@0: header flags ready for the kernel to use. sl@0: */ sl@0: enum TProcessCreateFlags sl@0: { sl@0: EDataPagingUnspecified = 0x00000000, ///< Use the global data paging default. sl@0: EDataPaged = 0x00000001, ///< Page the process's data by default. sl@0: EDataUnpaged = 0x00000002, ///< Don't page the process's data by default. sl@0: EDataPagingMask = 0x00000003, ///< Bit mask ofr data paging flags. sl@0: }; sl@0: sl@0: /** Default constructor that ensures flags are clear. */ sl@0: TProcessCreateInfo() : iFlags(0) {}; sl@0: sl@0: TInt iHeapSizeMin; sl@0: TInt iHeapSizeMax; sl@0: TInt iStackSize; sl@0: TInt iClientHandle; // handle to loader's client sl@0: TInt iProcessHandle; // handle to new DProcess sl@0: TInt iFinalHandle; // handle from loader client to new process sl@0: TOwnerType iOwnerType; sl@0: TProcessPriority iPriority; sl@0: TUint iSecurityZone; sl@0: TUint iDebugAttributes; ///< Set with values from TDebugAttributes. sl@0: TRequestStatus* iDestructStat; sl@0: TUint iFlags; ///< Flags for process creation, should set from TProcessCreateFlags. sl@0: }; sl@0: sl@0: const TUint KSecurityZoneUnique = 0u; sl@0: const TUint KSecurityZoneLegacyCode = ~0u; sl@0: sl@0: // sl@0: // Information required to attach a code segment to a process sl@0: // in the form of a library. sl@0: // sl@0: class TLibraryCreateInfo sl@0: { sl@0: public: sl@0: TAny* iCodeSegHandle; // pointer to kernel-side DCodeSeg object sl@0: TInt iClientHandle; // handle to loader's client sl@0: TInt iLibraryHandle; // handle to new DLibrary sl@0: TOwnerType iOwnerType; sl@0: }; sl@0: sl@0: // sl@0: // Information required to find an existing code segment sl@0: // sl@0: class TFindCodeSeg sl@0: { sl@0: public: sl@0: TUidType iUids; // required UIDs sl@0: const TAny* iRomImgHdr; // ROM image header if ROM code required, NULL otherwise sl@0: TUint32 iAttrMask; // mask for attributes sl@0: TUint32 iAttrVal; // required value for masked attributes sl@0: TInt iProcess; // handle to process in which code is required to operate sl@0: // not used if kernel only specified sl@0: SSecurityInfo iS; // required capabilities/SID sl@0: TUint32 iModuleVersion; // required version sl@0: TBuf8 iName; // name to look for - zero length means any sl@0: }; sl@0: sl@0: // sl@0: // Information required to by the reaper from the codeseg. sl@0: // sl@0: struct TCodeSegLoaderCookie sl@0: { sl@0: RFileClamp iFileClamp; sl@0: TInt64 iStartAddress; sl@0: TInt iDriveNumber; sl@0: }; sl@0: sl@0: // sl@0: // Loader magic executive functions sl@0: // sl@0: class E32Loader sl@0: { sl@0: public: sl@0: // used by loader only sl@0: IMPORT_C static TInt CodeSegCreate(TCodeSegCreateInfo& aInfo); sl@0: IMPORT_C static TInt CodeSegLoaded(TCodeSegCreateInfo& aInfo); sl@0: IMPORT_C static TInt LibraryCreate(TLibraryCreateInfo& aInfo); sl@0: IMPORT_C static TInt CodeSegOpen(TAny* aHandle, TInt aClientProcessHandle); sl@0: IMPORT_C static void CodeSegClose(TAny* aHandle); sl@0: IMPORT_C static void CodeSegNext(TAny*& aHandle, const TFindCodeSeg& aFind); sl@0: IMPORT_C static void CodeSegInfo(TAny* aHandle, TCodeSegCreateInfo& aInfo); sl@0: IMPORT_C static TInt CodeSegAddDependency(TAny* aImporter, TAny* aExporter); sl@0: IMPORT_C static void CodeSegDeferDeletes(); sl@0: IMPORT_C static void CodeSegEndDeferDeletes(); sl@0: IMPORT_C static TInt ProcessCreate(TProcessCreateInfo& aInfo, const TDesC8* aCommandLine); sl@0: IMPORT_C static TInt ProcessLoaded(TProcessCreateInfo& aInfo); sl@0: IMPORT_C static TInt CheckClientState(TInt aClientHandle); sl@0: IMPORT_C static TInt DeviceLoad(TAny* aHandle, TInt aType); sl@0: IMPORT_C static TAny* ThreadProcessCodeSeg(TInt aHandle); sl@0: IMPORT_C static void ReadExportDir(TAny* aHandle, TUint32* aDest); sl@0: IMPORT_C static TInt LocaleExports(TAny* aHandle, TLibraryFunction* aExportsList); sl@0: sl@0: #ifdef __MARM__ sl@0: IMPORT_C static void GetV7StubAddresses(TLinAddr& aExe, TLinAddr& aDll); sl@0: static TInt V7ExeEntryStub(); sl@0: static TInt V7DllEntryStub(TInt aReason); sl@0: #endif sl@0: sl@0: IMPORT_C static TUint32 PagingPolicy(); sl@0: sl@0: IMPORT_C static TInt NotifyIfCodeSegDestroyed(TRequestStatus& aStatus); sl@0: IMPORT_C static TInt GetDestroyedCodeSegInfo(TCodeSegLoaderCookie& aCookie); sl@0: sl@0: public: sl@0: // used by client side sl@0: static TInt WaitDllLock(); sl@0: static TInt ReleaseDllLock(); sl@0: static TInt LibraryAttach(TInt aHandle, TInt& aNumEps, TLinAddr* aEpList); sl@0: static TInt LibraryAttached(TInt aHandle); sl@0: static TInt StaticCallList(TInt& aNumEps, TLinAddr* aEpList); sl@0: static TInt LibraryDetach(TInt& aNumEps, TLinAddr* aEpList); sl@0: static TInt LibraryDetached(); sl@0: }; sl@0: sl@0: typedef TInt (*TSupervisorFunction)(TAny*); sl@0: sl@0: // Relocation types sl@0: /** sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: const TUint16 KReservedRelocType = (TUint16)0x0000; sl@0: /** sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: const TUint16 KTextRelocType = (TUint16)0x1000; sl@0: /** sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: const TUint16 KDataRelocType = (TUint16)0x2000; sl@0: /** sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: const TUint16 KInferredRelocType = (TUint16)0x3000; sl@0: sl@0: // Compression types sl@0: sl@0: /** sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: const TUint KFormatNotCompressed=0; sl@0: /** sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: const TUint KUidCompressionDeflate=0x101F7AFC; sl@0: sl@0: sl@0: const TUint KUidCompressionBytePair=0x102822AA; sl@0: sl@0: sl@0: #endif // __E32LDR_PRIVATE_H__ sl@0: