summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BaseLib
AgeCommit message (Collapse)Author
2019-02-19MdePkg/BaseLib: Change a variable type in a bitwise operationShenglei Zhang
Change the type of variable Chr from CHAR8 to UINT32 in a bitwise operation, to make the two variables in the operation have the same size. https://bugzilla.tianocore.org/show_bug.cgi?id=1527 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: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2019-02-12MdePkg/BaseLib: implement SpeculationBarrier() for ARM and AArch64Ard Biesheuvel
Replace the dummy C implementation of SpeculationBarrier() with implementations consisting of the recommended DSB SY + ISB sequence, as recommended by ARM in the whitepaper "Cache Speculation Side-channels" version 2.4, dated October 2018. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
2019-02-02MdePkg/BaseLib: Add Base64Encode() and Base64Decode()Mike Turner
Introduce public functions Base64Encode and Base64Decode. https://bugzilla.tianocore.org/show_bug.cgi?id=1370 v2:1.Remove some white space. 2.Add unit test with test vectors in RFC 4648. https://github.com/shenglei10/edk2/tree/encode_test https://github.com/shenglei10/edk2/tree/decode_test v3:1.Align white space. 2.Update comments of Base64Encode and Base64Decode. 3.Change the use of macro RETURN_DEVICE_ERROR to RETURN_INVALID_PARAMETER in string.c. v4:Change parameters' names. v5:1.Update usage of variables. 2.Remove debug message in Base64Decode(). 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: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2019-01-31MdePkg/BaseLib: Remove definitions of two functionsShenglei Zhang
InternalCharToUpper and InternalBaseLibAsciiToUpper are internal functions and now we will introduce public functions that have the same effects. So I remove their definitions in BaseLibInternals.h. https://bugzilla.tianocore.org/show_bug.cgi?id=1369 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: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
2019-01-31MdePkg/BaseLib: Introduce CharToUpper and AsciiCharToUpper publiclyMike Turner
Introduce two public functions CharToUpper and AsciiCharToUpper. They have the same functions as InternalCharToUpper and InternalBaseLibAsciiToUpper.Considering the internal functions will be removed,so directly I change their function names to the public ones'. https://bugzilla.tianocore.org/show_bug.cgi?id=1369 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: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
2018-12-25MdePkg/BaseLib: Introduce new SpeculationBarrier APIHao Wu
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1417 X86 specific BaseLib API AsmLfence() was introduced to address the Spectre Variant 1 (CVE-2017-5753) issue. The purpose of this API is to insert barriers to stop speculative execution. However, the API is highly architecture (X86) specific, and thus should be avoided using across generic code. To address this issue, this patch will add a new BaseLib API called SpeculationBarrier(). Different architectures will have different implementations for this API. For IA32 and x64, the implementation of SpeculationBarrier() will directly call AsmLfence(). For ARM and AARCH64, this patch will add a temporary empty implementation as a placeholder. We hope experts in ARM can help to contribute the actual implementation. For EBC, similar to the ARM and AARCH64 cases, a temporary empty implementation is added. Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Leif Lindholm <leif.lindholm@linaro.org> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-10-24MdePkg-BaseLib: Fix PathCleanUpDirectories() issue with "\\..\\.."Jim.Dailey@dell.com
Replace multiple, consecutive "\" characters prior to other processing involving "\" characters. This fixes an issue where "\\..\\..", "//..//..", and similar input paths are not cleaned properly. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jim Dailey <jim_dailey@dell.com> Reviewed-by: Ruiyu Ni <Ruiyu.ni@Intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-10-23MdePkg/BaseLib: AsciiStrToUnicodeStr(S) not handle EASCII properlyHao Wu
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1262 Current implementation of BaseLib APIs: AsciiStrToUnicodeStr() AsciiStrToUnicodeStrS() AsciiStrnToUnicodeStrS() do not handle EASCII properly. More specifically, if the value of ASCII character is larger than 0x7F, then the converted Unicode character will have all '1's in the higher 8 bits. An example: 0xC9 => 0xFFC9 (current implementations) and it should be: 0xC9 => 0x00C9 This commit will address this issue. Cc: Bin.Lain <bin_601@mail2000.com.tw> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-10-12MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.."Jim.Dailey@dell.com
MdePkg-BaseLib: Fix PathCleanUpDirectories() error involving "\..\.." The loop that removes "xxxx\..\" errs when multiple "\.." sequences are in the path. Before this change the code would modify a path like "FS0:\efi\tools\..\.." to "FS0:\efi\\.." and then to "FS0:\efi\", but the correct path is "FS0:\". You can test the effect of this change in the shell by setting the current directory to something like FS0:\efi\boot and then executing the command "ls ..\..". Before the change you will see the files in the FS0:\efi directory; after the change, you will see the files in the root directory of FS0:. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jim Dailey <jim_dailey@dell.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
2018-09-30MdePkg/BaseLib: Add new AsmLfence APIHao Wu
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1193 This commit will add a new BaseLib API AsmLfence(). This API will perform a serializing operation on all load-from-memory instructions that were issued prior to the call of this function. Please note that this API is only available on IA-32 and x64. The purpose of adding this API is to mitigate of the [CVE-2017-5753] Bounds Check Bypass issue when untrusted data are being processed within SMM. More details can be referred at the 'Bounds check bypass mitigation' section at the below link: https://software.intel.com/security-software-guidance/insights/host-firmware-speculative-execution-side-channel-mitigation Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Leif Lindholm <leif.lindholm@linaro.org> Cc: Michael D Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
2018-09-30MdePkg/BaseLib: Remove an unused PCDshenglei
The PCD below is unused, so it has been removed from inf. gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: shenglei <shenglei.zhang@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2018-09-25MdePkg: Removing ipf which is no longer supported from edk2.Chen A Chen
Removing rules for Ipf sources file: * Remove the source file which path with "ipf" and also listed in [Sources.IPF] section of INF file. * Remove the source file which listed in [Components.IPF] section of DSC file and not listed in any other [Components] section. * Remove the embedded Ipf code for MDE_CPU_IPF. Removing rules for Inf file: * Remove IPF from VALID_ARCHITECTURES comments. * Remove DXE_SAL_DRIVER from LIBRARY_CLASS in [Defines] section. * Remove the INF which only listed in [Components.IPF] section in DSC. * Remove statements from [BuildOptions] that provide IPF specific flags. * Remove any IPF sepcific sections. Removing rules for Dec file: * Remove [Includes.IPF] section from Dec. Removing rules for Dsc file: * Remove IPF from SUPPORTED_ARCHITECTURES in [Defines] section of DSC. * Remove any IPF specific sections. * Remove statements from [BuildOptions] that provide IPF specific flags. Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Chen A Chen <chen.a.chen@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-08-06MdePkg/BaseLib: Add an additional check within AsciiStriCmpRuiyu Ni
This commit adds an addtional check in AsciiStriCmp. It explicitly checks the end of the sting pointed by 'SecondString' to make the code logic easier for reading and to prevent possible mis-reports by static code checkers. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Hao Wu <Hao.a.wu@intel.com>
2018-07-09MdePkg/BaseLib: Add bit field population calculating methodsTomas Pilar (tpilar)
Hopefully this should tidy the conversion warnings. ---- Add 32-bit and 64-bit functions that count number of set bits in a bitfield using a divide-and-count method. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Tomas Pilar <tpilar@solarflare.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
2018-06-28MdePkg: Clean up source filesLiming Gao
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>
2018-06-07MdePkg: Remove X86 ASM and S filesLiming Gao
NASM has replaced ASM and S files. 1. Remove ASM from all modules. 2. Remove S files from the drivers only. 3. https://bugzilla.tianocore.org/show_bug.cgi?id=881 After NASM is updated, S files can be removed from Library. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
2018-04-04MdePkg/BaseLib: add PatchInstructionX86()Laszlo Ersek
Some edk2 modules generate X86 machine code at module execution time by: - compiling "template" code with NASM at module build time, - linking the object code into the module, - and patching the immediate (constant) operands of some instructions when the module is executed. Add a helper function to BaseLib so that the C code performing the patching is easier to read and maintain. The implementation in this patch is taken mainly from Mike Kinney's mailing list messages at <http://mid.mail-archive.com/E92EE9817A31E24EB0585FDF735412F5B895C360@ORSMSX113.amr.corp.intel.com>, <http://mid.mail-archive.com/E92EE9817A31E24EB0585FDF735412F5B898BF66@ORSMSX112.amr.corp.intel.com>. Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=866 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-03-20MdePkg/Library/BaseLib/AArch64: Comment style harmonizationPete Batard
Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard <pete@akeo.ie> Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-03-19MdePkg/Library/BaseLib: Enable VS2017/ARM64 buildsPete Batard
Required GCC assembly files are converted for the MSFT assembler Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard <pete@akeo.ie> Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-02-07MdePkg/Library/BaseLib: Enable VS2017/ARM buildsPete Batard
Most of the RVCT assembly can be reused as is for MSFT except for CpuBreakpoint.asm, which we need to force to Arm mode. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard <pete@akeo.ie> Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-02-06MdePkg/SafeString: Fix potential out-of-bound memory accessRuiyu Ni
Today's implementation of [Ascii]StrnCpyS/[Ascii]StrnCatS calls StrnLenS () to get the length of source string but supplies the destination buffer size as max size. It's a bug that may cause out-of-bound memory access. For example: StrnCpyS (Dest[10], 10, "hello", 6) -> StrnLenS ("hello", 10) //< cause out-of bound memory access In a pool guard enabled environment, when using shell to edit an existing file which contains empty line, the page fault is met. The patch fixes the four library functions to avoid such out-of-bound memory access. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Jian J Wang <jian.j.wang@intel.com>
2018-01-10MdePkg/BaseLib: add attribute 'RETURNS_TWICE' to SetJumpM1cha
When compiling with any ARM toolchain and Os, registers can get trashed when returning for the second time from SetJump because GCC only handles this correctly when using standard names like 'setjmp' or 'getcontext'. When different names are used you have to use the attribute 'returns_twice' to tell gcc to be extra careful. example: extern int FN_NAME(void*); void jmp_buf_set(void *jmpb, void (*f)(void)) { if (!FN_NAME(jmpb)) f(); } this code produces this wrong code with Os: 00000000 <jmp_buf_set>: 0: e92d4010 push {r4, lr} 4: e1a04001 mov r4, r1 8: ebfffffe bl 0 <nonstandard_setjmp> c: e3500000 cmp r0, #0 10: 01a03004 moveq r3, r4 14: 08bd4010 popeq {r4, lr} 18: 012fff13 bxeq r3 1c: e8bd4010 pop {r4, lr} 20: e12fff1e bx lr The generated code pushes backups of r4 and lr to the stack and then saves all registers using nonstandard_setjmp. Then it pops the stack and jumps to the function in r3 which is the main problem because now the function can overwrite our register backups on the stack. When we return a second time from the call to nonstandard_setjmp, the stack pointer has it's original(pushed) position and when the code pops r4 and lr from the stack the values are not guaranteed to be the same. When using a standard name like setjmp or getcontext or adding '__attribute__((returns_twice))' to nonstandard_setjmp's declaration the code looks different: 00000000 <jmp_buf_set>: 0: e92d4007 push {r0, r1, r2, lr} 4: e58d1004 str r1, [sp, #4] 8: ebfffffe bl 0 <setjmp> c: e3500000 cmp r0, #0 10: 059d3004 ldreq r3, [sp, #4] 14: 01a0e00f moveq lr, pc 18: 012fff13 bxeq r3 1c: e28dd00c add sp, sp, #12 20: e49de004 pop {lr} ; (ldr lr, [sp], #4) 24: e12fff1e bx lr Here the problem is being solved by restoring r3 from the stack without popping it. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2017-12-08MdePkg/BaseLib: Add stack switch related definitions for IA32Jian J Wang
The new definitions include two structures IA32_TASK_STATE_SEGMENT IA32_TSS_DESCRIPTOR two macros IA32_GDT_TYPE_TSS IA32_GDT_ALIGNMENT and one API VOID EFIAPI AsmWriteTr ( IN UINT16 Selector ); They're needed to setup task gate and interrupt stack table for stack switch. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang <jian.j.wang@intel.com> Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com> Reviewed-by: Jiewen.yao@intel.com
2017-11-14MdePkg: Fix MSFT C4255 warningSong, BinX
V2: Fix MSFT C4255 warning V1: Enable MSFT C4255 warning. From MSDN: Compiler Warning (level 4) C4255 function' : no function prototype given: converting '()' to '(void)' The compiler did not find an explicit list of arguments to a function. This warning is for the C compiler only. Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bell Song <binx.song@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2017-10-10MdePkg BaseLib: Add new API CalculateCrc32()Liming Gao
CalculateCrc32() bases on the initialized mCrcTable. When CalculateCrc32() is used, mCrcTable will take 1KB size in the image. When CalculateCrc32() is not used, mCrcTable will not be built in the image, and no size impact. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao <liming.gao@intel.com>
2017-09-21MdePkg/BaseLib: Avoid reading content beyond string boundaryHao Wu
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=705 As mentioned in the above Bugzilla link by Steven, within the function PathCleanUpDirectories(), when executing command: "cd ." under Shell, the input parameter 'Path' string will have string length less than 2. Hence, it is possible for the below statement: "if (StrCmp (Path + StrLen (Path) - 2, L"\\.") == 0) {" to read contents before the string boundary. This commit adds additional checks to avoid this. Cc: Steven Shi <steven.shi@intel.com> Cc: Michael Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
2017-08-16MdePkg/BaseLib: Update internal LinkedList verifications.Marvin.Haeuser@outlook.com
1) Replace InternalBaseLibIsNodeInList() with InternalBaseLibIsListValid(). - The verification whether Node is within the doubly-linked List is now done by IsNodeInList(). - Whether the list is valid is returned. 2) The comments within InsertHeadList() and InsertTailList() stated that it is checked whether Entry is not part of the doubly-linked list. This was not done as argument 3 of InternalBaseLibIsNodeInList() indicated whether the check is done, not whether to check if the node is or is not in the list. This has been fixed by using IsNodeInList() for the ASSERTs. V2: - Fix IsListEmpty() to ASSERT when the passed list is invalid. - Introduce the VERIFY_IS_NODE_IN_LIST() macro to only verify whether the passed node is part of the list when PcdVerifyNodeInList is TRUE. V3: - Introduce the ASSERT_VERIFY_NODE_IN_VALID_LIST() macro which, depending on the value of PcdVerifyNodeInList, verifies whether SecondEntry is or is not part of the same doubly-linked list as FirstEntry and unconditionally verifies whether the doubly-linked list FirstEntry is part of is valid. This prevents InternalBaseLibIsListValid() from being called twice when a function ASSERTs via the result of IsNodeInList(), as it calls InternalBaseLibIsListValid() already. - Remove the VERIFY_IS_NODE_IN_LIST() macro in favor of ASSERT_VERIFY_NODE_IN_VALID_LIST(). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2017-08-16MdePkg/BaseLib: Add IsNodeInList() function.Marvin.Haeuser@outlook.com
This patch adds IsNodeInList() to BaseLib, which verifies the given Node is part of the doubly-linked List provided. V2: - Rename "List" to "FirstEntry" and "Node" to "SecondEntry" to clarify that "FirstEntry" does not need to be the doubly-linked list's head node. V3: - Remove ASSERTs from IsNodeInList() which are present in InternalBaseLibIsListValid(). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2017-04-06MdePkg: Convert files to CRLF line endingHao Wu
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2017-03-07MdePkg/SafeString.c: Fix code to be more readableRuiyu Ni
The change doesn't impact the functionality. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
2017-03-06MdePkg: Refine casting expression result to bigger sizeHao Wu
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>
2017-02-28MdePkg/BaseLib: Add AsciiStrToGuid/HexToBytes/ToIpv[4/6]AddressRuiyu Ni
The patch adds 4 APIs to convert ASCII string to GUID, bytes buffer, IP v4 address and IP v6 address. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Siyuan Fu <siyuan.fu@intel.com>
2017-02-28MdePkg/BaseLib: Add StrToGuid/StrHexToBytes/StrToIpv[4/6]AddressRuiyu Ni
The patch adds 4 APIs to convert Unicode string to GUID, bytes buffer, IP v4 address and IP v6 address. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Siyuan Fu <siyuan.fu@intel.com>
2017-02-15MdePkg/BaseLib: Refine logic for (Ascii)StrnLenS to handle MaxSize = 0Hao Wu
https://bugzilla.tianocore.org/show_bug.cgi?id=378 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2017-01-09MdePkg/BaseLib: Add safe string functions [U|A]StrnTo[A|U]StrSHao Wu
Add the following 2 APIs: UnicodeStrnToAsciiStrS AsciiStrnToUnicodeStrS These APIs are used to enhance APIs UnicodeStrToAsciiStrS and AsciiStrToUnicodeStrS (without 'n' in names) by: 1. Adds an input parameter 'Length' to specify the maximum number of Ascii/Unicode characters to convert. 2. Adds an output parameter 'DestinationLength' to indicate the number of Ascii/Unicode characters successfully converted. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2017-01-09MdePkg/BaseLib: Enhance the return value for string to uint functionsHao Wu
For the following 8 APIs in MdePkg/BaseLib: [Ascii]StrDecimalToUintn [Ascii]StrDecimalToUint64 [Ascii]StrHexToUintn [Ascii]StrHexToUint64 They will ASSERT for DEBUG build when the input string exceeds the range of UINTN/UINT64. However, for RELEASE build, incorrect value will be returned. This commit refines those APIs to direcly call their enhanced counterparts (with trailing 'S' in API names) so as to remove those exceed-range ASSERT checks and to make those APIs to return MAX_UINTN/MAX_UINT64 instead. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2017-01-09MdePkg/BaseLib: Add safe string functions that convert str to valueHao Wu
Add the following 8 APIs: [Ascii]StrDecimalToUintnS [Ascii]StrDecimalToUint64S [Ascii]StrHexToUintnS [Ascii]StrHexToUint64S These safe version APIs are used to enhance their counterpart (APIs without trailing 'S' in function names). These safe version APIs perform checks to the input string and will return relative status to reflect the check result: When the input string exceeds the range of UINTN/64, these APIs will return RETURN_UNSUPPORTED and store MAX_UINTN/64 in the output data. When no conversion can be performed for the input string, these APIs will return RETURN_SUCCESS and store 0 in the output data. The optional parameter 'EndPointer', if provided, will point to the character that stopped the scan. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2017-01-09MdePkg/BaseLib: Add safe string functions [Ascii]StrnSizeSHao Wu
Add StrnSizeS() and AsciiStrnSizeS() APIs. These 2 safe version APIs are used to replace StrSize() and AsciiStrSize(). Those two APIs use similar checks as [Ascii]StrnLenS(). Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2016-12-29MdePkg/BaseLib: Fix PathCleanUpDirectories to correctly handle "\.\"Ruiyu Ni
The old code incorrectly cleans path like "fs0:\abc\.\.." to "fs0:\abc", instead of "fs0:\" The patch fixes this bug. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chen A Chen <chen.a.chen@intel.com> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
2016-12-22MdePkg/BaseLib: Add an additional check within (Ascii)StrnCmpHao Wu
This commit adds an addtional check in AsciiStrnCmp and StrnCmp. It explicitly checks the end of the sting pointed by 'SecondString' to make the code logic easier for reading and to prevent possible mis-reports by static code checkers. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
2016-12-22MdePkg/BaseLib: Refine (Ascii)StrnLenS functions logicHao Wu
This commit refines the logic for AsciiStrnLenS and StrnLenS. It makes the logic more straightforward to prevent possible mis-reports by static code checkers. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2016-11-21MdePkg BaseLib: API PathRemoveLastItem not handle root paths properlyHao Wu
https://bugzilla.tianocore.org/show_bug.cgi?id=239 When the input path for API PathRemoveLastItem() is a root path like 'fs0:\', the API will return TRUE (indicating a directory or file was removed from the path) and modifies the path to 'fs0:'. In fact, there's no directory or file removed in the above case. This commit adds additional check to resolve this issue and modifies the API's description to make it more straightforward. Cc: Ruiyu Ni <ruiyu.ni@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
2016-11-16MdePkg/BaseLib: Add one wrapper on RdRand access for parameter check.Qin Long
Add one wrapper implementation over assembly RdRand access to check possible NULL parameter, for better alignment with comment description. Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qin Long <qin.long@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2016-11-04MdePkg/BaseLib: Move CHAR_NULL definition to Base.h in BaseLibSong, BinX
- Required unicode control chars -> Null character - Remove CHAR_NULL definition in SimpleTextIn.h - https://bugzilla.tianocore.org/show_bug.cgi?id=172 Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Bell Song <binx.song@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2016-10-18MdePkg/BaseLib: Remove the unnecessary '_' before library APIs in ASM/NASMHao Wu
The leading underscore (i.e. '_') before the names of some BaseLib library API in ASM/NASM files is unnecessary. It will cause link error with GCC tool chains. Cc: Liming Gao <liming.gao@intel.com> Cc: Michael Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
2016-10-07MdePkg: Fix some typing errorsThomas Huth
Correct the typos in some files of MdePkg. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
2016-09-09MdePkg/BaseLib AARCH64: terminate stack frame list on stack switchArd Biesheuvel
When switching to the DXE phase stack, set the frame pointer to zero so that code walking the stack frame will not try to access stack frames belonging to the old stack. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
2016-08-10MdePkg: Enhance PathRemoveLastItem() to support "FS0:File.txt"Ruiyu Ni
The original implementation only looks for very last backslash and removes the string after that. But when the path is like "FS0:File.txt" which doesn't contain backslash, the function cannot work well. The patch enhances the code to look for very last backslash or colon to support the path which doesn't contain backslash. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Tapan Shah <tapandshah@hpe.com>
2016-07-20MdePkg BaseLib: Add the missing nasm source file InternalSwitchStack.nasmLiming Gao
BaseLib Ia32 InternalSwitchStack.S has no matched InternalSwitchStack.nasm. Use ObjDump to verify the output object files be same. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Jeff Fan <jeff.fan@intel.com>
2016-06-28MdePkg BaseLib: Convert Ia32/DisablePaging32.asm to NASMLiming Gao
The BaseTools/Scripts/ConvertMasmToNasm.py script was used to convert Ia32/DisablePaging32.asm to Ia32/DisablePaging32.nasm Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>