From nobody Sat Nov 2 12:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1491053146840196.0124213798133; Sat, 1 Apr 2017 06:25:46 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5F6D0219392F5; Sat, 1 Apr 2017 06:25:39 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C4431219392E6 for ; Sat, 1 Apr 2017 06:25:37 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP; 01 Apr 2017 06:25:37 -0700 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga004.fm.intel.com with ESMTP; 01 Apr 2017 06:25:36 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,257,1486454400"; d="scan'208";a="242805986" From: Jeff Fan To: edk2-devel@lists.01.org Date: Sat, 1 Apr 2017 21:25:25 +0800 Message-Id: <20170401132530.8340-5-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170401132530.8340-1-jeff.fan@intel.com> References: <20170401132530.8340-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 4/9] UefiCpuPkg/CpuExceptionHandlerLib: Add DumpModuleImageInfo() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian , Jiewen Yao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add internal DumpModuleImageInfo() to replace FindModuleImageBase(). It will consume PeCoffGetEntrypointLib's PeCoffSerachImageBase() to get PE/COFF ima= ge base. Cc: Jiewen Yao Cc: Michael Kinney Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- .../CpuExceptionHandlerLib/CpuExceptionCommon.c | 75 ++++++------------= ---- .../CpuExceptionHandlerLib/CpuExceptionCommon.h | 11 +--- .../Library/CpuExceptionHandlerLib/DxeException.c | 7 +- .../Ia32/ArchExceptionHandler.c | 15 +---- .../CpuExceptionHandlerLib/PeiCpuException.c | 6 +- .../CpuExceptionHandlerLib/SecPeiCpuException.c | 4 -- .../Library/CpuExceptionHandlerLib/SmmException.c | 7 +- .../X64/ArchExceptionHandler.c | 12 +--- 8 files changed, 30 insertions(+), 107 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c index 3d85b0c..6080d1e 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c @@ -113,75 +113,40 @@ InternalPrintMessage ( @return !0 Image base address. @return 0 Image header cannot be found. **/ -UINTN -FindModuleImageBase ( - IN UINTN CurrentEip, - OUT UINTN *EntryPoint +VOID +DumpModuleImageInfo ( + IN UINTN CurrentEip ) { + EFI_STATUS Status; UINTN Pe32Data; - EFI_IMAGE_DOS_HEADER *DosHdr; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; VOID *PdbPointer; + VOID *EntryPoint; =20 - // - // Find Image Base - // - Pe32Data =3D CurrentEip & ~(mImageAlignSize - 1); - while (Pe32Data !=3D 0) { - DosHdr =3D (EFI_IMAGE_DOS_HEADER *) Pe32Data; - if (DosHdr->e_magic =3D=3D EFI_IMAGE_DOS_SIGNATURE) { - // - // DOS image header is present, so read the PE header after the DOS = image header. - // - Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN) ((DosHdr-= >e_lfanew) & 0x0ffff)); - // - // Make sure PE header address does not overflow and is less than th= e initial address. - // - if (((UINTN)Hdr.Pe32 > Pe32Data) && ((UINTN)Hdr.Pe32 < CurrentEip)) { - if (Hdr.Pe32->Signature =3D=3D EFI_IMAGE_NT_SIGNATURE) { - // - // It's PE image. - // - InternalPrintMessage ("!!!! Find PE image "); - *EntryPoint =3D (UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHead= er.AddressOfEntryPoint & 0x0ffffffff); - break; - } - } - } else { - // - // DOS image header is not present, TE header is at the image base. - // - Hdr.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)Pe32Data; - if ((Hdr.Te->Signature =3D=3D EFI_TE_IMAGE_HEADER_SIGNATURE) && - ((Hdr.Te->Machine =3D=3D IMAGE_FILE_MACHINE_I386) || Hdr.Te->Mac= hine =3D=3D IMAGE_FILE_MACHINE_X64)) { - // - // It's TE image, it TE header and Machine type match - // - InternalPrintMessage ("!!!! Find TE image "); - *EntryPoint =3D (UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPo= int & 0x0ffffffff) + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize; - break; - } - } - + Pe32Data =3D PeCoffSerachImageBase (CurrentEip); + if (Pe32Data =3D=3D 0) { + InternalPrintMessage ("!!!! Can't find image information. !!!!\n"); + } else { // - // Not found the image base, check the previous aligned address + // Find Image Base entry point // - Pe32Data -=3D mImageAlignSize; - } - - if (Pe32Data !=3D 0) { + Status =3D PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, &EntryPoint); + if (EFI_ERROR (Status)) { + EntryPoint =3D NULL; + } + InternalPrintMessage ("!!!! Find image "); PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data); if (PdbPointer !=3D NULL) { InternalPrintMessage ("%a", PdbPointer); } else { InternalPrintMessage ("(No PDB) " ); } - } else { - InternalPrintMessage ("!!!! Can't find image information. !!!!\n"); + InternalPrintMessage ( + " (ImageBase=3D%016lp, EntryPoint=3D%016p) !!!!\n", + (VOID *) Pe32Data, + EntryPoint + ); } - - return Pe32Data; } =20 /** diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h index 9adb6a1..0047ad6 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h @@ -53,7 +53,6 @@ typedef struct { } EXCEPTION_HANDLER_DATA; =20 extern CONST UINT32 mErrorCodeFlag; -extern CONST UINTN mImageAlignSize; extern CONST UINTN mDoFarReturnFlag; =20 /** @@ -112,15 +111,11 @@ InternalPrintMessage ( Find and display image base address and return image base and its entry = point. =20 @param CurrentEip Current instruction pointer. - @param EntryPoint Return module entry point if module header is fou= nd. =20 - @return !0 Image base address. - @return 0 Image header cannot be found. **/ -UINTN=20 -FindModuleImageBase ( - IN UINTN CurrentEip, - OUT UINTN *EntryPoint +VOID=20 +DumpModuleImageInfo ( + IN UINTN CurrentEip ); =20 /** diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c b/Uef= iCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c index a61a52b..ab13e5e 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c @@ -1,7 +1,7 @@ /** @file CPU exception handler library implemenation for DXE modules. =20 - Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -19,11 +19,6 @@ =20 CONST UINTN mDoFarReturnFlag =3D 0; =20 -// -// Image align size for DXE/SMM -// -CONST UINTN mImageAlignSize =3D SIZE_4KB; - RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM]; EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_N= UM]; UINTN mEnabledInterruptNum =3D 0; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHa= ndler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandl= er.c index aaf90f6..d3b26d3 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c @@ -119,9 +119,6 @@ DumpImageAndCpuContent ( IN EFI_SYSTEM_CONTEXT SystemContext ) { - UINTN ImageBase; - UINTN EntryPoint; - InternalPrintMessage ( "!!!! IA32 Exception Type - %02x(%a) CPU Apic ID - %08x !!!!\n", ExceptionType, @@ -200,14 +197,8 @@ DumpImageAndCpuContent ( ); =20 // - // Find module image base and module entry point by RIP + // Find module image base and module entry point by EIP // - ImageBase =3D FindModuleImageBase (SystemContext.SystemContextIa32->Eip,= &EntryPoint); - if (ImageBase !=3D 0) { - InternalPrintMessage ( - " (ImageBase=3D%08x, EntryPoint=3D%08x) !!!!\n", - ImageBase, - EntryPoint - ); - } + DumpModuleImageInfo (SystemContext.SystemContextIa32->Eip); + } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c b/= UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c index c3fd8ae..53fa3c6 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c @@ -1,7 +1,7 @@ /** @file CPU exception handler library implementation for PEIM module. =20 -Copyright (c) 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availabl= e under the terms and conditions of the BSD License that accompanies this distribu= tion. The full text of the license may be found at @@ -18,10 +18,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHE= R EXPRESS OR IMPLIED. #include #include =20 -// -// Image Alignment size for PEI phase -// -CONST UINTN mImageAlignSize =3D 4; CONST UINTN mDoFarReturnFlag =3D 0; =20 EFI_GUID mCpuExceptrionHandlerLibHobGuid =3D CPU_EXCEPTION_HANDLER_LIB_HOB= _GUID; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c index 7ac3fc2..5d6807b 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c @@ -15,10 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHE= R EXPRESS OR IMPLIED. #include #include "CpuExceptionCommon.h" =20 -// -// Image Aglinment size for SEC/PEI phase -// -CONST UINTN mImageAlignSize =3D 4; CONST UINTN mDoFarReturnFlag =3D 0; =20 /** diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c b/Uef= iCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c index 7ad228c..5a3d416 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c @@ -1,7 +1,7 @@ /** @file CPU exception handler library implemenation for SMM modules. =20 - Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -22,11 +22,6 @@ CONST UINTN mDoFarReturnFlag =3D 1; // SPIN_LOCK mDisplayMessageSpinLock; =20 -// -// Image align size for DXE/SMM -// -CONST UINTN mImageAlignSize =3D SIZE_4KB; - RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM]; EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_N= UM]; EXCEPTION_HANDLER_DATA mExceptionHandlerData; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHan= dler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler= .c index 3cda7d5..9cd2cc2 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c @@ -124,9 +124,6 @@ DumpImageAndCpuContent ( IN EFI_SYSTEM_CONTEXT SystemContext ) { - UINTN ImageBase; - UINTN EntryPoint; - InternalPrintMessage ( "!!!! X64 Exception Type - %02x(%a) CPU Apic ID - %08x !!!!\n", ExceptionType, @@ -234,12 +231,5 @@ DumpImageAndCpuContent ( // // Find module image base and module entry point by RIP // - ImageBase =3D FindModuleImageBase (SystemContext.SystemContextX64->Rip, = &EntryPoint); - if (ImageBase !=3D 0) { - InternalPrintMessage ( - " (ImageBase=3D%016lx, EntryPoint=3D%016lx) !!!!\n", - ImageBase, - EntryPoint - ); - } + DumpModuleImageInfo (SystemContext.SystemContextX64->Rip); } --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel