Changeset 77662 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxePrintLibPrint2Protocol
- Timestamp:
- Mar 12, 2019 12:40:12 PM (6 years ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776 /vendor/edk2/current 103735-103757,103769-103776,129194-129237
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Protocol.inf
r58459 r77662 2 2 # Library instance that implements Print Library class based on protocol gEfiPrint2ProtocolGuid. 3 3 # 4 # Copyright (c) 2009 - 201 4, Intel Corporation. All rights reserved.<BR>4 # Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR> 5 5 # 6 6 # This program and the accompanying materials … … 34 34 BaseLib 35 35 DebugLib 36 PcdLib 36 37 37 38 [Protocols] 38 gEfiPrint2ProtocolGuid ## CONSUMES 39 gEfiPrint2SProtocolGuid ## CONSUMES 40 41 [Pcd] 42 gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength ## SOMETIMES_CONSUMES 43 gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength ## SOMETIMES_CONSUMES 39 44 40 45 [Depex.common.DXE_DRIVER, Depex.common.DXE_RUNTIME_DRIVER, Depex.common.DXE_SAL_DRIVER, Depex.common.DXE_SMM_DRIVER] 41 gEfiPrint2 ProtocolGuid46 gEfiPrint2SProtocolGuid -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Protocol.uni
r58464 r77662 1 // /** @file2 // Library instance that implements Print Library class based on protocol gEfiPrint2 ProtocolGuid.1 // /** @file 2 // Library instance that implements Print Library class based on protocol gEfiPrint2SProtocolGuid. 3 3 // 4 // Library instance that implements Print Library class based on protocol gEfiPrint2 ProtocolGuid.4 // Library instance that implements Print Library class based on protocol gEfiPrint2SProtocolGuid. 5 5 // 6 // Copyright (c) 2009 - 201 4, Intel Corporation. All rights reserved.<BR>6 // Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR> 7 7 // 8 8 // This program and the accompanying materials … … 16 16 17 17 18 #string STR_MODULE_ABSTRACT #language en-US "Implements Print Library class based on protocol gEfiPrint2 ProtocolGuid"18 #string STR_MODULE_ABSTRACT #language en-US "Implements Print Library class based on protocol gEfiPrint2SProtocolGuid" 19 19 20 #string STR_MODULE_DESCRIPTION #language en-US "Library instance that implements Print Library class based on protocol gEfiPrint2 ProtocolGuid."20 #string STR_MODULE_DESCRIPTION #language en-US "Library instance that implements Print Library class based on protocol gEfiPrint2SProtocolGuid." 21 21 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
r58466 r77662 1 1 /** @file 2 Instance of Print Library based on gEfiPrint2 ProtocolGuid.2 Instance of Print Library based on gEfiPrint2SProtocolGuid. 3 3 4 4 Implement the print library instance by wrap the interface 5 provided in the Print2 protocol. This protocol is defined as the internal5 provided in the Print2S protocol. This protocol is defined as the internal 6 6 protocol related to this implementation, not in the public spec. So, this 7 7 library instance is only for this code base. 8 8 9 Copyright (c) 2009 - 201 5, Intel Corporation. All rights reserved.<BR>9 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR> 10 10 This program and the accompanying materials 11 11 are licensed and made available under the terms and conditions of the BSD License … … 26 26 #include <Library/BaseLib.h> 27 27 #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 46 EFI_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. 35 52 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. 36 53 … … 51 68 52 69 Status = SystemTable->BootServices->LocateProtocol ( 53 &gEfiPrint2 ProtocolGuid,70 &gEfiPrint2SProtocolGuid, 54 71 NULL, 55 (VOID**) &mPrint2 Protocol72 (VOID**) &mPrint2SProtocol 56 73 ); 57 74 ASSERT_EFI_ERROR (Status); 58 ASSERT (mPrint2 Protocol != NULL);75 ASSERT (mPrint2SProtocol != NULL); 59 76 60 77 return Status; … … 72 89 @param Size The size, in bytes, of the BaseListMarker buffer. 73 90 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. 75 93 76 94 **/ … … 91 109 BOOLEAN Done; 92 110 93 ASSERT (Format != NULL);94 111 ASSERT (BaseListMarker != NULL); 112 SAFE_PRINT_CONSTRAINT_CHECK ((Format != NULL), FALSE); 95 113 96 114 BaseListStart = BaseListMarker; 97 115 98 116 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 } 100 120 BytesPerFormatCharacter = 1; 101 121 FormatMask = 0xff; 102 122 } 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 } 104 126 BytesPerFormatCharacter = 2; 105 127 FormatMask = 0xffff; … … 109 131 // Get the first character from the format string 110 132 // 111 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;133 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 112 134 113 135 while (FormatCharacter != 0) { … … 127 149 // Get the next character from the format string 128 150 // 129 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;151 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 130 152 131 153 switch (FormatCharacter) { … … 178 200 case 'X': 179 201 case 'x': 202 case 'u': 180 203 case 'd': 181 204 if (Long) { … … 204 227 // If BASE_LIST is larger than Size, then return FALSE 205 228 // 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")); 207 231 return FALSE; 208 232 } … … 216 240 // Get the next character from the format string 217 241 // 218 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;242 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 219 243 } 220 244 return TRUE; … … 223 247 /** 224 248 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. 226 252 227 253 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer … … 232 258 The number of Unicode characters in the produced output buffer is returned not including 233 259 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. 240 271 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than 241 272 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. 246 276 247 277 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 248 278 Unicode string. 249 279 @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. 251 281 @param Marker VA_LIST marker for the variable argument list. 252 282 … … 264 294 ) 265 295 { 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 } 275 312 276 313 return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker); … … 279 316 /** 280 317 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. 282 319 283 320 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer … … 288 325 The number of Unicode characters in the produced output buffer is returned not including 289 326 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. 296 338 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than 297 339 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. 302 343 303 344 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 304 345 Unicode string. 305 346 @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. 307 348 @param Marker BASE_LIST marker for the variable argument list. 308 349 … … 320 361 ) 321 362 { 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); 323 366 } 324 367 … … 326 369 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated 327 370 Unicode format string and variable argument list. 371 372 This function is similar as snprintf_s defined in C11. 328 373 329 374 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer … … 333 378 The number of Unicode characters in the produced output buffer is returned not including 334 379 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. 341 391 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than 342 392 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. 347 396 348 397 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 349 398 Unicode string. 350 399 @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. 352 401 @param ... Variable argument list whose contents are accessed based on the 353 402 format string specified by FormatString. … … 377 426 /** 378 427 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. 380 431 381 432 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer … … 386 437 The number of Unicode characters in the produced output buffer is returned not including 387 438 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 388 453 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 than394 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then395 ASSERT().396 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string397 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the398 Null-terminator, then ASSERT().399 454 400 455 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 401 456 Unicode string. 402 457 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. 403 @param FormatString Null-terminated Unicodeformat string.458 @param FormatString A Null-terminated ASCII format string. 404 459 @param Marker VA_LIST marker for the variable argument list. 405 460 … … 417 472 ) 418 473 { 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 } 428 489 429 490 return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker); … … 432 493 /** 433 494 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. 435 496 436 497 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer … … 441 502 The number of Unicode characters in the produced output buffer is returned not including 442 503 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 443 518 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 than449 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then450 ASSERT().451 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string452 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the453 Null-terminator, then ASSERT().454 519 455 520 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 456 521 Unicode string. 457 522 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. 458 @param FormatString Null-terminated Unicodeformat string.523 @param FormatString A Null-terminated ASCII format string. 459 524 @param Marker BASE_LIST marker for the variable argument list. 460 525 … … 472 537 ) 473 538 { 474 return mPrint2Protocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker); 539 ASSERT_UNICODE_BUFFER (StartOfBuffer); 540 return mPrint2SProtocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker); 475 541 } 476 542 … … 478 544 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated 479 545 ASCII format string and variable argument list. 546 547 This function is similar as snprintf_s defined in C11. 480 548 481 549 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer … … 486 554 The number of Unicode characters in the produced output buffer is returned not including 487 555 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 488 570 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 than494 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then495 ASSERT().496 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string497 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the498 Null-terminator, then ASSERT().499 571 500 572 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 501 573 Unicode string. 502 574 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. 503 @param FormatString Null-terminated Unicodeformat string.575 @param FormatString A Null-terminated ASCII format string. 504 576 @param ... Variable argument list whose contents are accessed based on the 505 577 format string specified by FormatString. … … 527 599 } 528 600 529 /** 601 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES 602 603 /** 604 [ATTENTION] This function is deprecated for security reason. 605 530 606 Converts a decimal value to a Null-terminated Unicode string. 531 607 … … 577 653 ) 578 654 { 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 **/ 725 RETURN_STATUS 726 EFIAPI 727 UnicodeValueToStringS ( 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); 580 736 } 581 737 … … 583 739 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated 584 740 ASCII format string and a VA_LIST argument list. 741 742 This function is similar as vsnprintf_s defined in C11. 585 743 586 744 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer … … 591 749 The number of ASCII characters in the produced output buffer is returned not including 592 750 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 593 763 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 than598 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then599 ASSERT().600 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string601 contains more than PcdMaximumAsciiStringLength ASCII characters not including the602 Null-terminator, then ASSERT().603 764 604 765 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 605 766 ASCII string. 606 767 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. 607 @param FormatString Null-terminated Unicodeformat string.768 @param FormatString A Null-terminated ASCII format string. 608 769 @param Marker VA_LIST marker for the variable argument list. 609 770 … … 621 782 ) 622 783 { 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 } 632 797 633 798 return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker); … … 645 810 The number of ASCII characters in the produced output buffer is returned not including 646 811 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 647 824 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 than652 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then653 ASSERT().654 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string655 contains more than PcdMaximumAsciiStringLength ASCII characters not including the656 Null-terminator, then ASSERT().657 825 658 826 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 659 827 ASCII string. 660 828 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. 661 @param FormatString Null-terminated Unicodeformat string.829 @param FormatString A Null-terminated ASCII format string. 662 830 @param Marker BASE_LIST marker for the variable argument list. 663 831 … … 675 843 ) 676 844 { 677 return mPrint2 Protocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);845 return mPrint2SProtocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker); 678 846 } 679 847 … … 681 849 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated 682 850 ASCII format string and variable argument list. 851 852 This function is similar as snprintf_s defined in C11. 683 853 684 854 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer … … 689 859 The number of ASCII characters in the produced output buffer is returned not including 690 860 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 691 873 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 than696 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then697 ASSERT().698 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string699 contains more than PcdMaximumAsciiStringLength ASCII characters not including the700 Null-terminator, then ASSERT().701 874 702 875 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 703 876 ASCII string. 704 877 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer. 705 @param FormatString Null-terminated Unicodeformat string.878 @param FormatString A Null-terminated ASCII format string. 706 879 @param ... Variable argument list whose contents are accessed based on the 707 880 format string specified by FormatString. … … 731 904 /** 732 905 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. 734 909 735 910 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer … … 740 915 The number of ASCII characters in the produced output buffer is returned not including 741 916 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. 747 927 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than 748 928 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. 753 932 754 933 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 755 934 ASCII string. 756 935 @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. 758 937 @param Marker VA_LIST marker for the variable argument list. 759 938 … … 771 950 ) 772 951 { 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 } 782 967 783 968 return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker); … … 786 971 /** 787 972 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated 788 ASCIIformat string and a BASE_LIST argument list.973 Unicode format string and a BASE_LIST argument list. 789 974 790 975 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer … … 795 980 The number of ASCII characters in the produced output buffer is returned not including 796 981 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. 802 992 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than 803 993 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. 808 997 809 998 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 810 999 ASCII string. 811 1000 @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. 813 1002 @param Marker BASE_LIST marker for the variable argument list. 814 1003 … … 826 1015 ) 827 1016 { 828 return mPrint2Protocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker); 1017 ASSERT_UNICODE_BUFFER (FormatString); 1018 return mPrint2SProtocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker); 829 1019 } 830 1020 831 1021 /** 832 1022 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. 834 1026 835 1027 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer … … 840 1032 The number of ASCII characters in the produced output buffer is returned not including 841 1033 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. 847 1044 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than 848 1045 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. 853 1049 854 1050 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated 855 1051 ASCII string. 856 1052 @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. 858 1054 @param ... Variable argument list whose contents are accessed based on the 859 1055 format string specified by FormatString. … … 882 1078 883 1079 884 /** 1080 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES 1081 1082 /** 1083 [ATTENTION] This function is deprecated for security reason. 1084 885 1085 Converts a decimal value to a Null-terminated ASCII string. 886 1086 … … 931 1131 ) 932 1132 { 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 **/ 1201 RETURN_STATUS 1202 EFIAPI 1203 AsciiValueToStringS ( 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); 934 1212 } 935 1213 … … 944 1222 #define ARGUMENT_REVERSED BIT12 945 1223 #define COUNT_ONLY_NO_PRINT BIT13 1224 #define UNSIGNED_TYPE BIT14 946 1225 947 1226 // … … 1080 1359 #define ERROR_STATUS_NUMBER 33 1081 1360 1082 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * mStatusString[] = {1361 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * CONST mStatusString[] = { 1083 1362 "Success", // RETURN_SUCCESS = 0 1084 1363 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1 … … 1235 1514 // 1236 1515 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 1237 1566 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) { 1238 1567 if (BufferSize == 0) { … … 1246 1575 return 0; 1247 1576 } 1248 ASSERT (Buffer != NULL);1249 }1250 1251 if ((Flags & OUTPUT_UNICODE) != 0) {1252 BytesPerOutputCharacter = 2;1253 } else {1254 BytesPerOutputCharacter = 1;1255 1577 } 1256 1578 … … 1272 1594 } 1273 1595 1274 if ((Flags & FORMAT_UNICODE) != 0) {1275 //1276 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength1277 // 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 PcdMaximumAsciiStringLength1285 // Ascii characters if PcdMaximumAsciiStringLength is not zero.1286 //1287 ASSERT (AsciiStrSize (Format) != 0);1288 BytesPerFormatCharacter = 1;1289 FormatMask = 0xff;1290 }1291 1292 1596 // 1293 1597 // Get the first character from the format string 1294 1598 // 1295 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;1599 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 1296 1600 1297 1601 // … … 1325 1629 for (Done = FALSE; !Done; ) { 1326 1630 Format += BytesPerFormatCharacter; 1327 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;1631 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 1328 1632 switch (FormatCharacter) { 1329 1633 case '.': … … 1378 1682 Count = (Count * 10) + FormatCharacter - '0'; 1379 1683 Format += BytesPerFormatCharacter; 1380 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;1684 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 1381 1685 } 1382 1686 Format -= BytesPerFormatCharacter; … … 1430 1734 // break skipped on purpose 1431 1735 // 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 // 1432 1744 case 'd': 1433 1745 if ((Flags & LONG_TYPE) == 0) { 1434 1746 // 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". 1436 1748 // This assumption is made so the format string definition is compatible with the ANSI C 1437 1749 // Specification for formatted strings. It is recommended that the Base Types be used … … 1467 1779 Precision = 1; 1468 1780 } 1469 if (Value < 0 ) {1781 if (Value < 0 && (Flags & UNSIGNED_TYPE) == 0) { 1470 1782 Flags |= PREFIX_SIGN; 1471 1783 Prefix = '-'; 1472 1784 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; 1473 1795 } 1474 1796 } else { … … 1477 1799 if ((Flags & LONG_TYPE) == 0 && Value < 0) { 1478 1800 // 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". 1480 1802 // This assumption is made so the format string definition is compatible with the ANSI C 1481 1803 // Specification for formatted strings. It is recommended that the Base Types be used … … 1639 1961 case '\r': 1640 1962 Format += BytesPerFormatCharacter; 1641 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;1963 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 1642 1964 if (FormatCharacter == '\n') { 1643 1965 // … … 1660 1982 ArgumentString = "\r\n"; 1661 1983 Format += BytesPerFormatCharacter; 1662 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;1984 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 1663 1985 if (FormatCharacter != '\r') { 1664 1986 Format -= BytesPerFormatCharacter; … … 1679 2001 case '\r': 1680 2002 Format += BytesPerFormatCharacter; 1681 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;2003 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 1682 2004 if (FormatCharacter == '\n') { 1683 2005 // … … 1700 2022 ArgumentString = "\r\n"; 1701 2023 Format += BytesPerFormatCharacter; 1702 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;2024 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 1703 2025 if (FormatCharacter != '\r') { 1704 2026 Format -= BytesPerFormatCharacter; … … 1729 2051 // ArgumentString is either null-terminated, or it contains Precision characters 1730 2052 // 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++) { 1732 2059 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask; 1733 2060 if (ArgumentCharacter == 0) { … … 1786 2113 // Copy the string into the output buffer performing the required type conversions 1787 2114 // 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; 1790 2119 1791 2120 LengthToReturn += (1 * BytesPerOutputCharacter); … … 1828 2157 // Get the next character from the format string 1829 2158 // 1830 FormatCharacter = ((*Format & 0xff) | ( *(Format + 1) << 8)) & FormatMask;2159 FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask; 1831 2160 } 1832 2161 … … 1840 2169 // 1841 2170 InternalPrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter); 1842 //1843 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength1844 // 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 PcdMaximumAsciiStringLength1849 // ASCII characters if PcdMaximumAsciiStringLength is not zero.1850 //1851 ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));1852 2171 1853 2172 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter); … … 1858 2177 output were produced not including the Null-terminator. 1859 2178 1860 If FormatString is NULL, then ASSERT().1861 2179 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. 1862 2185 1863 2186 @param[in] FormatString A Null-terminated Unicode format string. … … 1874 2197 ) 1875 2198 { 1876 ASSERT (FormatString != NULL);2199 ASSERT_UNICODE_BUFFER (FormatString); 1877 2200 return InternalPrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL); 1878 2201 } … … 1882 2205 output were produced not including the Null-terminator. 1883 2206 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. 1885 2211 1886 2212 @param[in] FormatString A Null-terminated ASCII format string. … … 1897 2223 ) 1898 2224 { 1899 ASSERT(FormatString != NULL);1900 2225 return InternalPrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL); 1901 2226 }
Note:
See TracChangeset
for help on using the changeset viewer.