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.h
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#ifndef __D_CONTEXT_H__
|
sl@0
|
19 |
#define __D_CONTEXT_H__
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <e32cmn.h>
|
sl@0
|
22 |
#ifndef __KLIB_H__
|
sl@0
|
23 |
#include <e32std.h>
|
sl@0
|
24 |
#endif
|
sl@0
|
25 |
#include <kernel/arm/arm_types.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
_LIT(KTestLddName, "TestContext");
|
sl@0
|
28 |
|
sl@0
|
29 |
enum TUserCallbackState
|
sl@0
|
30 |
{
|
sl@0
|
31 |
ENoCallback, // thread does nothing special
|
sl@0
|
32 |
ESpinningCallback, // thread will be given a callback that spins forever
|
sl@0
|
33 |
ESleepingCallback, // thread will be given a callback that sleeps for a long time
|
sl@0
|
34 |
};
|
sl@0
|
35 |
|
sl@0
|
36 |
struct TArmFullContext
|
sl@0
|
37 |
{
|
sl@0
|
38 |
TArmRegSet iUserContext;
|
sl@0
|
39 |
TUint32 iUserAvail;
|
sl@0
|
40 |
TArmRegSet iSystemContext;
|
sl@0
|
41 |
TUint32 iSystemAvail;
|
sl@0
|
42 |
};
|
sl@0
|
43 |
|
sl@0
|
44 |
class RContextLdd : public RBusLogicalChannel
|
sl@0
|
45 |
{
|
sl@0
|
46 |
public:
|
sl@0
|
47 |
enum
|
sl@0
|
48 |
{
|
sl@0
|
49 |
EHook,
|
sl@0
|
50 |
EGetLastExc,
|
sl@0
|
51 |
ETrapNextHwExc,
|
sl@0
|
52 |
ETrapNextSwExc,
|
sl@0
|
53 |
ETrapNextDeath,
|
sl@0
|
54 |
ESetGetContext,
|
sl@0
|
55 |
EGetContext,
|
sl@0
|
56 |
EGetKernelContext,
|
sl@0
|
57 |
ESpinInKernel,
|
sl@0
|
58 |
ESetGetFullContext,
|
sl@0
|
59 |
EAddUserCallback,
|
sl@0
|
60 |
EResumeTrappedThread,
|
sl@0
|
61 |
};
|
sl@0
|
62 |
|
sl@0
|
63 |
struct TTrapInfo
|
sl@0
|
64 |
{
|
sl@0
|
65 |
TUint iThreadId;
|
sl@0
|
66 |
TAny* iContextPtr;
|
sl@0
|
67 |
TRequestStatus* iStatusPtr;
|
sl@0
|
68 |
TBool iKillThread;
|
sl@0
|
69 |
};
|
sl@0
|
70 |
|
sl@0
|
71 |
public:
|
sl@0
|
72 |
static inline TVersion Version() { return TVersion(1, 0, 1); }
|
sl@0
|
73 |
#ifndef __KERNEL_MODE__
|
sl@0
|
74 |
public:
|
sl@0
|
75 |
inline RContextLdd();
|
sl@0
|
76 |
inline TInt Open();
|
sl@0
|
77 |
inline TInt Hook(TInt* aCounterPtr);
|
sl@0
|
78 |
inline TExcType LastException();
|
sl@0
|
79 |
inline TBool IsHooked() const;
|
sl@0
|
80 |
inline void TrapNextHwExc(TThreadId aId, TAny* aContext, TRequestStatus& aStatus, TBool aKillThread);
|
sl@0
|
81 |
inline void TrapNextSwExc(TThreadId aId, TAny* aContext, TRequestStatus& aStatus, TBool aKillThread);
|
sl@0
|
82 |
inline void TrapNextDeath(TThreadId aId, TAny* aContext, TRequestStatus& aStatus);
|
sl@0
|
83 |
inline TInt SetAndGetBackContext(TThreadId aId, TAny* aContext);
|
sl@0
|
84 |
inline TInt SetAndGetFullContext(TThreadId aId, TArmFullContext* aContextData);
|
sl@0
|
85 |
inline void GetContext(TThreadId aId, TAny* aContext);
|
sl@0
|
86 |
inline void GetKernelContext(TThreadId aId, TAny* aContext);
|
sl@0
|
87 |
inline TUint32 SpinInKernel(TBool aReallySpin);
|
sl@0
|
88 |
inline void AddUserCallback(TThreadId aId, TUserCallbackState aCallback);
|
sl@0
|
89 |
inline void ResumeTrappedThread(TThreadId aId);
|
sl@0
|
90 |
private:
|
sl@0
|
91 |
TBool iHooked;
|
sl@0
|
92 |
#endif
|
sl@0
|
93 |
};
|
sl@0
|
94 |
|
sl@0
|
95 |
|
sl@0
|
96 |
#ifndef __KERNEL_MODE__
|
sl@0
|
97 |
|
sl@0
|
98 |
inline RContextLdd::RContextLdd()
|
sl@0
|
99 |
: iHooked(EFalse)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
inline TBool RContextLdd::IsHooked() const
|
sl@0
|
104 |
{
|
sl@0
|
105 |
return iHooked;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
inline TInt RContextLdd::Open()
|
sl@0
|
109 |
{
|
sl@0
|
110 |
return DoCreate(KTestLddName, Version(), KNullUnit, NULL, NULL, EOwnerProcess);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
inline TInt RContextLdd::Hook(TInt* aCounterPtr)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
TInt r = DoControl(EHook, aCounterPtr);
|
sl@0
|
116 |
iHooked = (r == KErrNone);
|
sl@0
|
117 |
return r;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
inline TExcType RContextLdd::LastException()
|
sl@0
|
121 |
{
|
sl@0
|
122 |
return static_cast<TExcType>(DoControl(EGetLastExc));
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
inline void RContextLdd::TrapNextHwExc(TThreadId aId, TAny* aExcContext, TRequestStatus& aStatus, TBool aKillThread)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
aStatus = KRequestPending;
|
sl@0
|
128 |
TTrapInfo info;
|
sl@0
|
129 |
info.iThreadId = aId;
|
sl@0
|
130 |
info.iContextPtr = aExcContext;
|
sl@0
|
131 |
info.iStatusPtr = &aStatus;
|
sl@0
|
132 |
info.iKillThread = aKillThread;
|
sl@0
|
133 |
DoControl(ETrapNextHwExc, &info);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
inline void RContextLdd::TrapNextSwExc(TThreadId aId, TAny* aContext, TRequestStatus& aStatus, TBool aKillThread)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
aStatus = KRequestPending;
|
sl@0
|
139 |
TTrapInfo info;
|
sl@0
|
140 |
info.iThreadId = aId;
|
sl@0
|
141 |
info.iContextPtr = aContext;
|
sl@0
|
142 |
info.iStatusPtr = &aStatus;
|
sl@0
|
143 |
info.iKillThread = aKillThread;
|
sl@0
|
144 |
DoControl(ETrapNextSwExc, &info);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
inline void RContextLdd::TrapNextDeath(TThreadId aId, TAny* aContext, TRequestStatus& aStatus)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
aStatus = KRequestPending;
|
sl@0
|
150 |
TTrapInfo info;
|
sl@0
|
151 |
info.iThreadId = aId;
|
sl@0
|
152 |
info.iContextPtr = aContext;
|
sl@0
|
153 |
info.iStatusPtr = &aStatus;
|
sl@0
|
154 |
DoControl(ETrapNextDeath, &info);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
inline TInt RContextLdd::SetAndGetBackContext(TThreadId aId, TAny* aContext)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
return DoControl(ESetGetContext, (TAny*)(TUint)aId, aContext);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
inline TInt RContextLdd::SetAndGetFullContext(TThreadId aId, TArmFullContext* aContextData)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
return DoControl(ESetGetFullContext, (TAny*)(TUint)aId, (TAny*)aContextData);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
inline void RContextLdd::GetContext(TThreadId aId, TAny* aContext)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
DoControl(EGetContext, (TAny*)(TUint)aId, aContext);
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
inline void RContextLdd::GetKernelContext(TThreadId aId, TAny* aContext)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
DoControl(EGetKernelContext, (TAny*)(TUint)aId, aContext);
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
inline TUint32 RContextLdd::SpinInKernel(TBool aReallySpin)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
return DoControl(ESpinInKernel, (TAny*)aReallySpin);
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
inline void RContextLdd::AddUserCallback(TThreadId aId, TUserCallbackState aCallback)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
DoControl(EAddUserCallback, (TAny*)(TUint)aId, (TAny*)aCallback);
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
inline void RContextLdd::ResumeTrappedThread(TThreadId aId)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
DoControl(EResumeTrappedThread, (TAny*)(TUint)aId);
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
#endif // __KERNEL_MODE__
|
sl@0
|
193 |
|
sl@0
|
194 |
#endif
|