os/kernelhwsrv/kerneltest/f32test/loader/security/t_ldrtst.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // f32test\loader\t_ldrtst.h
    15 // 
    16 //
    17 
    18 #ifndef __T_LDRTST_H__
    19 #define __T_LDRTST_H__
    20 
    21 #define __INCLUDE_DEPENDENCY_GRAPH
    22 
    23 #include <e32svr.h>
    24 #include <e32test.h>
    25 #include "dlltree.h"
    26 #include "dllt.h"
    27 #include "exetifc.h"
    28 #include <d_ldrtst.h>
    29 #include <f32file.h>
    30 #include <f32dbg.h>
    31 #include <e32rom.h>
    32 
    33 GLREF_D RTest test;
    34 
    35 class TModuleList;
    36 class TModuleSet
    37 	{
    38 public:
    39 	TModuleSet();
    40 	TModuleSet(const TModuleList&, TInt aMask, TInt aVal);
    41 	void Add(TInt aModule);
    42 	void Remove(TInt aModule);
    43 	void Remove(const TModuleList&);
    44 	void Display(const TDesC& aTitle) const;
    45 	inline TBool Present(TInt aModule) const
    46 		{ return iBitMap[aModule>>3]&(1<<(aModule&7)); }
    47 public:
    48 	TInt iCount;
    49 	TUint8 iBitMap[(KNumModules+7)/8];
    50 	};
    51 
    52 class TModuleList
    53 	{
    54 public:
    55 	TModuleList();
    56 	void SetCount();
    57 	void Display(const TDesC& aTitle) const;
    58 	TBool IsPresent(TInt aModNum) const;
    59 	TInt Find(TInt aModNum) const;
    60 	void Add(const SDllInfo& a);
    61 public:
    62 	TInt iCount;
    63 	SDllInfo iInfo[KNumModules];
    64 	};
    65 
    66 class LoaderTest
    67 	{
    68 public:
    69 	static LoaderTest* New();
    70 	void Close();
    71 	void Init();
    72 public:
    73 	void TestOneByOne();
    74 	void TestMultipleExeInstances();
    75 	void TestOOM();
    76 	void TestMultipleLoads();
    77 private:
    78 	TBool IsRomAddress(TLinAddr a);
    79 	TBool IsRamCodeAddress(TLinAddr a);
    80 	TBool CheckDataAddress(TLinAddr a, TInt aDllNum, TInt aExeNum);
    81 	TInt DetermineDllLoadResult(TInt aDllNum, TInt aExeNum);
    82 	TInt DetermineDllLoadResult(TInt aDllNum, TInt aExeNum1, TInt aExeNum2);
    83 	TInt DetermineLoadExe2Result(TInt aExeNum);
    84 	void DumpModuleList(const TModuleList& aList, TInt aExeNum);
    85 	void DumpModuleInfo(const SDllInfo& aInfo, TInt aExeNum);
    86 	void CheckModuleList(TInt aRoot, const TModuleList& aList);
    87 public:
    88 	void TraceOn();
    89 	void TraceOff();
    90 private:
    91 	LoaderTest();
    92 	~LoaderTest();
    93 public:
    94 	RFs iFs;
    95 	RLdrTest iDev;
    96 	TUint32 iMemModelAtt;
    97 	TInt iCmdLine[8];
    98 	};
    99 
   100 
   101 const TInt KMaxHandlesPerDll=4;
   102 const TInt KMaxHandles=KMaxHandlesPerDll*KNumModules;
   103 
   104 struct SModuleInstance
   105 	{
   106 	TInt iAccessCount;
   107 	TInt iModNum;
   108 	TLinAddr iEntryPointAddress;
   109 	TModuleHandle iModuleHandle;
   110 	TLinAddr iData;
   111 	TAny* iCodeSeg;
   112 	};
   113 
   114 class CGlobalModuleList;
   115 class CPerProcessInfo : public CBase
   116 	{
   117 public:
   118 	static CPerProcessInfo* New(TInt aExeNum, CGlobalModuleList& aG);
   119 	virtual ~CPerProcessInfo();
   120 	void GetModuleSet(TModuleSet& aSet);
   121 	void Check();
   122 	void Unlink(const SDllInfo& a, TModuleList& aList);
   123 	TInt Load(TInt aDllNum);
   124 	TInt AddModules(TInt aDllNum, TModuleList* aCList, TModuleList* aIList);
   125 	TInt CloseHandle(TInt aHandle);
   126 private:
   127 	CPerProcessInfo();
   128 	TInt Init();
   129 public:
   130 	TInt iExeNum;
   131 	TRequestStatus iStatus;
   132 	RProcess iProcess;
   133 	RLoaderTest iSession;
   134 	RLdrTest iDev;
   135 	CGlobalModuleList* iGlobalList;
   136 	TInt iModuleNum[KMaxHandles];
   137 	TInt iHandleCount[KNumModules];
   138 	SModuleInstance* iModules[KNumModules];
   139 	};
   140 
   141 class CGlobalModuleList : public CBase
   142 	{
   143 public:
   144 	static CGlobalModuleList* New(const LoaderTest&);
   145 	virtual ~CGlobalModuleList();
   146 	void Close(SModuleInstance* a);
   147 	void Free(SModuleInstance* a);
   148 	SModuleInstance* GetMI();
   149 	TAny* CodeSegFromHandle(TModuleHandle aModHandle);
   150 	void CheckAll();
   151 	TInt Load(TInt aExeNum, TInt aDllNum);
   152 	TInt CloseHandle(TInt aExeNum, TInt aDllNum);
   153 private:
   154 	CGlobalModuleList();
   155 	void Init();
   156 public:
   157 	TInt iMaxModules;
   158 	TInt iNumExes;
   159 	TInt iFixedExes;
   160 	TInt iParam;
   161 	RLdrTest iDev;
   162 	TUint32 iMemModelAtt;
   163 	CPerProcessInfo* iPPInfo[KNumModules];
   164 	RPointerArray<SModuleInstance> iModules;
   165 	SModuleInstance* iModuleAlloc;
   166 	SModuleInstance* iFreeModules;
   167 	};
   168 
   169 #endif