os/kernelhwsrv/kerneltest/e32test/dll/oe/t_oeexport.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-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 // e32test\dll\t_oeexport.cpp
    15 // Overview:
    16 // Tests it is possible to retrieve the 0th ordinal from exes and dlls
    17 // that are marked as having named symbol export data.  This is loaded
    18 // as non-XIP so loader fixups of 0th ordinal imports can be tested
    19 // API Information:
    20 // RProcess, RLibrary
    21 // Details:
    22 // - 	Test reading 0th ordinal from a dll which has a E32EpocExpSymInfoHdr 
    23 // struct at the 0th ordinal and verify the contents of the header
    24 // -	Test attempts to get the 0th ordinal from a dll without the named symbol 
    25 // data returns NULL
    26 // -	Test reading the named symbol data from an exe that contains a
    27 // E32EpocExpSymInfoHdr struct at the 0th ordinal and verify the contents
    28 // -	Test import fixups has correctly fixed up the 0th ordinal of the static
    29 // dependencies to this stdexe
    30 // -	Test NULL is returned when attempting to read the 0th ordinal of
    31 // an exe that doesn't contain a E32EpocExpSymInfoHdr
    32 // Platforms/Drives/Compatibility:
    33 // All
    34 // Assumptions/Requirement/Pre-requisites:
    35 // Failures and causes:
    36 // Base Port information:
    37 // 
    38 //
    39 
    40 #include <t_oedll.h>
    41 #include <e32test.h>
    42 #include <e32panic.h>
    43 #include <f32image.h>
    44 
    45 RTest test(_L("T_OEEXPORT"));
    46 
    47 // This is defined as LOCAL_D(static) to ensure that tools allow static symbol in stdexe/dlls
    48 // as this was not always the case.
    49 LOCAL_D void VerifyHdr(E32EpocExpSymInfoHdr& aExpectedHdr, E32EpocExpSymInfoHdr &aReadHdr)
    50 	{
    51 	test(aExpectedHdr.iSize == aReadHdr.iSize);
    52 	test(aExpectedHdr.iFlags == aReadHdr.iFlags);
    53 	test(aExpectedHdr.iSymCount == aReadHdr.iSymCount);
    54 	test(aExpectedHdr.iSymbolTblOffset == aReadHdr.iSymbolTblOffset);
    55 	test(aExpectedHdr.iStringTableSz == aReadHdr.iStringTableSz);
    56 	test(aExpectedHdr.iStringTableOffset == aReadHdr.iStringTableOffset);
    57 	test(aExpectedHdr.iDllCount == aReadHdr.iDllCount);
    58 	test(aExpectedHdr.iDepDllZeroOrdTableOffset == aReadHdr.iDepDllZeroOrdTableOffset);
    59 	}
    60 
    61 TInt E32Main()
    62 	{
    63 	test.Title();
    64 
    65 	test.Start(_L("Test retrieving 0th ordinal and therefore named symbol export data"));
    66 	
    67 	E32EpocExpSymInfoHdr tmpHdr;
    68 	E32EpocExpSymInfoHdr *readHdr;
    69 	RLibrary library;
    70 
    71 	// The values for the header of the dll with a 0th ordinal
    72 	tmpHdr.iSize = 0x1a4;
    73 	tmpHdr.iFlags = 0x0;
    74 	tmpHdr.iSymCount = 0xc;	
    75 	tmpHdr.iSymbolTblOffset = 0x1c;
    76 	tmpHdr.iStringTableSz = 0x134;
    77 	tmpHdr.iStringTableOffset = 0x64;
    78 	tmpHdr.iDllCount = 0x3;	
    79 	tmpHdr.iDepDllZeroOrdTableOffset = 0x198;
    80 	test(library.Load(_L("t_oedll.dll")) == KErrNone);
    81 	test.Next(_L("Attempt to retrieve named symbol data from t_oedll.dll"));
    82 	readHdr = (E32EpocExpSymInfoHdr*)library.Lookup(0);
    83 	test(readHdr!=NULL);
    84 	test.Next(_L("Verify export data of t_oedll.dll at the 0th ordinal is that expected"));
    85 	VerifyHdr(tmpHdr, *readHdr);
    86 	library.Close();
    87 
    88 	test.Next(_L("Verify lookup on dll without oe export data returns NULL"));
    89 	test(library.Load(_L("t_dll1.dll")) == KErrNone);
    90 	readHdr = (E32EpocExpSymInfoHdr*)library.Lookup(0);
    91 	test(readHdr == NULL);
    92 	library.Close();
    93 
    94 	// The values for the header of the exe of the current process with a 0th ordinal
    95 	tmpHdr.iSize = 0x48;
    96 	tmpHdr.iFlags = 0x0;
    97 	tmpHdr.iSymCount = 0x2;
    98 	tmpHdr.iSymbolTblOffset = 0x1c;
    99 	tmpHdr.iStringTableSz = 0x14;
   100 	tmpHdr.iStringTableOffset = 0x28;
   101 	tmpHdr.iDllCount = 0x3;
   102 	tmpHdr.iDepDllZeroOrdTableOffset = 0x3c;
   103 	test.Next(_L("Attempt to retrieve named symbol data from current process"));
   104 	readHdr = (E32EpocExpSymInfoHdr*)(RProcess::ExeExportData());
   105 	test(readHdr!=NULL);
   106 	test.Next(_L("Verify export data at th 0th ordinal of this exe is that expected"));
   107 
   108 //#define PRINT_ZEROTH
   109 #ifdef PRINT_ZEROTH
   110 	test.Printf(_L("iSize=%08x;iFlags=%08x;iSymCount=%08x;iSymbolTblOffset=%08x\n"),readHdr->iSize,readHdr->iFlags,readHdr->iSymCount,readHdr->iSymbolTblOffset);
   111 	test.Printf(_L("iStringTableSz=%08x,iStringTableOffset=%08x,iDllCount=%08x,iDepDllZeroOrdTableOffset=%08x\n"), readHdr->iStringTableSz, readHdr->iStringTableOffset,readHdr->iDllCount,readHdr->iDepDllZeroOrdTableOffset);
   112 #endif
   113 	VerifyHdr(tmpHdr, *readHdr);
   114 
   115 	test.Next(_L("Verify static dependency t_oedll1 has been fixed up correctly"));
   116 	test(myfoo()==0x1234);
   117 
   118 	// Get the 0th ordinal data from the dependency t_oedll1 and verify it
   119 	readHdr=(E32EpocExpSymInfoHdr *)((TUint32)readHdr+readHdr->iDepDllZeroOrdTableOffset);
   120 	TUint32 readHdrEnd = (TUint32)readHdr + 12;
   121 	// This stdexe only links one stddll so the only non-NULL entry in iDepDllZeroOrdTable
   122 	// should point to 0th ordinal of t_oedll1
   123 	while (*(TUint32*)readHdr == NULL && (TUint32)readHdr < readHdrEnd)
   124 		{
   125 		readHdr=(E32EpocExpSymInfoHdr *)(((TUint32*)readHdr)+1);
   126 		}
   127 
   128 #ifdef PRINT_ZEROTH
   129 	test.Printf(_L("iSize=%08x;iFlags=%08x;iSymCount=%08x;iSymbolTblOffset=%08x\n"),(*(E32EpocExpSymInfoHdr**)readHdr)->iSize,(*(E32EpocExpSymInfoHdr**)readHdr)->iFlags,(*(E32EpocExpSymInfoHdr**)readHdr)->iSymCount,(*(E32EpocExpSymInfoHdr**)readHdr)->iSymbolTblOffset);
   130 	test.Printf(_L("iStringTableSz=%08x,iStringTableOffset=%08x,iDllCount=%08x,iDepDllZeroOrdTableOffset=%08x\n"), (*(E32EpocExpSymInfoHdr**)readHdr)->iStringTableSz, (*(E32EpocExpSymInfoHdr**)readHdr)->iStringTableOffset,(*(E32EpocExpSymInfoHdr**)readHdr)->iDllCount,(*(E32EpocExpSymInfoHdr**)readHdr)->iDepDllZeroOrdTableOffset);
   131 #endif
   132 
   133 	tmpHdr.iSize = 0x1a4;
   134 	tmpHdr.iFlags = 0x0;
   135 	tmpHdr.iSymCount = 0xc;	
   136 	tmpHdr.iSymbolTblOffset = 0x1c;
   137 	tmpHdr.iStringTableSz = 0x134;
   138 	tmpHdr.iStringTableOffset = 0x64;
   139 	tmpHdr.iDllCount = 0x3;	
   140 	tmpHdr.iDepDllZeroOrdTableOffset = 0x198;
   141 	VerifyHdr(tmpHdr,**(E32EpocExpSymInfoHdr**)readHdr);
   142 	
   143 	test.End();
   144 	return KErrNone;
   145 	}