sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test/debug/d_context.h sl@0: // sl@0: // sl@0: sl@0: #ifndef __D_CONTEXT_H__ sl@0: #define __D_CONTEXT_H__ sl@0: sl@0: #include sl@0: #ifndef __KLIB_H__ sl@0: #include sl@0: #endif sl@0: #include sl@0: sl@0: _LIT(KTestLddName, "TestContext"); sl@0: sl@0: enum TUserCallbackState sl@0: { sl@0: ENoCallback, // thread does nothing special sl@0: ESpinningCallback, // thread will be given a callback that spins forever sl@0: ESleepingCallback, // thread will be given a callback that sleeps for a long time sl@0: }; sl@0: sl@0: struct TArmFullContext sl@0: { sl@0: TArmRegSet iUserContext; sl@0: TUint32 iUserAvail; sl@0: TArmRegSet iSystemContext; sl@0: TUint32 iSystemAvail; sl@0: }; sl@0: sl@0: class RContextLdd : public RBusLogicalChannel sl@0: { sl@0: public: sl@0: enum sl@0: { sl@0: EHook, sl@0: EGetLastExc, sl@0: ETrapNextHwExc, sl@0: ETrapNextSwExc, sl@0: ETrapNextDeath, sl@0: ESetGetContext, sl@0: EGetContext, sl@0: EGetKernelContext, sl@0: ESpinInKernel, sl@0: ESetGetFullContext, sl@0: EAddUserCallback, sl@0: EResumeTrappedThread, sl@0: }; sl@0: sl@0: struct TTrapInfo sl@0: { sl@0: TUint iThreadId; sl@0: TAny* iContextPtr; sl@0: TRequestStatus* iStatusPtr; sl@0: TBool iKillThread; sl@0: }; sl@0: sl@0: public: sl@0: static inline TVersion Version() { return TVersion(1, 0, 1); } sl@0: #ifndef __KERNEL_MODE__ sl@0: public: sl@0: inline RContextLdd(); sl@0: inline TInt Open(); sl@0: inline TInt Hook(TInt* aCounterPtr); sl@0: inline TExcType LastException(); sl@0: inline TBool IsHooked() const; sl@0: inline void TrapNextHwExc(TThreadId aId, TAny* aContext, TRequestStatus& aStatus, TBool aKillThread); sl@0: inline void TrapNextSwExc(TThreadId aId, TAny* aContext, TRequestStatus& aStatus, TBool aKillThread); sl@0: inline void TrapNextDeath(TThreadId aId, TAny* aContext, TRequestStatus& aStatus); sl@0: inline TInt SetAndGetBackContext(TThreadId aId, TAny* aContext); sl@0: inline TInt SetAndGetFullContext(TThreadId aId, TArmFullContext* aContextData); sl@0: inline void GetContext(TThreadId aId, TAny* aContext); sl@0: inline void GetKernelContext(TThreadId aId, TAny* aContext); sl@0: inline TUint32 SpinInKernel(TBool aReallySpin); sl@0: inline void AddUserCallback(TThreadId aId, TUserCallbackState aCallback); sl@0: inline void ResumeTrappedThread(TThreadId aId); sl@0: private: sl@0: TBool iHooked; sl@0: #endif sl@0: }; sl@0: sl@0: sl@0: #ifndef __KERNEL_MODE__ sl@0: sl@0: inline RContextLdd::RContextLdd() sl@0: : iHooked(EFalse) sl@0: { sl@0: } sl@0: sl@0: inline TBool RContextLdd::IsHooked() const sl@0: { sl@0: return iHooked; sl@0: } sl@0: sl@0: inline TInt RContextLdd::Open() sl@0: { sl@0: return DoCreate(KTestLddName, Version(), KNullUnit, NULL, NULL, EOwnerProcess); sl@0: } sl@0: sl@0: inline TInt RContextLdd::Hook(TInt* aCounterPtr) sl@0: { sl@0: TInt r = DoControl(EHook, aCounterPtr); sl@0: iHooked = (r == KErrNone); sl@0: return r; sl@0: } sl@0: sl@0: inline TExcType RContextLdd::LastException() sl@0: { sl@0: return static_cast(DoControl(EGetLastExc)); sl@0: } sl@0: sl@0: inline void RContextLdd::TrapNextHwExc(TThreadId aId, TAny* aExcContext, TRequestStatus& aStatus, TBool aKillThread) sl@0: { sl@0: aStatus = KRequestPending; sl@0: TTrapInfo info; sl@0: info.iThreadId = aId; sl@0: info.iContextPtr = aExcContext; sl@0: info.iStatusPtr = &aStatus; sl@0: info.iKillThread = aKillThread; sl@0: DoControl(ETrapNextHwExc, &info); sl@0: } sl@0: sl@0: inline void RContextLdd::TrapNextSwExc(TThreadId aId, TAny* aContext, TRequestStatus& aStatus, TBool aKillThread) sl@0: { sl@0: aStatus = KRequestPending; sl@0: TTrapInfo info; sl@0: info.iThreadId = aId; sl@0: info.iContextPtr = aContext; sl@0: info.iStatusPtr = &aStatus; sl@0: info.iKillThread = aKillThread; sl@0: DoControl(ETrapNextSwExc, &info); sl@0: } sl@0: sl@0: inline void RContextLdd::TrapNextDeath(TThreadId aId, TAny* aContext, TRequestStatus& aStatus) sl@0: { sl@0: aStatus = KRequestPending; sl@0: TTrapInfo info; sl@0: info.iThreadId = aId; sl@0: info.iContextPtr = aContext; sl@0: info.iStatusPtr = &aStatus; sl@0: DoControl(ETrapNextDeath, &info); sl@0: } sl@0: sl@0: inline TInt RContextLdd::SetAndGetBackContext(TThreadId aId, TAny* aContext) sl@0: { sl@0: return DoControl(ESetGetContext, (TAny*)(TUint)aId, aContext); sl@0: } sl@0: sl@0: inline TInt RContextLdd::SetAndGetFullContext(TThreadId aId, TArmFullContext* aContextData) sl@0: { sl@0: return DoControl(ESetGetFullContext, (TAny*)(TUint)aId, (TAny*)aContextData); sl@0: } sl@0: sl@0: inline void RContextLdd::GetContext(TThreadId aId, TAny* aContext) sl@0: { sl@0: DoControl(EGetContext, (TAny*)(TUint)aId, aContext); sl@0: } sl@0: sl@0: inline void RContextLdd::GetKernelContext(TThreadId aId, TAny* aContext) sl@0: { sl@0: DoControl(EGetKernelContext, (TAny*)(TUint)aId, aContext); sl@0: } sl@0: sl@0: inline TUint32 RContextLdd::SpinInKernel(TBool aReallySpin) sl@0: { sl@0: return DoControl(ESpinInKernel, (TAny*)aReallySpin); sl@0: } sl@0: sl@0: inline void RContextLdd::AddUserCallback(TThreadId aId, TUserCallbackState aCallback) sl@0: { sl@0: DoControl(EAddUserCallback, (TAny*)(TUint)aId, (TAny*)aCallback); sl@0: } sl@0: sl@0: inline void RContextLdd::ResumeTrappedThread(TThreadId aId) sl@0: { sl@0: DoControl(EResumeTrappedThread, (TAny*)(TUint)aId); sl@0: } sl@0: sl@0: #endif // __KERNEL_MODE__ sl@0: sl@0: #endif