author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:34:56 +0100 | |
branch | RCL_3 |
changeset 44 | 3e88ff8f41d5 |
parent 6 | 0173bcd7697c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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 |
// f32\sfile\sf_image.h |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#ifndef __SF_IMAGE_H__ |
|
19 |
#define __SF_IMAGE_H__ |
|
20 |
#include <f32file.h> |
|
21 |
#include <f32image.h> |
|
22 |
#include <e32ldr.h> |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
23 |
#include <e32ldr_private.h> |
0 | 24 |
#include <e32rom.h> |
25 |
#include "sf_deflate.h" |
|
26 |
||
27 |
_LIT(KLitLoader,"LOADER"); |
|
28 |
//__DATA_CAGING__ |
|
29 |
const TUint32 KCapabilityOffSet = 0x18; |
|
30 |
const TUint32 KCapabilityLength = 0x04; |
|
31 |
const TUint32 KCapabilityMask = 0x00000001; |
|
32 |
||
33 |
enum TPanic |
|
34 |
{ |
|
35 |
ELoadLibraryWithoutDllLock=0, |
|
36 |
}; |
|
37 |
||
38 |
class E32Image; |
|
39 |
class RImageArray : public RPointerArray<E32Image> |
|
40 |
{ |
|
41 |
public: |
|
42 |
RImageArray(); |
|
43 |
TInt Add(E32Image* aImage); |
|
44 |
void Find(const TDesC8& aRootName, TInt& aFirst, TInt& aLast) const; |
|
45 |
E32Image* Find(const TRomImageHeader* aRomImgHdr) const; |
|
46 |
}; |
|
47 |
||
48 |
class TFileNameInfo |
|
49 |
{ |
|
50 |
public: |
|
51 |
enum { |
|
52 |
EIncludeDrive=1, |
|
53 |
EIncludePath=2, |
|
54 |
EIncludeBase=4, |
|
55 |
EIncludeVer=8, |
|
56 |
EForceVer=16, |
|
57 |
EIncludeUid=32, |
|
58 |
EForceUid=64, |
|
59 |
EIncludeExt=128, |
|
60 |
EIncludeDrivePath=EIncludeDrive|EIncludePath, |
|
61 |
EIncludeBaseExt=EIncludeBase|EIncludeExt, |
|
62 |
EIncludeDrivePathBaseExt=EIncludeDrive|EIncludePath|EIncludeBase|EIncludeExt, |
|
63 |
}; |
|
64 |
enum { |
|
65 |
EAllowUid=1, |
|
66 |
EAllowPlaceholder=2, |
|
67 |
EAllowDecimalVersion=4, |
|
68 |
}; |
|
69 |
public: |
|
70 |
TFileNameInfo(); |
|
71 |
TInt Set(const TDesC8& aFileName, TUint aFlags); |
|
72 |
void Dump() const; |
|
73 |
public: |
|
74 |
inline TInt DriveLen() const {return iPathPos;} |
|
75 |
inline TInt PathLen() const {return iBasePos-iPathPos;} |
|
76 |
inline TInt BaseLen() const {return iVerPos-iBasePos;} |
|
77 |
inline TInt VerLen() const {return iUidPos-iVerPos;} |
|
78 |
inline TInt UidLen() const {return iExtPos-iUidPos;} |
|
79 |
inline TInt ExtLen() const {return iLen-iExtPos;} |
|
80 |
inline TPtrC8 Drive() const {return TPtrC8(iName, iPathPos);} |
|
81 |
inline TPtrC8 Path() const {return TPtrC8(iName+iPathPos, iBasePos-iPathPos);} |
|
82 |
inline TPtrC8 DriveAndPath() const {return TPtrC8(iName, iBasePos);} |
|
83 |
inline TPtrC8 Base() const {return TPtrC8(iName+iBasePos, iVerPos-iBasePos);} |
|
84 |
inline TPtrC8 VerStr() const {return TPtrC8(iName+iVerPos, iUidPos-iVerPos);} |
|
85 |
inline TPtrC8 UidStr() const {return TPtrC8(iName+iUidPos, iExtPos-iUidPos);} |
|
86 |
inline TPtrC8 Ext() const {return TPtrC8(iName+iExtPos, iLen-iExtPos);} |
|
87 |
inline TUint32 Version() const {return iVersion;} |
|
88 |
inline TUint32 Uid() const {return iUid;} |
|
89 |
void GetName(TDes8& aName, TUint aFlags) const; |
|
90 |
public: |
|
91 |
const TText8* iName; |
|
92 |
TInt iPathPos; |
|
93 |
TInt iBasePos; |
|
94 |
TInt iVerPos; |
|
95 |
TInt iUidPos; |
|
96 |
TInt iExtPos; |
|
97 |
TInt iLen; |
|
98 |
TUint32 iVersion; |
|
99 |
TUint32 iUid; |
|
100 |
}; |
|
101 |
||
102 |
class RLoaderMsg; |
|
103 |
||
104 |
// Information used to search for an image file |
|
105 |
class RLdrReq : public TLdrInfo |
|
106 |
{ |
|
107 |
public: |
|
108 |
RLdrReq(); |
|
109 |
void Close(); |
|
110 |
void Panic(TInt aPanic); |
|
111 |
TInt CheckForSubstDriveInName(); |
|
112 |
TInt CheckForSubstDrivesInPath(); |
|
113 |
TInt AddFileExtension(const TDesC8& aExt); |
|
114 |
void Dump(const char* aTitle) const; |
|
115 |
TInt CheckSecInfo(const SSecurityInfo& aCandidate) const; |
|
116 |
public: |
|
117 |
HBufC8* iFileName; |
|
118 |
HBufC8* iCmd; |
|
119 |
HBufC8* iPath; |
|
120 |
const RLoaderMsg* iMsg; |
|
121 |
SCapabilitySet iPlatSecCaps; |
|
122 |
RThread iClientThread; |
|
123 |
RProcess iClientProcess; |
|
124 |
TFileNameInfo iFileNameInfo; |
|
125 |
E32Image* iImporter; |
|
126 |
}; |
|
127 |
||
128 |
class RLoaderFile : public RFile |
|
129 |
{ |
|
130 |
public: |
|
131 |
inline TBool IsOpen() |
|
132 |
{ return Session().Handle() && SubSessionHandle(); } |
|
133 |
}; |
|
134 |
||
135 |
class TImageInfo |
|
136 |
{ |
|
137 |
public: |
|
138 |
TUint32 iUid[KMaxCheckedUid]; |
|
139 |
TUint32 iModuleVersion; |
|
140 |
SSecurityInfo iS; |
|
141 |
TUint32 iAttr; |
|
142 |
TUint16 iExportDirCount; |
|
143 |
TUint8 iExportDescType; |
|
144 |
TUint8 iNameLength; |
|
145 |
enum TCacheStatusFlags |
|
146 |
{ |
|
147 |
EHashChecked = 1, |
|
148 |
}; |
|
149 |
TUint8 iCacheStatus; |
|
150 |
// 8-bit name follows (store base+ext only, not version) |
|
151 |
// export description follows name |
|
152 |
}; |
|
153 |
||
154 |
// Information returned by a search for an image file |
|
155 |
class TFileCacheRecord; |
|
156 |
class RImageInfo : public TImageInfo |
|
157 |
{ |
|
158 |
public: |
|
159 |
RImageInfo(); |
|
160 |
RImageInfo& operator=(const TFileCacheRecord& aRecord); |
|
161 |
void Close(); |
|
162 |
void Accept(RImageInfo& aInfo); |
|
163 |
inline TBool FileOpened() { return ((RLoaderFile*)&iFile)->IsOpen(); } |
|
164 |
public: |
|
165 |
RFile iFile; |
|
166 |
E32ImageHeader* iHeader; // header if available |
|
167 |
TUint8* iFileData; // file data if it's been loaded |
|
168 |
TUint32 iFileSize; // size of loaded data |
|
169 |
const TRomImageHeader* iRomImageHeader; // pointer to ROM image header for XIP |
|
170 |
TUint16 iExportDescSize; |
|
171 |
const TUint8* iExportDesc; // points into cache record so only valid during a single directory search |
|
172 |
TUint8 iNeedHashCheck; // true if hash check was skipped and must be done at load time |
|
173 |
}; |
|
174 |
||
175 |
// Image finder - looks at candidates for a load and remembers the best one |
|
176 |
class RImageFinder |
|
177 |
{ |
|
178 |
public: |
|
179 |
RImageFinder(); |
|
180 |
TInt Set(const RLdrReq& aReq); |
|
181 |
void Close(); |
|
182 |
TInt Search(); |
|
183 |
TInt Search(const TDesC8* aPath, TInt aDrive); |
|
184 |
TInt SearchSingleDir(); |
|
185 |
TInt SearchExisting(const RImageArray& aArray); |
|
186 |
TInt Try(RImageInfo& aInfo, const TDesC8& aRootName, const TDesC8& aDriveAndPath); |
|
187 |
void RecordCorruptFile(); |
|
188 |
void SetName(const TDesC8& aRootName, const TDesC8& aDriveAndPath); |
|
189 |
void Dump(const char* aTitle, TInt aR); |
|
190 |
void CompareHashL(RImageInfo& aInfo, const TDesC8& aDriveAndPath); |
|
191 |
public: |
|
192 |
TInt iNameMatches; // number of files for which name matches |
|
193 |
TInt iUidFail; // number of files for which UIDs are incompatible |
|
194 |
TInt iCapFail; // number of files for which capabilities/SID are incompatible |
|
195 |
TInt iMajorVersionFail; // number of files with lower major version than requested |
|
196 |
TInt iImportFail; // number of files which failed import check |
|
197 |
TUint32 iCurrentVersion; // version of current best match |
|
198 |
TPtrC8 iCurrentPath; // current search directory |
|
199 |
TUint8 iCurrentDrive; // current search drive |
|
200 |
TUint8 iFindExact; |
|
201 |
TUint8 iNewValid; // a valid new image has been found |
|
202 |
const RLdrReq* iReq; |
|
203 |
E32Image* iExisting; // pointer to existing image if that is currently the best |
|
204 |
RImageInfo iNew; // new image info if that is currently the best |
|
205 |
TBuf8<KMaxFileName> iNewFileName; // full path name for new image file |
|
206 |
TBuf8<KMaxKernelName> iRootName; |
|
207 |
}; |
|
208 |
||
209 |
extern RFs gTheLoaderFs; |
|
210 |
extern TAny* gExeCodeSeg; |
|
211 |
extern TUint32 gExeAttr; |
|
212 |
extern TAny* gKernelCodeSeg; |
|
213 |
extern TUint32 gKernelAttr; |
|
214 |
extern TBool gExecutesInSupervisorMode; |
|
215 |
||
216 |
TInt GetModuleInfo(RLdrReq& aReq); |
|
217 |
TInt GetInfoFromHeader(const RLoaderMsg& aMsg); |
|
218 |
TInt CheckSystemBin(const TDesC& aThePath); |
|
219 |
TInt LoadProcess(RLdrReq& aReq); |
|
220 |
TInt LoadLibrary(RLdrReq& aReq); |
|
221 |
TInt LoadDeviceDriver(RLdrReq& aReq, TInt aDeviceType); |
|
222 |
TInt LoadLocale(RLdrReq& aReq, TLibraryFunction* aExportsList); |
|
223 |
TInt CheckUids(const TUidType& aUids, const TUidType& aRequestedUids); |
|
224 |
TInt OpenFile8(RFile& aFile, const TDesC8& aName); |
|
225 |
TInt CheckSubstDrive(TDes8& aDest, const TDesC8& aSrc); |
|
226 |
TInt CompareVersions(TUint32 aL, TUint32 aR); |
|
227 |
TInt CheckRequiredImports(E32Image* aImporter, E32Image* aExporter, TInt aAction); |
|
228 |
TInt CheckRequiredImports(E32Image* aImporter, const RImageInfo& aExporter, TInt aAction); |
|
229 |
TInt CheckedCollapse(TDes8& aDest, const TDesC16& aSrc); |
|
230 |
||
231 |
||
232 |
enum TVersionCompareResult |
|
233 |
{ |
|
234 |
EVersion_MinorBigger=0, |
|
235 |
EVersion_Exact, |
|
236 |
EVersion_MajorBigger, |
|
237 |
EVersion_MinorSmaller, |
|
238 |
EVersion_MajorSmaller, |
|
239 |
}; |
|
240 |
||
241 |
TInt DetailedCompareVersions(TUint32 aCandidate, TUint32 aRequest); |
|
242 |
TInt DetailedCompareVersions(TUint32 aCandidate, TUint32 aRequest, TUint32 aCurrent, TBool aStrict); |
|
243 |
||
244 |
enum TVersionCompareAction |
|
245 |
{ |
|
246 |
EAction_Skip=0, |
|
247 |
EAction_CheckLastImport, |
|
248 |
EAction_CheckImports, |
|
249 |
EAction_Replace, |
|
250 |
}; |
|
251 |
||
252 |
||
253 |
||
254 |
class E32Image : public TProcessCreateInfo |
|
255 |
{ |
|
256 |
public: |
|
257 |
E32Image(); |
|
258 |
~E32Image(); |
|
259 |
void Reset(); |
|
260 |
||
261 |
TInt Construct(RImageFinder& aFinder); |
|
262 |
void Construct(const TRomImageHeader& a); |
|
263 |
TInt OpenFile(); |
|
264 |
||
265 |
TBool AlwaysLoaded(); |
|
266 |
||
267 |
TInt LoadProcess(const RLdrReq& aReq); |
|
268 |
TInt LoadCodeSeg(const RLdrReq& aReq); |
|
269 |
TInt DoLoadCodeSeg(const RLdrReq& aReq, RImageFinder& aFinder); |
|
270 |
TInt DoLoadCodeSeg(const TRomImageHeader& aRomImgHdr); |
|
271 |
TInt CheckAlreadyLoaded(); |
|
272 |
TInt CheckRomXIPAlreadyLoaded(); |
|
273 |
TInt ProcessFileName(); |
|
274 |
void GetRomFileName(); |
|
275 |
static TBool TraverseDirs(const TRomDir& aDir, const TRomImageHeader* aHdr, TDes8& aName); |
|
276 |
||
277 |
TInt LoadToRam(); |
|
278 |
TInt LoadFile(); |
|
279 |
TInt LoadFileNoCompress(); |
|
280 |
TInt Read(TUint aPos,TUint8* aDest,TUint aSize,TBool aSvPerms=EFalse); |
|
281 |
void LoadFileInflateL(); |
|
282 |
void LoadFileBytePairUnpakL(); |
|
283 |
TInt RelocateCode(); |
|
284 |
TInt RelocateExports(); |
|
285 |
TInt LoadAndRelocateData(); |
|
286 |
TInt RelocateSection(E32RelocSection* aSection, TUint32 aLoadAddress); |
|
287 |
static TUint8* WordCopy(TAny* aDestination, const TAny* aSource, TInt aNumberOfBytes); |
|
288 |
static TUint8* MemCopy(TAny* aDestination, const TAny* aSource, TInt aNumberOfBytes); |
|
289 |
TInt ReadImportData(); |
|
290 |
||
291 |
TInt ProcessImports(); |
|
292 |
||
293 |
TInt LoadDlls(RImageArray& aDllArray); |
|
294 |
TInt GetCurrentImportList(const E32ImportBlock* aBlock); |
|
295 |
static TInt FixupDlls(RImageArray& aDllArray); |
|
296 |
TUint64* ExpandFixups(TInt aNumFixups); |
|
297 |
TInt FinaliseDlls(RImageArray& aDllArray); |
|
298 |
void CleanupDlls(RImageArray& aDllArray); |
|
299 |
||
300 |
TInt LastCurrentImport(); |
|
301 |
void SortCurrentImportList(); |
|
302 |
static TInt Order(const E32Image& aL, const E32Image& aR); |
|
303 |
TInt ReadExportDirLoad(); |
|
304 |
||
305 |
// for demand paging... |
|
306 |
TInt ShouldBeCodePaged(TBool& aPage); |
|
307 |
TInt LoadCompressionData(); |
|
308 |
TInt LoadCompressionDataNoCompress(); |
|
309 |
void LoadCompressionDataBytePairUnpakL(); |
|
310 |
TInt BuildCodeBlockMap(); |
|
311 |
TInt AllocateRelocationData(E32RelocSection* aSection, TUint32 aAreaSize, TUint32 aLoadAddress, TUint32*& aProcessedBlock); |
|
312 |
TInt BuildImportFixupTable(); |
|
313 |
public: |
|
314 |
const TRomImageHeader* iRomImageHeader; |
|
315 |
E32ImageHeader* iHeader; |
|
316 |
E32RelocSection* iCodeRelocSection; // address within iRestOfFileData |
|
317 |
E32RelocSection* iDataRelocSection; // address within iRestOfFileData |
|
318 |
TUint32* iImportData; |
|
319 |
TUint8* iRestOfFileData; // buffer holding all file data after code section |
|
320 |
TUint32 iRestOfFileSize; // size of data at iRestOfFileData |
|
321 |
TUint32 iConversionOffset; |
|
322 |
RFile iFile; |
|
323 |
TUint8* iFileData; // file data if it's been loaded |
|
324 |
TUint32 iFileSize; // size of loaded data |
|
325 |
TUint32* iCopyOfExportDir; |
|
326 |
TUint32 iExportDirLoad; |
|
327 |
TUint32 iExportDirEntryDelta; // value to add to all values read from iExportDirLoad |
|
328 |
E32Image* iMain; |
|
329 |
TAny* iCloseCodeSeg; |
|
330 |
TInt iCurrentImportCount; |
|
331 |
TInt iNextImportPos; |
|
332 |
TUint32* iCurrentImportList; |
|
333 |
TUint8 iCurrentImportListSorted; |
|
334 |
TUint8 iIsDll; |
|
335 |
TUint8 iAlreadyLoaded; |
|
336 |
TUint8 iPadding2; |
|
337 |
TInt iFixupCount; // number of fixups in iFixups |
|
338 |
TUint64* iFixups; // array of fixups to apply to demand paged code {addr,value} pairs |
|
339 |
}; |
|
340 |
||
341 |
||
342 |
inline TBool CheckUid(TUint32 aUid, TUint32 aRequestedUid) |
|
343 |
{ |
|
344 |
return (aRequestedUid==0 || aRequestedUid==aUid); |
|
345 |
} |
|
346 |
||
347 |
||
348 |
#endif |