os/kernelhwsrv/kerneltest/f32test/loader/security/dllt.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1999-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
// f32test\loader\security\dllt.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32svr.h>
sl@0
    19
#include "dllt.h"
sl@0
    20
#include <d_ldrtst.h>
sl@0
    21
sl@0
    22
#ifdef __VC32__
sl@0
    23
#pragma warning(disable:4706)
sl@0
    24
#endif
sl@0
    25
sl@0
    26
extern "C" TInt _E32Dll(TInt);
sl@0
    27
sl@0
    28
extern "C" __MODULE_EXPORT TInt INITFUNC(MDllList&);
sl@0
    29
extern "C" __MODULE_EXPORT TInt CHKCFUNC();
sl@0
    30
extern "C" __MODULE_EXPORT TInt RBLKIFUNC(TInt, TInt);
sl@0
    31
sl@0
    32
extern "C" __MODULE_IMPORT TInt BLKIFUNC(TInt);
sl@0
    33
sl@0
    34
#ifdef __DLL_LINK_TO_EXE
sl@0
    35
extern "C" IMPORT_C void RegisterConstructorCall(TInt aDllNum);
sl@0
    36
extern "C" IMPORT_C void RegisterInitCall(TInt aDllNum);
sl@0
    37
extern "C" IMPORT_C void RegisterDestructorCall(TInt aDllNum);
sl@0
    38
#endif
sl@0
    39
sl@0
    40
void GetDllInfo(SDllInfo& aInfo)
sl@0
    41
	{
sl@0
    42
	aInfo.iDllNum=DLLNUM;
sl@0
    43
	aInfo.iEntryPointAddress=((TInt)&_E32Dll);
sl@0
    44
	RLdrTest ldd;
sl@0
    45
	ldd.Open();
sl@0
    46
	aInfo.iModuleHandle=ldd.ModuleHandleFromAddr((TInt)&_E32Dll);
sl@0
    47
	ldd.Close();
sl@0
    48
	}
sl@0
    49
sl@0
    50
#ifdef __MODULE_HAS_DATA
sl@0
    51
class TDllData
sl@0
    52
	{
sl@0
    53
public:
sl@0
    54
	TDllData();
sl@0
    55
	~TDllData();
sl@0
    56
public:
sl@0
    57
	TTime iStartTime;
sl@0
    58
	TTime iInitTime;
sl@0
    59
	TInt iTest1;
sl@0
    60
	TFileName iFileName;
sl@0
    61
	RLibrary iLib;
sl@0
    62
	};
sl@0
    63
sl@0
    64
class TDllData2
sl@0
    65
	{
sl@0
    66
public:
sl@0
    67
	TDllData2();
sl@0
    68
	~TDllData2();
sl@0
    69
public:
sl@0
    70
	TInt iTest2;
sl@0
    71
	};
sl@0
    72
sl@0
    73
TInt Bss[16];
sl@0
    74
TInt DllNum=DLLNUM;
sl@0
    75
TInt Generation=0;
sl@0
    76
TInt InitFlag=0;
sl@0
    77
TInt CDFlag=0;
sl@0
    78
TFullName StartThread=RThread().FullName();
sl@0
    79
TName StartProcess=RProcess().Name();
sl@0
    80
TDllData TheDllDataObject;
sl@0
    81
TDllData2 TheDllDataObject2;
sl@0
    82
sl@0
    83
void AddToCDList()
sl@0
    84
	{
sl@0
    85
	MDllList* pM=(MDllList*)UserSvr::DllTls(TLS_INDEX);
sl@0
    86
	if (pM)
sl@0
    87
		{
sl@0
    88
		SDllInfo di;
sl@0
    89
		GetDllInfo(di);
sl@0
    90
		pM->Add(di);
sl@0
    91
		}
sl@0
    92
	}
sl@0
    93
sl@0
    94
TDllData::TDllData()
sl@0
    95
	{
sl@0
    96
	CDFlag|=1;
sl@0
    97
	if (CDFlag==3)
sl@0
    98
		AddToCDList();
sl@0
    99
#ifndef __DLL_IN_CYCLE
sl@0
   100
	TInt r;
sl@0
   101
	CHKDEPS(r);		// Check our dependencies are initialised
sl@0
   102
	if (r!=KErrNone)
sl@0
   103
		User::Panic(_L("CHKDEPS"),r);
sl@0
   104
#endif
sl@0
   105
	iStartTime.HomeTime();
sl@0
   106
	iTest1=299792458;
sl@0
   107
	Dll::FileName(iFileName);
sl@0
   108
#ifdef __DLL_LINK_TO_EXE
sl@0
   109
	RegisterConstructorCall(DLLNUM);
sl@0
   110
#endif
sl@0
   111
	}
sl@0
   112
sl@0
   113
TDllData::~TDllData()
sl@0
   114
	{
sl@0
   115
	CDFlag|=4;
sl@0
   116
	if (CDFlag==15)
sl@0
   117
		AddToCDList();
sl@0
   118
#ifdef __DLL_LINK_TO_EXE
sl@0
   119
	RegisterDestructorCall(DLLNUM);
sl@0
   120
#endif
sl@0
   121
	iLib.Close();
sl@0
   122
	}
sl@0
   123
sl@0
   124
TDllData2::TDllData2()
sl@0
   125
	{
sl@0
   126
	CDFlag|=2;
sl@0
   127
	if (CDFlag==3)
sl@0
   128
		AddToCDList();
sl@0
   129
	iTest2=DLLNUM^0x3bb;
sl@0
   130
	iTest2*=iTest2;
sl@0
   131
	}
sl@0
   132
sl@0
   133
TDllData2::~TDllData2()
sl@0
   134
	{
sl@0
   135
	CDFlag|=8;
sl@0
   136
	if (CDFlag==15)
sl@0
   137
		AddToCDList();
sl@0
   138
	}
sl@0
   139
#endif
sl@0
   140
sl@0
   141
#ifdef __MODULE_HAS_DATA
sl@0
   142
void RecordInitCall()
sl@0
   143
	{
sl@0
   144
	TheDllDataObject.iInitTime.HomeTime();
sl@0
   145
	}
sl@0
   146
#endif
sl@0
   147
sl@0
   148
extern "C" __MODULE_EXPORT TInt INITFUNC(MDllList& aList)
sl@0
   149
	{
sl@0
   150
	TInt r=KErrNone;
sl@0
   151
	SDllInfo info;
sl@0
   152
	GetDllInfo(info);
sl@0
   153
	if (!aList.IsPresent(info))
sl@0
   154
		{
sl@0
   155
		TInt pos=aList.Add(info);
sl@0
   156
		INITDEPS(r,aList);		// Call Init on our dependencies
sl@0
   157
		aList.MoveToEnd(pos);
sl@0
   158
#ifdef __MODULE_HAS_DATA
sl@0
   159
		if (r==KErrNone)
sl@0
   160
			r=CHKCFUNC();		// Check initial values for .data/.bss and check constructors have been called
sl@0
   161
		if (r==KErrNone)
sl@0
   162
			RecordInitCall();
sl@0
   163
#endif
sl@0
   164
#ifdef __DLL_LINK_TO_EXE
sl@0
   165
		RegisterInitCall(DLLNUM);
sl@0
   166
#endif
sl@0
   167
		}
sl@0
   168
	return r;
sl@0
   169
	}
sl@0
   170
sl@0
   171
extern "C" __MODULE_EXPORT TInt CHKCFUNC()
sl@0
   172
	{
sl@0
   173
#ifdef __MODULE_HAS_DATA
sl@0
   174
	TInt i;
sl@0
   175
	TInt x=0;
sl@0
   176
	for (i=0; i<16; ++i) x|=Bss[i];
sl@0
   177
	if (x)
sl@0
   178
		return 0x425353;
sl@0
   179
	if (DllNum!=DLLNUM)
sl@0
   180
		return 0x44415441;
sl@0
   181
	if (TheDllDataObject.iTest1!=299792458)
sl@0
   182
		return 0x54455354;
sl@0
   183
	x=DLLNUM^0x3bb;
sl@0
   184
	x*=x;
sl@0
   185
	if (x!=TheDllDataObject2.iTest2)
sl@0
   186
		return 0x54535432;
sl@0
   187
	TInt init_mark=~((DLLNUM+DLLNUMOFFSET)*(DLLNUM+DLLNUMOFFSET));
sl@0
   188
	if (InitFlag==init_mark)
sl@0
   189
		return KErrNone;
sl@0
   190
	if (InitFlag!=0)
sl@0
   191
		return 0x494e4946;
sl@0
   192
	if (Generation!=0)
sl@0
   193
		return 0x47454e;
sl@0
   194
	if (StartProcess!=RProcess().Name())
sl@0
   195
		return 0x535450;
sl@0
   196
	TFileName fn;
sl@0
   197
	Dll::FileName(fn);
sl@0
   198
	if (fn!=TheDllDataObject.iFileName)
sl@0
   199
		return 0x464e414d;
sl@0
   200
	InitFlag=init_mark;
sl@0
   201
	RDebug::Print(_L("ChkC %S OK"),&fn);
sl@0
   202
#endif
sl@0
   203
	return KErrNone;
sl@0
   204
	}
sl@0
   205
sl@0
   206
extern "C" __MODULE_EXPORT TInt GetGeneration()
sl@0
   207
	{
sl@0
   208
#ifdef __MODULE_HAS_DATA
sl@0
   209
	return Generation;
sl@0
   210
#else
sl@0
   211
	return 0;
sl@0
   212
#endif
sl@0
   213
	}
sl@0
   214
sl@0
   215
extern "C" __MODULE_EXPORT TInt RBLKIFUNC(TInt aInput, TInt aGeneration)
sl@0
   216
	{
sl@0
   217
	(void)aGeneration;
sl@0
   218
#ifdef __MODULE_HAS_DATA
sl@0
   219
	TInt r=aInput;
sl@0
   220
	if (aGeneration!=Generation)
sl@0
   221
		{
sl@0
   222
		Generation=aGeneration;
sl@0
   223
		r=BLKIFUNC(aInput);
sl@0
   224
		RBLKIFUNC_DEPS(r,aGeneration);
sl@0
   225
		}
sl@0
   226
	return r;
sl@0
   227
#else
sl@0
   228
	return aInput;
sl@0
   229
#endif
sl@0
   230
	}
sl@0
   231
sl@0
   232
extern "C" __MODULE_EXPORT void SetCloseLib(TInt aLibHandle)
sl@0
   233
	{
sl@0
   234
	(void)aLibHandle;
sl@0
   235
#ifdef __MODULE_HAS_DATA
sl@0
   236
	TheDllDataObject.iLib.SetHandle(aLibHandle);
sl@0
   237
#endif
sl@0
   238
	}