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