author | William Roberts <williamr@symbian.org> |
Mon, 23 Aug 2010 16:53:40 +0100 | |
changeset 250 | ac18961ed598 |
parent 201 | 43365a9b78a3 |
child 259 | 57b9594f5772 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1994-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\sexec.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <kernel/kern_priv.h> |
|
19 |
#include <e32uid.h> |
|
20 |
#include <e32ver.h> |
|
21 |
//#include <unicode.h> |
|
22 |
#include "execs.h" |
|
23 |
||
24 |
TInt ExecHandler::ObjectNext(TObjectType aType, TBuf8<KMaxFullName>& aName, TFindHandle& aFindHandle) |
|
25 |
// |
|
26 |
// Do the next find. |
|
27 |
// |
|
28 |
{ |
|
29 |
||
30 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ObjectNext type %d",aType)); |
|
31 |
if (aType<0 || aType>=ENumObjectTypes) |
|
32 |
K::PanicKernExec(EBadObjectType); |
|
33 |
DObjectCon* pC=K::Containers[aType]; |
|
34 |
TFullName fn; |
|
35 |
TFullName match; |
|
36 |
TFindHandle h; |
|
37 |
Kern::KUDesGet(match,aName); |
|
38 |
kumemget32(&h,&aFindHandle,sizeof(h)); |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
39 |
__KTRACE_OPT(KEXEC,Kern::Printf("ObjN: %S %08x", &match, h.Handle())); |
0 | 40 |
NKern::ThreadEnterCS(); |
41 |
TInt r=pC->FindByFullName(h, match, fn); |
|
42 |
NKern::ThreadLeaveCS(); |
|
43 |
Kern::KUDesPut(aName,fn); |
|
44 |
kumemput32(&aFindHandle,&h,sizeof(h)); |
|
45 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ObjectNext ret %d",r)); |
|
46 |
return r; |
|
47 |
} |
|
48 |
||
49 |
TUint8 *ExecHandler::ChunkBase(DChunk* aChunk) |
|
50 |
// |
|
51 |
// Return the address of the base of the Chunk. |
|
52 |
// |
|
53 |
{ |
|
54 |
||
55 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ChunkBase")); |
|
56 |
return (TUint8*)aChunk->Base(&Kern::CurrentProcess()); |
|
57 |
} |
|
58 |
||
59 |
TInt ExecHandler::ChunkSize(DChunk* aChunk) |
|
60 |
// |
|
61 |
// Return the current size of the Chunk. |
|
62 |
// |
|
63 |
{ |
|
64 |
||
65 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ChunkSize")); |
|
66 |
return aChunk->Size(); |
|
67 |
} |
|
68 |
||
69 |
TInt ExecHandler::ChunkMaxSize(DChunk* aChunk) |
|
70 |
// |
|
71 |
// Return the maximum size of the Chunk. |
|
72 |
// |
|
73 |
{ |
|
74 |
||
75 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ChunkMaxSize")); |
|
76 |
return aChunk->MaxSize(); |
|
77 |
} |
|
78 |
||
79 |
TInt ExecHandler::ChunkBottom(DChunk* aChunk) |
|
80 |
// |
|
81 |
// Return the position of the bottom of the chunk |
|
82 |
// |
|
83 |
{ |
|
84 |
||
85 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ChunkBottom")); |
|
86 |
return aChunk->Bottom(); |
|
87 |
} |
|
88 |
||
89 |
TInt ExecHandler::ChunkTop(DChunk* aChunk) |
|
90 |
// |
|
91 |
// Return the position of the top of the chunk |
|
92 |
// |
|
93 |
{ |
|
94 |
||
95 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ChunkTop")); |
|
96 |
return aChunk->Top(); |
|
97 |
} |
|
98 |
||
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
99 |
TInt ExecHandler::MutexWait(DMutex* aMutex, TInt aTimeout) |
0 | 100 |
// |
101 |
// Wait for the mutex. |
|
102 |
// |
|
103 |
{ |
|
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
104 |
if (aTimeout) // 0 means wait forever, -1 means poll |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
105 |
{ |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
106 |
if (aTimeout<-1) |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
107 |
{ |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
108 |
return KErrArgument; |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
109 |
} |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
110 |
if (aTimeout>0) |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
111 |
{ |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
112 |
// Convert microseconds to NTimer ticks, rounding up |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
113 |
TInt ntp = NKern::TickPeriod(); |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
114 |
aTimeout += ntp-1; |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
115 |
aTimeout /= ntp; |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
116 |
} |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
117 |
} |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
118 |
return aMutex->Wait(aTimeout); |
0 | 119 |
} |
120 |
||
121 |
void ExecHandler::MutexSignal(DMutex* aMutex) |
|
122 |
// |
|
123 |
// Signal the mutex. |
|
124 |
// |
|
125 |
{ |
|
126 |
||
127 |
// __KTRACE_OPT(KEXEC,Kern::Printf("Exec::MutexSignal")); |
|
128 |
if (TheCurrentThread==aMutex->iCleanup.iThread) |
|
129 |
{ |
|
130 |
aMutex->Signal(); |
|
131 |
return; |
|
132 |
} |
|
133 |
K::PanicCurrentThread(EAccessDenied); |
|
134 |
} |
|
135 |
||
136 |
/** |
|
137 |
Test if mutex is held by the current thread. |
|
138 |
@return True if the current thread has waited on the mutex, false otherwise. |
|
139 |
*/ |
|
140 |
TBool ExecHandler::MutexIsHeld(DMutex* aMutex) |
|
141 |
{ |
|
142 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::MutexIsHeld")); |
|
143 |
return TheCurrentThread==aMutex->iCleanup.iThread; |
|
144 |
} |
|
145 |
||
146 |
void ExecHandler::ProcessType(DProcess* aProcess, TUidType& aUids) |
|
147 |
// |
|
148 |
// Get process' UIDs. |
|
149 |
// |
|
150 |
{ |
|
151 |
||
152 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessType")); |
|
153 |
TUidType uids(aProcess->iUids); |
|
154 |
NKern::UnlockSystem(); |
|
155 |
kumemput32(&aUids,&uids,sizeof(TUidType)); |
|
156 |
} |
|
157 |
||
158 |
TInt ExecHandler::ProcessId(DProcess* aProcess) |
|
159 |
// |
|
160 |
// Get process ID. |
|
161 |
// |
|
162 |
{ |
|
163 |
||
164 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessId")); |
|
165 |
return (TInt)aProcess->iId; |
|
166 |
} |
|
167 |
||
168 |
void ExecHandler::ProcessSecurityInfo(DProcess* aProcess,SSecurityInfo& aInfo) |
|
169 |
// |
|
170 |
// Get process security info. |
|
171 |
// |
|
172 |
{ |
|
173 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessSecurityInfo")); |
|
174 |
SSecurityInfo info(aProcess->iS); |
|
175 |
NKern::UnlockSystem(); |
|
176 |
kumemput32(&aInfo,&info,sizeof(info)); |
|
177 |
} |
|
178 |
||
179 |
void ExecHandler::ThreadSecurityInfo(DThread* aThread,SSecurityInfo& aInfo) |
|
180 |
// |
|
181 |
// Get threads security info. |
|
182 |
// |
|
183 |
{ |
|
184 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadSecurityInfo")); |
|
185 |
SSecurityInfo info(aThread->iOwningProcess->iS); |
|
186 |
NKern::UnlockSystem(); |
|
187 |
kumemput32(&aInfo,&info,sizeof(info)); |
|
188 |
} |
|
189 |
||
190 |
void ExecHandler::MessageSecurityInfo(DThread* aClient,SSecurityInfo& aInfo) |
|
191 |
// |
|
192 |
// Get clients security info. |
|
193 |
// |
|
194 |
{ |
|
195 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::MessageSecurityInfo")); |
|
196 |
SSecurityInfo info(aClient->iOwningProcess->iS); |
|
197 |
NKern::UnlockSystem(); |
|
198 |
kumemput32(&aInfo,&info,sizeof(info)); |
|
199 |
} |
|
200 |
||
201 |
TInt ExecHandler::SessionSecurityInfo(TInt aSession,SSecurityInfo& aInfo) |
|
202 |
// |
|
203 |
// Get session security info. |
|
204 |
// |
|
205 |
{ |
|
206 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::SessionSecurityInfo")); |
|
207 |
TInt r = KErrBadHandle; |
|
208 |
SSecurityInfo info; |
|
209 |
NKern::LockSystem(); |
|
210 |
DSession* s = (DSession*)TheCurrentThread->ObjectFromHandle(aSession,ESession); |
|
211 |
if (s) |
|
212 |
{ |
|
213 |
if (s->iServer && s->iServer->iOwningThread) |
|
214 |
{ |
|
215 |
// session is connected, and server is alive |
|
216 |
info = s->iServer->iOwningThread->iOwningProcess->iS; |
|
217 |
r = KErrNone; |
|
218 |
} |
|
219 |
else |
|
220 |
{ |
|
221 |
r = KErrServerTerminated; |
|
222 |
} |
|
223 |
} |
|
224 |
NKern::UnlockSystem(); |
|
225 |
if (r==KErrNone) |
|
226 |
kumemput32(&aInfo,&info,sizeof(info)); |
|
227 |
return r; |
|
228 |
} |
|
229 |
||
230 |
void ExecHandler::CreatorSecurityInfo(SSecurityInfo& aInfo) |
|
231 |
// |
|
232 |
// Get creator's security info. |
|
233 |
// |
|
234 |
{ |
|
235 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::CreatorSecurityInfo")); |
|
236 |
kumemput32(&aInfo,&TheCurrentThread->iOwningProcess->iCreatorInfo,sizeof(aInfo)); |
|
237 |
} |
|
238 |
||
239 |
void ExecHandler::DisabledCapabilities(SCapabilitySet& aCaps) |
|
240 |
// |
|
241 |
// Get the set of capabilities which are not to be checked (implemented by effectively |
|
242 |
// setting them for all executables). |
|
243 |
// |
|
244 |
{ |
|
245 |
__KTRACE_OPT(KEXEC, Kern::Printf("Exec::DisabledCapabilities")); |
|
246 |
#ifdef __PLATSEC_UNLOCKED__ |
|
247 |
kumemput32(&aCaps, &TheSuperPage().iDisabledCapabilities, sizeof(aCaps)); |
|
248 |
#else |
|
249 |
kumemset(&aCaps, 0, sizeof(aCaps)); |
|
250 |
#endif // __PLATSEC_UNLOCKED__ |
|
251 |
} |
|
252 |
||
253 |
void ExecHandler::ProcessResume(DProcess* aProcess) |
|
254 |
// |
|
255 |
// Resume the first thread in the process. |
|
256 |
// |
|
257 |
{ |
|
258 |
||
259 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessResume")); |
|
260 |
if (aProcess->iCreatorId!=TheCurrentThread->iOwningProcess->iId) // Not creator... |
|
261 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RProcess::Resume")); |
|
262 |
aProcess->Resume(); |
|
263 |
} |
|
264 |
||
265 |
void ExecHandler::ProcessFileName(DProcess* aProcess, TDes8& aName) |
|
266 |
// |
|
267 |
// Return the process file name. |
|
268 |
// |
|
269 |
{ |
|
270 |
||
271 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessFileName")); |
|
272 |
TFileName fn; |
|
273 |
DCodeSeg* pS=aProcess->iCodeSeg; |
|
274 |
if (pS) |
|
275 |
pS->AppendFullFileName(fn); |
|
276 |
NKern::UnlockSystem(); |
|
277 |
if (pS) |
|
278 |
P::NormalizeExecutableFileName(fn); |
|
279 |
Kern::KUDesPut(aName, fn); |
|
280 |
} |
|
281 |
||
282 |
TInt ExecHandler::ProcessCommandLineLength(DProcess* aProcess) |
|
283 |
// |
|
284 |
// Return the process command line length. |
|
285 |
// |
|
286 |
{ |
|
287 |
||
288 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessCommandLineLength")); |
|
289 |
||
290 |
if (aProcess->iSecurityZone!=TheCurrentThread->iOwningProcess->iSecurityZone) |
|
291 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RProcess::CommandLineLength")); |
|
292 |
const TDesC* pC=aProcess->iCommandLine; |
|
293 |
#ifdef _UNICODE |
|
294 |
return pC?(pC->Length()>>1):0; |
|
295 |
#else |
|
296 |
return pC?(pC->Length()):0; |
|
297 |
#endif |
|
298 |
} |
|
299 |
||
300 |
void ExecHandler::ProcessCommandLine(DProcess* aProcess, TDes8& aCommandLine) |
|
301 |
// |
|
302 |
// Return the process command line. |
|
303 |
// |
|
304 |
{ |
|
305 |
||
306 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessCommandLine")); |
|
307 |
if (aProcess->iSecurityZone!=TheCurrentThread->iOwningProcess->iSecurityZone) |
|
308 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RProcess::CommandLine")); |
|
309 |
aProcess->CheckedOpen(); |
|
310 |
DThread& t=*TheCurrentThread; |
|
311 |
t.iTempObj=aProcess; |
|
312 |
NKern::UnlockSystem(); |
|
313 |
const TDesC* pC=aProcess->iCommandLine; |
|
314 |
if (!pC) |
|
315 |
pC=&KNullDesC; |
|
316 |
Kern::KUDesPut(aCommandLine,*pC); |
|
317 |
NKern::ThreadEnterCS(); |
|
318 |
t.iTempObj=NULL; |
|
319 |
aProcess->Close(NULL); |
|
320 |
NKern::ThreadLeaveCS(); |
|
321 |
} |
|
322 |
||
323 |
TExitType ExecHandler::ProcessExitType(DProcess* aProcess) |
|
324 |
// |
|
325 |
// Return the exit type. |
|
326 |
// |
|
327 |
{ |
|
328 |
||
329 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessExitType")); |
|
330 |
return (TExitType)aProcess->iExitType; |
|
331 |
} |
|
332 |
||
333 |
TInt ExecHandler::ProcessExitReason(DProcess* aProcess) |
|
334 |
// |
|
335 |
// Return the exit reason. |
|
336 |
// |
|
337 |
{ |
|
338 |
||
339 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessExitReason")); |
|
340 |
return aProcess->iExitReason; |
|
341 |
} |
|
342 |
||
343 |
void ExecHandler::ProcessExitCategory(DProcess* aProcess, TDes8& aName) |
|
344 |
// |
|
345 |
// Return the category of the exit type. |
|
346 |
// |
|
347 |
{ |
|
348 |
||
349 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessExitCategory")); |
|
350 |
TBufC<KMaxExitCategoryName> exitCat(aProcess->iExitCategory); |
|
351 |
NKern::UnlockSystem(); |
|
352 |
Kern::KUDesPut(aName,exitCat); |
|
353 |
} |
|
354 |
||
355 |
LOCAL_D const TProcessPriority procPriorityConvertTable[8]= |
|
356 |
{ |
|
357 |
EPriorityLow, EPriorityBackground, EPriorityForeground, EPriorityHigh, |
|
358 |
EPriorityWindowServer, EPriorityFileServer, EPrioritySupervisor, EPriorityRealTimeServer |
|
359 |
}; |
|
360 |
||
361 |
LOCAL_D const TThreadPriority thrdPriorityConvertTable[8]= |
|
362 |
{ |
|
363 |
EPriorityMuchLess, EPriorityMuchLess, EPriorityLess, EPriorityNormal, |
|
364 |
EPriorityMore, EPriorityMuchMore, EPriorityRealTime, EPriorityRealTime |
|
365 |
}; |
|
366 |
||
367 |
LOCAL_C TThreadPriority ConvertThreadPriority(TInt p) |
|
368 |
{ |
|
369 |
switch(p) |
|
370 |
{ |
|
371 |
case EThrdPriorityAbsoluteVeryLow: |
|
372 |
return EPriorityAbsoluteVeryLow; |
|
373 |
case EThrdPriorityAbsoluteLowNormal: |
|
374 |
return EPriorityAbsoluteLowNormal; |
|
375 |
case EThrdPriorityAbsoluteLow: |
|
376 |
return EPriorityAbsoluteLow; |
|
377 |
case EThrdPriorityAbsoluteBackgroundNormal: |
|
378 |
return EPriorityAbsoluteBackgroundNormal; |
|
379 |
case EThrdPriorityAbsoluteBackground: |
|
380 |
return EPriorityAbsoluteBackground; |
|
381 |
case EThrdPriorityAbsoluteForegroundNormal: |
|
382 |
return EPriorityAbsoluteForegroundNormal; |
|
383 |
case EThrdPriorityAbsoluteForeground: |
|
384 |
return EPriorityAbsoluteForeground; |
|
385 |
case EThrdPriorityAbsoluteHighNormal: |
|
386 |
return EPriorityAbsoluteHighNormal; |
|
387 |
case EThrdPriorityAbsoluteHigh: |
|
388 |
return EPriorityAbsoluteHigh; |
|
389 |
case EThrdPriorityAbsoluteRealTime1: |
|
390 |
return EPriorityAbsoluteRealTime1; |
|
391 |
case EThrdPriorityAbsoluteRealTime2: |
|
392 |
return EPriorityAbsoluteRealTime2; |
|
393 |
case EThrdPriorityAbsoluteRealTime3: |
|
394 |
return EPriorityAbsoluteRealTime3; |
|
395 |
case EThrdPriorityAbsoluteRealTime4: |
|
396 |
return EPriorityAbsoluteRealTime4; |
|
397 |
case EThrdPriorityAbsoluteRealTime5: |
|
398 |
return EPriorityAbsoluteRealTime5; |
|
399 |
case EThrdPriorityAbsoluteRealTime6: |
|
400 |
return EPriorityAbsoluteRealTime6; |
|
401 |
case EThrdPriorityAbsoluteRealTime7: |
|
402 |
return EPriorityAbsoluteRealTime7; |
|
403 |
case EThrdPriorityAbsoluteRealTime8: |
|
404 |
return EPriorityAbsoluteRealTime8; |
|
405 |
default: |
|
406 |
if (p>=-8 && p<0) |
|
407 |
return thrdPriorityConvertTable[p+8]; |
|
408 |
} |
|
409 |
return EPriorityNormal; |
|
410 |
} |
|
411 |
||
412 |
LOCAL_C TBool ProcessPriorityValid(TProcessPriority p) |
|
413 |
{ |
|
414 |
switch(p) |
|
415 |
{ |
|
416 |
case EPriorityLow: |
|
417 |
case EPriorityBackground: |
|
418 |
case EPriorityForeground: |
|
419 |
case EPriorityHigh: |
|
420 |
return ETrue; |
|
421 |
default: |
|
422 |
return EFalse; |
|
423 |
} |
|
424 |
} |
|
425 |
||
426 |
TProcessPriority ExecHandler::ProcessPriority(DProcess* aProcess) |
|
427 |
// |
|
428 |
// Get the process base priority. |
|
429 |
// |
|
430 |
{ |
|
431 |
||
432 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessPriority")); |
|
433 |
return procPriorityConvertTable[aProcess->iPriority]; |
|
434 |
} |
|
435 |
||
436 |
TInt ExecHandler::ProcessSetPriority(DProcess* aProcess, TProcessPriority aPriority) |
|
437 |
// |
|
438 |
// Set the process base priority. |
|
439 |
// |
|
440 |
{ |
|
441 |
||
442 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessSetPriority")); |
|
443 |
aProcess->CheckedOpen(); |
|
444 |
DThread& t=*TheCurrentThread; |
|
445 |
t.iTempObj=aProcess; |
|
446 |
NKern::UnlockSystem(); |
|
447 |
if (!ProcessPriorityValid(aPriority)) |
|
448 |
K::PanicKernExec(EBadPriority); |
|
449 |
||
450 |
TBool allowed=ETrue; |
|
451 |
DProcess* currentProcess=TheCurrentThread->iOwningProcess; |
|
452 |
if (aProcess->iSecurityZone!=currentProcess->iSecurityZone) // Not self... |
|
453 |
if (aProcess->iCreatorId!=currentProcess->iId) // Not creator |
|
454 |
{ |
|
455 |
TInt processPriority=aProcess->iPriority; |
|
456 |
if (!(aProcess->iFlags&KProcessFlagPriorityControl) // No remote control... |
|
457 |
|| (processPriority!=EProcPriorityBackground && processPriority!=EProcPriorityForeground && processPriority!=EProcPriorityHigh) |
|
458 |
|| (aPriority!=EPriorityBackground && aPriority!=EPriorityForeground && aPriority!=EPriorityHigh) ) // Or not foreground/background/high |
|
459 |
allowed=!(TheSuperPage().KernelConfigFlags() & EKernelConfigPlatSecProcessIsolation); |
|
460 |
} |
|
461 |
||
462 |
NKern::ThreadEnterCS(); |
|
463 |
t.iTempObj=NULL; |
|
464 |
if(allowed) |
|
465 |
aProcess->SetPriority(aPriority); |
|
466 |
aProcess->Close(NULL); |
|
467 |
NKern::ThreadLeaveCS(); |
|
468 |
if (allowed) |
|
469 |
{ |
|
470 |
return KErrNone; |
|
471 |
} |
|
472 |
else |
|
473 |
{ |
|
474 |
return KErrPermissionDenied; |
|
475 |
} |
|
476 |
||
477 |
} |
|
478 |
||
479 |
||
480 |
||
481 |
const TUint32 KDefinedProcessFlags= |
|
482 |
KProcessFlagSystemCritical| |
|
483 |
KProcessFlagSystemPermanent| |
|
484 |
KProcessFlagJustInTime| |
|
485 |
KProcessFlagPriorityControl| |
|
486 |
KThreadFlagProcessCritical; |
|
487 |
||
488 |
const TUint32 KRestrictedProcessFlags = |
|
489 |
~(KProcessFlagJustInTime|KProcessFlagPriorityControl|KThreadFlagProcessCritical); // All but these are restricted |
|
490 |
||
491 |
const TUint32 KSelfOnlyProcessFlags = |
|
492 |
~0u; // (KProcessFlagJustInTime|KProcessFlagPriorityControl); // Only self can change these |
|
493 |
||
494 |
const TUint32 KDefinedThreadFlags= |
|
495 |
KThreadFlagProcessCritical| |
|
496 |
KThreadFlagProcessPermanent| |
|
497 |
KThreadFlagSystemCritical| |
|
498 |
KThreadFlagSystemPermanent| |
|
499 |
KThreadFlagLastChance| |
|
500 |
KThreadFlagRealtime| |
|
501 |
KThreadFlagRealtimeTest; |
|
502 |
||
503 |
const TUint32 KRestrictedThreadFlags = |
|
504 |
~(KThreadFlagProcessCritical|KThreadFlagProcessPermanent|KThreadFlagLastChance| |
|
505 |
KThreadFlagRealtime|KThreadFlagRealtimeTest); // All but these are restricted |
|
506 |
||
507 |
const TUint32 KSelfOnlyThreadFlags = |
|
508 |
~0u; // (KThreadFlagProcessCritical|KThreadFlagProcessPermanent|KThreadFlagLastChance); // Only owning process can change these |
|
509 |
||
510 |
||
511 |
TUint ExecHandler::ProcessFlags(DProcess* aProcess) |
|
512 |
// |
|
513 |
// Get the process flags |
|
514 |
// |
|
515 |
{ |
|
516 |
||
517 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessFlags")); |
|
518 |
return aProcess->iFlags; |
|
519 |
} |
|
520 |
||
521 |
TUint ExecHandler::ThreadProcessFlags(DThread* aThread) |
|
522 |
// |
|
523 |
// Get the process flags |
|
524 |
// |
|
525 |
{ |
|
526 |
||
527 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadProcessFlags")); |
|
528 |
return aThread->iOwningProcess->iFlags; |
|
529 |
} |
|
530 |
||
531 |
void ExecHandler::ProcessSetFlags(DProcess* aProcess, TUint aClearMask, TUint aSetMask) |
|
532 |
// |
|
533 |
// Set the process flags |
|
534 |
// |
|
535 |
{ |
|
536 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessSetFlags")); |
|
537 |
||
538 |
TUint flags = aProcess->iFlags; |
|
539 |
TUint modified = ((flags&~aClearMask)|aSetMask); |
|
540 |
modified = (modified^flags)&KDefinedProcessFlags; |
|
541 |
||
542 |
DProcess* currentProcess=TheCurrentThread->iOwningProcess; |
|
543 |
||
544 |
if (modified&KSelfOnlyProcessFlags) |
|
545 |
if(aProcess->iSecurityZone!=currentProcess->iSecurityZone) |
|
546 |
if(aProcess->iCreatorId!=currentProcess->iId) |
|
547 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Attempt to modify the attributes of another Process. Possibly RProcess::SetSystem.")); |
|
548 |
||
549 |
if (modified&KRestrictedProcessFlags) |
|
550 |
if(!currentProcess->HasCapability(ECapabilityProtServ,__PLATSEC_DIAGNOSTIC_STRING("Checked by User::SetProcessCritical (or RProcess::SetSystem)"))) |
|
551 |
K::LockedPlatformSecurityPanic(); |
|
552 |
||
553 |
aProcess->iFlags=flags^modified; |
|
554 |
||
555 |
// if flags altered before resume, original thread inherits system critical and |
|
556 |
// process critical from process. |
|
557 |
if (!(aProcess->iAttributes & DProcess::EResumed)) |
|
558 |
{ |
|
559 |
TUint32& tf = aProcess->FirstThread()->iFlags; |
|
560 |
tf = (tf &~ (KThreadFlagSystemCritical|KThreadFlagProcessCritical)) | |
|
561 |
(aProcess->iFlags & (KThreadFlagSystemCritical|KThreadFlagProcessCritical)); |
|
562 |
} |
|
563 |
} |
|
564 |
||
565 |
TInt ExecHandler::SemaphoreWait(DSemaphore* aSemaphore, TInt aTimeout) |
|
566 |
// |
|
567 |
// Wait for a signal. |
|
568 |
// |
|
569 |
{ |
|
570 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::SemaphoreWait")); |
|
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
571 |
if (aTimeout) // 0 means wait forever, -1 means poll |
0 | 572 |
{ |
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
573 |
if (aTimeout<-1) |
0 | 574 |
{ |
575 |
NKern::UnlockSystem(); |
|
576 |
return KErrArgument; |
|
577 |
} |
|
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
578 |
if (aTimeout>0) |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
579 |
{ |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
580 |
// Convert microseconds to NTimer ticks, rounding up |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
581 |
TInt ntp = NKern::TickPeriod(); |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
582 |
aTimeout += ntp-1; |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
583 |
aTimeout /= ntp; |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
152
diff
changeset
|
584 |
} |
0 | 585 |
} |
586 |
return aSemaphore->Wait(aTimeout); |
|
587 |
} |
|
588 |
||
589 |
void ExecHandler::SemaphoreSignal1(DSemaphore* aSemaphore) |
|
590 |
// |
|
591 |
// Signal the semaphore once. |
|
592 |
// |
|
593 |
{ |
|
594 |
||
595 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::SemaphoreSignal1")); |
|
596 |
aSemaphore->Signal(); |
|
597 |
} |
|
598 |
||
599 |
void ExecHandler::SemaphoreSignalN(DSemaphore* aSem, TInt aCount) |
|
600 |
// |
|
601 |
// Signal the semaphore aCount times. |
|
602 |
// |
|
603 |
{ |
|
604 |
||
605 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::SemaphoreSignalN")); |
|
606 |
aSem->CheckedOpen(); |
|
607 |
NKern::ThreadEnterCS(); |
|
608 |
aSem->SignalN(aCount); |
|
609 |
NKern::UnlockSystem(); |
|
610 |
aSem->Close(NULL); |
|
611 |
NKern::ThreadLeaveCS(); |
|
612 |
} |
|
613 |
||
614 |
TInt ExecHandler::ThreadId(DThread* aThread) |
|
615 |
// |
|
616 |
// Get thread ID. |
|
617 |
// |
|
618 |
{ |
|
619 |
||
620 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadId")); |
|
621 |
return (TInt)aThread->iId; |
|
622 |
} |
|
623 |
||
624 |
LOCAL_C TBool IsThreadPriorityAbsoluteRealTime(TThreadPriority p) |
|
625 |
// |
|
626 |
// Returns true if priority is an absolute "real time" thread priority. |
|
627 |
// |
|
628 |
{ |
|
629 |
switch(p) |
|
630 |
{ |
|
631 |
case EPriorityAbsoluteRealTime1: |
|
632 |
case EPriorityAbsoluteRealTime2: |
|
633 |
case EPriorityAbsoluteRealTime3: |
|
634 |
case EPriorityAbsoluteRealTime4: |
|
635 |
case EPriorityAbsoluteRealTime5: |
|
636 |
case EPriorityAbsoluteRealTime6: |
|
637 |
case EPriorityAbsoluteRealTime7: |
|
638 |
case EPriorityAbsoluteRealTime8: |
|
639 |
return ETrue; |
|
640 |
default: |
|
641 |
return EFalse; |
|
642 |
} |
|
643 |
} |
|
644 |
||
645 |
void ExecHandler::ThreadResume(DThread* aThread) |
|
646 |
// |
|
647 |
// Resume a thread. |
|
648 |
// |
|
649 |
{ |
|
650 |
||
651 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadResume")); |
|
652 |
if (aThread->iOwningProcess->iSecurityZone!=TheCurrentThread->iOwningProcess->iSecurityZone) |
|
653 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Use of RThread::Resume on a thread in another process")); |
|
654 |
aThread->Resume(); |
|
655 |
} |
|
656 |
||
657 |
TThreadPriority ExecHandler::ThreadPriority(DThread* aThread) |
|
658 |
// |
|
659 |
// Get the threads priority. |
|
660 |
// |
|
661 |
{ |
|
662 |
||
663 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadPriority")); |
|
664 |
return ConvertThreadPriority(aThread->iThreadPriority); |
|
665 |
} |
|
666 |
||
667 |
void ExecHandler::ThreadSetPriority(DThread* aThread,TThreadPriority aPriority) |
|
668 |
// |
|
669 |
// Set the threads priority. |
|
670 |
// |
|
671 |
{ |
|
672 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadSetPriority")); |
|
673 |
if (aThread->iOwningProcess->iSecurityZone!=TheCurrentThread->iOwningProcess->iSecurityZone) |
|
674 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Use of RThread::SetPriority on a thread in a different process")); |
|
675 |
if(IsThreadPriorityAbsoluteRealTime(aPriority) && |
|
676 |
!(TheCurrentThread->HasCapability(ECapabilityProtServ,__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::SetPriority")))) |
|
677 |
K::LockedPlatformSecurityPanic(); |
|
678 |
else |
|
679 |
aThread->SetPriority(aPriority); |
|
680 |
} |
|
681 |
||
682 |
TProcessPriority ExecHandler::ThreadProcessPriority(DThread* aThread) |
|
683 |
// |
|
684 |
// Get the owning process's priority. |
|
685 |
// |
|
686 |
{ |
|
687 |
||
688 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadProcessPriority")); |
|
689 |
return procPriorityConvertTable[aThread->iOwningProcess->iPriority]; |
|
690 |
} |
|
691 |
||
692 |
void ExecHandler::ThreadSetProcessPriority(DThread* aThread, TProcessPriority aPriority) |
|
693 |
// |
|
694 |
// Set the owning process's priority. |
|
695 |
// |
|
696 |
{ |
|
697 |
ExecHandler::ProcessSetPriority(aThread->iOwningProcess,aPriority); |
|
698 |
} |
|
699 |
||
700 |
TUint ExecHandler::ThreadFlags(DThread* aThread) |
|
701 |
// |
|
702 |
// Get the threads flag state. |
|
703 |
// |
|
704 |
{ |
|
705 |
||
706 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadFlags")); |
|
707 |
return(aThread->iFlags); |
|
708 |
} |
|
709 |
||
710 |
void ExecHandler::ThreadSetFlags(DThread* aThread,TUint aClearMask,TUint aSetMask) |
|
711 |
// |
|
712 |
// Set the thread flags |
|
713 |
// |
|
714 |
{ |
|
715 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadSetFlags")); |
|
716 |
TUint flags = aThread->iFlags; |
|
717 |
TUint modified = ((flags&~aClearMask)|aSetMask); |
|
718 |
modified = (modified^flags)&KDefinedThreadFlags; |
|
719 |
||
720 |
DProcess* currentProcess=TheCurrentThread->iOwningProcess; |
|
721 |
||
722 |
if (modified&KSelfOnlyThreadFlags) |
|
723 |
if(aThread->iOwningProcess->iSecurityZone!=currentProcess->iSecurityZone) |
|
724 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Attempt to modify attributes of a thread in another process. Possibly RThread::SetSystem")); |
|
725 |
||
726 |
if (modified&KRestrictedThreadFlags) |
|
727 |
if(!currentProcess->HasCapability(ECapabilityProtServ,__PLATSEC_DIAGNOSTIC_STRING("Checked by User::SetCritical (or RThread::SetSystem)"))) |
|
728 |
K::LockedPlatformSecurityPanic(); |
|
729 |
||
730 |
aThread->iFlags=flags^modified; |
|
731 |
} |
|
732 |
||
733 |
TExitType ExecHandler::ThreadExitType(DThread* aThread) |
|
734 |
// |
|
735 |
// Return the exit type. |
|
736 |
// |
|
737 |
{ |
|
738 |
||
739 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadExitType")); |
|
740 |
return (TExitType)aThread->iExitType; |
|
741 |
} |
|
742 |
||
743 |
TInt ExecHandler::ThreadExitReason(DThread* aThread) |
|
744 |
// |
|
745 |
// Return the exit reason. |
|
746 |
// |
|
747 |
{ |
|
748 |
||
749 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadExitReason")); |
|
750 |
return aThread->iExitReason; |
|
751 |
} |
|
752 |
||
753 |
void ExecHandler::ThreadExitCategory(DThread* aThread, TDes8& aName) |
|
754 |
// |
|
755 |
// Return the category of the exit type. |
|
756 |
// |
|
757 |
{ |
|
758 |
||
759 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadExitCategory")); |
|
760 |
TBufC<KMaxExitCategoryName> exitCat(aThread->iExitCategory); |
|
761 |
NKern::UnlockSystem(); |
|
762 |
Kern::KUDesPut(aName,exitCat); |
|
763 |
} |
|
764 |
||
765 |
void ExecHandler::ThreadRequestSignal(DThread* aThread) |
|
766 |
// |
|
767 |
// Signal a request completion. |
|
768 |
// Enter with system locked, return with system unlocked. |
|
769 |
// |
|
770 |
{ |
|
771 |
||
772 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadRequestSignal")); |
|
773 |
if(aThread->iOwningProcess!=TheCurrentThread->iOwningProcess) |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
774 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Attempt to use RThread::RequestComplete or RThread::RequestSignal on a thread in another process")); |
0 | 775 |
NKern::ThreadRequestSignal(&aThread->iNThread, SYSTEM_LOCK); |
776 |
} |
|
777 |
||
778 |
TInt ExecHandler::FindHandleOpen(TOwnerType aType, const TFindHandle& aFindHandle) |
|
779 |
{ |
|
780 |
||
781 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::FindHandleOpen")); |
|
782 |
TFindHandle fh; |
|
783 |
kumemget32(&fh,&aFindHandle,sizeof(fh)); |
|
784 |
NKern::ThreadEnterCS(); |
|
785 |
TInt h; |
|
786 |
TInt r=TheCurrentThread->OpenFindHandle(aType,fh,h); |
|
787 |
if(r==KErrNone) |
|
788 |
r = h; |
|
789 |
NKern::ThreadLeaveCS(); |
|
790 |
if (r==KErrBadHandle) |
|
791 |
K::PanicKernExec(EBadHandle); |
|
792 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::FindHandleOpen returns %d",r)); |
|
793 |
return r; |
|
794 |
} |
|
795 |
||
796 |
TInt ExecHandler::HandleClose(TInt aHandle) |
|
797 |
{ |
|
798 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::HandleClose %08x",aHandle)); |
|
799 |
NKern::ThreadEnterCS(); |
|
800 |
TInt r=K::HandleClose(aHandle); |
|
801 |
NKern::ThreadLeaveCS(); |
|
802 |
if (r==KErrBadHandle) |
|
803 |
K::PanicKernExec(EBadHandle); |
|
804 |
else if (r==DObject::EObjectUnmapped) |
|
805 |
TheCurrentThread->iOwningProcess->WaitDllLock(); |
|
806 |
return r; |
|
807 |
} |
|
808 |
||
809 |
TInt ExecHandler::LastThreadHandle() |
|
810 |
{ |
|
811 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::LastThreadHandle")); |
|
812 |
DThread& t=*TheCurrentThread; |
|
813 |
NKern::ThreadEnterCS(); |
|
814 |
RObjectIx::Wait(); |
|
815 |
TInt r=t.iHandles.LastHandle(); |
|
816 |
RObjectIx::Signal(); |
|
817 |
NKern::ThreadLeaveCS(); |
|
818 |
if (r) |
|
819 |
r|=KHandleFlagLocal; |
|
820 |
return r; |
|
821 |
} |
|
822 |
||
823 |
TInt ExecHandler::ChunkCreate(TOwnerType aType, const TDesC8* aName, TChunkCreate& anInfo) |
|
824 |
{ |
|
825 |
TKName n; |
|
826 |
if (aName) |
|
827 |
Kern::KUDesGet(n,*aName); |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
828 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ChunkCreate %S",&n)); |
0 | 829 |
TChunkCreate uinfo; |
830 |
SChunkCreateInfo info; |
|
831 |
kumemget32(&uinfo,&anInfo,sizeof(uinfo)); |
|
832 |
info.iGlobal=uinfo.iAtt & TChunkCreate::EGlobal; |
|
833 |
info.iAtt = uinfo.iAtt&TChunkCreate::EChunkCreateAttMask; |
|
834 |
info.iForceFixed=uinfo.iForceFixed; |
|
835 |
info.iOperations=SChunkCreateInfo::EAdjust; // adjust but don't add to process |
|
836 |
info.iRunAddress=0; |
|
837 |
info.iType=(uinfo.iAtt & TChunkCreate::ECode) ? EUserSelfModCode : EUserData; |
|
838 |
info.iMaxSize=uinfo.iMaxSize; |
|
839 |
info.iInitialBottom=uinfo.iInitialBottom; |
|
840 |
info.iInitialTop=uinfo.iInitialTop; |
|
841 |
info.iPreallocated=0; |
|
842 |
info.iClearByte = uinfo.iClearByte; |
|
843 |
DThread* pT=TheCurrentThread; |
|
844 |
DProcess* pP=pT->iOwningProcess; |
|
845 |
if (aName) |
|
846 |
info.iName.Set(n); |
|
847 |
else |
|
848 |
info.iName.Set(NULL,0); |
|
849 |
if (!info.iGlobal) |
|
850 |
info.iOwner=(aType==EOwnerThread)?(DObject*)pT:(DObject*)pP; |
|
851 |
else |
|
852 |
info.iOwner=NULL; |
|
853 |
NKern::ThreadEnterCS(); |
|
854 |
DChunk* pC=NULL; |
|
855 |
TLinAddr addr; |
|
856 |
TInt r=pP->NewChunk(pC,info,addr); |
|
857 |
if (r==KErrNone) |
|
858 |
r=K::MakeHandle(aType,pC); // this will add the chunk to the process |
|
859 |
if (r<KErrNone && pC) |
|
860 |
pC->Close(NULL); // can't have been added so NULL |
|
861 |
NKern::ThreadLeaveCS(); |
|
862 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Exec::ChunkCreate returns %d",r)); |
|
863 |
return r; |
|
864 |
} |
|
865 |
||
866 |
TInt ExecHandler::ChunkSetRestrictions(DChunk* aChunk, TUint aRestrictions) |
|
867 |
{ |
|
868 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ChunkSetRestrictions %O flags=%x",aChunk,aRestrictions)); |
|
869 |
if(aChunk->iControllingOwner!=TheCurrentThread->iOwningProcess->iId) |
|
870 |
return KErrAccessDenied; |
|
871 |
aChunk->iRestrictions = aRestrictions; |
|
872 |
return KErrNone; |
|
873 |
} |
|
874 |
||
875 |
TInt ExecHandler::ChunkAdjust(DChunk* aChunk, TInt aType, TInt a1, TInt a2) |
|
876 |
{ |
|
877 |
__KTRACE_OPT(KPROC,Kern::Printf("Exec::ChunkAdjust %O type %d a1=%x a2=%x",aChunk,aType,a1,a2)); |
|
878 |
aChunk->CheckedOpen(); |
|
879 |
NKern::ThreadEnterCS(); |
|
880 |
NKern::UnlockSystem(); |
|
881 |
TInt r=KErrNone; |
|
882 |
TInt s=aChunk->CheckAccess(); |
|
883 |
if (s!=KErrNone) |
|
884 |
goto done; |
|
885 |
if((aChunk->iRestrictions&EChunkPreventAdjust) && (aChunk->iControllingOwner!=TheCurrentThread->iOwningProcess->iId)) |
|
886 |
{ |
|
887 |
r=KErrAccessDenied; |
|
888 |
goto done; |
|
889 |
} |
|
890 |
switch (aType) |
|
891 |
{ |
|
892 |
case EChunkAdjust: |
|
893 |
r=aChunk->Adjust(a1); |
|
894 |
break; |
|
895 |
case EChunkAdjustDoubleEnded: |
|
896 |
r=aChunk->AdjustDoubleEnded(a1,a2); |
|
897 |
break; |
|
898 |
case EChunkCommit: |
|
899 |
r=aChunk->Commit(a1,a2); |
|
900 |
break; |
|
901 |
case EChunkDecommit: |
|
902 |
r=aChunk->Decommit(a1,a2); |
|
903 |
break; |
|
904 |
case EChunkAllocate: |
|
905 |
r=aChunk->Allocate(a1); |
|
906 |
break; |
|
907 |
case EChunkLock: |
|
908 |
if(&Kern::CurrentProcess()!=aChunk->iOwningProcess) |
|
909 |
r = KErrAccessDenied; |
|
910 |
else |
|
911 |
r=aChunk->Lock(a1,a2); |
|
912 |
break; |
|
913 |
case EChunkUnlock: |
|
914 |
if(&Kern::CurrentProcess()!=aChunk->iOwningProcess) |
|
915 |
r = KErrAccessDenied; |
|
916 |
else |
|
917 |
r=aChunk->Unlock(a1,a2); |
|
918 |
break; |
|
919 |
default: |
|
920 |
r=KErrArgument; |
|
921 |
break; |
|
922 |
} |
|
923 |
done: |
|
924 |
aChunk->Close(NULL); // NULL because we didn't up the process access count |
|
925 |
NKern::ThreadLeaveCS(); |
|
926 |
if (s!=KErrNone) |
|
927 |
K::PanicKernExec(EAccessDenied); |
|
928 |
__KTRACE_OPT(KPROC,Kern::Printf("Exec::ChunkAdjust returns %d",r)); |
|
929 |
return r; |
|
930 |
} |
|
931 |
||
932 |
||
933 |
/** |
|
934 |
@return ETrue if the chunk is data paged, EFalse otherwise. |
|
935 |
*/ |
|
936 |
TBool ExecHandler::ChunkIsPaged(DChunk* aChunk) |
|
937 |
{ |
|
938 |
return (aChunk->iAttributes & DChunk::EDataPaged) != 0; |
|
939 |
} |
|
940 |
||
941 |
||
942 |
/** |
|
943 |
@return ETrue if the process is data paged, EFalse otherwise. |
|
944 |
*/ |
|
945 |
TBool ExecHandler::ProcessDefaultDataPaged(DProcess* aProcess) |
|
946 |
{ |
|
947 |
return (aProcess->iAttributes & DProcess::EDataPaged) != 0; |
|
948 |
} |
|
949 |
||
950 |
||
951 |
||
952 |
TInt ExecHandler::OpenObject(TObjectType aObjType, const TDesC8& aName, TOwnerType aType) |
|
953 |
{ |
|
954 |
TFullName n; |
|
955 |
Kern::KUDesGet(n,aName); |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
956 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Exec::OpenObject %S",&n)); |
0 | 957 |
if (Kern::ValidateFullName(n)!=KErrNone) |
958 |
K::PanicKernExec(EBadName); |
|
959 |
if ((TUint)aObjType>=(TUint)ENumObjectTypes) |
|
960 |
K::PanicKernExec(EBadObjectType); |
|
961 |
TInt h=0; |
|
962 |
DObject* pO=NULL; |
|
963 |
NKern::ThreadEnterCS(); |
|
964 |
TInt r=TheCurrentThread->OpenObject(aType,n,h,pO,aObjType); |
|
965 |
NKern::ThreadLeaveCS(); |
|
966 |
if(r==KErrNone) |
|
967 |
r = h; |
|
968 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Exec::OpenObject returns %d",r)); |
|
969 |
return r; |
|
970 |
} |
|
971 |
||
972 |
||
973 |
TInt ExecHandler::HandleDuplicate(TInt aThreadHandle, TOwnerType aType, TInt& aHandle) |
|
974 |
{ |
|
975 |
TInt h; |
|
976 |
kumemget32(&h, &aHandle, sizeof(h)); |
|
977 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Exec::HandleDuplicate %08x", h)); |
|
978 |
DThread* pC=TheCurrentThread; |
|
979 |
NKern::LockSystem(); |
|
980 |
DThread* pT=(DThread*)K::ThreadEnterCS(aThreadHandle,EThread); |
|
981 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Exec::HandleDuplicate source thread %O",pT)); |
|
982 |
TInt r=KErrBadHandle; |
|
983 |
NKern::LockSystem(); |
|
984 |
DObject* pO=pT->ObjectFromHandle(h); |
|
985 |
h = 0; // now holds value to be returned |
|
986 |
if (pO) |
|
987 |
r=pO->Open(); |
|
988 |
NKern::UnlockSystem(); |
|
989 |
if (r==KErrNone) |
|
990 |
{ |
|
991 |
if (pO->Protection()!=DObject::EGlobal |
|
992 |
&& pT->iOwningProcess->iSecurityZone!=pC->iOwningProcess->iSecurityZone) |
|
993 |
{ |
|
994 |
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__ |
|
995 |
r = PlatSec::ProcessIsolationFail(__PLATSEC_DIAGNOSTIC_STRING("Checked by RHandleBase::Duplicate")); |
|
996 |
#else //__REMOVE_PLATSEC_DIAGNOSTICS__ |
|
997 |
r = PlatSec::EmitDiagnostic(); |
|
998 |
#endif // !__REMOVE_PLATSEC_DIAGNOSTICS__ |
|
999 |
} |
|
1000 |
if (r==KErrNone) |
|
1001 |
r = pC->MakeHandle(aType, pO, h); // this will add to process if necessary |
|
1002 |
if (r<KErrNone) |
|
1003 |
pO->Close(NULL); // can't have been added to process so NULL |
|
1004 |
} |
|
1005 |
pT->Close(NULL); |
|
1006 |
TInt s = KErrNone; |
|
1007 |
XTRAP(s, XT_DEFAULT, kumemput32(&aHandle, &h, sizeof(h))); |
|
1008 |
if (s!=KErrNone && r==KErrNone) |
|
1009 |
pC->HandleClose(h); |
|
1010 |
NKern::ThreadLeaveCS(); |
|
1011 |
if (r == KErrBadHandle) |
|
1012 |
K::PanicKernExec(EBadHandle); |
|
1013 |
if (s != KErrNone) |
|
1014 |
K::PanicKernExec(ECausedException); |
|
1015 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Exec::HandleDuplicate returns %d",r)); |
|
1016 |
return r; |
|
1017 |
} |
|
1018 |
||
1019 |
TInt ExecHandler::MutexCreate(const TDesC8* aName, TOwnerType aType) |
|
1020 |
{ |
|
1021 |
TKName n; |
|
1022 |
DObject* pO=NULL; |
|
1023 |
const TDesC* pN=NULL; |
|
1024 |
if (aName) |
|
1025 |
{ |
|
1026 |
Kern::KUDesGet(n,*aName); |
|
1027 |
pN=&n; |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1028 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Exec::MutexCreate %S",pN)); |
0 | 1029 |
} |
1030 |
else if (aType==EOwnerThread) |
|
1031 |
pO=TheCurrentThread; |
|
1032 |
else |
|
1033 |
pO=TheCurrentThread->iOwningProcess; |
|
1034 |
NKern::ThreadEnterCS(); |
|
1035 |
DMutex* pM; |
|
1036 |
TInt r=K::MutexCreate(pM, *pN, pO, ETrue, KMutexOrdUser); |
|
1037 |
if (r==KErrNone) |
|
1038 |
{ |
|
1039 |
if(aName) |
|
1040 |
pM->SetProtection(n.Length()? DObject::EGlobal : DObject::EProtected); |
|
1041 |
r=K::MakeHandle(aType,pM); |
|
1042 |
if (r<KErrNone) |
|
1043 |
pM->Close(NULL); |
|
1044 |
} |
|
1045 |
NKern::ThreadLeaveCS(); |
|
1046 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Exec::MutexCreate returns %d",r)); |
|
1047 |
return r; |
|
1048 |
} |
|
1049 |
||
1050 |
TInt ExecHandler::SemaphoreCreate(const TDesC8* aName, TInt aCount, TOwnerType aType) |
|
1051 |
{ |
|
1052 |
TKName n; |
|
1053 |
DObject* pO=NULL; |
|
1054 |
const TDesC* pN=NULL; |
|
1055 |
if (aName) |
|
1056 |
{ |
|
1057 |
Kern::KUDesGet(n,*aName); |
|
1058 |
pN=&n; |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1059 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Exec::SemaphoreCreate %S",pN)); |
0 | 1060 |
} |
1061 |
else if (aType==EOwnerThread) |
|
1062 |
pO=TheCurrentThread; |
|
1063 |
else |
|
1064 |
pO=TheCurrentThread->iOwningProcess; |
|
1065 |
NKern::ThreadEnterCS(); |
|
1066 |
TInt r=KErrNoMemory; |
|
1067 |
DSemaphore* pS=new DSemaphore; |
|
1068 |
if (pS) |
|
1069 |
r=pS->Create(pO,pN,aCount); |
|
1070 |
if (r==KErrNone) |
|
1071 |
{ |
|
1072 |
if(aName) |
|
1073 |
pS->SetProtection(n.Length()? DObject::EGlobal : DObject::EProtected); |
|
1074 |
r=K::MakeHandle(aType,pS); |
|
1075 |
} |
|
1076 |
if (r<KErrNone && pS) |
|
1077 |
pS->Close(NULL); |
|
1078 |
NKern::ThreadLeaveCS(); |
|
1079 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Exec::SemaphoreCreate returns %d",r)); |
|
1080 |
return r; |
|
1081 |
} |
|
1082 |
||
1083 |
LOCAL_C TInt OpenById(TUint anId, TOwnerType aType, TBool aProcess) |
|
1084 |
{ |
|
1085 |
NKern::ThreadEnterCS(); |
|
1086 |
TInt type=aProcess?EProcess:EThread; |
|
1087 |
DObjectCon* pC=K::Containers[type]; |
|
1088 |
pC->Wait(); |
|
1089 |
DObject* pO=aProcess?(DObject*)Kern::ProcessFromId(anId):(DObject*)Kern::ThreadFromId(anId); |
|
1090 |
TInt r=KErrNotFound; |
|
1091 |
if (pO && (r=pO->Open())==KErrNone) |
|
1092 |
{ |
|
1093 |
pC->Signal(); // must release this before opening handle |
|
1094 |
DProcess* pP; |
|
1095 |
if(aProcess) |
|
1096 |
pP=(DProcess*)pO; |
|
1097 |
else |
|
1098 |
pP=((DThread*)pO)->iOwningProcess; |
|
1099 |
||
1100 |
if( pO->Protection()!=DObject::EGlobal |
|
1101 |
&& pP->iSecurityZone!=TheCurrentThread->iOwningProcess->iSecurityZone) |
|
1102 |
{ |
|
1103 |
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__ |
|
1104 |
r = PlatSec::ProcessIsolationFail(__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::Open(TThreadId)")); |
|
1105 |
#else //__REMOVE_PLATSEC_DIAGNOSTICS__ |
|
1106 |
r = PlatSec::EmitDiagnostic(); |
|
1107 |
#endif // !__REMOVE_PLATSEC_DIAGNOSTICS__ |
|
1108 |
} |
|
1109 |
if (r==KErrNone) |
|
1110 |
r=K::MakeHandle(aType,pO); |
|
1111 |
if (r<KErrNone) |
|
1112 |
pO->Close(NULL); |
|
1113 |
} |
|
1114 |
else |
|
1115 |
pC->Signal(); |
|
1116 |
NKern::ThreadLeaveCS(); |
|
1117 |
return r; |
|
1118 |
} |
|
1119 |
||
1120 |
TInt ExecHandler::ThreadOpenById(TUint anId, TOwnerType aType) |
|
1121 |
{ |
|
1122 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Exec::ThreadOpenById %d",anId)); |
|
1123 |
TInt r=OpenById(anId,aType,EFalse); |
|
1124 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Exec::ThreadOpenById returns %d",r)); |
|
1125 |
return r; |
|
1126 |
} |
|
1127 |
||
1128 |
TInt ExecHandler::ProcessOpenById(TUint anId, TOwnerType aType) |
|
1129 |
{ |
|
1130 |
__KTRACE_OPT(KPROC,Kern::Printf("Exec::ProcessOpenById %d",anId)); |
|
1131 |
TInt r=OpenById(anId,aType,ETrue); |
|
1132 |
__KTRACE_OPT(KPROC,Kern::Printf("Exec::ProcessOpenById returns %d",r)); |
|
1133 |
return r; |
|
1134 |
} |
|
1135 |
||
1136 |
// Enter with system locked, return with system unlocked |
|
1137 |
void ExecHandler::ThreadLogon(DThread* aThread, TRequestStatus* aStatus, TBool aRendezvous) |
|
1138 |
{ |
|
1139 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadLogon")); |
|
1140 |
aThread->CheckedOpen(); |
|
1141 |
NKern::ThreadEnterCS(); |
|
1142 |
NKern::UnlockSystem(); |
|
1143 |
TInt r=aThread->Logon(aStatus,aRendezvous); |
|
1144 |
if (r!=KErrNone) |
|
1145 |
{ |
|
1146 |
if (r==KErrDied) |
|
1147 |
r=aThread->iExitReason; |
|
1148 |
Kern::RequestComplete(aStatus,r); |
|
1149 |
} |
|
1150 |
aThread->Close(NULL); |
|
1151 |
NKern::ThreadLeaveCS(); |
|
1152 |
} |
|
1153 |
||
1154 |
// Enter with system locked, return with system unlocked |
|
1155 |
TInt ExecHandler::ThreadLogonCancel(DThread* aThread, TRequestStatus* aStatus, TBool aRendezvous) |
|
1156 |
{ |
|
1157 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadLogonCancel")); |
|
1158 |
aThread->CheckedOpen(); |
|
1159 |
NKern::ThreadEnterCS(); |
|
1160 |
NKern::UnlockSystem(); |
|
1161 |
DThread& t = *TheCurrentThread; |
|
1162 |
TUint32 type = TLogon::ETargetThread; |
|
1163 |
if (aRendezvous) |
|
1164 |
type |= TLogon::ERendezvous; |
|
1165 |
TInt r = TLogon::Cancel(t.iOwnedLogons, aThread, aStatus, type); |
|
1166 |
aThread->Close(NULL); |
|
1167 |
NKern::ThreadLeaveCS(); |
|
1168 |
return r; |
|
1169 |
} |
|
1170 |
||
1171 |
// Enter with system locked, return with system unlocked |
|
1172 |
void ExecHandler::ProcessLogon(DProcess* aProcess, TRequestStatus* aStatus, TBool aRendezvous) |
|
1173 |
{ |
|
1174 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessLogon")); |
|
1175 |
aProcess->CheckedOpen(); |
|
1176 |
NKern::ThreadEnterCS(); |
|
1177 |
NKern::UnlockSystem(); |
|
1178 |
TInt r=aProcess->Logon(aStatus,aRendezvous); |
|
1179 |
if (r!=KErrNone) |
|
1180 |
{ |
|
1181 |
if (r==KErrDied) |
|
1182 |
r=aProcess->iExitReason; |
|
1183 |
Kern::RequestComplete(aStatus,r); |
|
1184 |
} |
|
1185 |
aProcess->Close(NULL); |
|
1186 |
NKern::ThreadLeaveCS(); |
|
1187 |
} |
|
1188 |
||
1189 |
// Enter with system locked, return with system unlocked |
|
1190 |
TInt ExecHandler::ProcessLogonCancel(DProcess* aProcess, TRequestStatus* aStatus, TBool aRendezvous) |
|
1191 |
{ |
|
1192 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessLogonCancel")); |
|
1193 |
aProcess->CheckedOpen(); |
|
1194 |
NKern::ThreadEnterCS(); |
|
1195 |
NKern::UnlockSystem(); |
|
1196 |
DThread& t = *TheCurrentThread; |
|
1197 |
TUint32 type = TLogon::ETargetProcess; |
|
1198 |
if (aRendezvous) |
|
1199 |
type |= TLogon::ERendezvous; |
|
1200 |
TInt r = TLogon::Cancel(t.iOwnedLogons, aProcess, aStatus, type); |
|
1201 |
aProcess->Close(NULL); |
|
1202 |
NKern::ThreadLeaveCS(); |
|
1203 |
return r; |
|
1204 |
} |
|
1205 |
||
1206 |
TAny* ExecHandler::DllTls(TInt aHandle, TInt aDllUid) |
|
1207 |
{ |
|
1208 |
// no protection needed since only this thread can access the TLS array |
|
1209 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::DllTls")); |
|
1210 |
#ifndef __EPOC32__ |
|
1211 |
extern TInt LookupDllUid(TInt); |
|
1212 |
||
1213 |
if (aDllUid == KDllUid_Special) |
|
1214 |
aDllUid = LookupDllUid(aHandle); |
|
1215 |
#endif |
|
1216 |
return TheCurrentThread->Tls(aHandle,aDllUid); |
|
1217 |
} |
|
1218 |
||
1219 |
TInt ExecHandler::DllSetTls(TInt aHandle, TInt aDllUid, TAny* aPtr) |
|
1220 |
{ |
|
1221 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::DllSetTls %08x->%08x", aHandle, aPtr)); |
|
1222 |
#ifndef __EPOC32__ |
|
1223 |
extern TInt LookupDllUid(TInt); |
|
1224 |
||
1225 |
if (aDllUid == KDllUid_Special) |
|
1226 |
aDllUid = LookupDllUid(aHandle); |
|
1227 |
#endif |
|
1228 |
NKern::ThreadEnterCS(); |
|
1229 |
TInt r=TheCurrentThread->SetTls(aHandle,aDllUid,aPtr); |
|
1230 |
NKern::ThreadLeaveCS(); |
|
1231 |
return r; |
|
1232 |
} |
|
1233 |
||
1234 |
void ExecHandler::DllFreeTls(TInt aHandle) |
|
1235 |
{ |
|
1236 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::DllFreeTls")); |
|
1237 |
NKern::ThreadEnterCS(); |
|
1238 |
TheCurrentThread->FreeTls(aHandle); |
|
1239 |
NKern::ThreadLeaveCS(); |
|
1240 |
} |
|
1241 |
||
1242 |
TInt ExecHandler::ThreadRename(TInt aHandle, const TDesC8& aName) |
|
1243 |
{ |
|
1244 |
TKName n; |
|
1245 |
Kern::KUDesGet(n,aName); |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1246 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadRename %S",&n)); |
0 | 1247 |
NKern::LockSystem(); |
1248 |
DThread* pT=(DThread*)K::ThreadEnterCS(aHandle,EThread); |
|
1249 |
if (pT!=TheCurrentThread && |
|
1250 |
pT->iOwningProcess->iSecurityZone!=TheCurrentThread->iOwningProcess->iSecurityZone) |
|
1251 |
{ |
|
1252 |
if(TheSuperPage().KernelConfigFlags() & EKernelConfigPlatSecEnforcement) |
|
1253 |
{ |
|
1254 |
pT->Close(NULL); |
|
1255 |
K::ThreadLeaveCS(); |
|
1256 |
} |
|
1257 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::Rename")); |
|
1258 |
if(TheSuperPage().KernelConfigFlags() & EKernelConfigPlatSecEnforcement) |
|
1259 |
Kern::Fault("ThreadRename",0); |
|
1260 |
} |
|
1261 |
TInt r=pT->Rename(n); |
|
1262 |
pT->Close(NULL); |
|
1263 |
NKern::ThreadLeaveCS(); |
|
1264 |
return r; |
|
1265 |
} |
|
1266 |
||
1267 |
TInt ExecHandler::ProcessRename(TInt aHandle, const TDesC8& aName) |
|
1268 |
{ |
|
1269 |
TKName n; |
|
1270 |
Kern::KUDesGet(n,aName); |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1271 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessRename %S",&n)); |
0 | 1272 |
NKern::LockSystem(); |
1273 |
DProcess* pP=(DProcess*)K::ThreadEnterCS(aHandle,EProcess); |
|
1274 |
if (pP->iSecurityZone!=TheCurrentThread->iOwningProcess->iSecurityZone) |
|
1275 |
{ |
|
1276 |
if(TheSuperPage().KernelConfigFlags() & EKernelConfigPlatSecEnforcement) |
|
1277 |
{ |
|
1278 |
pP->Close(NULL); |
|
1279 |
K::ThreadLeaveCS(); |
|
1280 |
} |
|
1281 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RProcess::Rename")); |
|
1282 |
if(TheSuperPage().KernelConfigFlags() & EKernelConfigPlatSecEnforcement) |
|
1283 |
Kern::Fault("ProcessRename",0); |
|
1284 |
} |
|
1285 |
TInt r=pP->Rename(n); |
|
1286 |
pP->Close(NULL); |
|
1287 |
NKern::ThreadLeaveCS(); |
|
1288 |
return r; |
|
1289 |
} |
|
1290 |
||
1291 |
TInt ExecHandler::ThreadProcess(DThread* aThread) |
|
1292 |
{ |
|
1293 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadProcess")); |
|
1294 |
DProcess* pP=aThread->iOwningProcess; |
|
1295 |
pP->Open(); // can't get an error here |
|
1296 |
NKern::ThreadEnterCS(); |
|
1297 |
NKern::UnlockSystem(); |
|
1298 |
TInt r=K::MakeHandle(EOwnerThread,pP); |
|
1299 |
if (r<KErrNone) |
|
1300 |
pP->Close(NULL); |
|
1301 |
NKern::ThreadLeaveCS(); |
|
1302 |
return r; |
|
1303 |
} |
|
1304 |
||
1305 |
RAllocator* ExecHandler::ThreadGetHeap(DThread* aThread) |
|
1306 |
{ |
|
1307 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadGetHeap %O",aThread)); |
|
1308 |
if (aThread->iOwningProcess->iSecurityZone!=TheCurrentThread->iOwningProcess->iSecurityZone) |
|
1309 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::Heap")); |
|
1310 |
return aThread->iAllocator; |
|
1311 |
} |
|
1312 |
||
1313 |
void ExecHandler::HandleName(TInt aHandle, TDes8& aName) |
|
1314 |
{ |
|
1315 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::HandleName")); |
|
1316 |
DObject* pO=NULL; |
|
1317 |
TInt r=K::OpenObjectFromHandle(aHandle,pO); |
|
1318 |
if (r!=KErrNone) |
|
1319 |
K::PanicKernExec(EBadHandle); |
|
1320 |
TKName n; |
|
1321 |
pO->Name(n); |
|
1322 |
pO->Close(NULL); |
|
1323 |
NKern::ThreadLeaveCS(); |
|
1324 |
Kern::KUDesPut(aName,n); |
|
1325 |
} |
|
1326 |
||
1327 |
void ExecHandler::HandleFullName(TInt aHandle, TDes8& aFullName) |
|
1328 |
{ |
|
1329 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::HandleFullName")); |
|
1330 |
DObject* pO=NULL; |
|
1331 |
TInt r=K::OpenObjectFromHandle(aHandle,pO); |
|
1332 |
if (r!=KErrNone) |
|
1333 |
K::PanicKernExec(EBadHandle); |
|
1334 |
TFullName n; |
|
1335 |
pO->FullName(n); |
|
1336 |
pO->Close(NULL); |
|
1337 |
NKern::ThreadLeaveCS(); |
|
1338 |
Kern::KUDesPut(aFullName,n); |
|
1339 |
} |
|
1340 |
||
1341 |
void ExecHandler::HandleCount(DThread* aThread, TInt& aProcessHandleCount, TInt& aThreadHandleCount) |
|
1342 |
{ |
|
1343 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::HandleCount")); |
|
1344 |
TInt tCount=aThread->iHandles.ActiveCount(); |
|
1345 |
TInt pCount=aThread->iOwningProcess->iHandles.ActiveCount(); |
|
1346 |
NKern::UnlockSystem(); |
|
1347 |
kumemput32(&aProcessHandleCount,&pCount,sizeof(pCount)); |
|
1348 |
kumemput32(&aThreadHandleCount,&tCount,sizeof(tCount)); |
|
1349 |
} |
|
1350 |
||
1351 |
TInt ExecHandler::GetBTraceId(DObject* aObj) |
|
1352 |
// |
|
1353 |
// Get the BTraceID of any given RHandleBase-derived object. In practice |
|
1354 |
// this ID is simply a pointer to the associated DObject. |
|
1355 |
// |
|
1356 |
{ |
|
1357 |
return (TInt)aObj; |
|
1358 |
} |
|
1359 |
||
1360 |
void ExecHandler::HandleInfo(TInt aHandle, THandleInfo* anInfo) |
|
1361 |
// |
|
1362 |
// Find out how many threads and processes have an open handle on the object given by |
|
1363 |
// a handle, and whether it's open in this process and thread. |
|
1364 |
// |
|
1365 |
{ |
|
1366 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::HandleInfo")); |
|
1367 |
THandleInfo hinfo; |
|
1368 |
memclr(&hinfo, sizeof(hinfo)); |
|
1369 |
DObject* pO=NULL; |
|
1370 |
TInt r=K::OpenObjectFromHandle(aHandle,pO); |
|
1371 |
if (r==KErrNone) |
|
1372 |
{ |
|
1373 |
RObjectIx::Wait(); |
|
1374 |
DProcess* pCurrentProcess=TheCurrentThread->iOwningProcess; |
|
1375 |
hinfo.iNumOpenInThread=TheCurrentThread->iHandles.Count(pO); |
|
1376 |
hinfo.iNumOpenInProcess=pCurrentProcess->iHandles.Count(pO); |
|
1377 |
||
1378 |
DObjectCon& threads=*K::Containers[EThread]; |
|
1379 |
threads.Wait(); |
|
1380 |
TInt c=threads.Count(); |
|
1381 |
TInt i=0; |
|
1382 |
for (;i<c;i++) |
|
1383 |
{ |
|
1384 |
DThread *pT=(DThread *)threads[i]; |
|
1385 |
TInt r=pT->iHandles.At(pO); |
|
1386 |
if (r!=KErrNotFound) |
|
1387 |
{ |
|
1388 |
++hinfo.iNumThreads; |
|
1389 |
if (pT->iOwningProcess==pCurrentProcess) |
|
1390 |
++hinfo.iNumOpenInProcess; |
|
1391 |
} |
|
1392 |
} |
|
1393 |
threads.Signal(); |
|
1394 |
DObjectCon& processes=*K::Containers[EProcess]; |
|
1395 |
processes.Wait(); |
|
1396 |
c=processes.Count(); |
|
1397 |
for (i=0;i<c;i++) |
|
1398 |
{ |
|
1399 |
DProcess *pP=(DProcess *)processes[i]; |
|
1400 |
TInt r=pP->iHandles.At(pO); |
|
1401 |
if (r!=KErrNotFound) |
|
1402 |
++hinfo.iNumProcesses; |
|
1403 |
} |
|
1404 |
processes.Signal(); |
|
1405 |
RObjectIx::Signal(); |
|
1406 |
pO->Close(NULL); |
|
1407 |
NKern::ThreadLeaveCS(); |
|
1408 |
} |
|
1409 |
kumemput32(anInfo,&hinfo,sizeof(hinfo)); |
|
1410 |
} |
|
1411 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1412 |
TUint ExecHandler::HandleAttributes(TInt aHandle) |
0 | 1413 |
{ |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1414 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::HandleAttributes")); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1415 |
TUint attributes = RHandleBase::EReadAccess | RHandleBase::EDirectReadAccess; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1416 |
NKern::LockSystem(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1417 |
DObject* pO = K::ObjectFromHandle(aHandle); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1418 |
if (pO->UniqueID() - 1 == EChunk) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1419 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1420 |
DChunk* pChunk = (DChunk*) pO; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1421 |
if (!(pChunk->iAttributes & DChunk::EReadOnly) || |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1422 |
(TheCurrentThread->iOwningProcess->iId == pChunk->iControllingOwner)) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1423 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1424 |
attributes |= (RHandleBase::EWriteAccess | RHandleBase::EDirectWriteAccess); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1425 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1426 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1427 |
else |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1428 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1429 |
attributes |= (RHandleBase::EWriteAccess | RHandleBase::EDirectWriteAccess); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1430 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1431 |
NKern::UnlockSystem(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1432 |
return attributes; |
0 | 1433 |
} |
1434 |
||
1435 |
TLibraryFunction ExecHandler::LibraryLookup(TInt aLibraryHandle, TInt aOrdinal) |
|
1436 |
{ |
|
1437 |
TLibraryFunction f = NULL; |
|
1438 |
NKern::LockSystem(); |
|
1439 |
||
1440 |
XTRAP_PAGING_RETRY( |
|
1441 |
DLibrary* library = (DLibrary*)K::ObjectFromHandle(aLibraryHandle,ELibrary); |
|
1442 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::LibraryLookup %O %d",library,aOrdinal)); |
|
1443 |
DCodeSeg* pS = library->iCodeSeg; |
|
1444 |
if(pS) |
|
1445 |
f = pS->Lookup(aOrdinal); |
|
1446 |
) |
|
1447 |
NKern::UnlockSystem(); |
|
1448 |
return f; |
|
1449 |
} |
|
1450 |
||
1451 |
/** |
|
1452 |
Retrieves pointer to the named symbol export data, if present. |
|
1453 |
||
1454 |
@param aProcessHandle Handle to the process whose code seg to search |
|
1455 |
@return Pointer to named symbol export data if its present, NULL otherwise |
|
1456 |
@internalComponent |
|
1457 |
*/ |
|
1458 |
TAny* ExecHandler::ProcessExeExportData(void) |
|
1459 |
{ |
|
1460 |
DProcess* pP = &Kern::CurrentProcess(); |
|
1461 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessExeExportData %O",pP)); |
|
1462 |
DCodeSeg* pS = pP->CodeSeg(); // can't be null if process is running |
|
1463 |
||
1464 |
// Lookup() returns NULL if this is not a stdexe/stddll |
|
1465 |
return (TAny*)pS->Lookup(0); |
|
1466 |
} |
|
1467 |
||
1468 |
void ExecHandler::LibraryType(DLibrary* aLibrary, TUidType& aUids) |
|
1469 |
{ |
|
1470 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::LibraryType")); |
|
1471 |
TUidType uids; |
|
1472 |
memclr(&uids, sizeof(uids)); |
|
1473 |
DCodeSeg* pS=aLibrary->iCodeSeg; |
|
1474 |
if (pS) |
|
1475 |
uids=pS->iUids; |
|
1476 |
__KTRACE_OPT(KEXEC,Kern::Printf("UIDS: %08x,%08x,%08x",uids.iUid[0],uids.iUid[1],uids.iUid[2])); |
|
1477 |
NKern::UnlockSystem(); |
|
1478 |
kumemput32(&aUids,&uids,sizeof(TUidType)); |
|
1479 |
} |
|
1480 |
||
1481 |
void ExecHandler::LibraryFileName(DLibrary* aLibrary, TDes8& aFileName) |
|
1482 |
{ |
|
1483 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::LibraryFileName")); |
|
1484 |
TFileName fn; |
|
1485 |
DCodeSeg* pS=aLibrary->iCodeSeg; |
|
1486 |
if (pS) |
|
1487 |
pS->AppendFullFileName(fn); |
|
1488 |
NKern::UnlockSystem(); |
|
1489 |
P::NormalizeExecutableFileName(fn); |
|
1490 |
Kern::KUDesPut(aFileName, fn); |
|
1491 |
} |
|
1492 |
||
1493 |
TInt ExecHandler::HalFunction(TInt aGroup, TInt aFunction, TAny* a1, TAny* a2) |
|
1494 |
{ |
|
1495 |
TInt aDeviceNumber = TUint(aGroup)>>16; |
|
1496 |
aGroup=aGroup&0xffff; |
|
1497 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::HalFunction(%d,%d,%08x,%08x,%d)",aGroup,aFunction,a1,a2,aDeviceNumber)); |
|
1498 |
TInt r=KErrNotSupported; |
|
1499 |
if(TUint(aDeviceNumber)>=TUint(KMaxHalEntries)) |
|
1500 |
return r; |
|
1501 |
if (aGroup>=0 && aGroup<KMaxHalGroups) |
|
1502 |
{ |
|
1503 |
SHalEntry2* pE=&K::HalEntryArray[aGroup]; |
|
1504 |
SHalEntry* pBase=(SHalEntry*)pE; |
|
1505 |
THalFunc f=NULL; |
|
1506 |
TAny* p=NULL; |
|
1507 |
if(aDeviceNumber>0) |
|
1508 |
{ |
|
1509 |
if(!pE->iExtendedEntries) |
|
1510 |
return r; |
|
1511 |
pBase=pE->iExtendedEntries + (aDeviceNumber-1); |
|
1512 |
} |
|
1513 |
NKern::LockSystem(); |
|
1514 |
f=pBase->iFunction; |
|
1515 |
p=pBase->iPtr; |
|
1516 |
NKern::UnlockSystem(); |
|
1517 |
if (f) |
|
1518 |
r=(*f)(p,aFunction,a1,a2); |
|
1519 |
} |
|
1520 |
return r; |
|
1521 |
} |
|
1522 |
||
1523 |
TUint32 ExecHandler::DebugMask() |
|
1524 |
{ |
|
1525 |
return TheSuperPage().iDebugMask[0]; |
|
1526 |
} |
|
1527 |
||
1528 |
TUint32 ExecHandler::DebugMaskIndex(TUint aIndex) |
|
1529 |
{ |
|
1530 |
if (aIndex >= (TUint)KNumTraceMaskWords) |
|
1531 |
return 0; |
|
1532 |
else |
|
1533 |
return TheSuperPage().iDebugMask[aIndex]; |
|
1534 |
} |
|
1535 |
||
1536 |
void ExecHandler::SetDebugMask(TUint32 aVal) |
|
1537 |
{ |
|
1538 |
TheSuperPage().iDebugMask[0]=(TInt)aVal; |
|
1539 |
} |
|
1540 |
||
1541 |
void ExecHandler::SetDebugMaskIndex(TUint32 aVal, TUint aIndex) |
|
1542 |
{ |
|
1543 |
if (aIndex >= (TUint)KNumTraceMaskWords) return; |
|
1544 |
||
1545 |
// check that we have permission to set KALLTHREADSSYSTEM bit |
|
1546 |
if (aIndex == DEBUGMASKWORD2 && (aVal & (1 << (KALLTHREADSSYSTEM%32)))) |
|
1547 |
{ |
|
1548 |
DProcess* currentProcess=TheCurrentThread->iOwningProcess; |
|
1549 |
if(!currentProcess->HasCapability(ECapabilityProtServ,__PLATSEC_DIAGNOSTIC_STRING("Checked by User::SetDebugMask(TUint32, TUint)"))) |
|
1550 |
K::UnlockedPlatformSecurityPanic(); |
|
1551 |
} |
|
1552 |
||
1553 |
TheSuperPage().iDebugMask[aIndex]=(TInt)aVal; |
|
1554 |
} |
|
1555 |
||
1556 |
RAllocator* ExecHandler::HeapSwitch(RAllocator* aA) |
|
1557 |
{ |
|
1558 |
DThread* pT = TheCurrentThread; |
|
1559 |
RAllocator* pA = pT->iAllocator; |
|
1560 |
pT->iAllocator = aA; |
|
1561 |
if (!pT->iCreatedAllocator) |
|
1562 |
pT->iCreatedAllocator = aA; |
|
1563 |
return pA; |
|
1564 |
} |
|
1565 |
||
1566 |
void ExecHandler::KernelHeapDebug(TInt aFunction, TInt a1, TAny* a2) |
|
1567 |
{ |
|
1568 |
(void)aFunction; |
|
1569 |
(void)a1; |
|
1570 |
(void)a2; |
|
1571 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::KernelHeapDebug %d,%08x,%08x",aFunction,a1,a2)); |
|
1572 |
#ifdef _DEBUG |
|
1573 |
TInt panic=KMinTInt; |
|
1574 |
switch (aFunction) |
|
1575 |
{ |
|
1576 |
case EDbgMarkStart: |
|
1577 |
NKern::ThreadEnterCS(); |
|
1578 |
K::Allocator->__DbgMarkStart(); |
|
1579 |
NKern::ThreadLeaveCS(); |
|
1580 |
break; |
|
1581 |
||
1582 |
case EDbgMarkCheck: |
|
1583 |
{ |
|
1584 |
TBuf8<KMaxFileName> name; |
|
1585 |
TKernelHeapMarkCheckInfo info; |
|
1586 |
kumemget32(&info,a2,sizeof(info)); |
|
1587 |
Kern::KUDesGet(name,*info.iFileName); |
|
1588 |
NKern::ThreadEnterCS(); |
|
1589 |
TInt r = K::Allocator->__DbgMarkCheck(info.iCountAll, a1, name, info.iLineNum); |
|
1590 |
if (r!=KErrNone) |
|
1591 |
panic=EFailedKernelHeapCheck; |
|
1592 |
NKern::ThreadLeaveCS(); |
|
1593 |
break; |
|
1594 |
} |
|
1595 |
||
1596 |
case EDbgMarkEnd: |
|
1597 |
{ |
|
1598 |
NKern::ThreadEnterCS(); |
|
1599 |
TInt r = K::Allocator->__DbgMarkEnd(a1); |
|
1600 |
if (r!=KErrNone) |
|
1601 |
panic=EFailedKernelHeapCheck; |
|
1602 |
NKern::ThreadLeaveCS(); |
|
1603 |
break; |
|
1604 |
} |
|
1605 |
||
1606 |
case EDbgSetAllocFail: |
|
1607 |
NKern::ThreadEnterCS(); |
|
1608 |
K::Allocator->__DbgSetAllocFail((RAllocator::TAllocFail)a1,(TInt)a2); |
|
1609 |
NKern::ThreadLeaveCS(); |
|
1610 |
break; |
|
1611 |
||
1612 |
case EDbgSetBurstAllocFail: |
|
1613 |
{ |
|
1614 |
SRAllocatorBurstFail burstFail; |
|
1615 |
kumemget32(&burstFail, a2, sizeof(SRAllocatorBurstFail)); |
|
1616 |
NKern::ThreadEnterCS(); |
|
1617 |
K::Allocator->__DbgSetBurstAllocFail((RAllocator::TAllocFail)a1, burstFail.iRate, burstFail.iBurst); |
|
1618 |
NKern::ThreadLeaveCS(); |
|
1619 |
break; |
|
1620 |
} |
|
1621 |
||
1622 |
case EDbgCheckFailure: |
|
1623 |
{ |
|
1624 |
NKern::ThreadEnterCS(); |
|
1625 |
TUint failures = K::Allocator->__DbgCheckFailure(); |
|
1626 |
NKern::ThreadLeaveCS(); |
|
1627 |
kumemput32(a2, (TAny*)&failures, sizeof(TUint)); |
|
1628 |
break; |
|
1629 |
} |
|
1630 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1631 |
case EDbgGetAllocFail: |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1632 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1633 |
NKern::ThreadEnterCS(); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1634 |
TInt allocFail = K::Allocator->__DbgGetAllocFail(); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1635 |
NKern::ThreadLeaveCS(); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1636 |
kumemput32(a2, (TAny*)&allocFail, sizeof(TInt)); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1637 |
break; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1638 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
1639 |
|
0 | 1640 |
default: |
1641 |
panic=EBadKernelHeapDebugFunction; |
|
1642 |
break; |
|
1643 |
} |
|
1644 |
if (panic>KMinTInt) |
|
1645 |
K::PanicKernExec(panic); |
|
1646 |
#endif |
|
1647 |
} |
|
1648 |
||
1649 |
TExceptionHandler ExecHandler::ExceptionHandler(DThread* aThread) |
|
1650 |
{ |
|
1651 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ExceptionHandler")); |
|
1652 |
if(aThread!=TheCurrentThread) |
|
1653 |
if(TheCurrentThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1654 |
|| aThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1655 |
) |
|
1656 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::ExceptionHandler")); |
|
1657 |
return aThread->iExceptionHandler; |
|
1658 |
} |
|
1659 |
||
1660 |
TInt ExecHandler::SetExceptionHandler(DThread* aThread, TExceptionHandler aHandler, TUint32 aMask) |
|
1661 |
{ |
|
1662 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::SetExceptionHandler")); |
|
1663 |
if(aThread!=TheCurrentThread) |
|
1664 |
if(TheCurrentThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1665 |
|| aThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1666 |
) |
|
1667 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::SetExceptionHandler")); |
|
1668 |
aThread->iExceptionHandler=aHandler; |
|
1669 |
aThread->iExceptionMask=aMask; |
|
1670 |
return KErrNone; |
|
1671 |
} |
|
1672 |
||
1673 |
void ExecHandler::ModifyExceptionMask(DThread* aThread, TUint32 aClearMask, TUint32 aSetMask) |
|
1674 |
{ |
|
1675 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ModifyExceptionMask")); |
|
1676 |
if(aThread!=TheCurrentThread) |
|
1677 |
if(TheCurrentThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1678 |
|| aThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1679 |
) |
|
1680 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::ModifyExceptionMask")); |
|
1681 |
TUint& m=aThread->iExceptionMask; |
|
1682 |
m=(m&~aClearMask)|aSetMask; |
|
1683 |
} |
|
1684 |
||
1685 |
TInt ExecHandler::RaiseException(DThread* aThread, TExcType aType) |
|
1686 |
{ |
|
1687 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::RaiseException %d on %O",aType,aThread)); |
|
1688 |
if(aThread!=TheCurrentThread) |
|
1689 |
if(TheCurrentThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1690 |
|| aThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1691 |
) |
|
1692 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::RaiseException")); |
|
1693 |
return aThread->RaiseException(aType); |
|
1694 |
} |
|
1695 |
||
1696 |
TBool ExecHandler::IsExceptionHandled(DThread* aThread,TExcType aType, TBool aSwExcInProgress) |
|
1697 |
{ |
|
1698 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::IsExceptionHandled %d %d",aType,aSwExcInProgress)); |
|
1699 |
if(aThread!=TheCurrentThread) |
|
1700 |
if(TheCurrentThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1701 |
|| aThread->iOwningProcess->iSecurityZone!=KSecurityZoneLegacyCode |
|
1702 |
) |
|
1703 |
K::ProcessIsolationFailure(__PLATSEC_DIAGNOSTIC_STRING("Checked by RThread::IsExceptionHandled")); |
|
1704 |
TBool isHandled=aThread->IsExceptionHandled(aType); |
|
1705 |
NKern::UnlockSystem(); |
|
1706 |
if (aSwExcInProgress) |
|
1707 |
DKernelEventHandler::Dispatch(EEventSwExc, (TAny*)aType, NULL); |
|
1708 |
return isHandled; |
|
1709 |
} |
|
1710 |
||
1711 |
void ExecHandler::ThreadContext(DThread* aThread, TDes8& aDes) |
|
1712 |
{ |
|
1713 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadContext %O",aThread)); |
|
1714 |
TBuf8<KMaxThreadContext> c; |
|
1715 |
aThread->Context(c); |
|
1716 |
NKern::UnlockSystem(); |
|
1717 |
Kern::InfoCopy(aDes,c); |
|
1718 |
} |
|
1719 |
||
1720 |
TInt ExecHandler::ThreadStackInfo(DThread* aThread, TThreadStackInfo& aInfo) |
|
1721 |
{ |
|
1722 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadStackInfo %O",aThread)); |
|
1723 |
TThreadStackInfo info; |
|
1724 |
memclr(&info, sizeof(info)); |
|
1725 |
TInt r=KErrGeneral; |
|
1726 |
if(aThread->iUserStackRunAddress) |
|
1727 |
{ |
|
1728 |
info.iBase = aThread->iUserStackRunAddress+aThread->iUserStackSize; |
|
1729 |
info.iLimit = aThread->iUserStackRunAddress; |
|
1730 |
info.iExpandLimit = aThread->iUserStackRunAddress; |
|
1731 |
r = KErrNone; |
|
1732 |
} |
|
1733 |
NKern::UnlockSystem(); |
|
1734 |
kumemput32(&aInfo,&info,sizeof(info)); |
|
1735 |
return r; |
|
1736 |
} |
|
1737 |
||
1738 |
TInt ExecHandler::ProcessGetMemoryInfo(TInt aProcessHandle, TModuleMemoryInfo& aInfo) |
|
1739 |
{ |
|
1740 |
TModuleMemoryInfo info; |
|
1741 |
memclr(&info, sizeof(info)); |
|
1742 |
TInt r = KErrGeneral; |
|
1743 |
NKern::LockSystem(); |
|
1744 |
||
1745 |
XTRAP_PAGING_RETRY( |
|
1746 |
DProcess* process = (DProcess*)K::ObjectFromHandle(aProcessHandle,EProcess); |
|
1747 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessGetMemoryInfo %O",process)); |
|
1748 |
DCodeSeg* seg=process->iCodeSeg; |
|
1749 |
if(seg) |
|
1750 |
r = seg->GetMemoryInfo(info,TheCurrentThread->iOwningProcess); |
|
1751 |
) |
|
1752 |
NKern::UnlockSystem(); |
|
1753 |
kumemput32(&aInfo, &info, sizeof(info)); |
|
1754 |
return r; |
|
1755 |
} |
|
1756 |
||
1757 |
TInt ExecHandler::LibraryGetMemoryInfo(TInt aLibraryHandle, TModuleMemoryInfo& aInfo) |
|
1758 |
{ |
|
1759 |
TModuleMemoryInfo info; |
|
1760 |
memclr(&info, sizeof(info)); |
|
1761 |
TInt r = KErrGeneral; |
|
1762 |
NKern::LockSystem(); |
|
1763 |
||
1764 |
XTRAP_PAGING_RETRY( |
|
1765 |
DLibrary* library = (DLibrary*)K::ObjectFromHandle(aLibraryHandle,ELibrary); |
|
1766 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::LibraryGetMemoryInfo %O",library)); |
|
1767 |
DCodeSeg* seg=library->iCodeSeg; |
|
1768 |
if(seg) |
|
1769 |
r = seg->GetMemoryInfo(info,TheCurrentThread->iOwningProcess); |
|
1770 |
) |
|
1771 |
NKern::UnlockSystem(); |
|
1772 |
kumemput32(&aInfo, &info, sizeof(info)); |
|
1773 |
return r; |
|
1774 |
} |
|
1775 |
||
1776 |
void AccessMachineConfig() |
|
1777 |
{ |
|
1778 |
NKern::ThreadEnterCS(); |
|
1779 |
Kern::MutexWait(*K::MachineConfigMutex); |
|
1780 |
} |
|
1781 |
||
1782 |
void EndAccessMachineConfig() |
|
1783 |
{ |
|
1784 |
Kern::MutexSignal(*K::MachineConfigMutex); |
|
1785 |
NKern::ThreadLeaveCS(); |
|
1786 |
} |
|
1787 |
||
1788 |
TInt ExecHandler::MachineConfiguration(TDes8& aConfig, TInt& aSize) |
|
1789 |
// |
|
1790 |
// Get the machine configuration |
|
1791 |
// Enter and leave with system unlocked |
|
1792 |
// |
|
1793 |
{ |
|
1794 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::MachineConfiguration")); |
|
1795 |
if(!Kern::CurrentThreadHasCapability(ECapabilityReadDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by User::MachineConfiguration"))) |
|
1796 |
K::UnlockedPlatformSecurityPanic(); |
|
1797 |
const TPtrC8 platConfig(A::MachineConfiguration()); |
|
1798 |
TInt platSize=platConfig.Length(); |
|
1799 |
TInt usize=sizeof(TUid)+sizeof(TVersion)+sizeof(platSize)+platSize; |
|
1800 |
||
1801 |
TInt ulen, umax; |
|
1802 |
Kern::KUDesInfo(aConfig,ulen,umax); |
|
1803 |
TInt r = KErrArgument; |
|
1804 |
if(umax<usize) |
|
1805 |
goto done; // user buffer not big enough |
|
1806 |
||
1807 |
// create tempory buffer for config data |
|
1808 |
{ |
|
1809 |
DThread& t=*TheCurrentThread; |
|
1810 |
NKern::ThreadEnterCS(); |
|
1811 |
TUint8* buf=(TUint8*)Kern::Alloc(usize); |
|
1812 |
t.iTempAlloc=buf; // if we are killed, buf will be deleted |
|
1813 |
NKern::ThreadLeaveCS(); |
|
1814 |
r = KErrNoMemory; |
|
1815 |
if (!buf) |
|
1816 |
goto done; // no memory |
|
1817 |
||
1818 |
// get config data |
|
1819 |
{ |
|
1820 |
TUint8* p=buf; |
|
1821 |
*((TUid*&)p)++ = KMachineConfigurationUid; |
|
1822 |
*((TVersion*&)p)++ = TVersion(KMachineConfigurationMajorVersionNumber,KMachineConfigurationMinorVersionNumber,KMachineConfigurationBuildVersionNumber); |
|
1823 |
*((TInt*&)p)++ = platSize; |
|
1824 |
AccessMachineConfig(); |
|
1825 |
NKern::LockSystem(); |
|
1826 |
memcpy(p,platConfig.Ptr(),platSize); |
|
1827 |
NKern::UnlockSystem(); |
|
1828 |
EndAccessMachineConfig(); |
|
1829 |
||
1830 |
Kern::KUDesPut(aConfig,TPtrC8(buf,usize)); |
|
1831 |
||
1832 |
NKern::ThreadEnterCS(); |
|
1833 |
t.iTempAlloc=NULL; |
|
1834 |
delete buf; |
|
1835 |
NKern::ThreadLeaveCS(); |
|
1836 |
||
1837 |
r = KErrNone; |
|
1838 |
} |
|
1839 |
} |
|
1840 |
done: |
|
1841 |
kumemput32(&aSize,&usize,sizeof(usize)); |
|
1842 |
return r; |
|
1843 |
} |
|
1844 |
||
1845 |
TInt ExecHandler::SetMachineConfiguration(const TDesC8& aConfig) |
|
1846 |
// |
|
1847 |
// Set the machine configuration |
|
1848 |
// Enter and leave with system unlocked |
|
1849 |
// |
|
1850 |
{ |
|
1851 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::SetMachineConfiguration")); |
|
1852 |
if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by User::SetMachineConfiguration"))) |
|
1853 |
K::UnlockedPlatformSecurityPanic(); |
|
1854 |
TInt len; |
|
1855 |
TInt maxLen; |
|
1856 |
const TUint8* pC=Kern::KUDesInfo(aConfig,len,maxLen); |
|
1857 |
TInt r=KErrNoMemory; |
|
1858 |
TUint8* pB=NULL; |
|
1859 |
TPckgBuf<TUid> uid; |
|
1860 |
TPckgBuf<TVersion> version; |
|
1861 |
TPckgBuf<TInt> platSizeBuf; |
|
1862 |
TInt platSize; |
|
1863 |
TInt i=0; |
|
1864 |
TPtrC8 platConfig; |
|
1865 |
DThread& t=*TheCurrentThread; |
|
1866 |
||
1867 |
// first allocate a kernel-side buffer big enough to hold the new configuration |
|
1868 |
NKern::ThreadEnterCS(); |
|
1869 |
pB=(TUint8*)Kern::Alloc(len); |
|
1870 |
if (!pB) |
|
1871 |
goto endSetMachineConfig2; |
|
1872 |
t.iTempAlloc=pB; // if we are killed, pB will be deleted |
|
1873 |
NKern::ThreadLeaveCS(); |
|
1874 |
||
1875 |
// copy the configuration |
|
1876 |
kumemget(pB,pC,len); |
|
1877 |
r=KErrArgument; |
|
1878 |
if (len<(TInt)(sizeof(TUid)+sizeof(TVersion)+sizeof(TInt))) |
|
1879 |
goto endSetMachineConfig; |
|
1880 |
||
1881 |
// extract and check the UID |
|
1882 |
uid.Copy(pB+i,(TInt)sizeof(TUid)); |
|
1883 |
if (uid().iUid!=KMachineConfigurationUidValue) |
|
1884 |
goto endSetMachineConfig; |
|
1885 |
i+=(TInt)sizeof(TUid); |
|
1886 |
||
1887 |
// extract and check the version |
|
1888 |
version.Copy(pB+i,(TInt)sizeof(TVersion)); |
|
1889 |
r=KErrNotSupported; |
|
1890 |
if(!Kern::QueryVersionSupported(TVersion(KMachineConfigurationMajorVersionNumber,KMachineConfigurationMinorVersionNumber,KMachineConfigurationBuildVersionNumber),version())) |
|
1891 |
goto endSetMachineConfig; |
|
1892 |
i+=(TInt)sizeof(TVersion); |
|
1893 |
||
1894 |
// extract and check the super page size |
|
1895 |
platSizeBuf.Copy(pB+i,(TInt)sizeof(TInt)); |
|
1896 |
i+=(TInt)sizeof(TInt); |
|
1897 |
platSize=platSizeBuf(); |
|
1898 |
r=KErrArgument; |
|
1899 |
if (platSize>(len-i)) |
|
1900 |
goto endSetMachineConfig; |
|
1901 |
||
1902 |
platConfig.Set(pB+i,platSize); |
|
1903 |
||
1904 |
// restore the super page config |
|
1905 |
AccessMachineConfig(); |
|
1906 |
K::SetMachineConfiguration(platConfig); |
|
1907 |
r=KErrNone; |
|
1908 |
EndAccessMachineConfig(); |
|
1909 |
||
1910 |
endSetMachineConfig: |
|
1911 |
NKern::ThreadEnterCS(); |
|
1912 |
t.iTempAlloc=NULL; |
|
1913 |
delete pB; |
|
1914 |
endSetMachineConfig2: |
|
1915 |
NKern::ThreadLeaveCS(); |
|
1916 |
return r; |
|
1917 |
} |
|
1918 |
||
1919 |
TInt ExecHandler::ThreadCreate(const TDesC8& aName, TOwnerType aType, SThreadCreateInfo& aInfo) |
|
1920 |
{ |
|
1921 |
TKName n; |
|
1922 |
Kern::KUDesGet(n,aName); |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1923 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadCreate %S",&n)); |
0 | 1924 |
TUint32 infoBuf[KMaxThreadCreateInfo/sizeof(TUint32)]; |
1925 |
SThreadCreateInfo& info = *(SThreadCreateInfo*)infoBuf; |
|
1926 |
kumemget32(&info, &aInfo, sizeof(SThreadCreateInfo)); |
|
1927 |
TInt r = ( (info.iTotalSize < (TInt)sizeof(SThreadCreateInfo)) || (info.iTotalSize > KMaxThreadCreateInfo) || (info.iTotalSize & 7) ) |
|
1928 |
? KErrArgument : KErrNone; |
|
1929 |
if (info.iUserStackSize < KMaxThreadCreateInfo*2) |
|
1930 |
r=KErrArgument; |
|
1931 |
if (r==KErrNone) |
|
1932 |
{ |
|
1933 |
if (info.iTotalSize > (TInt)sizeof(SThreadCreateInfo)) |
|
1934 |
kumemget32( (&info)+1, (&aInfo)+1, info.iTotalSize-(TInt)sizeof(SThreadCreateInfo) ); |
|
1935 |
info.iType=EThreadUser; |
|
1936 |
info.iSupervisorStackSize=0; // zero means use default value |
|
1937 |
info.iSupervisorStack=NULL; |
|
1938 |
info.iInitialThreadPriority=EThrdPriorityNormal; |
|
1939 |
info.iName.Set(n); |
|
1940 |
NKern::ThreadEnterCS(); |
|
1941 |
DThread* pT=NULL; |
|
1942 |
TInt h; |
|
1943 |
r=TheCurrentThread->iOwningProcess->NewThread(pT, info, &h, aType); |
|
1944 |
if(r==KErrNone) |
|
1945 |
r = h; |
|
1946 |
NKern::ThreadLeaveCS(); |
|
1947 |
} |
|
1948 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadCreate returns %d",r)); |
|
1949 |
return r; |
|
1950 |
} |
|
1951 |
||
1952 |
/******************************************** |
|
1953 |
* Kernel-side executive calls |
|
1954 |
********************************************/ |
|
1955 |
||
1956 |
TInt K::MutexCreate(DMutex*& aMutex, const TDesC& aName, DObject* anOwner, TBool aVisible, TUint aOrder) |
|
1957 |
{ |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1958 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("K::MutexCreate %S owner %O visible=%d order=%02x",&aName,anOwner,aVisible,aOrder)); |
0 | 1959 |
DMutex* pM=new DMutex; |
1960 |
TInt r=KErrNoMemory; |
|
1961 |
if (pM) |
|
1962 |
{ |
|
1963 |
r=pM->Create(anOwner, &aName, aVisible, aOrder); |
|
1964 |
if (r==KErrNone) |
|
1965 |
aMutex=pM; |
|
1966 |
else |
|
1967 |
pM->Close(NULL); |
|
1968 |
} |
|
1969 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("K::MutexCreate returns %d %08x",r,pM)); |
|
1970 |
return r; |
|
1971 |
} |
|
1972 |
||
1973 |
/** Creates a new thread. |
|
1974 |
||
1975 |
It receives a parameter of type SThreadCreateInfo. The members of this structure have the following meaning for this function: |
|
1976 |
||
1977 |
iHandle [out] Heap allocated DThread pointer to the new created thread. |
|
1978 |
This member is valid only if the return code is KErrNone. |
|
1979 |
Do not assume it's NULL if the operation failed. |
|
1980 |
iType [in] Specifies if the thread will run in User mode or in Kernel mode. |
|
1981 |
It can be one of: |
|
1982 |
EThreadInitial - this is the initial thread |
|
1983 |
EThreadSupervisor - this runs in supervisor mode |
|
1984 |
EThreadMinimalSupervisor - this runs in supervisor mode and has no handles array |
|
1985 |
EThreadUser - this runs in User Mode |
|
1986 |
EThreadAPInitial - this is the initial thread on a non-boot processor (SMP only) |
|
1987 |
iFunction [in] This is the function that will be run in the new thread. |
|
1988 |
iPtr [in] Extra custom parameters passed to iFunction when it starts running. |
|
1989 |
iSupervisorStack Ignored. |
|
1990 |
iSupervisorStackSize [in] If the thread is a Kernel thread, this parameter will specify the desired supervisor stack size. |
|
1991 |
If the size is 0, the size will be specified by K::SupervisorThreadStackSize, which is 4K. |
|
1992 |
The size will be rounded up to Page or Block size. |
|
1993 |
iUserStack Ignored. |
|
1994 |
iUserStackSize [in] If the thread is a User Mode thread, this parameter will specify the desired user stack size. |
|
1995 |
The size will be rounded up to Page or Block size. |
|
1996 |
It will fail with KErrTooBig if the size is greater than PP::MaxUserThreadStack which is usually set to 0x14000 (80K). |
|
1997 |
iInitialThreadPriority [in] Initial priority for this thread. Must be in [0,63] interval. |
|
1998 |
iName [in] Name of the thread. In case you do not specify a name for this thread, it will be created EProtected |
|
1999 |
and any attempts to open it will fail with KErrPermissionDenied. Otherwise, the object will be EGlobal. |
|
2000 |
iTotalSize [in] Total size in bytes of the SThreadCreateInfo, including the extras. Fails with KErrArgument if it's less than sizeof(SThreadCreateInfo) or greater than KMaxThreadCreateInfo. |
|
2001 |
||
2002 |
It can fail with KErrArgument if aInfo.iTotalSize is not set correctly or aInfo.iPriority is not in [0,63] interval |
|
2003 |
In x86 port it can fail with KErrArgument if anInfo.iStackBase is NULL or anInfo.iStackSize is less than 0x100 |
|
2004 |
It can fail with KErrTooBig if aInfo.iUserStackSize is bigger than maximum user stack size |
|
2005 |
It can fail in Emulator with a Win32 error code returned by GetLastError if the Win32 thread or the scheduler Win32 event cannot be created |
|
2006 |
It can fail with KErrDied if the thread dies during the creation process |
|
2007 |
It can fail with KErrNoMemory in OOM scenarios. |
|
2008 |
It can fail with KErrGeneral indicating a general malfunction or data corruption. |
|
2009 |
||
2010 |
If it succeeds it will return the heap allocated DThread pointer to the new created thread in iHandle member of aInfo |
|
2011 |
||
2012 |
@param aInfo Information passed by the caller to specify how to create the thread. |
|
2013 |
||
2014 |
@pre Calling thread must be in a critical section. |
|
2015 |
@pre Call in a thread context. |
|
2016 |
@pre Kernel must be unlocked. |
|
2017 |
@pre interrupts enabled |
|
2018 |
@pre No fast mutex can be held |
|
2019 |
||
2020 |
@post Calling thread is in a critical section. |
|
2021 |
*/ |
|
2022 |
EXPORT_C TInt Kern::ThreadCreate(SThreadCreateInfo& aInfo) |
|
2023 |
{ |
|
2024 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ThreadCreate"); |
|
152
657f875b013e
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
2025 |
__KTRACE_OPT(KEXEC,Kern::Printf("Kern::ThreadCreate %S",&aInfo.iName)); |
0 | 2026 |
aInfo.iHandle=NULL; |
2027 |
DThread* pT=NULL; |
|
2028 |
TBool svc = aInfo.iType!=EThreadUser; |
|
2029 |
DProcess* pP = svc ? K::TheKernelProcess : TheCurrentThread->iOwningProcess; |
|
2030 |
aInfo.iSupervisorStack = NULL; |
|
2031 |
aInfo.iUserStack = NULL; |
|
2032 |
TInt r = pP->NewThread(pT, aInfo, NULL, EOwnerProcess); |
|
2033 |
if (r==KErrNone) |
|
2034 |
aInfo.iHandle = pT; |
|
2035 |
__KTRACE_OPT(KEXEC,Kern::Printf("Kern::ThreadCreate returns %d",r)); |
|
2036 |
return r; |
|
2037 |
} |
|
2038 |
||
2039 |
#ifdef _UNICODE |
|
2040 |
void ccopy (TUint16* aDest, const TAny* aSrc) |
|
2041 |
{ |
|
2042 |
TUint16* pSrc = (TUint16*)aSrc; |
|
2043 |
if(aSrc) { |
|
2044 |
TUint16* p = aDest + 1; |
|
2045 |
for (;*pSrc;) |
|
2046 |
*p++ = *pSrc++; |
|
2047 |
*aDest = (TUint16)(p-aDest-1); |
|
2048 |
} |
|
2049 |
else |
|
2050 |
*aDest = 0; |
|
2051 |
} |
|
2052 |
#else |
|
2053 |
void ccopy (TUint8* aDest, const TAny* aSrc) |
|
2054 |
{ |
|
2055 |
TUint8* pSrc = (TUint8*)aSrc; |
|
2056 |
if(aSrc) { |
|
2057 |
TUint8* p = aDest + 1; |
|
2058 |
for (;*pSrc;) |
|
2059 |
*p++ = *pSrc++; |
|
2060 |
*aDest = (TUint8)(p-aDest-1); |
|
2061 |
} |
|
2062 |
else |
|
2063 |
*aDest = 0; |
|
2064 |
} |
|
2065 |
#endif |
|
2066 |
||
2067 |
TInt ExecHandler::GetModuleNameFromAddress(TAny* aPtr, TDes8& aModuleName) |
|
2068 |
{ |
|
2069 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::GetModuleNameFromAddress 0x%X", aPtr)); |
|
2070 |
TFileName fn; |
|
2071 |
Kern::AccessCode(); |
|
2072 |
DCodeSeg* pSeg = Kern::CodeSegFromAddress( (TLinAddr)aPtr, TheCurrentThread->iOwningProcess ); |
|
2073 |
if (pSeg) |
|
2074 |
pSeg->AppendFullFileName(fn); |
|
2075 |
Kern::EndAccessCode(); |
|
2076 |
if (!pSeg) |
|
2077 |
{ |
|
2078 |
return KErrNotFound; |
|
2079 |
} |
|
2080 |
Kern::KUDesPut(aModuleName, fn); |
|
2081 |
return KErrNone; |
|
2082 |
} |
|
2083 |
||
2084 |
TInt ExecHandler::LocaleExports(TAny* aHandle, TLibraryFunction* aExportList) |
|
2085 |
// |
|
2086 |
// Change Locale setups |
|
2087 |
// |
|
2088 |
// NOTES |
|
2089 |
// |
|
2090 |
// 1. A mutex is NOT used to protect this, so if it is called by more than one thread |
|
2091 |
// simultaneousely, the locale info may be garbled. |
|
2092 |
// 2. Locale libraries are never closed once they have been used. This prevents them from |
|
2093 |
// being unloaded whilst other threads are referencing the data contained in them. |
|
2094 |
// 3. This function doesn't duplicate the EKA1 behaviour of saving the default data for |
|
2095 |
// restoring later. |
|
2096 |
// |
|
2097 |
// The current use case for this function is that it is called once by WSERV after boot, |
|
2098 |
// so the above points should never be a problem. ( A generic 'change locale' will cause |
|
2099 |
// all sorts of problems throught the OS, so current practice won't change before a |
|
2100 |
// comprehensive rearchitecture occurs anyway.) |
|
2101 |
// |
|
2102 |
{ |
|
2103 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::LocaleExports")); |
|
2104 |
||
2105 |
DCodeSeg& cs=*DCodeSeg::VerifyCallerAndHandle(aHandle); |
|
2106 |
||
2107 |
if(cs.iUids.iUid[1].iUid != KLocaleDllUid.iUid) |
|
2108 |
return KErrNotSupported; |
|
2109 |
||
2110 |
// Increment the code segment's access count |
|
2111 |
// This will increment every time the same locale is reloaded, but |
|
2112 |
// this doesn't matter since we don't unload locale DLLs. |
|
2113 |
NKern::ThreadEnterCS(); |
|
2114 |
DCodeSeg::Wait(); |
|
2115 |
cs.CheckedOpen(); |
|
2116 |
DCodeSeg::Signal(); |
|
2117 |
NKern::ThreadLeaveCS(); |
|
2118 |
||
2119 |
TLibraryFunction data[KNumLocaleExports]; |
|
2120 |
TInt n; |
|
2121 |
for(n=0; n<KNumLocaleExports; n++) |
|
2122 |
data[n] = (TLibraryFunction)cs.Lookup(n); |
|
2123 |
||
2124 |
kumemput32(aExportList, &data[0], KNumLocaleExports * sizeof(TLibraryFunction)); |
|
2125 |
||
2126 |
return KErrNone; |
|
2127 |
} |
|
2128 |
||
2129 |
TInt ExecHandler::ResetMachine(TMachineStartupType /*aType*/) |
|
2130 |
{ |
|
2131 |
// Don't implement without considering Platform Security! |
|
2132 |
return KErrNotSupported; |
|
2133 |
} |
|
2134 |
||
2135 |
TInt ExecHandler::ExecuteInSupervisorMode(TSupervisorFunction aFunction, TAny* aParameter) |
|
2136 |
// |
|
2137 |
// Execute a function in supervisor mode. Only available to F32 - panic anyone else |
|
2138 |
// |
|
2139 |
{ |
|
2140 |
#ifndef __MEMMODEL_FLEXIBLE__ |
|
2141 |
if (TheCurrentThread->iOwningProcess == K::TheFileServerProcess) |
|
2142 |
{ |
|
2143 |
UNLOCK_USER_MEMORY(); |
|
2144 |
TInt r = A::CallSupervisorFunction(aFunction,aParameter); |
|
2145 |
LOCK_USER_MEMORY(); |
|
2146 |
return r; |
|
2147 |
} |
|
2148 |
#endif |
|
2149 |
K::PanicKernExec(EAccessDenied); |
|
2150 |
return 0; |
|
2151 |
} |
|
2152 |
||
2153 |
_LIT(KDriveZed, "Z:"); |
|
2154 |
void ExecHandler::DllFileName(TInt aHandle, TDes8& aFileName) |
|
2155 |
{ |
|
2156 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::DllFileName %08x",aHandle)); |
|
2157 |
TFileName n; |
|
2158 |
Kern::AccessCode(); |
|
2159 |
DCodeSeg* pS=DCodeSeg::CodeSegFromEntryPoint(aHandle); |
|
2160 |
if (pS) |
|
2161 |
pS->AppendFullFileName(n); |
|
2162 |
else |
|
2163 |
n=KDriveZed; |
|
2164 |
Kern::EndAccessCode(); |
|
2165 |
if (pS) |
|
2166 |
P::NormalizeExecutableFileName(n); |
|
2167 |
Kern::KUDesPut(aFileName,n); |
|
2168 |
} |
|
2169 |
||
2170 |
#ifdef MONITOR_THREAD_CPU_TIME |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2171 |
TInt ExecHandler::ThreadGetCpuTime(TInt aThreadHandle, Int64& aTime) |
0 | 2172 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2173 |
TUint64 t = 0; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2174 |
if (aThreadHandle == KCurrentThreadHandle) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2175 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2176 |
t = NKern::ThreadCpuTime(NKern::CurrentThread()); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2177 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2178 |
else |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2179 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2180 |
NKern::LockSystem(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2181 |
DThread* pT = (DThread*)K::ObjectFromHandle(aThreadHandle, EThread); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2182 |
t = NKern::ThreadCpuTime(&pT->iNThread); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2183 |
NKern::UnlockSystem(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2184 |
} |
0 | 2185 |
TUint32 f = NKern::CpuTimeMeasFreq(); |
2186 |
TUint64 t2 = t>>32; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2187 |
t = (t & KMaxTUint32)*1000000; |
0 | 2188 |
t2 *= 1000000; |
2189 |
t2 += (t>>32); |
|
2190 |
t &= TUint64(KMaxTUint32); |
|
2191 |
TUint64 q2 = t2/f; |
|
2192 |
t2 -= q2*f; |
|
2193 |
t += (t2<<32); |
|
2194 |
TUint64 q = t/f; |
|
2195 |
q += (q2<<32); |
|
2196 |
kumemput32(&aTime, &q, sizeof(TInt64)); |
|
2197 |
return KErrNone; |
|
2198 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2199 |
#else |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
2200 |
TInt ExecHandler::ThreadGetCpuTime(TInt /*aThreadHandle*/, Int64& /*aTime*/) |
0 | 2201 |
{ |
2202 |
return KErrNotSupported; |
|
2203 |
} |
|
2204 |
#endif |
|
2205 |
||
2206 |
TInt ExecHandler::SetMemoryThresholds(TInt aLowThreshold, TInt aGoodThreshold) |
|
2207 |
{ |
|
2208 |
if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by UserSvr::SetMemoryThresholds"))) |
|
2209 |
K::LockedPlatformSecurityPanic(); |
|
2210 |
if (aLowThreshold<0 || aGoodThreshold<aLowThreshold) |
|
2211 |
return KErrArgument; |
|
2212 |
K::MemoryLowThreshold=aLowThreshold; |
|
2213 |
K::MemoryGoodThreshold=aGoodThreshold; |
|
2214 |
return KErrNone; |
|
2215 |
} |
|
2216 |
||
2217 |
void ExecHandler::FsRegisterThread() |
|
2218 |
// |
|
2219 |
// Register the file server thread |
|
2220 |
// |
|
2221 |
{ |
|
2222 |
||
2223 |
__KTRACE_OPT(KBOOT,Kern::Printf("File server thread registered")); |
|
2224 |
DThread* pT = TheCurrentThread; |
|
2225 |
DProcess* pP = pT->iOwningProcess; |
|
2226 |
pP->iFlags |= (KThreadFlagProcessCritical | KProcessFlagSystemPermanent); |
|
2227 |
pT->iFlags |= KThreadFlagSystemPermanent; |
|
2228 |
if (K::TheFileServerProcess && K::TheFileServerProcess!=pP) |
|
2229 |
K::PanicCurrentThread(EAccessDenied); |
|
2230 |
K::TheFileServerProcess=pP; |
|
2231 |
K::ThreadEnterCS(); |
|
2232 |
pP->SetPriority(EPriorityFileServer); |
|
2233 |
M::FsRegisterThread(); |
|
2234 |
K::ThreadLeaveCS(); |
|
2235 |
} |
|
2236 |
||
2237 |
||
2238 |
void ExecHandler::RegisterTrustedChunk(DChunk* aChunk) |
|
2239 |
// |
|
2240 |
// Register file server's chunk intended for DMA transfer |
|
2241 |
// |
|
2242 |
{ |
|
2243 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::RegisterTrustedChunk %x",aChunk)); |
|
2244 |
||
2245 |
DProcess* pP=TheCurrentThread->iOwningProcess; |
|
2246 |
if (K::TheFileServerProcess && K::TheFileServerProcess!=pP) |
|
2247 |
{ |
|
2248 |
K::PanicCurrentThread(EAccessDenied); |
|
2249 |
} |
|
2250 |
aChunk->iAttributes |= DChunk::ETrustedChunk; |
|
2251 |
} |
|
2252 |
||
2253 |
void ExecHandler::WsRegisterThread() |
|
2254 |
// |
|
2255 |
// Register the window server thread |
|
2256 |
// |
|
2257 |
{ |
|
2258 |
||
2259 |
__KTRACE_OPT(KBOOT,Kern::Printf("Window server thread registered")); |
|
2260 |
DProcess* pP=TheCurrentThread->iOwningProcess; |
|
2261 |
if (K::TheWindowServerProcess && K::TheWindowServerProcess!=pP) |
|
2262 |
K::PanicCurrentThread(EAccessDenied); |
|
2263 |
K::TheWindowServerProcess=pP; |
|
2264 |
K::ThreadEnterCS(); |
|
2265 |
pP->SetPriority(EPriorityWindowServer); |
|
2266 |
K::ThreadLeaveCS(); |
|
2267 |
} |
|
2268 |
||
2269 |
void ExecHandler::RequestSignal(TInt aCount) |
|
2270 |
// |
|
2271 |
// Signal the request semaphore. |
|
2272 |
// |
|
2273 |
{ |
|
2274 |
||
2275 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::RequestSignal %d",aCount)); |
|
2276 |
NKern::ThreadRequestSignal(NULL,aCount); |
|
2277 |
} |
|
2278 |
||
2279 |
TInt ExecHandler::ThreadRequestCount(DThread* aThread) |
|
2280 |
// |
|
2281 |
// Get the request semaphores count. |
|
2282 |
// |
|
2283 |
{ |
|
2284 |
||
2285 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ThreadRequestCount")); |
|
2286 |
return aThread->iNThread.iRequestSemaphore.iCount; |
|
2287 |
} |
|
2288 |
||
2289 |
void CompleteUserAfter(TAny* aPtr) |
|
2290 |
{ |
|
2291 |
DThread* pT=DThread::FromTimer(aPtr); |
|
2292 |
if (pT->iTimer.iState==TTimer::EWaiting) |
|
2293 |
{ |
|
2294 |
Kern::QueueRequestComplete(pT,pT->iTimer.iRequest,KErrNone); |
|
2295 |
pT->iTimer.iState=TTimer::EIdle; |
|
2296 |
} |
|
2297 |
} |
|
2298 |
||
2299 |
void CompleteUserAt(TAny* aPtr) |
|
2300 |
{ |
|
2301 |
DThread* pT=DThread::FromTimer(aPtr); |
|
2302 |
if (pT->iTimer.iState==TTimer::EWaiting) |
|
2303 |
{ |
|
2304 |
Kern::QueueRequestComplete(pT,pT->iTimer.iRequest,KErrNone); |
|
2305 |
pT->iTimer.iState=TTimer::EIdle; |
|
2306 |
} |
|
2307 |
} |
|
2308 |
||
2309 |
void CompleteUserAfterHighRes(TAny* aPtr) |
|
2310 |
{ |
|
2311 |
DThread* pT=DThread::FromTimer(aPtr); |
|
2312 |
NKern::LockSystem(); |
|
2313 |
pT->iTimer.iState=TTimer::EIdle; |
|
2314 |
Kern::QueueRequestComplete(pT,pT->iTimer.iRequest,KErrNone); |
|
2315 |
NKern::UnlockSystem(); |
|
2316 |
} |
|
2317 |
||
2318 |
void ExecHandler::After(TInt anInterval, TRequestStatus& aStatus) |
|
2319 |
{ |
|
2320 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::After %d",anInterval)); |
|
2321 |
TInt iv=anInterval; |
|
2322 |
if (iv<=0) |
|
2323 |
{ |
|
2324 |
// just rotate the ready queue for this thread |
|
2325 |
NKern::RotateReadyList(-1); |
|
2326 |
TRequestStatus* s=&aStatus; |
|
2327 |
Kern::RequestComplete(s,KErrNone); |
|
2328 |
return; |
|
2329 |
} |
|
2330 |
NKern::ThreadEnterCS(); |
|
2331 |
TInt r=TheCurrentThread->iTimer.After(iv,CompleteUserAfter,aStatus); |
|
2332 |
NKern::ThreadLeaveCS(); |
|
2333 |
if (r==KErrInUse) |
|
2334 |
K::PanicKernExec(ETimerAlreadyPending); |
|
2335 |
else if (r!=KErrNone) |
|
2336 |
{ |
|
2337 |
TRequestStatus* s=&aStatus; |
|
2338 |
Kern::RequestComplete(s,r); |
|
2339 |
} |
|
2340 |
} |
|
2341 |
||
2342 |
void ExecHandler::AfterHighRes(TInt anInterval, TRequestStatus& aStatus) |
|
2343 |
{ |
|
2344 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::AfterHighRes %d",anInterval)); |
|
2345 |
TInt r=TheCurrentThread->iTimer.AfterHighRes(anInterval,CompleteUserAfterHighRes,aStatus); |
|
2346 |
if (r==KErrInUse) |
|
2347 |
K::PanicCurrentThread(ETimerAlreadyPending); |
|
2348 |
} |
|
2349 |
||
2350 |
void ExecHandler::At(const TTimeK& aTime, TRequestStatus& aStatus) |
|
2351 |
{ |
|
2352 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::At")); |
|
2353 |
TTimeK time; |
|
2354 |
kumemget32(&time,&aTime,sizeof(time)); |
|
2355 |
NKern::ThreadEnterCS(); |
|
2356 |
TInt r=TheCurrentThread->iTimer.At(time,CompleteUserAt,aStatus); |
|
2357 |
NKern::ThreadLeaveCS(); |
|
2358 |
if (r==KErrInUse) |
|
2359 |
K::PanicKernExec(ETimerAlreadyPending); |
|
2360 |
else if (r!=KErrNone) |
|
2361 |
{ |
|
2362 |
TRequestStatus* s=&aStatus; |
|
2363 |
Kern::RequestComplete(s,r); |
|
2364 |
} |
|
2365 |
} |
|
2366 |
||
2367 |
#ifndef __FASTEXEC_MACHINE_CODED__ |
|
2368 |
RAllocator* ExecHandler::Heap() |
|
2369 |
{ |
|
2370 |
return TheCurrentThread->iAllocator; |
|
2371 |
} |
|
2372 |
||
2373 |
extern void InvalidFastExec(); |
|
2374 |
||
2375 |
TTrapHandler* ExecHandler::PushTrapFrame(TTrap* aFrame) |
|
2376 |
// |
|
2377 |
// Push a new trap frame. |
|
2378 |
// |
|
2379 |
{ |
|
2380 |
#ifdef __LEAVE_EQUALS_THROW__ |
|
2381 |
#ifdef __WINS__ |
|
2382 |
// On WINS overload this function to remember when a TWin32SEHTrap is installed |
|
2383 |
// over another one |
|
2384 |
DThread& t=*TheCurrentThread; |
|
2385 |
t.iFrame=aFrame; |
|
2386 |
return 0; |
|
2387 |
#else |
|
2388 |
InvalidFastExec(); |
|
2389 |
return (TTrapHandler*)aFrame; // Prevents compiler warnings |
|
2390 |
#endif |
|
2391 |
#else |
|
2392 |
DThread& t=*TheCurrentThread; |
|
2393 |
aFrame->iHandler=t.iTrapHandler; |
|
2394 |
aFrame->iNext=t.iFrame; |
|
2395 |
t.iFrame=aFrame; |
|
2396 |
return t.iTrapHandler; |
|
2397 |
#endif |
|
2398 |
} |
|
2399 |
||
2400 |
TTrap* ExecHandler::PopTrapFrame() |
|
2401 |
// |
|
2402 |
// Pop the current frame. |
|
2403 |
// |
|
2404 |
{ |
|
2405 |
#ifdef __LEAVE_EQUALS_THROW__ |
|
2406 |
#ifdef __WINS__ |
|
2407 |
// On WINS overload this function to recall when a TWin32SEHTrap is installed |
|
2408 |
// over another one |
|
2409 |
DThread& t=*TheCurrentThread; |
|
2410 |
return t.iFrame; |
|
2411 |
#else |
|
2412 |
InvalidFastExec(); |
|
2413 |
return 0; |
|
2414 |
#endif |
|
2415 |
#else |
|
2416 |
DThread& t=*TheCurrentThread; |
|
2417 |
TTrap* pF=t.iFrame; |
|
2418 |
if (pF) |
|
2419 |
t.iFrame=pF->iNext; |
|
2420 |
return pF; |
|
2421 |
#endif |
|
2422 |
} |
|
2423 |
||
2424 |
CActiveScheduler* ExecHandler::ActiveScheduler() |
|
2425 |
// |
|
2426 |
// Return the address of the current active scheduler |
|
2427 |
// |
|
2428 |
{ |
|
2429 |
DThread& t=*TheCurrentThread; |
|
2430 |
return t.iScheduler; |
|
2431 |
} |
|
2432 |
||
2433 |
void ExecHandler::SetActiveScheduler(CActiveScheduler* aScheduler) |
|
2434 |
// |
|
2435 |
// Set the address of the current active scheduler |
|
2436 |
// |
|
2437 |
{ |
|
2438 |
DThread& t=*TheCurrentThread; |
|
2439 |
t.iScheduler=aScheduler; |
|
2440 |
} |
|
2441 |
||
2442 |
TTrapHandler* ExecHandler::TrapHandler() |
|
2443 |
// |
|
2444 |
// Return the current trap handler. |
|
2445 |
// |
|
2446 |
{ |
|
2447 |
DThread& t=*TheCurrentThread; |
|
2448 |
return t.iTrapHandler; |
|
2449 |
} |
|
2450 |
||
2451 |
TTrapHandler* ExecHandler::SetTrapHandler(TTrapHandler* aHandler) |
|
2452 |
// |
|
2453 |
// Set the current trap handler. |
|
2454 |
// |
|
2455 |
{ |
|
2456 |
DThread& t=*TheCurrentThread; |
|
2457 |
TTrapHandler* pH=t.iTrapHandler; |
|
2458 |
t.iTrapHandler=aHandler; |
|
2459 |
return pH; |
|
2460 |
} |
|
2461 |
||
2462 |
void ExecHandler::SetReentryPoint(TLinAddr a) |
|
2463 |
{ |
|
2464 |
DThread& t = *TheCurrentThread; |
|
2465 |
t.iOwningProcess->iReentryPoint = a; |
|
2466 |
} |
|
2467 |
#endif |
|
2468 |
||
2469 |
#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
2470 |
void K::DoProcessIsolationFailure(const char* aContextText) |
|
2471 |
{ |
|
2472 |
// enter with system locked |
|
2473 |
if(TheSuperPage().KernelConfigFlags() & EKernelConfigPlatSecProcessIsolation) |
|
2474 |
{ |
|
2475 |
if(PlatSec::ProcessIsolationFail(aContextText)==KErrNone) |
|
2476 |
return; |
|
2477 |
LockedPlatformSecurityPanic(); |
|
2478 |
} |
|
2479 |
} |
|
2480 |
#endif // !__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
2481 |
||
2482 |
void K::DoProcessIsolationFailure() |
|
2483 |
{ |
|
2484 |
// enter with system locked |
|
2485 |
#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
2486 |
DoProcessIsolationFailure(NULL); |
|
2487 |
#else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
2488 |
if (TheSuperPage().KernelConfigFlags() & EKernelConfigPlatSecProcessIsolation) |
|
2489 |
{ |
|
2490 |
if (PlatSec::EmitDiagnostic() == KErrNone) |
|
2491 |
return; |
|
2492 |
LockedPlatformSecurityPanic(); |
|
2493 |
} |
|
2494 |
#endif // !__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
2495 |
} |
|
2496 |
||
2497 |
||
2498 |
void K::UnlockedPlatformSecurityPanic() |
|
2499 |
{ |
|
2500 |
// enter with system unlocked |
|
2501 |
NKern::LockSystem(); |
|
2502 |
K::LockedPlatformSecurityPanic(); |
|
2503 |
} |
|
2504 |
||
2505 |
void K::LockedPlatformSecurityPanic() |
|
2506 |
{ |
|
2507 |
// enter with system locked |
|
2508 |
K::PanicCurrentThread(EPlatformSecurityTrap); |
|
2509 |
} |
|
2510 |
||
2511 |
void ExecHandler::ThreadRendezvous(TInt aReason) |
|
2512 |
{ |
|
2513 |
NKern::ThreadEnterCS(); |
|
2514 |
TheCurrentThread->Rendezvous(aReason); |
|
2515 |
NKern::ThreadLeaveCS(); |
|
2516 |
} |
|
2517 |
||
2518 |
void ExecHandler::ProcessRendezvous(TInt aReason) |
|
2519 |
{ |
|
2520 |
NKern::ThreadEnterCS(); |
|
2521 |
TheCurrentThread->iOwningProcess->Rendezvous(aReason); |
|
2522 |
NKern::ThreadLeaveCS(); |
|
2523 |
} |
|
2524 |
||
2525 |
void ExecHandler::DebugPrint(TAny* aDes, TInt aMode) |
|
2526 |
{ |
|
2527 |
TInt l, m; |
|
2528 |
const TText* p = Kern::KUDesInfo(*(const TDesC*)aDes, l, m); |
|
2529 |
||
2530 |
#ifdef __DEBUGGER_SUPPORT__ |
|
2531 |
TUint r = DKernelEventHandler::Dispatch(EEventUserTrace, (TAny*)p, (TAny*)l); |
|
2532 |
if (r & DKernelEventHandler::ETraceHandled) |
|
2533 |
l = 0; |
|
2534 |
#endif |
|
2535 |
||
2536 |
TBuf8<256> buffer; |
|
2537 |
l = Min(l,256); |
|
2538 |
buffer.SetLength(l); |
|
2539 |
kumemget((TUint8*)buffer.Ptr(), p, l); //Copy user-side data into kernel memory |
|
2540 |
K::TextTrace(buffer,EUserTrace,!aMode); |
|
2541 |
} |
|
2542 |
||
2543 |
||
2544 |
TInt ExecHandler::ProcessSetHandleParameter(DProcess* aProcess, TInt aSlot, TInt aHandle) |
|
2545 |
{ |
|
2546 |
if (aProcess->iCreatorId != TheCurrentThread->iOwningProcess->iId) //check called by creator |
|
2547 |
K::LockedPlatformSecurityPanic(); |
|
2548 |
||
2549 |
if ((aSlot < 0) || (aSlot >= KArgIndex)) |
|
2550 |
K::PanicCurrentThread(EParameterSlotRange); |
|
2551 |
||
2552 |
if (aProcess->iEnvironmentData[aSlot] != 0) |
|
2553 |
K::PanicCurrentThread(EParameterSlotInUse); |
|
2554 |
||
2555 |
DObject* pObject = K::ObjectFromHandle(aHandle); |
|
2556 |
||
2557 |
if (pObject->Protection() == DObject::ELocal) |
|
2558 |
K::LockedPlatformSecurityPanic(); |
|
2559 |
pObject->CheckedOpen(); |
|
2560 |
||
2561 |
aProcess->iEnvironmentData[aSlot] = (TInt)pObject | EHandle; |
|
2562 |
return KErrNone; |
|
2563 |
} |
|
2564 |
||
2565 |
//no locks held on entry |
|
2566 |
TInt ExecHandler::ProcessSetDataParameter(TInt aProcess, TInt aSlot, const TUint8* aData, TInt aLen) |
|
2567 |
{ |
|
2568 |
||
2569 |
if ((aSlot < 0) || (aSlot >= KArgIndex)) |
|
2570 |
K::PanicKernExec(EParameterSlotRange); |
|
2571 |
||
2572 |
if (aLen < 0) |
|
2573 |
K::PanicKernExec(EParameterSlotDataLength); |
|
2574 |
||
2575 |
NKern::ThreadEnterCS(); |
|
2576 |
HBuf8* pBuf = NULL; |
|
2577 |
if (aLen) |
|
2578 |
pBuf = HBuf8::New(aLen); |
|
2579 |
||
2580 |
DThread* currentThread = TheCurrentThread; |
|
2581 |
currentThread->iTempAlloc = pBuf; |
|
2582 |
NKern::ThreadLeaveCS(); |
|
2583 |
||
2584 |
if (aLen) |
|
2585 |
{ |
|
2586 |
if (!pBuf) |
|
2587 |
return KErrNoMemory; |
|
2588 |
kumemget((void*)pBuf->Ptr(), aData, aLen); |
|
2589 |
pBuf->SetLength(aLen); |
|
2590 |
} |
|
2591 |
||
2592 |
||
2593 |
NKern::LockSystem(); |
|
2594 |
DProcess* pProc = (DProcess*)K::ObjectFromHandle(aProcess, EProcess); |
|
2595 |
||
2596 |
if (pProc->iCreatorId != currentThread->iOwningProcess->iId) //check called by creator |
|
2597 |
K::LockedPlatformSecurityPanic(); |
|
2598 |
||
2599 |
if (pProc->iEnvironmentData[aSlot] != 0) |
|
2600 |
K::PanicCurrentThread(EParameterSlotInUse); |
|
2601 |
||
2602 |
pProc->iEnvironmentData[aSlot] = (TInt)pBuf | EBinaryData; |
|
2603 |
currentThread->iTempAlloc = NULL; |
|
2604 |
NKern::UnlockSystem(); |
|
2605 |
||
2606 |
return KErrNone; |
|
2607 |
} |
|
2608 |
||
2609 |
||
2610 |
||
2611 |
//need to have sys locked on way in |
|
2612 |
TInt ExecHandler::ProcessGetHandleParameter(TInt aSlot, TObjectType aObjectType, TOwnerType aOwnerType) |
|
2613 |
{ |
|
2614 |
||
2615 |
DThread * currentThread = TheCurrentThread; |
|
2616 |
DProcess * currentProcess = currentThread->iOwningProcess; |
|
2617 |
||
2618 |
if ((aSlot < 0) || (aSlot >= KArgIndex)) |
|
2619 |
K::PanicCurrentThread(EParameterSlotRange); |
|
2620 |
||
2621 |
TInt data = currentProcess->iEnvironmentData[aSlot]; |
|
2622 |
||
2623 |
if (!data) |
|
2624 |
return KErrNotFound; |
|
2625 |
||
2626 |
TProcessParameterType type = (TProcessParameterType)(data&3); |
|
2627 |
||
2628 |
if (type != EHandle) |
|
2629 |
return KErrArgument; |
|
2630 |
||
2631 |
DObject* pObject = (DObject*)(data&~3); |
|
2632 |
||
2633 |
if ((TInt)aObjectType+1 != pObject->UniqueID()) //check it's the correct type |
|
2634 |
return KErrArgument; |
|
2635 |
||
2636 |
// zero parameter to prevent race conditions while retrieving the object |
|
2637 |
currentProcess->iEnvironmentData[aSlot]=0; |
|
2638 |
||
2639 |
NKern::ThreadEnterCS(); |
|
2640 |
NKern::UnlockSystem(); |
|
2641 |
TInt handle = 0; |
|
2642 |
||
2643 |
TInt ret = currentThread->MakeHandle(aOwnerType, pObject, handle); |
|
2644 |
||
2645 |
NKern::LockSystem(); |
|
2646 |
NKern::ThreadLeaveCS(); |
|
2647 |
||
2648 |
if (ret != KErrNone) |
|
2649 |
{ |
|
2650 |
// restore parameter data as 'nothing happened' |
|
2651 |
currentProcess->iEnvironmentData[aSlot]=data; |
|
2652 |
return ret; |
|
2653 |
} |
|
2654 |
return handle; |
|
2655 |
} |
|
2656 |
||
2657 |
||
2658 |
//enter with the system lock held, auto release on exit |
|
2659 |
TInt ExecHandler::ProcessGetDataParameter(TInt aSlot, TUint8* aData, TInt aLen) |
|
2660 |
{ |
|
2661 |
||
2662 |
DThread * currentThread = TheCurrentThread; |
|
2663 |
DProcess * currentProcess = currentThread->iOwningProcess; |
|
2664 |
||
2665 |
if ((aSlot < 0) || (aSlot >= KArgIndex)) |
|
2666 |
K::PanicCurrentThread(EParameterSlotRange); |
|
2667 |
||
2668 |
TInt data = currentProcess->iEnvironmentData[aSlot]; |
|
2669 |
if (!data) |
|
2670 |
return KErrNotFound; |
|
2671 |
||
2672 |
TProcessParameterType type = (TProcessParameterType)(data&3); |
|
2673 |
if (type != EBinaryData) |
|
2674 |
return KErrArgument; |
|
2675 |
||
2676 |
HBuf8* p = (HBuf8*)(data&~3); |
|
2677 |
if (!p) //we've passed zero length binary data so nothing to copy |
|
2678 |
return 0; |
|
2679 |
||
2680 |
if (aLen < p->Length()) |
|
2681 |
return KErrArgument; |
|
2682 |
||
2683 |
currentThread->iTempAlloc = p; |
|
2684 |
currentProcess->iEnvironmentData[aSlot] = 0; |
|
2685 |
NKern::UnlockSystem(); |
|
2686 |
||
2687 |
TInt len = p->Length(); |
|
2688 |
kumemput((void*)aData, (void*)p->Ptr(), len); |
|
2689 |
||
2690 |
NKern::ThreadEnterCS(); |
|
2691 |
currentThread->iTempAlloc = NULL; |
|
2692 |
delete p; |
|
2693 |
NKern::ThreadLeaveCS(); |
|
2694 |
||
2695 |
NKern::LockSystem(); |
|
2696 |
return len; |
|
2697 |
} |
|
2698 |
||
2699 |
TInt ExecHandler::ProcessDataParameterLength(TInt aSlot) |
|
2700 |
{ |
|
2701 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::ProcessDesParameterLength")); |
|
2702 |
||
2703 |
DProcess * currentProcess = TheCurrentThread->iOwningProcess; |
|
2704 |
||
2705 |
if ((aSlot < 0) || (aSlot >= KArgIndex)) |
|
2706 |
K::PanicCurrentThread(EParameterSlotRange); |
|
2707 |
||
2708 |
TInt data = currentProcess->iEnvironmentData[aSlot]; |
|
2709 |
||
2710 |
if (!data) |
|
2711 |
return KErrNotFound; |
|
2712 |
||
2713 |
TProcessParameterType type = (TProcessParameterType)(data&3); |
|
2714 |
||
2715 |
if (type != EBinaryData) |
|
2716 |
return KErrArgument; |
|
2717 |
||
2718 |
const HBuf8* p = (const HBuf8*)(data&~3); |
|
2719 |
||
2720 |
return p ? p->Length() : 0; |
|
2721 |
} |
|
2722 |
||
2723 |
||
2724 |
||
2725 |
void ExecHandler::NotifyChanges(TUint aChanges) |
|
2726 |
// |
|
2727 |
// Check that the caller has permission to notify the requested changes, |
|
2728 |
// and pass it on to Kern::NotifyChanges if it's ok |
|
2729 |
// |
|
2730 |
{ |
|
2731 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::NotifyChanges")); |
|
2732 |
||
2733 |
if (aChanges & ~EChangesLocale) |
|
2734 |
K::UnlockedPlatformSecurityPanic(); |
|
2735 |
||
2736 |
NKern::ThreadEnterCS(); |
|
2737 |
Kern::NotifyChanges(aChanges); |
|
2738 |
NKern::ThreadLeaveCS(); |
|
2739 |
} |
|
2740 |
||
2741 |
||
2742 |
||
2743 |
static TInt GlobalUserData[EMaxGlobalUserData] = {0}; |
|
2744 |
||
2745 |
TInt ExecHandler::GetGlobalUserData(TInt aIndex) |
|
2746 |
{ |
|
2747 |
if(TUint(aIndex)<TUint(EMaxGlobalUserData)) |
|
2748 |
return GlobalUserData[aIndex]; |
|
2749 |
return 0; |
|
2750 |
} |
|
2751 |
||
2752 |
TInt ExecHandler::SetGlobalUserData(TInt aIndex,TInt aValue) |
|
2753 |
{ |
|
2754 |
__KTRACE_OPT(KEXEC,Kern::Printf("Exec::SetGlobalUserData %d 0x%8x",aIndex,aValue)); |
|
2755 |
if(TUint(aIndex)<TUint(EMaxGlobalUserData)) |
|
2756 |
{ |
|
2757 |
if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by SetGlobalUserData"))) |
|
2758 |
return KErrPermissionDenied; |
|
2759 |
else |
|
2760 |
{ |
|
2761 |
GlobalUserData[aIndex] = aValue; |
|
2762 |
return KErrNone; |
|
2763 |
} |
|
2764 |
} |
|
2765 |
return KErrArgument; |
|
2766 |
} |
|
2767 |
||
2768 |
TBool ExecHandler::UserThreadExiting(TInt aReason) |
|
2769 |
{ |
|
2770 |
// Mark this thread as exiting and check whether there are any other threads in the process that |
|
2771 |
// are not already exiting |
|
2772 |
||
2773 |
DThread* thread = TheCurrentThread; |
|
2774 |
DProcess* process = thread->iOwningProcess; |
|
2775 |
||
2776 |
NKern::ThreadEnterCS(); |
|
2777 |
||
2778 |
// If the thread is process permanent then all other threads in the process will be killed - |
|
2779 |
// make sure this happens now, so that this thread has a chance to run global object destructors. |
|
2780 |
if (thread->iFlags & KThreadFlagProcessPermanent) |
|
2781 |
{ |
|
2782 |
__NK_ASSERT_ALWAYS(process->WaitProcessLock() == KErrNone); |
|
2783 |
NKern::LockSystem(); |
|
2784 |
process->KillAllThreads(EExitKill, aReason, KNullDesC); |
|
2785 |
NKern::UnlockSystem(); |
|
2786 |
process->SignalProcessLock(); |
|
2787 |
} |
|
2788 |
||
2789 |
TBool lastThread = EFalse; |
|
2790 |
__NK_ASSERT_DEBUG(thread->iUserThreadState >= DThread::EUserThreadRunning); |
|
2791 |
if (thread->iUserThreadState == DThread::EUserThreadRunning) |
|
2792 |
{ |
|
2793 |
thread->iUserThreadState = DThread::EUserThreadExiting; |
|
2794 |
lastThread = (__e32_atomic_tas_ord32(&process->iUserThreadsRunning, 1, -1, 0) == 1); |
|
2795 |
} |
|
2796 |
||
2797 |
NKern::ThreadLeaveCS(); |
|
2798 |
||
2799 |
return lastThread; |
|
2800 |
} |
|
2801 |
||
2802 |
||
2803 |
#include <kernel/cache.h> |
|
2804 |
||
2805 |
void ExecHandler::IMBRange(TAny* aStart, TUint aSize) |
|
2806 |
{ |
|
2807 |
UNLOCK_USER_MEMORY(); |
|
2808 |
Cache::IMB_Range((TLinAddr)aStart,aSize); |
|
2809 |
LOCK_USER_MEMORY(); |
|
2810 |
} |