]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add the EFI_PRINT2S_PROTOCOL
authorHao Wu <hao.a.wu@intel.com>
Wed, 8 Feb 2017 03:20:37 +0000 (11:20 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 21 Feb 2017 05:56:22 +0000 (13:56 +0800)
Add the EFI_PRINT2S_PROTOCOL as a safe version of the EFI_PRINT2_PROTOCOL,
the EFI_PRINT2S_PROTOCOL replaces the following 2 services in
EFI_PRINT2_PROTOCOL:
UNICODE_VALUE_TO_STRING
ASCII_VALUE_TO_STRING

with:
UNICODE_VALUE_TO_STRING_S
ASCII_VALUE_TO_STRING_S

The 2 new services perform checks to the input parameters and will return
relative status to reflect the check result.

Return RETURN_INVALID_PARAMETER when:
1). The input Buffer is NULL.
2). The input BufferSize is greater than (PcdMaximumUnicodeStringLength *
sizeof (CHAR16) + 1) for UnicodeValueToStringS or greater than
PcdMaximumAsciiStringLength for AsciiValueToStringS.
3). The input Flags is not set properly.
4). The input Width is not smaller than MAXIMUM_VALUE_CHARACTERS.

Return RETURN_BUFFER_TOO_SMALL when:
1). The input BufferSize cannot hold the converted value.

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/Include/Protocol/Print2.h
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/Universal/PrintDxe/Print.c
MdeModulePkg/Universal/PrintDxe/PrintDxe.inf
MdeModulePkg/Universal/PrintDxe/PrintDxe.uni

index 8cad6fdef05979cba042686fece701e0430e7311..e4dd6f2be513b24ec98daa67dae9e3a7c78004ab 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
 \r
 /** @file\r
 \r
-  This print protocol defines six basic print functions to \r
-  print the format unicode and ascii string.\r
+  Produces EFI_PRINT2_PROTOCOL and EFI_PRINT2S_PROTOCOL.\r
+  These protocols define basic print functions to  print the format unicode and\r
+  ascii string.\r
 \r
 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under \r
 \r
 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under \r
@@ -515,4 +516,149 @@ struct _EFI_PRINT2_PROTOCOL {
 \r
 extern EFI_GUID gEfiPrint2ProtocolGuid;\r
 \r
 \r
 extern EFI_GUID gEfiPrint2ProtocolGuid;\r
 \r
+\r
+#define EFI_PRINT2S_PROTOCOL_GUID  \\r
+  { 0xcc252d2, 0xc106, 0x4661, { 0xb5, 0xbd, 0x31, 0x47, 0xa4, 0xf8, 0x1f, 0x92 } }\r
+\r
+//\r
+// Forward reference for pure ANSI compatability\r
+//\r
+typedef struct _EFI_PRINT2S_PROTOCOL  EFI_PRINT2S_PROTOCOL;\r
+\r
+/**\r
+  Converts a decimal value to a Null-terminated Unicode string.\r
+\r
+  Converts the decimal number specified by Value to a Null-terminated Unicode\r
+  string specified by Buffer containing at most Width characters. No padding of\r
+  spaces is ever performed. If Width is 0 then a width of\r
+  MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
+  Width characters, then only the first Width characters are placed in Buffer.\r
+  Additional conversion parameters are specified in Flags.\r
+\r
+  The Flags bit LEFT_JUSTIFY is always ignored.\r
+  All conversions are left justified in Buffer.\r
+  If Width is 0, PREFIX_ZERO is ignored in Flags.\r
+  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
+  commas are inserted every 3rd digit starting from the right.\r
+  If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
+  hexadecimal format.\r
+  If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
+  Buffer is a '-'.\r
+  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
+  Buffer is padded with '0' characters so the combination of the optional '-'\r
+  sign character, '0' characters, digit characters for Value, and the\r
+  Null-terminator add up to Width characters.\r
+\r
+  If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  @param  Buffer      The pointer to the output buffer for the produced\r
+                      Null-terminated Unicode string.\r
+  @param  BufferSize  The size of Buffer in bytes, including the\r
+                      Null-terminator.\r
+  @param  Flags       The bitmask of flags that specify left justification,\r
+                      zero 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\r
+                      Buffer, not including the Null-terminator.\r
+\r
+  @retval RETURN_SUCCESS           The decimal value is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted\r
+                                   value.\r
+  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and BufferSize is greater than\r
+                                   (PcdMaximumUnicodeStringLength *\r
+                                   sizeof (CHAR16) + 1).\r
+                                   If unsupported bits are set in Flags.\r
+                                   If both COMMA_TYPE and RADIX_HEX are set in\r
+                                   Flags.\r
+                                   If Width >= MAXIMUM_VALUE_CHARACTERS.\r
+\r
+**/\r
+typedef\r
+RETURN_STATUS\r
+(EFIAPI *UNICODE_VALUE_TO_STRING_S)(\r
+  IN OUT CHAR16  *Buffer,\r
+  IN UINTN       BufferSize,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width\r
+  );\r
+\r
+/**\r
+  Converts a decimal value to a Null-terminated Ascii string.\r
+\r
+  Converts the decimal number specified by Value to a Null-terminated Ascii\r
+  string specified by Buffer containing at most Width characters. No padding of\r
+  spaces is ever performed. If Width is 0 then a width of\r
+  MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r
+  Width characters, then only the first Width characters are placed in Buffer.\r
+  Additional conversion parameters are specified in Flags.\r
+\r
+  The Flags bit LEFT_JUSTIFY is always ignored.\r
+  All conversions are left justified in Buffer.\r
+  If Width is 0, PREFIX_ZERO is ignored in Flags.\r
+  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r
+  commas are inserted every 3rd digit starting from the right.\r
+  If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r
+  hexadecimal format.\r
+  If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r
+  Buffer is a '-'.\r
+  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r
+  Buffer is padded with '0' characters so the combination of the optional '-'\r
+  sign character, '0' characters, digit characters for Value, and the\r
+  Null-terminator add up to Width characters.\r
+\r
+  If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  @param  Buffer      The pointer to the output buffer for the produced\r
+                      Null-terminated Ascii string.\r
+  @param  BufferSize  The size of Buffer in bytes, including the\r
+                      Null-terminator.\r
+  @param  Flags       The bitmask of flags that specify left justification,\r
+                      zero 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\r
+                      Buffer, not including the Null-terminator.\r
+\r
+  @retval RETURN_SUCCESS           The decimal value is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted\r
+                                   value.\r
+  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not\r
+                                   zero, and BufferSize is greater than\r
+                                   PcdMaximumAsciiStringLength.\r
+                                   If unsupported bits are set in Flags.\r
+                                   If both COMMA_TYPE and RADIX_HEX are set in\r
+                                   Flags.\r
+                                   If Width >= MAXIMUM_VALUE_CHARACTERS.\r
+\r
+**/\r
+typedef\r
+RETURN_STATUS\r
+(EFIAPI *ASCII_VALUE_TO_STRING_S)(\r
+  IN OUT CHAR8   *Buffer,\r
+  IN  UINTN      BufferSize,\r
+  IN  UINTN      Flags,\r
+  IN  INT64      Value,\r
+  IN  UINTN      Width\r
+  );\r
+\r
+struct _EFI_PRINT2S_PROTOCOL {\r
+  UNICODE_BS_PRINT                     UnicodeBSPrint;\r
+  UNICODE_S_PRINT                      UnicodeSPrint;\r
+  UNICODE_BS_PRINT_ASCII_FORMAT        UnicodeBSPrintAsciiFormat;\r
+  UNICODE_S_PRINT_ASCII_FORMAT         UnicodeSPrintAsciiFormat;\r
+  UNICODE_VALUE_TO_STRING_S            UnicodeValueToStringS;\r
+  ASCII_BS_PRINT                       AsciiBSPrint;\r
+  ASCII_S_PRINT                        AsciiSPrint;\r
+  ASCII_BS_PRINT_UNICODE_FORMAT        AsciiBSPrintUnicodeFormat;\r
+  ASCII_S_PRINT_UNICODE_FORMAT         AsciiSPrintUnicodeFormat;\r
+  ASCII_VALUE_TO_STRING_S              AsciiValueToStringS;\r
+};\r
+\r
+extern EFI_GUID gEfiPrint2SProtocolGuid;\r
+\r
 #endif\r
 #endif\r
index 273cd7e1716f2b8c54489fd5bccbdd13720309c0..c95633c11758663f1b66416b9bcc14dd766081de 100644 (file)
   #  If developer need implement such functionality, they should use BasePeCoffLib.\r
   gEfiLoadPeImageProtocolGuid    = { 0x5CB5C776, 0x60D5, 0x45EE, { 0x88, 0x3C, 0x45, 0x27, 0x08, 0xCD, 0x74, 0x3F }}\r
 \r
   #  If developer need implement such functionality, they should use BasePeCoffLib.\r
   gEfiLoadPeImageProtocolGuid    = { 0x5CB5C776, 0x60D5, 0x45EE, { 0x88, 0x3C, 0x45, 0x27, 0x08, 0xCD, 0x74, 0x3F }}\r
 \r
-  ## Print protocol defines basic print functions to print the format unicode and ascii string.\r
+  ## Print protocols define basic print functions to print the format unicode and ascii string.\r
   # Include/Protocol/Print2.h\r
   gEfiPrint2ProtocolGuid          = { 0xf05976ef, 0x83f1, 0x4f3d, { 0x86, 0x19, 0xf7, 0x59, 0x5d, 0x41, 0xe5, 0x38 } }\r
   # Include/Protocol/Print2.h\r
   gEfiPrint2ProtocolGuid          = { 0xf05976ef, 0x83f1, 0x4f3d, { 0x86, 0x19, 0xf7, 0x59, 0x5d, 0x41, 0xe5, 0x38 } }\r
+  gEfiPrint2SProtocolGuid         = { 0xcc252d2, 0xc106, 0x4661, { 0xb5, 0xbd, 0x31, 0x47, 0xa4, 0xf8, 0x1f, 0x92 } }\r
 \r
   ## This protocol defines the generic memory test interfaces in Dxe phase.\r
   # Include/Protocol/GenericMemoryTest.h\r
 \r
   ## This protocol defines the generic memory test interfaces in Dxe phase.\r
   # Include/Protocol/GenericMemoryTest.h\r
index af55acfd2ba2fd660ea6c4c0be2582ab86391eff..85bc724a9028211eaea1d1f785d45c08e2d522da 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 /** @file\r
-  This driver produces Print2 protocol layered on top of the PrintLib from the MdePkg.\r
+  This driver produces Print2 protocols layered on top of the PrintLib from the MdePkg.\r
 \r
 \r
-Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -35,6 +35,19 @@ CONST EFI_PRINT2_PROTOCOL mPrint2Protocol = {
   AsciiValueToString\r
 };\r
 \r
   AsciiValueToString\r
 };\r
 \r
+CONST EFI_PRINT2S_PROTOCOL mPrint2SProtocol = {\r
+  UnicodeBSPrint,\r
+  UnicodeSPrint,\r
+  UnicodeBSPrintAsciiFormat,\r
+  UnicodeSPrintAsciiFormat,\r
+  UnicodeValueToStringS,\r
+  AsciiBSPrint,\r
+  AsciiSPrint,\r
+  AsciiBSPrintUnicodeFormat,\r
+  AsciiSPrintUnicodeFormat,\r
+  AsciiValueToStringS\r
+};\r
+\r
 /**\r
   The user Entry Point for Print module.\r
 \r
 /**\r
   The user Entry Point for Print module.\r
 \r
@@ -59,6 +72,7 @@ PrintEntryPoint (
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &mPrintThunkHandle,\r
                   &gEfiPrint2ProtocolGuid, &mPrint2Protocol,\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &mPrintThunkHandle,\r
                   &gEfiPrint2ProtocolGuid, &mPrint2Protocol,\r
+                  &gEfiPrint2SProtocolGuid, &mPrint2SProtocol,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
index 9ea06520d1b8f6115d448a2151cac35fcd215959..19eef5a8a89d313d52ac6b1ed82d6189ae40410c 100644 (file)
@@ -1,9 +1,9 @@
 ## @file\r
 ## @file\r
-#  Print DXE driver that produces Print2 Protocol.\r
+#  Print DXE driver that produces Print2 Protocols.\r
 #\r
 #\r
-#  This driver produces Print2 protocol layered on top of the PrintLib from the MdePkg.\r
+#  This driver produces Print2 protocols layered on top of the PrintLib from the MdePkg.\r
 #\r
 #\r
-#  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
@@ -44,6 +44,7 @@
 \r
 [Protocols]\r
   gEfiPrint2ProtocolGuid    ## PRODUCES\r
 \r
 [Protocols]\r
   gEfiPrint2ProtocolGuid    ## PRODUCES\r
+  gEfiPrint2SProtocolGuid   ## PRODUCES\r
 \r
 [Depex]\r
   TRUE\r
 \r
 [Depex]\r
   TRUE\r
index accb114fa657538d3adb061cfc66cbee47b535c0..10f0ff81c580f93e5e6b824c31777ebd7d5121f0 100644 (file)
@@ -1,9 +1,9 @@
 // /** @file\r
 // /** @file\r
-// Print DXE driver that produces Print2 Protocol.\r
+// Print DXE driver that produces Print2 Protocols.\r
 //\r
 //\r
-// This driver produces Print2 protocol layered on top of the PrintLib from the MdePkg.\r
+// This driver produces Print2 protocols layered on top of the PrintLib from the MdePkg.\r
 //\r
 //\r
-// Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+// Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 //\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
 //\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
@@ -16,7 +16,7 @@
 // **/\r
 \r
 \r
 // **/\r
 \r
 \r
-#string STR_MODULE_ABSTRACT             #language en-US "Print DXE driver that produces Print2 Protocol"\r
+#string STR_MODULE_ABSTRACT             #language en-US "Print DXE driver that produces Print2 Protocols"\r
 \r
 \r
-#string STR_MODULE_DESCRIPTION          #language en-US "This driver produces Print2 protocol layered on top of the PrintLib from the MdePkg."\r
+#string STR_MODULE_DESCRIPTION          #language en-US "This driver produces Print2 protocols layered on top of the PrintLib from the MdePkg."\r
 \r
 \r