|
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". |
|
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 |
|
20 /** |
|
21 @file |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #ifndef __E32LDR_H__ |
|
26 #define __E32LDR_H__ |
|
27 #include <e32cmn.h> |
|
28 |
|
29 const TInt KMaxLibraryEntryPoints=0x100; |
|
30 |
|
31 // |
|
32 // Loader version number. |
|
33 // |
|
34 const TInt KLoaderMajorVersionNumber=1; |
|
35 const TInt KLoaderMinorVersionNumber=0; |
|
36 |
|
37 // |
|
38 // IPC messages to the loader |
|
39 // |
|
40 enum TLoaderMsg |
|
41 { |
|
42 ELoadProcess=1, |
|
43 ELoadLibrary=2, |
|
44 ELoadLogicalDevice=3, |
|
45 ELoadPhysicalDevice=4, |
|
46 ELoadLocale=5, |
|
47 ELoadFileSystem=6, |
|
48 EGetInfo=7, |
|
49 ELoaderDebugFunction=8, |
|
50 ELoadFSExtension=9, |
|
51 EGetInfoFromHeader=10, |
|
52 ELoadFSPlugin=11, |
|
53 ELoaderCancelLazyDllUnload=12, |
|
54 ELdrDelete=13, |
|
55 ECheckLibraryHash=14, |
|
56 |
|
57 EMaxLoaderMsg |
|
58 }; |
|
59 // |
|
60 // Loader message arguments: |
|
61 // 0 = TLdrInfo |
|
62 // 1 = Filename |
|
63 // 2 = Command line (process) or path (library) |
|
64 // |
|
65 class TLdrInfo |
|
66 { |
|
67 public: |
|
68 IMPORT_C TLdrInfo(); // for BC |
|
69 public: |
|
70 TUidType iRequestedUids; |
|
71 TOwnerType iOwnerType; |
|
72 TInt iHandle; |
|
73 TUint32 iSecureId; |
|
74 TUint32 iRequestedVersion; |
|
75 TInt iMinStackSize; // CR0885 |
|
76 }; |
|
77 |
|
78 |
|
79 #ifndef __KERNEL_MODE__ |
|
80 #include <e32std.h> |
|
81 // |
|
82 // Loader client class |
|
83 // |
|
84 class RLoader : public RSessionBase |
|
85 { |
|
86 public: |
|
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); |
|
100 public: |
|
101 #ifdef __ARMCC__ |
|
102 // workaround for possible EDG bug (!!) |
|
103 inline TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const |
|
104 { return RSessionBase::SendReceive(aFunction, aArgs); } |
|
105 #else |
|
106 using RSessionBase::SendReceive; |
|
107 #endif |
|
108 }; |
|
109 #endif |
|
110 |
|
111 // |
|
112 // Information required to create a new code segment |
|
113 // |
|
114 enum TCodeSegAttributes |
|
115 { |
|
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 |
|
124 }; |
|
125 |
|
126 class TBlockMapEntryBase |
|
127 /** |
|
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. |
|
130 */ |
|
131 { |
|
132 public: |
|
133 TUint iNumberOfBlocks; // Number of contiguous blocks in map. |
|
134 TUint iStartBlock; // Number for first block in the map. |
|
135 }; |
|
136 |
|
137 struct SBlockMapInfoBase |
|
138 /** |
|
139 Describes context for TBlockMapEntryBase objects. |
|
140 */ |
|
141 { |
|
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. |
|
146 }; |
|
147 |
|
148 // forward declarations from file server |
|
149 class RFile; |
|
150 class RFs; |
|
151 |
|
152 /** |
|
153 A Handle used to identify a file on storage media. |
|
154 @internalTechnology |
|
155 */ |
|
156 class RFileClamp |
|
157 { |
|
158 public: |
|
159 inline RFileClamp() |
|
160 { |
|
161 iCookie[0] = 0; |
|
162 iCookie[1] = 0; |
|
163 } |
|
164 IMPORT_C TInt Clamp(RFile& aFile); |
|
165 IMPORT_C TInt Close(RFs& aFs); |
|
166 |
|
167 public: |
|
168 TInt64 iCookie[2]; |
|
169 }; |
|
170 |
|
171 |
|
172 class TCodeSegCreateInfo |
|
173 { |
|
174 public: |
|
175 TBuf8<KMaxFileName> iFileName; // not including {MMMMmmmm} version info |
|
176 TUidType iUids; // uid1 indicates EXE or DLL |
|
177 TUint32 iAttr; |
|
178 TInt iCodeSize; |
|
179 TInt iTextSize; |
|
180 TInt iDataSize; |
|
181 TInt iBssSize; |
|
182 TInt iTotalDataSize; |
|
183 TUint32 iEntryPtVeneer; // address of first instruction to be called |
|
184 TUint32 iFileEntryPoint; // address of entry point within this code segment |
|
185 TInt iDepCount; |
|
186 TUint32 iExportDir; |
|
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; |
|
195 TInt iExtOffset; |
|
196 TUint32 iModuleVersion; |
|
197 SSecurityInfo iS; |
|
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. */ |
|
209 TUint32 iCodeDelta; |
|
210 /** Offset to apply to each data address in the image when it is fixed up. */ |
|
211 TUint32 iDataDelta; |
|
212 /** |
|
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.) |
|
218 */ |
|
219 TBool iUseCodePaging; |
|
220 /** The UID of the compression scheme in use. */ |
|
221 TUint32 iCompressionType; |
|
222 /** |
|
223 Start of compressed pages within the file. The kernel uses |
|
224 this to load compressed pages from byte-pair files when demand |
|
225 paging. |
|
226 */ |
|
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; |
|
238 /** |
|
239 File clamp cookie, used to delete the file when the |
|
240 codeseg is destroyed. |
|
241 */ |
|
242 RFileClamp iFileClamp; |
|
243 public: |
|
244 IMPORT_C TPtrC8 RootName() const; |
|
245 }; |
|
246 |
|
247 // |
|
248 // Information required to create a new process |
|
249 // |
|
250 class TProcessCreateInfo : public TCodeSegCreateInfo |
|
251 { |
|
252 public: |
|
253 TInt iHeapSizeMin; |
|
254 TInt iHeapSizeMax; |
|
255 TInt iStackSize; |
|
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; |
|
261 TUint iSecurityZone; |
|
262 enum TDebugAttributes // must be the same as RLibrary::TInfoV2::TDebugAttributes |
|
263 { |
|
264 EDebugAllowed = 1<<0, ///< Flags set if executable may be debugged. |
|
265 ETraceAllowed = 1<<1 ///< Flags set if executable may be traced. |
|
266 }; |
|
267 TUint iDebugAttributes; |
|
268 TRequestStatus* iDestructStat; |
|
269 |
|
270 }; |
|
271 |
|
272 const TUint KSecurityZoneUnique = 0u; |
|
273 const TUint KSecurityZoneLegacyCode = ~0u; |
|
274 |
|
275 // |
|
276 // Information required to attach a code segment to a process |
|
277 // in the form of a library. |
|
278 // |
|
279 class TLibraryCreateInfo |
|
280 { |
|
281 public: |
|
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; |
|
286 }; |
|
287 |
|
288 // |
|
289 // Information required to find an existing code segment |
|
290 // |
|
291 class TFindCodeSeg |
|
292 { |
|
293 public: |
|
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 |
|
303 }; |
|
304 |
|
305 // |
|
306 // Information required to by the reaper from the codeseg. |
|
307 // |
|
308 struct TCodeSegLoaderCookie |
|
309 { |
|
310 RFileClamp iFileClamp; |
|
311 TInt64 iStartAddress; |
|
312 TInt iDriveNumber; |
|
313 }; |
|
314 |
|
315 // |
|
316 // Loader magic executive functions |
|
317 // |
|
318 class E32Loader |
|
319 { |
|
320 public: |
|
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); |
|
339 |
|
340 #ifdef __MARM__ |
|
341 IMPORT_C static void GetV7StubAddresses(TLinAddr& aExe, TLinAddr& aDll); |
|
342 static TInt V7ExeEntryStub(); |
|
343 static TInt V7DllEntryStub(TInt aReason); |
|
344 #endif |
|
345 |
|
346 IMPORT_C static TUint32 PagingPolicy(); |
|
347 |
|
348 IMPORT_C static TInt NotifyIfCodeSegDestroyed(TRequestStatus& aStatus); |
|
349 IMPORT_C static TInt GetDestroyedCodeSegInfo(TCodeSegLoaderCookie& aCookie); |
|
350 |
|
351 public: |
|
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(); |
|
360 }; |
|
361 |
|
362 typedef TInt (*TSupervisorFunction)(TAny*); |
|
363 |
|
364 // Relocation types |
|
365 /** |
|
366 @internalTechnology |
|
367 @released |
|
368 */ |
|
369 const TUint16 KReservedRelocType = (TUint16)0x0000; |
|
370 /** |
|
371 @internalTechnology |
|
372 @released |
|
373 */ |
|
374 const TUint16 KTextRelocType = (TUint16)0x1000; |
|
375 /** |
|
376 @internalTechnology |
|
377 @released |
|
378 */ |
|
379 const TUint16 KDataRelocType = (TUint16)0x2000; |
|
380 /** |
|
381 @internalTechnology |
|
382 @released |
|
383 */ |
|
384 const TUint16 KInferredRelocType = (TUint16)0x3000; |
|
385 |
|
386 // Compression types |
|
387 |
|
388 /** |
|
389 @internalTechnology |
|
390 @released |
|
391 */ |
|
392 const TUint KFormatNotCompressed=0; |
|
393 /** |
|
394 @internalTechnology |
|
395 @released |
|
396 */ |
|
397 const TUint KUidCompressionDeflate=0x101F7AFC; |
|
398 |
|
399 |
|
400 const TUint KUidCompressionBytePair=0x102822AA; |
|
401 |
|
402 |
|
403 #endif |