VirtualBox

Ignore:
Timestamp:
Mar 12, 2019 12:40:12 PM (6 years ago)
Author:
vboxsync
Message:

EFI: First step in UDK2018 merge. Does not build yet.

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Protocol.inf

    r58459 r77662  
    22#  Library instance that implements Print Library class based on protocol gEfiPrint2ProtocolGuid.
    33#
    4 #  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
     4#  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
    55#
    66#  This program and the accompanying materials
     
    3434  BaseLib
    3535  DebugLib
     36  PcdLib
    3637
    3738[Protocols]
    38   gEfiPrint2ProtocolGuid                         ## CONSUMES
     39  gEfiPrint2SProtocolGuid                        ## CONSUMES
     40
     41[Pcd]
     42  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength     ## SOMETIMES_CONSUMES
     43  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength   ## SOMETIMES_CONSUMES
    3944
    4045[Depex.common.DXE_DRIVER, Depex.common.DXE_RUNTIME_DRIVER, Depex.common.DXE_SAL_DRIVER, Depex.common.DXE_SMM_DRIVER]
    41   gEfiPrint2ProtocolGuid
     46  gEfiPrint2SProtocolGuid
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Protocol.uni

    r58464 r77662  
    1 // /** @file
    2 // Library instance that implements Print Library class based on protocol gEfiPrint2ProtocolGuid.
     1// /** @file
     2// Library instance that implements Print Library class based on protocol gEfiPrint2SProtocolGuid.
    33//
    4 // Library instance that implements Print Library class based on protocol gEfiPrint2ProtocolGuid.
     4// Library instance that implements Print Library class based on protocol gEfiPrint2SProtocolGuid.
    55//
    6 // Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
     6// Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
    77//
    88// This program and the accompanying materials
     
    1616
    1717
    18 #string STR_MODULE_ABSTRACT             #language en-US "Implements Print Library class based on protocol gEfiPrint2ProtocolGuid"
     18#string STR_MODULE_ABSTRACT             #language en-US "Implements Print Library class based on protocol gEfiPrint2SProtocolGuid"
    1919
    20 #string STR_MODULE_DESCRIPTION          #language en-US "Library instance that implements Print Library class based on protocol gEfiPrint2ProtocolGuid."
     20#string STR_MODULE_DESCRIPTION          #language en-US "Library instance that implements Print Library class based on protocol gEfiPrint2SProtocolGuid."
    2121
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c

    r58466 r77662  
    11/** @file
    2   Instance of Print Library based on gEfiPrint2ProtocolGuid.
     2  Instance of Print Library based on gEfiPrint2SProtocolGuid.
    33
    44  Implement the print library instance by wrap the interface
    5   provided in the Print2 protocol. This protocol is defined as the internal
     5  provided in the Print2S protocol. This protocol is defined as the internal
    66  protocol related to this implementation, not in the public spec. So, this
    77  library instance is only for this code base.
    88
    9 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
     9Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
    1010This program and the accompanying materials
    1111are licensed and made available under the terms and conditions of the BSD License
     
    2626#include <Library/BaseLib.h>
    2727#include <Library/DebugLib.h>
    28 
    29 EFI_PRINT2_PROTOCOL  *mPrint2Protocol = NULL;
    30 
    31 /**
    32   The constructor function caches the pointer to Print2 protocol.
    33 
    34   The constructor function locates Print2 protocol from protocol database.
     28#include <Library/PcdLib.h>
     29
     30#define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)
     31
     32//
     33// Safe print checks
     34//
     35#define RSIZE_MAX             (PcdGet32 (PcdMaximumUnicodeStringLength))
     36#define ASCII_RSIZE_MAX       (PcdGet32 (PcdMaximumAsciiStringLength))
     37
     38#define SAFE_PRINT_CONSTRAINT_CHECK(Expression, RetVal)  \
     39  do { \
     40    ASSERT (Expression); \
     41    if (!(Expression)) { \
     42      return RetVal; \
     43    } \
     44  } while (FALSE)
     45
     46EFI_PRINT2S_PROTOCOL  *mPrint2SProtocol = NULL;
     47
     48/**
     49  The constructor function caches the pointer to Print2S protocol.
     50
     51  The constructor function locates Print2S protocol from protocol database.
    3552  It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
    3653
     
    5168
    5269  Status = SystemTable->BootServices->LocateProtocol (
    53                                         &gEfiPrint2ProtocolGuid,
     70                                        &gEfiPrint2SProtocolGuid,
    5471                                        NULL,
    55                                         (VOID**) &mPrint2Protocol
     72                                        (VOID**) &mPrint2SProtocol
    5673                                        );
    5774  ASSERT_EFI_ERROR (Status);
    58   ASSERT (mPrint2Protocol != NULL);
     75  ASSERT (mPrint2SProtocol != NULL);
    5976
    6077  return Status;
     
    7289  @param  Size            The size, in bytes, of the BaseListMarker buffer.
    7390
    74   @return The number of bytes in BaseListMarker.  0 if BaseListMarker is too small.
     91  @return TRUE   The VA_LIST has been converted to BASE_LIST.
     92  @return FALSE  The VA_LIST has not been converted to BASE_LIST.
    7593
    7694**/
     
    91109  BOOLEAN    Done;
    92110
    93   ASSERT (Format         != NULL);
    94111  ASSERT (BaseListMarker != NULL);
     112  SAFE_PRINT_CONSTRAINT_CHECK ((Format != NULL), FALSE);
    95113
    96114  BaseListStart = BaseListMarker;
    97115
    98116  if (AsciiFormat) {
    99     ASSERT (AsciiStrSize (Format) != 0);
     117    if (ASCII_RSIZE_MAX != 0) {
     118      SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX + 1) <= ASCII_RSIZE_MAX), FALSE);
     119    }
    100120    BytesPerFormatCharacter = 1;
    101121    FormatMask = 0xff;
    102122  } else {
    103     ASSERT (StrSize ((CHAR16 *) Format) != 0);
     123    if (RSIZE_MAX != 0) {
     124      SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX + 1) <= RSIZE_MAX), FALSE);
     125    }
    104126    BytesPerFormatCharacter = 2;
    105127    FormatMask = 0xffff;
     
    109131  // Get the first character from the format string
    110132  //
    111   FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     133  FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    112134
    113135  while (FormatCharacter != 0) {
     
    127149        // Get the next character from the format string
    128150        //
    129         FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     151        FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    130152
    131153        switch (FormatCharacter) {
     
    178200      case 'X':
    179201      case 'x':
     202      case 'u':
    180203      case 'd':
    181204        if (Long) {
     
    204227    // If BASE_LIST is larger than Size, then return FALSE
    205228    //
    206     if ((UINTN)((UINT8 *)BaseListMarker - (UINT8 *)BaseListStart) > Size) {
     229    if (((UINTN)BaseListMarker - (UINTN)BaseListStart) > Size) {
     230      DEBUG ((DEBUG_ERROR, "The input variable argument list is too long. Please consider breaking into multiple print calls.\n"));
    207231      return FALSE;
    208232    }
     
    216240    // Get the next character from the format string
    217241    //
    218     FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     242    FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    219243  }
    220244  return TRUE;
     
    223247/**
    224248  Produces a Null-terminated Unicode string in an output buffer based on
    225   a Null-terminated Unicode format string and a VA_LIST argument list
     249  a Null-terminated Unicode format string and a VA_LIST argument list.
     250
     251  This function is similar as vsnprintf_s defined in C11.
    226252
    227253  Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
     
    232258  The number of Unicode characters in the produced output buffer is returned not including
    233259  the Null-terminator.
    234   If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
    235 
    236   If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
    237   If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
    238   If BufferSize > 1 and FormatString is NULL, then ASSERT().
    239   If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
     260
     261  If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
     262  If FormatString is not aligned on a 16-bit boundary, then ASSERT().
     263
     264  If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     265  unmodified and 0 is returned.
     266  If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     267  unmodified and 0 is returned.
     268  If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
     269  (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
     270  buffer is unmodified and 0 is returned.
    240271  If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
    241272  PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
    242   ASSERT().
    243   If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
    244   contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
    245   Null-terminator, then ASSERT().
     273  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     274
     275  If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
    246276
    247277  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    248278                          Unicode string.
    249279  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    250   @param  FormatString    Null-terminated Unicode format string.
     280  @param  FormatString    A Null-terminated Unicode format string.
    251281  @param  Marker          VA_LIST marker for the variable argument list.
    252282
     
    264294  )
    265295{
    266   UINT64  BaseListMarker[256 / sizeof (UINT64)];
    267 
    268   DxePrintLibPrint2ProtocolVaListToBaseList (
    269     FALSE,
    270     (CHAR8 *)FormatString,
    271     Marker,
    272     (BASE_LIST)BaseListMarker,
    273     sizeof (BaseListMarker) - 8
    274     );
     296  UINT64   BaseListMarker[256 / sizeof (UINT64)];
     297  BOOLEAN  Converted;
     298
     299  ASSERT_UNICODE_BUFFER (StartOfBuffer);
     300  ASSERT_UNICODE_BUFFER (FormatString);
     301
     302  Converted = DxePrintLibPrint2ProtocolVaListToBaseList (
     303                FALSE,
     304                (CHAR8 *)FormatString,
     305                Marker,
     306                (BASE_LIST)BaseListMarker,
     307                sizeof (BaseListMarker) - 8
     308                );
     309  if (!Converted) {
     310    return 0;
     311  }
    275312
    276313  return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
     
    279316/**
    280317  Produces a Null-terminated Unicode string in an output buffer based on
    281   a Null-terminated Unicode format string and a BASE_LIST argument list
     318  a Null-terminated Unicode format string and a BASE_LIST argument list.
    282319
    283320  Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
     
    288325  The number of Unicode characters in the produced output buffer is returned not including
    289326  the Null-terminator.
    290   If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
    291 
    292   If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
    293   If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
    294   If BufferSize > 1 and FormatString is NULL, then ASSERT().
    295   If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
     327
     328  If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
     329  If FormatString is not aligned on a 16-bit boundary, then ASSERT().
     330
     331  If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     332  unmodified and 0 is returned.
     333  If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     334  unmodified and 0 is returned.
     335  If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
     336  (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
     337  buffer is unmodified and 0 is returned.
    296338  If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
    297339  PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
    298   ASSERT().
    299   If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
    300   contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
    301   Null-terminator, then ASSERT().
     340  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     341
     342  If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
    302343
    303344  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    304345                          Unicode string.
    305346  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    306   @param  FormatString    Null-terminated Unicode format string.
     347  @param  FormatString    A Null-terminated Unicode format string.
    307348  @param  Marker          BASE_LIST marker for the variable argument list.
    308349
     
    320361  )
    321362{
    322   return mPrint2Protocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
     363  ASSERT_UNICODE_BUFFER (StartOfBuffer);
     364  ASSERT_UNICODE_BUFFER (FormatString);
     365  return mPrint2SProtocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
    323366}
    324367
     
    326369  Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
    327370  Unicode format string and variable argument list.
     371
     372  This function is similar as snprintf_s defined in C11.
    328373
    329374  Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
     
    333378  The number of Unicode characters in the produced output buffer is returned not including
    334379  the Null-terminator.
    335   If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
    336 
    337   If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
    338   If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
    339   If BufferSize > 1 and FormatString is NULL, then ASSERT().
    340   If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
     380
     381  If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
     382  If FormatString is not aligned on a 16-bit boundary, then ASSERT().
     383
     384  If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     385  unmodified and 0 is returned.
     386  If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     387  unmodified and 0 is returned.
     388  If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
     389  (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
     390  buffer is unmodified and 0 is returned.
    341391  If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
    342392  PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
    343   ASSERT().
    344   If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
    345   contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
    346   Null-terminator, then ASSERT().
     393  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     394
     395  If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.
    347396
    348397  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    349398                          Unicode string.
    350399  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    351   @param  FormatString    Null-terminated Unicode format string.
     400  @param  FormatString    A Null-terminated Unicode format string.
    352401  @param  ...             Variable argument list whose contents are accessed based on the
    353402                          format string specified by FormatString.
     
    377426/**
    378427  Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
    379   ASCII format string and a VA_LIST argument list
     428  ASCII format string and a VA_LIST argument list.
     429
     430  This function is similar as vsnprintf_s defined in C11.
    380431
    381432  Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
     
    386437  The number of Unicode characters in the produced output buffer is returned not including
    387438  the Null-terminator.
     439
     440  If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
     441
     442  If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     443  unmodified and 0 is returned.
     444  If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     445  unmodified and 0 is returned.
     446  If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
     447  (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
     448  buffer is unmodified and 0 is returned.
     449  If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
     450  PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
     451  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     452
    388453  If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
    389 
    390   If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
    391   If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
    392   If BufferSize > 1 and FormatString is NULL, then ASSERT().
    393   If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
    394   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
    395   ASSERT().
    396   If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
    397   contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
    398   Null-terminator, then ASSERT().
    399454
    400455  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    401456                          Unicode string.
    402457  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    403   @param  FormatString    Null-terminated Unicode format string.
     458  @param  FormatString    A Null-terminated ASCII format string.
    404459  @param  Marker          VA_LIST marker for the variable argument list.
    405460
     
    417472  )
    418473{
    419   UINT64  BaseListMarker[256 / sizeof (UINT64)];
    420 
    421   DxePrintLibPrint2ProtocolVaListToBaseList (
    422     TRUE,
    423     FormatString,
    424     Marker,
    425     (BASE_LIST)BaseListMarker,
    426     sizeof (BaseListMarker) - 8
    427     );
     474  UINT64   BaseListMarker[256 / sizeof (UINT64)];
     475  BOOLEAN  Converted;
     476
     477  ASSERT_UNICODE_BUFFER (StartOfBuffer);
     478
     479  Converted = DxePrintLibPrint2ProtocolVaListToBaseList (
     480                TRUE,
     481                FormatString,
     482                Marker,
     483                (BASE_LIST)BaseListMarker,
     484                sizeof (BaseListMarker) - 8
     485                );
     486  if (!Converted) {
     487    return 0;
     488  }
    428489
    429490  return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
     
    432493/**
    433494  Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
    434   ASCII format string and a BASE_LIST argument list
     495  ASCII format string and a BASE_LIST argument list.
    435496
    436497  Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
     
    441502  The number of Unicode characters in the produced output buffer is returned not including
    442503  the Null-terminator.
     504
     505  If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
     506
     507  If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     508  unmodified and 0 is returned.
     509  If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     510  unmodified and 0 is returned.
     511  If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
     512  (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
     513  buffer is unmodified and 0 is returned.
     514  If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
     515  PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
     516  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     517
    443518  If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
    444 
    445   If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
    446   If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
    447   If BufferSize > 1 and FormatString is NULL, then ASSERT().
    448   If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
    449   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
    450   ASSERT().
    451   If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
    452   contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
    453   Null-terminator, then ASSERT().
    454519
    455520  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    456521                          Unicode string.
    457522  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    458   @param  FormatString    Null-terminated Unicode format string.
     523  @param  FormatString    A Null-terminated ASCII format string.
    459524  @param  Marker          BASE_LIST marker for the variable argument list.
    460525
     
    472537  )
    473538{
    474   return mPrint2Protocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
     539  ASSERT_UNICODE_BUFFER (StartOfBuffer);
     540  return mPrint2SProtocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
    475541}
    476542
     
    478544  Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
    479545  ASCII format string and  variable argument list.
     546
     547  This function is similar as snprintf_s defined in C11.
    480548
    481549  Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
     
    486554  The number of Unicode characters in the produced output buffer is returned not including
    487555  the Null-terminator.
     556
     557  If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
     558
     559  If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     560  unmodified and 0 is returned.
     561  If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     562  unmodified and 0 is returned.
     563  If PcdMaximumUnicodeStringLength is not zero, and BufferSize >
     564  (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output
     565  buffer is unmodified and 0 is returned.
     566  If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
     567  PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
     568  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     569
    488570  If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
    489 
    490   If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
    491   If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
    492   If BufferSize > 1 and FormatString is NULL, then ASSERT().
    493   If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
    494   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
    495   ASSERT().
    496   If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
    497   contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
    498   Null-terminator, then ASSERT().
    499571
    500572  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    501573                          Unicode string.
    502574  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    503   @param  FormatString    Null-terminated Unicode format string.
     575  @param  FormatString    A Null-terminated ASCII format string.
    504576  @param  ...             Variable argument list whose contents are accessed based on the
    505577                          format string specified by FormatString.
     
    527599}
    528600
    529 /**
     601#ifndef DISABLE_NEW_DEPRECATED_INTERFACES
     602
     603/**
     604  [ATTENTION] This function is deprecated for security reason.
     605
    530606  Converts a decimal value to a Null-terminated Unicode string.
    531607
     
    577653  )
    578654{
    579   return mPrint2Protocol->UnicodeValueToString (Buffer, Flags, Value, Width);
     655  RETURN_STATUS  Status;
     656  UINTN          BufferSize;
     657
     658  if (Width == 0) {
     659    BufferSize = (MAXIMUM_VALUE_CHARACTERS + 1) * sizeof (CHAR16);
     660  } else {
     661    BufferSize = (Width + 1) * sizeof (CHAR16);
     662  }
     663
     664  Status = mPrint2SProtocol->UnicodeValueToStringS (Buffer, BufferSize, Flags, Value, Width);
     665  if (RETURN_ERROR (Status)) {
     666    return 0;
     667  }
     668
     669  return StrnLenS (Buffer, BufferSize / sizeof (CHAR16));
     670}
     671
     672#endif
     673
     674/**
     675  Converts a decimal value to a Null-terminated Unicode string.
     676
     677  Converts the decimal number specified by Value to a Null-terminated Unicode
     678  string specified by Buffer containing at most Width characters. No padding of
     679  spaces is ever performed. If Width is 0 then a width of
     680  MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than
     681  Width characters, then only the first Width characters are placed in Buffer.
     682  Additional conversion parameters are specified in Flags.
     683
     684  The Flags bit LEFT_JUSTIFY is always ignored.
     685  All conversions are left justified in Buffer.
     686  If Width is 0, PREFIX_ZERO is ignored in Flags.
     687  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and
     688  commas are inserted every 3rd digit starting from the right.
     689  If RADIX_HEX is set in Flags, then the output buffer will be formatted in
     690  hexadecimal format.
     691  If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in
     692  Buffer is a '-'.
     693  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then
     694  Buffer is padded with '0' characters so the combination of the optional '-'
     695  sign character, '0' characters, digit characters for Value, and the
     696  Null-terminator add up to Width characters.
     697
     698  If Buffer is not aligned on a 16-bit boundary, then ASSERT().
     699  If an error would be returned, then the function will also ASSERT().
     700
     701  @param  Buffer      The pointer to the output buffer for the produced
     702                      Null-terminated Unicode string.
     703  @param  BufferSize  The size of Buffer in bytes, including the
     704                      Null-terminator.
     705  @param  Flags       The bitmask of flags that specify left justification,
     706                      zero pad, and commas.
     707  @param  Value       The 64-bit signed value to convert to a string.
     708  @param  Width       The maximum number of Unicode characters to place in
     709                      Buffer, not including the Null-terminator.
     710
     711  @retval RETURN_SUCCESS           The decimal value is converted.
     712  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted
     713                                   value.
     714  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.
     715                                   If PcdMaximumUnicodeStringLength is not
     716                                   zero, and BufferSize is greater than
     717                                   (PcdMaximumUnicodeStringLength *
     718                                   sizeof (CHAR16) + 1).
     719                                   If unsupported bits are set in Flags.
     720                                   If both COMMA_TYPE and RADIX_HEX are set in
     721                                   Flags.
     722                                   If Width >= MAXIMUM_VALUE_CHARACTERS.
     723
     724**/
     725RETURN_STATUS
     726EFIAPI
     727UnicodeValueToStringS (
     728  IN OUT CHAR16  *Buffer,
     729  IN UINTN       BufferSize,
     730  IN UINTN       Flags,
     731  IN INT64       Value,
     732  IN UINTN       Width
     733  )
     734{
     735  return mPrint2SProtocol->UnicodeValueToStringS (Buffer, BufferSize, Flags, Value, Width);
    580736}
    581737
     
    583739  Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
    584740  ASCII format string and a VA_LIST argument list.
     741
     742  This function is similar as vsnprintf_s defined in C11.
    585743
    586744  Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
     
    591749  The number of ASCII characters in the produced output buffer is returned not including
    592750  the Null-terminator.
     751
     752  If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     753  unmodified and 0 is returned.
     754  If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     755  unmodified and 0 is returned.
     756  If PcdMaximumAsciiStringLength is not zero, and BufferSize >
     757  (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
     758  is unmodified and 0 is returned.
     759  If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
     760  PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
     761  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     762
    593763  If BufferSize is 0, then no output buffer is produced and 0 is returned.
    594 
    595   If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
    596   If BufferSize > 0 and FormatString is NULL, then ASSERT().
    597   If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
    598   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
    599   ASSERT().
    600   If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
    601   contains more than PcdMaximumAsciiStringLength ASCII characters not including the
    602   Null-terminator, then ASSERT().
    603764
    604765  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    605766                          ASCII string.
    606767  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    607   @param  FormatString    Null-terminated Unicode format string.
     768  @param  FormatString    A Null-terminated ASCII format string.
    608769  @param  Marker          VA_LIST marker for the variable argument list.
    609770
     
    621782  )
    622783{
    623   UINT64  BaseListMarker[256 / sizeof (UINT64)];
    624 
    625   DxePrintLibPrint2ProtocolVaListToBaseList (
    626     TRUE,
    627     FormatString,
    628     Marker,
    629     (BASE_LIST)BaseListMarker,
    630     sizeof (BaseListMarker) - 8
    631     );
     784  UINT64   BaseListMarker[256 / sizeof (UINT64)];
     785  BOOLEAN  Converted;
     786
     787  Converted = DxePrintLibPrint2ProtocolVaListToBaseList (
     788                TRUE,
     789                FormatString,
     790                Marker,
     791                (BASE_LIST)BaseListMarker,
     792                sizeof (BaseListMarker) - 8
     793                );
     794  if (!Converted) {
     795    return 0;
     796  }
    632797
    633798  return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
     
    645810  The number of ASCII characters in the produced output buffer is returned not including
    646811  the Null-terminator.
     812
     813  If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     814  unmodified and 0 is returned.
     815  If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     816  unmodified and 0 is returned.
     817  If PcdMaximumAsciiStringLength is not zero, and BufferSize >
     818  (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
     819  is unmodified and 0 is returned.
     820  If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
     821  PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
     822  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     823
    647824  If BufferSize is 0, then no output buffer is produced and 0 is returned.
    648 
    649   If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
    650   If BufferSize > 0 and FormatString is NULL, then ASSERT().
    651   If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
    652   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
    653   ASSERT().
    654   If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
    655   contains more than PcdMaximumAsciiStringLength ASCII characters not including the
    656   Null-terminator, then ASSERT().
    657825
    658826  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    659827                          ASCII string.
    660828  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    661   @param  FormatString    Null-terminated Unicode format string.
     829  @param  FormatString    A Null-terminated ASCII format string.
    662830  @param  Marker          BASE_LIST marker for the variable argument list.
    663831
     
    675843  )
    676844{
    677   return mPrint2Protocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
     845  return mPrint2SProtocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
    678846}
    679847
     
    681849  Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
    682850  ASCII format string and  variable argument list.
     851
     852  This function is similar as snprintf_s defined in C11.
    683853
    684854  Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
     
    689859  The number of ASCII characters in the produced output buffer is returned not including
    690860  the Null-terminator.
     861
     862  If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     863  unmodified and 0 is returned.
     864  If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     865  unmodified and 0 is returned.
     866  If PcdMaximumAsciiStringLength is not zero, and BufferSize >
     867  (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
     868  is unmodified and 0 is returned.
     869  If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
     870  PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then
     871  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     872
    691873  If BufferSize is 0, then no output buffer is produced and 0 is returned.
    692 
    693   If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
    694   If BufferSize > 0 and FormatString is NULL, then ASSERT().
    695   If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
    696   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
    697   ASSERT().
    698   If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
    699   contains more than PcdMaximumAsciiStringLength ASCII characters not including the
    700   Null-terminator, then ASSERT().
    701874
    702875  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    703876                          ASCII string.
    704877  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    705   @param  FormatString    Null-terminated Unicode format string.
     878  @param  FormatString    A Null-terminated ASCII format string.
    706879  @param  ...             Variable argument list whose contents are accessed based on the
    707880                          format string specified by FormatString.
     
    731904/**
    732905  Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
    733   ASCII format string and a VA_LIST argument list.
     906  Unicode format string and a VA_LIST argument list.
     907
     908  This function is similar as vsnprintf_s defined in C11.
    734909
    735910  Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
     
    740915  The number of ASCII characters in the produced output buffer is returned not including
    741916  the Null-terminator.
    742   If BufferSize is 0, then no output buffer is produced and 0 is returned.
    743 
    744   If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
    745   If BufferSize > 0 and FormatString is NULL, then ASSERT().
    746   If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
     917
     918  If FormatString is not aligned on a 16-bit boundary, then ASSERT().
     919
     920  If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     921  unmodified and 0 is returned.
     922  If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     923  unmodified and 0 is returned.
     924  If PcdMaximumAsciiStringLength is not zero, and BufferSize >
     925  (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
     926  is unmodified and 0 is returned.
    747927  If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
    748928  PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
    749   ASSERT().
    750   If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
    751   contains more than PcdMaximumAsciiStringLength ASCII characters not including the
    752   Null-terminator, then ASSERT().
     929  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     930
     931  If BufferSize is 0, then no output buffer is produced and 0 is returned.
    753932
    754933  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    755934                          ASCII string.
    756935  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    757   @param  FormatString    Null-terminated Unicode format string.
     936  @param  FormatString    A Null-terminated Unicode format string.
    758937  @param  Marker          VA_LIST marker for the variable argument list.
    759938
     
    771950  )
    772951{
    773   UINT64  BaseListMarker[256 / sizeof (UINT64)];
    774 
    775   DxePrintLibPrint2ProtocolVaListToBaseList (
    776     FALSE,
    777     (CHAR8 *)FormatString,
    778     Marker,
    779     (BASE_LIST)BaseListMarker,
    780     sizeof (BaseListMarker) - 8
    781     );
     952  UINT64   BaseListMarker[256 / sizeof (UINT64)];
     953  BOOLEAN  Converted;
     954
     955  ASSERT_UNICODE_BUFFER (FormatString);
     956
     957  Converted = DxePrintLibPrint2ProtocolVaListToBaseList (
     958                FALSE,
     959                (CHAR8 *)FormatString,
     960                Marker,
     961                (BASE_LIST)BaseListMarker,
     962                sizeof (BaseListMarker) - 8
     963                );
     964  if (!Converted) {
     965    return 0;
     966  }
    782967
    783968  return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
     
    786971/**
    787972  Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
    788   ASCII format string and a BASE_LIST argument list.
     973  Unicode format string and a BASE_LIST argument list.
    789974
    790975  Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
     
    795980  The number of ASCII characters in the produced output buffer is returned not including
    796981  the Null-terminator.
    797   If BufferSize is 0, then no output buffer is produced and 0 is returned.
    798 
    799   If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
    800   If BufferSize > 0 and FormatString is NULL, then ASSERT().
    801   If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
     982
     983  If FormatString is not aligned on a 16-bit boundary, then ASSERT().
     984
     985  If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     986  unmodified and 0 is returned.
     987  If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     988  unmodified and 0 is returned.
     989  If PcdMaximumAsciiStringLength is not zero, and BufferSize >
     990  (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
     991  is unmodified and 0 is returned.
    802992  If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
    803993  PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
    804   ASSERT().
    805   If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
    806   contains more than PcdMaximumAsciiStringLength ASCII characters not including the
    807   Null-terminator, then ASSERT().
     994  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     995
     996  If BufferSize is 0, then no output buffer is produced and 0 is returned.
    808997
    809998  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    810999                          ASCII string.
    8111000  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    812   @param  FormatString    Null-terminated Unicode format string.
     1001  @param  FormatString    A Null-terminated Unicode format string.
    8131002  @param  Marker          BASE_LIST marker for the variable argument list.
    8141003
     
    8261015  )
    8271016{
    828   return mPrint2Protocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
     1017  ASSERT_UNICODE_BUFFER (FormatString);
     1018  return mPrint2SProtocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
    8291019}
    8301020
    8311021/**
    8321022  Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
    833   ASCII format string and  variable argument list.
     1023  Unicode format string and  variable argument list.
     1024
     1025  This function is similar as snprintf_s defined in C11.
    8341026
    8351027  Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
     
    8401032  The number of ASCII characters in the produced output buffer is returned not including
    8411033  the Null-terminator.
    842   If BufferSize is 0, then no output buffer is produced and 0 is returned.
    843 
    844   If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
    845   If BufferSize > 0 and FormatString is NULL, then ASSERT().
    846   If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
     1034
     1035  If FormatString is not aligned on a 16-bit boundary, then ASSERT().
     1036
     1037  If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is
     1038  unmodified and 0 is returned.
     1039  If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is
     1040  unmodified and 0 is returned.
     1041  If PcdMaximumAsciiStringLength is not zero, and BufferSize >
     1042  (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer
     1043  is unmodified and 0 is returned.
    8471044  If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
    8481045  PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
    849   ASSERT().
    850   If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
    851   contains more than PcdMaximumAsciiStringLength ASCII characters not including the
    852   Null-terminator, then ASSERT().
     1046  ASSERT(). Also, the output buffer is unmodified and 0 is returned.
     1047
     1048  If BufferSize is 0, then no output buffer is produced and 0 is returned.
    8531049
    8541050  @param  StartOfBuffer   A pointer to the output buffer for the produced Null-terminated
    8551051                          ASCII string.
    8561052  @param  BufferSize      The size, in bytes, of the output buffer specified by StartOfBuffer.
    857   @param  FormatString    Null-terminated Unicode format string.
     1053  @param  FormatString    A Null-terminated Unicode format string.
    8581054  @param  ...             Variable argument list whose contents are accessed based on the
    8591055                          format string specified by FormatString.
     
    8821078
    8831079
    884 /**
     1080#ifndef DISABLE_NEW_DEPRECATED_INTERFACES
     1081
     1082/**
     1083  [ATTENTION] This function is deprecated for security reason.
     1084
    8851085  Converts a decimal value to a Null-terminated ASCII string.
    8861086
     
    9311131  )
    9321132{
    933   return mPrint2Protocol->AsciiValueToString (Buffer, Flags, Value, Width);
     1133  RETURN_STATUS  Status;
     1134  UINTN          BufferSize;
     1135
     1136  if (Width == 0) {
     1137    BufferSize = (MAXIMUM_VALUE_CHARACTERS + 1) * sizeof (CHAR8);
     1138  } else {
     1139    BufferSize = (Width + 1) * sizeof (CHAR8);
     1140  }
     1141
     1142  Status = mPrint2SProtocol->AsciiValueToStringS (Buffer, BufferSize, Flags, Value, Width);
     1143  if (RETURN_ERROR (Status)) {
     1144    return 0;
     1145  }
     1146
     1147  return AsciiStrnLenS (Buffer, BufferSize / sizeof (CHAR8));
     1148}
     1149
     1150#endif
     1151
     1152/**
     1153  Converts a decimal value to a Null-terminated Ascii string.
     1154
     1155  Converts the decimal number specified by Value to a Null-terminated Ascii
     1156  string specified by Buffer containing at most Width characters. No padding of
     1157  spaces is ever performed. If Width is 0 then a width of
     1158  MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than
     1159  Width characters, then only the first Width characters are placed in Buffer.
     1160  Additional conversion parameters are specified in Flags.
     1161
     1162  The Flags bit LEFT_JUSTIFY is always ignored.
     1163  All conversions are left justified in Buffer.
     1164  If Width is 0, PREFIX_ZERO is ignored in Flags.
     1165  If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and
     1166  commas are inserted every 3rd digit starting from the right.
     1167  If RADIX_HEX is set in Flags, then the output buffer will be formatted in
     1168  hexadecimal format.
     1169  If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in
     1170  Buffer is a '-'.
     1171  If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then
     1172  Buffer is padded with '0' characters so the combination of the optional '-'
     1173  sign character, '0' characters, digit characters for Value, and the
     1174  Null-terminator add up to Width characters.
     1175
     1176  If an error would be returned, then the function will ASSERT().
     1177
     1178  @param  Buffer      The pointer to the output buffer for the produced
     1179                      Null-terminated Ascii string.
     1180  @param  BufferSize  The size of Buffer in bytes, including the
     1181                      Null-terminator.
     1182  @param  Flags       The bitmask of flags that specify left justification,
     1183                      zero pad, and commas.
     1184  @param  Value       The 64-bit signed value to convert to a string.
     1185  @param  Width       The maximum number of Ascii characters to place in
     1186                      Buffer, not including the Null-terminator.
     1187
     1188  @retval RETURN_SUCCESS           The decimal value is converted.
     1189  @retval RETURN_BUFFER_TOO_SMALL  If BufferSize cannot hold the converted
     1190                                   value.
     1191  @retval RETURN_INVALID_PARAMETER If Buffer is NULL.
     1192                                   If PcdMaximumAsciiStringLength is not
     1193                                   zero, and BufferSize is greater than
     1194                                   PcdMaximumAsciiStringLength.
     1195                                   If unsupported bits are set in Flags.
     1196                                   If both COMMA_TYPE and RADIX_HEX are set in
     1197                                   Flags.
     1198                                   If Width >= MAXIMUM_VALUE_CHARACTERS.
     1199
     1200**/
     1201RETURN_STATUS
     1202EFIAPI
     1203AsciiValueToStringS (
     1204  IN OUT CHAR8   *Buffer,
     1205  IN UINTN       BufferSize,
     1206  IN UINTN       Flags,
     1207  IN INT64       Value,
     1208  IN UINTN       Width
     1209  )
     1210{
     1211  return mPrint2SProtocol->AsciiValueToStringS (Buffer, BufferSize, Flags, Value, Width);
    9341212}
    9351213
     
    9441222#define ARGUMENT_REVERSED     BIT12
    9451223#define COUNT_ONLY_NO_PRINT   BIT13
     1224#define UNSIGNED_TYPE         BIT14
    9461225
    9471226//
     
    10801359#define ERROR_STATUS_NUMBER           33
    10811360
    1082 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = {
     1361GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * CONST mStatusString[] = {
    10831362  "Success",                      //  RETURN_SUCCESS                = 0
    10841363  "Warning Unknown Glyph",        //  RETURN_WARN_UNKNOWN_GLYPH     = 1
     
    12351514  //
    12361515
     1516  //
     1517  // 1. Buffer shall not be a null pointer when both BufferSize > 0 and
     1518  //    COUNT_ONLY_NO_PRINT is not set in Flags.
     1519  //
     1520  if ((BufferSize > 0) && ((Flags & COUNT_ONLY_NO_PRINT) == 0)) {
     1521    SAFE_PRINT_CONSTRAINT_CHECK ((Buffer != NULL), 0);
     1522  }
     1523
     1524  //
     1525  // 2. Format shall not be a null pointer when BufferSize > 0 or when
     1526  //    COUNT_ONLY_NO_PRINT is set in Flags.
     1527  //
     1528  if ((BufferSize > 0) || ((Flags & COUNT_ONLY_NO_PRINT) != 0)) {
     1529    SAFE_PRINT_CONSTRAINT_CHECK ((Format != NULL), 0);
     1530  }
     1531
     1532  //
     1533  // 3. BufferSize shall not be greater than RSIZE_MAX for Unicode output or
     1534  //    ASCII_RSIZE_MAX for Ascii output.
     1535  //
     1536  if ((Flags & OUTPUT_UNICODE) != 0) {
     1537    if (RSIZE_MAX != 0) {
     1538      SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= RSIZE_MAX), 0);
     1539    }
     1540    BytesPerOutputCharacter = 2;
     1541  } else {
     1542    if (ASCII_RSIZE_MAX != 0) {
     1543      SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= ASCII_RSIZE_MAX), 0);
     1544    }
     1545    BytesPerOutputCharacter = 1;
     1546  }
     1547
     1548  //
     1549  // 4. Format shall not contain more than RSIZE_MAX Unicode characters or
     1550  //    ASCII_RSIZE_MAX Ascii characters.
     1551  //
     1552  if ((Flags & FORMAT_UNICODE) != 0) {
     1553    if (RSIZE_MAX != 0) {
     1554      SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX + 1) <= RSIZE_MAX), 0);
     1555    }
     1556    BytesPerFormatCharacter = 2;
     1557    FormatMask = 0xffff;
     1558  } else {
     1559    if (ASCII_RSIZE_MAX != 0) {
     1560      SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX + 1) <= ASCII_RSIZE_MAX), 0);
     1561    }
     1562    BytesPerFormatCharacter = 1;
     1563    FormatMask = 0xff;
     1564  }
     1565
    12371566  if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
    12381567    if (BufferSize == 0) {
     
    12461575      return 0;
    12471576    }
    1248     ASSERT (Buffer != NULL);
    1249   }
    1250 
    1251   if ((Flags & OUTPUT_UNICODE) != 0) {
    1252     BytesPerOutputCharacter = 2;
    1253   } else {
    1254     BytesPerOutputCharacter = 1;
    12551577  }
    12561578
     
    12721594  }
    12731595
    1274   if ((Flags & FORMAT_UNICODE) != 0) {
    1275     //
    1276     // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
    1277     // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
    1278     //
    1279     ASSERT (StrSize ((CHAR16 *) Format) != 0);
    1280     BytesPerFormatCharacter = 2;
    1281     FormatMask = 0xffff;
    1282   } else {
    1283     //
    1284     // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
    1285     // Ascii characters if PcdMaximumAsciiStringLength is not zero.
    1286     //
    1287     ASSERT (AsciiStrSize (Format) != 0);
    1288     BytesPerFormatCharacter = 1;
    1289     FormatMask = 0xff;
    1290   }
    1291 
    12921596  //
    12931597  // Get the first character from the format string
    12941598  //
    1295   FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     1599  FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    12961600
    12971601  //
     
    13251629      for (Done = FALSE; !Done; ) {
    13261630        Format += BytesPerFormatCharacter;
    1327         FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     1631        FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    13281632        switch (FormatCharacter) {
    13291633        case '.':
     
    13781682            Count = (Count * 10) + FormatCharacter - '0';
    13791683            Format += BytesPerFormatCharacter;
    1380             FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     1684            FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    13811685          }
    13821686          Format -= BytesPerFormatCharacter;
     
    14301734        // break skipped on purpose
    14311735        //
     1736      case 'u':
     1737        if ((Flags & RADIX_HEX) == 0) {
     1738          Flags &= ~((UINTN) (PREFIX_SIGN));
     1739          Flags |= UNSIGNED_TYPE;
     1740        }
     1741        //
     1742        // break skipped on purpose
     1743        //
    14321744      case 'd':
    14331745        if ((Flags & LONG_TYPE) == 0) {
    14341746          //
    1435           // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
     1747          // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
    14361748          // This assumption is made so the format string definition is compatible with the ANSI C
    14371749          // Specification for formatted strings.  It is recommended that the Base Types be used
     
    14671779            Precision = 1;
    14681780          }
    1469           if (Value < 0) {
     1781          if (Value < 0 && (Flags & UNSIGNED_TYPE) == 0) {
    14701782            Flags |= PREFIX_SIGN;
    14711783            Prefix = '-';
    14721784            Value = -Value;
     1785          } else if ((Flags & UNSIGNED_TYPE) != 0 && (Flags & LONG_TYPE) == 0) {
     1786            //
     1787            // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
     1788            // This assumption is made so the format string definition is compatible with the ANSI C
     1789            // Specification for formatted strings.  It is recommended that the Base Types be used
     1790            // everywhere, but in this one case, compliance with ANSI C is more important, and
     1791            // provides an implementation that is compatible with that largest possible set of CPU
     1792            // architectures.  This is why the type "unsigned int" is used in this one case.
     1793            //
     1794            Value = (unsigned int)Value;
    14731795          }
    14741796        } else {
     
    14771799          if ((Flags & LONG_TYPE) == 0 && Value < 0) {
    14781800            //
    1479             // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
     1801            // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
    14801802            // This assumption is made so the format string definition is compatible with the ANSI C
    14811803            // Specification for formatted strings.  It is recommended that the Base Types be used
     
    16391961      case '\r':
    16401962        Format += BytesPerFormatCharacter;
    1641         FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     1963        FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    16421964        if (FormatCharacter == '\n') {
    16431965          //
     
    16601982        ArgumentString = "\r\n";
    16611983        Format += BytesPerFormatCharacter;
    1662         FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     1984        FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    16631985        if (FormatCharacter != '\r') {
    16641986          Format   -= BytesPerFormatCharacter;
     
    16792001    case '\r':
    16802002      Format += BytesPerFormatCharacter;
    1681       FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     2003      FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    16822004      if (FormatCharacter == '\n') {
    16832005        //
     
    17002022      ArgumentString = "\r\n";
    17012023      Format += BytesPerFormatCharacter;
    1702       FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     2024      FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    17032025      if (FormatCharacter != '\r') {
    17042026        Format   -= BytesPerFormatCharacter;
     
    17292051      // ArgumentString is either null-terminated, or it contains Precision characters
    17302052      //
    1731       for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {
     2053      for (Count = 0;
     2054            (ArgumentString[Count * BytesPerArgumentCharacter] != '\0' ||
     2055             (BytesPerArgumentCharacter > 1 &&
     2056              ArgumentString[Count * BytesPerArgumentCharacter + 1]!= '\0')) &&
     2057            (Count < Precision || ((Flags & PRECISION) == 0));
     2058            Count++) {
    17322059        ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
    17332060        if (ArgumentCharacter == 0) {
     
    17862113    // Copy the string into the output buffer performing the required type conversions
    17872114    //
    1788     while (Index < Count) {
    1789       ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;
     2115    while (Index < Count &&
     2116           (ArgumentString[0] != '\0' ||
     2117            (BytesPerArgumentCharacter > 1 && ArgumentString[1] != '\0'))) {
     2118      ArgumentCharacter = ((*ArgumentString & 0xff) | (((UINT8)*(ArgumentString + 1)) << 8)) & ArgumentMask;
    17902119
    17912120      LengthToReturn += (1 * BytesPerOutputCharacter);
     
    18282157    // Get the next character from the format string
    18292158    //
    1830     FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
     2159    FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;
    18312160  }
    18322161
     
    18402169  //
    18412170  InternalPrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);
    1842   //
    1843   // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
    1844   // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
    1845   //
    1846   ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));
    1847   //
    1848   // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
    1849   // ASCII characters if PcdMaximumAsciiStringLength is not zero.
    1850   //
    1851   ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));
    18522171
    18532172  return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
     
    18582177  output were produced not including the Null-terminator.
    18592178
    1860   If FormatString is NULL, then ASSERT().
    18612179  If FormatString is not aligned on a 16-bit boundary, then ASSERT().
     2180
     2181  If FormatString is NULL, then ASSERT() and 0 is returned.
     2182  If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more
     2183  than PcdMaximumUnicodeStringLength Unicode characters not including the
     2184  Null-terminator, then ASSERT() and 0 is returned.
    18622185
    18632186  @param[in]  FormatString    A Null-terminated Unicode format string.
     
    18742197  )
    18752198{
    1876   ASSERT(FormatString != NULL);
     2199  ASSERT_UNICODE_BUFFER (FormatString);
    18772200  return InternalPrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);
    18782201}
     
    18822205  output were produced not including the Null-terminator.
    18832206
    1884   If FormatString is NULL, then ASSERT().
     2207  If FormatString is NULL, then ASSERT() and 0 is returned.
     2208  If PcdMaximumAsciiStringLength is not zero, and FormatString contains more
     2209  than PcdMaximumAsciiStringLength Ascii characters not including the
     2210  Null-terminator, then ASSERT() and 0 is returned.
    18852211
    18862212  @param[in]  FormatString    A Null-terminated ASCII format string.
     
    18972223  )
    18982224{
    1899   ASSERT(FormatString != NULL);
    19002225  return InternalPrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);
    19012226}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette