sl@0
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\debug\d_context.cpp
|
sl@0
|
15 |
// Test LDD exercising hardware/software exception hooks
|
sl@0
|
16 |
// and get/set user context APIs.
|
sl@0
|
17 |
//
|
sl@0
|
18 |
//
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "platform.h"
|
sl@0
|
21 |
#include <kernel/kern_priv.h>
|
sl@0
|
22 |
#include "kern_test.h"
|
sl@0
|
23 |
#include "d_context.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
_LIT(KClientPanicCat, "D_CONTEXT");
|
sl@0
|
26 |
|
sl@0
|
27 |
extern TUint32 SpinInKernel(TBool);
|
sl@0
|
28 |
|
sl@0
|
29 |
DThread* ThreadFromId(TUint aId)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
// This is risky because the thread could die on us an the DThread* become invalid.
|
sl@0
|
32 |
// We are relying on this never happening in our test code.
|
sl@0
|
33 |
NKern::ThreadEnterCS();
|
sl@0
|
34 |
DObjectCon& threads=*Kern::Containers()[EThread];
|
sl@0
|
35 |
threads.Wait();
|
sl@0
|
36 |
DThread* thread = Kern::ThreadFromId(aId);
|
sl@0
|
37 |
threads.Signal();
|
sl@0
|
38 |
NKern::ThreadLeaveCS();
|
sl@0
|
39 |
return thread;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
void ModifyContext(TArmRegSet& aContext)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
TArmReg* end = (TArmReg*)(&aContext+1);
|
sl@0
|
45 |
for (TArmReg* p = (TArmReg*)&aContext; p<end; ++p)
|
sl@0
|
46 |
*p = ~*p;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
void DumpContext(TArmRegSet& aContext)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
Kern::Printf(" r0 =%08x r1 =%08x r2 =%08x r3 =%08x",aContext.iR0,aContext.iR1,aContext.iR2,aContext.iR3);
|
sl@0
|
52 |
Kern::Printf(" r4 =%08x r5 =%08x r6 =%08x r7 =%08x",aContext.iR4,aContext.iR5,aContext.iR6,aContext.iR7);
|
sl@0
|
53 |
Kern::Printf(" r8 =%08x r9 =%08x r10=%08x r11=%08x",aContext.iR8,aContext.iR9,aContext.iR10,aContext.iR11);
|
sl@0
|
54 |
Kern::Printf(" r12=%08x r13=%08x r14=%08x r15=%08x",aContext.iR12,aContext.iR13,aContext.iR14,aContext.iR15);
|
sl@0
|
55 |
Kern::Printf(" cpsr=%08x dacr=%08x",aContext.iFlags, aContext.iDacr);
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
inline TBool IsRegisterAvailable(TInt aReg, TUint32 aMask)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
return aMask & (1<<aReg);
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
TInt CheckSetContext(const TArmRegSet& aSetContext, const TArmRegSet& aContextAfterSet, TUint32 aAvailMask)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
Kern::Printf("Checking all available registers have been modified (0%08x)", aAvailMask);
|
sl@0
|
66 |
|
sl@0
|
67 |
const TArmReg* pSet = (const TArmReg*)&aSetContext;
|
sl@0
|
68 |
const TArmReg* pAfterSet = (const TArmReg*)&aContextAfterSet;
|
sl@0
|
69 |
|
sl@0
|
70 |
for (int i=0; i<=EArmPc; ++i)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
if (pAfterSet[i] == 0 && IsRegisterAvailable(i, aAvailMask) && pSet[i] != 0)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
Kern::Printf("Register %d not set (expected %08x actual %08x)", i, pSet[i], pAfterSet[i]);
|
sl@0
|
75 |
return KErrCorrupt;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
if (pAfterSet[i] != 0 && ! IsRegisterAvailable(i, aAvailMask))
|
sl@0
|
78 |
{
|
sl@0
|
79 |
Kern::Printf("Register %d incorrectly set (expected %08x actual %08x)", i, 0, pAfterSet[i]);
|
sl@0
|
80 |
return KErrCorrupt;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
return KErrNone;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
88 |
|
sl@0
|
89 |
class DEventHandler : public DKernelEventHandler
|
sl@0
|
90 |
{
|
sl@0
|
91 |
public:
|
sl@0
|
92 |
DEventHandler();
|
sl@0
|
93 |
TInt Create(DLogicalDevice* aDevice);
|
sl@0
|
94 |
~DEventHandler();
|
sl@0
|
95 |
void Cancel();
|
sl@0
|
96 |
private:
|
sl@0
|
97 |
static TUint EventHandler(TKernelEvent aEvent, TAny* a1, TAny* a2, TAny* aThis);
|
sl@0
|
98 |
TUint HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2);
|
sl@0
|
99 |
TBool HandleException(TRequestStatus*& aStatusPtr, TClientRequest*& aRequestPtr);
|
sl@0
|
100 |
void HandleThreadDeath();
|
sl@0
|
101 |
void Cleanup();
|
sl@0
|
102 |
private:
|
sl@0
|
103 |
DThread* iClientThread;
|
sl@0
|
104 |
DMutex* iLock; // serialise calls to handler
|
sl@0
|
105 |
public:
|
sl@0
|
106 |
DLogicalDevice* iDevice; // open reference to LDD for avoiding lifetime issues
|
sl@0
|
107 |
// software exception fields
|
sl@0
|
108 |
TExcType iSwExcLastType;
|
sl@0
|
109 |
TInt* iSwExcCounterPtr;
|
sl@0
|
110 |
TRequestStatus* iSwExcStatusPtr;
|
sl@0
|
111 |
TClientRequest* iClientRequestSwExc;
|
sl@0
|
112 |
// hardware exception fields
|
sl@0
|
113 |
TRequestStatus* iHwExcStatusPtr;
|
sl@0
|
114 |
TClientRequest* iClientRequestHwExc;
|
sl@0
|
115 |
// fields used for both hardware and software exceptions
|
sl@0
|
116 |
TUint iExcThreadId;
|
sl@0
|
117 |
TAny* iExcContextPtr;
|
sl@0
|
118 |
TBool iExcKillThread;
|
sl@0
|
119 |
// thread death event fields
|
sl@0
|
120 |
TUint iDeathThreadId;
|
sl@0
|
121 |
TRequestStatus* iDeathStatusPtr;
|
sl@0
|
122 |
TAny* iDeathContextPtr;
|
sl@0
|
123 |
TClientRequest* iClientRequestDeath;
|
sl@0
|
124 |
};
|
sl@0
|
125 |
|
sl@0
|
126 |
|
sl@0
|
127 |
DEventHandler::DEventHandler()
|
sl@0
|
128 |
: DKernelEventHandler(EventHandler, this)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
|
sl@0
|
133 |
TInt DEventHandler::Create(DLogicalDevice* aDevice)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
TInt r;
|
sl@0
|
136 |
r = aDevice->Open();
|
sl@0
|
137 |
if (r != KErrNone)
|
sl@0
|
138 |
goto error;
|
sl@0
|
139 |
iDevice = aDevice;
|
sl@0
|
140 |
iClientThread = &Kern::CurrentThread();
|
sl@0
|
141 |
r = Kern::CreateClientRequest(iClientRequestSwExc);
|
sl@0
|
142 |
if (r != KErrNone)
|
sl@0
|
143 |
goto error;
|
sl@0
|
144 |
r = Kern::CreateClientRequest(iClientRequestHwExc);
|
sl@0
|
145 |
if (r != KErrNone)
|
sl@0
|
146 |
goto error;
|
sl@0
|
147 |
r = Kern::CreateClientRequest(iClientRequestDeath);
|
sl@0
|
148 |
if (r != KErrNone)
|
sl@0
|
149 |
goto error;
|
sl@0
|
150 |
r = Kern::MutexCreate(iLock, _L("EventHandlerLock"), KMutexOrdDebug);
|
sl@0
|
151 |
if (r != KErrNone)
|
sl@0
|
152 |
goto error;
|
sl@0
|
153 |
return Add();
|
sl@0
|
154 |
error:
|
sl@0
|
155 |
Cleanup();
|
sl@0
|
156 |
return r;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
void DEventHandler::Cleanup()
|
sl@0
|
160 |
{
|
sl@0
|
161 |
if (iLock)
|
sl@0
|
162 |
iLock->Close(NULL);
|
sl@0
|
163 |
if (iDevice)
|
sl@0
|
164 |
iDevice->Close(NULL);
|
sl@0
|
165 |
if (iClientRequestSwExc)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
Kern::DestroyClientRequest(iClientRequestSwExc);
|
sl@0
|
168 |
iClientRequestSwExc = NULL;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
if (iClientRequestHwExc)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
Kern::DestroyClientRequest(iClientRequestHwExc);
|
sl@0
|
173 |
iClientRequestHwExc = NULL;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
if (iClientRequestDeath)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
Kern::DestroyClientRequest(iClientRequestDeath);
|
sl@0
|
178 |
iClientRequestDeath = NULL;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
DEventHandler::~DEventHandler()
|
sl@0
|
183 |
{
|
sl@0
|
184 |
Cleanup();
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
|
sl@0
|
188 |
void DEventHandler::Cancel()
|
sl@0
|
189 |
{
|
sl@0
|
190 |
Kern::MutexWait(*iLock);
|
sl@0
|
191 |
if (iHwExcStatusPtr)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
Kern::QueueRequestComplete(iClientThread, iClientRequestHwExc, KErrCancel);
|
sl@0
|
194 |
iHwExcStatusPtr = NULL;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
if (iSwExcStatusPtr)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
Kern::QueueRequestComplete(iClientThread, iClientRequestSwExc, KErrCancel);
|
sl@0
|
199 |
iSwExcStatusPtr = NULL;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
Kern::MutexSignal(*iLock);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
|
sl@0
|
205 |
TUint DEventHandler::EventHandler(TKernelEvent aEvent, TAny* a1, TAny* a2, TAny* aThis)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
return ((DEventHandler*)aThis)->HandleEvent(aEvent, a1, a2);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
|
sl@0
|
211 |
// called in thread CS
|
sl@0
|
212 |
TUint DEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
// Ensure handler always called in thread critical section
|
sl@0
|
215 |
NThread& nt = Kern::CurrentThread().iNThread;
|
sl@0
|
216 |
__ASSERT_ALWAYS(nt.iCsCount != 0, (NKern::Lock(),*(TInt*)0xfaece5=0));
|
sl@0
|
217 |
|
sl@0
|
218 |
TUint r = DKernelEventHandler::ERunNext;
|
sl@0
|
219 |
|
sl@0
|
220 |
switch (aType)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
case EEventSwExc:
|
sl@0
|
223 |
// HACK, EVIL UNSAFE MEMORY ACCESS FOLLOWS...
|
sl@0
|
224 |
TInt counter;
|
sl@0
|
225 |
// folowing will kill system if memory is bad (because we're in a critical section)
|
sl@0
|
226 |
umemget32(&counter, iSwExcCounterPtr, sizeof(TInt*));
|
sl@0
|
227 |
++counter;
|
sl@0
|
228 |
umemput32(iSwExcCounterPtr, &counter, sizeof(TInt));
|
sl@0
|
229 |
|
sl@0
|
230 |
Kern::MutexWait(*iLock);
|
sl@0
|
231 |
iSwExcLastType = (TExcType)(TInt)a1;
|
sl@0
|
232 |
if (iSwExcStatusPtr)
|
sl@0
|
233 |
HandleException(iSwExcStatusPtr, iClientRequestSwExc);
|
sl@0
|
234 |
Kern::MutexSignal(*iLock);
|
sl@0
|
235 |
break;
|
sl@0
|
236 |
case EEventHwExc:
|
sl@0
|
237 |
Kern::MutexWait(*iLock);
|
sl@0
|
238 |
if (iHwExcStatusPtr)
|
sl@0
|
239 |
if (HandleException(iHwExcStatusPtr, iClientRequestHwExc))
|
sl@0
|
240 |
r |= (TUint)EExcHandled;
|
sl@0
|
241 |
Kern::MutexSignal(*iLock);
|
sl@0
|
242 |
break;
|
sl@0
|
243 |
case EEventKillThread:
|
sl@0
|
244 |
Kern::MutexWait(*iLock);
|
sl@0
|
245 |
HandleThreadDeath();
|
sl@0
|
246 |
Kern::MutexSignal(*iLock);
|
sl@0
|
247 |
break;
|
sl@0
|
248 |
default:
|
sl@0
|
249 |
// NO-OP
|
sl@0
|
250 |
break;
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
return r;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
|
sl@0
|
257 |
// called in thread CS
|
sl@0
|
258 |
TBool DEventHandler::HandleException(TRequestStatus*& aStatusPtr, TClientRequest*& aRequestPtr)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
DThread& t = Kern::CurrentThread();
|
sl@0
|
261 |
TBool handled = EFalse;
|
sl@0
|
262 |
|
sl@0
|
263 |
if (iExcThreadId == t.iId)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
Kern::Printf("Trapped exception");
|
sl@0
|
266 |
TArmRegSet context1;
|
sl@0
|
267 |
TUint32 availmask;
|
sl@0
|
268 |
NKern::ThreadGetUserContext(&t.iNThread, &context1, availmask);
|
sl@0
|
269 |
XTRAPD(r, XT_DEFAULT, umemput(iExcContextPtr, &context1, sizeof(context1)));
|
sl@0
|
270 |
|
sl@0
|
271 |
if (r == KErrNone)
|
sl@0
|
272 |
{
|
sl@0
|
273 |
if (iExcKillThread)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
// We must preserve PC for software exceptions because execution
|
sl@0
|
276 |
// goes back user-side and only then is the thread panicked.
|
sl@0
|
277 |
TArmReg r15usr = context1.iR15;
|
sl@0
|
278 |
ModifyContext(context1);
|
sl@0
|
279 |
context1.iR15 = r15usr;
|
sl@0
|
280 |
NKern::ThreadSetUserContext(&t.iNThread, &context1);
|
sl@0
|
281 |
|
sl@0
|
282 |
TArmRegSet context2;
|
sl@0
|
283 |
memclr(&context2, sizeof context2);
|
sl@0
|
284 |
NKern::ThreadGetUserContext(&t.iNThread, &context2, availmask);
|
sl@0
|
285 |
r = CheckSetContext(context1, context2, availmask);
|
sl@0
|
286 |
}
|
sl@0
|
287 |
else
|
sl@0
|
288 |
{
|
sl@0
|
289 |
Kern::ThreadSuspend(t, 1);
|
sl@0
|
290 |
handled = ETrue;
|
sl@0
|
291 |
}
|
sl@0
|
292 |
}
|
sl@0
|
293 |
Kern::QueueRequestComplete(iClientThread, aRequestPtr, r);
|
sl@0
|
294 |
aStatusPtr = NULL;
|
sl@0
|
295 |
}
|
sl@0
|
296 |
return handled;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
|
sl@0
|
300 |
// called in thread CS
|
sl@0
|
301 |
void DEventHandler::HandleThreadDeath()
|
sl@0
|
302 |
{
|
sl@0
|
303 |
DThread& t = Kern::CurrentThread();
|
sl@0
|
304 |
if (iDeathStatusPtr && iDeathThreadId == t.iId)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
Kern::Printf("Trapping thread death: %O", &t);
|
sl@0
|
307 |
TArmRegSet context;
|
sl@0
|
308 |
TUint32 unused;
|
sl@0
|
309 |
NKern::ThreadGetUserContext(&t.iNThread, &context, unused);
|
sl@0
|
310 |
XTRAPD(r, XT_DEFAULT, umemput(iDeathContextPtr, &context, sizeof(context)));
|
sl@0
|
311 |
Kern::QueueRequestComplete(iClientThread, iClientRequestDeath, r);
|
sl@0
|
312 |
iDeathStatusPtr = NULL;
|
sl@0
|
313 |
}
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
317 |
|
sl@0
|
318 |
class DTestChannel : public DLogicalChannelBase
|
sl@0
|
319 |
{
|
sl@0
|
320 |
public:
|
sl@0
|
321 |
virtual ~DTestChannel();
|
sl@0
|
322 |
protected:
|
sl@0
|
323 |
// from DLogicalChannelBase
|
sl@0
|
324 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
sl@0
|
325 |
virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
|
sl@0
|
326 |
private:
|
sl@0
|
327 |
TInt SetAndGetBackContext(TUint aId, TAny* aContext);
|
sl@0
|
328 |
TInt SetAndGetFullContext(TUint aId, TAny* aContext);
|
sl@0
|
329 |
void GetContext(TUint aId, TAny* aContext);
|
sl@0
|
330 |
void GetKernelContext(TUint aId, TAny* aContext);
|
sl@0
|
331 |
void AddUserCallback(TUint aId, TUserCallbackState aCallback);
|
sl@0
|
332 |
private:
|
sl@0
|
333 |
DEventHandler* iHandler;
|
sl@0
|
334 |
};
|
sl@0
|
335 |
|
sl@0
|
336 |
|
sl@0
|
337 |
// called in thread critical section
|
sl@0
|
338 |
TInt DTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
|
sl@0
|
339 |
{
|
sl@0
|
340 |
return KErrNone;
|
sl@0
|
341 |
}
|
sl@0
|
342 |
|
sl@0
|
343 |
// called in thread critical section
|
sl@0
|
344 |
DTestChannel::~DTestChannel()
|
sl@0
|
345 |
{
|
sl@0
|
346 |
if (iHandler)
|
sl@0
|
347 |
{
|
sl@0
|
348 |
iHandler->Cancel();
|
sl@0
|
349 |
iHandler->Close();
|
sl@0
|
350 |
}
|
sl@0
|
351 |
}
|
sl@0
|
352 |
|
sl@0
|
353 |
TInt DTestChannel::Request(TInt aFunction, TAny* a1, TAny* a2)
|
sl@0
|
354 |
{
|
sl@0
|
355 |
RContextLdd::TTrapInfo info;
|
sl@0
|
356 |
DThread* pT;
|
sl@0
|
357 |
TInt r = KErrNone;
|
sl@0
|
358 |
switch (aFunction)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
case RContextLdd::EHook:
|
sl@0
|
361 |
NKern::ThreadEnterCS();
|
sl@0
|
362 |
iHandler = new DEventHandler;
|
sl@0
|
363 |
if (!iHandler)
|
sl@0
|
364 |
r = KErrNoMemory;
|
sl@0
|
365 |
else
|
sl@0
|
366 |
{
|
sl@0
|
367 |
r = iHandler->Create(iDevice);
|
sl@0
|
368 |
iHandler->iSwExcCounterPtr = (TInt*)a1;
|
sl@0
|
369 |
}
|
sl@0
|
370 |
NKern::ThreadLeaveCS();
|
sl@0
|
371 |
break;
|
sl@0
|
372 |
case RContextLdd::EGetLastExc:
|
sl@0
|
373 |
r = iHandler->iSwExcLastType;
|
sl@0
|
374 |
break;
|
sl@0
|
375 |
case RContextLdd::ETrapNextSwExc:
|
sl@0
|
376 |
case RContextLdd::ETrapNextHwExc:
|
sl@0
|
377 |
umemget(&info, a1, sizeof(info));
|
sl@0
|
378 |
if (aFunction == RContextLdd::ETrapNextHwExc)
|
sl@0
|
379 |
{
|
sl@0
|
380 |
__ASSERT_ALWAYS(iHandler->iSwExcStatusPtr==NULL, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
381 |
iHandler->iHwExcStatusPtr = info.iStatusPtr;
|
sl@0
|
382 |
r = iHandler->iClientRequestHwExc->SetStatus(iHandler->iHwExcStatusPtr);
|
sl@0
|
383 |
__ASSERT_ALWAYS(r==KErrNone, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
384 |
}
|
sl@0
|
385 |
else
|
sl@0
|
386 |
{
|
sl@0
|
387 |
__ASSERT_ALWAYS(iHandler->iHwExcStatusPtr==NULL, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
388 |
iHandler->iSwExcStatusPtr = info.iStatusPtr;
|
sl@0
|
389 |
r = iHandler->iClientRequestSwExc->SetStatus(iHandler->iSwExcStatusPtr);
|
sl@0
|
390 |
__ASSERT_ALWAYS(r==KErrNone, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
391 |
}
|
sl@0
|
392 |
iHandler->iExcThreadId = info.iThreadId;
|
sl@0
|
393 |
iHandler->iExcContextPtr = info.iContextPtr;
|
sl@0
|
394 |
iHandler->iExcKillThread = info.iKillThread;
|
sl@0
|
395 |
break;
|
sl@0
|
396 |
case RContextLdd::ETrapNextDeath:
|
sl@0
|
397 |
umemget(&info, a1, sizeof(info));
|
sl@0
|
398 |
iHandler->iDeathThreadId = info.iThreadId;
|
sl@0
|
399 |
iHandler->iDeathContextPtr = info.iContextPtr;
|
sl@0
|
400 |
iHandler->iDeathStatusPtr = info.iStatusPtr;
|
sl@0
|
401 |
r = iHandler->iClientRequestDeath->SetStatus(iHandler->iDeathStatusPtr);
|
sl@0
|
402 |
__ASSERT_ALWAYS(r==KErrNone, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
403 |
break;
|
sl@0
|
404 |
case RContextLdd::EGetContext:
|
sl@0
|
405 |
GetContext((TUint)a1, a2);
|
sl@0
|
406 |
break;
|
sl@0
|
407 |
case RContextLdd::ESetGetContext:
|
sl@0
|
408 |
r = SetAndGetBackContext((TUint)a1, a2);
|
sl@0
|
409 |
break;
|
sl@0
|
410 |
case RContextLdd::ESetGetFullContext:
|
sl@0
|
411 |
r = SetAndGetFullContext((TUint)a1, a2);
|
sl@0
|
412 |
break;
|
sl@0
|
413 |
case RContextLdd::EGetKernelContext:
|
sl@0
|
414 |
GetKernelContext((TUint)a1, a2);
|
sl@0
|
415 |
break;
|
sl@0
|
416 |
case RContextLdd::ESpinInKernel:
|
sl@0
|
417 |
r = SpinInKernel((TBool)a1);
|
sl@0
|
418 |
break;
|
sl@0
|
419 |
case RContextLdd::EAddUserCallback:
|
sl@0
|
420 |
AddUserCallback((TUint)a1, (TUserCallbackState)(TUint)a2);
|
sl@0
|
421 |
break;
|
sl@0
|
422 |
case RContextLdd::EResumeTrappedThread:
|
sl@0
|
423 |
pT = ThreadFromId((TUint)a1);
|
sl@0
|
424 |
Kern::ThreadResume(*pT);
|
sl@0
|
425 |
break;
|
sl@0
|
426 |
default:
|
sl@0
|
427 |
Kern::PanicCurrentThread(KClientPanicCat, __LINE__);
|
sl@0
|
428 |
break;
|
sl@0
|
429 |
}
|
sl@0
|
430 |
return r;
|
sl@0
|
431 |
}
|
sl@0
|
432 |
|
sl@0
|
433 |
|
sl@0
|
434 |
TInt DTestChannel::SetAndGetBackContext(TUint aId, TAny* aContext)
|
sl@0
|
435 |
{
|
sl@0
|
436 |
DThread* pT = ThreadFromId(aId);
|
sl@0
|
437 |
__ASSERT_ALWAYS(pT!=NULL, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
438 |
|
sl@0
|
439 |
// The following code assumes the inspected thread does not run between the
|
sl@0
|
440 |
// set context and get context call.
|
sl@0
|
441 |
|
sl@0
|
442 |
TArmRegSet context1;
|
sl@0
|
443 |
umemget(&context1, aContext, sizeof context1);
|
sl@0
|
444 |
NKern::ThreadSetUserContext(&pT->iNThread, &context1);
|
sl@0
|
445 |
|
sl@0
|
446 |
TArmRegSet context2;
|
sl@0
|
447 |
memclr(&context2, sizeof context2);
|
sl@0
|
448 |
TUint32 availmask;
|
sl@0
|
449 |
NKern::ThreadGetUserContext(&pT->iNThread, &context2, availmask);
|
sl@0
|
450 |
umemput(aContext, &context2, sizeof context2);
|
sl@0
|
451 |
|
sl@0
|
452 |
return CheckSetContext(context1, context2, availmask);
|
sl@0
|
453 |
}
|
sl@0
|
454 |
|
sl@0
|
455 |
#ifdef __SMP__
|
sl@0
|
456 |
class NKTest
|
sl@0
|
457 |
{
|
sl@0
|
458 |
public:
|
sl@0
|
459 |
static TBool IsDead(NThreadBase* aT)
|
sl@0
|
460 |
{ return aT->iWaitState.ThreadIsDead(); }
|
sl@0
|
461 |
};
|
sl@0
|
462 |
#endif
|
sl@0
|
463 |
|
sl@0
|
464 |
TInt DTestChannel::SetAndGetFullContext(TUint aId, TAny* aContext)
|
sl@0
|
465 |
{
|
sl@0
|
466 |
DThread* pT = ThreadFromId(aId);
|
sl@0
|
467 |
__ASSERT_ALWAYS(pT != NULL, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
468 |
TBool dead;
|
sl@0
|
469 |
#ifdef __SMP__
|
sl@0
|
470 |
dead = NKTest::IsDead(&pT->iNThread);
|
sl@0
|
471 |
#else
|
sl@0
|
472 |
dead = pT->iNThread.iSpare1 == NThreadBase::EDead;
|
sl@0
|
473 |
#endif
|
sl@0
|
474 |
__ASSERT_ALWAYS(dead, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
475 |
|
sl@0
|
476 |
TArmFullContext contextData;
|
sl@0
|
477 |
umemget(&contextData, aContext, sizeof contextData);
|
sl@0
|
478 |
NKern::ThreadSetUserContext(&pT->iNThread, &contextData.iUserContext);
|
sl@0
|
479 |
|
sl@0
|
480 |
NKern::ThreadGetUserContext(&pT->iNThread, &contextData.iUserContext, contextData.iUserAvail);
|
sl@0
|
481 |
NKern::ThreadGetSystemContext(&pT->iNThread, &contextData.iSystemContext, contextData.iSystemAvail);
|
sl@0
|
482 |
|
sl@0
|
483 |
umemput(aContext, &contextData, sizeof contextData);
|
sl@0
|
484 |
|
sl@0
|
485 |
return KErrNone;
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
void DTestChannel::GetContext(TUint aId, TAny* aContext)
|
sl@0
|
489 |
{
|
sl@0
|
490 |
DThread* pT = ThreadFromId(aId);
|
sl@0
|
491 |
__ASSERT_ALWAYS(pT!=NULL, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
492 |
|
sl@0
|
493 |
TArmRegSet context;
|
sl@0
|
494 |
memclr(&context, sizeof context);
|
sl@0
|
495 |
TUint32 unused;
|
sl@0
|
496 |
NKern::ThreadGetUserContext(&pT->iNThread, &context, unused);
|
sl@0
|
497 |
umemput(aContext, &context, sizeof context);
|
sl@0
|
498 |
}
|
sl@0
|
499 |
|
sl@0
|
500 |
void DTestChannel::GetKernelContext(TUint aId, TAny* aContext)
|
sl@0
|
501 |
{
|
sl@0
|
502 |
DThread* pT = ThreadFromId(aId);
|
sl@0
|
503 |
__ASSERT_ALWAYS(pT!=NULL, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
504 |
|
sl@0
|
505 |
TArmRegSet context;
|
sl@0
|
506 |
memclr(&context, sizeof context);
|
sl@0
|
507 |
TUint32 unused;
|
sl@0
|
508 |
NKern::ThreadGetSystemContext(&pT->iNThread, &context, unused);
|
sl@0
|
509 |
umemput(aContext, &context, sizeof context);
|
sl@0
|
510 |
}
|
sl@0
|
511 |
|
sl@0
|
512 |
void DTestChannel::AddUserCallback(TUint aId, TUserCallbackState aCallback)
|
sl@0
|
513 |
{
|
sl@0
|
514 |
DThread* pT = ThreadFromId(aId);
|
sl@0
|
515 |
__ASSERT_ALWAYS(pT!=NULL, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
|
sl@0
|
516 |
|
sl@0
|
517 |
switch (aCallback)
|
sl@0
|
518 |
{
|
sl@0
|
519 |
case ESpinningCallback:
|
sl@0
|
520 |
KernTest::Test(KernTest::EUserModeCallbackSpin, pT);
|
sl@0
|
521 |
break;
|
sl@0
|
522 |
case ESleepingCallback:
|
sl@0
|
523 |
KernTest::Test(KernTest::EUserModeCallbackSleep, pT);
|
sl@0
|
524 |
break;
|
sl@0
|
525 |
default:
|
sl@0
|
526 |
Kern::PanicCurrentThread(KClientPanicCat, __LINE__);
|
sl@0
|
527 |
}
|
sl@0
|
528 |
}
|
sl@0
|
529 |
|
sl@0
|
530 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
531 |
|
sl@0
|
532 |
class DTestFactory : public DLogicalDevice
|
sl@0
|
533 |
{
|
sl@0
|
534 |
public:
|
sl@0
|
535 |
DTestFactory();
|
sl@0
|
536 |
// from DLogicalDevice
|
sl@0
|
537 |
virtual TInt Install();
|
sl@0
|
538 |
virtual void GetCaps(TDes8& aDes) const;
|
sl@0
|
539 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
sl@0
|
540 |
};
|
sl@0
|
541 |
|
sl@0
|
542 |
DTestFactory::DTestFactory()
|
sl@0
|
543 |
{
|
sl@0
|
544 |
iVersion = RContextLdd::Version();
|
sl@0
|
545 |
// iParseMask = 0; // no unit, no info, no PDD
|
sl@0
|
546 |
// iUnitsMask = 0; // only one thing
|
sl@0
|
547 |
}
|
sl@0
|
548 |
|
sl@0
|
549 |
TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
|
sl@0
|
550 |
{
|
sl@0
|
551 |
aChannel=new DTestChannel;
|
sl@0
|
552 |
return aChannel ? KErrNone : KErrNoMemory;
|
sl@0
|
553 |
}
|
sl@0
|
554 |
|
sl@0
|
555 |
TInt DTestFactory::Install()
|
sl@0
|
556 |
{
|
sl@0
|
557 |
return SetName(&KTestLddName);
|
sl@0
|
558 |
}
|
sl@0
|
559 |
|
sl@0
|
560 |
void DTestFactory::GetCaps(TDes8& /*aDes*/) const
|
sl@0
|
561 |
{
|
sl@0
|
562 |
}
|
sl@0
|
563 |
|
sl@0
|
564 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
565 |
|
sl@0
|
566 |
DECLARE_STANDARD_LDD()
|
sl@0
|
567 |
{
|
sl@0
|
568 |
return new DTestFactory;
|
sl@0
|
569 |
}
|