]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/PrintDxe: Handle the deprecation of [A|U]ValueToString
authorHao Wu <hao.a.wu@intel.com>
Mon, 13 Feb 2017 03:03:30 +0000 (11:03 +0800)
committerHao Wu <hao.a.wu@intel.com>
Thu, 2 Mar 2017 01:59:06 +0000 (09:59 +0800)
To handle the deprecation of PrintLib APIs UnicodeValueToString and
AsciiValueToString by subsequent commits, the commit refines the logic for
the implemetation of the UnicodeValueToString and AsciiValueToString
services in EFI_PRINT2_PROTOCOL.

When the macro DISABLE_NEW_DEPRECATED_INTERFACES is defined (indicating
the deprecation of the PrintLib APIs), the above two services will ASSERT
and will return zero to reflect not being supported.

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>
MdeModulePkg/Universal/PrintDxe/Print.c

index 85bc724a9028211eaea1d1f785d45c08e2d522da..80298367b976f50270a98b3022653f801997e38e 100644 (file)
@@ -20,6 +20,94 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DebugLib.h>\r
 #include <Library/UefiDriverEntryPoint.h>\r
 \r
+/**\r
+  Implementaion of the UnicodeValueToString service in EFI_PRINT2_PROTOCOL.\r
+\r
+  If the macro DISABLE_NEW_DEPRECATED_INTERFACES is defined, then ASSERT().\r
+\r
+  @param  Buffer  The pointer to the output buffer for the produced\r
+                  Null-terminated Unicode string.\r
+  @param  Flags   The bitmask of flags that specify left justification, zero\r
+                  pad, and commas.\r
+  @param  Value   The 64-bit signed value to convert to a string.\r
+  @param  Width   The maximum number of Unicode characters to place in Buffer,\r
+                  not including the Null-terminator.\r
+\r
+  @return If the macro DISABLE_NEW_DEPRECATED_INTERFACES is defined, return 0.\r
+          Otherwise, return the number of Unicode characters in Buffer not\r
+          including the Null-terminator.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+PrintDxeUnicodeValueToString (\r
+  IN OUT CHAR16  *Buffer,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width\r
+  )\r
+{\r
+#ifdef DISABLE_NEW_DEPRECATED_INTERFACES\r
+  //\r
+  // If the macro DISABLE_NEW_DEPRECATED_INTERFACES is defined, then the\r
+  // PrintLib API UnicodeValueToString is already deprecated.\r
+  // In this case, ASSERT will be triggered and zero will be returned for the\r
+  // implementation of the UnicodeValueToString service in EFI_PRINT2_PROTOCOL\r
+  // to indicate that the service is no longer supported.\r
+  //\r
+  DEBUG ((DEBUG_ERROR, "PrintDxe: The UnicodeValueToString service in EFI_PRINT2_PROTOCOL is no longer supported for security reason.\n"));\r
+  DEBUG ((DEBUG_ERROR, "PrintDxe: Please consider using the UnicodeValueToStringS service in EFI_PRINT2S_PROTOCOL.\n"));\r
+  ASSERT (FALSE);\r
+  return 0;\r
+#else\r
+  return UnicodeValueToString (Buffer, Flags, Value, Width);\r
+#endif\r
+}\r
+\r
+/**\r
+  Implementaion of the AsciiValueToString service in EFI_PRINT2_PROTOCOL.\r
+\r
+  If the macro DISABLE_NEW_DEPRECATED_INTERFACES is defined, then ASSERT().\r
+\r
+  @param  Buffer  A pointer to the output buffer for the produced\r
+                  Null-terminated ASCII string.\r
+  @param  Flags   The bitmask of flags that specify left justification, zero\r
+                  pad, and commas.\r
+  @param  Value   The 64-bit signed value to convert to a string.\r
+  @param  Width   The maximum number of ASCII characters to place in Buffer,\r
+                  not including the Null-terminator.\r
+\r
+  @return If the macro DISABLE_NEW_DEPRECATED_INTERFACES is defined, return 0.\r
+          Otherwise, return the number of ASCII characters in Buffer not\r
+          including the Null-terminator.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+PrintDxeAsciiValueToString (\r
+  OUT CHAR8      *Buffer,\r
+  IN  UINTN      Flags,\r
+  IN  INT64      Value,\r
+  IN  UINTN      Width\r
+  )\r
+{\r
+#ifdef DISABLE_NEW_DEPRECATED_INTERFACES\r
+  //\r
+  // If the macro DISABLE_NEW_DEPRECATED_INTERFACES is defined, then the\r
+  // PrintLib API AsciiValueToString is already deprecated.\r
+  // In this case, ASSERT will be triggered and zero will be returned for the\r
+  // implementation of the AsciiValueToString service in EFI_PRINT2_PROTOCOL\r
+  // to indicate that the service is no longer supported.\r
+  //\r
+  DEBUG ((DEBUG_ERROR, "PrintDxe: The AsciiValueToString service in EFI_PRINT2_PROTOCOL is no longer supported for security reason.\n"));\r
+  DEBUG ((DEBUG_ERROR, "PrintDxe: Please consider using the AsciiValueToStringS service in EFI_PRINT2S_PROTOCOL.\n"));\r
+  ASSERT (FALSE);\r
+  return 0;\r
+#else\r
+  return AsciiValueToString (Buffer, Flags, Value, Width);\r
+#endif\r
+}\r
+\r
 EFI_HANDLE  mPrintThunkHandle = NULL;\r
 \r
 CONST EFI_PRINT2_PROTOCOL mPrint2Protocol = {\r
@@ -27,12 +115,12 @@ CONST EFI_PRINT2_PROTOCOL mPrint2Protocol = {
   UnicodeSPrint,\r
   UnicodeBSPrintAsciiFormat,\r
   UnicodeSPrintAsciiFormat,\r
-  UnicodeValueToString,\r
+  PrintDxeUnicodeValueToString,\r
   AsciiBSPrint,\r
   AsciiSPrint,\r
   AsciiBSPrintUnicodeFormat,\r
   AsciiSPrintUnicodeFormat,\r
-  AsciiValueToString\r
+  PrintDxeAsciiValueToString\r
 };\r
 \r
 CONST EFI_PRINT2S_PROTOCOL mPrint2SProtocol = {\r