1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/debug/d_codemodifier.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,165 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\debug\d_codemodifier.cpp
1.18 +// See e32test\debug\t_codemodifier.cpp for details
1.19 +//
1.20 +//
1.21 +
1.22 +#include "d_codemodifier.h"
1.23 +#include <kernel/kern_priv.h>
1.24 +#include <kernel/cache.h>
1.25 +
1.26 +class DCodeModifier : public DLogicalChannelBase
1.27 + {
1.28 +public:
1.29 + DCodeModifier();
1.30 + ~DCodeModifier();
1.31 + static TBool Handler (const TDesC8& aText, TTraceSource aTraceSource);
1.32 +protected:
1.33 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.34 + virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
1.35 +private:
1.36 + DThread* iThread[2];
1.37 + };
1.38 +
1.39 +DCodeModifier* CodeModifierDriver;
1.40 +
1.41 +DCodeModifier::DCodeModifier()
1.42 + {
1.43 + }
1.44 +
1.45 +DCodeModifier::~DCodeModifier()
1.46 + {
1.47 + CodeModifierDriver = NULL;
1.48 + }
1.49 +
1.50 +
1.51 +/**Creates the channel*/
1.52 +TInt DCodeModifier::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
1.53 + {
1.54 + return KErrNone;
1.55 + }
1.56 +
1.57 +/**User side request entry point.*/
1.58 +TInt DCodeModifier::Request(TInt aFunction, TAny* a1, TAny* a2)
1.59 + {
1.60 + TInt r = KErrNone;
1.61 + RCodeModifierDevice::TData data;
1.62 +
1.63 + kumemget(&data,a1,sizeof(data));
1.64 + switch (aFunction)
1.65 + {
1.66 + case RCodeModifierDevice::EControlThreadId:
1.67 + {
1.68 + DObjectCon* threads=Kern::Containers()[EThread];
1.69 + NKern::ThreadEnterCS();
1.70 + threads->Wait();
1.71 + iThread[data.iServer]=Kern::ThreadFromId(data.iThreadId);
1.72 + if(!iThread[data.iServer])
1.73 + r=KErrNotFound;
1.74 + threads->Signal();
1.75 + NKern::ThreadLeaveCS();
1.76 + }
1.77 + break;
1.78 +
1.79 + case RCodeModifierDevice::EControlReadWord:
1.80 + {
1.81 + TInt val;
1.82 + r = Kern::ThreadRawRead(iThread[data.iServer], (const TAny*) data.iAddress, (TAny*) &val, sizeof(TInt));
1.83 + kumemput(a2,&val,sizeof(TInt));
1.84 + }
1.85 + break;
1.86 +
1.87 + case RCodeModifierDevice::EControlWriteWord:
1.88 + r = Kern::ThreadRawWrite(iThread[data.iServer], (TAny*)data.iAddress,(const TAny*) &a2, sizeof(TInt));
1.89 + break;
1.90 +
1.91 + case RCodeModifierDevice::EControlWriteCode:
1.92 + r = DebugSupport::ModifyCode(iThread[data.iServer], (TLinAddr) data.iAddress, data.iSize, (TUint)a2, DebugSupport::EBreakpointGlobal);
1.93 + if (r == DebugSupport::EBreakpointGlobal)
1.94 + r = KErrNone;
1.95 + break;
1.96 +
1.97 + case RCodeModifierDevice::EControlRestoreCode:
1.98 + r = DebugSupport::RestoreCode(iThread[data.iServer], (TLinAddr)data.iAddress);
1.99 + break;
1.100 +
1.101 + case RCodeModifierDevice::EInitialiseCodeModifier:
1.102 + {
1.103 + TUint cap;
1.104 + r = DebugSupport::InitialiseCodeModifier(cap,data.iSize);
1.105 + if (r && (cap!=DebugSupport::EBreakpointGlobal))
1.106 + r = KErrGeneral;
1.107 + }
1.108 + break;
1.109 +
1.110 + case RCodeModifierDevice::ECloseCodeModifier:
1.111 + DebugSupport::CloseCodeModifier();
1.112 + break;
1.113 +
1.114 + case RCodeModifierDevice::EControlAllocShadowPage:
1.115 + NKern::ThreadEnterCS();
1.116 + r = Epoc::AllocShadowPage(data.iAddress & ~(Kern::RoundToPageSize(1)-1));
1.117 + NKern::ThreadLeaveCS();
1.118 + break;
1.119 +
1.120 + case RCodeModifierDevice::EControlFreeShadowPage:
1.121 + NKern::ThreadEnterCS();
1.122 + r = Epoc::FreeShadowPage(data.iAddress & ~(Kern::RoundToPageSize(1)-1));
1.123 + NKern::ThreadLeaveCS();
1.124 + break;
1.125 +
1.126 + default:
1.127 + r=KErrNotSupported;
1.128 + }
1.129 + return r;
1.130 + }
1.131 +
1.132 +//////////////////////////////////////////
1.133 +class DTestFactory : public DLogicalDevice
1.134 + {
1.135 +public:
1.136 + DTestFactory();
1.137 + // from DLogicalDevice
1.138 + virtual TInt Install();
1.139 + virtual void GetCaps(TDes8& aDes) const;
1.140 + virtual TInt Create(DLogicalChannelBase*& aChannel);
1.141 + };
1.142 +
1.143 +DTestFactory::DTestFactory()
1.144 + {
1.145 + iParseMask = KDeviceAllowUnit;
1.146 + iUnitsMask = 0x3;
1.147 + }
1.148 +
1.149 +TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
1.150 + {
1.151 + CodeModifierDriver = new DCodeModifier;
1.152 + aChannel = CodeModifierDriver;
1.153 + return (aChannel ? KErrNone : KErrNoMemory);
1.154 + }
1.155 +
1.156 +TInt DTestFactory::Install()
1.157 + {
1.158 + return SetName(&KCodeModifierName);
1.159 + }
1.160 +
1.161 +void DTestFactory::GetCaps(TDes8& /*aDes*/) const
1.162 + {
1.163 + }
1.164 +
1.165 +DECLARE_STANDARD_LDD()
1.166 + {
1.167 + return new DTestFactory;
1.168 + }