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" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\e32ldr.h
29 const TInt KMaxLibraryEntryPoints=0x100;
32 // Loader version number.
34 const TInt KLoaderMajorVersionNumber=1;
35 const TInt KLoaderMinorVersionNumber=0;
38 // IPC messages to the loader
45 ELoadPhysicalDevice=4,
49 ELoaderDebugFunction=8,
51 EGetInfoFromHeader=10,
53 ELoaderCancelLazyDllUnload=12,
60 // Loader message arguments:
63 // 2 = Command line (process) or path (library)
68 IMPORT_C TLdrInfo(); // for BC
70 TUidType iRequestedUids;
71 TOwnerType iOwnerType;
74 TUint32 iRequestedVersion;
75 TInt iMinStackSize; // CR0885
79 #ifndef __KERNEL_MODE__
82 // Loader client class
84 class RLoader : public RSessionBase
87 IMPORT_C TInt Connect();
88 TVersion Version() const;
89 TInt LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TOwnerType aType);
90 IMPORT_C TInt LoadLibrary(TInt& aHandle, const TDesC& aFileName, const TDesC& aPath, const TUidType& aType, TUint32 aModuleVersion);
91 IMPORT_C TInt GetInfo(const TDesC& aFileName, TDes8& aInfoBuf);
92 TInt LoadDeviceDriver(const TDesC& aFileName, TInt aDeviceType);
93 IMPORT_C TInt DebugFunction(TInt aFunction, TInt a1, TInt a2, TInt a3);
94 TInt LoadLocale(const TDesC& aLocaleDllName, TLibraryFunction* aExportList);
95 TInt GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf);
96 IMPORT_C TInt CancelLazyDllUnload();
97 IMPORT_C TInt Delete(const TDesC& aFileName);
98 IMPORT_C TInt CheckLibraryHash(const TDesC& aFileName, TBool aValidateHash=EFalse);
99 TInt LoadProcess(TInt& aHandle, const TDesC& aFileName, const TDesC& aCommand, const TUidType& aUidType, TInt aMinStackSize, TOwnerType aType);
102 // workaround for possible EDG bug (!!)
103 inline TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
104 { return RSessionBase::SendReceive(aFunction, aArgs); }
106 using RSessionBase::SendReceive;
112 // Information required to create a new code segment
114 enum TCodeSegAttributes
116 ECodeSegAttKernel =0x00000001,
117 ECodeSegAttGlobal =0x00000002,
118 ECodeSegAttFixed =0x00000004,
119 ECodeSegAttABIMask =0x00000018, // same values as in image header
120 ECodeSegAttPaged =0x00000200, // the code seg is demand paged
121 ECodeSegAttHDll =(TInt)0x80000000,// Emulator host file type: 1=DLL, 0=EXE
122 ECodeSegAttExpVer =0x40000000, // Filename is explicitly versioned
123 ECodeSegAttNmdExpData=0x20000000 // Named symbol export data in code seg
126 class TBlockMapEntryBase
128 Where sections of a file are located on the media.
129 The kernel uses this to load in parts of a demand paged file.
133 TUint iNumberOfBlocks; // Number of contiguous blocks in map.
134 TUint iStartBlock; // Number for first block in the map.
137 struct SBlockMapInfoBase
139 Describes context for TBlockMapEntryBase objects.
142 TUint iBlockGranularity; // Size of a block in bytes.
143 TUint iBlockStartOffset; // Offset to start of the file or requested file position within a block.
144 TInt64 iStartBlockAddress; // Address of the first block of the partition.
145 TInt iLocalDriveNumber; // Local drive number of where the file lies on.
148 // forward declarations from file server
153 A Handle used to identify a file on storage media.
164 IMPORT_C TInt Clamp(RFile& aFile);
165 IMPORT_C TInt Close(RFs& aFs);
172 class TCodeSegCreateInfo
175 TBuf8<KMaxFileName> iFileName; // not including {MMMMmmmm} version info
176 TUidType iUids; // uid1 indicates EXE or DLL
183 TUint32 iEntryPtVeneer; // address of first instruction to be called
184 TUint32 iFileEntryPoint; // address of entry point within this code segment
187 TInt iExportDirCount;
188 TUint32 iCodeLoadAddress; // 0 for RAM loaded code, else pointer to TRomImageHeader
189 TUint32 iCodeRunAddress;
190 TUint32 iDataLoadAddress;
191 TUint32 iDataRunAddress;
192 TUint32 iExceptionDescriptor;
193 TInt iRootNameOffset;
194 TInt iRootNameLength;
196 TUint32 iModuleVersion;
198 TAny* iHandle; // pointer to kernel-side DCodeSeg object
199 TInt iClientProcessHandle; // handle to client process for user DLL loads
200 /** Code relocation information stored on loader heap. */
201 TUint32* iCodeRelocTable;
202 /** Size of code relocation table in bytes. */
203 TInt iCodeRelocTableSize;
204 /** Import fixup information stored on loader heap. */
205 TUint32* iImportFixupTable;
206 /** Size of import fixup table in bytes. */
207 TInt iImportFixupTableSize;
208 /** Offset to apply to each code address in the image when it is fixed up. */
210 /** Offset to apply to each data address in the image when it is fixed up. */
213 Whether the code is paged. If this is set, then
214 TCodeSegCreateInfo::iCodeRelocTable[Size] and
215 TCodeSegCreateInfo::iImportFixupTable[Size] contain fixup information
216 which the kernel uses to fix up each page.
217 (They may be null if the binary has no imports or no code section.)
219 TBool iUseCodePaging;
220 /** The UID of the compression scheme in use. */
221 TUint32 iCompressionType;
223 Start of compressed pages within the file. The kernel uses
224 this to load compressed pages from byte-pair files when demand
227 TInt32* iCodePageOffsets;
228 /** Where (possibly compressed) object code starts in iFile. */
229 TInt iCodeStartInFile;
230 /** Length of (possibly compressed) object code in iFile. */
231 TInt iCodeLengthInFile;
232 /** Information about block map entries in iCodeBlockMapEntries. */
233 SBlockMapInfoBase iCodeBlockMapCommon;
234 /** Where object code is located on the media. */
235 TBlockMapEntryBase* iCodeBlockMapEntries;
236 /** Size of block map entry array in bytes. */
237 TInt iCodeBlockMapEntriesSize;
239 File clamp cookie, used to delete the file when the
240 codeseg is destroyed.
242 RFileClamp iFileClamp;
244 IMPORT_C TPtrC8 RootName() const;
248 // Information required to create a new process
250 class TProcessCreateInfo : public TCodeSegCreateInfo
256 TInt iClientHandle; // handle to loader's client
257 TInt iProcessHandle; // handle to new DProcess
258 TInt iFinalHandle; // handle from loader client to new process
259 TOwnerType iOwnerType;
260 TProcessPriority iPriority;
262 enum TDebugAttributes // must be the same as RLibrary::TInfoV2::TDebugAttributes
264 EDebugAllowed = 1<<0, ///< Flags set if executable may be debugged.
265 ETraceAllowed = 1<<1 ///< Flags set if executable may be traced.
267 TUint iDebugAttributes;
268 TRequestStatus* iDestructStat;
272 const TUint KSecurityZoneUnique = 0u;
273 const TUint KSecurityZoneLegacyCode = ~0u;
276 // Information required to attach a code segment to a process
277 // in the form of a library.
279 class TLibraryCreateInfo
282 TAny* iCodeSegHandle; // pointer to kernel-side DCodeSeg object
283 TInt iClientHandle; // handle to loader's client
284 TInt iLibraryHandle; // handle to new DLibrary
285 TOwnerType iOwnerType;
289 // Information required to find an existing code segment
294 TUidType iUids; // required UIDs
295 const TAny* iRomImgHdr; // ROM image header if ROM code required, NULL otherwise
296 TUint32 iAttrMask; // mask for attributes
297 TUint32 iAttrVal; // required value for masked attributes
298 TInt iProcess; // handle to process in which code is required to operate
299 // not used if kernel only specified
300 SSecurityInfo iS; // required capabilities/SID
301 TUint32 iModuleVersion; // required version
302 TBuf8<KMaxLibraryName> iName; // name to look for - zero length means any
306 // Information required to by the reaper from the codeseg.
308 struct TCodeSegLoaderCookie
310 RFileClamp iFileClamp;
311 TInt64 iStartAddress;
316 // Loader magic executive functions
321 // used by loader only
322 IMPORT_C static TInt CodeSegCreate(TCodeSegCreateInfo& aInfo);
323 IMPORT_C static TInt CodeSegLoaded(TCodeSegCreateInfo& aInfo);
324 IMPORT_C static TInt LibraryCreate(TLibraryCreateInfo& aInfo);
325 IMPORT_C static TInt CodeSegOpen(TAny* aHandle, TInt aClientProcessHandle);
326 IMPORT_C static void CodeSegClose(TAny* aHandle);
327 IMPORT_C static void CodeSegNext(TAny*& aHandle, const TFindCodeSeg& aFind);
328 IMPORT_C static void CodeSegInfo(TAny* aHandle, TCodeSegCreateInfo& aInfo);
329 IMPORT_C static TInt CodeSegAddDependency(TAny* aImporter, TAny* aExporter);
330 IMPORT_C static void CodeSegDeferDeletes();
331 IMPORT_C static void CodeSegEndDeferDeletes();
332 IMPORT_C static TInt ProcessCreate(TProcessCreateInfo& aInfo, const TDesC8* aCommandLine);
333 IMPORT_C static TInt ProcessLoaded(TProcessCreateInfo& aInfo);
334 IMPORT_C static TInt CheckClientState(TInt aClientHandle);
335 IMPORT_C static TInt DeviceLoad(TAny* aHandle, TInt aType);
336 IMPORT_C static TAny* ThreadProcessCodeSeg(TInt aHandle);
337 IMPORT_C static void ReadExportDir(TAny* aHandle, TUint32* aDest);
338 IMPORT_C static TInt LocaleExports(TAny* aHandle, TLibraryFunction* aExportsList);
341 IMPORT_C static void GetV7StubAddresses(TLinAddr& aExe, TLinAddr& aDll);
342 static TInt V7ExeEntryStub();
343 static TInt V7DllEntryStub(TInt aReason);
346 IMPORT_C static TUint32 PagingPolicy();
348 IMPORT_C static TInt NotifyIfCodeSegDestroyed(TRequestStatus& aStatus);
349 IMPORT_C static TInt GetDestroyedCodeSegInfo(TCodeSegLoaderCookie& aCookie);
352 // used by client side
353 static TInt WaitDllLock();
354 static TInt ReleaseDllLock();
355 static TInt LibraryAttach(TInt aHandle, TInt& aNumEps, TLinAddr* aEpList);
356 static TInt LibraryAttached(TInt aHandle);
357 static TInt StaticCallList(TInt& aNumEps, TLinAddr* aEpList);
358 static TInt LibraryDetach(TInt& aNumEps, TLinAddr* aEpList);
359 static TInt LibraryDetached();
362 typedef TInt (*TSupervisorFunction)(TAny*);
369 const TUint16 KReservedRelocType = (TUint16)0x0000;
374 const TUint16 KTextRelocType = (TUint16)0x1000;
379 const TUint16 KDataRelocType = (TUint16)0x2000;
384 const TUint16 KInferredRelocType = (TUint16)0x3000;
392 const TUint KFormatNotCompressed=0;
397 const TUint KUidCompressionDeflate=0x101F7AFC;
400 const TUint KUidCompressionBytePair=0x102822AA;