293
|
1 |
// Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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_ldr.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "sf_std.h"
|
|
19 |
#include <f32image.h>
|
|
20 |
#include "sf_image.h"
|
|
21 |
#include "sf_cache.h"
|
|
22 |
#include "sf_ldr.h"
|
|
23 |
#include <e32uid.h>
|
|
24 |
#include <hal.h>
|
|
25 |
|
|
26 |
|
|
27 |
#ifdef _DEBUG
|
|
28 |
#define IF_DEBUG(x) x
|
|
29 |
TInt KernHeapFailCount=0;
|
|
30 |
TInt LdrHeapFailCount=0;
|
|
31 |
TInt HeapFailActive=0;
|
|
32 |
void SetupHeapFail(const RMessage2& aMsg);
|
|
33 |
void EndHeapFailCheck(TInt);
|
|
34 |
TInt RFsFailCount=0;
|
|
35 |
TInt RFsErrorCode=0;
|
|
36 |
TBool RFsFailActive=0;
|
|
37 |
void SetupRFsFail(const RMessage2& aMsg);
|
|
38 |
void EndRFsFailCheck(TInt);
|
|
39 |
TRequestStatus ProcessDestructStat;
|
|
40 |
TRequestStatus* ProcessDestructStatPtr=0;
|
|
41 |
TBool ProcessCreated=EFalse;
|
|
42 |
#else
|
|
43 |
#define IF_DEBUG(x)
|
|
44 |
#endif
|
|
45 |
TInt DoLoaderDebugFunction(const RMessage2& aMsg);
|
|
46 |
|
|
47 |
|
|
48 |
//#define __TRACE_LOADER_HEAP__
|
|
49 |
|
|
50 |
class RLoaderFs : public RFs
|
|
51 |
{
|
|
52 |
public:
|
|
53 |
inline TInt SendReceive(TInt aFunction, const TIpcArgs& aArgs) const
|
|
54 |
{ return RSessionBase::SendReceive(aFunction, aArgs); }
|
|
55 |
};
|
|
56 |
|
|
57 |
static TInt CheckLibraryHash(RLdrReq& aReq);
|
|
58 |
const TInt KPriorityVeryHigh=14641;
|
|
59 |
|
|
60 |
GLDEF_D RFs gTheLoaderFs;
|
|
61 |
GLDEF_D TAny* gExeCodeSeg;
|
|
62 |
GLDEF_D TUint32 gExeAttr;
|
|
63 |
GLDEF_D TAny* gKernelCodeSeg;
|
|
64 |
GLDEF_D TUint32 gKernelAttr;
|
|
65 |
GLDEF_D SSecurityInfo gKernelSecInfo;
|
|
66 |
GLDEF_D TBool gExecutesInSupervisorMode;
|
|
67 |
GLDEF_D TAny* gFileServerCodeSeg;
|
|
68 |
GLDEF_D TUint32 gFileServerAttr;
|
|
69 |
GLDEF_D SSecurityInfo gFileServerSecInfo;
|
|
70 |
GLDEF_D CActiveReaper* gActiveReaper=NULL;
|
|
71 |
|
|
72 |
CSlottedChunkAllocator gFileDataAllocator;
|
|
73 |
|
|
74 |
|
|
75 |
GLREF_D TCodePageUtils TheCodePage;
|
|
76 |
|
|
77 |
|
|
78 |
_LIT(KDriveSystemRoot, "?:\\");
|
|
79 |
_LIT(KLoaderThreadName, "LoaderThread");
|
|
80 |
_LIT8(KFileExtensionExe,".EXE");
|
|
81 |
_LIT8(KFileExtensionDll,".DLL");
|
|
82 |
_LIT8(KFileExtensionLdd,".LDD");
|
|
83 |
_LIT8(KFileExtensionPdd,".PDD");
|
|
84 |
_LIT8(KFileExtensionFsy,".FSY");
|
|
85 |
_LIT8(KFileExtensionFxt,".FXT");
|
|
86 |
_LIT8(KFileExtensionPxt,".PXT");
|
|
87 |
_LIT8(KFileExtensionPxy,".PXY");
|
|
88 |
_LIT(KPathDel,"?:\\sys\\del\\");
|
|
89 |
const TInt KPathDelLength = 11;
|
|
90 |
const TInt KExtensionLength=4;
|
|
91 |
|
|
92 |
#if defined(__EPOC32__) && defined(__X86__)
|
|
93 |
TInt UseFloppy;
|
|
94 |
#endif
|
|
95 |
|
|
96 |
/******************************************************************************
|
|
97 |
* Loader top level stuff
|
|
98 |
******************************************************************************/
|
|
99 |
|
|
100 |
TUint32 GetCodeSegAttr(TAny* aCodeSeg, SSecurityInfo* aS, TUint32* aVer)
|
|
101 |
{
|
|
102 |
TCodeSegCreateInfo info;
|
|
103 |
E32Loader::CodeSegInfo(aCodeSeg, info);
|
|
104 |
if (aS)
|
|
105 |
*aS = info.iS;
|
|
106 |
if (aVer)
|
|
107 |
*aVer = info.iModuleVersion;
|
|
108 |
return info.iAttr;
|
|
109 |
}
|
|
110 |
|
|
111 |
#ifdef __EPOC32__
|
|
112 |
extern void InitExecuteInSupervisorMode();
|
|
113 |
#endif
|
|
114 |
|
|
115 |
_LIT(KNullThreadName,"EKern*Null");
|
|
116 |
void GetKernelInfo()
|
|
117 |
{
|
|
118 |
TFindThread ft(KNullThreadName);
|
|
119 |
TFullName fn;
|
|
120 |
TInt r = ft.Next(fn);
|
|
121 |
if (r==KErrNone)
|
|
122 |
{
|
|
123 |
RThread null;
|
|
124 |
r = null.Open(ft);
|
|
125 |
if (r==KErrNone)
|
|
126 |
{
|
|
127 |
gKernelCodeSeg = E32Loader::ThreadProcessCodeSeg(null.Handle());
|
|
128 |
if (gKernelCodeSeg)
|
|
129 |
{
|
|
130 |
gKernelAttr = GetCodeSegAttr(gKernelCodeSeg, &gKernelSecInfo, NULL);
|
|
131 |
__IF_DEBUG(Printf("gKernelCodeSeg=%08x", gKernelCodeSeg));
|
|
132 |
__IF_DEBUG(Printf("gKernelAttr=%08x", gKernelAttr));
|
|
133 |
}
|
|
134 |
else
|
|
135 |
r=KErrGeneral;
|
|
136 |
null.Close();
|
|
137 |
}
|
|
138 |
}
|
|
139 |
if (r==KErrNone)
|
|
140 |
{
|
|
141 |
gFileServerCodeSeg = E32Loader::ThreadProcessCodeSeg(KCurrentThreadHandle);
|
|
142 |
if (gFileServerCodeSeg)
|
|
143 |
{
|
|
144 |
gFileServerAttr = GetCodeSegAttr(gFileServerCodeSeg, &gFileServerSecInfo, NULL);
|
|
145 |
__IF_DEBUG(Printf("gFileServerCodeSeg=%08x", gFileServerCodeSeg));
|
|
146 |
__IF_DEBUG(Printf("gFileServerAttr=%08x", gFileServerAttr));
|
|
147 |
}
|
|
148 |
else
|
|
149 |
r=KErrGeneral;
|
|
150 |
}
|
|
151 |
|
|
152 |
#ifdef __EPOC32__
|
|
153 |
InitExecuteInSupervisorMode();
|
|
154 |
#else
|
|
155 |
// When running on the emulator the loader can access all memory so effectively it is
|
|
156 |
// running in supervisor mode.
|
|
157 |
gExecutesInSupervisorMode = ETrue;
|
|
158 |
#endif
|
|
159 |
|
|
160 |
__ASSERT_ALWAYS(r==KErrNone, Fault(ELdrGetKernelInfoFailed));
|
|
161 |
}
|
|
162 |
|
|
163 |
|
|
164 |
#ifdef __TRACE_LOADER_HEAP__
|
|
165 |
void InstallHeapTracer();
|
|
166 |
#endif
|
|
167 |
|
|
168 |
|
|
169 |
#ifdef __LAZY_DLL_UNLOAD
|
|
170 |
const TInt KLoaderLazyDllDurationDefault=120; // 120 seconds default
|
|
171 |
TInt KLoaderLazyDllDuration=KLoaderLazyDllDurationDefault;
|
|
172 |
CLazyUnloadTimer* LazyUnloadTimer=NULL;
|
|
173 |
|
|
174 |
void CLazyUnloadTimer::New()
|
|
175 |
//
|
|
176 |
// Create a new CLazyUnloadTimer.
|
|
177 |
//
|
|
178 |
{
|
|
179 |
|
|
180 |
CLazyUnloadTimer* lazyUnloadTimer=new CLazyUnloadTimer;
|
|
181 |
if(lazyUnloadTimer)
|
|
182 |
{
|
|
183 |
TRAPD(err,lazyUnloadTimer->ConstructL());
|
|
184 |
if(err==KErrNone)
|
|
185 |
{
|
|
186 |
lazyUnloadTimer->Start();
|
|
187 |
}
|
|
188 |
else
|
|
189 |
{
|
|
190 |
delete lazyUnloadTimer;
|
|
191 |
}
|
|
192 |
}
|
|
193 |
}
|
|
194 |
|
|
195 |
CLazyUnloadTimer::CLazyUnloadTimer()
|
|
196 |
//
|
|
197 |
// Constructor
|
|
198 |
//
|
|
199 |
: CTimer(EPriorityIdle)
|
|
200 |
{
|
|
201 |
Finish();
|
|
202 |
LazyUnloadTimer = this;
|
|
203 |
if (KLoaderLazyDllDuration < 0)
|
|
204 |
KLoaderLazyDllDuration = KLoaderLazyDllDurationDefault;
|
|
205 |
}
|
|
206 |
|
|
207 |
CLazyUnloadTimer::~CLazyUnloadTimer()
|
|
208 |
{
|
|
209 |
LazyUnloadTimer = NULL;
|
|
210 |
}
|
|
211 |
|
|
212 |
void CLazyUnloadTimer::Start()
|
|
213 |
{
|
|
214 |
E32Loader::CodeSegDeferDeletes();
|
|
215 |
CActiveScheduler::Add(this);
|
|
216 |
TTimeIntervalMicroSeconds32 timeout=KLoaderLazyDllDuration*1000000;
|
|
217 |
After(timeout);
|
|
218 |
}
|
|
219 |
|
|
220 |
void CLazyUnloadTimer::RunL()
|
|
221 |
//
|
|
222 |
// The timer has completed.
|
|
223 |
//
|
|
224 |
{
|
|
225 |
E32Loader::CodeSegEndDeferDeletes();
|
|
226 |
delete this;
|
|
227 |
}
|
|
228 |
|
|
229 |
void CLazyUnloadTimer::Finish()
|
|
230 |
{
|
|
231 |
if(LazyUnloadTimer)
|
|
232 |
{
|
|
233 |
LazyUnloadTimer->Cancel();
|
|
234 |
LazyUnloadTimer->RunL();
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
#endif
|
|
239 |
|
|
240 |
/* ReaperCleanupTimer - Used to clear /sys/del/ shortly after boot. */
|
|
241 |
|
|
242 |
const TInt KLoaderReaperCleanupTimeDefault=60; // 60 seconds default
|
|
243 |
TInt KLoaderReaperCleanupTime=KLoaderReaperCleanupTimeDefault;
|
|
244 |
CReaperCleanupTimer* CReaperCleanupTimer::Timer=NULL;
|
|
245 |
|
|
246 |
TInt CReaperCleanupTimer::New()
|
|
247 |
//
|
|
248 |
// Create a new CReaperCleanupTimer.
|
|
249 |
//
|
|
250 |
{
|
|
251 |
if (Timer)
|
|
252 |
return KErrInUse;
|
|
253 |
|
|
254 |
CReaperCleanupTimer* timer=new CReaperCleanupTimer;
|
|
255 |
if(timer)
|
|
256 |
{
|
|
257 |
TRAPD(err,Timer->ConstructL());
|
|
258 |
if(err==KErrNone)
|
|
259 |
{
|
|
260 |
Timer->Start();
|
|
261 |
return KErrNone;
|
|
262 |
}
|
|
263 |
else
|
|
264 |
{
|
|
265 |
delete Timer;
|
|
266 |
return err;
|
|
267 |
}
|
|
268 |
}
|
|
269 |
return KErrNoMemory;
|
|
270 |
}
|
|
271 |
|
|
272 |
CReaperCleanupTimer::CReaperCleanupTimer()
|
|
273 |
: CTimer(EPriorityIdle)
|
|
274 |
{
|
|
275 |
Timer=this;
|
|
276 |
}
|
|
277 |
|
|
278 |
CReaperCleanupTimer::~CReaperCleanupTimer()
|
|
279 |
{
|
|
280 |
Timer = NULL;
|
|
281 |
}
|
|
282 |
|
|
283 |
void CReaperCleanupTimer::Start()
|
|
284 |
{
|
|
285 |
CActiveScheduler::Add(this);
|
|
286 |
TTimeIntervalMicroSeconds32 timeout=KLoaderReaperCleanupTime*1000000;
|
|
287 |
After(timeout);
|
|
288 |
}
|
|
289 |
|
|
290 |
void CReaperCleanupTimer::RunL()
|
|
291 |
{
|
|
292 |
if (gActiveReaper)
|
|
293 |
gActiveReaper->InitDelDir();
|
|
294 |
delete this;
|
|
295 |
}
|
|
296 |
|
|
297 |
void CReaperCleanupTimer::Complete()
|
|
298 |
{
|
|
299 |
if(Timer)
|
|
300 |
{
|
|
301 |
Timer->Cancel();
|
|
302 |
Timer->RunL();
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
GLDEF_C TInt LoaderThread(TAny*)
|
|
307 |
//
|
|
308 |
// The loader thread.
|
|
309 |
//
|
|
310 |
{
|
|
311 |
#ifdef __TRACE_LOADER_HEAP__
|
|
312 |
InstallHeapTracer();
|
|
313 |
#endif
|
|
314 |
|
|
315 |
TInt r;
|
|
316 |
__IF_DEBUG(Printf("LoaderThread"));
|
|
317 |
User::SetCritical(User::ESystemCritical);
|
|
318 |
GetKernelInfo();
|
|
319 |
|
|
320 |
CServerLoader* serverLoader;
|
|
321 |
CActiveSchedulerLoader* scheduler;
|
|
322 |
|
|
323 |
CTrapCleanup* cleanup=CTrapCleanup::New();
|
|
324 |
__ASSERT_ALWAYS(cleanup!=NULL, Fault(ELdrCleanupCreate));
|
|
325 |
scheduler=CActiveSchedulerLoader::New();
|
|
326 |
__ASSERT_ALWAYS(scheduler!=NULL, Fault(ELdrSchedulerCreate));
|
|
327 |
serverLoader=CServerLoader::New();
|
|
328 |
__ASSERT_ALWAYS(serverLoader!=NULL, Fault(ELdrServerCreate));
|
|
329 |
|
|
330 |
RThread::Rendezvous(KErrNone);
|
|
331 |
r=gTheLoaderFs.Connect();
|
|
332 |
__ASSERT_ALWAYS(r==KErrNone, Fault(ELdrFsConnect));
|
|
333 |
TBuf<sizeof(KDriveSystemRoot)> driveSystemRoot(KDriveSystemRoot);
|
|
334 |
driveSystemRoot[0] = (TUint8) RFs::GetSystemDriveChar();
|
|
335 |
r=gTheLoaderFs.SetSessionPath(driveSystemRoot);
|
|
336 |
__ASSERT_ALWAYS(r==KErrNone, Fault(ELdrFsSetPath));
|
|
337 |
|
|
338 |
#ifdef __EPOC32__
|
|
339 |
InitializeFileNameCache();
|
|
340 |
|
|
341 |
r=gFileDataAllocator.Construct();
|
|
342 |
__ASSERT_ALWAYS(r==KErrNone, Fault(ELdrFileDataAllocInit));
|
|
343 |
#endif
|
|
344 |
|
|
345 |
#ifdef __LAZY_DLL_UNLOAD
|
|
346 |
CLazyUnloadTimer::New();
|
|
347 |
#endif
|
|
348 |
|
|
349 |
gActiveReaper = CActiveReaper::New();
|
|
350 |
__ASSERT_ALWAYS(gActiveReaper!=NULL, Fault(ELdrReaperCreate));
|
|
351 |
|
|
352 |
r=CReaperCleanupTimer::New();
|
|
353 |
__ASSERT_ALWAYS(r==KErrNone, Fault(ELdrReaperCleanupTimerCreate));
|
|
354 |
|
|
355 |
CActiveSchedulerLoader::Start();
|
|
356 |
Fault(ELdrSchedulerStopped);
|
|
357 |
return 0;
|
|
358 |
}
|
|
359 |
|
|
360 |
TInt InitLoader()
|
|
361 |
{
|
|
362 |
|
|
363 |
TRequestStatus lts;
|
|
364 |
RThread loaderThread;
|
|
365 |
RHeap* h = (RHeap*)&User::Allocator();
|
|
366 |
TInt maxsize = h->MaxLength(); // loader heap max size = file server heap max size
|
|
367 |
TInt r=loaderThread.Create(KLoaderThreadName,LoaderThread,KLoaderStackSize,KHeapMinSize,maxsize,NULL);
|
|
368 |
if (r!=KErrNone)
|
|
369 |
{
|
|
370 |
return r;
|
|
371 |
}
|
|
372 |
loaderThread.Rendezvous(lts);
|
|
373 |
loaderThread.Resume();
|
|
374 |
User::WaitForRequest(lts);
|
|
375 |
loaderThread.Close();
|
|
376 |
return lts.Int();
|
|
377 |
}
|
|
378 |
|
|
379 |
TInt CompareVersions(TUint32 aL, TUint32 aR)
|
|
380 |
{
|
|
381 |
if (aL>aR)
|
|
382 |
return 1;
|
|
383 |
if (aL<aR)
|
|
384 |
return -1;
|
|
385 |
return 0;
|
|
386 |
}
|
|
387 |
|
|
388 |
TInt DetailedCompareVersions(TUint32 aCandidate, TUint32 aRequest)
|
|
389 |
{
|
|
390 |
if (aRequest == KModuleVersionNull)
|
|
391 |
return EVersion_MinorBigger;
|
|
392 |
if (aCandidate == KModuleVersionNull)
|
|
393 |
return EVersion_MajorSmaller;
|
|
394 |
TUint32 C = aCandidate >> 16;
|
|
395 |
TUint32 c = aCandidate & 0x0000ffffu;
|
|
396 |
TUint32 R = aRequest >> 16;
|
|
397 |
TUint32 r = aRequest & 0x0000ffffu;
|
|
398 |
if (C==R)
|
|
399 |
{
|
|
400 |
if (c>r)
|
|
401 |
return EVersion_MinorBigger;
|
|
402 |
if (c==r)
|
|
403 |
return EVersion_Exact;
|
|
404 |
return EVersion_MinorSmaller;
|
|
405 |
}
|
|
406 |
if (C>R)
|
|
407 |
return EVersion_MajorBigger;
|
|
408 |
return EVersion_MajorSmaller;
|
|
409 |
}
|
|
410 |
|
|
411 |
TInt DetailedCompareVersions(TUint32 aCandidate, TUint32 aRequest, TUint32 aCurrent, TBool aStrict)
|
|
412 |
{
|
|
413 |
TInt cvc = DetailedCompareVersions(aCandidate, aCurrent);
|
|
414 |
if (aRequest == KModuleVersionWild)
|
|
415 |
{
|
|
416 |
return (cvc == EVersion_MinorBigger || cvc == EVersion_MajorBigger) ? EAction_Replace : EAction_Skip;
|
|
417 |
}
|
|
418 |
TInt candidate_state = DetailedCompareVersions(aCandidate, aRequest);
|
|
419 |
if (aStrict)
|
|
420 |
{
|
|
421 |
if (candidate_state > EVersion_Exact)
|
|
422 |
return EAction_Skip; // no match
|
|
423 |
if (cvc == EVersion_MinorBigger)
|
|
424 |
return EAction_Replace; // later minor version so take it
|
|
425 |
return EAction_Skip; // same or earlier minor version
|
|
426 |
}
|
|
427 |
TInt current_state = DetailedCompareVersions(aCurrent, aRequest);
|
|
428 |
if (candidate_state < current_state)
|
|
429 |
{
|
|
430 |
// better match
|
|
431 |
if (candidate_state <= EVersion_Exact)
|
|
432 |
return EAction_Replace;
|
|
433 |
return (candidate_state == EVersion_MajorBigger) ? EAction_CheckImports : EAction_CheckLastImport;
|
|
434 |
}
|
|
435 |
if (candidate_state > current_state)
|
|
436 |
return EAction_Skip; // worse match
|
|
437 |
// match state same
|
|
438 |
// skip if (i) state=exact
|
|
439 |
// (ii) state=major smaller
|
|
440 |
// replace if (i) state=minor bigger and candidate minor > current minor
|
|
441 |
// (ii) state=minor smaller and candidate minor > current minor
|
|
442 |
// (iii) state=major bigger, candidate major=current major and candidate minor > current minor
|
|
443 |
// check if (i) state=major bigger and candidate major < current major
|
|
444 |
switch (candidate_state)
|
|
445 |
{
|
|
446 |
case EVersion_MinorBigger:
|
|
447 |
case EVersion_MinorSmaller:
|
|
448 |
return (cvc == EVersion_MinorBigger) ? EAction_Replace : EAction_Skip;
|
|
449 |
case EVersion_MajorBigger:
|
|
450 |
if (cvc == EVersion_MinorBigger)
|
|
451 |
return EAction_Replace;
|
|
452 |
return (cvc == EVersion_MajorSmaller) ? EAction_CheckImports : EAction_Skip;
|
|
453 |
default:
|
|
454 |
return EAction_Skip;
|
|
455 |
}
|
|
456 |
}
|
|
457 |
|
|
458 |
TFileNameInfo::TFileNameInfo()
|
|
459 |
{
|
|
460 |
memclr(this, sizeof(TFileNameInfo));
|
|
461 |
}
|
|
462 |
|
|
463 |
TInt TFileNameInfo::Set(const TDesC8& aFileName, TUint aFlags)
|
|
464 |
{
|
|
465 |
__IF_DEBUG(Printf(">TFileNameInfo::Set %S %08x", &aFileName, aFlags));
|
|
466 |
iUid = 0;
|
|
467 |
iVersion = 0;
|
|
468 |
iPathPos = 0;
|
|
469 |
iName = aFileName.Ptr();
|
|
470 |
iLen = aFileName.Length();
|
|
471 |
iExtPos = aFileName.LocateReverse('.');
|
|
472 |
if (iExtPos<0)
|
|
473 |
iExtPos = iLen;
|
|
474 |
TInt osq = aFileName.LocateReverse('[');
|
|
475 |
TInt csq = aFileName.LocateReverse(']');
|
|
476 |
if (!(aFlags & EAllowUid) && (osq>=0 || csq>=0))
|
|
477 |
{
|
|
478 |
__IF_DEBUG(Printf("<TFileNameInfo::Set BadName1"));
|
|
479 |
return KErrBadName;
|
|
480 |
}
|
|
481 |
if (osq>=iExtPos || csq>=iExtPos)
|
|
482 |
{
|
|
483 |
__IF_DEBUG(Printf("<TFileNameInfo::Set BadName2"));
|
|
484 |
return KErrBadName;
|
|
485 |
}
|
|
486 |
TInt p = iExtPos;
|
|
487 |
if ((aFlags & EAllowUid) && p>=10 && iName[p-1]==']' && iName[p-10]=='[')
|
|
488 |
{
|
|
489 |
TPtrC8 uidstr(iName + p - 9, 8);
|
|
490 |
TLex8 uidlex(uidstr);
|
|
491 |
TUint32 uid = 0;
|
|
492 |
TInt r = uidlex.Val(uid, EHex);
|
|
493 |
if (r==KErrNone && uidlex.Eos())
|
|
494 |
iUid = uid, p -= 10;
|
|
495 |
}
|
|
496 |
iUidPos = p;
|
|
497 |
TInt ob = aFileName.LocateReverse('{');
|
|
498 |
TInt cb = aFileName.LocateReverse('}');
|
|
499 |
if (ob>=iUidPos || cb>=iUidPos)
|
|
500 |
{
|
|
501 |
__IF_DEBUG(Printf("<TFileNameInfo::Set BadName3"));
|
|
502 |
return KErrBadName;
|
|
503 |
}
|
|
504 |
if (ob>=0 && cb>=0 && p-1==cb)
|
|
505 |
{
|
|
506 |
TPtrC8 p8(iName, p);
|
|
507 |
TInt d = p8.LocateReverse('.');
|
|
508 |
TPtrC8 verstr(iName+ob+1, p-ob-2);
|
|
509 |
TLex8 verlex(verstr);
|
|
510 |
if (ob==p-10 && d<ob)
|
|
511 |
{
|
|
512 |
TUint32 ver = 0;
|
|
513 |
TInt r = verlex.Val(ver, EHex);
|
|
514 |
if (r==KErrNone && verlex.Eos())
|
|
515 |
iVersion = ver, p = ob;
|
|
516 |
}
|
|
517 |
else if (d>ob && p-1>d && (aFlags & EAllowDecimalVersion))
|
|
518 |
{
|
|
519 |
TUint32 maj = 0;
|
|
520 |
TUint32 min = 0;
|
|
521 |
TInt r = verlex.Val(maj, EDecimal);
|
|
522 |
TUint c = (TUint)verlex.Get();
|
|
523 |
TInt r2 = verlex.Val(min, EDecimal);
|
|
524 |
if (r==KErrNone && c=='.' && r2==KErrNone && verlex.Eos() && maj<32768 && min<32768)
|
|
525 |
iVersion = (maj << 16) | min, p = ob;
|
|
526 |
}
|
|
527 |
}
|
|
528 |
iVerPos = p;
|
|
529 |
if (iLen>=2 && iName[1]==':')
|
|
530 |
{
|
|
531 |
TUint c = iName[0];
|
|
532 |
if (c!='?' || !(aFlags & EAllowPlaceholder))
|
|
533 |
{
|
|
534 |
c |= 0x20;
|
|
535 |
if (c<'a' || c>'z')
|
|
536 |
{
|
|
537 |
__IF_DEBUG(Printf("<TFileNameInfo::Set BadName4"));
|
|
538 |
return KErrBadName;
|
|
539 |
}
|
|
540 |
}
|
|
541 |
iPathPos = 2;
|
|
542 |
}
|
|
543 |
TPtrC8 pathp(iName+iPathPos, iVerPos-iPathPos);
|
|
544 |
if (pathp.Locate('[')>=0 || pathp.Locate(']')>=0 || pathp.Locate('{')>=0 || pathp.Locate('}')>=0 || pathp.Locate(':')>=0)
|
|
545 |
{
|
|
546 |
__IF_DEBUG(Printf("<TFileNameInfo::Set BadName5"));
|
|
547 |
return KErrBadName;
|
|
548 |
}
|
|
549 |
iBasePos = pathp.LocateReverse('\\') + 1 + iPathPos;
|
|
550 |
__IF_DEBUG(Printf("<TFileNameInfo::Set OK"));
|
|
551 |
__LDRTRACE(Dump());
|
|
552 |
return KErrNone;
|
|
553 |
}
|
|
554 |
|
|
555 |
void TFileNameInfo::GetName(TDes8& aName, TUint aFlags) const
|
|
556 |
{
|
|
557 |
if (aFlags & EIncludeDrive)
|
|
558 |
aName.Append(Drive());
|
|
559 |
if (aFlags & EIncludePath)
|
|
560 |
{
|
|
561 |
if (PathLen() && iName[iPathPos]!='\\')
|
|
562 |
aName.Append('\\');
|
|
563 |
aName.Append(Path());
|
|
564 |
}
|
|
565 |
if (aFlags & EIncludeBase)
|
|
566 |
aName.Append(Base());
|
|
567 |
if ((aFlags & EForceVer) || ((aFlags & EIncludeVer) && VerLen()) )
|
|
568 |
{
|
|
569 |
aName.Append('{');
|
|
570 |
aName.AppendNumFixedWidth(iVersion, EHex, 8);
|
|
571 |
aName.Append('}');
|
|
572 |
}
|
|
573 |
if ((aFlags & EForceUid) || ((aFlags & EIncludeUid) && UidLen()) )
|
|
574 |
{
|
|
575 |
aName.Append('[');
|
|
576 |
aName.AppendNumFixedWidth(iUid, EHex, 8);
|
|
577 |
aName.Append(']');
|
|
578 |
}
|
|
579 |
if (aFlags & EIncludeExt)
|
|
580 |
aName.Append(Ext());
|
|
581 |
}
|
|
582 |
|
|
583 |
TInt OpenFile8(RFile& aFile, const TDesC8& aName)
|
|
584 |
{
|
|
585 |
TFileName fn;
|
|
586 |
fn.Copy(aName);
|
|
587 |
TInt r = aFile.Open(gTheLoaderFs, fn, EFileStream|EFileRead|EFileShareReadersOnly|EFileReadDirectIO);
|
|
588 |
return r;
|
|
589 |
}
|
|
590 |
|
|
591 |
RLdrReq::RLdrReq()
|
|
592 |
{
|
|
593 |
memclr(&iFileName, sizeof(RLdrReq) - sizeof(TLdrInfo));
|
|
594 |
}
|
|
595 |
|
|
596 |
void RLdrReq::Close()
|
|
597 |
{
|
|
598 |
delete iFileName;
|
|
599 |
delete iCmd;
|
|
600 |
delete iPath;
|
|
601 |
iClientThread.Close();
|
|
602 |
iClientProcess.Close();
|
|
603 |
}
|
|
604 |
|
|
605 |
void RLdrReq::Panic(TInt aPanic)
|
|
606 |
{
|
|
607 |
iMsg->Panic(KLitLoader,aPanic);
|
|
608 |
}
|
|
609 |
|
|
610 |
TInt CheckedCollapse(TDes8& aDest, const TDesC16& aSrc)
|
|
611 |
{
|
|
612 |
TInt rl = aSrc.Length();
|
|
613 |
aDest.SetLength(rl);
|
|
614 |
TText8* d = (TText8*)aDest.Ptr();
|
|
615 |
const TText16* s = aSrc.Ptr();
|
|
616 |
const TText16* sE = s + rl;
|
|
617 |
while (s<sE && *s>=0x20u && *s<0x7fu)
|
|
618 |
*d++ = (TText8)*s++;
|
|
619 |
return (s<sE) ? KErrBadName : KErrNone;
|
|
620 |
}
|
|
621 |
|
|
622 |
TInt RLoaderMsg::GetString(HBufC8*& aBuf, TInt aParam, TInt aMaxLen, TInt aHeadroom, TBool aReduce) const
|
|
623 |
{
|
|
624 |
aBuf=NULL;
|
|
625 |
TInt l=GetDesLength(aParam);
|
|
626 |
if (l<0)
|
|
627 |
return l;
|
|
628 |
if (l>aMaxLen)
|
|
629 |
return KErrOverflow;
|
|
630 |
aBuf=HBufC8::New((l+aHeadroom)*sizeof(TText));
|
|
631 |
if (!aBuf)
|
|
632 |
return KErrNoMemory;
|
|
633 |
TPtr8 bp8(aBuf->Des());
|
|
634 |
TPtr16 bp16((TText*)bp8.Ptr(), 0, bp8.MaxLength()/sizeof(TText));
|
|
635 |
TInt r = Read(aParam, bp16);
|
|
636 |
if (r == KErrNone)
|
|
637 |
{
|
|
638 |
TInt rl = bp16.Length();
|
|
639 |
if (aReduce)
|
|
640 |
r = CheckedCollapse(bp8, bp16);
|
|
641 |
else
|
|
642 |
bp8.SetLength(rl*sizeof(TText));
|
|
643 |
}
|
|
644 |
if (r!=KErrNone)
|
|
645 |
{
|
|
646 |
delete aBuf;
|
|
647 |
aBuf=NULL;
|
|
648 |
}
|
|
649 |
return r;
|
|
650 |
}
|
|
651 |
|
|
652 |
TInt RLoaderMsg::GetLdrInfo(TLdrInfo& aInfo) const
|
|
653 |
{
|
|
654 |
TPckg<TLdrInfo> infoPckg(aInfo);
|
|
655 |
return Read(0, infoPckg);
|
|
656 |
}
|
|
657 |
|
|
658 |
TInt RLoaderMsg::UpdateLdrInfo(const TLdrInfo& aInfo) const
|
|
659 |
{
|
|
660 |
TPckgC<TLdrInfo> infoPckg(aInfo);
|
|
661 |
return Write(0, infoPckg);
|
|
662 |
}
|
|
663 |
|
|
664 |
TInt RLdrReq::AddFileExtension(const TDesC8& aExt)
|
|
665 |
{
|
|
666 |
if (iFileName->LocateReverse('.')==KErrNotFound)
|
|
667 |
{
|
|
668 |
if (iFileName->Length()+aExt.Length()>KMaxFileName)
|
|
669 |
return KErrBadName;
|
|
670 |
iFileName->Des().Append(aExt);
|
|
671 |
}
|
|
672 |
TInt r = iFileNameInfo.Set(*iFileName, TFileNameInfo::EAllowDecimalVersion);
|
|
673 |
if (r == KErrNone)
|
|
674 |
{
|
|
675 |
TInt l = iFileNameInfo.BaseLen() + iFileNameInfo.ExtLen();
|
|
676 |
if (l > KMaxProcessName)
|
|
677 |
r = KErrBadName;
|
|
678 |
}
|
|
679 |
return r;
|
|
680 |
}
|
|
681 |
|
|
682 |
TInt CheckSubstDrive(TDes8& aDest, const TDesC8& aSrc, TBool aIsPathOnly)
|
|
683 |
{
|
|
684 |
TInt r = KErrNone;
|
|
685 |
TInt l = aSrc.Length();
|
|
686 |
TInt mdl = aDest.MaxLength();
|
|
687 |
TInt pathStart = 0;
|
|
688 |
if (l>=3 && aSrc[1]==':')
|
|
689 |
{
|
|
690 |
// drive letter specified...
|
|
691 |
pathStart = 2;
|
|
692 |
TInt drive;
|
|
693 |
TDriveInfo dI;
|
|
694 |
r = RFs::CharToDrive((TChar)aSrc[0], drive);
|
|
695 |
if (r!=KErrNone)
|
|
696 |
{
|
|
697 |
return r;
|
|
698 |
}
|
|
699 |
r = gTheLoaderFs.Drive(dI, drive);
|
|
700 |
if (r!=KErrNone)
|
|
701 |
{
|
|
702 |
return r;
|
|
703 |
}
|
|
704 |
if (dI.iDriveAtt & KDriveAttSubsted)
|
|
705 |
{
|
|
706 |
TPtr16 ptr16(aDest.Expand());
|
|
707 |
r = gTheLoaderFs.Subst(ptr16, drive);
|
|
708 |
if (r!=KErrNone)
|
|
709 |
{
|
|
710 |
return r;
|
|
711 |
}
|
|
712 |
aDest.SetLength(ptr16.Length()*sizeof(TText));
|
|
713 |
aDest.Collapse();
|
|
714 |
TInt srcm = (aSrc[2]=='\\') ? 3 : 2;
|
|
715 |
TPtrC8 rest(aSrc.Mid(srcm));
|
|
716 |
if (rest.Length() + aDest.Length() > mdl)
|
|
717 |
return KErrBadName;
|
|
718 |
aDest.Append(rest);
|
|
719 |
r=1;
|
|
720 |
}
|
|
721 |
}
|
|
722 |
|
|
723 |
if(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
|
|
724 |
return r;
|
|
725 |
|
|
726 |
// make sure path starts with "\sys\bin\"...
|
|
727 |
|
|
728 |
// get filename/path...
|
|
729 |
TPtrC8 ptr;
|
|
730 |
if(!r)
|
|
731 |
ptr.Set(aSrc);
|
|
732 |
else
|
|
733 |
ptr.Set(aDest);
|
|
734 |
|
|
735 |
// set pathStart to first character of path (after any initial '\')
|
|
736 |
if(ptr.Length() && ptr[pathStart]=='\\')
|
|
737 |
++pathStart; // drop initial '\'
|
|
738 |
|
|
739 |
// set pathEnd to first character after path (the final '\' if present)
|
|
740 |
TInt pathEnd;
|
|
741 |
if(aIsPathOnly)
|
|
742 |
{
|
|
743 |
pathEnd = ptr.Length();
|
|
744 |
if(pathEnd && ptr[pathEnd-1]==';')
|
|
745 |
--pathEnd; // drop trailing ';'
|
|
746 |
if(pathEnd && ptr[pathEnd-1]=='\\')
|
|
747 |
--pathEnd; // drop trailing '\'
|
|
748 |
}
|
|
749 |
else
|
|
750 |
{
|
|
751 |
pathEnd = ptr.LocateReverse('\\');
|
|
752 |
if(pathEnd<0)
|
|
753 |
return r; // no path, so end
|
|
754 |
}
|
|
755 |
|
|
756 |
// check if path starts with "sys\bin"...
|
|
757 |
const TUint8* fn = ptr.Ptr();
|
|
758 |
_LIT8(KSysBin,"sys\\bin");
|
|
759 |
const TInt KSysBinLength = 7;
|
|
760 |
if(pathStart+KSysBinLength <= pathEnd)
|
|
761 |
if(KSysBin().CompareF(TPtrC8(fn+pathStart,KSysBinLength))==0)
|
|
762 |
return r; // path already starts with "sys\bin", so end
|
|
763 |
|
|
764 |
// replace path with "sys\bin"...
|
|
765 |
TBuf8<KMaxFileName*sizeof(TText)> temp;
|
|
766 |
temp.Append(TPtrC8(fn,pathStart)); // add bits before path
|
|
767 |
temp.Append(KSysBin); // add "sys\bin"
|
|
768 |
TInt rootLen = ptr.Length()-pathEnd;
|
|
769 |
if(temp.Length()+rootLen>temp.MaxLength())
|
|
770 |
return KErrBadName; // would overflow
|
|
771 |
temp.Append(TPtrC8(fn+pathEnd,rootLen)); // add bits after path
|
|
772 |
|
|
773 |
// return modified string...
|
|
774 |
aDest = temp;
|
|
775 |
return 1;
|
|
776 |
}
|
|
777 |
|
|
778 |
|
|
779 |
TInt RLdrReq::CheckForSubstDriveInName()
|
|
780 |
{
|
|
781 |
TBuf8<KMaxFileName*sizeof(TText)> temp;
|
|
782 |
TInt r = CheckSubstDrive(temp, *iFileName, EFalse);
|
|
783 |
if (r<0)
|
|
784 |
{
|
|
785 |
return r;
|
|
786 |
}
|
|
787 |
if (r>0)
|
|
788 |
{
|
|
789 |
TInt l=temp.Length();
|
|
790 |
HBufC8* p = HBufC8::New(l+KExtensionLength);
|
|
791 |
if (!p)
|
|
792 |
return KErrNoMemory;
|
|
793 |
TPtr8 bp8(p->Des());
|
|
794 |
bp8 = temp;
|
|
795 |
delete iFileName;
|
|
796 |
iFileName = p;
|
|
797 |
r = KErrNone;
|
|
798 |
}
|
|
799 |
return r;
|
|
800 |
}
|
|
801 |
|
|
802 |
|
|
803 |
TInt RLdrReq::CheckForSubstDrivesInPath()
|
|
804 |
{
|
|
805 |
if (!iPath)
|
|
806 |
return KErrNone;
|
|
807 |
TBuf8<(KMaxFileName+1)*sizeof(TText)> temp;
|
|
808 |
TInt ppos = 0;
|
|
809 |
TInt plen = iPath->Length();
|
|
810 |
HBufC8* newpath = NULL;
|
|
811 |
while (ppos < plen)
|
|
812 |
{
|
|
813 |
TPtrC8 rmn(iPath->Mid(ppos));
|
|
814 |
TInt term = rmn.Locate(';');
|
|
815 |
TInt pel = (term<0) ? rmn.Length() : term+1;
|
|
816 |
TPtrC8 path_element(iPath->Mid(ppos, pel));
|
|
817 |
ppos += pel;
|
|
818 |
temp.Zero();
|
|
819 |
TInt r = CheckSubstDrive(temp, path_element, ETrue);
|
|
820 |
if (r<0)
|
|
821 |
{
|
|
822 |
delete newpath;
|
|
823 |
return r;
|
|
824 |
}
|
|
825 |
else if (r>0 || newpath)
|
|
826 |
{
|
|
827 |
if(!newpath)
|
|
828 |
{
|
|
829 |
// initialise 'newpath' to contain everything in path before the element just processed...
|
|
830 |
newpath = iPath->Left(ppos-pel).Alloc();
|
|
831 |
if(!newpath)
|
|
832 |
return KErrNoMemory;
|
|
833 |
}
|
|
834 |
// grow 'newpath'...
|
|
835 |
TInt xl = (r>0) ? temp.Length() : pel;
|
|
836 |
HBufC8* np = newpath->ReAlloc(newpath->Length() + xl);
|
|
837 |
if(!np)
|
|
838 |
{
|
|
839 |
delete newpath;
|
|
840 |
return KErrNoMemory;
|
|
841 |
}
|
|
842 |
newpath = np;
|
|
843 |
// append modified path element to the 'newpath'...
|
|
844 |
newpath->Des().Append( (r>0) ? (const TDesC8&)temp : (const TDesC8&)path_element);
|
|
845 |
}
|
|
846 |
}
|
|
847 |
if(newpath)
|
|
848 |
{
|
|
849 |
delete iPath;
|
|
850 |
iPath = newpath;
|
|
851 |
}
|
|
852 |
return KErrNone;
|
|
853 |
}
|
|
854 |
|
|
855 |
#ifdef __VC32__
|
|
856 |
#pragma warning( disable : 4701 ) // disable warning C4701: local variable 'missingCaps' may be used without having been initialized
|
|
857 |
#endif
|
|
858 |
|
|
859 |
TInt RLdrReq::CheckSecInfo(const SSecurityInfo& aCandidate) const
|
|
860 |
//
|
|
861 |
// Check that the security info of a candidate loadee is sufficient
|
|
862 |
//
|
|
863 |
{
|
|
864 |
if (iSecureId && iSecureId != aCandidate.iSecureId)
|
|
865 |
return KErrPermissionDenied;
|
|
866 |
|
|
867 |
SCapabilitySet missingCaps;
|
|
868 |
TUint32 checkFail = 0;
|
|
869 |
for (TInt i=0; i<SCapabilitySet::ENCapW; ++i)
|
|
870 |
{
|
|
871 |
TUint32 missing = iPlatSecCaps[i] & ~aCandidate.iCaps[i];
|
|
872 |
missingCaps[i] = missing;
|
|
873 |
checkFail |= missing;
|
|
874 |
}
|
|
875 |
if(!checkFail)
|
|
876 |
return KErrNone;
|
|
877 |
// Failed check...
|
|
878 |
if(iImporter)
|
|
879 |
{
|
|
880 |
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
|
|
881 |
return PlatSec::LoaderCapabilityViolation(iImporter->iFileName,*iFileName,missingCaps);
|
|
882 |
#else //__REMOVE_PLATSEC_DIAGNOSTICS__
|
|
883 |
return PlatSec::EmitDiagnostic();
|
|
884 |
#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
|
|
885 |
}
|
|
886 |
|
|
887 |
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
|
|
888 |
return PlatSec::LoaderCapabilityViolation(iClientProcess,*iFileName,missingCaps);
|
|
889 |
#else //__REMOVE_PLATSEC_DIAGNOSTICS__
|
|
890 |
return PlatSec::EmitDiagnostic();
|
|
891 |
#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
|
|
892 |
}
|
|
893 |
|
|
894 |
#ifdef __VC32__
|
|
895 |
#pragma warning( default : 4701 ) // enable warning C4701: local variable 'missingCaps' may be used without having been initialized
|
|
896 |
#endif
|
|
897 |
|
|
898 |
void CSessionLoader::ServiceL(const RMessage2& aMessage)
|
|
899 |
//
|
|
900 |
// Handle messages for this server.
|
|
901 |
//
|
|
902 |
{
|
|
903 |
const RLoaderMsg& msg = (const RLoaderMsg&)aMessage;
|
|
904 |
TLoaderMsg mid=(TLoaderMsg)msg.Function();
|
|
905 |
__IF_DEBUG(Printf("Loader: RX msg %d", mid));
|
|
906 |
if (mid<1 || mid>=EMaxLoaderMsg)
|
|
907 |
{
|
|
908 |
aMessage.Complete(KErrNotSupported);
|
|
909 |
return;
|
|
910 |
}
|
|
911 |
#ifdef __EPOC32__
|
|
912 |
#ifdef __X86__
|
|
913 |
UseFloppy = -1;
|
|
914 |
#endif
|
|
915 |
TInt r=CheckLoaderCacheInit();
|
|
916 |
if (r!=KErrNone)
|
|
917 |
{
|
|
918 |
aMessage.Complete(r);
|
|
919 |
return;
|
|
920 |
}
|
|
921 |
#else
|
|
922 |
TInt r = KErrNone;
|
|
923 |
#endif
|
|
924 |
#ifdef _DEBUG
|
|
925 |
if(mid==ELoaderDebugFunction)
|
|
926 |
{
|
|
927 |
msg.Complete(DoLoaderDebugFunction(msg));
|
|
928 |
return;
|
|
929 |
}
|
|
930 |
#endif
|
|
931 |
if(mid==ELoaderCancelLazyDllUnload)
|
|
932 |
{
|
|
933 |
#ifdef __LAZY_DLL_UNLOAD
|
|
934 |
CLazyUnloadTimer::Finish();
|
|
935 |
#endif
|
|
936 |
msg.Complete(KErrNone);
|
|
937 |
return;
|
|
938 |
}
|
293
|
939 |
if(mid==ELoaderRunReaper)
|
|
940 |
{
|
|
941 |
CReaperCleanupTimer::Complete();
|
|
942 |
msg.Complete(KErrNone);
|
|
943 |
return;
|
|
944 |
}
|
0
|
945 |
#ifdef _DEBUG
|
|
946 |
gTheLoaderFs.ResourceCountMarkStart();
|
|
947 |
#endif
|
|
948 |
if(mid==EGetInfoFromHeader)
|
|
949 |
{
|
|
950 |
r=GetInfoFromHeader(msg);
|
|
951 |
#ifdef _DEBUG
|
|
952 |
gTheLoaderFs.ResourceCountMarkEnd();
|
|
953 |
#endif
|
|
954 |
msg.Complete(r);
|
|
955 |
return;
|
|
956 |
}
|
|
957 |
|
|
958 |
if (mid == ELdrDelete)
|
|
959 |
{
|
|
960 |
// TCB and AllFiles are sufficient to ensure that write
|
|
961 |
// access to any part of the file system without having to
|
|
962 |
// check substitutions and access rights here.
|
|
963 |
if (! aMessage.HasCapability(ECapabilityTCB, ECapabilityAllFiles, __PLATSEC_DIAGNOSTIC_STRING("ELdrDelete,TCB+AllFiles")))
|
|
964 |
{
|
|
965 |
r = KErrPermissionDenied;
|
|
966 |
}
|
|
967 |
// because this function is a general-purpose replacement for RFs::Delete,
|
|
968 |
// it doesn't use the transformed filename which would be put into ldrReq.iFileName,
|
|
969 |
// but the literal filename which was supplied, provided it is absolute.
|
|
970 |
else
|
|
971 |
{
|
|
972 |
TInt filenameLength = msg.GetDesLength(1);
|
|
973 |
if(filenameLength<0)
|
|
974 |
r = filenameLength;
|
|
975 |
else
|
|
976 |
{
|
|
977 |
HBufC* fnSupply = HBufC::New(filenameLength);
|
|
978 |
if(!fnSupply)
|
|
979 |
r = KErrNoMemory;
|
|
980 |
else
|
|
981 |
{
|
|
982 |
TPtr buf = fnSupply->Des();
|
|
983 |
if ((r=msg.Read( 1, buf)) == KErrNone)
|
|
984 |
{
|
|
985 |
_LIT(KAbsolutePathPattern,"?:\\*");
|
|
986 |
if (fnSupply->MatchF(KAbsolutePathPattern) != 0)
|
|
987 |
r = KErrBadName;
|
|
988 |
else
|
|
989 |
{
|
|
990 |
_LIT(KSysBin,"?:\\sys\\bin\\*");
|
|
991 |
if (fnSupply->MatchF(KSysBin) == 0)
|
|
992 |
r = DeleteExecutable(*fnSupply);
|
|
993 |
else
|
|
994 |
r = gTheLoaderFs.Delete(*fnSupply);
|
|
995 |
}
|
|
996 |
}
|
|
997 |
delete fnSupply;
|
|
998 |
}
|
|
999 |
}
|
|
1000 |
} // endif !aMessage.HasCapability
|
|
1001 |
|
|
1002 |
#ifdef _DEBUG
|
|
1003 |
gTheLoaderFs.ResourceCountMarkEnd();
|
|
1004 |
#endif
|
|
1005 |
msg.Complete(r);
|
|
1006 |
return;
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
RLdrReq ldrReq;
|
|
1010 |
ldrReq.iMsg=&msg;
|
|
1011 |
r=msg.GetString(ldrReq.iFileName, 1, KMaxFileName, KExtensionLength, ETrue);
|
|
1012 |
__IF_DEBUG(Printf("Filename: %S", ldrReq.iFileName));
|
|
1013 |
if (r==KErrNone)
|
|
1014 |
r = ldrReq.CheckForSubstDriveInName();
|
|
1015 |
__IF_DEBUG(Printf("Post-subst filename: %S", ldrReq.iFileName));
|
|
1016 |
if (r!=KErrNone)
|
|
1017 |
goto error;
|
|
1018 |
|
|
1019 |
ldrReq.iPlatSecCaps = AllCapabilities; // secure default, require loaded executable to have all capabilities
|
|
1020 |
|
|
1021 |
#ifndef __EPOC32__
|
|
1022 |
// On the emulator, temporarily disable CPU speed restrictions whilst loading executables...
|
|
1023 |
TInt cpu;
|
|
1024 |
HAL::Get(HALData::ECPUSpeed, cpu);
|
|
1025 |
HAL::Set(HALData::ECPUSpeed, 0);
|
|
1026 |
#endif
|
|
1027 |
IF_DEBUG(SetupRFsFail(msg));
|
|
1028 |
IF_DEBUG(SetupHeapFail(msg));
|
|
1029 |
switch (mid)
|
|
1030 |
{
|
|
1031 |
//__DATA_CAGING__
|
|
1032 |
case EGetInfo:
|
|
1033 |
{
|
|
1034 |
r=ldrReq.AddFileExtension(KFileExtensionDll);
|
|
1035 |
if (r==KErrNone)
|
|
1036 |
r=msg.GetLdrInfo(ldrReq);
|
|
1037 |
if (r==KErrNone)
|
|
1038 |
r=GetModuleInfo(ldrReq);
|
|
1039 |
break;
|
|
1040 |
}
|
|
1041 |
//__DATA_CAGING__
|
|
1042 |
case ELoadProcess:
|
|
1043 |
{
|
|
1044 |
r=ldrReq.AddFileExtension(KFileExtensionExe);
|
|
1045 |
if (r==KErrNone)
|
|
1046 |
r=msg.GetString(ldrReq.iCmd, 2, KMaxTInt, 0, EFalse);
|
|
1047 |
if (r==KErrNone)
|
|
1048 |
r=msg.GetLdrInfo(ldrReq);
|
|
1049 |
if (r==KErrNone)
|
|
1050 |
{
|
|
1051 |
static const SCapabilitySet NoCapabilities={{0}};
|
|
1052 |
ldrReq.iPlatSecCaps=NoCapabilities; // We don't care what EXEs capabilities are
|
|
1053 |
r=LoadProcess(ldrReq);
|
|
1054 |
}
|
|
1055 |
break;
|
|
1056 |
}
|
|
1057 |
case ELoadLibrary:
|
|
1058 |
{
|
|
1059 |
r=E32Loader::CheckClientState(msg.Handle());
|
|
1060 |
if (r!=KErrNone)
|
|
1061 |
ldrReq.Panic(ELoadLibraryWithoutDllLock);
|
|
1062 |
else
|
|
1063 |
r=ldrReq.AddFileExtension(KFileExtensionDll);
|
|
1064 |
if (r==KErrNone)
|
|
1065 |
r=msg.GetString(ldrReq.iPath, 2, KMaxPath, 0, ETrue);
|
|
1066 |
if (ldrReq.iPath)
|
|
1067 |
{
|
|
1068 |
__IF_DEBUG(Printf("Path: %S", ldrReq.iPath));
|
|
1069 |
}
|
|
1070 |
if (r==KErrNone)
|
|
1071 |
r = ldrReq.CheckForSubstDrivesInPath();
|
|
1072 |
if (ldrReq.iPath)
|
|
1073 |
{
|
|
1074 |
__IF_DEBUG(Printf("Post-subst Path: %S", ldrReq.iPath));
|
|
1075 |
}
|
|
1076 |
if (r==KErrNone)
|
|
1077 |
r=msg.GetLdrInfo(ldrReq);
|
|
1078 |
if (r==KErrNone)
|
|
1079 |
r=LoadLibrary(ldrReq);
|
|
1080 |
break;
|
|
1081 |
}
|
|
1082 |
|
|
1083 |
case ECheckLibraryHash:
|
|
1084 |
|
|
1085 |
r = ldrReq.AddFileExtension(KFileExtensionDll);
|
|
1086 |
if (r==KErrNone)
|
|
1087 |
{
|
|
1088 |
r = CheckLibraryHash(ldrReq);
|
|
1089 |
}
|
|
1090 |
break;
|
|
1091 |
|
|
1092 |
case ELoadLogicalDevice:
|
|
1093 |
{
|
|
1094 |
r=ldrReq.AddFileExtension(KFileExtensionLdd);
|
|
1095 |
if (r==KErrNone)
|
|
1096 |
r=LoadDeviceDriver(ldrReq, 0);
|
|
1097 |
break;
|
|
1098 |
}
|
|
1099 |
case ELoadPhysicalDevice:
|
|
1100 |
{
|
|
1101 |
r=ldrReq.AddFileExtension(KFileExtensionPdd);
|
|
1102 |
if (r==KErrNone)
|
|
1103 |
r=LoadDeviceDriver(ldrReq, 1);
|
|
1104 |
break;
|
|
1105 |
}
|
|
1106 |
case ELoadLocale:
|
|
1107 |
{
|
|
1108 |
r=ldrReq.AddFileExtension(KFileExtensionDll);
|
|
1109 |
if (r==KErrNone)
|
|
1110 |
{
|
|
1111 |
ldrReq.iRequestedUids=TUidType(TUid::Uid(KDynamicLibraryUidValue),TUid::Uid(KLocaleDllUidValue));
|
|
1112 |
ldrReq.iOwnerType=EOwnerProcess;
|
|
1113 |
ldrReq.iHandle=0;
|
|
1114 |
ldrReq.iPlatSecCaps=AllCapabilities;
|
|
1115 |
ldrReq.iMsg=NULL; // null msg -> client is self
|
|
1116 |
TLibraryFunction functionList[KNumLocaleExports];
|
|
1117 |
r=LoadLocale(ldrReq, functionList);
|
|
1118 |
if(r==KErrNone)
|
|
1119 |
{
|
|
1120 |
TInt size = KNumLocaleExports * sizeof(TLibraryFunction);
|
|
1121 |
TPtr8 functionListBuf((TUint8*)&functionList[0], size, size);
|
|
1122 |
TRAP(r, aMessage.WriteL(2, functionListBuf, 0));
|
|
1123 |
}
|
|
1124 |
}
|
|
1125 |
break;
|
|
1126 |
}
|
|
1127 |
case ELoadCodePage:
|
|
1128 |
{
|
|
1129 |
if (!KCapDiskAdmin.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING("Loader : ELoadCodePage")))
|
|
1130 |
{
|
|
1131 |
r = KErrPermissionDenied;
|
|
1132 |
break;
|
|
1133 |
}
|
|
1134 |
r=ldrReq.AddFileExtension(KFileExtensionDll);
|
|
1135 |
if (r==KErrNone)
|
|
1136 |
{
|
|
1137 |
ldrReq.iRequestedUids=TUidType(TUid::Uid(KDynamicLibraryUidValue),TUid::Uid(KLocaleDllUidValue));
|
|
1138 |
ldrReq.iOwnerType=EOwnerProcess;
|
|
1139 |
ldrReq.iHandle=0;
|
|
1140 |
ldrReq.iPlatSecCaps=gFileServerSecInfo.iCaps;
|
|
1141 |
ldrReq.iMsg=NULL; // null msg -> client is self
|
|
1142 |
r=LoadLibrary(ldrReq);
|
|
1143 |
if (r==KErrNone)
|
|
1144 |
{
|
|
1145 |
// call file server to install code page dll
|
|
1146 |
r = ((RLoaderFs*)&gTheLoaderFs)->SendReceive(EFsLoadCodePage, TIpcArgs(ldrReq.iHandle));
|
|
1147 |
}
|
|
1148 |
}
|
|
1149 |
if (r!=KErrNone)
|
|
1150 |
{
|
|
1151 |
RLibrary lib;
|
|
1152 |
lib.SetHandle(ldrReq.iHandle);
|
|
1153 |
lib.Close();
|
|
1154 |
}
|
|
1155 |
break;
|
|
1156 |
}
|
|
1157 |
case ELoadFileSystem:
|
|
1158 |
{
|
|
1159 |
if (!KCapFsAddFileSystem.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING("Add File System")))
|
|
1160 |
{
|
|
1161 |
r = KErrPermissionDenied;
|
|
1162 |
break;
|
|
1163 |
}
|
|
1164 |
r=ldrReq.AddFileExtension(KFileExtensionFsy);
|
|
1165 |
if (r==KErrNone)
|
|
1166 |
{
|
|
1167 |
ldrReq.iRequestedUids=TUidType(TUid::Uid(KDynamicLibraryUidValue),TUid::Uid(KFileSystemUidValue));
|
|
1168 |
ldrReq.iOwnerType=EOwnerProcess;
|
|
1169 |
ldrReq.iHandle=0;
|
|
1170 |
ldrReq.iPlatSecCaps=gFileServerSecInfo.iCaps;
|
|
1171 |
ldrReq.iMsg=NULL; // null msg -> client is self
|
|
1172 |
r=LoadLibrary(ldrReq);
|
|
1173 |
if (r==KErrNone)
|
|
1174 |
{
|
|
1175 |
// call file server to install file system
|
|
1176 |
r = ((RLoaderFs*)&gTheLoaderFs)->SendReceive(EFsAddFileSystem, TIpcArgs(ldrReq.iHandle));
|
|
1177 |
}
|
|
1178 |
}
|
|
1179 |
if (r!=KErrNone)
|
|
1180 |
{
|
|
1181 |
RLibrary lib;
|
|
1182 |
lib.SetHandle(ldrReq.iHandle);
|
|
1183 |
lib.Close();
|
|
1184 |
}
|
|
1185 |
break;
|
|
1186 |
}
|
|
1187 |
case ELoadFSExtension:
|
|
1188 |
{
|
|
1189 |
if (!KCapFsAddExtension.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING("Add File Extension")))
|
|
1190 |
{
|
|
1191 |
r = KErrPermissionDenied;
|
|
1192 |
break;
|
|
1193 |
}
|
|
1194 |
r=ldrReq.AddFileExtension(KFileExtensionFxt);
|
|
1195 |
if (r==KErrNone)
|
|
1196 |
{
|
|
1197 |
ldrReq.iRequestedUids=TUidType(TUid::Uid(KDynamicLibraryUidValue),TUid::Uid(KFileSystemUidValue));
|
|
1198 |
ldrReq.iOwnerType=EOwnerProcess;
|
|
1199 |
ldrReq.iHandle=0;
|
|
1200 |
ldrReq.iPlatSecCaps=gFileServerSecInfo.iCaps;
|
|
1201 |
ldrReq.iMsg=NULL; // null msg -> client is self
|
|
1202 |
r=LoadLibrary(ldrReq);
|
|
1203 |
if (r==KErrNone)
|
|
1204 |
{
|
|
1205 |
// call file server to install file system
|
|
1206 |
r = ((RLoaderFs*)&gTheLoaderFs)->SendReceive(EFsAddExtension, TIpcArgs(ldrReq.iHandle));
|
|
1207 |
}
|
|
1208 |
}
|
|
1209 |
if (r!=KErrNone)
|
|
1210 |
{
|
|
1211 |
RLibrary lib;
|
|
1212 |
lib.SetHandle(ldrReq.iHandle);
|
|
1213 |
lib.Close();
|
|
1214 |
}
|
|
1215 |
break;
|
|
1216 |
}
|
|
1217 |
case ELoadFSProxyDrive:
|
|
1218 |
{
|
|
1219 |
if (!KCapFsAddProxyDrive.CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING("Add Proxy Drive")))
|
|
1220 |
{
|
|
1221 |
r = KErrPermissionDenied;
|
|
1222 |
break;
|
|
1223 |
}
|
|
1224 |
r=ldrReq.AddFileExtension(KFileExtensionPxy);
|
|
1225 |
if (r==KErrNone)
|
|
1226 |
{
|
|
1227 |
ldrReq.iRequestedUids=TUidType(TUid::Uid(KDynamicLibraryUidValue),TUid::Uid(KFileSystemUidValue));
|
|
1228 |
ldrReq.iOwnerType=EOwnerProcess;
|
|
1229 |
ldrReq.iHandle=0;
|
|
1230 |
ldrReq.iPlatSecCaps=gFileServerSecInfo.iCaps;
|
|
1231 |
ldrReq.iMsg=NULL; // null msg -> client is self
|
|
1232 |
r=LoadLibrary(ldrReq);
|
|
1233 |
if (r==KErrNone)
|
|
1234 |
{
|
|
1235 |
// call file server to install file system
|
|
1236 |
r = ((RLoaderFs*)&gTheLoaderFs)->SendReceive(EFsAddProxyDrive, TIpcArgs(ldrReq.iHandle));
|
|
1237 |
}
|
|
1238 |
}
|
|
1239 |
if (r!=KErrNone)
|
|
1240 |
{
|
|
1241 |
RLibrary lib;
|
|
1242 |
lib.SetHandle(ldrReq.iHandle);
|
|
1243 |
lib.Close();
|
|
1244 |
}
|
|
1245 |
break;
|
|
1246 |
}
|
|
1247 |
case ELoadFSPlugin:
|
|
1248 |
{
|
|
1249 |
r=ldrReq.AddFileExtension(KFileExtensionPxt);
|
|
1250 |
if (r==KErrNone)
|
|
1251 |
{
|
|
1252 |
ldrReq.iRequestedUids=TUidType(TUid::Uid(KDynamicLibraryUidValue),TUid::Uid(KFileSystemUidValue));
|
|
1253 |
ldrReq.iOwnerType=EOwnerProcess;
|
|
1254 |
ldrReq.iHandle=0;
|
|
1255 |
ldrReq.iPlatSecCaps=gFileServerSecInfo.iCaps;
|
|
1256 |
ldrReq.iMsg=NULL; // null msg -> client is self
|
|
1257 |
r=LoadLibrary(ldrReq);
|
|
1258 |
if (r==KErrNone)
|
|
1259 |
{
|
|
1260 |
// call file server to install file system
|
|
1261 |
r = ((RLoaderFs*)&gTheLoaderFs)->SendReceive(EFsAddPlugin, TIpcArgs(ldrReq.iHandle));
|
|
1262 |
}
|
|
1263 |
}
|
|
1264 |
if (r!=KErrNone)
|
|
1265 |
{
|
|
1266 |
RLibrary lib;
|
|
1267 |
lib.SetHandle(ldrReq.iHandle);
|
|
1268 |
lib.Close();
|
|
1269 |
}
|
|
1270 |
break;
|
|
1271 |
}
|
|
1272 |
|
|
1273 |
default:
|
|
1274 |
r=KErrNotSupported;
|
|
1275 |
break;
|
|
1276 |
}
|
|
1277 |
|
|
1278 |
ldrReq.Close();
|
|
1279 |
IF_DEBUG(EndRFsFailCheck(r));
|
|
1280 |
IF_DEBUG(EndHeapFailCheck(r));
|
|
1281 |
#ifndef __EPOC32__
|
|
1282 |
HAL::Set(HALData::ECPUSpeed, cpu);
|
|
1283 |
#endif
|
|
1284 |
error:
|
|
1285 |
#ifdef _DEBUG
|
|
1286 |
gTheLoaderFs.ResourceCountMarkEnd();
|
|
1287 |
#endif
|
|
1288 |
if (!aMessage.IsNull())
|
|
1289 |
{
|
|
1290 |
__IF_DEBUG(Printf("Loader: msg complete %d", r));
|
|
1291 |
aMessage.Complete(r);
|
|
1292 |
}
|
|
1293 |
}
|
|
1294 |
|
|
1295 |
//-----------------------------------------------------------------------------------
|
|
1296 |
#ifndef __WINS__
|
|
1297 |
/**
|
|
1298 |
Helper function that reads a hash file from c:\\sys\\hash and compares it with the givem dll hash.
|
|
1299 |
|
|
1300 |
@param aHashFile represents opened hash file in c:\\sys\\hash directory
|
|
1301 |
@param aDllFileName full path to the dll file, which hash will be calculated and compared with aHashFile contents.
|
|
1302 |
@leave on file operation error or if hashes differ.
|
|
1303 |
*/
|
|
1304 |
static void DoCheckHashL(RFile& aHashFile, const TDesC& aDllFileName)
|
|
1305 |
{
|
|
1306 |
TBuf8<SHA1_HASH> hashInstalled; //-- installed dll hash, from c:\\sys\\hash
|
|
1307 |
User::LeaveIfError(aHashFile.Read(hashInstalled));
|
|
1308 |
|
|
1309 |
CSHA1* hasher=CSHA1::NewL();
|
|
1310 |
CleanupStack::PushL(hasher);
|
|
1311 |
|
|
1312 |
RFile fileDll;
|
|
1313 |
CleanupClosePushL(fileDll);
|
|
1314 |
|
|
1315 |
//-- open dll file
|
|
1316 |
User::LeaveIfError(fileDll.Open(gTheLoaderFs, aDllFileName, EFileRead|EFileReadDirectIO));
|
|
1317 |
|
|
1318 |
TInt fileSz;
|
|
1319 |
User::LeaveIfError(fileDll.Size(fileSz));
|
|
1320 |
|
|
1321 |
//-- check if the file is on removable media
|
|
1322 |
TInt drvNum;
|
|
1323 |
TDriveInfo drvInfo;
|
|
1324 |
User::LeaveIfError(fileDll.Drive(drvNum, drvInfo));
|
|
1325 |
if(!(drvInfo.iDriveAtt & KDriveAttRemovable))
|
|
1326 |
User::Leave(KErrNotSupported);
|
|
1327 |
|
|
1328 |
TInt offset=0;
|
|
1329 |
TInt readSize = KHashFileReadSize;
|
|
1330 |
RBuf8 readBuf;
|
|
1331 |
|
|
1332 |
CleanupClosePushL(readBuf);
|
|
1333 |
readBuf.CreateMaxL(readSize);
|
|
1334 |
|
|
1335 |
//-- calculate dll hash
|
|
1336 |
do {
|
|
1337 |
if((fileSz - offset) < readSize)
|
|
1338 |
readSize = (fileSz - offset);
|
|
1339 |
|
|
1340 |
User::LeaveIfError(fileDll.Read(offset, readBuf, readSize));
|
|
1341 |
hasher->Update(readBuf);
|
|
1342 |
offset+=readSize;
|
|
1343 |
}
|
|
1344 |
while(offset < fileSz);
|
|
1345 |
|
|
1346 |
TBuf8<SHA1_HASH> hashCalculated; //-- calculated dll hash
|
|
1347 |
hashCalculated=hasher->Final();
|
|
1348 |
|
|
1349 |
//-- compare hashes
|
|
1350 |
if(hashCalculated.Compare(hashInstalled) !=0)
|
|
1351 |
User::Leave(KErrCorrupt);
|
|
1352 |
|
|
1353 |
CleanupStack::PopAndDestroy(3); //hasher, fileDll, readBuf
|
|
1354 |
}
|
|
1355 |
#endif //__WINS__
|
|
1356 |
|
|
1357 |
//-----------------------------------------------------------------------------------
|
|
1358 |
|
|
1359 |
/**
|
|
1360 |
Check if specified dll hash exists in \\sys\\hash on system drive and optionally validate it.
|
|
1361 |
|
|
1362 |
|
|
1363 |
@param aReq loader request parameters
|
|
1364 |
|
|
1365 |
@return System-wide error code, see RLoader::CheckLibraryHash() description
|
|
1366 |
@return KErrNotSupported for the emulator version, because loading dlls from the emulated removable media is not supported
|
|
1367 |
*/
|
|
1368 |
static TInt CheckLibraryHash(RLdrReq& aReq)
|
|
1369 |
{
|
|
1370 |
#ifdef __WINS__
|
|
1371 |
(void)aReq;
|
|
1372 |
return KErrNotSupported; //-- loading dlls from removable media and dll hashing isn't supported for WINS
|
|
1373 |
#else
|
|
1374 |
|
|
1375 |
const TInt fNameLen=aReq.iFileName->Length();
|
|
1376 |
if(fNameLen <= 0 || fNameLen > KMaxFileName)
|
|
1377 |
return KErrArgument;
|
|
1378 |
|
|
1379 |
const TBool bValidateHash=aReq.iMsg->Int2();
|
|
1380 |
|
|
1381 |
//-- extract pure dll name
|
|
1382 |
TInt posNameStart=aReq.iFileName->LocateReverse('\\');
|
|
1383 |
if(posNameStart <0)
|
|
1384 |
posNameStart = 0;
|
|
1385 |
else
|
|
1386 |
posNameStart++;
|
|
1387 |
|
|
1388 |
//-- compose hash file name \\sys\\hash\\xxx on system drive
|
|
1389 |
TFileName hashFName;
|
|
1390 |
hashFName.Copy(aReq.iFileName->Right(fNameLen-posNameStart));
|
|
1391 |
hashFName.Insert(0, KSysHash);
|
|
1392 |
hashFName[0] = (TUint8) RFs::GetSystemDriveChar();
|
|
1393 |
|
|
1394 |
//-- try to locate hash file
|
|
1395 |
TInt nRes=KErrNone;
|
|
1396 |
RFile fileHash;
|
|
1397 |
nRes = fileHash.Open(gTheLoaderFs, hashFName, EFileRead|EFileReadDirectIO);
|
|
1398 |
|
|
1399 |
if(nRes != KErrNone)
|
|
1400 |
{
|
|
1401 |
nRes = KErrNotFound; //-- hash file couldn't be found
|
|
1402 |
}
|
|
1403 |
else if(bValidateHash)
|
|
1404 |
{//-- request to validate the hash.
|
|
1405 |
hashFName.Copy(aReq.iFileName->Left(fNameLen)); //-- expand file name to unicode
|
|
1406 |
TRAP(nRes, DoCheckHashL(fileHash, hashFName));
|
|
1407 |
|
|
1408 |
if(nRes != KErrNone)
|
|
1409 |
nRes=KErrCorrupt;
|
|
1410 |
}
|
|
1411 |
|
|
1412 |
fileHash.Close();
|
|
1413 |
|
|
1414 |
return nRes;
|
|
1415 |
|
|
1416 |
#endif //__WINS__
|
|
1417 |
}
|
|
1418 |
|
|
1419 |
// This safely deletes something that could be an executable (ie in /sys/bin)
|
|
1420 |
// aName will be deleted either in, or sometime after this call
|
|
1421 |
// (The descriptor and the file it represents)
|
|
1422 |
TInt CSessionLoader::DeleteExecutable(const TDesC& aName)
|
|
1423 |
{
|
|
1424 |
__IF_DEBUG(Printf("DeleteExecutable %S", &aName));
|
|
1425 |
TInt r;
|
|
1426 |
r = gTheLoaderFs.Delete(aName);
|
|
1427 |
if (r!=KErrInUse)
|
|
1428 |
{
|
|
1429 |
return r;
|
|
1430 |
}
|
|
1431 |
RFile toDelete;
|
|
1432 |
CReaperCleanupTimer::Complete();
|
|
1433 |
|
|
1434 |
HBufC* newName=NULL;
|
|
1435 |
r = toDelete.Open(gTheLoaderFs,aName,EFileShareExclusive|EFileReadDirectIO);
|
|
1436 |
if (r==KErrNone)
|
|
1437 |
{
|
|
1438 |
TInt64 startPos=0;
|
|
1439 |
SBlockMapInfo blockmapInfo;
|
|
1440 |
|
|
1441 |
// find drive number, and starting block
|
|
1442 |
r = toDelete.BlockMap(blockmapInfo,startPos, 1, ETrue);
|
|
1443 |
if (r == KErrCompletion)
|
|
1444 |
{
|
|
1445 |
TInt64 startBlock = blockmapInfo.iStartBlockAddress +
|
|
1446 |
((TBlockMapEntry *)(&(blockmapInfo.iMap[0])))->iStartBlock *
|
|
1447 |
blockmapInfo.iBlockGranularity +
|
|
1448 |
blockmapInfo.iBlockStartOffset;
|
|
1449 |
TInt driveNumber = blockmapInfo.iLocalDriveNumber;
|
|
1450 |
|
|
1451 |
newName = HBufC::New(KPathDelLength+2+16); // + 2 digits for drive and 16 for start block block
|
|
1452 |
if(!newName)
|
|
1453 |
r = KErrNoMemory;
|
|
1454 |
else
|
|
1455 |
{
|
|
1456 |
// make unique name for file...
|
|
1457 |
TPtr name = newName->Des();
|
|
1458 |
name.Copy(KPathDel);
|
|
1459 |
name[0] = aName[0]; // copy drive letter
|
|
1460 |
name.AppendNumFixedWidth(driveNumber, EHex, 2);
|
|
1461 |
name.AppendNumFixedWidth(TUint32(startBlock>>32), EHex, 8);
|
|
1462 |
name.AppendNumFixedWidth(TUint32(startBlock), EHex, 8);
|
|
1463 |
|
|
1464 |
TLoaderDeletedList* tmpLink = new TLoaderDeletedList();
|
|
1465 |
if(tmpLink==NULL)
|
|
1466 |
r = KErrNoMemory;
|
|
1467 |
else
|
|
1468 |
{
|
|
1469 |
toDelete.Close();
|
|
1470 |
gTheLoaderFs.MkDirAll(*newName); // ignore error and let rename fail if path doesn't exists
|
|
1471 |
r = gTheLoaderFs.Rename(aName, *newName);
|
|
1472 |
__IF_DEBUG(Printf("DeleteExecutable rename to %S returns %d", &newName, r));
|
|
1473 |
if(r==KErrNone)
|
|
1474 |
{
|
|
1475 |
// add to pending deletion list
|
|
1476 |
tmpLink->iStartBlock = startBlock;
|
|
1477 |
tmpLink->iDriveNumber = driveNumber;
|
|
1478 |
tmpLink->iFileName = newName;
|
|
1479 |
gActiveReaper->AddDeleted(tmpLink);
|
|
1480 |
return r;
|
|
1481 |
} //endif rename
|
|
1482 |
delete tmpLink;
|
|
1483 |
} // alloc
|
|
1484 |
delete newName;
|
|
1485 |
} // alloc name
|
|
1486 |
} //endif blockmap
|
|
1487 |
else if (r == KErrNotSupported)
|
|
1488 |
r = KErrInUse;
|
|
1489 |
else if (r == KErrNone)
|
|
1490 |
r = KErrGeneral;
|
|
1491 |
toDelete.Close();
|
|
1492 |
} // endif open
|
|
1493 |
return r;
|
|
1494 |
}
|
|
1495 |
|
|
1496 |
|
|
1497 |
GLDEF_C TInt LoadProcess(RLdrReq& aReq)
|
|
1498 |
{
|
|
1499 |
__LDRTRACE(aReq.Dump("LoadProcess:"));
|
|
1500 |
TInt32* uid=(TInt32*)&aReq.iRequestedUids;
|
|
1501 |
if (uid[0] && uid[0]!=KExecutableImageUidValue)
|
|
1502 |
return KErrNotSupported;
|
|
1503 |
uid[0]=KExecutableImageUidValue;
|
|
1504 |
gExeCodeSeg=NULL; // new process doesn't load into another process
|
|
1505 |
gExeAttr=0;
|
|
1506 |
E32Image* e=new E32Image;
|
|
1507 |
if (!e)
|
|
1508 |
return KErrNoMemory;
|
|
1509 |
e->iMain=e;
|
|
1510 |
TInt r=e->LoadProcess(aReq);
|
|
1511 |
if (r==KErrNone)
|
|
1512 |
{
|
|
1513 |
aReq.iHandle=e->iFinalHandle;
|
|
1514 |
r=aReq.iMsg->UpdateLdrInfo(aReq);
|
|
1515 |
if (r!=KErrNone)
|
|
1516 |
aReq.Panic(KErrBadDescriptor);
|
|
1517 |
}
|
|
1518 |
if (r!=KErrNone && e->iProcessHandle)
|
|
1519 |
{
|
|
1520 |
RProcess p;
|
|
1521 |
p.SetHandle(e->iProcessHandle);
|
|
1522 |
p.Kill(0);
|
|
1523 |
}
|
|
1524 |
delete e;
|
|
1525 |
return r;
|
|
1526 |
}
|
|
1527 |
|
|
1528 |
|
|
1529 |
|
|
1530 |
TInt LoadLibrary(RLdrReq& aReq)
|
|
1531 |
{
|
|
1532 |
__LDRTRACE(aReq.Dump("LoadLibrary:"));
|
|
1533 |
TInt32* uid=(TInt32*)&aReq.iRequestedUids;
|
|
1534 |
if (uid[0] && uid[0]!=KDynamicLibraryUidValue)
|
|
1535 |
return KErrNotSupported;
|
|
1536 |
uid[0]=KDynamicLibraryUidValue;
|
|
1537 |
TInt r=KErrNone;
|
|
1538 |
if (aReq.iMsg)
|
|
1539 |
{
|
|
1540 |
r = aReq.iMsg->Client(aReq.iClientThread);
|
|
1541 |
if (r==KErrNone)
|
|
1542 |
r = aReq.iClientThread.Process(aReq.iClientProcess);
|
|
1543 |
if (r!=KErrNone)
|
|
1544 |
{
|
|
1545 |
return r;
|
|
1546 |
}
|
|
1547 |
}
|
|
1548 |
else
|
|
1549 |
{
|
|
1550 |
aReq.iClientThread.SetHandle(KCurrentThreadHandle);
|
|
1551 |
aReq.iClientProcess.SetHandle(KCurrentProcessHandle);
|
|
1552 |
}
|
|
1553 |
E32Loader::CodeSegDeferDeletes();
|
|
1554 |
gExeCodeSeg=E32Loader::ThreadProcessCodeSeg(aReq.iClientThread.Handle());
|
|
1555 |
SSecurityInfo si;
|
|
1556 |
gExeAttr=GetCodeSegAttr(gExeCodeSeg, &si, NULL);
|
|
1557 |
aReq.iPlatSecCaps=si.iCaps;
|
|
1558 |
E32Loader::CodeSegEndDeferDeletes();
|
|
1559 |
E32Image* e=new E32Image;
|
|
1560 |
if (!e)
|
|
1561 |
return KErrNoMemory;
|
|
1562 |
e->iMain=e;
|
|
1563 |
e->iClientProcessHandle=aReq.iClientProcess.Handle();
|
|
1564 |
__IF_DEBUG(Printf("e->iClientProcessHandle = %08x", e->iClientProcessHandle));
|
|
1565 |
if (r==KErrNone)
|
|
1566 |
r=e->LoadCodeSeg(aReq);
|
|
1567 |
if (r==KErrNone)
|
|
1568 |
{
|
|
1569 |
TLibraryCreateInfo libInfo;
|
|
1570 |
libInfo.iCodeSegHandle=e->iHandle;
|
|
1571 |
libInfo.iClientHandle=aReq.iClientThread.Handle();
|
|
1572 |
libInfo.iLibraryHandle=0;
|
|
1573 |
libInfo.iOwnerType=aReq.iOwnerType;
|
|
1574 |
r=E32Loader::LibraryCreate(libInfo);
|
|
1575 |
if (r==KErrNone)
|
|
1576 |
{
|
|
1577 |
aReq.iHandle=libInfo.iLibraryHandle;
|
|
1578 |
if (aReq.iMsg)
|
|
1579 |
{
|
|
1580 |
r=aReq.iMsg->UpdateLdrInfo(aReq);
|
|
1581 |
if (r!=KErrNone)
|
|
1582 |
aReq.Panic(KErrBadDescriptor);
|
|
1583 |
}
|
|
1584 |
}
|
|
1585 |
}
|
|
1586 |
delete e;
|
|
1587 |
return r;
|
|
1588 |
}
|
|
1589 |
|
|
1590 |
struct TFatUtilityFunctions;
|
|
1591 |
|
|
1592 |
GLDEF_C TInt LoadLocale(RLdrReq& aReq, TLibraryFunction* aExportsList)
|
|
1593 |
{
|
|
1594 |
__LDRTRACE(aReq.Dump("LoadLocale:"));
|
|
1595 |
TUint32* uid=(TUint32*)&aReq.iRequestedUids;
|
|
1596 |
uid[2]=0;
|
|
1597 |
gExeCodeSeg=NULL;
|
|
1598 |
gExeAttr = gFileServerAttr;
|
|
1599 |
E32Image* e=new E32Image;
|
|
1600 |
if (!e)
|
|
1601 |
return KErrNoMemory;
|
|
1602 |
e->iMain=e;
|
|
1603 |
e->iAttr=ECodeSegAttGlobal;
|
|
1604 |
TInt r=e->LoadCodeSeg(aReq);
|
|
1605 |
if (r==KErrNone)
|
|
1606 |
{
|
|
1607 |
r = E32Loader::LocaleExports(e->iHandle, aExportsList);
|
|
1608 |
#ifdef SYMBIAN_DISTINCT_LOCALE_MODEL
|
|
1609 |
_LIT8(KLocLan, "elocl_lan");
|
|
1610 |
_LIT8(KLoc, "elocl.");
|
|
1611 |
if(aReq.iFileName->Find(KLocLan) != KErrNotFound)
|
|
1612 |
{
|
|
1613 |
TheCodePage.SetLocaleCodePage((TFatUtilityFunctions*)aExportsList[FnFatUtilityFunctionsV2]());
|
|
1614 |
}
|
|
1615 |
if(aReq.iFileName->Find(KLoc) != KErrNotFound)
|
|
1616 |
{
|
|
1617 |
TheCodePage.SetLocaleCodePage((TFatUtilityFunctions*)aExportsList[FnFatUtilityFunctions]());
|
|
1618 |
}
|
|
1619 |
#else
|
|
1620 |
// The 'old' version of the locale DLL contained a set of code page conversion exports.
|
|
1621 |
// This has now been superceeded by the use of a seperate code page DLL.
|
|
1622 |
// - To ease migration both are currently supported.
|
|
1623 |
// - If both locale and CP DLL functions are present, CP DLL's will take precedence
|
|
1624 |
// - This functionality will eventually be deprecated.
|
|
1625 |
TheCodePage.SetLocaleCodePage((TFatUtilityFunctions*)aExportsList[FnFatUtilityFunctions]());
|
|
1626 |
#endif
|
|
1627 |
}
|
|
1628 |
delete e;
|
|
1629 |
return r;
|
|
1630 |
}
|
|
1631 |
|
|
1632 |
TInt LoadDeviceDriver(RLdrReq& aReq, TInt aDeviceType)
|
|
1633 |
{
|
|
1634 |
__IF_DEBUG(Printf("LoadDeviceDriver type %d", aDeviceType));
|
|
1635 |
__LDRTRACE(aReq.Dump(""));
|
|
1636 |
TUint32* uid=(TUint32*)&aReq.iRequestedUids;
|
|
1637 |
uid[0]=KDynamicLibraryUidValue;
|
|
1638 |
uid[1]=aDeviceType ? KPhysicalDeviceDriverUidValue : KLogicalDeviceDriverUidValue;
|
|
1639 |
uid[2]=0;
|
|
1640 |
gExeCodeSeg=gKernelCodeSeg;
|
|
1641 |
gExeAttr=gKernelAttr;
|
|
1642 |
E32Image* e=new E32Image;
|
|
1643 |
if (!e)
|
|
1644 |
return KErrNoMemory;
|
|
1645 |
e->iMain=e;
|
|
1646 |
e->iAttr=ECodeSegAttKernel;
|
|
1647 |
aReq.iOwnerType=EOwnerProcess;
|
|
1648 |
aReq.iHandle=0;
|
|
1649 |
aReq.iPlatSecCaps=gKernelSecInfo.iCaps;
|
|
1650 |
TInt r=e->LoadCodeSeg(aReq);
|
|
1651 |
if (r==KErrNone)
|
|
1652 |
r=E32Loader::DeviceLoad(e->iHandle, aDeviceType);
|
|
1653 |
delete e;
|
|
1654 |
return r;
|
|
1655 |
}
|
|
1656 |
|
|
1657 |
CServerLoader* CServerLoader::New()
|
|
1658 |
//
|
|
1659 |
// Create a new CServerLoader.
|
|
1660 |
//
|
|
1661 |
{
|
|
1662 |
CServerLoader* pS=new CServerLoader(EPriorityNormal);
|
|
1663 |
if (pS==NULL)
|
|
1664 |
return(NULL);
|
|
1665 |
_LIT(KLoaderServerName,"!Loader");
|
|
1666 |
TInt r=pS->Start(KLoaderServerName);
|
|
1667 |
if (r!=KErrNone)
|
|
1668 |
return(NULL);
|
|
1669 |
return(pS);
|
|
1670 |
}
|
|
1671 |
|
|
1672 |
CServerLoader::CServerLoader(TInt aPriority)
|
|
1673 |
//
|
|
1674 |
// Constructor.
|
|
1675 |
//
|
|
1676 |
: CServer2(aPriority)
|
|
1677 |
{
|
|
1678 |
}
|
|
1679 |
|
|
1680 |
CSession2* CServerLoader::NewSessionL(const TVersion& aVersion, const RMessage2&) const
|
|
1681 |
//
|
|
1682 |
// Create a new client for this server.
|
|
1683 |
//
|
|
1684 |
{
|
|
1685 |
|
|
1686 |
TVersion v(KLoaderMajorVersionNumber,KLoaderMinorVersionNumber,KF32BuildVersionNumber);
|
|
1687 |
TBool r=User::QueryVersionSupported(v,aVersion);
|
|
1688 |
if (!r)
|
|
1689 |
User::Leave(KErrNotSupported);
|
|
1690 |
return new (ELeave) CSessionLoader;
|
|
1691 |
}
|
|
1692 |
|
|
1693 |
TInt CServerLoader::RunError(TInt aError)
|
|
1694 |
//
|
|
1695 |
// Complete the request with the error code
|
|
1696 |
//
|
|
1697 |
{
|
|
1698 |
Message().Complete(aError);
|
|
1699 |
ReStart();
|
|
1700 |
return KErrNone;
|
|
1701 |
}
|
|
1702 |
|
|
1703 |
CActiveSchedulerLoader* CActiveSchedulerLoader::New()
|
|
1704 |
//
|
|
1705 |
// Create and install the active scheduler.
|
|
1706 |
//
|
|
1707 |
{
|
|
1708 |
|
|
1709 |
CActiveSchedulerLoader* pA=new CActiveSchedulerLoader;
|
|
1710 |
if (pA==NULL)
|
|
1711 |
return(NULL);
|
|
1712 |
CActiveScheduler::Install(pA);
|
|
1713 |
return(pA);
|
|
1714 |
}
|
|
1715 |
|
|
1716 |
void CActiveSchedulerLoader::Error(TInt anError) const
|
|
1717 |
//
|
|
1718 |
// Called if any Run() method leaves.
|
|
1719 |
//
|
|
1720 |
{
|
|
1721 |
_LIT(KPanicLoaderErr, "LOADER-ERR");
|
|
1722 |
User::Panic(KPanicLoaderErr,anError);
|
|
1723 |
}
|
|
1724 |
|
|
1725 |
/******************************************************************************
|
|
1726 |
* E32Image functions common to WINS and EPOC
|
|
1727 |
******************************************************************************/
|
|
1728 |
|
|
1729 |
TInt CheckUids(const TUidType& aUids, const TUidType& aRequestedUids)
|
|
1730 |
{
|
|
1731 |
const TUint32* uid=(const TUint32*)&aUids;
|
|
1732 |
const TUint32* req=(const TUint32*)&aRequestedUids;
|
|
1733 |
__IF_DEBUG(Printf("CheckUids %08x,%08x,%08x req %08x,%08x,%08x", uid[0],uid[1],uid[2],
|
|
1734 |
req[0],req[1],req[2]));
|
|
1735 |
return (CheckUid(uid[0],req[0]) && CheckUid(uid[1],req[1]) && CheckUid(uid[2],req[2]))
|
|
1736 |
? KErrNone : KErrNotSupported;
|
|
1737 |
}
|
|
1738 |
|
|
1739 |
E32Image::E32Image()
|
|
1740 |
{
|
|
1741 |
__IF_DEBUG(Printf("E32Image Constructor"));
|
|
1742 |
Mem::FillZ(&iUids, sizeof(E32Image)-sizeof(iFileName));
|
|
1743 |
}
|
|
1744 |
|
|
1745 |
E32Image::~E32Image()
|
|
1746 |
{
|
|
1747 |
|
|
1748 |
__IF_DEBUG(Printf("E32Image Destructor"));
|
|
1749 |
Reset();
|
|
1750 |
}
|
|
1751 |
|
|
1752 |
void E32Image::Reset()
|
|
1753 |
{
|
|
1754 |
__IF_DEBUG(Printf("E32Image::Reset"));
|
|
1755 |
delete iHeader;
|
|
1756 |
__IF_DEBUG(Printf("iHeader"));
|
|
1757 |
|
|
1758 |
// demand paging fixup data
|
|
1759 |
User::Free(iImportFixupTable);
|
|
1760 |
__IF_DEBUG(Printf("iImportFixupTable"));
|
|
1761 |
|
|
1762 |
// demand paging file data
|
|
1763 |
__IF_DEBUG(Printf("iCodePageOffsets"));
|
|
1764 |
delete[] iCodePageOffsets;
|
|
1765 |
__IF_DEBUG(Printf("iCodeBlockMapEntries"));
|
|
1766 |
User::Free(iCodeBlockMapEntries);
|
|
1767 |
|
|
1768 |
__IF_DEBUG(Printf("iCodeRelocSection"));
|
|
1769 |
User::Free(iCodeRelocTable);
|
|
1770 |
__IF_DEBUG(Printf("iDataRelocSection"));
|
|
1771 |
User::Free(iRestOfFileData);
|
|
1772 |
__IF_DEBUG(Printf("iRestOfFileData"));
|
|
1773 |
User::Free(iCurrentImportList);
|
|
1774 |
__IF_DEBUG(Printf("iCurrentImportList"));
|
|
1775 |
User::Free(iFixups);
|
|
1776 |
__IF_DEBUG(Printf("iFixups"));
|
|
1777 |
gFileDataAllocator.Free(iFileData);
|
|
1778 |
iFileData = NULL;
|
|
1779 |
__IF_DEBUG(Printf("iFileData"));
|
|
1780 |
iFile.Close();
|
|
1781 |
__IF_DEBUG(Printf("iFile"));
|
|
1782 |
User::Free(iCopyOfExportDir);
|
|
1783 |
if (iProcessHandle)
|
|
1784 |
{
|
|
1785 |
RProcess p;
|
|
1786 |
p.SetHandle(iProcessHandle);
|
|
1787 |
p.Close();
|
|
1788 |
__IF_DEBUG(Printf("iProcessHandle"));
|
|
1789 |
}
|
|
1790 |
if (iCloseCodeSeg)
|
|
1791 |
E32Loader::CodeSegClose(iCloseCodeSeg);
|
|
1792 |
if (iMain==this)
|
|
1793 |
E32Loader::CodeSegClose(NULL);
|
|
1794 |
|
|
1795 |
// Unclamp file if load failed. Cannot handle error from RFs here.
|
|
1796 |
__IF_DEBUG(Printf("iFileClamp,%ld,%ld", iFileClamp.iCookie[0], iFileClamp.iCookie[1]));
|
|
1797 |
iFileClamp.Close(gTheLoaderFs);
|
|
1798 |
|
|
1799 |
__IF_DEBUG(Printf("Reset done"));
|
|
1800 |
}
|
|
1801 |
|
|
1802 |
|
|
1803 |
TInt E32Image::OpenFile()
|
|
1804 |
{
|
|
1805 |
TBuf8<KMaxFileName*sizeof(TText)> fnb;
|
|
1806 |
if (iAttr & ECodeSegAttExpVer)
|
|
1807 |
{
|
|
1808 |
TFileNameInfo fi;
|
|
1809 |
fi.Set(iFileName, 0);
|
|
1810 |
fi.iVersion = iModuleVersion;
|
|
1811 |
fi.GetName(fnb, TFileNameInfo::EIncludeDrivePathBaseExt|TFileNameInfo::EForceVer);
|
|
1812 |
}
|
|
1813 |
else
|
|
1814 |
fnb = iFileName;
|
|
1815 |
TPtr16 fn(fnb.Expand());
|
|
1816 |
__IF_DEBUG(Print(_L(">E32Image::OpenFile %S"),&fn));
|
|
1817 |
TInt r = iFile.Open(gTheLoaderFs, fn, EFileStream|EFileRead|EFileShareReadersOnly|EFileReadDirectIO);
|
|
1818 |
__IF_DEBUG(Printf("<E32Image::OpenFile %d", r));
|
|
1819 |
return r;
|
|
1820 |
}
|
|
1821 |
|
|
1822 |
|
|
1823 |
/**
|
|
1824 |
Check if this executable is already loaded. If it is, set iAlreadyLoaded true and
|
|
1825 |
iHandle to an newly opened reference on the CodeSeg. Also set iExportDirLoad if the
|
|
1826 |
export directory of the executable is directly visible to the Loader.
|
|
1827 |
*/
|
|
1828 |
TInt E32Image::CheckAlreadyLoaded()
|
|
1829 |
{
|
|
1830 |
__IF_DEBUG(Printf(">E32Image::CheckAlreadyLoaded %S", &iFileName));
|
|
1831 |
__IF_DEBUG(Printf("UIDs %08x,%08x,%08x",iUids[0],iUids[1],iUids[2]));
|
|
1832 |
__IF_DEBUG(Printf("VER %08x",iModuleVersion));
|
|
1833 |
__IF_DEBUG(Printf("CAPS %08x %08x SID %08x", iS.iSecureId, iS.iCaps[1], iS.iCaps[0]));
|
|
1834 |
__IF_DEBUG(Printf("Client process handle %08x",iClientProcessHandle));
|
|
1835 |
|
|
1836 |
TFindCodeSeg find;
|
|
1837 |
find.iUids = iUids;
|
|
1838 |
find.iRomImgHdr = NULL;
|
|
1839 |
#ifndef __WINS__
|
|
1840 |
// Make sure we check the code segment attributes (kernel or global)
|
|
1841 |
// as part of the decision as to whether we are loaded or not.
|
|
1842 |
find.iAttrMask = (ECodeSegAttKernel|ECodeSegAttGlobal);
|
|
1843 |
find.iAttrVal = iAttr&(ECodeSegAttKernel|ECodeSegAttGlobal);
|
|
1844 |
#else
|
|
1845 |
// On the emulator, all DLLs are loaded into the same process, so we
|
|
1846 |
// don't distinguish between instances of the same DLL loaded with
|
|
1847 |
// different code segment attributes.
|
|
1848 |
find.iAttrMask = 0;
|
|
1849 |
find.iAttrVal = 0;
|
|
1850 |
#endif
|
|
1851 |
find.iProcess = iClientProcessHandle;
|
|
1852 |
find.iS = iS;
|
|
1853 |
find.iModuleVersion = iModuleVersion;
|
|
1854 |
find.iName = RootName();
|
|
1855 |
__IF_DEBUG(Printf("Required root name %S", &find.iName));
|
|
1856 |
|
|
1857 |
E32Loader::CodeSegDeferDeletes();
|
|
1858 |
iHandle = NULL;
|
|
1859 |
TAny* h = NULL;
|
|
1860 |
TInt r = KErrNone;
|
|
1861 |
E32Loader::CodeSegNext(h, find);
|
|
1862 |
if(h)
|
|
1863 |
{
|
|
1864 |
// found...
|
|
1865 |
iHandle = h;
|
|
1866 |
__IF_DEBUG(Printf("Client process handle %08x",iClientProcessHandle));
|
|
1867 |
E32Loader::CodeSegInfo(h, *this);
|
|
1868 |
__IF_DEBUG(Printf("Client process handle %08x",iClientProcessHandle));
|
|
1869 |
r = E32Loader::CodeSegOpen(h, iClientProcessHandle);
|
|
1870 |
}
|
|
1871 |
E32Loader::CodeSegEndDeferDeletes();
|
|
1872 |
|
|
1873 |
if(iHandle && r==KErrNone)
|
|
1874 |
{
|
|
1875 |
iAlreadyLoaded = ETrue;
|
|
1876 |
TUint32 attrMask = (gExecutesInSupervisorMode)?
|
|
1877 |
// The loader reads export directories in kernel mode so it can access
|
|
1878 |
// kernel code export directories and global export directories.
|
|
1879 |
ECodeSegAttKernel | ECodeSegAttGlobal :
|
|
1880 |
// The loader reads export directories in user mode so it can't access
|
|
1881 |
// kernel code export directories but can access global export directories.
|
|
1882 |
ECodeSegAttGlobal;
|
|
1883 |
|
|
1884 |
if(iAttr & attrMask)
|
|
1885 |
{// The export directory is visible to loader so set iExportDirLoad to prevent
|
|
1886 |
// the loader from invoking E32Loader::ReadExportDir() to copy the kernel's copy
|
|
1887 |
// of the export directory to the loader's heap.
|
|
1888 |
iExportDirLoad = iExportDir;
|
|
1889 |
}
|
|
1890 |
}
|
|
1891 |
|
|
1892 |
__IF_DEBUG(Printf("<E32Image::CheckAlreadyLoaded %08x, %d",iHandle,r));
|
|
1893 |
return r;
|
|
1894 |
}
|
|
1895 |
|
|
1896 |
TInt E32Image::Order(const E32Image& aL, const E32Image& aR)
|
|
1897 |
{
|
|
1898 |
return aL.RootName().CompareF(aR.RootName());
|
|
1899 |
}
|
|
1900 |
|
|
1901 |
/******************************************************************************
|
|
1902 |
* Loader debug code
|
|
1903 |
******************************************************************************/
|
|
1904 |
|
|
1905 |
#ifdef _DEBUG
|
|
1906 |
TInt DoLoaderDebugFunction(const RMessage2& aMsg)
|
|
1907 |
{
|
|
1908 |
TInt f=aMsg.Int0();
|
|
1909 |
__IF_DEBUG(Printf("LdrDbg: %d,%d,%d,%d",f,aMsg.Int1(),aMsg.Int2(),aMsg.Int3()));
|
|
1910 |
switch(f)
|
|
1911 |
{
|
|
1912 |
case ELoaderDebug_SetHeapFail:
|
|
1913 |
KernHeapFailCount=aMsg.Int2();
|
|
1914 |
LdrHeapFailCount=aMsg.Int1();
|
|
1915 |
return KErrNone;
|
|
1916 |
case ELoaderDebug_SetRFsFail:
|
|
1917 |
RFsErrorCode = aMsg.Int1();
|
|
1918 |
RFsFailCount = aMsg.Int2();
|
|
1919 |
return KErrNone;
|
|
1920 |
default:
|
|
1921 |
return KErrNotSupported;
|
|
1922 |
}
|
|
1923 |
}
|
|
1924 |
#endif
|
|
1925 |
|
|
1926 |
#ifdef _DEBUG
|
|
1927 |
void SetupHeapFail(const RMessage2& /*aMsg*/)
|
|
1928 |
{
|
|
1929 |
__IF_DEBUG(Printf("SetupHeapFail: %d,%d",LdrHeapFailCount,KernHeapFailCount));
|
|
1930 |
if (KernHeapFailCount>0)
|
|
1931 |
{
|
|
1932 |
__KHEAP_SETFAIL(RHeap::EFailNext, KernHeapFailCount);
|
|
1933 |
__KHEAP_MARK;
|
|
1934 |
HeapFailActive|=1;
|
|
1935 |
}
|
|
1936 |
if (LdrHeapFailCount>0)
|
|
1937 |
{
|
|
1938 |
__UHEAP_SETFAIL(RHeap::EFailNext, LdrHeapFailCount);
|
|
1939 |
__UHEAP_MARK;
|
|
1940 |
HeapFailActive|=2;
|
|
1941 |
}
|
|
1942 |
ProcessCreated = EFalse;
|
|
1943 |
ProcessDestructStat = KRequestPending;
|
|
1944 |
ProcessDestructStatPtr = &ProcessDestructStat;
|
|
1945 |
}
|
|
1946 |
|
|
1947 |
void EndHeapFailCheck(TInt aError)
|
|
1948 |
{
|
|
1949 |
__IF_DEBUG(Printf("EndHeapFail: %d",aError));
|
|
1950 |
if (aError==KErrNone && ProcessCreated)
|
|
1951 |
{
|
|
1952 |
User::CancelMiscNotifier(ProcessDestructStat);
|
|
1953 |
User::WaitForRequest(ProcessDestructStat);
|
|
1954 |
}
|
|
1955 |
if (aError!=KErrNone)
|
|
1956 |
{
|
|
1957 |
if (ProcessCreated)
|
|
1958 |
// wait for any partially created process to die
|
|
1959 |
User::WaitForRequest(ProcessDestructStat);
|
|
1960 |
|
|
1961 |
// wait for reaper to run
|
|
1962 |
TInt rr;
|
|
1963 |
if (CActiveScheduler::RunIfReady(rr,KPriorityVeryHigh))
|
|
1964 |
User::WaitForAnyRequest();
|
|
1965 |
|
|
1966 |
// wait for any async cleanup in the supervisor to finish
|
|
1967 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
|
|
1968 |
|
|
1969 |
if (HeapFailActive&1)
|
|
1970 |
{
|
|
1971 |
__KHEAP_MARKEND;
|
|
1972 |
}
|
|
1973 |
if (HeapFailActive&2)
|
|
1974 |
{
|
|
1975 |
__UHEAP_MARKEND;
|
|
1976 |
}
|
|
1977 |
}
|
|
1978 |
if (HeapFailActive & 3)
|
|
1979 |
{
|
|
1980 |
__KHEAP_TOTAL_RESET;
|
|
1981 |
__UHEAP_TOTAL_RESET;
|
|
1982 |
}
|
|
1983 |
HeapFailActive=0;
|
|
1984 |
ProcessDestructStatPtr = 0;
|
|
1985 |
ProcessCreated = EFalse;
|
|
1986 |
}
|
|
1987 |
|
|
1988 |
void SetupRFsFail(const RMessage2& /*aMsg*/)
|
|
1989 |
{
|
|
1990 |
__IF_DEBUG(Printf("SetupRFsFail: %d,%d", RFsErrorCode, RFsFailCount));
|
|
1991 |
if (RFsErrorCode!=KErrNone && RFsFailCount>0)
|
|
1992 |
{
|
|
1993 |
gTheLoaderFs.SetErrorCondition(RFsErrorCode, RFsFailCount);
|
|
1994 |
RFsFailActive = ETrue;
|
|
1995 |
}
|
|
1996 |
}
|
|
1997 |
|
|
1998 |
void EndRFsFailCheck(TInt /*aError*/)
|
|
1999 |
{
|
|
2000 |
if (RFsFailActive)
|
|
2001 |
{
|
|
2002 |
gTheLoaderFs.SetErrorCondition(KErrNone);
|
|
2003 |
RFsFailActive = EFalse;
|
|
2004 |
}
|
|
2005 |
}
|
|
2006 |
|
|
2007 |
#endif
|
|
2008 |
|
|
2009 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
2010 |
void RLdrReq::Dump(const char* aTitle) const
|
|
2011 |
{
|
|
2012 |
RDebug::Printf(aTitle);
|
|
2013 |
if (iFileName)
|
|
2014 |
RDebug::Printf("iFileName=%S", iFileName);
|
|
2015 |
if (iPath)
|
|
2016 |
RDebug::Printf("iPath=%S", iPath);
|
|
2017 |
RDebug::Printf("SID %08x Caps %08x %08x", iSecureId, iPlatSecCaps[1], iPlatSecCaps[0]);
|
|
2018 |
const TUint32* uid = (const TUint32*)&iRequestedUids;
|
|
2019 |
RDebug::Printf("REQ UIDs %08x %08x %08x REQ VER %08x", uid[0], uid[1], uid[2], iRequestedVersion);
|
|
2020 |
iFileNameInfo.Dump();
|
|
2021 |
}
|
|
2022 |
|
|
2023 |
void TFileNameInfo::Dump() const
|
|
2024 |
{
|
|
2025 |
const TDesC8& d = Drive();
|
|
2026 |
const TDesC8& p = Path();
|
|
2027 |
const TDesC8& b = Base();
|
|
2028 |
const TDesC8& v = VerStr();
|
|
2029 |
const TDesC8& u = UidStr();
|
|
2030 |
const TDesC8& e = Ext();
|
|
2031 |
RDebug::Printf("D=%S P=%S B=%S V=%S U=%S E=%S", &d, &p, &b, &v, &u, &e);
|
|
2032 |
}
|
|
2033 |
#endif
|
|
2034 |
|
|
2035 |
#ifdef __TRACE_LOADER_HEAP__
|
|
2036 |
|
|
2037 |
class RTraceHeap : public RAllocator
|
|
2038 |
{
|
|
2039 |
public:
|
|
2040 |
virtual TAny* Alloc(TInt aSize);
|
|
2041 |
virtual void Free(TAny* aPtr);
|
|
2042 |
virtual TAny* ReAlloc(TAny* aPtr, TInt aSize, TInt aMode=0);
|
|
2043 |
virtual TInt AllocLen(const TAny* aCell) const;
|
|
2044 |
virtual TInt Compress();
|
|
2045 |
virtual void Reset();
|
|
2046 |
virtual TInt AllocSize(TInt& aTotalAllocSize) const;
|
|
2047 |
virtual TInt Available(TInt& aBiggestBlock) const;
|
|
2048 |
virtual TInt DebugFunction(TInt aFunc, TAny* a1=NULL, TAny* a2=NULL);
|
|
2049 |
public:
|
|
2050 |
RAllocator* iA;
|
|
2051 |
};
|
|
2052 |
|
|
2053 |
void InstallHeapTracer()
|
|
2054 |
{
|
|
2055 |
RTraceHeap* p = new RTraceHeap;
|
|
2056 |
__ASSERT_ALWAYS(p!=NULL, User::Invariant());
|
|
2057 |
p->iA = &User::Heap();
|
|
2058 |
User::SwitchHeap(p);
|
|
2059 |
}
|
|
2060 |
|
|
2061 |
TAny* RTraceHeap::Alloc(TInt aSize)
|
|
2062 |
{
|
|
2063 |
RDebug::Printf("TH:Alloc(%08x)", aSize);
|
|
2064 |
TAny* p = iA->Alloc(aSize);
|
|
2065 |
RDebug::Printf("TH:returns %08x", p);
|
|
2066 |
return p;
|
|
2067 |
}
|
|
2068 |
|
|
2069 |
void RTraceHeap::Free(TAny* aPtr)
|
|
2070 |
{
|
|
2071 |
RDebug::Printf("TH:Free(%08x)", aPtr);
|
|
2072 |
iA->Free(aPtr);
|
|
2073 |
}
|
|
2074 |
|
|
2075 |
TAny* RTraceHeap::ReAlloc(TAny* aPtr, TInt aSize, TInt aMode=0)
|
|
2076 |
{
|
|
2077 |
RDebug::Printf("TH:ReAlloc(%08x,%08x,%x)", aPtr, aSize, aMode);
|
|
2078 |
TAny* p = iA->ReAlloc(aPtr,aSize,aMode);
|
|
2079 |
RDebug::Printf("TH:returns %08x", p);
|
|
2080 |
return p;
|
|
2081 |
}
|
|
2082 |
|
|
2083 |
TInt RTraceHeap::AllocLen(const TAny* aCell) const
|
|
2084 |
{
|
|
2085 |
RDebug::Printf("TH:AllocLen(%08x)", aCell);
|
|
2086 |
TInt l = iA->AllocLen(aCell);
|
|
2087 |
RDebug::Printf("TH:returns %08x", l);
|
|
2088 |
return l;
|
|
2089 |
}
|
|
2090 |
|
|
2091 |
TInt RTraceHeap::Compress()
|
|
2092 |
{
|
|
2093 |
RDebug::Printf("TH:Compress()");
|
|
2094 |
TInt l = iA->Compress();
|
|
2095 |
RDebug::Printf("TH:returns %08x", l);
|
|
2096 |
return l;
|
|
2097 |
}
|
|
2098 |
|
|
2099 |
void RTraceHeap::Reset()
|
|
2100 |
{
|
|
2101 |
RDebug::Printf("TH:Reset()");
|
|
2102 |
iA->Reset();
|
|
2103 |
}
|
|
2104 |
|
|
2105 |
TInt RTraceHeap::AllocSize(TInt& aTotalAllocSize) const
|
|
2106 |
{
|
|
2107 |
RDebug::Printf("TH:AllocSize()");
|
|
2108 |
TInt s;
|
|
2109 |
TInt r = iA->AllocSize(s);
|
|
2110 |
RDebug::Printf("TH:returns %08x(%08x)", r, s);
|
|
2111 |
aTotalAllocSize = s;
|
|
2112 |
return r;
|
|
2113 |
}
|
|
2114 |
|
|
2115 |
TInt RTraceHeap::Available(TInt& aBiggestBlock) const
|
|
2116 |
{
|
|
2117 |
RDebug::Printf("TH:Available()");
|
|
2118 |
TInt s;
|
|
2119 |
TInt r = iA->Available(s);
|
|
2120 |
RDebug::Printf("TH:returns %08x(%08x)", r, s);
|
|
2121 |
aBiggestBlock = s;
|
|
2122 |
return r;
|
|
2123 |
}
|
|
2124 |
|
|
2125 |
TInt RTraceHeap::DebugFunction(TInt aFunc, TAny* a1=NULL, TAny* a2=NULL)
|
|
2126 |
{
|
|
2127 |
RDebug::Printf("TH:DebugFunction(%d,%08x,%08x)", aFunc, a1, a2);
|
|
2128 |
TInt r = iA->DebugFunction(aFunc, a1, a2);
|
|
2129 |
RDebug::Printf("TH:returns %08x", r);
|
|
2130 |
return r;
|
|
2131 |
}
|
|
2132 |
|
|
2133 |
#endif
|
|
2134 |
|
|
2135 |
/* The Reaper - Used to delete binarys in /sys/del/ after they are no longer needed by demand paging */
|
|
2136 |
|
|
2137 |
CActiveReaper::CActiveReaper()
|
|
2138 |
: CActive(KPriorityVeryHigh)
|
|
2139 |
{
|
|
2140 |
iLoaderDeletedList=NULL;
|
|
2141 |
}
|
|
2142 |
|
|
2143 |
CActiveReaper* CActiveReaper::New()
|
|
2144 |
{
|
|
2145 |
CActiveReaper *self = new CActiveReaper();
|
|
2146 |
if (self!=NULL)
|
|
2147 |
self->Construct();
|
|
2148 |
return self;
|
|
2149 |
}
|
|
2150 |
|
|
2151 |
void CActiveReaper::Construct()
|
|
2152 |
{
|
|
2153 |
iStatus=KRequestPending;
|
|
2154 |
CActiveScheduler::Add(this);
|
|
2155 |
E32Loader::NotifyIfCodeSegDestroyed(iStatus);
|
|
2156 |
SetActive();
|
|
2157 |
}
|
|
2158 |
|
|
2159 |
/*
|
|
2160 |
Initialises the \sys\del\ directory, where files can be moved too, on deletion.
|
|
2161 |
If the directory exists, then it is emptied.
|
|
2162 |
*/
|
|
2163 |
|
|
2164 |
void CActiveReaper::InitDelDir()
|
|
2165 |
{
|
|
2166 |
TDriveList driveList;
|
|
2167 |
TDriveInfo driveInfo;
|
|
2168 |
CDir* dir=NULL;
|
|
2169 |
TFileName fileName;
|
|
2170 |
TInt i;
|
|
2171 |
TBuf<KPathDelLength> drivePath(KPathDel);
|
|
2172 |
TInt r = gTheLoaderFs.DriveList(driveList);
|
|
2173 |
if (r!=KErrNone)
|
|
2174 |
return;
|
|
2175 |
TChar ch;
|
|
2176 |
for (TInt drvNum=0; drvNum<KMaxDrives; ++drvNum)
|
|
2177 |
{
|
|
2178 |
if(!driveList[drvNum])
|
|
2179 |
continue; //-- skip nonexistent drive
|
|
2180 |
r = gTheLoaderFs.Drive(driveInfo, drvNum);
|
|
2181 |
if ((r==KErrNone) && (driveInfo.iDriveAtt & KDriveAttPageable) && !(driveInfo.iMediaAtt & KMediaAttWriteProtected))
|
|
2182 |
{
|
|
2183 |
gTheLoaderFs.DriveToChar(drvNum, ch);
|
|
2184 |
drivePath[0]=(TText)ch;
|
|
2185 |
r = gTheLoaderFs.GetDir(drivePath,KEntryAttMatchExclude | KEntryAttDir ,ESortNone,dir);
|
|
2186 |
if (r==KErrNone)
|
|
2187 |
{
|
|
2188 |
for (i=dir->Count()-1;i>=0;i--)
|
|
2189 |
{
|
|
2190 |
fileName = drivePath;
|
|
2191 |
fileName.Append((*dir)[i].iName);
|
|
2192 |
r = gTheLoaderFs.SetAtt(fileName,0,KEntryAttReadOnly|KEntryAttSystem);
|
|
2193 |
r = gTheLoaderFs.Delete(fileName);
|
|
2194 |
}
|
|
2195 |
delete dir;
|
|
2196 |
}
|
|
2197 |
}
|
|
2198 |
}
|
|
2199 |
}
|
|
2200 |
|
|
2201 |
|
|
2202 |
void CActiveReaper::RunL()
|
|
2203 |
{
|
|
2204 |
|
|
2205 |
TCodeSegLoaderCookie cookie;
|
|
2206 |
TInt r;
|
|
2207 |
|
|
2208 |
TLoaderDeletedList* link;
|
|
2209 |
TLoaderDeletedList* prev;
|
|
2210 |
|
|
2211 |
iStatus=KRequestPending;
|
|
2212 |
E32Loader::NotifyIfCodeSegDestroyed(iStatus);
|
|
2213 |
SetActive();
|
|
2214 |
FOREVER
|
|
2215 |
{
|
|
2216 |
r=E32Loader::GetDestroyedCodeSegInfo(cookie);
|
|
2217 |
if (r!=KErrNone)
|
|
2218 |
break;
|
|
2219 |
r = cookie.iFileClamp.Close(gTheLoaderFs);
|
|
2220 |
// See if its on our list.
|
|
2221 |
if (r==KErrNone)
|
|
2222 |
{
|
|
2223 |
link = iLoaderDeletedList;
|
|
2224 |
prev= (TLoaderDeletedList*) &iLoaderDeletedList;
|
|
2225 |
|
|
2226 |
while (link!=NULL)
|
|
2227 |
{
|
|
2228 |
if ((link->iStartBlock==cookie.iStartAddress) && (link->iDriveNumber==cookie.iDriveNumber))
|
|
2229 |
{
|
|
2230 |
gTheLoaderFs.Delete(*link->iFileName);
|
|
2231 |
// Ignore error from file delete operation. If it does fail then the
|
|
2232 |
// file will just have to sit around until it is cleaned up on the next reboot.
|
|
2233 |
|
|
2234 |
// Remove from our list.
|
|
2235 |
prev->iNext=link->iNext;
|
|
2236 |
delete link;
|
|
2237 |
link = prev->iNext;
|
|
2238 |
}
|
|
2239 |
else
|
|
2240 |
{
|
|
2241 |
prev = link;
|
|
2242 |
link = link->iNext;
|
|
2243 |
}
|
|
2244 |
}// while
|
|
2245 |
} // if unclamp ok
|
|
2246 |
} //Forever
|
|
2247 |
}
|
|
2248 |
|
|
2249 |
void CActiveReaper::DoCancel(){};
|
|
2250 |
|
|
2251 |
CActiveReaper::~CActiveReaper() {}
|
|
2252 |
|
|
2253 |
void CActiveReaper::AddDeleted(TLoaderDeletedList* aLink)
|
|
2254 |
{
|
|
2255 |
aLink->iNext=iLoaderDeletedList;
|
|
2256 |
iLoaderDeletedList = aLink;
|
|
2257 |
}
|
|
2258 |
|
|
2259 |
/* Slotted allocator - used to store iFileData from hashchecked images */
|
|
2260 |
|
|
2261 |
TInt CSlottedChunkAllocator::Construct()
|
|
2262 |
{
|
|
2263 |
TInt r = iChunk.CreateDisconnectedLocal(0, 0, KSlotSize * KSlots);
|
|
2264 |
if (r == KErrNone)
|
|
2265 |
iBase = iChunk.Base();
|
|
2266 |
return r;
|
|
2267 |
}
|
|
2268 |
|
|
2269 |
TAny* CSlottedChunkAllocator::Alloc(TUint aSize)
|
|
2270 |
{
|
|
2271 |
if (aSize == 0 || aSize > KSlotSize)
|
|
2272 |
return NULL;
|
|
2273 |
|
|
2274 |
for (TInt i=0; i<KSlots; ++i)
|
|
2275 |
if (!iUsed[i])
|
|
2276 |
{
|
|
2277 |
if (iChunk.Commit(i * KSlotSize, aSize) == KErrNone)
|
|
2278 |
{
|
|
2279 |
iUsed[i] = aSize;
|
|
2280 |
return iBase + i * KSlotSize;
|
|
2281 |
}
|
|
2282 |
else
|
|
2283 |
return NULL;
|
|
2284 |
}
|
|
2285 |
|
|
2286 |
return NULL;
|
|
2287 |
}
|
|
2288 |
|
|
2289 |
void CSlottedChunkAllocator::Free(TAny* aPtr)
|
|
2290 |
{
|
|
2291 |
if (!aPtr)
|
|
2292 |
return;
|
|
2293 |
|
|
2294 |
TInt offset = ((TUint8*)aPtr) - iBase;
|
|
2295 |
TInt slot = offset / KSlotSize;
|
|
2296 |
__ASSERT_DEBUG(offset % KSlotSize == 0 && slot >= 0 && slot < KSlots, Fault(ELdrFileDataAllocError));
|
|
2297 |
#ifdef _DEBUG
|
|
2298 |
TInt r =
|
|
2299 |
#endif
|
|
2300 |
iChunk.Decommit(offset, iUsed[slot]);
|
|
2301 |
__ASSERT_DEBUG(r==KErrNone, Fault(ELdrFileDataAllocError));
|
|
2302 |
iUsed[slot] = 0;
|
|
2303 |
}
|