sl@0: // Copyright (c) 2004-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\mmu\d_asid.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "d_asid.h" sl@0: sl@0: // sl@0: // Class definitions sl@0: // sl@0: sl@0: class DAsidFactory : public DLogicalDevice sl@0: { sl@0: public: sl@0: ~DAsidFactory(); sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8& aDes) const; sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); sl@0: }; sl@0: sl@0: class DAsidChannel : public DLogicalChannelBase sl@0: { sl@0: public: sl@0: DAsidChannel(); sl@0: ~DAsidChannel(); sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2); sl@0: public: sl@0: DAsidFactory* iFactory; sl@0: private: sl@0: DThread* iThread; sl@0: }; sl@0: sl@0: // sl@0: // DAsidFactory sl@0: // sl@0: sl@0: TInt DAsidFactory::Install() sl@0: { sl@0: return SetName(&KMemoryTestLddName); sl@0: } sl@0: sl@0: DAsidFactory::~DAsidFactory() sl@0: { sl@0: } sl@0: sl@0: void DAsidFactory::GetCaps(TDes8& /*aDes*/) const sl@0: { sl@0: // Not used but required as DLogicalDevice::GetCaps is pure virtual sl@0: } sl@0: sl@0: TInt DAsidFactory::Create(DLogicalChannelBase*& aChannel) sl@0: { sl@0: aChannel = NULL; sl@0: DAsidChannel* channel=new DAsidChannel; sl@0: if(!channel) sl@0: return KErrNoMemory; sl@0: channel->iFactory = this; sl@0: aChannel = channel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: DECLARE_STANDARD_LDD() sl@0: { sl@0: return new DAsidFactory; sl@0: } sl@0: sl@0: // sl@0: // DAsidChannel sl@0: // sl@0: sl@0: TInt DAsidChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: DAsidChannel::DAsidChannel() : iThread(NULL) sl@0: { sl@0: } sl@0: sl@0: DAsidChannel::~DAsidChannel() sl@0: { sl@0: if (iThread) sl@0: iThread->Close(NULL); sl@0: } sl@0: sl@0: sl@0: TInt DAsidChannel::Request(TInt aFunction, TAny* a1, TAny* a2) sl@0: { sl@0: TInt r=KErrNotSupported; sl@0: sl@0: switch(aFunction) sl@0: { sl@0: case RAsidLdd::EGetCurrentThread: sl@0: { sl@0: DThread* thread = &Kern::CurrentThread(); sl@0: kumemput32(a1, (TAny*)&thread, sizeof(DThread*)); sl@0: r = KErrNone; sl@0: } sl@0: break; sl@0: sl@0: case RAsidLdd::EOpenThread: sl@0: { sl@0: if (iThread) sl@0: { sl@0: r = KErrInUse; sl@0: break; sl@0: } sl@0: iThread = (DThread*) a1; sl@0: iThread->Open(); sl@0: r = KErrNone; sl@0: } sl@0: break; sl@0: sl@0: case RAsidLdd::ECloseThread: sl@0: { sl@0: if (!iThread) sl@0: { sl@0: r = KErrNotFound; sl@0: break; sl@0: } sl@0: NKern::ThreadEnterCS(); sl@0: iThread->Close(NULL); sl@0: iThread = NULL; sl@0: r = KErrNone; sl@0: NKern::ThreadLeaveCS(); sl@0: } sl@0: break; sl@0: sl@0: case RAsidLdd::EReadDesHeader: sl@0: { sl@0: SDesHeader hdr; sl@0: TUint8* ptr; sl@0: kumemget32((TAny*)&hdr, a2, sizeof(SDesHeader)); sl@0: r = Kern::ThreadGetDesInfo((DThread*)a1, hdr.iDes, hdr.iLength, hdr.iMaxLength, ptr, ETrue); sl@0: if (r == KErrNone) sl@0: {// copy the data back to user side struct. sl@0: kumemput32(a2, &hdr, sizeof(SDesHeader)); sl@0: } sl@0: } sl@0: break; sl@0: } sl@0: return r; sl@0: }