Update contrib.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\debug\d_codemodifier.cpp
15 // See e32test\debug\t_codemodifier.cpp for details
19 #include "d_codemodifier.h"
20 #include <kernel/kern_priv.h>
21 #include <kernel/cache.h>
23 class DCodeModifier : public DLogicalChannelBase
28 static TBool Handler (const TDesC8& aText, TTraceSource aTraceSource);
30 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
31 virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
36 DCodeModifier* CodeModifierDriver;
38 DCodeModifier::DCodeModifier()
42 DCodeModifier::~DCodeModifier()
44 CodeModifierDriver = NULL;
48 /**Creates the channel*/
49 TInt DCodeModifier::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
54 /**User side request entry point.*/
55 TInt DCodeModifier::Request(TInt aFunction, TAny* a1, TAny* a2)
58 RCodeModifierDevice::TData data;
60 kumemget(&data,a1,sizeof(data));
63 case RCodeModifierDevice::EControlThreadId:
65 DObjectCon* threads=Kern::Containers()[EThread];
66 NKern::ThreadEnterCS();
68 iThread[data.iServer]=Kern::ThreadFromId(data.iThreadId);
69 if(!iThread[data.iServer])
72 NKern::ThreadLeaveCS();
76 case RCodeModifierDevice::EControlReadWord:
79 r = Kern::ThreadRawRead(iThread[data.iServer], (const TAny*) data.iAddress, (TAny*) &val, sizeof(TInt));
80 kumemput(a2,&val,sizeof(TInt));
84 case RCodeModifierDevice::EControlWriteWord:
85 r = Kern::ThreadRawWrite(iThread[data.iServer], (TAny*)data.iAddress,(const TAny*) &a2, sizeof(TInt));
88 case RCodeModifierDevice::EControlWriteCode:
89 r = DebugSupport::ModifyCode(iThread[data.iServer], (TLinAddr) data.iAddress, data.iSize, (TUint)a2, DebugSupport::EBreakpointGlobal);
90 if (r == DebugSupport::EBreakpointGlobal)
94 case RCodeModifierDevice::EControlRestoreCode:
95 r = DebugSupport::RestoreCode(iThread[data.iServer], (TLinAddr)data.iAddress);
98 case RCodeModifierDevice::EInitialiseCodeModifier:
101 r = DebugSupport::InitialiseCodeModifier(cap,data.iSize);
102 if (r && (cap!=DebugSupport::EBreakpointGlobal))
107 case RCodeModifierDevice::ECloseCodeModifier:
108 DebugSupport::CloseCodeModifier();
111 case RCodeModifierDevice::EControlAllocShadowPage:
112 NKern::ThreadEnterCS();
113 r = Epoc::AllocShadowPage(data.iAddress & ~(Kern::RoundToPageSize(1)-1));
114 NKern::ThreadLeaveCS();
117 case RCodeModifierDevice::EControlFreeShadowPage:
118 NKern::ThreadEnterCS();
119 r = Epoc::FreeShadowPage(data.iAddress & ~(Kern::RoundToPageSize(1)-1));
120 NKern::ThreadLeaveCS();
129 //////////////////////////////////////////
130 class DTestFactory : public DLogicalDevice
134 // from DLogicalDevice
135 virtual TInt Install();
136 virtual void GetCaps(TDes8& aDes) const;
137 virtual TInt Create(DLogicalChannelBase*& aChannel);
140 DTestFactory::DTestFactory()
142 iParseMask = KDeviceAllowUnit;
146 TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
148 CodeModifierDriver = new DCodeModifier;
149 aChannel = CodeModifierDriver;
150 return (aChannel ? KErrNone : KErrNoMemory);
153 TInt DTestFactory::Install()
155 return SetName(&KCodeModifierName);
158 void DTestFactory::GetCaps(TDes8& /*aDes*/) const
162 DECLARE_STANDARD_LDD()
164 return new DTestFactory;