summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
Commit message (Collapse)AuthorAgeFilesLines
* MdePkg/BasePeCoffLib: Deal with broken debug directoriesArd Biesheuvel2023-05-051-0/+15
| | | | | | | | | | | | | | | | | | | | | | | Older versions of GenFw put the wrong value in the debug directory size field in the PE/COFF header: instead of putting the combined size of all the entries, it puts the size of the only entry it creates, but adds the size of the NB10 payload that the entry points to. This confuses the loader now that we started using additional debug directory entries to describe DLL characteristics. GenFw was fixed in commit 60e85a39fe49071, but the binaries that were generated with it still need to be supported. So let's detect this condition, and check whether the size of the debug directory is consistent with the NB10 payload: if we should expect additional directory entries where we observe the NB10 payload, the size field is clearly wrong, and we can break from the loop. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4425 Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Tested-by: Liming Gao <gaoliming@byosoft.com.cn> Acked-by: Michael Kubacki <michael.kubacki@microsoft.com>
* MdePkg/PeCoffLib: Capture DLL characteristics fields in image contextArd Biesheuvel2023-04-071-11/+35
| | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4405 When loading a PE/COFF image, capture the DLL characteristics fields of the header into our image context structure so we can refer to them when mapping the image. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com> Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* MdePkg/BasePeCoff: Add LoongArch PE/Coff related code.Chao Li2022-10-141-1/+2
| | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4053 Add LoongArch image relocation. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Zhiguang Liu <zhiguang.liu@intel.com> Signed-off-by: Chao Li <lichao@loongson.cn> Co-authored-by: Baoqi Zhang <zhangbaoqi@loongson.cn> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
* MdePkg: Apply uncrustify changesMichael Kubacki2021-12-071-470/+521
| | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the MdePkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.Abner Chang2020-05-071-1/+2
| | | | | | | | | | | | | | | | Support RISC-V image relocation. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2672 Signed-off-by: Abner Chang <abner.chang@hpe.com> Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org> Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Leif Lindholm <leif.lindholm@linaro.org> Cc: Gilbert Chen <gilbert.chen@hpe.com>
* MdePkg: Replace BSD License with BSD+Patent LicenseMichael D Kinney2019-04-091-7/+1
| | | | | | | | | | | | | | | | | | | | https://bugzilla.tianocore.org/show_bug.cgi?id=1373 Replace BSD 2-Clause License with BSD+Patent License. This change is based on the following emails: https://lists.01.org/pipermail/edk2-devel/2019-February/036260.html https://lists.01.org/pipermail/edk2-devel/2018-October/030385.html RFCs with detailed process for the license change: V3: https://lists.01.org/pipermail/edk2-devel/2019-March/038116.html V2: https://lists.01.org/pipermail/edk2-devel/2019-March/037669.html V1: https://lists.01.org/pipermail/edk2-devel/2019-March/037500.html Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
* MdePkg/BasePeCoffLib: skip runtime relocation if reloc info is invalidHsueh, Hong-chihX2019-01-311-10/+20
| | | | | | | | | | | | | | | | Skip runtime relocation for PE images that provide invalid relocation infomation (ex: RelocDir->Size = 0) to fix a hang observed while booting Windows. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Neo Hsueh <hong-chihx.hsueh@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Dandan Bi <dandan.bi@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Bi Dandan <dandan.bi@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* MdePkg/BasePeCoffLib: Correct the address of RelocBaseEndDandan Bi2019-01-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1426 When calculating the address of RelocBaseEnd, the RelocBase address is ImageBase + RelocDir->VirtualAddress, the size of RelocDir is RelocDir->Size. So the RelocBaseEnd address is: ImageBase + RelocDir->VirtualAddress + RelocDir->Size - 1 not ImageBase + RelocDir->VirtualAddress + RelocDir->Size This patch is to fix this issue when call PeCoffLoaderImageAddress function to calculate the address of RelocBaseEnd. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi <dandan.bi@intel.com> Tested-by: Gary Lin <glin@suse.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
* MdePkg/BasePeCoffLib: Add more check for relocation dataDandan Bi2019-01-161-70/+95
| | | | | | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1426 V2: (1) Add NULL pointer check for the input parameters (2) Add check for the "Adjust" value before applying fix ups. In function PeCoffLoaderRelocateImageForRuntime, it doesn't do much check when do relocation. For API level consideration, it's not safe enough. So this patch is to replace the same code logic with function PeCoffLoaderImageAddress which will cover more validation. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi <dandan.bi@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
* MdePkg/BasePeCoffLib: remove PE/COFF header workaround for ELILO on IPFArd Biesheuvel2018-09-241-52/+9
| | | | | | | | | | | | | Now that Itanium support has been dropped, we can remove the various occurrences of the ELILO on Itanium PE/COFF header workaround. Link: https://bugzilla.tianocore.org/show_bug.cgi?id=816 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
* MdePkg: Clean up source filesLiming Gao2018-06-281-71/+71
| | | | | | | | | 1. Do not use tab characters 2. No trailing white space in one line 3. All files must end with CRLF Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao <liming.gao@intel.com>
* MdePkg: Refine casting expression result to bigger sizeHao Wu2017-03-061-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are cases that the operands of an expression are all with rank less than UINT64/INT64 and the result of the expression is explicitly cast to UINT64/INT64 to fit the target size. An example will be: UINT32 a,b; // a and b can be any unsigned int type with rank less than UINT64, like // UINT8, UINT16, etc. UINT64 c; c = (UINT64) (a + b); Some static code checkers may warn that the expression result might overflow within the rank of "int" (integer promotions) and the result is then cast to a bigger size. The commit refines codes by the following rules: 1). When the expression is possible to overflow the range of unsigned int/ int: c = (UINT64)a + b; 2). When the expression will not overflow within the rank of "int", remove the explicit type casts: c = a + b; 3). When the expression will be cast to pointer of possible greater size: UINT32 a,b; VOID *c; c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b); 4). When one side of a comparison expression contains only operands with rank less than UINT32: UINT8 a; UINT16 b; UINTN c; if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...} For rule 4), if we remove the 'UINTN' type cast like: if (a + b > c) {...} The VS compiler will complain with warning C4018 (signed/unsigned mismatch, level 3 warning) due to promoting 'a + b' to type 'int'. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* Support load 64 bit image from 32 bit core.Eric Dong2014-03-251-6/+25
| | | | | | | | | | | | | Add more enhancement to check invalid PE format. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Jiewen, Yao <jiewen.yao@intel.com> Reviewed-by: Liming, Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15387 6f19259b-4bc3-4df7-8a09-765794883524
* Add more check for PE COFF SizeOfHeader field.jyao12014-02-121-1/+25
| | | | | | | | Signed-off by: jiewen yao <jiewen.yao@intel.com> reviewed by: eric dong <eric.dong@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15233 6f19259b-4bc3-4df7-8a09-765794883524
* Checks the TE image before use it.ydong102012-12-261-189/+192
| | | | | | | Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Yao, Jiewen <jiewen.yao@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14024 6f19259b-4bc3-4df7-8a09-765794883524
* Remove the ASSERT (FALSE) code, just return unsupported.ydong102012-12-061-7/+0
| | | | | | | | Signed-off-by: Dong Eric <eric.dong@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13985 6f19259b-4bc3-4df7-8a09-765794883524
* Enhance the check for RelocBase->SizeOfBlock before use it.ydong102012-11-281-5/+4
| | | | | | | Signed-off-by: Dong Eric <eric.dong@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13973 6f19259b-4bc3-4df7-8a09-765794883524
* Enhance the check for some fields in the PE image before use it.ydong102012-11-281-20/+63
| | | | | | | Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Jiewen Yao<jiewen.yao@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13972 6f19259b-4bc3-4df7-8a09-765794883524
* Enhance the check for resource section data.ydong102012-11-261-2/+36
| | | | | | | Signed-off-by: Dong Eric <eric.dong@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13962 6f19259b-4bc3-4df7-8a09-765794883524
* Enhance the check for debug data before get the PdbPointer.ydong102012-11-261-0/+18
| | | | | | | Signed-off-by: Dong Eric <eric.dong@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13961 6f19259b-4bc3-4df7-8a09-765794883524
* Remove the useless code.ydong102012-11-201-6/+1
| | | | | | | Signed-off-by: Dong Eric <eric.dong@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13954 6f19259b-4bc3-4df7-8a09-765794883524
* Enhance the error code info.ydong102012-09-111-4/+54
| | | | | | | Signed-off-by: Dong Eric <eric.dong@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13716 6f19259b-4bc3-4df7-8a09-765794883524
* Enhance the comments.ydong102012-09-111-0/+2
| | | | | | | Signed-off-by: Dong Eric <eric.dong@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13715 6f19259b-4bc3-4df7-8a09-765794883524
* Enhance the check for some fields in the PE image before use it.ydong102012-08-221-0/+15
| | | | | | | Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Jiewen Yao<jiewen.yao@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13665 6f19259b-4bc3-4df7-8a09-765794883524
* Enhance the check when ImageRead function return.ydong102012-08-211-16/+30
| | | | | | | Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13657 6f19259b-4bc3-4df7-8a09-765794883524
* Add comment for modules which have external input.jyao12012-06-121-2/+20
| | | | | | | | | | | | signed-off-by: jiewen.yao@intel.com reviewed-by: guo.dong@intel.com reviewed-by: ting.ye@intel.com reviewed-by: liming.gao@intel.com reviewed-by: elvin.li@intel.com git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13446 6f19259b-4bc3-4df7-8a09-765794883524
* Update the logic related to get section header offset for TE image.ydong102012-05-041-2/+10
| | | | | | | Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13273 6f19259b-4bc3-4df7-8a09-765794883524
* Patch include:ydong102012-04-261-8/+0
| | | | | | | | | | | 1.Change function name to avoid name conflict. 2.Refine check for Pe Image. Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13220 6f19259b-4bc3-4df7-8a09-765794883524
* Validate some fields in PE image to make sure not access violation for later ↵ydong102012-04-241-1/+195
| | | | | | | | | code. Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13211 6f19259b-4bc3-4df7-8a09-765794883524
* Update the offset when read every debug entries info.ydong102012-03-161-3/+3
| | | | | | | Signed-off-by: ydong10 Reviewed-by: lgao4 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13104 6f19259b-4bc3-4df7-8a09-765794883524
* MdePkg: Fix X64 clang compile issues.andrewfish2011-07-121-3/+5
| | | | | | | | | | | | Fixed issues with X64 clang, and also make StackSwitch push a zero on the new stack to prevent a stack unwind into memory that is no longer valid. signed-off-by: andrewfish reviewed-by: lgao4 reviewed-by: mdkinney git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12007 6f19259b-4bc3-4df7-8a09-765794883524
* Per PI1.2B spec, for the case that TE Image Relocation Data Directory Entry ↵lgao42011-02-161-1/+9
| | | | | | Virtual Address is non-zero, but the Relocation Data Directory Size is zero, BasePeCoffLib should only handle such case as PIC TE image. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11315 6f19259b-4bc3-4df7-8a09-765794883524
* Minor grammatical work--mostly adding periods. Items with ONLY period added ↵myronporter2010-06-301-3/+3
| | | | | | did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10615 6f19259b-4bc3-4df7-8a09-765794883524
* Minor grammatical work--mostly adding periods. Items with ONLY period added ↵myronporter2010-06-251-7/+7
| | | | | | did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10604 6f19259b-4bc3-4df7-8a09-765794883524
* Update the copyright notice formathhtian2010-04-231-3/+3
| | | | git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10412 6f19259b-4bc3-4df7-8a09-765794883524
* Do not update the ImageBase in the PE/COFF header if Adjust is 0.mdkinney2009-10-151-3/+9
| | | | git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9341 6f19259b-4bc3-4df7-8a09-765794883524
* Do not apply relocation fixups if the Adjust value is zero, which means the ↵mdkinney2009-10-081-85/+90
| | | | | | image is XIP. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9333 6f19259b-4bc3-4df7-8a09-765794883524
* Check to see if the section size of non-zero before failing a load operation ↵mdkinney2009-10-011-10/+10
| | | | | | due to a NULL base or end address git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9326 6f19259b-4bc3-4df7-8a09-765794883524
* Fix file headersmdkinney2009-08-241-1/+1
| | | | git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9189 6f19259b-4bc3-4df7-8a09-765794883524
* Remove tabs in source code in MdePkg.qhuang82009-08-191-1/+1
| | | | git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9142 6f19259b-4bc3-4df7-8a09-765794883524
* Update to make end-of-line consistent for all source files in MdePkg. There ↵qhuang82009-08-191-4/+4
| | | | | | are no other updates besides that change. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9141 6f19259b-4bc3-4df7-8a09-765794883524
* Add ARM supportmdkinney2009-08-181-1/+6
| | | | git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9111 6f19259b-4bc3-4df7-8a09-765794883524
* add the extra comments into BasePeCoffRelocateImage, BasePeCoffLoadImage and ↵eric_tian2009-05-111-0/+12
| | | | | | | | BasePeCoffRelocateImageForRuntime to help user to know the usage model of these APIs. The comments mainly used to clarify it's caller's responsibility to to perform cache maintenance operations git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8283 6f19259b-4bc3-4df7-8a09-765794883524
* Update BasePeCoff to Initialize the debug field to zero.lgao42009-05-061-3/+4
| | | | git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8243 6f19259b-4bc3-4df7-8a09-765794883524
* Add check for the validity of resource directory address.qhuang82009-04-231-32/+32
| | | | git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8164 6f19259b-4bc3-4df7-8a09-765794883524
* Add HiiResourceData field to PeCoffLib library class. PeCoffLoaderLoadImage ↵qhuang82009-04-221-11/+84
| | | | | | () will set this field to HII resource data if it detects the existence in PE image. otherwise, it set that field to 0. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8141 6f19259b-4bc3-4df7-8a09-765794883524
* Remove PeRemove PeiPeCoffLoader.h and gPeiPeCoffLoaderGuid, and Add ↵qhuang82009-03-051-0/+11
| | | | | | PeCoffExtraActionLib class and instances. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7811 6f19259b-4bc3-4df7-8a09-765794883524
* 1) Remove UEFI specific defines from IndustryStandard/PeImage.hmdkinney2009-02-051-1/+1
| | | | | | | | 2) Add UEFI specific defines to Uefi/UefiBaseType.h 3) Update Base PE/COFF related libs to only use defines from IndustryStandard/PeImage.h git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7438 6f19259b-4bc3-4df7-8a09-765794883524
* Add check for Zero Relocation section.lgao42009-01-071-31/+49
| | | | git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7197 6f19259b-4bc3-4df7-8a09-765794883524
* Temporarily remove the assertions and we may find some error handling way to ↵qhuang82009-01-041-3/+0
| | | | | | address potential dereference to NULL pointer. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7173 6f19259b-4bc3-4df7-8a09-765794883524