os/kernelhwsrv/kerneltest/f32test/loader/security/dllt.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/loader/security/dllt.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,238 @@
     1.4 +// Copyright (c) 1999-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 +// f32test\loader\security\dllt.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32svr.h>
    1.22 +#include "dllt.h"
    1.23 +#include <d_ldrtst.h>
    1.24 +
    1.25 +#ifdef __VC32__
    1.26 +#pragma warning(disable:4706)
    1.27 +#endif
    1.28 +
    1.29 +extern "C" TInt _E32Dll(TInt);
    1.30 +
    1.31 +extern "C" __MODULE_EXPORT TInt INITFUNC(MDllList&);
    1.32 +extern "C" __MODULE_EXPORT TInt CHKCFUNC();
    1.33 +extern "C" __MODULE_EXPORT TInt RBLKIFUNC(TInt, TInt);
    1.34 +
    1.35 +extern "C" __MODULE_IMPORT TInt BLKIFUNC(TInt);
    1.36 +
    1.37 +#ifdef __DLL_LINK_TO_EXE
    1.38 +extern "C" IMPORT_C void RegisterConstructorCall(TInt aDllNum);
    1.39 +extern "C" IMPORT_C void RegisterInitCall(TInt aDllNum);
    1.40 +extern "C" IMPORT_C void RegisterDestructorCall(TInt aDllNum);
    1.41 +#endif
    1.42 +
    1.43 +void GetDllInfo(SDllInfo& aInfo)
    1.44 +	{
    1.45 +	aInfo.iDllNum=DLLNUM;
    1.46 +	aInfo.iEntryPointAddress=((TInt)&_E32Dll);
    1.47 +	RLdrTest ldd;
    1.48 +	ldd.Open();
    1.49 +	aInfo.iModuleHandle=ldd.ModuleHandleFromAddr((TInt)&_E32Dll);
    1.50 +	ldd.Close();
    1.51 +	}
    1.52 +
    1.53 +#ifdef __MODULE_HAS_DATA
    1.54 +class TDllData
    1.55 +	{
    1.56 +public:
    1.57 +	TDllData();
    1.58 +	~TDllData();
    1.59 +public:
    1.60 +	TTime iStartTime;
    1.61 +	TTime iInitTime;
    1.62 +	TInt iTest1;
    1.63 +	TFileName iFileName;
    1.64 +	RLibrary iLib;
    1.65 +	};
    1.66 +
    1.67 +class TDllData2
    1.68 +	{
    1.69 +public:
    1.70 +	TDllData2();
    1.71 +	~TDllData2();
    1.72 +public:
    1.73 +	TInt iTest2;
    1.74 +	};
    1.75 +
    1.76 +TInt Bss[16];
    1.77 +TInt DllNum=DLLNUM;
    1.78 +TInt Generation=0;
    1.79 +TInt InitFlag=0;
    1.80 +TInt CDFlag=0;
    1.81 +TFullName StartThread=RThread().FullName();
    1.82 +TName StartProcess=RProcess().Name();
    1.83 +TDllData TheDllDataObject;
    1.84 +TDllData2 TheDllDataObject2;
    1.85 +
    1.86 +void AddToCDList()
    1.87 +	{
    1.88 +	MDllList* pM=(MDllList*)UserSvr::DllTls(TLS_INDEX);
    1.89 +	if (pM)
    1.90 +		{
    1.91 +		SDllInfo di;
    1.92 +		GetDllInfo(di);
    1.93 +		pM->Add(di);
    1.94 +		}
    1.95 +	}
    1.96 +
    1.97 +TDllData::TDllData()
    1.98 +	{
    1.99 +	CDFlag|=1;
   1.100 +	if (CDFlag==3)
   1.101 +		AddToCDList();
   1.102 +#ifndef __DLL_IN_CYCLE
   1.103 +	TInt r;
   1.104 +	CHKDEPS(r);		// Check our dependencies are initialised
   1.105 +	if (r!=KErrNone)
   1.106 +		User::Panic(_L("CHKDEPS"),r);
   1.107 +#endif
   1.108 +	iStartTime.HomeTime();
   1.109 +	iTest1=299792458;
   1.110 +	Dll::FileName(iFileName);
   1.111 +#ifdef __DLL_LINK_TO_EXE
   1.112 +	RegisterConstructorCall(DLLNUM);
   1.113 +#endif
   1.114 +	}
   1.115 +
   1.116 +TDllData::~TDllData()
   1.117 +	{
   1.118 +	CDFlag|=4;
   1.119 +	if (CDFlag==15)
   1.120 +		AddToCDList();
   1.121 +#ifdef __DLL_LINK_TO_EXE
   1.122 +	RegisterDestructorCall(DLLNUM);
   1.123 +#endif
   1.124 +	iLib.Close();
   1.125 +	}
   1.126 +
   1.127 +TDllData2::TDllData2()
   1.128 +	{
   1.129 +	CDFlag|=2;
   1.130 +	if (CDFlag==3)
   1.131 +		AddToCDList();
   1.132 +	iTest2=DLLNUM^0x3bb;
   1.133 +	iTest2*=iTest2;
   1.134 +	}
   1.135 +
   1.136 +TDllData2::~TDllData2()
   1.137 +	{
   1.138 +	CDFlag|=8;
   1.139 +	if (CDFlag==15)
   1.140 +		AddToCDList();
   1.141 +	}
   1.142 +#endif
   1.143 +
   1.144 +#ifdef __MODULE_HAS_DATA
   1.145 +void RecordInitCall()
   1.146 +	{
   1.147 +	TheDllDataObject.iInitTime.HomeTime();
   1.148 +	}
   1.149 +#endif
   1.150 +
   1.151 +extern "C" __MODULE_EXPORT TInt INITFUNC(MDllList& aList)
   1.152 +	{
   1.153 +	TInt r=KErrNone;
   1.154 +	SDllInfo info;
   1.155 +	GetDllInfo(info);
   1.156 +	if (!aList.IsPresent(info))
   1.157 +		{
   1.158 +		TInt pos=aList.Add(info);
   1.159 +		INITDEPS(r,aList);		// Call Init on our dependencies
   1.160 +		aList.MoveToEnd(pos);
   1.161 +#ifdef __MODULE_HAS_DATA
   1.162 +		if (r==KErrNone)
   1.163 +			r=CHKCFUNC();		// Check initial values for .data/.bss and check constructors have been called
   1.164 +		if (r==KErrNone)
   1.165 +			RecordInitCall();
   1.166 +#endif
   1.167 +#ifdef __DLL_LINK_TO_EXE
   1.168 +		RegisterInitCall(DLLNUM);
   1.169 +#endif
   1.170 +		}
   1.171 +	return r;
   1.172 +	}
   1.173 +
   1.174 +extern "C" __MODULE_EXPORT TInt CHKCFUNC()
   1.175 +	{
   1.176 +#ifdef __MODULE_HAS_DATA
   1.177 +	TInt i;
   1.178 +	TInt x=0;
   1.179 +	for (i=0; i<16; ++i) x|=Bss[i];
   1.180 +	if (x)
   1.181 +		return 0x425353;
   1.182 +	if (DllNum!=DLLNUM)
   1.183 +		return 0x44415441;
   1.184 +	if (TheDllDataObject.iTest1!=299792458)
   1.185 +		return 0x54455354;
   1.186 +	x=DLLNUM^0x3bb;
   1.187 +	x*=x;
   1.188 +	if (x!=TheDllDataObject2.iTest2)
   1.189 +		return 0x54535432;
   1.190 +	TInt init_mark=~((DLLNUM+DLLNUMOFFSET)*(DLLNUM+DLLNUMOFFSET));
   1.191 +	if (InitFlag==init_mark)
   1.192 +		return KErrNone;
   1.193 +	if (InitFlag!=0)
   1.194 +		return 0x494e4946;
   1.195 +	if (Generation!=0)
   1.196 +		return 0x47454e;
   1.197 +	if (StartProcess!=RProcess().Name())
   1.198 +		return 0x535450;
   1.199 +	TFileName fn;
   1.200 +	Dll::FileName(fn);
   1.201 +	if (fn!=TheDllDataObject.iFileName)
   1.202 +		return 0x464e414d;
   1.203 +	InitFlag=init_mark;
   1.204 +	RDebug::Print(_L("ChkC %S OK"),&fn);
   1.205 +#endif
   1.206 +	return KErrNone;
   1.207 +	}
   1.208 +
   1.209 +extern "C" __MODULE_EXPORT TInt GetGeneration()
   1.210 +	{
   1.211 +#ifdef __MODULE_HAS_DATA
   1.212 +	return Generation;
   1.213 +#else
   1.214 +	return 0;
   1.215 +#endif
   1.216 +	}
   1.217 +
   1.218 +extern "C" __MODULE_EXPORT TInt RBLKIFUNC(TInt aInput, TInt aGeneration)
   1.219 +	{
   1.220 +	(void)aGeneration;
   1.221 +#ifdef __MODULE_HAS_DATA
   1.222 +	TInt r=aInput;
   1.223 +	if (aGeneration!=Generation)
   1.224 +		{
   1.225 +		Generation=aGeneration;
   1.226 +		r=BLKIFUNC(aInput);
   1.227 +		RBLKIFUNC_DEPS(r,aGeneration);
   1.228 +		}
   1.229 +	return r;
   1.230 +#else
   1.231 +	return aInput;
   1.232 +#endif
   1.233 +	}
   1.234 +
   1.235 +extern "C" __MODULE_EXPORT void SetCloseLib(TInt aLibHandle)
   1.236 +	{
   1.237 +	(void)aLibHandle;
   1.238 +#ifdef __MODULE_HAS_DATA
   1.239 +	TheDllDataObject.iLib.SetHandle(aLibHandle);
   1.240 +#endif
   1.241 +	}