author | hgs |
Mon, 24 May 2010 18:38:55 +0100 | |
changeset 134 | 95847726fe57 |
parent 90 | 947f0dc9f7a8 |
child 300 | 1d28c8722707 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32\kernel\scodeseg.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <kernel/kern_priv.h> |
|
19 |
#include <e32uid.h> |
|
20 |
#include "execs.h" |
|
21 |
||
22 |
extern void InvalidExecHandler(); |
|
23 |
||
24 |
// Compare code segments by name |
|
25 |
TInt CompareCodeSegsByName(const DCodeSeg& aA, const DCodeSeg& aB) |
|
26 |
{ |
|
27 |
TLinAddr aa = (TLinAddr)&aA; |
|
28 |
const TDesC8* pA = (aa & 1) ? (const TDesC8*)(aa&~3) : &aA.iRootName; |
|
29 |
return pA->CompareF(aB.iRootName); |
|
30 |
} |
|
31 |
||
32 |
||
33 |
// |
|
34 |
// DCodeSeg::RCodeSegsByAddress |
|
35 |
// |
|
36 |
||
37 |
DCodeSeg::RCodeSegsByAddress::RCodeSegsByAddress(TInt aMinGrowBy, TInt aFactor) |
|
38 |
: iActive(0) |
|
39 |
{ |
|
40 |
new (iArray+0) RPointerArray<DCodeSeg>(aMinGrowBy, aFactor); |
|
41 |
new (iArray+1) RPointerArray<DCodeSeg>(aMinGrowBy, aFactor); |
|
42 |
} |
|
43 |
||
44 |
||
45 |
TInt DCodeSeg::RCodeSegsByAddress::Add(DCodeSeg* aCodeSeg) |
|
46 |
{ |
|
47 |
TInt r = iArray[iActive^1].InsertInOrder(aCodeSeg, Compare); |
|
48 |
if(r!=KErrNone) |
|
49 |
return r; |
|
50 |
NKern::LockSystem(); |
|
51 |
iActive^=1; |
|
52 |
NKern::UnlockSystem(); |
|
53 |
r = iArray[iActive^1].InsertInOrder(aCodeSeg, Compare); |
|
54 |
if(r!=KErrNone) |
|
55 |
Remove(aCodeSeg); |
|
56 |
return r; |
|
57 |
} |
|
58 |
||
59 |
||
60 |
TInt DCodeSeg::RCodeSegsByAddress::Remove(DCodeSeg* aCodeseg) |
|
61 |
{ |
|
62 |
TInt result = KErrNotFound; |
|
63 |
TInt active = iActive; |
|
64 |
for(;;) |
|
65 |
{ |
|
66 |
RPointerArray<DCodeSeg>& array = iArray[iActive^1]; |
|
67 |
TInt first = array.SpecificFindInOrder(aCodeseg, Compare, EArrayFindMode_First); |
|
68 |
TInt last = array.SpecificFindInOrder(aCodeseg, Compare, EArrayFindMode_Last); |
|
69 |
for(; first >= 0 && first < last; ++first) |
|
70 |
if(array[first]==aCodeseg) |
|
71 |
{ |
|
72 |
array.Remove(first); |
|
73 |
result = KErrNone; |
|
74 |
break; |
|
75 |
} |
|
76 |
if(active!=iActive) |
|
77 |
return result; |
|
78 |
NKern::LockSystem(); |
|
79 |
iActive ^= 1; |
|
80 |
NKern::UnlockSystem(); |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
||
85 |
DCodeSeg* DCodeSeg::RCodeSegsByAddress::Find(TLinAddr aAddress) |
|
86 |
{ |
|
87 |
DCodeSeg* s = NULL; |
|
88 |
DCodeSeg* st = (DCodeSeg*)(TLinAddr(&aAddress)+1); |
|
89 |
RPointerArray<DCodeSeg>& array = iArray[iActive]; |
|
90 |
TInt ix; |
|
91 |
array.SpecificFindInOrder(st, ix, Compare, EArrayFindMode_Last); |
|
92 |
if (ix) |
|
93 |
{ |
|
94 |
s = array[ix-1]; |
|
95 |
if (aAddress<s->iRunAddress || (aAddress-s->iRunAddress) >= s->iSize) |
|
96 |
s = NULL; |
|
97 |
} |
|
98 |
return s; |
|
99 |
} |
|
100 |
||
101 |
||
102 |
TInt DCodeSeg::RCodeSegsByAddress::Compare(const DCodeSeg& aA, const DCodeSeg& aB) |
|
103 |
{ |
|
104 |
TLinAddr aa = (TLinAddr)&aA; |
|
105 |
TLinAddr a = (aa&1) ? *(TLinAddr*)(aa&~3) : aA.iRunAddress; |
|
106 |
TLinAddr b = aB.iRunAddress; |
|
107 |
if (a > b) |
|
108 |
return 1; |
|
109 |
else if (a < b) |
|
110 |
return -1; |
|
111 |
return 0; |
|
112 |
} |
|
113 |
||
114 |
||
115 |
inline TBool CheckUid(const TUid aUid, const TUid aRequestedUid) |
|
116 |
{ |
|
117 |
return (aRequestedUid.iUid==0 || aRequestedUid.iUid==aUid.iUid); |
|
118 |
} |
|
119 |
||
120 |
TBool K::CheckUids(const TUidType& aUids, const TUidType& aRequestedUids) |
|
121 |
{ |
|
122 |
return CheckUid(aUids.iUid[0],aRequestedUids.iUid[0]) && |
|
123 |
CheckUid(aUids.iUid[1],aRequestedUids.iUid[1]) && |
|
124 |
CheckUid(aUids.iUid[2],aRequestedUids.iUid[2]); |
|
125 |
} |
|
126 |
||
127 |
/** Enters thread critical section and acquires code segment mutex. |
|
128 |
||
129 |
@pre No fast mutex can be held. |
|
130 |
@pre Call in a thread context. |
|
131 |
@pre Kernel must be unlocked |
|
132 |
@pre interrupts enabled |
|
133 |
*/ |
|
134 |
EXPORT_C void Kern::AccessCode() |
|
135 |
{ |
|
136 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Kern::AccessCode"); |
|
137 |
NKern::ThreadEnterCS(); |
|
138 |
DCodeSeg::Wait(); |
|
139 |
} |
|
140 |
||
141 |
/** Exits thread critical section and releases code segment mutex. |
|
142 |
||
143 |
@pre No fast mutex can be held. |
|
144 |
@pre Call in a thread context. |
|
145 |
@pre Kernel must be unlocked |
|
146 |
@pre interrupts enabled |
|
147 |
@pre Calling thread must be in a critical section |
|
148 |
*/ |
|
149 |
EXPORT_C void Kern::EndAccessCode() |
|
150 |
{ |
|
151 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::EndAccessCode"); |
|
152 |
DCodeSeg::Signal(); |
|
153 |
NKern::ThreadLeaveCS(); |
|
154 |
} |
|
155 |
||
156 |
/** Accessor function for the kernel's code segment list. |
|
157 |
||
158 |
@return Pointer to the code segment list. |
|
159 |
*/ |
|
160 |
EXPORT_C SDblQue* Kern::CodeSegList() |
|
161 |
{ |
|
162 |
return &DCodeSeg::GlobalList; |
|
163 |
} |
|
164 |
||
165 |
/** Accessor function for the kernel's code segment list mutex. |
|
166 |
||
167 |
@return Pointer to the code segment list mutex. |
|
168 |
*/ |
|
169 |
EXPORT_C DMutex* Kern::CodeSegLock() |
|
170 |
{ |
|
171 |
return DCodeSeg::CodeSegLock; |
|
172 |
} |
|
173 |
||
174 |
#ifdef KDLL |
|
175 |
GLDEF_C void DumpCodeSegCreateInfo(TCodeSegCreateInfo& a) |
|
176 |
{ |
|
177 |
Kern::Printf("UIDS: %08x %08x %08x",a.iUids.iUid[0],a.iUids.iUid[1],a.iUids.iUid[2]); |
|
178 |
Kern::Printf("Attr: %08x",a.iAttr); |
|
179 |
Kern::Printf("Code size: %08x",a.iCodeSize); |
|
180 |
Kern::Printf("Text size: %08x",a.iTextSize); |
|
181 |
Kern::Printf("Data size: %08x",a.iDataSize); |
|
182 |
Kern::Printf("Bss size: %08x",a.iBssSize); |
|
183 |
Kern::Printf("Total data size: %08x",a.iTotalDataSize); |
|
184 |
Kern::Printf("Entry Point Veneer: %08x",a.iEntryPtVeneer); |
|
185 |
Kern::Printf("File Entry Point: %08x",a.iFileEntryPoint); |
|
186 |
Kern::Printf("DepCount: %d",a.iDepCount); |
|
187 |
Kern::Printf("ExportDir: %08x",a.iExportDir); |
|
188 |
Kern::Printf("ExportDirCount: %08x",a.iExportDirCount); |
|
189 |
Kern::Printf("CodeLoad: %08x",a.iCodeLoadAddress); |
|
190 |
Kern::Printf("CodeRun: %08x",a.iCodeRunAddress); |
|
191 |
Kern::Printf("DataLoad: %08x",a.iDataLoadAddress); |
|
192 |
Kern::Printf("DataRun: %08x",a.iDataRunAddress); |
|
193 |
Kern::Printf("RootName off: %d len: %d",a.iRootNameOffset,a.iRootNameLength); |
|
194 |
Kern::Printf("Ext offset: %d",a.iExtOffset); |
|
195 |
Kern::Printf("Ver: %08x",a.iModuleVersion); |
|
196 |
Kern::Printf("SID: %08x",a.iS.iSecureId); |
|
197 |
Kern::Printf("Cap: %08x %08x",a.iS.iCaps[1],a.iS.iCaps[0]); |
|
198 |
Kern::Printf("Handle: %08x",a.iHandle); |
|
199 |
Kern::Printf("Client Process Handle: %08x",a.iClientProcessHandle); |
|
200 |
Kern::Printf("CodeRelocTable: %d bytes at %08x", a.iCodeRelocTableSize, a.iCodeRelocTable); |
|
201 |
Kern::Printf("ImportFixupTabl: %d bytes at %08x", a.iImportFixupTableSize, a.iImportFixupTable); |
|
202 |
Kern::Printf("CodeDelta: %08x", a.iCodeDelta); |
|
203 |
Kern::Printf("DataDelta: %08x", a.iDataDelta); |
|
204 |
Kern::Printf("UseCodePaging: %d", a.iUseCodePaging); |
|
205 |
} |
|
206 |
||
207 |
GLDEF_C void DumpProcessCreateInfo(TProcessCreateInfo& a) |
|
208 |
{ |
|
209 |
DumpCodeSegCreateInfo(a); |
|
210 |
Kern::Printf("HeapSizeMin: %08x", a.iHeapSizeMin); |
|
211 |
Kern::Printf("HeapSizeMax: %08x", a.iHeapSizeMax); |
|
212 |
Kern::Printf("StackSize: %08x", a.iStackSize); |
|
213 |
Kern::Printf("Client Handle: %08x",a.iClientHandle); |
|
214 |
Kern::Printf("Process Handle: %08x",a.iProcessHandle); |
|
215 |
Kern::Printf("Final Handle: %08x",a.iFinalHandle); |
|
216 |
Kern::Printf("OwnerType: %08x",a.iOwnerType); |
|
217 |
Kern::Printf("Priority: %08x",a.iPriority); |
|
218 |
Kern::Printf("Debug Attributes: %08x", a.iDebugAttributes); |
|
219 |
} |
|
220 |
#endif |
|
221 |
||
222 |
/****************************************************************************** |
|
223 |
* DCodeSeg class |
|
224 |
******************************************************************************/ |
|
225 |
void DCodeSeg::Wait() |
|
226 |
{ |
|
227 |
if (CodeSegLock) |
|
228 |
Kern::MutexWait(*CodeSegLock); |
|
229 |
} |
|
230 |
||
231 |
void DCodeSeg::Signal() |
|
232 |
{ |
|
233 |
if (CodeSegLock) |
|
234 |
Kern::MutexSignal(*CodeSegLock); |
|
235 |
} |
|
236 |
||
237 |
||
238 |
/** Verifies that a code segment handle is valid. |
|
239 |
||
240 |
@param aHandle The code segment handle to check. |
|
241 |
||
242 |
@return A pointer to the code segment if the handle is valid; |
|
243 |
NULL, if the handle is invalid. |
|
244 |
||
245 |
@pre Call in a thread context. |
|
246 |
*/ |
|
247 |
EXPORT_C DCodeSeg* DCodeSeg::VerifyHandle(TAny* aHandle) |
|
248 |
{ |
|
249 |
CHECK_PRECONDITIONS(MASK_NOT_ISR|MASK_NOT_IDFC,"DCodeSeg::VerifyHandle"); |
|
250 |
DCodeSeg* pS=NULL; |
|
251 |
if (K::IsInKernelHeap(aHandle,sizeof(DCodeSeg))) |
|
252 |
{ |
|
253 |
TUint32 cs_buf[sizeof(DCodeSeg)/sizeof(TUint32)]; |
|
254 |
if (!Kern::SafeRead(aHandle,cs_buf,sizeof(DCodeSeg))) |
|
255 |
{ |
|
256 |
DCodeSeg& cs=*(DCodeSeg*)cs_buf; |
|
257 |
TInt32 uid1=cs.iUids.iUid[0].iUid; |
|
258 |
if (cs.iAsyncDeleteNext==aHandle && (uid1==KDynamicLibraryUidValue || uid1==KExecutableImageUidValue)) |
|
259 |
pS=(DCodeSeg*)aHandle; |
|
260 |
} |
|
261 |
} |
|
262 |
return pS; |
|
263 |
} |
|
264 |
||
265 |
DCodeSeg* DCodeSeg::VerifyHandleP(TAny* aHandle) |
|
266 |
{ |
|
267 |
DCodeSeg* pS=VerifyHandle(aHandle); |
|
268 |
if (!pS) |
|
269 |
K::PanicKernExec(EBadCodeSegHandle); |
|
270 |
return pS; |
|
271 |
} |
|
272 |
||
273 |
DCodeSeg* DCodeSeg::VerifyCallerAndHandle(TAny* aHandle) |
|
274 |
{ |
|
275 |
K::CheckFileServerAccess(); |
|
276 |
return VerifyHandleP(aHandle); |
|
277 |
} |
|
278 |
||
279 |
DCodeSeg* DCodeSeg::FindCodeSeg(const TFindCodeSeg& aFind) |
|
280 |
{ |
|
281 |
if (GlobalList.IsEmpty()) |
|
282 |
return NULL; |
|
283 |
DCodeSeg* st = (DCodeSeg*)(TLinAddr(&aFind.iName)+1); |
|
284 |
TBool newExe = (aFind.iUids.iUid[0].iUid==KExecutableImageUidValue); |
|
285 |
DProcess* pP = (DProcess*)aFind.iProcess; |
|
286 |
TInt first = CodeSegsByName.SpecificFindInOrder(st, &CompareCodeSegsByName, EArrayFindMode_First); |
|
287 |
TInt last = CodeSegsByName.SpecificFindInOrder(st, &CompareCodeSegsByName, EArrayFindMode_Last); |
|
288 |
__KTRACE_OPT(KDLL, Kern::Printf("FindCodeSeg %S first=%d last=%d", &aFind.iName, first, last)); |
|
289 |
for (; first >= 0 && first < last; ++first) |
|
290 |
{ |
|
291 |
DCodeSeg* pS = CodeSegsByName[first]; |
|
292 |
if (!(pS->iMark&EMarkLoaded)) |
|
293 |
continue; |
|
294 |
if (((pS->iAttr ^ aFind.iAttrVal) & aFind.iAttrMask) != 0 || !K::CheckUids(pS->iUids,aFind.iUids) ) |
|
295 |
continue; |
|
296 |
if (aFind.iS.iSecureId && aFind.iS.iSecureId != pS->iS.iSecureId) |
|
297 |
continue; |
|
298 |
if (aFind.iModuleVersion!=KModuleVersionWild && aFind.iModuleVersion!=pS->iModuleVersion) |
|
299 |
continue; |
|
300 |
TUint32 c = 0; |
|
301 |
TInt i; |
|
302 |
for (i=0; i<SCapabilitySet::ENCapW; ++i) |
|
303 |
c |= (aFind.iS.iCaps[i] &~ pS->iS.iCaps[i]); |
|
304 |
if (c) |
|
305 |
continue; |
|
306 |
if ((pP||newExe) && !pS->FindCheck(pP)) |
|
307 |
continue; |
|
308 |
return pS; |
|
309 |
} |
|
310 |
return NULL; |
|
311 |
} |
|
312 |
||
313 |
||
314 |
/** Removes a specified set of mark bits from every code segment in the system. |
|
315 |
||
316 |
@param aMask The mask of bits to reset. |
|
317 |
||
318 |
@pre Calling thread must be in a critical section. |
|
319 |
@pre No fast mutex can be held. |
|
320 |
@pre Call in a thread context. |
|
321 |
@pre Code segment lock mutex held. |
|
322 |
@pre Kernel must be unlocked |
|
323 |
@pre interrupts enabled |
|
324 |
*/ |
|
325 |
EXPORT_C void DCodeSeg::UnmarkAll(TUint32 aMask) |
|
326 |
{ |
|
327 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"DCodeSeg::UnmarkAll"); |
|
328 |
__ASSERT_WITH_MESSAGE_MUTEX(CodeSegLock,"Code segment lock mutex held","DCodeSeg::UnmarkAll"); |
|
329 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::UnmarkAll %08x",aMask)); |
|
330 |
SDblQueLink* anchor=&GlobalList.iA; |
|
331 |
SDblQueLink* pL=anchor->iNext; |
|
332 |
for (; pL!=anchor; pL=pL->iNext) |
|
333 |
_LOFF(pL,DCodeSeg,iLink)->iMark &= ~aMask; |
|
334 |
} |
|
335 |
||
336 |
||
337 |
void DCodeSeg::UnmarkAndCloseAll(TUint32 aMask) |
|
338 |
{ |
|
339 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::UnmarkAndCloseAll %08x",aMask)); |
|
340 |
SDblQueLink* anchor=&GlobalList.iA; |
|
341 |
SDblQueLink* pL=anchor->iNext; |
|
342 |
SDblQueLink* pN=pL->iNext; |
|
343 |
for (; pL!=anchor; pL=pN, pN=pN->iNext) |
|
344 |
{ |
|
345 |
DCodeSeg* pS=_LOFF(pL,DCodeSeg,iLink); |
|
346 |
if (pS->iMark & aMask) |
|
347 |
{ |
|
348 |
pS->iMark &= ~aMask; |
|
349 |
pS->Close(); |
|
350 |
} |
|
351 |
} |
|
352 |
} |
|
353 |
||
354 |
TInt DCodeSeg::ListMarked(SDblQue& aQ, TUint32 aMask) |
|
355 |
{ |
|
356 |
__KTRACE_OPT(KDLL,Kern::Printf(">DCodeSeg::ListMarked %08x",aMask)); |
|
357 |
TInt n=0; |
|
358 |
SDblQueLink* anchor=&GlobalList.iA; |
|
359 |
SDblQueLink* pL=anchor->iNext; |
|
360 |
for (; pL!=anchor; pL=pL->iNext) |
|
361 |
{ |
|
362 |
DCodeSeg* pS=_LOFF(pL,DCodeSeg,iLink); |
|
363 |
if (pS->iMark & aMask) |
|
364 |
{ |
|
365 |
aQ.Add(&pS->iTempLink); |
|
366 |
++n; |
|
367 |
} |
|
368 |
} |
|
369 |
__KTRACE_OPT(KDLL,Kern::Printf("<DCodeSeg::ListMarked %d",n)); |
|
370 |
return n; |
|
371 |
} |
|
372 |
||
373 |
||
374 |
/** Removes all code segments from a queue and clear specified mark(s). |
|
375 |
||
376 |
@param aQ Queue to iterate. Code segments are linked together via DCodeSeg::iTempLink. |
|
377 |
@param aMask Bits to clear in DCodeSeg::iMark fields of iterated code segments. |
|
378 |
||
379 |
@pre DCodeSeg::CodeSegLock mutex held |
|
380 |
||
381 |
@post DCodeSeg::CodeSegLock mutex held |
|
382 |
||
383 |
@publishedPartner |
|
384 |
@released |
|
385 |
*/ |
|
386 |
EXPORT_C void DCodeSeg::EmptyQueue(SDblQue& aQ, TUint32 aMask) |
|
387 |
{ |
|
388 |
__ASSERT_WITH_MESSAGE_MUTEX(CodeSegLock,"Code segment lock mutex held","DCodeSeg::EmptyQueue"); |
|
389 |
while(!aQ.IsEmpty()) |
|
390 |
{ |
|
391 |
DCodeSeg* pS=_LOFF(aQ.First()->Deque(), DCodeSeg, iTempLink); |
|
392 |
pS->iTempLink.iNext=NULL; |
|
393 |
pS->iMark &= ~aMask; |
|
394 |
} |
|
395 |
} |
|
396 |
||
397 |
void DCodeSeg::DoKernelCleanup(TAny*) |
|
398 |
{ |
|
399 |
// Clean up kernel-side code segments |
|
400 |
// Runs in supervisor thread |
|
401 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::DoKernelCleanup")); |
|
402 |
DCodeSeg::Wait(); |
|
403 |
while(!KernelGarbageList.IsEmpty()) |
|
404 |
{ |
|
405 |
// if system has not gone idle since next codeseg was queued... |
|
406 |
DCodeSeg* pS = _LOFF(KernelGarbageList.First(),DCodeSeg,iGbgLink); |
|
407 |
TUint32 idleGenerationCount = pS->iGbgIdleGenerationCount; |
|
408 |
if(idleGenerationCount==NKern::IdleGenerationCount()) |
|
409 |
{ |
|
410 |
// then queue cleanup again for later... |
|
411 |
QueueKernelCleanup(); |
|
412 |
break; |
|
413 |
} |
|
414 |
||
415 |
// close all codesegs with the same iGbgIdleGenerationCount... |
|
416 |
do |
|
417 |
{ |
|
418 |
// deque and close codeseg... |
|
419 |
pS->iGbgLink.Deque(); |
|
420 |
pS->iGbgLink.iNext = NULL; |
|
421 |
__NK_ASSERT_DEBUG(pS->iAccessCount>0); |
|
422 |
pS->CheckedClose(); |
|
423 |
||
424 |
// get next codeseg... |
|
425 |
if(KernelGarbageList.IsEmpty()) |
|
426 |
break; |
|
427 |
pS = _LOFF(KernelGarbageList.First(),DCodeSeg,iGbgLink); |
|
428 |
} |
|
429 |
while(pS->iGbgIdleGenerationCount==idleGenerationCount); |
|
430 |
} |
|
431 |
DCodeSeg::Signal(); |
|
432 |
} |
|
433 |
||
434 |
void DCodeSeg::EmptyGarbageList() |
|
435 |
{ |
|
436 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::EmptyGarbageList")); |
|
437 |
while(!GarbageList.IsEmpty()) |
|
438 |
{ |
|
439 |
DCodeSeg* pS=_LOFF(GarbageList.First()->Deque(),DCodeSeg,iGbgLink); |
|
440 |
__NK_ASSERT_DEBUG(pS->iAccessCount==0); |
|
441 |
pS->iGbgLink.iNext=NULL; |
|
442 |
delete pS; |
|
443 |
} |
|
444 |
} |
|
445 |
||
446 |
void DCodeSeg::DeferDeletes() |
|
447 |
{ |
|
448 |
++DeleteLock; |
|
449 |
} |
|
450 |
||
451 |
void DCodeSeg::EndDeferDeletes() |
|
452 |
{ |
|
453 |
if (--DeleteLock==0) |
|
454 |
EmptyGarbageList(); |
|
455 |
} |
|
456 |
||
457 |
TInt DCodeSeg::WriteCallList(SDblQue& aList, TLinAddr* aEpList, TBool aInitData) |
|
458 |
{ |
|
459 |
__KTRACE_OPT(KDLL,Kern::Printf(">DCodeSeg::WriteCallList")); |
|
460 |
SDblQueLink* anchor=&aList.iA; |
|
461 |
SDblQueLink* pL=aList.First(); |
|
462 |
TAny* p=NULL; |
|
463 |
for (; !p && pL!=anchor; pL=pL->iNext, ++aEpList) |
|
464 |
{ |
|
465 |
DCodeSeg* pS=_LOFF(pL, DCodeSeg, iTempLink); |
|
466 |
if (aInitData) |
|
467 |
pS->InitData(); |
|
468 |
TLinAddr ep=pS->iEntryPtVeneer; |
|
469 |
__KTRACE_OPT(KDLL,Kern::Printf("Writing EP %08x->%08x",ep,aEpList)); |
|
470 |
p=Kern::KUSafeWrite(aEpList, &ep, sizeof(TLinAddr)); |
|
471 |
} |
|
472 |
TInt r=p?ECausedException:0; |
|
473 |
__KTRACE_OPT(KDLL,Kern::Printf("<DCodeSeg::WriteCallList %d",r)); |
|
474 |
return r; |
|
475 |
} |
|
476 |
||
477 |
/** Finds a code segment by its entry point address. |
|
478 |
||
479 |
@param aEntryPoint The entry point to search for. |
|
480 |
||
481 |
@return A pointer to the code segment if it exists; |
|
482 |
NULL if the entry point does not match any code segment. |
|
483 |
||
484 |
@pre Calling thread must be in a critical section. |
|
485 |
@pre No fast mutex can be held. |
|
486 |
@pre Call in a thread context. |
|
487 |
@pre Code segment lock mutex held. |
|
488 |
@pre Kernel must be unlocked |
|
489 |
@pre interrupts enabled |
|
490 |
*/ |
|
491 |
EXPORT_C DCodeSeg* DCodeSeg::CodeSegFromEntryPoint(TInt aEntryPoint) |
|
492 |
{ |
|
493 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"DCodeSeg::CodeSegFromEntryPoint"); |
|
494 |
__ASSERT_WITH_MESSAGE_MUTEX(CodeSegLock,"Code segment lock mutex held","DCodeSeg::CodeSegFromEntryPoint"); |
|
495 |
DCodeSeg* s = Kern::CodeSegFromAddress( (TLinAddr)aEntryPoint, TheCurrentThread->iOwningProcess ); |
|
496 |
if (s && s->iFileEntryPoint == TLinAddr(aEntryPoint)) |
|
497 |
return s; |
|
498 |
return NULL; |
|
499 |
} |
|
500 |
||
501 |
DCodeSeg::DCodeSeg() |
|
502 |
: iAccessCount(1), iMark(EMarkLdr) |
|
503 |
{ |
|
504 |
iLink.iNext=NULL; |
|
505 |
iTempLink.iNext=NULL; |
|
506 |
iGbgLink.iNext=NULL; |
|
507 |
} |
|
508 |
||
509 |
void DCodeSeg::Destruct() |
|
510 |
{ |
|
511 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::Destruct %C", this)); |
|
512 |
#ifdef BTRACE_CODESEGS |
|
513 |
BTrace4(BTrace::ECodeSegs,BTrace::ECodeSegDestroyed,this); |
|
514 |
#endif |
|
515 |
Wait(); |
|
516 |
TInt first = CodeSegsByName.SpecificFindInOrder(this, &CompareCodeSegsByName, EArrayFindMode_First); |
|
517 |
TInt last = CodeSegsByName.SpecificFindInOrder(this, &CompareCodeSegsByName, EArrayFindMode_Last); |
|
518 |
for (; first >= 0 && first < last; ++first) |
|
519 |
{ |
|
520 |
if (CodeSegsByName[first] == this) |
|
521 |
{ |
|
522 |
CodeSegsByName.Remove(first); |
|
523 |
__KTRACE_OPT(KDLL,Kern::Printf("CodeSeg @%08x Removed By Name", this)); |
|
524 |
break; |
|
525 |
} |
|
526 |
} |
|
527 |
if(CodeSegsByAddress.Remove(this)==KErrNone) |
|
528 |
{ |
|
529 |
__KTRACE_OPT(KDLL,Kern::Printf("CodeSeg @%08x Removed By Address %08x (index %d)", this, iRunAddress, first)); |
|
530 |
} |
|
531 |
if (iLink.iNext) |
|
532 |
iLink.Deque(); |
|
533 |
if (iTempLink.iNext) |
|
534 |
iTempLink.Deque(); |
|
535 |
Signal(); |
|
536 |
delete iFileName; |
|
537 |
Kern::Free(iDeps); |
|
538 |
Kern::SafeClose((DObject*&)iAttachProcess,NULL); |
|
539 |
iAsyncDeleteNext = NULL; // from now on VerifyHandle(this) will fail |
|
540 |
} |
|
541 |
||
542 |
void DCodeSeg::Close() |
|
543 |
{ |
|
544 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::Close %d %C", iAccessCount, this)); |
|
545 |
__NK_ASSERT_DEBUG(iAccessCount>0); |
|
546 |
if (--iAccessCount==0) |
|
547 |
delete this; |
|
548 |
} |
|
549 |
||
550 |
void DCodeSeg::CheckedClose() |
|
551 |
{ |
|
552 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::CheckedClose %d %C", iAccessCount, this)); |
|
553 |
__NK_ASSERT_DEBUG(iAccessCount>0); |
|
554 |
if (--iAccessCount==0) |
|
555 |
{ |
|
556 |
if (DeleteLock) |
|
557 |
GarbageList.Add(&iGbgLink); |
|
558 |
else |
|
559 |
delete this; |
|
560 |
} |
|
561 |
} |
|
562 |
||
563 |
void DCodeSeg::CheckedOpen() |
|
564 |
{ |
|
565 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::CheckedOpen %d %C", iAccessCount, this)); |
|
566 |
if (iGbgLink.iNext) |
|
567 |
{ |
|
568 |
__NK_ASSERT_DEBUG(iAccessCount==0 || iAccessCount==1); |
|
569 |
iAccessCount = 1; |
|
570 |
iGbgLink.Deque(); |
|
571 |
iGbgLink.iNext=NULL; |
|
572 |
} |
|
573 |
else |
|
574 |
++iAccessCount; |
|
575 |
} |
|
576 |
||
577 |
void DCodeSeg::WaitCheckedOpen() |
|
578 |
{ |
|
579 |
DCodeSeg::Wait(); |
|
580 |
CheckedOpen(); |
|
581 |
DCodeSeg::Signal(); |
|
582 |
} |
|
583 |
||
584 |
void DCodeSeg::QueueKernelCleanup() |
|
585 |
{ |
|
586 |
__ASSERT_MUTEX(CodeSegLock); |
|
587 |
if(!KernelCleanupLock && !KernelGarbageList.IsEmpty()) |
|
588 |
KernelCleanupDfc.QueueOnIdle(); |
|
589 |
} |
|
590 |
||
591 |
void DCodeSeg::DeferKernelCleanup() |
|
592 |
{ |
|
593 |
DCodeSeg::Wait(); |
|
594 |
++KernelCleanupLock; |
|
595 |
DCodeSeg::Signal(); |
|
596 |
} |
|
597 |
||
598 |
void DCodeSeg::EndDeferKernelCleanup() |
|
599 |
{ |
|
600 |
DCodeSeg::Wait(); |
|
601 |
__NK_ASSERT_DEBUG(KernelCleanupLock>0); |
|
602 |
if(!--KernelCleanupLock) |
|
603 |
{ |
|
604 |
TUint32 idleGenerationCount = NKern::IdleGenerationCount(); |
|
605 |
while (!DeferredKernelGarbageList.IsEmpty()) |
|
606 |
{ |
|
607 |
DCodeSeg* pS = _LOFF(DeferredKernelGarbageList.GetFirst(), DCodeSeg, iGbgLink); |
|
608 |
pS->iGbgIdleGenerationCount = idleGenerationCount; |
|
609 |
KernelGarbageList.Add(&pS->iGbgLink); |
|
610 |
} |
|
611 |
if(!KernelGarbageList.IsEmpty()) |
|
612 |
KernelCleanupDfc.QueueOnIdle(); |
|
613 |
} |
|
614 |
DCodeSeg::Signal(); |
|
615 |
} |
|
616 |
||
617 |
void DCodeSeg::ScheduleKernelCleanup(TBool aImmed) |
|
618 |
{ |
|
619 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::ScheduleKernelCleanup %d %C %d", iAccessCount, this, aImmed)); |
|
620 |
__NK_ASSERT_DEBUG(iAccessCount && (iAttr & ECodeSegAttKernel)); |
|
621 |
DProcess& kern = *K::TheKernelProcess; |
|
622 |
SDblQue cs_list; |
|
623 |
DCodeSeg::Wait(); |
|
624 |
kern.RemoveCodeSeg(this, &cs_list); // remove this code seg from the kernel's list |
|
625 |
||
626 |
// Call destructors in all codesegs... |
|
627 |
// Go through in reverse order since the top level code segment appears at the end |
|
628 |
// and we want to call destructors in highest-level-first order. |
|
629 |
SDblQueLink* next_link = &cs_list.iA; |
|
630 |
while ((next_link=next_link->iPrev) != &cs_list.iA) |
|
631 |
{ |
|
632 |
DCodeSeg* pS=_LOFF(next_link, DCodeSeg, iTempLink); |
|
633 |
if (pS->iMark & DCodeSeg::EMarkDataInit) |
|
634 |
{ |
|
635 |
TLibraryEntry f=(TLibraryEntry)pS->iEntryPtVeneer; |
|
636 |
__KTRACE_OPT(KDLL,Kern::Printf("EntryPoint %08x DETACH",f)); |
|
637 |
(*f)(KModuleEntryReasonProcessDetach); |
|
638 |
} |
|
639 |
} |
|
640 |
||
641 |
// close all codesegs... |
|
642 |
TUint32 idleGenerationCount = NKern::IdleGenerationCount(); |
|
643 |
while (!cs_list.IsEmpty()) |
|
644 |
{ |
|
645 |
DCodeSeg* pS=_LOFF(cs_list.Last()->Deque(), DCodeSeg, iTempLink); |
|
646 |
pS->iTempLink.iNext=NULL; |
|
647 |
if (aImmed) |
|
648 |
pS->CheckedClose(); |
|
649 |
else |
|
650 |
{ |
|
651 |
// Don't actually delete the code segment until the system goes idle. |
|
652 |
__NK_ASSERT_DEBUG(!pS->iGbgLink.iNext); |
|
653 |
if(KernelCleanupLock) |
|
654 |
DeferredKernelGarbageList.Add(&pS->iGbgLink); |
|
655 |
else |
|
656 |
{ |
|
657 |
pS->iGbgIdleGenerationCount = idleGenerationCount; |
|
658 |
KernelGarbageList.Add(&pS->iGbgLink); |
|
659 |
} |
|
660 |
} |
|
661 |
} |
|
662 |
||
663 |
if (!aImmed) |
|
664 |
QueueKernelCleanup(); |
|
665 |
||
666 |
DCodeSeg::Signal(); |
|
667 |
} |
|
668 |
||
669 |
TInt DCodeSeg::Create(TCodeSegCreateInfo& aInfo, DProcess* aProcess) |
|
670 |
{ |
|
671 |
const TInt KValidAttrMask = |
|
672 |
ECodeSegAttKernel | ECodeSegAttGlobal | ECodeSegAttFixed | ECodeSegAttABIMask | ECodeSegAttHDll | ECodeSegAttExpVer | ECodeSegAttNmdExpData | ECodeSegAttSMPSafe; |
|
673 |
||
134 | 674 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg::Create %08x file %S ver %08x process %O",this,&aInfo.iFileName,aInfo.iModuleVersion,aProcess)); |
0 | 675 |
TInt32 uid1=aInfo.iUids.iUid[0].iUid; |
676 |
if (uid1!=KDynamicLibraryUidValue && uid1!=KExecutableImageUidValue) |
|
677 |
return KErrNotSupported; |
|
678 |
iUids=aInfo.iUids; |
|
679 |
iAttr=aInfo.iAttr & KValidAttrMask; |
|
680 |
TInt fnl=aInfo.iFileName.Length(); |
|
681 |
if (TUint32(aInfo.iRootNameOffset)>=TUint32(fnl-1)) |
|
682 |
return KErrArgument; |
|
683 |
if (TUint32(aInfo.iRootNameLength)>TUint32(fnl)) |
|
684 |
return KErrArgument; |
|
685 |
if (TUint32(aInfo.iRootNameOffset+aInfo.iRootNameLength)>TUint32(fnl)) |
|
686 |
return KErrArgument; |
|
687 |
if (TUint32(aInfo.iExtOffset)>TUint32(fnl) || TUint32(aInfo.iExtOffset)<TUint32(aInfo.iRootNameOffset)) |
|
688 |
return KErrArgument; |
|
689 |
if (aInfo.iDepCount<0) |
|
690 |
return KErrArgument; |
|
691 |
if (!(iAttr&ECodeSegAttKernel) && !aProcess && aInfo.iTotalDataSize!=0) |
|
692 |
return KErrNotSupported; // don't allow static data for non-kernel code unless client process is specified |
|
693 |
iFileName=HBuf::New(aInfo.iFileName); |
|
694 |
if (!iFileName) |
|
695 |
return KErrNoMemory; |
|
696 |
#ifdef BTRACE_CODESEGS |
|
697 |
BTraceBig(BTrace::ECodeSegs,BTrace::ECodeSegCreated,this,iFileName->Ptr(),iFileName->Length()); |
|
698 |
#endif |
|
699 |
iRootName.Set(iFileName->Mid(aInfo.iRootNameOffset,aInfo.iRootNameLength)); |
|
700 |
iExtOffset=aInfo.iExtOffset; |
|
701 |
iModuleVersion=aInfo.iModuleVersion; |
|
702 |
iDepCount=aInfo.iDepCount; |
|
703 |
iS=aInfo.iS; |
|
704 |
if (iDepCount) |
|
705 |
{ |
|
706 |
iDeps=(DCodeSeg**)Kern::AllocZ(iDepCount*sizeof(DCodeSeg*)); |
|
707 |
if (!iDeps) |
|
708 |
return KErrNoMemory; |
|
709 |
} |
|
710 |
TInt r=DoCreate(aInfo,aProcess); |
|
711 |
__KTRACE_OPT(KDLL,Kern::Printf("attach proc=%O exe code seg=%08x",iAttachProcess,iExeCodeSeg)); |
|
712 |
if (r==KErrNone) |
|
713 |
{ |
|
714 |
iFileEntryPoint=aInfo.iFileEntryPoint; |
|
715 |
aInfo.iEntryPtVeneer=aInfo.iFileEntryPoint; // default - modified by loader if necessary |
|
716 |
iEntryPtVeneer=0; // for now |
|
717 |
DCodeSeg::Wait(); |
|
718 |
r = CodeSegsByName.InsertInOrderAllowRepeats(this, &CompareCodeSegsByName); |
|
719 |
if (r == KErrNone) |
|
720 |
{ |
|
721 |
__KTRACE_OPT(KDLL,Kern::Printf("CodeSeg @%08x Added By Name", this)); |
|
722 |
if(!(iAttr&ECodeSegAttAddrNotUnique)) |
|
723 |
{ |
|
724 |
// put codesegs which have a unique run address into a container... |
|
725 |
r = CodeSegsByAddress.Add(this); |
|
726 |
if (r == KErrNone) |
|
727 |
{ |
|
728 |
__KTRACE_OPT(KDLL,Kern::Printf("CodeSeg @%08x Added By Address %08x", this, iRunAddress)); |
|
729 |
} |
|
730 |
} |
|
731 |
} |
|
732 |
if (r == KErrNone) |
|
733 |
GlobalList.Add(&iLink); |
|
734 |
iAsyncDeleteNext=this; |
|
735 |
DCodeSeg::Signal(); |
|
736 |
#ifdef BTRACE_CODESEGS |
|
737 |
TModuleMemoryInfo info; |
|
738 |
GetMemoryInfo(info,NULL); |
|
739 |
BTraceN(BTrace::ECodeSegs,BTrace::ECodeSegInfo,this,iAttr,&info,sizeof(info)); |
|
740 |
#endif |
|
741 |
} |
|
742 |
return r; |
|
743 |
} |
|
744 |
||
745 |
TInt DCodeSeg::Loaded(TCodeSegCreateInfo& aInfo) |
|
746 |
{ |
|
747 |
iAttr &= ~ECodeSegAttSMPSafe; |
|
748 |
iAttr |= aInfo.iAttr & ECodeSegAttSMPSafe; |
|
749 |
iEntryPtVeneer = aInfo.iEntryPtVeneer; // final value provided by loader |
|
750 |
FinaliseRecursiveFlags(); |
|
751 |
return KErrNone; |
|
752 |
} |
|
753 |
||
754 |
void DCodeSeg::SetAttachProcess(DProcess* aProcess) |
|
755 |
{ |
|
756 |
__KTRACE_OPT(KDLL,Kern::Printf("DCodeSeg %C SetAttachProcess(%O)", this, aProcess)); |
|
757 |
__ASSERT_ALWAYS(!iAttachProcess, K::Fault(K::ECodeSegAttachProcess)); |
|
758 |
DCodeSeg* pPSeg=aProcess->CodeSeg(); |
|
759 |
iAttachProcess=aProcess; |
|
760 |
__ASSERT_DEBUG(!iExeCodeSeg || iExeCodeSeg==pPSeg, K::Fault(K::ECodeSegBadExeCodeSeg)); |
|
761 |
iExeCodeSeg=pPSeg; |
|
762 |
iAttachProcess->Open(); |
|
763 |
} |
|
764 |
||
765 |
void DCodeSeg::FinaliseRecursiveFlags() |
|
766 |
{ |
|
767 |
if (!(iMark&EMarkRecursiveFlagsValid)) |
|
768 |
{ |
|
769 |
DCodeSeg::UnmarkAll(EMarkRecursiveFlagsCheck); |
|
770 |
CalcRecursiveFlags(); |
|
771 |
iMark|=EMarkRecursiveFlagsValid; |
|
772 |
} |
|
773 |
} |
|
774 |
||
775 |
void DCodeSeg::CalcRecursiveFlags() |
|
776 |
{ |
|
777 |
__KTRACE_OPT(KDLL,Kern::Printf(">DCodeSeg::CalcRecursiveFlags %C %08x", this, iMark)); |
|
778 |
if (!(iMark&EMarkRecursiveFlagsCheck)) |
|
779 |
{ |
|
780 |
TUint32 valid=EMarkRecursiveFlagsValid; |
|
781 |
iMark|=EMarkRecursiveFlagsCheck; |
|
782 |
TInt i; |
|
783 |
for (i=0; i<iDepCount; ++i) |
|
784 |
{ |
|
785 |
DCodeSeg* pS=iDeps[i]; |
|
786 |
if (pS) |
|
787 |
{ |
|
788 |
if (!(pS->iMark & EMarkRecursiveFlagsValid)) |
|
789 |
{ |
|
790 |
pS->CalcRecursiveFlags(); |
|
791 |
if (!(pS->iMark & EMarkRecursiveFlagsValid)) |
|
792 |
valid=0; |
|
793 |
} |
|
794 |
TUint32 m=pS->iMark; |
|
795 |
if (m & EMarkDataPresent) |
|
796 |
iMark|=EMarkDataPresent; |
|
797 |
if (IsDll() && pS->IsDll() && (m & EMarkDataInit)) |
|
798 |
iMark|=EMarkDataInit; |
|
799 |
if (!iAttachProcess && pS->iAttachProcess) |
|
800 |
SetAttachProcess(pS->iAttachProcess); |
|
801 |
if (!iExeCodeSeg && pS->iExeCodeSeg) |
|
802 |
iExeCodeSeg=pS->iExeCodeSeg; |
|
803 |
if (!(pS->iAttr & ECodeSegAttSMPSafe)) |
|
804 |
iAttr &= ~ECodeSegAttSMPSafe; |
|
805 |
} |
|
806 |
} |
|
807 |
iMark|=valid; // set valid bit if no cycles were encountered |
|
808 |
} |
|
809 |
__KTRACE_OPT(KDLL,Kern::Printf("<DCodeSeg::CalcRecursiveFlags %C %08x", this, iMark)); |
|
810 |
} |
|
811 |
||
812 |
void DCodeSeg::Info(TCodeSegCreateInfo& aInfo) |
|
813 |
{ |
|
814 |
aInfo.iFileName=*iFileName; |
|
815 |
aInfo.iUids=iUids; |
|
816 |
aInfo.iAttr=iAttr; |
|
817 |
aInfo.iEntryPtVeneer=(TUint32)iEntryPtVeneer; |
|
818 |
aInfo.iFileEntryPoint=(TUint32)iFileEntryPoint; |
|
819 |
aInfo.iDepCount=iDepCount; |
|
820 |
aInfo.iRootNameOffset=iRootName.Ptr()-iFileName->Ptr(); |
|
821 |
aInfo.iRootNameLength=iRootName.Length(); |
|
822 |
aInfo.iExtOffset=iExtOffset; |
|
823 |
aInfo.iModuleVersion=iModuleVersion; |
|
824 |
aInfo.iS=iS; |
|
825 |
aInfo.iHandle=this; |
|
826 |
} |
|
827 |
||
828 |
TInt DCodeSeg::AddDependency(DCodeSeg* aExporter) |
|
829 |
{ |
|
830 |
__ASSERT_ALWAYS(iNextDep<iDepCount, K::Fault(K::ECodeDependenciesInconsistent)); |
|
831 |
if (aExporter->IsExe()) |
|
832 |
{ |
|
833 |
if (iExeCodeSeg && iExeCodeSeg!=aExporter) |
|
834 |
return KErrNotSupported; |
|
835 |
iExeCodeSeg=aExporter; |
|
836 |
} |
|
837 |
iDeps[iNextDep++]=aExporter; |
|
838 |
return KErrNone; |
|
839 |
} |
|
840 |
||
841 |
TInt DCodeSeg::ListDeps(SDblQue* aQ, TUint32 aMark) |
|
842 |
{ |
|
843 |
__KTRACE_OPT(KDLL,Kern::Printf(">DCodeSeg::ListDeps %C %08x", this, aMark)); |
|
844 |
TInt n=0; |
|
845 |
if (!(iMark & aMark)) |
|
846 |
{ |
|
847 |
iMark|=aMark; |
|
848 |
TInt i; |
|
849 |
for (i=0; i<iDepCount; ++i) |
|
850 |
if (iDeps[i]) |
|
851 |
n+=iDeps[i]->ListDeps(aQ,aMark); |
|
852 |
if (aQ) |
|
853 |
aQ->Add(&iTempLink); |
|
854 |
++n; |
|
855 |
} |
|
856 |
__KTRACE_OPT(KDLL,Kern::Printf("<DCodeSeg::ListDeps %d",n)); |
|
857 |
return n; |
|
858 |
} |
|
859 |
||
860 |
TInt DCodeSeg::UnListDeps(TUint32 aMark) |
|
861 |
{ |
|
862 |
__KTRACE_OPT(KDLL,Kern::Printf(">DCodeSeg::UnListDeps %C", this)); |
|
863 |
TInt n=0; |
|
864 |
if (!(iMark & aMark)) |
|
865 |
{ |
|
866 |
iMark|=aMark; |
|
867 |
TInt i; |
|
868 |
for (i=0; i<iDepCount; ++i) |
|
869 |
if (iDeps[i]) |
|
870 |
n+=iDeps[i]->UnListDeps(aMark); |
|
871 |
if (iTempLink.iNext) |
|
872 |
{ |
|
873 |
iTempLink.Deque(); |
|
874 |
iTempLink.iNext=NULL; |
|
875 |
++n; |
|
876 |
} |
|
877 |
} |
|
878 |
__KTRACE_OPT(KDLL,Kern::Printf("<DCodeSeg::UnListDeps %d",n)); |
|
879 |
return n; |
|
880 |
} |
|
881 |
||
882 |
TInt DCodeSeg::MarkAndOpenDeps(TUint32 aMark) |
|
883 |
{ |
|
884 |
__KTRACE_OPT(KDLL,Kern::Printf(">DCodeSeg::MarkAndOpenDeps %C %08x", this, aMark)); |
|
885 |
TInt n=0; |
|
886 |
if (!(iMark & aMark)) |
|
887 |
{ |
|
888 |
iMark|=aMark; |
|
889 |
TInt i; |
|
890 |
for (i=0; i<iDepCount; ++i) |
|
891 |
if (iDeps[i]) |
|
892 |
n+=iDeps[i]->MarkAndOpenDeps(aMark); |
|
893 |
CheckedOpen(); |
|
894 |
++n; |
|
895 |
} |
|
896 |
__KTRACE_OPT(KDLL,Kern::Printf("<DCodeSeg::MarkAndOpenDeps %d",n)); |
|
897 |
return n; |
|
898 |
} |
|
899 |
||
900 |
void DCodeSeg::AppendFullRootName(TDes& aDes) |
|
901 |
{ |
|
902 |
if (!iFileName) |
|
903 |
{ |
|
904 |
aDes.Append('@'); |
|
905 |
aDes.AppendNumFixedWidth((TUint32)this, EHex, 8); |
|
906 |
return; |
|
907 |
} |
|
908 |
if (!(iAttr & ECodeSegAttExpVer)) |
|
909 |
{ |
|
910 |
aDes.Append(iRootName); |
|
911 |
return; |
|
912 |
} |
|
913 |
TInt root_offset = iRootName.Ptr() - iFileName->Ptr(); |
|
914 |
TInt root_base_len = iExtOffset - root_offset; |
|
915 |
aDes.Append(iRootName.Left(root_base_len)); |
|
916 |
AppendVerExt(aDes); |
|
917 |
} |
|
918 |
||
919 |
void DCodeSeg::AppendFullFileName(TDes& aDes) |
|
920 |
{ |
|
921 |
if (!iFileName) |
|
922 |
{ |
|
923 |
aDes.Append('@'); |
|
924 |
aDes.AppendNumFixedWidth((TUint32)this, EHex, 8); |
|
925 |
return; |
|
926 |
} |
|
927 |
if (!(iAttr & ECodeSegAttExpVer)) |
|
928 |
{ |
|
929 |
aDes.Append(*iFileName); |
|
930 |
return; |
|
931 |
} |
|
932 |
aDes.Append(iFileName->Left(iExtOffset)); |
|
933 |
AppendVerExt(aDes); |
|
934 |
} |
|
935 |
||
936 |
void DCodeSeg::AppendVerExt(TDes& aDes) |
|
937 |
{ |
|
938 |
aDes.Append('{'); |
|
939 |
aDes.AppendNumFixedWidth(iModuleVersion, EHex, 8); |
|
940 |
aDes.Append('}'); |
|
941 |
aDes.Append(iFileName->Mid(iExtOffset)); |
|
942 |
} |
|
943 |
||
944 |
void DCodeSeg::TraceAppendFullName(TDes& aDes) |
|
945 |
{ |
|
946 |
AppendFullFileName(aDes); |
|
947 |
aDes.Append(_S8(" Ver "), 5); |
|
948 |
aDes.AppendNum((TInt)(iModuleVersion >> 16)); |
|
949 |
aDes.Append('.'); |
|
950 |
aDes.AppendNum((TInt)(iModuleVersion & 0x0000ffffu)); |
|
951 |
} |
|
952 |
||
953 |
void DCodeSeg::BTracePrime(TInt aCategory) |
|
954 |
{ |
|
955 |
#ifdef BTRACE_CODESEGS |
|
956 |
if (aCategory == BTrace::ECodeSegs || aCategory == -1) |
|
957 |
{ |
|
958 |
BTraceBig(BTrace::ECodeSegs,BTrace::ECodeSegCreated,this,iFileName->Ptr(),iFileName->Length()); |
|
959 |
TModuleMemoryInfo info; |
|
960 |
GetMemoryInfo(info,NULL); |
|
961 |
BTraceN(BTrace::ECodeSegs,BTrace::ECodeSegInfo,this,iAttr,&info,sizeof(info)); |
|
962 |
} |
|
963 |
#endif |
|
964 |
} |
|
965 |
||
966 |
/****************************************************************************** |
|
967 |
* Process stuff |
|
968 |
******************************************************************************/ |
|
969 |
||
970 |
TInt DProcess::WaitDllLock() |
|
971 |
{ |
|
972 |
// Can not use Kern::MutexWait() here as DLL lock can be held without calling |
|
973 |
// thread being in CS. |
|
974 |
NKern::LockSystem(); |
|
975 |
TInt r = iDllLock->Wait(); |
|
976 |
NKern::UnlockSystem(); |
|
977 |
return r; |
|
978 |
} |
|
979 |
||
980 |
void DProcess::SignalDllLock() |
|
981 |
{ |
|
982 |
// Can not use Kern::MutexSignal() here as DLL lock can be held without calling |
|
983 |
// thread being in CS. |
|
984 |
NKern::LockSystem(); |
|
985 |
iDllLock->Signal(); |
|
986 |
} |
|
987 |
||
988 |
/** Walks through all code segments used by this process. |
|
989 |
||
990 |
Iterates through the static and dynamic code dependency graph of this |
|
991 |
process and marks each traversed code segment using the specified mark. |
|
992 |
||
993 |
Optionally adds the traversed code segments to a specified queue, or removes |
|
994 |
them from this queue. The queue uses DCodeSeg::iTempLink. |
|
995 |
||
996 |
When the queue is not used anymore, the mark must be cleared by calling |
|
997 |
DCodeSeg::EmptyQueue(). |
|
998 |
||
999 |
The code segment mutex must be acquired before calling this function and released |
|
1000 |
only when the queue is not used anymore. |
|
1001 |
||
1002 |
@param aQ Queue where code segment should be added/removed or NULL. |
|
1003 |
@param aExclude Code segment to exclude from the iteration or NULL. |
|
1004 |
@param aMark Mark or-ed to DCodeSeg::iMark of all iterated code segments. |
|
1005 |
@param aFlags Bitmask storing action to perform on queue and traversal policy. |
|
1006 |
||
1007 |
@return Number of code segments traversed. |
|
1008 |
||
1009 |
@pre Calling thread must be in a critical section. |
|
1010 |
@pre DCodeSeg::CodeSegLock mutex held. |
|
1011 |
@pre Kernel must be unlocked |
|
1012 |
@pre interrupts enabled |
|
1013 |
@pre No fast mutex can be held |
|
1014 |
@pre Call in a thread context |
|
1015 |
||
1016 |
@post DCodeSeg::CodeSegLock mutex held. |
|
1017 |
@post Calling thread is in a critical section. |
|
1018 |
||
1019 |
@see Kern::AccessCode() |
|
1020 |
@see Kern::EndAccessCode() |
|
1021 |
@see DCodeSeg::TMark |
|
1022 |
@see DProcess::TTraverseFlags |
|
1023 |
@see DCodeSeg::EmptyQueue() |
|
1024 |
||
1025 |
@publishedPartner |
|
1026 |
@released |
|
1027 |
*/ |
|
1028 |
EXPORT_C TInt DProcess::TraverseCodeSegs(SDblQue* aQ, DCodeSeg* aExclude, TUint32 aMark, TUint32 aFlags) |
|
1029 |
{ |
|
1030 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"DProcess::TraverseCodeSegs"); |
|
1031 |
__ASSERT_WITH_MESSAGE_MUTEX(DCodeSeg::CodeSegLock,"DCodeSeg::CodeSegLock mutex held","DProcess::TraverseCodeSegs"); |
|
1032 |
__KTRACE_OPT(KDLL,Kern::Printf(">DProcess %O TraverseCodeSegs exclude %08x mark %08x flg %x",this,aExclude,aMark,aFlags)); |
|
1033 |
TInt n=0; |
|
1034 |
TInt i; |
|
1035 |
TInt c=iDynamicCode.Count(); |
|
1036 |
for (i=-1; i<c; ++i) |
|
1037 |
{ |
|
1038 |
DCodeSeg* pS=(i<0)?iCodeSeg:iDynamicCode[i].iSeg; |
|
1039 |
if (pS && pS!=aExclude) |
|
1040 |
{ |
|
1041 |
if ((aFlags & ETraverseFlagRestrict) && i>=0) |
|
1042 |
{ |
|
1043 |
DLibrary* pL=iDynamicCode[i].iLib; |
|
1044 |
if (pL && pL->iState!=DLibrary::EAttached) |
|
1045 |
continue; |
|
1046 |
} |
|
1047 |
if (aFlags & ETraverseFlagAdd) |
|
1048 |
n+=pS->ListDeps(aQ,aMark); |
|
1049 |
else |
|
1050 |
n+=pS->UnListDeps(aMark); |
|
1051 |
} |
|
1052 |
} |
|
1053 |
__KTRACE_OPT(KDLL,Kern::Printf("<DProcess %O TraverseCodeSegs %d",this,n)); |
|
1054 |
return n; |
|
1055 |
} |
|
1056 |
||
1057 |
TInt DProcess::OpenDeps() |
|
1058 |
{ |
|
1059 |
__KTRACE_OPT(KDLL,Kern::Printf(">DProcess %O OpenDeps",this)); |
|
1060 |
TInt r=KErrNone; |
|
1061 |
DCodeSeg::UnmarkAll(DCodeSeg::EMarkListDeps|DCodeSeg::EMarkUnListDeps); |
|
1062 |
SDblQue cs_list; |
|
1063 |
iTempCodeSeg->ListDeps(&cs_list, DCodeSeg::EMarkListDeps); // list code segments in least-first order |
|
1064 |
SDblQueLink* anchor=&cs_list.iA; |
|
1065 |
SDblQueLink* pL=cs_list.First(); |
|
1066 |
for(; pL!=anchor; pL=pL->iNext) |
|
1067 |
{ |
|
1068 |
DCodeSeg* pN=_LOFF(pL,DCodeSeg,iTempLink); |
|
1069 |
r=MapCodeSeg(pN); |
|
1070 |
if (r!=KErrNone) |
|
1071 |
break; |
|
1072 |
pN->CheckedOpen(); |
|
1073 |
__DEBUG_EVENT2(EEventAddCodeSeg, pN, this); |
|
1074 |
#ifdef BTRACE_CODESEGS |
|
1075 |
BTrace8(BTrace::ECodeSegs,BTrace::ECodeSegMapped,pN,this); |
|
1076 |
#endif |
|
1077 |
} |
|
1078 |
if (r!=KErrNone) |
|
1079 |
{ |
|
1080 |
pL=pL->iPrev; // points to last one which was actually mapped |
|
1081 |
SDblQueLink* pLL=pL->iPrev; |
|
1082 |
for (; pL!=anchor; pL=pLL, pLL=pLL->iPrev) |
|
1083 |
{ |
|
1084 |
DCodeSeg* pN=_LOFF(pL,DCodeSeg,iTempLink); |
|
1085 |
||
1086 |
__REMOVE_CODESEG_FROM_CODEMODIFIER(pN,this); |
|
1087 |
__DEBUG_EVENT2(EEventRemoveCodeSeg, pN, this); |
|
1088 |
UnmapCodeSeg(pN); |
|
1089 |
#ifdef BTRACE_CODESEGS |
|
1090 |
BTrace8(BTrace::ECodeSegs,BTrace::ECodeSegUnmapped,pN,this); |
|
1091 |
#endif |
|
1092 |
pN->CheckedClose(); |
|
1093 |
} |
|
1094 |
} |
|
1095 |
else |
|
1096 |
{ |
|
1097 |
iCodeSeg=iTempCodeSeg; |
|
1098 |
iTempCodeSeg=NULL; |
|
1099 |
iCodeSeg->iMark|=DCodeSeg::EMarkLoaded; // process code segment could now be reloaded |
|
1100 |
iCodeSeg->CheckedClose(); // balance extra access for EXE code segment |
|
1101 |
} |
|
1102 |
DCodeSeg::EmptyQueue(cs_list,0); |
|
1103 |
__KTRACE_OPT(KDLL,Kern::Printf("<DProcess %O OpenDeps %d",this,r)); |
|
1104 |
return r; |
|
1105 |
} |
|
1106 |
||
1107 |
TInt DProcess::AddCodeSeg(DCodeSeg* aSeg, DLibrary* aLib, SDblQue& aQ) |
|
1108 |
{ |
|
1109 |
__KTRACE_OPT(KDLL,Kern::Printf(">DProcess %O AddCodeSeg %O",this,aLib)); |
|
1110 |
DCodeSeg* pS=aSeg; |
|
1111 |
SCodeSegEntry e; |
|
1112 |
e.iSeg=pS; |
|
1113 |
e.iLib=aLib; |
|
1114 |
DCodeSeg::UnmarkAll(DCodeSeg::EMarkListDeps|DCodeSeg::EMarkUnListDeps); |
|
1115 |
TInt n=pS->ListDeps(&aQ, DCodeSeg::EMarkListDeps); // list code segments in least-first order |
|
1116 |
n-=TraverseCodeSegs(&aQ, NULL, DCodeSeg::EMarkUnListDeps, 0); // remove already present ones |
|
1117 |
TInt r=KErrNone; |
|
1118 |
SDblQueLink* anchor=&aQ.iA; |
|
1119 |
SDblQueLink* pL=aQ.First(); |
|
1120 |
for(; pL!=anchor; pL=pL->iNext) |
|
1121 |
{ |
|
1122 |
DCodeSeg* pN=_LOFF(pL,DCodeSeg,iTempLink); |
|
1123 |
r=MapCodeSeg(pN); |
|
1124 |
if (r!=KErrNone) |
|
1125 |
break; |
|
1126 |
__DEBUG_EVENT2(EEventAddCodeSeg, pN, this); |
|
1127 |
#ifdef BTRACE_CODESEGS |
|
1128 |
BTrace8(BTrace::ECodeSegs,BTrace::ECodeSegMapped,pN,this); |
|
1129 |
#endif |
|
1130 |
pN->CheckedOpen(); |
|
1131 |
__KTRACE_OPT(KDLL,Kern::Printf("pN=%08x aLib=%08x iMark=%08x", pN, aLib, pN->iMark)); |
|
1132 |
if (!aLib && pN->iMark&DCodeSeg::EMarkDataInit) |
|
1133 |
{ |
|
1134 |
// kernel library - initialise data now |
|
1135 |
pN->InitData(); |
|
1136 |
TLibraryEntry f=(TLibraryEntry)pN->iEntryPtVeneer; |
|
1137 |
__KTRACE_OPT(KDLL,Kern::Printf("EntryPoint %08x ATTACH",f)); |
|
1138 |
(*f)(KModuleEntryReasonProcessAttach); |
|
1139 |
} |
|
1140 |
} |
|
1141 |
if (r==KErrNone && !(pS->iAttr & ECodeSegAttSMPSafe)) |
|
1142 |
{ |
|
1143 |
if (__e32_atomic_add_ord32(&iSMPUnsafeCount, 1) == 0) |
|
1144 |
{ |
|
1145 |
#ifdef __SMP__ |
|
1146 |
r = UpdateSMPSafe(); |
|
1147 |
#endif |
|
1148 |
} |
|
1149 |
} |
|
1150 |
if (r==KErrNone) |
|
1151 |
r=iDynamicCode.InsertInUnsignedKeyOrder(e); |
|
1152 |
if (r!=KErrNone && !(pS->iAttr & ECodeSegAttSMPSafe)) |
|
1153 |
{ |
|
1154 |
if (__e32_atomic_add_ord32(&iSMPUnsafeCount, (TUint)-1) == 1) |
|
1155 |
{ |
|
1156 |
#ifdef __SMP__ |
|
1157 |
UpdateSMPSafe(); |
|
1158 |
#endif |
|
1159 |
} |
|
1160 |
} |
|
1161 |
if (r!=KErrNone && n!=0) // n=0 if code seg already mapped owing to an implicit linkage |
|
1162 |
{ |
|
1163 |
pL=pL->iPrev; // points to last one which was actually mapped |
|
1164 |
SDblQueLink* pLL=pL->iPrev; |
|
1165 |
for (; pL!=anchor; pL=pLL, pLL=pLL->iPrev) |
|
1166 |
{ |
|
1167 |
DCodeSeg* pN=_LOFF(pL,DCodeSeg,iTempLink); |
|
1168 |
if (!aLib && pN->iMark&DCodeSeg::EMarkDataInit) |
|
1169 |
{ |
|
1170 |
TLibraryEntry f=(TLibraryEntry)pN->iEntryPtVeneer; |
|
1171 |
__KTRACE_OPT(KDLL,Kern::Printf("EntryPoint %08x DETACH",f)); |
|
1172 |
(*f)(KModuleEntryReasonProcessDetach); |
|
1173 |
} |
|
1174 |
||
1175 |
__REMOVE_CODESEG_FROM_CODEMODIFIER(pN,this); |
|
1176 |
__DEBUG_EVENT2(EEventRemoveCodeSeg, pN, this); |
|
1177 |
UnmapCodeSeg(pN); |
|
1178 |
#ifdef BTRACE_CODESEGS |
|
1179 |
BTrace8(BTrace::ECodeSegs,BTrace::ECodeSegUnmapped,pN,this); |
|
1180 |
#endif |
|
1181 |
pN->CheckedClose(); |
|
1182 |
} |
|
1183 |
} |
|
1184 |
__KTRACE_OPT(KDLL,Kern::Printf("<DProcess %O AddCodeSeg %d",this,r)); |
|
1185 |
return r; |
|
1186 |
} |
|
1187 |
||
1188 |
void DProcess::RemoveCodeSeg(DCodeSeg* aSeg, SDblQue* aQ) |
|
1189 |
{ |
|
1190 |
__KTRACE_OPT(KDLL,Kern::Printf(">DProcess %O RemoveCodeSeg %08x(%C) Q:%08x", this, aSeg, aSeg, aQ)); |
|
1191 |
SCodeSegEntry e; |
|
1192 |
e.iSeg=aSeg; |
|
1193 |
e.iLib=NULL; |
|
1194 |
TInt i; |
|
1195 |
if (aSeg!=iCodeSeg) |
|
1196 |
{ |
|
1197 |
TInt r=iDynamicCode.FindInUnsignedKeyOrder(e,i); |
|
1198 |
__ASSERT_ALWAYS(r==KErrNone, K::Fault(K::ECodeSegRemoveAbsent)); |
|
1199 |
iDynamicCode.Remove(i); |
|
1200 |
if (!(aSeg->iAttr & ECodeSegAttSMPSafe)) |
|
1201 |
{ |
|
1202 |
if (__e32_atomic_add_ord32(&iSMPUnsafeCount, (TUint)-1) == 1) |
|
1203 |
{ |
|
1204 |
#ifdef __SMP__ |
|
1205 |
UpdateSMPSafe(); |
|
1206 |
#endif |
|
1207 |
} |
|
1208 |
} |
|
1209 |
} |
|
1210 |
SDblQue cs_list; |
|
1211 |
SDblQue* q = aQ ? aQ : &cs_list; |
|
1212 |
DCodeSeg::UnmarkAll(DCodeSeg::EMarkListDeps|DCodeSeg::EMarkUnListDeps); |
|
1213 |
aSeg->ListDeps(q, DCodeSeg::EMarkListDeps); // list all dependents of this code seg |
|
1214 |
TraverseCodeSegs(q, aSeg, DCodeSeg::EMarkUnListDeps, 0); // remove those still needed |
|
1215 |
NKern::LockSystem(); |
|
1216 |
if (aSeg==iCodeSeg) |
|
1217 |
iCodeSeg=NULL; |
|
1218 |
NKern::UnlockSystem(); |
|
1219 |
if (!aQ) |
|
1220 |
{ |
|
1221 |
while(!cs_list.IsEmpty()) |
|
1222 |
{ |
|
1223 |
DCodeSeg* pS=_LOFF(cs_list.First()->Deque(), DCodeSeg, iTempLink); |
|
1224 |
pS->iTempLink.iNext=NULL; |
|
1225 |
__REMOVE_CODESEG_FROM_CODEMODIFIER(pS,this); |
|
1226 |
__DEBUG_EVENT2(EEventRemoveCodeSeg, pS, this); |
|
1227 |
UnmapCodeSeg(pS); |
|
1228 |
#ifdef BTRACE_CODESEGS |
|
1229 |
BTrace8(BTrace::ECodeSegs,BTrace::ECodeSegUnmapped,pS,this); |
|
1230 |
#endif |
|
1231 |
pS->CheckedClose(); |
|
1232 |
} |
|
1233 |
} |
|
1234 |
__KTRACE_OPT(KDLL,Kern::Printf("<DProcess %O RemoveCodeSeg",this)); |
|
1235 |
} |
|
1236 |
||
1237 |
TInt DProcess::CallList(SDblQue& aQ, DCodeSeg* aSeg, TUint32 aFlag) |
|
1238 |
{ |
|
1239 |
__KTRACE_OPT(KDLL,Kern::Printf("DProcess %O CallList seg=%08x flg=%x",this,aSeg,aFlag)); |
|
1240 |
DCodeSeg::UnmarkAll(DCodeSeg::EMarkListDeps|DCodeSeg::EMarkUnListDeps); |
|
1241 |
TInt n=aSeg->ListDeps(&aQ, DCodeSeg::EMarkListDeps); |
|
1242 |
n-=TraverseCodeSegs(&aQ, aSeg, DCodeSeg::EMarkUnListDeps, aFlag&~ETraverseFlagAdd); |
|
1243 |
return n; |
|
1244 |
} |
|
1245 |
||
1246 |
/****************************************************************************** |
|
1247 |
* Library |
|
1248 |
******************************************************************************/ |
|
1249 |
DLibrary::DLibrary() |
|
1250 |
{ |
|
1251 |
iThreadLink.iNext=NULL; |
|
1252 |
} |
|
1253 |
||
1254 |
DLibrary::~DLibrary() |
|
1255 |
{ |
|
1256 |
__ASSERT_ALWAYS(iMapCount==0, K::Fault(K::ELibDestructBadMapCount)); |
|
1257 |
} |
|
1258 |
||
1259 |
// If aPtr!=NULL a user handle is being closed |
|
1260 |
TInt DLibrary::Close(TAny* aPtr) |
|
1261 |
{ |
|
1262 |
DProcess* pP=(DProcess*)aPtr; |
|
1263 |
DThread& t=*TheCurrentThread; |
|
1264 |
TInt m=1; |
|
1265 |
if (pP) |
|
1266 |
{ |
|
1267 |
DCodeSeg::Wait(); |
|
1268 |
m=--iMapCount; |
|
1269 |
// debugger will be notified later if library is being unloaded |
|
1270 |
__COND_DEBUG_EVENT(m>0, EEventRemoveLibrary, this); |
|
1271 |
if (m==0) |
|
1272 |
{ |
|
1273 |
TBool first_close=t.iClosingLibs.IsEmpty(); |
|
1274 |
if (t.iOwningProcess==pP && iState==EAttached && (!first_close || iCodeSeg->iMark&DCodeSeg::EMarkDataInit)) |
|
1275 |
{ |
|
1276 |
iState=EDetachPending; |
|
1277 |
t.iClosingLibs.Add(&iThreadLink); // need to run destructors |
|
1278 |
if (!first_close) |
|
1279 |
{ |
|
1280 |
// this is a close within a close |
|
1281 |
// destructors only run after those from first Close |
|
1282 |
__KTRACE_OPT(KDLL,Kern::Printf("DLibrary %O CWC",this)); |
|
1283 |
DCodeSeg::Signal(); |
|
1284 |
return 0; |
|
1285 |
} |
|
1286 |
} |
|
1287 |
else |
|
1288 |
{ |
|
1289 |
// thread exiting/constructors never run/constructors not needed |
|
1290 |
__DEBUG_EVENT(EEventRemoveLibrary, this); |
|
1291 |
iState=ELoaded; |
|
1292 |
RemoveFromProcess(); |
|
1293 |
m=-1; |
|
1294 |
} |
|
1295 |
} |
|
1296 |
__KTRACE_OPT(KDLL,Kern::Printf("DLibrary %O Close m=%d",this,m)); |
|
1297 |
TInt ret = EObjectUnmapped; |
|
1298 |
// close the object before signal to prevent an open race condition. |
|
1299 |
if (m) // don't close yet if destructors needed |
|
1300 |
ret = DObject::Close(aPtr); |
|
1301 |
// THIS OBJECT MAY NOW BE DEAD, only Signal and return should follow. |
|
1302 |
DCodeSeg::Signal(); |
|
1303 |
return ret; // signal that destructors are required |
|
1304 |
} |
|
1305 |
else |
|
1306 |
return DObject::Close(aPtr); |
|
1307 |
} |
|
1308 |
||
1309 |
void DLibrary::RemoveFromProcess() |
|
1310 |
{ |
|
1311 |
DProcess* pP=(DProcess*)Owner(); |
|
1312 |
if (pP->iThreadsLeaving) |
|
1313 |
{ |
|
1314 |
// Put library on process garbage list |
|
1315 |
Open(); |
|
1316 |
pP->iGarbageList.Add(&iGbgLink); |
|
1317 |
} |
|
1318 |
else |
|
1319 |
ReallyRemoveFromProcess(); |
|
1320 |
} |
|
1321 |
||
1322 |
void DLibrary::ReallyRemoveFromProcess() |
|
1323 |
{ |
|
1324 |
DProcess* pP=(DProcess*)Owner(); |
|
1325 |
NKern::FMWait(&DObject::Lock); |
|
1326 |
DCodeSeg* pS=iCodeSeg; |
|
1327 |
iCodeSeg=NULL; |
|
1328 |
NKern::FMSignal(&DObject::Lock); |
|
1329 |
NKern::LockSystem(); |
|
1330 |
NKern::UnlockSystem(); |
|
1331 |
pP->RemoveCodeSeg(pS, NULL); |
|
1332 |
} |
|
1333 |
||
1334 |
// Called when a handle is opened to this library |
|
1335 |
TInt DLibrary::AddToProcess(DProcess* /*aProcess*/) |
|
1336 |
{ |
|
1337 |
DCodeSeg::Wait(); |
|
1338 |
++iMapCount; |
|
1339 |
DCodeSeg::Signal(); |
|
1340 |
return KErrNone; |
|
1341 |
} |
|
1342 |
||
1343 |
void DLibrary::DoAppendName(TDes& aDes) |
|
1344 |
{ |
|
1345 |
DObject::DoAppendName(aDes); |
|
1346 |
TUint32 uid=iCodeSeg?iCodeSeg->iUids.iUid[2].iUid:0; |
|
1347 |
TUint32 ver=iCodeSeg?iCodeSeg->iModuleVersion:0; |
|
1348 |
aDes.Append('{'); |
|
1349 |
aDes.AppendNumFixedWidth(ver,EHex,8); |
|
1350 |
aDes.Append('}'); |
|
1351 |
aDes.Append('['); |
|
1352 |
aDes.AppendNumFixedWidth(uid,EHex,8); |
|
1353 |
aDes.Append(']'); |
|
1354 |
} |
|
1355 |
||
1356 |
TInt DLibrary::New(DLibrary*& aLib, DProcess* aProcess, DCodeSeg* aSeg) |
|
1357 |
{ |
|
1358 |
aLib=new DLibrary; |
|
1359 |
if (!aLib) |
|
1360 |
return KErrNoMemory; |
|
1361 |
TInt r=aLib->SetOwner(aProcess); |
|
1362 |
if (r==KErrNone) |
|
1363 |
{ |
|
1364 |
if (aSeg->iRootName.Length() > KMaxKernelName-KMaxUidName-KMaxVersionName) |
|
1365 |
r = KErrBadName; |
|
1366 |
else |
|
1367 |
r=aLib->SetName(&aSeg->iRootName); |
|
1368 |
} |
|
1369 |
if (r==KErrNone) |
|
1370 |
r=K::AddObject(aLib,ELibrary); |
|
1371 |
if (r!=KErrNone) |
|
1372 |
{ |
|
1373 |
aLib->Close(NULL); |
|
1374 |
aLib=NULL; |
|
1375 |
return r; |
|
1376 |
} |
|
1377 |
aLib->iCodeSeg=aSeg; |
|
1378 |
return KErrNone; |
|
1379 |
} |
|
1380 |
||
1381 |
||
1382 |
/****************************************************************************** |
|
1383 |
* Thread cleanup |
|
1384 |
******************************************************************************/ |
|
1385 |
void DThread::RemoveClosingLibs() |
|
1386 |
{ |
|
1387 |
__KTRACE_OPT(KDLL,Kern::Printf(">DThread::RemoveClosingLibs")); |
|
1388 |
DCodeSeg::Wait(); |
|
1389 |
while(!iClosingLibs.IsEmpty()) |
|
1390 |
{ |
|
1391 |
DLibrary* pL=_LOFF(iClosingLibs.First()->Deque(), DLibrary, iThreadLink); |
|
1392 |
pL->iThreadLink.iNext=NULL; |
|
1393 |
__DEBUG_EVENT(EEventRemoveLibrary, pL); |
|
1394 |
pL->RemoveFromProcess(); |
|
1395 |
pL->Close(NULL); |
|
1396 |
} |
|
1397 |
DCodeSeg::Signal(); |
|
1398 |
__KTRACE_OPT(KDLL,Kern::Printf("<DThread::RemoveClosingLibs")); |
|
1399 |
} |
|
1400 |
||
1401 |
/****************************************************************************** |
|
1402 |
* Executive Handlers - Loader |
|
1403 |
******************************************************************************/ |
|
1404 |
DProcess* OpenProcess(TInt aHandle, TBool aAllowNull) |
|
1405 |
{ |
|
1406 |
DProcess* pP=NULL; |
|
1407 |
if (aHandle) |
|
1408 |
{ |
|
1409 |
NKern::LockSystem(); |
|
1410 |
pP=(DProcess*)K::ThreadEnterCS(aHandle, EProcess); |
|
1411 |
} |
|
1412 |
else if (!aAllowNull) |
|
1413 |
K::PanicKernExec(EBadHandle); |
|
1414 |
else |
|
1415 |
NKern::ThreadEnterCS(); |
|
1416 |
return pP; |
|
1417 |
} |
|
1418 |
||
1419 |
TInt ExecHandler::CodeSegCreate(TCodeSegCreateInfo& aInfo) |
|
1420 |
{ |
|
1421 |
TCodeSegCreateInfo info; |
|
1422 |
kumemget32(&info, &aInfo, sizeof(info)); |
|
134 | 1423 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegCreate %S ver %08x", &info.iFileName, info.iModuleVersion)); |
0 | 1424 |
__KTRACE_OPT(KDLL,DumpCodeSegCreateInfo(info)); |
1425 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1426 |
info.iHandle=NULL; |
|
1427 |
DProcess* pP=OpenProcess(info.iClientProcessHandle, ETrue); |
|
1428 |
TInt r=KErrNoMemory; |
|
1429 |
DCodeSeg* pS=M::NewCodeSeg(info); |
|
1430 |
if (pS) |
|
1431 |
{ |
|
1432 |
r=pS->Create(info, pP); |
|
1433 |
if (r==KErrNone) |
|
1434 |
info.iHandle=pS; |
|
1435 |
else |
|
1436 |
pS->Close(); |
|
1437 |
} |
|
1438 |
if (pP) |
|
1439 |
pP->Close(NULL); |
|
1440 |
NKern::ThreadLeaveCS(); |
|
1441 |
kumemput32(&aInfo.iUids, &info.iUids, sizeof(info)-sizeof(info.iFileName)); |
|
1442 |
__KTRACE_OPT(KDLL,DumpCodeSegCreateInfo(info)); |
|
1443 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegCreate returns %d",r)); |
|
1444 |
return r; |
|
1445 |
} |
|
1446 |
||
1447 |
TInt ExecHandler::CodeSegLoaded(TCodeSegCreateInfo& aInfo) |
|
1448 |
{ |
|
1449 |
TCodeSegCreateInfo info; |
|
1450 |
kumemget32(&info, &aInfo, sizeof(info)); |
|
134 | 1451 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegLoaded %S ver %08x", &info.iFileName, info.iModuleVersion)); |
0 | 1452 |
__KTRACE_OPT(KDLL,DumpCodeSegCreateInfo(info)); |
1453 |
DCodeSeg* pS=DCodeSeg::VerifyCallerAndHandle(info.iHandle); |
|
1454 |
Kern::AccessCode(); |
|
1455 |
TInt r=pS->Loaded(info); |
|
1456 |
if (r==KErrNone) |
|
1457 |
pS->iMark|=DCodeSeg::EMarkLoaded; |
|
1458 |
Kern::EndAccessCode(); |
|
1459 |
kumemput32(&aInfo.iUids, &info.iUids, sizeof(info)-sizeof(info.iFileName)); |
|
1460 |
__KTRACE_OPT(KDLL,DumpCodeSegCreateInfo(info)); |
|
1461 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegLoaded returns %d",r)); |
|
1462 |
return r; |
|
1463 |
} |
|
1464 |
||
1465 |
TInt ExecHandler::LibraryCreate(TLibraryCreateInfo& aInfo) |
|
1466 |
{ |
|
1467 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::LibraryCreate")); |
|
1468 |
TLibraryCreateInfo info; |
|
1469 |
kumemget32(&info, &aInfo, sizeof(info)); |
|
1470 |
DCodeSeg* pS=DCodeSeg::VerifyCallerAndHandle(info.iCodeSegHandle); |
|
1471 |
NKern::ThreadEnterCS(); |
|
1472 |
NKern::LockSystem(); |
|
1473 |
DThread* pT=(DThread*)K::ObjectFromHandle(info.iClientHandle,EThread); |
|
1474 |
if (!pT || pT->Open()) |
|
1475 |
{ |
|
1476 |
NKern::ThreadLeaveCS(); |
|
1477 |
K::PanicCurrentThread(EBadHandle); |
|
1478 |
} |
|
1479 |
NKern::UnlockSystem(); |
|
1480 |
DProcess* pP=pT->iOwningProcess; |
|
1481 |
DCodeSeg::Wait(); |
|
1482 |
DLibrary* pL=NULL; |
|
1483 |
SCodeSegEntry find; |
|
1484 |
find.iSeg=pS; |
|
1485 |
find.iLib=NULL; |
|
1486 |
TInt i; |
|
1487 |
TInt r=pP->iDynamicCode.FindInUnsignedKeyOrder(find,i); |
|
1488 |
if (r==KErrNone) |
|
1489 |
{ |
|
1490 |
// this code segment is already explicitly in use by the process |
|
1491 |
pL=pP->iDynamicCode[i].iLib; |
|
1492 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Already loaded into process, lib=%O@%08x",pL,pL)); |
|
1493 |
r=pT->MakeHandleAndOpen(info.iOwnerType, pL, info.iLibraryHandle); |
|
1494 |
if (r==KErrNone) |
|
1495 |
{ |
|
1496 |
if (pL->iState==DLibrary::EDetachPending) |
|
1497 |
{ |
|
1498 |
// load got in between Close and destructors running |
|
1499 |
pL->iState=DLibrary::EAttached; |
|
1500 |
} |
|
1501 |
if (pL->iThreadLink.iNext) |
|
1502 |
{ |
|
1503 |
pL->iThreadLink.Deque(); |
|
1504 |
pL->iThreadLink.iNext=NULL; |
|
1505 |
pL->Close(NULL); |
|
1506 |
} |
|
1507 |
if (pL->iGbgLink.iNext) |
|
1508 |
{ |
|
1509 |
pL->iGbgLink.Deque(); |
|
1510 |
pL->iGbgLink.iNext=NULL; |
|
1511 |
pL->DObject::Close(NULL); |
|
1512 |
} |
|
1513 |
__DEBUG_EVENT2(EEventAddLibrary, pL, pT); |
|
1514 |
} |
|
1515 |
DCodeSeg::Signal(); |
|
1516 |
pT->Close(NULL); |
|
1517 |
NKern::ThreadLeaveCS(); |
|
1518 |
kumemput32(&aInfo, &info, sizeof(info)); |
|
1519 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::LibraryCreate returns %d",r)); |
|
1520 |
return r; |
|
1521 |
} |
|
1522 |
DCodeSeg::Signal(); |
|
1523 |
r=DLibrary::New(pL,pP,pS); |
|
1524 |
if (r==KErrNone) |
|
1525 |
{ |
|
1526 |
DCodeSeg::Wait(); |
|
1527 |
SDblQue cs_list; |
|
1528 |
r = (pT->iExitType==EExitPending) ? pP->AddCodeSeg(pS,pL,cs_list) : KErrDied; |
|
1529 |
if (r==KErrNone) |
|
1530 |
{ |
|
1531 |
r=pT->MakeHandle(info.iOwnerType, pL, info.iLibraryHandle); |
|
1532 |
if (r==KErrNone) |
|
1533 |
{ |
|
1534 |
if (pS->iMark&DCodeSeg::EMarkDataInit) |
|
1535 |
pL->iState=DLibrary::ELoaded; |
|
1536 |
else |
|
1537 |
pL->iState=DLibrary::EAttached; |
|
1538 |
} |
|
1539 |
else |
|
1540 |
{ |
|
1541 |
DCodeSeg::EmptyQueue(cs_list, 0); // unlink mapped DLLs, leave cs_list empty |
|
1542 |
pL->RemoveFromProcess(); |
|
1543 |
} |
|
1544 |
} |
|
1545 |
DCodeSeg::EmptyQueue(cs_list, 0); // unlink mapped DLLs, leave cs_list empty |
|
1546 |
if (r!=KErrNone) |
|
1547 |
{ |
|
1548 |
pL->iCodeSeg=NULL; |
|
1549 |
pL->Close(NULL); |
|
1550 |
} |
|
1551 |
else |
|
1552 |
__DEBUG_EVENT2(EEventAddLibrary, pL, pT); |
|
1553 |
DCodeSeg::Signal(); |
|
1554 |
} |
|
1555 |
pT->Close(NULL); |
|
1556 |
NKern::ThreadLeaveCS(); |
|
1557 |
kumemput32(&aInfo, &info, sizeof(info)); |
|
1558 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::LibraryCreate returns %d",r)); |
|
1559 |
return r; |
|
1560 |
} |
|
1561 |
||
1562 |
TInt ExecHandler::CodeSegOpen(TAny* aHandle, TInt aClientProcessHandle) |
|
1563 |
{ |
|
1564 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegOpen")); |
|
1565 |
DCodeSeg* pS=DCodeSeg::VerifyCallerAndHandle(aHandle); |
|
1566 |
DProcess* pP=OpenProcess(aClientProcessHandle, ETrue); |
|
1567 |
DCodeSeg::Wait(); |
|
1568 |
TInt r=KErrNone; |
|
1569 |
if (pP && !pS->OpenCheck(pP)) |
|
1570 |
r=KErrNotSupported; |
|
1571 |
if (r==KErrNone) |
|
1572 |
pS->MarkAndOpenDeps(DCodeSeg::EMarkLdr); |
|
1573 |
DCodeSeg::Signal(); |
|
1574 |
if (pP) |
|
1575 |
pP->Close(NULL); |
|
1576 |
NKern::ThreadLeaveCS(); |
|
1577 |
return r; |
|
1578 |
} |
|
1579 |
||
1580 |
void ExecHandler::CodeSegClose(TAny* aHandle) |
|
1581 |
{ |
|
1582 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegClose %08x",aHandle)); |
|
1583 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1584 |
DCodeSeg* pS=NULL; |
|
1585 |
if (aHandle) |
|
1586 |
pS=DCodeSeg::VerifyHandleP(aHandle); |
|
1587 |
Kern::AccessCode(); |
|
1588 |
if (pS) |
|
1589 |
pS->Close(); |
|
1590 |
else |
|
1591 |
DCodeSeg::UnmarkAndCloseAll(DCodeSeg::EMarkLdr); |
|
1592 |
Kern::EndAccessCode(); |
|
1593 |
} |
|
1594 |
||
1595 |
void ExecHandler::CodeSegNext(TAny*& aHandle, const TFindCodeSeg& aFind) |
|
1596 |
{ |
|
1597 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf(">Exec::CodeSegNext")); |
|
1598 |
TFindCodeSeg find; |
|
1599 |
kumemget32(&find, &aFind, sizeof(find)); |
|
1600 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1601 |
DCodeSeg* pS; |
|
1602 |
if (find.iRomImgHdr) |
|
1603 |
pS=DCodeSeg::FindRomCode(find.iRomImgHdr); |
|
1604 |
else |
|
1605 |
{ |
|
1606 |
DProcess* pP=OpenProcess(find.iProcess, ETrue); |
|
1607 |
DThread& t=*TheCurrentThread; |
|
1608 |
t.iTempObj=pP; |
|
1609 |
find.iProcess=(TInt)pP; |
|
1610 |
NKern::ThreadLeaveCS(); |
|
1611 |
pS=DCodeSeg::FindCodeSeg(find); |
|
1612 |
if (pP) |
|
1613 |
{ |
|
1614 |
NKern::ThreadEnterCS(); |
|
1615 |
t.iTempObj=NULL; |
|
1616 |
pP->Close(NULL); |
|
1617 |
NKern::ThreadLeaveCS(); |
|
1618 |
} |
|
1619 |
} |
|
1620 |
kumemput32(&aHandle, &pS, sizeof(pS)); |
|
1621 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("<Exec::CodeSegNext %08x",pS)); |
|
1622 |
} |
|
1623 |
||
1624 |
void ExecHandler::CodeSegInfo(TAny* aHandle, TCodeSegCreateInfo& aInfo) |
|
1625 |
{ |
|
1626 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegInfo %08x",aHandle)); |
|
1627 |
TCodeSegCreateInfo info; |
|
1628 |
DCodeSeg* pS=DCodeSeg::VerifyCallerAndHandle(aHandle); |
|
1629 |
Kern::AccessCode(); |
|
1630 |
pS->Info(info); |
|
1631 |
info.iHandle = pS; |
|
1632 |
Kern::EndAccessCode(); |
|
1633 |
kumemput32(&aInfo, &info, _FOFF(TCodeSegCreateInfo,iClientProcessHandle)); |
|
1634 |
__KTRACE_OPT(KDLL,DumpCodeSegCreateInfo(info)); |
|
1635 |
} |
|
1636 |
||
1637 |
TInt ExecHandler::CodeSegAddDependency(TAny* aImporter, TAny* aExporter) |
|
1638 |
{ |
|
1639 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegAddDependency %08x on %08x",aImporter,aExporter)); |
|
1640 |
DCodeSeg* pI=DCodeSeg::VerifyCallerAndHandle(aImporter); |
|
1641 |
DCodeSeg* pE=DCodeSeg::VerifyHandleP(aExporter); |
|
1642 |
Kern::AccessCode(); |
|
1643 |
TInt r=pI->AddDependency(pE); |
|
1644 |
Kern::EndAccessCode(); |
|
1645 |
return r; |
|
1646 |
} |
|
1647 |
||
1648 |
void ExecHandler::CodeSegDeferDeletes() |
|
1649 |
{ |
|
1650 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegDeferDeletes")); |
|
1651 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1652 |
Kern::AccessCode(); |
|
1653 |
DCodeSeg::DeferDeletes(); |
|
1654 |
Kern::EndAccessCode(); |
|
1655 |
} |
|
1656 |
||
1657 |
void ExecHandler::CodeSegEndDeferDeletes() |
|
1658 |
{ |
|
1659 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegEndDeferDeletes")); |
|
1660 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1661 |
Kern::AccessCode(); |
|
1662 |
DCodeSeg::EndDeferDeletes(); |
|
1663 |
Kern::EndAccessCode(); |
|
1664 |
} |
|
1665 |
||
1666 |
TInt ExecHandler::ProcessCreate(TProcessCreateInfo& aInfo, const TDesC* aCommandLine) |
|
1667 |
{ |
|
1668 |
TProcessCreateInfo info; |
|
1669 |
kumemget32(&info, &aInfo, sizeof(info)); |
|
134 | 1670 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::ProcessCreate %S ver %08x", &info.iFileName, info.iModuleVersion)); |
0 | 1671 |
__KTRACE_OPT(KDLL,DumpProcessCreateInfo(info)); |
1672 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1673 |
if (info.iHandle) |
|
1674 |
DCodeSeg::VerifyHandleP(info.iHandle); |
|
1675 |
info.iProcessHandle=0; |
|
1676 |
DThread& t=*TheCurrentThread; |
|
1677 |
TInt cmdlen=0; |
|
1678 |
if (aCommandLine) |
|
1679 |
{ |
|
1680 |
TInt maxLen; |
|
1681 |
Kern::KUDesInfo(*aCommandLine,cmdlen,maxLen); |
|
1682 |
} |
|
1683 |
NKern::ThreadEnterCS(); |
|
1684 |
HBuf* pCmd=NULL; |
|
1685 |
if (cmdlen) |
|
1686 |
pCmd=HBuf::New(cmdlen); |
|
1687 |
t.iTempAlloc=pCmd; |
|
1688 |
NKern::ThreadLeaveCS(); // we can die here but HBuf will be freed |
|
1689 |
if (cmdlen) |
|
1690 |
{ |
|
1691 |
if (!pCmd) |
|
1692 |
return KErrNoMemory; |
|
1693 |
Kern::KUDesGet(*pCmd,*aCommandLine); |
|
1694 |
} |
|
1695 |
NKern::ThreadEnterCS(); |
|
1696 |
t.iTempAlloc=NULL; // no more panics allowed |
|
1697 |
TMiscNotifier* n = 0; |
|
1698 |
SMiscNotifierQ* q = 0; |
|
1699 |
TInt r = KErrNone; |
|
1700 |
if (info.iDestructStat) |
|
1701 |
{ |
|
1702 |
n = new TMiscNotifier; |
|
1703 |
q = new SMiscNotifierQ; |
|
1704 |
if (!n || !q) |
|
1705 |
r = KErrNoMemory; |
|
1706 |
} |
|
1707 |
DProcess* pP=NULL; |
|
1708 |
if (r == KErrNone) |
|
1709 |
r = Kern::ProcessCreate(pP, info, pCmd, &info.iProcessHandle); |
|
1710 |
if (r == KErrNone && info.iDestructStat) |
|
1711 |
{ |
|
1712 |
r = K::TheMiscNotifierMgr.NewMiscNotifier(info.iDestructStat, TRUE, pP, n, q); |
|
1713 |
__NK_ASSERT_DEBUG(r >= 0); // can't fail |
|
1714 |
r = KErrNone; |
|
1715 |
} |
|
1716 |
delete pCmd; // in case P::NewProcess() failed |
|
1717 |
delete q; |
|
1718 |
if (n) |
|
1719 |
n->Close(); |
|
1720 |
NKern::ThreadLeaveCS(); |
|
1721 |
kumemput32(&aInfo.iUids, &info.iUids, sizeof(info)-sizeof(info.iFileName)); |
|
1722 |
__KTRACE_OPT(KDLL,DumpProcessCreateInfo(info)); |
|
1723 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::ProcessCreate returns %d",r)); |
|
1724 |
return r; |
|
1725 |
} |
|
1726 |
||
1727 |
||
1728 |
/** Creates a user execute-in-place process. |
|
1729 |
||
1730 |
Creates and constructs a new DProcess object and optionally creates and |
|
1731 |
opens a handle to it. The caller must call DProcess::Loaded() to complete |
|
1732 |
process initialisation. |
|
1733 |
||
1734 |
This function is only documented because it is used by the EXSTART kernel |
|
1735 |
extension to start the secondary process (i.e. file server). In general |
|
1736 |
processes should be created by user-side code because this function |
|
1737 |
bypasses the file server/loader. |
|
1738 |
||
1739 |
@param aProcess On successful return, contains a pointer to the newly |
|
1740 |
created process. |
|
1741 |
@param aInfo Information required to create the process. |
|
1742 |
@param aCommand Pointer to heap-based descriptor containing the command |
|
1743 |
line to pass to the process. On return, set to NULL if |
|
1744 |
and only if ownership has been transferred to the newly |
|
1745 |
created process. In other words, The caller must delete |
|
1746 |
the descriptor if the call fails and the pointer is not |
|
1747 |
set to NULL. |
|
1748 |
@param aHandle Pointer to handle or NULL if no handle is to be created. |
|
1749 |
If non NULL contains on successful return a handle to |
|
1750 |
the newly created process. |
|
1751 |
||
1752 |
@return Standard error code. |
|
1753 |
||
1754 |
@pre Calling thread must be in a critical section. |
|
1755 |
@pre Kernel must be unlocked |
|
1756 |
@pre interrupts enabled |
|
1757 |
@pre No fast mutex can be held |
|
1758 |
@pre Call in a thread context |
|
1759 |
||
1760 |
@post Calling thread is in a critical section. |
|
1761 |
||
1762 |
@internalTechnology |
|
1763 |
||
1764 |
@See TProcessCreateInfo |
|
1765 |
*/ |
|
1766 |
EXPORT_C TInt Kern::ProcessCreate(DProcess*& aProcess, TProcessCreateInfo& aInfo, HBuf*& aCommand, TInt* aHandle) |
|
1767 |
{ |
|
1768 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ProcessCreate"); |
|
1769 |
TInt r=KErrNoMemory; |
|
1770 |
aProcess=P::NewProcess(); |
|
1771 |
if (aProcess) |
|
1772 |
{ |
|
1773 |
r=aProcess->Create(EFalse,aInfo,aCommand); |
|
1774 |
__KTRACE_OPT(KPROC,Kern::Printf("DProcess::Create returns %d",r)); |
|
1775 |
aCommand=NULL; // will be deleted by process destruct if an error occurs |
|
1776 |
if (r==KErrNone && aHandle) |
|
1777 |
r=K::MakeHandleAndOpen(EOwnerProcess,aProcess,*aHandle); |
|
1778 |
if (r!=KErrNone) |
|
1779 |
{ |
|
1780 |
if (!aProcess->iThreadQ.IsEmpty()) |
|
1781 |
{ |
|
1782 |
// must remove thread |
|
1783 |
DThread* pT=_LOFF(aProcess->iThreadQ.First()->Deque(),DThread,iProcessLink); |
|
1784 |
pT->iProcessLink.iNext=NULL; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1785 |
pT->Stillborn(); |
0 | 1786 |
} |
1787 |
aProcess->Release(); |
|
1788 |
} |
|
1789 |
} |
|
1790 |
return r; |
|
1791 |
} |
|
1792 |
||
1793 |
TInt ExecHandler::ProcessLoaded(TProcessCreateInfo& aInfo) |
|
1794 |
{ |
|
1795 |
TProcessCreateInfo info; |
|
1796 |
kumemget32(&info, &aInfo, sizeof(info)); |
|
134 | 1797 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::ProcessLoaded %S ver %08x", &info.iFileName, info.iModuleVersion)); |
0 | 1798 |
__KTRACE_OPT(KDLL,DumpProcessCreateInfo(info)); |
1799 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1800 |
NKern::LockSystem(); |
|
1801 |
DProcess* pP=(DProcess*)K::ThreadEnterCS(info.iProcessHandle, EProcess); |
|
1802 |
TInt r=pP->Loaded(info); |
|
1803 |
info.iFinalHandle=0; |
|
1804 |
if (r==KErrNone) |
|
1805 |
{ |
|
1806 |
NKern::LockSystem(); |
|
1807 |
DThread* pT=(DThread*)K::ObjectFromHandle(info.iClientHandle,EThread); |
|
1808 |
if (!pT || pT->Open()) |
|
1809 |
{ |
|
1810 |
NKern::ThreadLeaveCS(); |
|
1811 |
K::PanicCurrentThread(EBadHandle); |
|
1812 |
} |
|
1813 |
NKern::UnlockSystem(); |
|
1814 |
r=pT->MakeHandle(info.iOwnerType, pP, info.iFinalHandle); |
|
1815 |
if (r==KErrNone) |
|
1816 |
{ |
|
1817 |
DProcess* creator = pT->iOwningProcess; |
|
1818 |
pP->iCreatorId = creator->iId; |
|
1819 |
pP->iCreatorInfo = creator->iS; |
|
1820 |
} |
|
1821 |
pT->Close(NULL); |
|
1822 |
} |
|
1823 |
if (r!=KErrNone) |
|
1824 |
pP->Close(NULL); |
|
1825 |
NKern::ThreadLeaveCS(); |
|
1826 |
kumemput32(&aInfo.iUids, &info.iUids, sizeof(info)-sizeof(info.iFileName)); |
|
1827 |
__KTRACE_OPT(KDLL,DumpProcessCreateInfo(info)); |
|
1828 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::ProcessLoaded returns %d",r)); |
|
1829 |
return r; |
|
1830 |
} |
|
1831 |
||
1832 |
TInt ExecHandler::CheckLoaderClientState(DThread* aClient) |
|
1833 |
{ |
|
1834 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CheckLoaderClientState %O", aClient)); |
|
1835 |
DMutex* pM = aClient->iOwningProcess->iDllLock; |
|
1836 |
if (pM && pM->iCleanup.iThread==aClient && aClient->iClosingLibs.IsEmpty()) |
|
1837 |
return KErrNone; |
|
1838 |
return KErrGeneral; |
|
1839 |
} |
|
1840 |
||
1841 |
TAny* ExecHandler::ThreadProcessCodeSeg(DThread* aThread) |
|
1842 |
{ |
|
1843 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::ThreadProcessCodeSeg %O",aThread)); |
|
1844 |
DProcess& p=*aThread->iOwningProcess; |
|
1845 |
TAny* h=p.CodeSeg(); |
|
1846 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::ThreadProcessCodeSeg returns %08x",h)); |
|
1847 |
return h; |
|
1848 |
} |
|
1849 |
||
1850 |
void ExecHandler::CodeSegReadExportDir(TAny* aHandle, TUint32* aDest) |
|
1851 |
{ |
|
1852 |
DCodeSeg* pS=DCodeSeg::VerifyCallerAndHandle(aHandle); |
|
1853 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::CodeSegReadExportDir %C", pS)); |
|
1854 |
pS->ReadExportDir(aDest); |
|
1855 |
} |
|
1856 |
||
1857 |
TLinAddr ExecHandler::ExceptionDescriptor(TLinAddr aCodeAddress) |
|
1858 |
{ |
|
1859 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf(">Exec::ExceptionDescriptor %08x", aCodeAddress)); |
|
1860 |
TLinAddr xd = 0; |
|
1861 |
Kern::AccessCode(); |
|
1862 |
DCodeSeg* s = Kern::CodeSegFromAddress(aCodeAddress, TheCurrentThread->iOwningProcess); |
|
1863 |
if (s) |
|
1864 |
xd = s->ExceptionDescriptor(); |
|
1865 |
Kern::EndAccessCode(); |
|
1866 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("<Exec::ExceptionDescriptor %08x", xd)); |
|
1867 |
return xd; |
|
1868 |
} |
|
1869 |
||
1870 |
/** Finds the code segment which contains a specified instruction address in a |
|
1871 |
specified process address space. |
|
1872 |
||
1873 |
@param aAddr The address to search for. |
|
1874 |
@param aProcess The process in which aAddr resides. |
|
1875 |
||
1876 |
@return A pointer to the code segment if it exists; |
|
1877 |
NULL if no corresponding code segment could be found. |
|
1878 |
||
1879 |
@pre Calling thread must be in a critical section. |
|
1880 |
@pre No fast mutex can be held. |
|
1881 |
@pre Call in a thread context. |
|
1882 |
@pre Code segment lock mutex held. |
|
1883 |
@pre Kernel must be unlocked |
|
1884 |
@pre interrupts enabled |
|
1885 |
@pre Call in a thread context |
|
1886 |
*/ |
|
1887 |
EXPORT_C DCodeSeg* Kern::CodeSegFromAddress(TLinAddr aAddr, DProcess* aProcess) |
|
1888 |
{ |
|
1889 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::CodeSegFromAddress"); |
|
1890 |
__ASSERT_WITH_MESSAGE_MUTEX(DCodeSeg::CodeSegLock,"Code segment lock mutex held","Kern::CodeSegFromAddress"); |
|
1891 |
__KTRACE_OPT(KDLL,Kern::Printf(">Kern::CodeSegFromAddress %08x", aAddr)); |
|
1892 |
DCodeSeg* s = aProcess->iCodeSeg; |
|
1893 |
if(!s || aAddr<s->iRunAddress || (aAddr-s->iRunAddress) >= s->iSize) |
|
1894 |
{ |
|
1895 |
// if not in EXE's codeseg, then find in list... |
|
1896 |
s = DCodeSeg::CodeSegsByAddress.Find(aAddr); |
|
1897 |
} |
|
1898 |
__KTRACE_OPT(KDLL,Kern::Printf("<Kern::CodeSegFromAddress %C", s)); |
|
1899 |
return s; |
|
1900 |
} |
|
1901 |
||
1902 |
/* Requests to be notified when something is added to the CodeSegLoaderCookie list. |
|
1903 |
||
1904 |
Called with the system locked. |
|
1905 |
*/ |
|
1906 |
||
1907 |
TInt ExecHandler::NotifyIfCodeSegDestroyed(TRequestStatus& aStatus) |
|
1908 |
{ |
|
1909 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1910 |
TInt r = DCodeSeg::DestructNotifyRequest->SetStatus(&aStatus); |
|
1911 |
if (r == KErrNone) |
|
1912 |
DCodeSeg::DestructNotifyThread = TheCurrentThread; |
|
1913 |
return r; |
|
1914 |
} |
|
1915 |
||
1916 |
||
1917 |
||
1918 |
/* Removes one CodeSeg from the cleanup list and returns it's cookie. |
|
1919 |
The CodeSeg is then destroyed. |
|
1920 |
*/ |
|
1921 |
||
1922 |
TInt ExecHandler::GetDestroyedCodeSegInfo(TCodeSegLoaderCookie& aCookie) |
|
1923 |
{ |
|
1924 |
TCodeSegLoaderCookieList* cookie; |
|
1925 |
K::CheckFileServerAccess(); // only F32 can use this exec function |
|
1926 |
NKern::ThreadEnterCS(); |
|
1927 |
DCodeSeg::Wait(); |
|
1928 |
if (DCodeSeg::DestructNotifyList==NULL) |
|
1929 |
{ |
|
1930 |
DCodeSeg::Signal(); |
|
1931 |
NKern::ThreadLeaveCS(); |
|
1932 |
return KErrNotFound; |
|
1933 |
} |
|
1934 |
||
1935 |
cookie=DCodeSeg::DestructNotifyList; |
|
1936 |
DCodeSeg::DestructNotifyList=DCodeSeg::DestructNotifyList->iNext; |
|
1937 |
DCodeSeg::Signal(); |
|
1938 |
kumemput(&aCookie,&cookie->iCookie, sizeof(TCodeSegLoaderCookie)); |
|
1939 |
delete cookie; |
|
1940 |
NKern::ThreadLeaveCS(); |
|
1941 |
return KErrNone; |
|
1942 |
} |
|
1943 |
||
1944 |
||
1945 |
/****************************************************************************** |
|
1946 |
* Executive Handlers - Client |
|
1947 |
******************************************************************************/ |
|
1948 |
||
1949 |
// Acquire the process DLL lock just before a load |
|
1950 |
TInt ExecHandler::WaitDllLock() |
|
1951 |
{ |
|
1952 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::WaitDllLock")); |
|
1953 |
DThread& t=*TheCurrentThread; |
|
1954 |
DProcess& p=*t.iOwningProcess; |
|
1955 |
__ASSERT_ALWAYS(t.iClosingLibs.IsEmpty(), K::PanicKernExec(EWaitDllLockInvalid)); |
|
1956 |
return p.WaitDllLock(); |
|
1957 |
} |
|
1958 |
||
1959 |
// Release the process DLL lock if a load fails |
|
1960 |
TInt ExecHandler::ReleaseDllLock() |
|
1961 |
{ |
|
1962 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::ReleaseDllLock")); |
|
1963 |
DThread& t=*TheCurrentThread; |
|
1964 |
DProcess& p=*t.iOwningProcess; |
|
1965 |
__ASSERT_ALWAYS(t.iClosingLibs.IsEmpty(), K::PanicKernExec(EReleaseDllLockInvalid)); |
|
1966 |
p.SignalDllLock(); |
|
1967 |
return KErrNone; |
|
1968 |
} |
|
1969 |
||
1970 |
// Accept a DLibrary just after a load and extract a list of entry points |
|
1971 |
TInt ExecHandler::LibraryAttach(TInt aHandle, TInt& aNumEps, TLinAddr* aEpList) |
|
1972 |
{ |
|
1973 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf(">Exec::LibraryAttach")); |
|
1974 |
DThread& t=*TheCurrentThread; |
|
1975 |
DProcess& p=*t.iOwningProcess; |
|
1976 |
TInt maxEps; |
|
1977 |
TInt numEps=0; |
|
1978 |
kumemget32(&maxEps, &aNumEps, sizeof(TInt)); |
|
1979 |
__ASSERT_ALWAYS( p.iDllLock->iCleanup.iThread==&t && |
|
1980 |
t.iClosingLibs.IsEmpty() && |
|
1981 |
maxEps>0, |
|
1982 |
K::PanicKernExec(ELibraryAttachInvalid)); |
|
1983 |
Kern::AccessCode(); |
|
1984 |
NKern::LockSystem(); |
|
1985 |
DLibrary* pL=(DLibrary*)t.ObjectFromHandle(aHandle,ELibrary); |
|
1986 |
NKern::UnlockSystem(); |
|
1987 |
if (!pL) |
|
1988 |
{ |
|
1989 |
Kern::EndAccessCode(); |
|
1990 |
K::PanicKernExec(EBadHandle); |
|
1991 |
} |
|
1992 |
DCodeSeg* pS=pL->iCodeSeg; |
|
1993 |
TInt r=KErrNone; |
|
1994 |
if (pL->iState!=DLibrary::EAttached) // already loaded or no entry points required |
|
1995 |
{ |
|
1996 |
SDblQue cs_list; |
|
1997 |
numEps=p.CallList(cs_list, pS, DProcess::ETraverseFlagRestrict); |
|
1998 |
if (numEps>maxEps) |
|
1999 |
r=ETooManyEntryPoints; |
|
2000 |
else if (numEps>0) |
|
2001 |
{ |
|
2002 |
r=DCodeSeg::WriteCallList(cs_list, aEpList, ETrue); |
|
2003 |
DCodeSeg::EmptyQueue(cs_list, 0); |
|
2004 |
if (r==KErrNone) |
|
2005 |
pL->iState=DLibrary::EAttaching; |
|
2006 |
} |
|
2007 |
else |
|
2008 |
pL->iState=DLibrary::EAttached; |
|
2009 |
} |
|
2010 |
Kern::EndAccessCode(); |
|
2011 |
if (r>0 || numEps==0) |
|
2012 |
p.SignalDllLock(); |
|
2013 |
if (r>0) |
|
2014 |
K::PanicKernExec(r); |
|
2015 |
kumemput32(&aNumEps,&numEps,sizeof(TInt)); |
|
2016 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("<Exec::LibraryAttach numEps=%d r=%d",numEps,r)); |
|
2017 |
return r; |
|
2018 |
} |
|
2019 |
||
2020 |
// Signal that entry points have been completed and release DLL lock |
|
2021 |
TInt ExecHandler::LibraryAttached(TInt aHandle) |
|
2022 |
{ |
|
2023 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("Exec::LibraryAttached")); |
|
2024 |
DThread& t=*TheCurrentThread; |
|
2025 |
DProcess& p=*t.iOwningProcess; |
|
2026 |
__ASSERT_ALWAYS( p.iDllLock->iCleanup.iThread==&t && |
|
2027 |
t.iClosingLibs.IsEmpty(), |
|
2028 |
K::PanicKernExec(ELibraryAttachedInvalid)); |
|
2029 |
TInt s; |
|
2030 |
Kern::AccessCode(); |
|
2031 |
NKern::LockSystem(); |
|
2032 |
DLibrary* pL=(DLibrary*)t.ObjectFromHandle(aHandle,ELibrary); |
|
2033 |
NKern::UnlockSystem(); |
|
2034 |
if (!pL) |
|
2035 |
{ |
|
2036 |
Kern::EndAccessCode(); |
|
2037 |
K::PanicKernExec(EBadHandle); |
|
2038 |
} |
|
2039 |
s=pL->iState; |
|
2040 |
if (s==DLibrary::EAttaching) |
|
2041 |
pL->iState=DLibrary::EAttached; |
|
2042 |
Kern::EndAccessCode(); |
|
2043 |
__ASSERT_ALWAYS(s==DLibrary::EAttaching, K::PanicKernExec(ELibraryAttachedInvalid)); |
|
2044 |
p.SignalDllLock(); |
|
2045 |
return KErrNone; |
|
2046 |
} |
|
2047 |
||
2048 |
// Extract a list of implicit DLL entry points for the current process |
|
2049 |
TInt ExecHandler::StaticCallList(TInt& aNumEps, TLinAddr* aEpList) |
|
2050 |
{ |
|
2051 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf(">Exec::StaticCallList")); |
|
2052 |
DThread& t=*TheCurrentThread; |
|
2053 |
DProcess& p=*t.iOwningProcess; |
|
2054 |
NKern::LockSystem(); |
|
2055 |
TBool initData=t.iFlags&KThreadFlagOriginal; |
|
2056 |
if (initData) |
|
2057 |
t.iFlags&=~KThreadFlagOriginal; |
|
2058 |
NKern::UnlockSystem(); |
|
2059 |
TInt maxEps; |
|
2060 |
TInt numEps=0; |
|
2061 |
kumemget32(&maxEps, &aNumEps, sizeof(TInt)); |
|
2062 |
Kern::AccessCode(); |
|
2063 |
DCodeSeg* pS=p.iCodeSeg; |
|
2064 |
SDblQue cs_list; |
|
2065 |
DCodeSeg::UnmarkAll(DCodeSeg::EMarkListDeps|DCodeSeg::EMarkUnListDeps); |
|
2066 |
numEps=pS->ListDeps(&cs_list, DCodeSeg::EMarkListDeps); |
|
2067 |
TInt r=KErrNone; |
|
2068 |
if (numEps>maxEps) |
|
2069 |
r=ETooManyEntryPoints; |
|
2070 |
else |
|
2071 |
r=DCodeSeg::WriteCallList(cs_list, aEpList, initData); |
|
2072 |
DCodeSeg::EmptyQueue(cs_list,0); |
|
2073 |
Kern::EndAccessCode(); |
|
2074 |
if (r>0) |
|
2075 |
K::PanicKernExec(r); |
|
2076 |
kumemput32(&aNumEps,&numEps,sizeof(TInt)); |
|
2077 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("<Exec::StaticCallList numEps=%d",numEps)); |
|
2078 |
return KErrNone; |
|
2079 |
} |
|
2080 |
||
2081 |
// Extract a list of DLL entry points for a closing DLL |
|
2082 |
TInt ExecHandler::LibraryDetach(TInt& aNumEps, TLinAddr* aEpList) |
|
2083 |
{ |
|
2084 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf(">Exec::LibraryDetach")); |
|
2085 |
DThread& t=*TheCurrentThread; |
|
2086 |
DProcess& p=*t.iOwningProcess; |
|
2087 |
TInt maxEps; |
|
2088 |
TInt numEps=0; |
|
2089 |
kumemget32(&maxEps, &aNumEps, sizeof(TInt)); |
|
2090 |
__ASSERT_ALWAYS( p.iDllLock->iCleanup.iThread==&t && |
|
2091 |
maxEps>0, |
|
2092 |
K::PanicKernExec(ELibraryDetachInvalid)); |
|
2093 |
Kern::AccessCode(); |
|
2094 |
TInt r=KErrEof; |
|
2095 |
if (!t.iClosingLibs.IsEmpty()) // could be empty if a DLL is reloaded by another thread |
|
2096 |
{ |
|
2097 |
DLibrary* pL=_LOFF(t.iClosingLibs.First(), DLibrary, iThreadLink); |
|
2098 |
DCodeSeg* pS=pL->iCodeSeg; |
|
2099 |
SDblQue cs_list; |
|
2100 |
numEps=p.CallList(cs_list, pS, DProcess::ETraverseFlagRestrict); |
|
2101 |
if (numEps>maxEps) |
|
2102 |
r=ETooManyEntryPoints; |
|
2103 |
else if (numEps>0) |
|
2104 |
{ |
|
2105 |
r=DCodeSeg::WriteCallList(cs_list, aEpList, EFalse); |
|
2106 |
DCodeSeg::EmptyQueue(cs_list, 0); |
|
2107 |
pL->iState=DLibrary::EDetaching; |
|
2108 |
} |
|
2109 |
else |
|
2110 |
{ |
|
2111 |
r=KErrNone; |
|
2112 |
pL->iState=DLibrary::ELoaded; |
|
2113 |
} |
|
2114 |
DCodeSeg::EmptyQueue(cs_list,0); |
|
2115 |
} |
|
2116 |
Kern::EndAccessCode(); |
|
2117 |
if (r>0) |
|
2118 |
K::PanicKernExec(r); |
|
2119 |
if (r==KErrEof) |
|
2120 |
p.SignalDllLock(); |
|
2121 |
kumemput32(&aNumEps,&numEps,sizeof(TInt)); |
|
2122 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("<Exec::LibraryDetach numEps=%d r=%d",numEps,r)); |
|
2123 |
return r; |
|
2124 |
} |
|
2125 |
||
2126 |
// Signal that entry points have been completed and release DLL |
|
2127 |
TInt ExecHandler::LibraryDetached() |
|
2128 |
{ |
|
2129 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf(">Exec::LibraryDetached")); |
|
2130 |
DThread& t=*TheCurrentThread; |
|
2131 |
DProcess& p=*t.iOwningProcess; |
|
2132 |
__ASSERT_ALWAYS( p.iDllLock->iCleanup.iThread==&t && |
|
2133 |
!t.iClosingLibs.IsEmpty(), |
|
2134 |
K::PanicKernExec(ELibraryDetachedInvalid)); |
|
2135 |
TInt r=KErrNone; |
|
2136 |
Kern::AccessCode(); |
|
2137 |
DLibrary* pL=_LOFF(t.iClosingLibs.First()->Deque(), DLibrary, iThreadLink); |
|
2138 |
__DEBUG_EVENT(EEventRemoveLibrary, pL); |
|
2139 |
pL->iThreadLink.iNext=NULL; |
|
2140 |
pL->iState=DLibrary::ELoaded; |
|
2141 |
pL->RemoveFromProcess(); |
|
2142 |
pL->Close(NULL); |
|
2143 |
if (t.iClosingLibs.IsEmpty()) |
|
2144 |
r=KErrEof; |
|
2145 |
Kern::EndAccessCode(); |
|
2146 |
if (r==KErrEof) |
|
2147 |
p.SignalDllLock(); |
|
2148 |
__KTRACE_OPT2(KEXEC,KDLL,Kern::Printf("<Exec::LibraryDetached r=%d",r)); |
|
2149 |
return r; |
|
2150 |
} |
|
2151 |
||
2152 |
// Signal that User::Leave() is about to throw a C++ exception |
|
2153 |
// that will unwind the stack, potentially touching code that |
|
2154 |
// could be unloaded by code on the cleanup stack. Therefore, |
|
2155 |
// delay unmapping code from this process whilst there are |
|
2156 |
// threads leaving. |
|
2157 |
TTrapHandler* ExecHandler::LeaveStart() |
|
2158 |
{ |
|
2159 |
__KTRACE_OPT(KEXEC, Kern::Printf(">Exec::LeaveStart")); |
|
2160 |
||
2161 |
#ifndef __LEAVE_EQUALS_THROW__ |
|
2162 |
||
2163 |
InvalidExecHandler(); |
|
2164 |
__KTRACE_OPT(KEXEC, Kern::Printf("<Exec::LeaveStart")); |
|
2165 |
return NULL; |
|
2166 |
||
2167 |
#else //__LEAVE_EQUALS_THROW__ |
|
2168 |
||
2169 |
DThread& thread = *TheCurrentThread; |
|
2170 |
||
2171 |
NKern::ThreadEnterCS(); |
|
2172 |
if (++thread.iLeaveDepth == 1) |
|
2173 |
{ |
|
2174 |
__e32_atomic_add_ord32(&thread.iOwningProcess->iThreadsLeaving, 1); |
|
2175 |
} |
|
2176 |
NKern::ThreadLeaveCS(); |
|
2177 |
||
2178 |
__KTRACE_OPT(KEXEC, Kern::Printf("<Exec::LeaveStart")); |
|
2179 |
return thread.iTrapHandler; |
|
2180 |
||
2181 |
#endif // !__LEAVE_EQUALS_THROW__ |
|
2182 |
||
2183 |
} |
|
2184 |
||
2185 |
// Signal that the C++ exception thrown by User::Leave() has been |
|
2186 |
// caught and that therefore this thread's stack has been unwound. |
|
2187 |
// Any code that is pending being unloaded and which could have |
|
2188 |
// been accessed whilst the stack was unwound may therefore be |
|
2189 |
// safely unloaded if all threads have completed leaving and this |
|
2190 |
// was not a recursive call to User::Leave(). |
|
2191 |
void ExecHandler::LeaveEnd() |
|
2192 |
{ |
|
2193 |
__KTRACE_OPT(KEXEC, Kern::Printf(">Exec::LeaveEnd")); |
|
2194 |
||
2195 |
#ifndef __LEAVE_EQUALS_THROW__ |
|
2196 |
||
2197 |
InvalidExecHandler(); |
|
2198 |
||
2199 |
#else //__LEAVE_EQUALS_THROW__ |
|
2200 |
||
2201 |
DThread& thread = *TheCurrentThread; |
|
2202 |
||
2203 |
__ASSERT_ALWAYS(thread.iLeaveDepth > 0, InvalidExecHandler()); |
|
2204 |
||
2205 |
NKern::ThreadEnterCS(); |
|
2206 |
thread.CleanupLeave(); |
|
2207 |
NKern::ThreadLeaveCS(); |
|
2208 |
||
2209 |
#endif // !__LEAVE_EQUALS_THROW__ |
|
2210 |
||
2211 |
__KTRACE_OPT(KEXEC, Kern::Printf("<Exec::LeaveEnd")); |
|
2212 |
} |