Update FwImage to zero .xdata information if the image type is X64 and all debug...
authormdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 4 Oct 2006 23:02:50 +0000 (23:02 +0000)
committermdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 4 Oct 2006 23:02:50 +0000 (23:02 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1659 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/TianoTools/FwImage/fwimage.c

index 0097a94..5dd1634 100644 (file)
@@ -164,12 +164,16 @@ Returns:
   EFI_IMAGE_DOS_HEADER  BackupDosHdr;\r
   ULONG             Index;\r
   ULONG             Index1;\r
   EFI_IMAGE_DOS_HEADER  BackupDosHdr;\r
   ULONG             Index;\r
   ULONG             Index1;\r
+  ULONG             Index2;\r
+  ULONG             Index3;\r
   BOOLEAN           TimeStampPresent;\r
   UINTN                                 AllignedRelocSize;\r
   UINTN                                 Delta;\r
   EFI_IMAGE_SECTION_HEADER              *SectionHeader;\r
   UINT8      *FileBuffer;\r
   UINTN      FileLength;\r
   BOOLEAN           TimeStampPresent;\r
   UINTN                                 AllignedRelocSize;\r
   UINTN                                 Delta;\r
   EFI_IMAGE_SECTION_HEADER              *SectionHeader;\r
   UINT8      *FileBuffer;\r
   UINTN      FileLength;\r
+  RUNTIME_FUNCTION  *RuntimeFunction;\r
+  UNWIND_INFO       *UnwindInfo;\r
 \r
   SetUtilityName (UTILITY_NAME);\r
   //\r
 \r
   SetUtilityName (UTILITY_NAME);\r
   //\r
@@ -373,26 +377,6 @@ Returns:
     Optional32->SizeOfHeapReserve  = 0;\r
     Optional32->SizeOfHeapCommit   = 0;\r
 \r
     Optional32->SizeOfHeapReserve  = 0;\r
     Optional32->SizeOfHeapCommit   = 0;\r
 \r
-    //\r
-    // Zero the .pdata section if the machine type is X64 and the Debug Directoty entry is empty\r
-    //\r
-    if (PeHdr->FileHeader.Machine == 0x8664) { // X64\r
-      if (Optional32->NumberOfRvaAndSizes >= 4) {\r
-        if (Optional32->NumberOfRvaAndSizes < 7 || (Optional32->NumberOfRvaAndSizes >= 7 && Optional32->DataDirectory[6].Size == 0)) {\r
-          SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);\r
-          for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) {\r
-            if (SectionHeader->VirtualAddress == Optional32->DataDirectory[3].VirtualAddress) {\r
-              for (Index1 = 0; Index1 < Optional32->DataDirectory[3].Size; Index1++) {\r
-                FileBuffer[SectionHeader->PointerToRawData + Index1] = 0;\r
-              }\r
-            }\r
-          }\r
-          Optional32->DataDirectory[3].Size = 0;\r
-          Optional32->DataDirectory[3].VirtualAddress = 0;\r
-        }\r
-      }\r
-    }\r
-\r
     //\r
     // Strip zero padding at the end of the .reloc section \r
     //\r
     //\r
     // Strip zero padding at the end of the .reloc section \r
     //\r
@@ -454,8 +438,19 @@ Returns:
           SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);\r
           for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) {\r
             if (SectionHeader->VirtualAddress == Optional64->DataDirectory[3].VirtualAddress) {\r
           SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);\r
           for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) {\r
             if (SectionHeader->VirtualAddress == Optional64->DataDirectory[3].VirtualAddress) {\r
-              for (Index1 = 0; Index1 < Optional64->DataDirectory[3].Size; Index1++) {\r
-                FileBuffer[SectionHeader->PointerToRawData + Index1] = 0;\r
+              RuntimeFunction = (RUNTIME_FUNCTION *)(FileBuffer + SectionHeader->PointerToRawData);\r
+              for (Index1 = 0; Index1 < Optional64->DataDirectory[3].Size / sizeof (RUNTIME_FUNCTION); Index1++, RuntimeFunction++) {\r
+                SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);\r
+                for (Index2 = 0; Index2 < PeHdr->FileHeader.NumberOfSections; Index2++, SectionHeader++) {\r
+                  if (RuntimeFunction->UnwindInfoAddress > SectionHeader->VirtualAddress && RuntimeFunction->UnwindInfoAddress < (SectionHeader->VirtualAddress + SectionHeader->SizeOfRawData)) {\r
+                    UnwindInfo = (UNWIND_INFO *)(FileBuffer + SectionHeader->PointerToRawData + (RuntimeFunction->UnwindInfoAddress - SectionHeader->VirtualAddress));\r
+                    if (UnwindInfo->Version == 1) {\r
+                      memset (UnwindInfo + 1, 0, UnwindInfo->CountOfUnwindCodes * sizeof (UINT16));\r
+                      memset (UnwindInfo, 0, sizeof (UNWIND_INFO));\r
+                    }\r
+                  }\r
+                }\r
+                memset (RuntimeFunction, 0, sizeof (RUNTIME_FUNCTION));\r
               }\r
             }\r
           }\r
               }\r
             }\r
           }\r