test_oeexe.cpp 5.9 KB

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