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