os/kernelhwsrv/kerneltest/e32test/secure/d_sldd.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\secure\d_ldd.cpp
sl@0
    15
// LDD for testing kernel platsec APIs
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
/* Hack to make sure we get the true value of iKernelConfigFlags */
sl@0
    20
#include "u32std.h"
sl@0
    21
#undef __PLATSEC_FORCED_FLAGS__
sl@0
    22
#define __PLATSEC_FORCED_FLAGS__ 0
sl@0
    23
/* End hack */
sl@0
    24
sl@0
    25
#include <kernel/kern_priv.h>
sl@0
    26
sl@0
    27
#include "d_sldd.h"
sl@0
    28
sl@0
    29
_LIT(KLddName,"D_SLDD");
sl@0
    30
sl@0
    31
const TInt KMajorVersionNumber=0;
sl@0
    32
const TInt KMinorVersionNumber=1;
sl@0
    33
const TInt KBuildVersionNumber=1;
sl@0
    34
sl@0
    35
TInt AFunction()
sl@0
    36
	{
sl@0
    37
	return KErrNone;
sl@0
    38
	}
sl@0
    39
sl@0
    40
TInt data=0x100;
sl@0
    41
TAny* dataptr=(TAny*)&AFunction;
sl@0
    42
TInt TheBss;
sl@0
    43
sl@0
    44
sl@0
    45
TUint32 KernelTestData[16] = { 0x32345678, 0x12345678 };
sl@0
    46
sl@0
    47
class DTest;
sl@0
    48
sl@0
    49
class DTestFactory : public DLogicalDevice
sl@0
    50
//
sl@0
    51
// Test LDD factory
sl@0
    52
//
sl@0
    53
	{
sl@0
    54
public:
sl@0
    55
	DTestFactory();
sl@0
    56
	virtual TInt Install(); 					//overriding pure virtual
sl@0
    57
	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
sl@0
    58
	virtual TInt Create(DLogicalChannelBase*& aChannel); 	//overriding pure virtual
sl@0
    59
	};
sl@0
    60
sl@0
    61
class DTest : public DLogicalChannelBase
sl@0
    62
//
sl@0
    63
// Test logical channel
sl@0
    64
//
sl@0
    65
	{
sl@0
    66
public:
sl@0
    67
	virtual ~DTest();
sl@0
    68
protected:
sl@0
    69
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    70
	virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
sl@0
    71
	};
sl@0
    72
sl@0
    73
DECLARE_STANDARD_LDD()
sl@0
    74
	{
sl@0
    75
	return new DTestFactory;
sl@0
    76
	}
sl@0
    77
sl@0
    78
DTestFactory::DTestFactory()
sl@0
    79
//
sl@0
    80
// Constructor
sl@0
    81
//
sl@0
    82
	{
sl@0
    83
	iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
    84
	//iParseMask=0;//No units, no info, no PDD
sl@0
    85
	//iUnitsMask=0;//Only one thing
sl@0
    86
	}
sl@0
    87
sl@0
    88
TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
    89
//
sl@0
    90
// Create a new DTest on this logical device
sl@0
    91
//
sl@0
    92
	{
sl@0
    93
	aChannel=new DTest;
sl@0
    94
	return aChannel?KErrNone:KErrNoMemory;
sl@0
    95
	}
sl@0
    96
sl@0
    97
TInt DTestFactory::Install()
sl@0
    98
//
sl@0
    99
// Install the LDD - overriding pure virtual
sl@0
   100
//
sl@0
   101
	{
sl@0
   102
	return SetName(&KLddName);
sl@0
   103
	}
sl@0
   104
sl@0
   105
void DTestFactory::GetCaps(TDes8& /*aDes*/) const
sl@0
   106
//
sl@0
   107
// Get capabilities - overriding pure virtual
sl@0
   108
//
sl@0
   109
	{
sl@0
   110
	// deliberately do nothing here for testing purpose
sl@0
   111
	}
sl@0
   112
sl@0
   113
TInt DTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
sl@0
   114
//
sl@0
   115
// Create channel
sl@0
   116
//
sl@0
   117
	{
sl@0
   118
sl@0
   119
	if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
sl@0
   120
		return KErrNotSupported;
sl@0
   121
	return KErrNone;
sl@0
   122
	}
sl@0
   123
sl@0
   124
DTest::~DTest()
sl@0
   125
//
sl@0
   126
// Destructor
sl@0
   127
//
sl@0
   128
	{
sl@0
   129
	}
sl@0
   130
sl@0
   131
TInt DTest::Request(TInt aFunction, TAny* a1, TAny* a2)
sl@0
   132
	{
sl@0
   133
	TInt r = KErrNone;
sl@0
   134
	switch (aFunction)
sl@0
   135
		{
sl@0
   136
		case RLddTest::EControlTest1:
sl@0
   137
			r = RLddTest::ETest1Value;
sl@0
   138
			break;
sl@0
   139
sl@0
   140
		case RLddTest::EGetIds:
sl@0
   141
			{
sl@0
   142
			RLddTest::TIds ids;
sl@0
   143
			memclr(&ids, sizeof(ids));
sl@0
   144
			DThread* thread = &Kern::CurrentThread();
sl@0
   145
			ids.iThreadVID = Kern::ThreadVendorId(thread);
sl@0
   146
			ids.iThreadSID = Kern::ThreadSecureId(thread);
sl@0
   147
			DProcess* process = &Kern::CurrentProcess();
sl@0
   148
			ids.iProcessVID = Kern::ProcessVendorId(process);
sl@0
   149
			ids.iProcessSID = Kern::ProcessSecureId(process);
sl@0
   150
			kumemput(a1, &ids, sizeof(ids));
sl@0
   151
			break;
sl@0
   152
			}
sl@0
   153
		
sl@0
   154
		case RLddTest::EGetKernelConfigFlags:
sl@0
   155
			{
sl@0
   156
			TSuperPage& superPage = Kern::SuperPage();
sl@0
   157
			r = superPage.KernelConfigFlags();
sl@0
   158
			break;
sl@0
   159
			}
sl@0
   160
sl@0
   161
		case RLddTest::ESetKernelConfigFlags:
sl@0
   162
			{
sl@0
   163
			TSuperPage& superPage = Kern::SuperPage();
sl@0
   164
			superPage.SetKernelConfigFlags((TUint32)a1);
sl@0
   165
			break;
sl@0
   166
			}
sl@0
   167
sl@0
   168
		case RLddTest::ESetDisabledCapabilities0:
sl@0
   169
			{
sl@0
   170
			TSuperPage& superPage = Kern::SuperPage();
sl@0
   171
			memcpy(superPage.iDisabledCapabilities, &a1, sizeof(TUint32));
sl@0
   172
			break;
sl@0
   173
			}
sl@0
   174
sl@0
   175
		case RLddTest::EKernelTestData:
sl@0
   176
			{
sl@0
   177
			TUint32* ptr = KernelTestData;
sl@0
   178
			TUint32 data = *ptr;
sl@0
   179
			kumemput32(a1,&ptr,sizeof(ptr));
sl@0
   180
			kumemput32(a2,&data,sizeof(data));
sl@0
   181
			}
sl@0
   182
			break;
sl@0
   183
sl@0
   184
		case RLddTest::EGetSecureInfos:
sl@0
   185
			{
sl@0
   186
			TSecurityInfo infoThread(&Kern::CurrentThread());
sl@0
   187
			TSecurityInfo infoProcess(&Kern::CurrentProcess());
sl@0
   188
			kumemput32(a1,&infoThread,sizeof(infoThread));			
sl@0
   189
			kumemput32(a2,&infoProcess,sizeof(infoProcess));			
sl@0
   190
			}
sl@0
   191
			break;
sl@0
   192
sl@0
   193
		default:
sl@0
   194
			r = KErrNotSupported;
sl@0
   195
			break;
sl@0
   196
		}
sl@0
   197
	return r;
sl@0
   198
	}