1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/secure/d_sldd.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,198 @@
1.4 +// Copyright (c) 1998-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\secure\d_ldd.cpp
1.18 +// LDD for testing kernel platsec APIs
1.19 +//
1.20 +//
1.21 +
1.22 +/* Hack to make sure we get the true value of iKernelConfigFlags */
1.23 +#include "u32std.h"
1.24 +#undef __PLATSEC_FORCED_FLAGS__
1.25 +#define __PLATSEC_FORCED_FLAGS__ 0
1.26 +/* End hack */
1.27 +
1.28 +#include <kernel/kern_priv.h>
1.29 +
1.30 +#include "d_sldd.h"
1.31 +
1.32 +_LIT(KLddName,"D_SLDD");
1.33 +
1.34 +const TInt KMajorVersionNumber=0;
1.35 +const TInt KMinorVersionNumber=1;
1.36 +const TInt KBuildVersionNumber=1;
1.37 +
1.38 +TInt AFunction()
1.39 + {
1.40 + return KErrNone;
1.41 + }
1.42 +
1.43 +TInt data=0x100;
1.44 +TAny* dataptr=(TAny*)&AFunction;
1.45 +TInt TheBss;
1.46 +
1.47 +
1.48 +TUint32 KernelTestData[16] = { 0x32345678, 0x12345678 };
1.49 +
1.50 +class DTest;
1.51 +
1.52 +class DTestFactory : public DLogicalDevice
1.53 +//
1.54 +// Test LDD factory
1.55 +//
1.56 + {
1.57 +public:
1.58 + DTestFactory();
1.59 + virtual TInt Install(); //overriding pure virtual
1.60 + virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
1.61 + virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
1.62 + };
1.63 +
1.64 +class DTest : public DLogicalChannelBase
1.65 +//
1.66 +// Test logical channel
1.67 +//
1.68 + {
1.69 +public:
1.70 + virtual ~DTest();
1.71 +protected:
1.72 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.73 + virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
1.74 + };
1.75 +
1.76 +DECLARE_STANDARD_LDD()
1.77 + {
1.78 + return new DTestFactory;
1.79 + }
1.80 +
1.81 +DTestFactory::DTestFactory()
1.82 +//
1.83 +// Constructor
1.84 +//
1.85 + {
1.86 + iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
1.87 + //iParseMask=0;//No units, no info, no PDD
1.88 + //iUnitsMask=0;//Only one thing
1.89 + }
1.90 +
1.91 +TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
1.92 +//
1.93 +// Create a new DTest on this logical device
1.94 +//
1.95 + {
1.96 + aChannel=new DTest;
1.97 + return aChannel?KErrNone:KErrNoMemory;
1.98 + }
1.99 +
1.100 +TInt DTestFactory::Install()
1.101 +//
1.102 +// Install the LDD - overriding pure virtual
1.103 +//
1.104 + {
1.105 + return SetName(&KLddName);
1.106 + }
1.107 +
1.108 +void DTestFactory::GetCaps(TDes8& /*aDes*/) const
1.109 +//
1.110 +// Get capabilities - overriding pure virtual
1.111 +//
1.112 + {
1.113 + // deliberately do nothing here for testing purpose
1.114 + }
1.115 +
1.116 +TInt DTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
1.117 +//
1.118 +// Create channel
1.119 +//
1.120 + {
1.121 +
1.122 + if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
1.123 + return KErrNotSupported;
1.124 + return KErrNone;
1.125 + }
1.126 +
1.127 +DTest::~DTest()
1.128 +//
1.129 +// Destructor
1.130 +//
1.131 + {
1.132 + }
1.133 +
1.134 +TInt DTest::Request(TInt aFunction, TAny* a1, TAny* a2)
1.135 + {
1.136 + TInt r = KErrNone;
1.137 + switch (aFunction)
1.138 + {
1.139 + case RLddTest::EControlTest1:
1.140 + r = RLddTest::ETest1Value;
1.141 + break;
1.142 +
1.143 + case RLddTest::EGetIds:
1.144 + {
1.145 + RLddTest::TIds ids;
1.146 + memclr(&ids, sizeof(ids));
1.147 + DThread* thread = &Kern::CurrentThread();
1.148 + ids.iThreadVID = Kern::ThreadVendorId(thread);
1.149 + ids.iThreadSID = Kern::ThreadSecureId(thread);
1.150 + DProcess* process = &Kern::CurrentProcess();
1.151 + ids.iProcessVID = Kern::ProcessVendorId(process);
1.152 + ids.iProcessSID = Kern::ProcessSecureId(process);
1.153 + kumemput(a1, &ids, sizeof(ids));
1.154 + break;
1.155 + }
1.156 +
1.157 + case RLddTest::EGetKernelConfigFlags:
1.158 + {
1.159 + TSuperPage& superPage = Kern::SuperPage();
1.160 + r = superPage.KernelConfigFlags();
1.161 + break;
1.162 + }
1.163 +
1.164 + case RLddTest::ESetKernelConfigFlags:
1.165 + {
1.166 + TSuperPage& superPage = Kern::SuperPage();
1.167 + superPage.SetKernelConfigFlags((TUint32)a1);
1.168 + break;
1.169 + }
1.170 +
1.171 + case RLddTest::ESetDisabledCapabilities0:
1.172 + {
1.173 + TSuperPage& superPage = Kern::SuperPage();
1.174 + memcpy(superPage.iDisabledCapabilities, &a1, sizeof(TUint32));
1.175 + break;
1.176 + }
1.177 +
1.178 + case RLddTest::EKernelTestData:
1.179 + {
1.180 + TUint32* ptr = KernelTestData;
1.181 + TUint32 data = *ptr;
1.182 + kumemput32(a1,&ptr,sizeof(ptr));
1.183 + kumemput32(a2,&data,sizeof(data));
1.184 + }
1.185 + break;
1.186 +
1.187 + case RLddTest::EGetSecureInfos:
1.188 + {
1.189 + TSecurityInfo infoThread(&Kern::CurrentThread());
1.190 + TSecurityInfo infoProcess(&Kern::CurrentProcess());
1.191 + kumemput32(a1,&infoThread,sizeof(infoThread));
1.192 + kumemput32(a2,&infoProcess,sizeof(infoProcess));
1.193 + }
1.194 + break;
1.195 +
1.196 + default:
1.197 + r = KErrNotSupported;
1.198 + break;
1.199 + }
1.200 + return r;
1.201 + }