VirtualBox

Ignore:
Timestamp:
Mar 31, 2025 11:31:09 AM (5 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168237
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
127 added
3 deleted
61 edited

Legend:

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

  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.c

    r99404 r108794  
    4242  )
    4343{
    44   ASSERT (FALSE);
     44  DEBUG ((DEBUG_ERROR, "ArmTrng Backend not found\n"));
    4545  return RETURN_UNSUPPORTED;
    4646}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf

    r101291 r108794  
    5858
    5959[BuildOptions]
    60   MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
    61   MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
     60# warning C4706: assignment within conditional expression
     61# if ((err = fdt_splice_(fdt, p, oldlen, newlen)))
     62# in BaseFdtLib\libfdt\libfdt\fdt_rw.c (wait for sub module update to remove this)
     63  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245 /wd4706
     64  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267 /wd4706
    6265
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseFdtLib/FdtLib.c

    r105670 r108794  
    88
    99#include <libfdt/libfdt/libfdt.h>
     10#include <Library/FdtLib.h>
     11#include <Uefi/UefiBaseType.h>
    1012
    1113/**
     
    148150
    149151/**
     152  Unpack FDT blob into new buffer
     153
     154  @param[in]  Fdt            The pointer to FDT blob.
     155  @param[out] Buffer         Pointer to destination buffer.
     156  @param[in]  BufferSize     The size of destination buffer.
     157
     158  @return Zero for successfully, otherwise failed.
     159
     160 **/
     161INT32
     162EFIAPI
     163FdtOpenInto (
     164  IN  CONST VOID  *Fdt,
     165  OUT VOID        *Buffer,
     166  IN  INT32       BufferSize
     167  )
     168{
     169  return fdt_open_into (Fdt, Buffer, BufferSize);
     170}
     171
     172/**
     173  Pack FDT blob in place.
     174
     175  @param[in][out]  Fdt            The pointer to FDT blob.
     176
     177  @return Zero.
     178**/
     179INT32
     180EFIAPI
     181FdtPack (
     182  IN OUT VOID  *Fdt
     183  )
     184{
     185  return fdt_pack (Fdt);
     186}
     187
     188/**
     189  Returns a pointer to the node at a given offset.
     190
     191  @param[in] Fdt            The pointer to FDT blob.
     192  @param[in] Offset         The offset to node.
     193  @param[in] Length         Maximum length of node.
     194
     195  @return pointer to node.
     196**/
     197CONST VOID *
     198EFIAPI
     199FdtOffsetPointer (
     200  IN CONST VOID  *Fdt,
     201  IN INT32       Offset,
     202  IN UINT32      Length
     203  )
     204{
     205  return fdt_offset_ptr (Fdt, Offset, Length);
     206}
     207
     208/**
    150209  Returns a offset of next node from the given node.
    151210
     
    204263{
    205264  return fdt_next_subnode (Fdt, Offset);
     265}
     266
     267/**
     268  Returns the number of memory reserve map entries.
     269
     270  @param[in] Fdt             The pointer to FDT blob.
     271
     272  @return The number of entries in the reserve map.
     273
     274**/
     275INTN
     276EFIAPI
     277FdtGetNumberOfReserveMapEntries (
     278  IN CONST VOID  *Fdt
     279  )
     280{
     281  return fdt_num_mem_rsv (Fdt);
     282}
     283
     284/**
     285  Returns a memory reserve map entry.
     286
     287  @param[in] *Fdt            The pointer to FDT blob.
     288  @param[in] Index           Index of reserve map entry.
     289  @param[out] Addr           Pointer to 64-bit variable to hold the start address
     290  @param[out] *Size          Pointer to 64-bit variable to hold size of reservation
     291
     292  @return 0 on success, or negative error code.
     293
     294**/
     295INTN
     296EFIAPI
     297FdtGetReserveMapEntry (
     298  IN CONST VOID             *Fdt,
     299  IN INTN                   Index,
     300  OUT EFI_PHYSICAL_ADDRESS  *Addr,
     301  OUT UINT64                *Size
     302  )
     303{
     304  return fdt_get_mem_rsv (Fdt, Index, Addr, Size);
    206305}
    207306
     
    230329
    231330/**
     331  Returns a offset of first node which matches the given name.
     332
     333  @param[in] Fdt             The pointer to FDT blob.
     334  @param[in] ParentOffset    The offset to the node which start find under.
     335  @param[in] Name            The name to search the node with the name.
     336
     337  @return The offset to node offset with given node name.
     338
     339 **/
     340INT32
     341EFIAPI
     342FdtSubnodeOffset (
     343  IN CONST VOID   *Fdt,
     344  IN INT32        ParentOffset,
     345  IN CONST CHAR8  *Name
     346  )
     347{
     348  return fdt_subnode_offset (Fdt, ParentOffset, Name);
     349}
     350
     351/**
     352  Find the parent of a given node.
     353
     354  @param[in] Fdt             The pointer to FDT blob.
     355  @param[in] NodeOffset      The offset to the node to find the parent for.
     356
     357  @return Structure block offset, or negative return value.
     358**/
     359INT32
     360EFIAPI
     361FdtParentOffset (
     362  IN CONST VOID  *Fdt,
     363  IN INT32       NodeOffset
     364  )
     365{
     366  return fdt_parent_offset (Fdt, NodeOffset);
     367}
     368
     369/**
    232370  Returns a offset of first node which includes the given property name and value.
    233371
     
    243381INT32
    244382EFIAPI
    245 FdtNodeOffsetByPropValue (
     383FdtNodeOffsetByPropertyValue (
    246384  IN CONST VOID   *Fdt,
    247385  IN INT32        StartOffset,
     
    255393
    256394/**
     395  Returns a offset of first node which includes the given property name and value.
     396
     397  @param[in] Fdt             The pointer to FDT blob.
     398  @param[in] Phandle         Phandle value to search for.
     399
     400  @return The offset to node with matching Phandle value.
     401**/
     402INT32
     403EFIAPI
     404FdtNodeOffsetByPhandle (
     405  IN CONST VOID  *Fdt,
     406  IN UINT32      Phandle
     407  )
     408{
     409  return fdt_node_offset_by_phandle (Fdt, Phandle);
     410}
     411
     412/**
     413  Look for a string in  a stringlist
     414
     415  @param[in] StringList     Pointer to stringlist to search.
     416  @param[in] ListLength     Length of StringList.
     417  @param[in] String         Pointer to string to search for.
     418
     419  @return 1 if found.
     420**/
     421INT32
     422EFIAPI
     423FdtStringListContains (
     424  IN CONST CHAR8  *StringList,
     425  IN INT32        ListLength,
     426  IN CONST CHAR8  *String
     427  )
     428{
     429  return fdt_stringlist_contains (StringList, ListLength, String);
     430}
     431
     432/**
    257433  Returns a property with the given name from the given node.
    258434
     
    266442
    267443**/
    268 CONST struct fdt_property *
     444CONST FDT_PROPERTY *
    269445EFIAPI
    270446FdtGetProperty (
     
    275451  )
    276452{
    277   return fdt_get_property (Fdt, NodeOffset, Name, Length);
     453  return (FDT_PROPERTY *)fdt_get_property (Fdt, NodeOffset, Name, Length);
     454}
     455
     456/**
     457  Returns a pointer to a node mapped to an alias matching a substring.
     458
     459  @param[in] Fdt            The pointer to FDT blob.
     460  @param[in] Name           The alias name string.
     461  @param[in] Length         The length to the size of the property found.
     462
     463  @return A pointer to the expansion of the alias matching the substring,
     464          or NULL if alias not found.
     465
     466**/
     467CONST CHAR8 *
     468EFIAPI
     469FdtGetAliasNameLen (
     470  IN CONST VOID   *Fdt,
     471  IN CONST CHAR8  *Name,
     472  IN INT32        Length
     473  )
     474{
     475  return fdt_get_alias_namelen (Fdt, Name, Length);
    278476}
    279477
     
    326524
    327525**/
    328 CONST struct fdt_property *
     526CONST FDT_PROPERTY *
    329527EFIAPI
    330528FdtGetPropertyByOffset (
     
    334532  )
    335533{
    336   return fdt_get_property_by_offset (Fdt, Offset, Length);
     534  return (FDT_PROPERTY *)fdt_get_property_by_offset (Fdt, Offset, Length);
    337535}
    338536
     
    393591INT32
    394592EFIAPI
    395 FdtSetProp (
     593FdtSetProperty (
    396594  IN VOID         *Fdt,
    397595  IN INT32        NodeOffset,
     
    405603
    406604/**
     605  Set a property to a 64-bit integer.
     606
     607  @param[in] Fdt            The pointer to FDT blob.
     608  @param[in] NodeOffset     The offset to the node offset which want to add in.
     609  @param[in] Name           The name to name the property.
     610  @param[in] Value          The value (big-endian) to the property value.
     611
     612  @return  Zero for successfully, otherwise failed.
     613
     614 **/
     615INT32
     616EFIAPI
     617FdtSetPropU64 (
     618  IN VOID         *Fdt,
     619  IN INT32        NodeOffset,
     620  IN CONST CHAR8  *Name,
     621  IN UINT64       Value
     622  )
     623{
     624  UINT64  Tmp;
     625
     626  Tmp = cpu_to_fdt64 (Value);
     627
     628  return fdt_setprop (Fdt, NodeOffset, Name, &Tmp, sizeof (Tmp));
     629}
     630
     631/**
     632  Append or create a property in the given node.
     633
     634  @param[in] Fdt            The pointer to FDT blob.
     635  @param[in] NodeOffset     The offset to the node offset which want to add in.
     636  @param[in] Name           The name to name the property.
     637  @param[in] Value          The value (big-endian) to the property value.
     638  @param[in] Length         The length to the size of the property.
     639
     640  @return  Zero for successfully, otherwise failed.
     641
     642 **/
     643INT32
     644EFIAPI
     645FdtAppendProp (
     646  IN VOID         *Fdt,
     647  IN INT32        NodeOffset,
     648  IN CONST CHAR8  *Name,
     649  IN CONST VOID   *Value,
     650  IN UINT32       Length
     651  )
     652{
     653  return fdt_appendprop (Fdt, NodeOffset, Name, Value, (int)Length);
     654}
     655
     656/**
     657  Delete a property.
     658
     659  This function will delete data from the blob, and will therefore
     660  change the offsets of some existing nodes.
     661
     662  @param[in][out] Fdt         Pointer to the device tree blob.
     663  @param[in]      NodeOffset  Offset of the node whose property to nop.
     664  @param[in]      Name        Name of the property to nop.
     665
     666  @return  Zero for successfully, otherwise failed.
     667
     668**/
     669INT32
     670FdtDelProp (
     671  IN OUT VOID         *Fdt,
     672  IN     INT32        NodeOffset,
     673  IN     CONST CHAR8  *Name
     674  )
     675{
     676  return fdt_delprop (Fdt, NodeOffset, Name);
     677}
     678
     679/**
     680  Finds a tree node by substring
     681
     682  @param[in] Fdt            The pointer to FDT blob.
     683  @param[in] Path           Full path of the node to locate.
     684  @param[in] NameLength      The length of the name to check only.
     685
     686  @return structure block offset of the node with the requested path (>=0), on success
     687**/
     688INT32
     689EFIAPI
     690FdtPathOffsetNameLen (
     691  IN CONST VOID   *Fdt,
     692  IN CONST CHAR8  *Path,
     693  IN INT32        NameLength
     694  )
     695{
     696  return fdt_path_offset_namelen (Fdt, Path, NameLength);
     697}
     698
     699/**
     700  Finds a tree node by its full path.
     701
     702  @param[in] Fdt            The pointer to FDT blob.
     703  @param[in] Path           Full path of the node to locate.
     704
     705  @return structure block offset of the node with the requested path (>=0), on success
     706**/
     707INT32
     708EFIAPI
     709FdtPathOffset (
     710  IN CONST VOID   *Fdt,
     711  IN CONST CHAR8  *Path
     712  )
     713{
     714  return fdt_path_offset (Fdt, Path);
     715}
     716
     717/**
    407718  Returns the name of a given node.
    408719
     
    443754  return fdt_node_depth (Fdt, NodeOffset);
    444755}
     756
     757/**
     758  Find nodes with a given 'compatible' value.
     759
     760  @param[in] Fdt            The pointer to FDT blob.
     761  @param[in] StartOffset    Only find nodes after this offset.
     762  @param[in] Compatible     The string to match against.
     763
     764  @retval The offset of the first node after StartOffset.
     765**/
     766INT32
     767EFIAPI
     768FdtNodeOffsetByCompatible (
     769  IN CONST VOID   *Fdt,
     770  IN INT32        StartOffset,
     771  IN CONST CHAR8  *Compatible
     772  )
     773{
     774  return fdt_node_offset_by_compatible (Fdt, StartOffset, Compatible);
     775}
     776
     777/**
     778   Retrieve address size for a bus represented in the tree
     779
     780  @param[in] Fdt            The pointer to FDT blob.
     781  @param[in] NodeOffset     Offset of node to check.
     782
     783  @return Number of cells in the bus address, or negative error.
     784**/
     785INT32
     786EFIAPI
     787FdtAddressCells (
     788  IN CONST VOID  *Fdt,
     789  IN INT32       NodeOffset
     790  )
     791{
     792  return fdt_address_cells (Fdt, NodeOffset);
     793}
     794
     795/**
     796   Retrieve address range size for a bus represented in the tree
     797
     798  @param[in] Fdt            The pointer to FDT blob.
     799  @param[in] NodeOffset     Offset of node to check.
     800
     801  @return Number of cells in the bus size, or negative error.
     802**/
     803INT32
     804EFIAPI
     805FdtSizeCells (
     806  IN CONST VOID  *Fdt,
     807  IN INT32       NodeOffset
     808  )
     809{
     810  return fdt_size_cells (Fdt, NodeOffset);
     811}
     812
     813/* Debug functions. */
     814CONST
     815CHAR8
     816*
     817FdtStrerror (
     818  IN INT32  ErrVal
     819  )
     820{
     821  return fdt_strerror (ErrVal);
     822}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseFdtLib/LibFdtSupport.h

    r105670 r108794  
    1515#include <Library/BaseMemoryLib.h>
    1616
    17 typedef UINT8    uint8_t;
    18 typedef UINT16   uint16_t;
    19 typedef INT32    int32_t;
    20 typedef UINT32   uint32_t;
    21 typedef UINT64   uint64_t;
    22 typedef UINTN    uintptr_t;
    23 typedef UINTN    size_t;
    24 typedef BOOLEAN  bool;
     17typedef UINT8   uint8_t;
     18typedef UINT16  uint16_t;
     19typedef INT32   int32_t;
     20typedef UINT32  uint32_t;
     21typedef UINT64  uint64_t;
     22typedef UINTN   uintptr_t;
     23typedef UINTN   size_t;
    2524
     25#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
     26/* bool, true and false are keywords.  */
     27#else
     28typedef BOOLEAN bool;
    2629#define true   (1 == 1)
    2730#define false  (1 == 0)
     31#endif
    2832
    2933//
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/BaseLib.inf

    r105670 r108794  
    44#  Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>
    55#  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
    6 #  Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
     6#  Portions copyright (c) 2011 - 2024, Arm Limited. All rights reserved.<BR>
    77#  Copyright (c) 2020 - 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
    88#
     
    353353  Unaligned.c
    354354  Math64.c
     355  IntelTdxNull.c
    355356
    356357[Sources.ARM]
     
    378379  Arm/MemoryFence.S             | GCC
    379380  Arm/SpeculationBarrier.S      | GCC
     381  IntelTdxNull.c
    380382
    381383[Sources.AARCH64]
     
    392394  AArch64/CpuBreakpoint.S           | GCC
    393395  AArch64/SpeculationBarrier.S      | GCC
     396  AArch64/ArmReadCntPctReg.S        | GCC
     397  AArch64/ArmReadIdAA64Isar0Reg.S       | GCC
    394398
    395399  AArch64/MemoryFence.asm           | MSFT
     
    401405  AArch64/CpuBreakpoint.asm         | MSFT
    402406  AArch64/SpeculationBarrier.asm    | MSFT
     407  AArch64/ArmReadCntPctReg.asm      | MSFT
     408  AArch64/ArmReadIdAA64Isar0Reg.asm     | MSFT
     409  IntelTdxNull.c
    403410
    404411[Sources.RISCV64]
     
    422429  RiscV64/RiscVMmu.S                | GCC
    423430  RiscV64/SpeculationBarrier.S      | GCC
     431  IntelTdxNull.c
    424432
    425433[Sources.LOONGARCH64]
     
    442450  LoongArch64/Cpucfg.S              | GCC
    443451  LoongArch64/ReadStableCounter.S   | GCC
     452  IntelTdxNull.c
    444453
    445454[Packages]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/CheckSum.c

    r105670 r108794  
    763763  return ~Crc;
    764764}
     765
     766// The lookup table is inherited from [https://crccalc.com/](https://crccalc.com/%60)
     767GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT16  mCrc16CcittFLookupTable[256] = {
     768  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
     769  0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
     770  0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
     771  0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
     772  0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
     773  0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
     774  0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
     775  0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
     776  0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
     777  0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
     778  0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
     779  0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
     780  0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
     781  0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
     782  0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
     783  0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
     784  0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
     785  0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
     786  0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
     787  0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
     788  0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
     789  0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
     790  0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
     791  0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
     792  0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
     793  0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
     794  0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
     795  0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
     796  0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
     797  0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
     798  0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
     799  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
     800};
     801
     802/**
     803  Calculates the CRC16-CCITT-FALSE checksum of the given buffer.
     804
     805  @param[in]      Buffer        Pointer to the buffer.
     806  @param[in]      Length        Length of the buffer, in bytes.
     807  @param[in]      InitialValue  Initial value of the CRC.
     808
     809  @return The CRC16-CCITT-FALSE checksum.
     810**/
     811UINT16
     812EFIAPI
     813CalculateCrc16CcittF (
     814  IN CONST VOID  *Buffer,
     815  IN UINTN       Length,
     816  IN UINT16      InitialValue
     817  )
     818{
     819  CONST UINT8  *Buf;
     820  UINT16       Crc;
     821
     822  ASSERT (Buffer != NULL);
     823  ASSERT (Length <= (MAX_ADDRESS - ((UINTN)Buffer) + 1));
     824
     825  Buf = Buffer;
     826  Crc = InitialValue;
     827
     828  while (Length-- != 0) {
     829    Crc = mCrc16CcittFLookupTable[((Crc >> 8) ^ *(Buf++)) & 0xFF] ^ (Crc << 8);
     830  }
     831
     832  return Crc;
     833}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/CpuDeadLoop.c

    r99404 r108794  
    22  Base Library CPU Functions for all architectures.
    33
    4   Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.<BR>
    55  SPDX-License-Identifier: BSD-2-Clause-Patent
    66
     
    99#include <Base.h>
    1010#include <Library/BaseLib.h>
     11
     12static volatile UINTN  mDeadLoopComparator = 0;
    1113
    1214/**
     
    2729  volatile UINTN  Index;
    2830
    29   for (Index = 0; Index == 0;) {
     31  for (Index = mDeadLoopComparator; Index == mDeadLoopComparator;) {
    3032    CpuPause ();
    3133  }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/LoongArch64/AsmCsr.S

    r105670 r108794  
    5151
    5252CfgCsrRd:
    53   li.w     $t0, LOONGARCH_CSR_CPUNUM
     53  li.w     $t0, LOONGARCH_CSR_CPUID
    5454  bltu     $a0, $t0, ReadSelNumErr
    5555  li.w     $t0, LOONGARCH_CSR_PRCFG3
    5656  bltu     $t0, $a0, KcsCsrRd
    5757  la.pcrel $t0, CfgCsrRead
    58   addi.w   $t1, $a0, -LOONGARCH_CSR_CPUNUM
     58  addi.w   $t1, $a0, -LOONGARCH_CSR_CPUID
    5959  alsl.d   $t0, $t1, $t0, 3
    6060  jirl     $zero, $t0, 0
     
    101101
    102102ReadSelNumErr:
    103   addi.d   $a0, $zero, -1
    104   jirl     $zero, $ra, 0
     103  break    0
    105104
    106105BasicCsrRead:
     
    119118
    120119CfgCsrRead:
    121   CsrSel = LOONGARCH_CSR_CPUNUM
    122   .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUNUM + 1
     120  CsrSel = LOONGARCH_CSR_CPUID
     121  .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUID + 1
    123122    AsmCsrRd CsrSel
    124123    CsrSel = CsrSel + 1
     
    176175
    177176CfgCsrWr:
    178   li.w     $t0, LOONGARCH_CSR_CPUNUM
     177  li.w     $t0, LOONGARCH_CSR_CPUID
    179178  bltu     $a0, $t0, WriteSelNumErr
    180179  li.w     $t0, LOONGARCH_CSR_PRCFG3
    181180  bltu     $t0, $a0, KcsCsrWr
    182181  la.pcrel $t0, CfgCsrWrite
    183   addi.w   $t1, $a0, -LOONGARCH_CSR_CPUNUM
     182  addi.w   $t1, $a0, -LOONGARCH_CSR_CPUID
    184183  alsl.d   $t0, $t1, $t0, 3
    185184  move     $a0, $a1
     
    231230
    232231WriteSelNumErr:
    233   addi.d   $a0, $zero, -1
    234   jirl     $zero, $ra, 0
     232  break    0
    235233
    236234BasicCsrWrite:
     
    249247
    250248CfgCsrWrite:
    251   CsrSel = LOONGARCH_CSR_CPUNUM
    252   .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUNUM + 1
     249  CsrSel = LOONGARCH_CSR_CPUID
     250  .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUID + 1
    253251    AsmCsrWr CsrSel
    254252    CsrSel = CsrSel + 1
     
    309307
    310308CfgCsrXchg:
    311   li.w     $t0, LOONGARCH_CSR_CPUNUM
     309  li.w     $t0, LOONGARCH_CSR_CPUID
    312310  bltu     $a0, $t0, XchgSelNumErr
    313311  li.w     $t0, LOONGARCH_CSR_PRCFG3
    314312  bltu     $t0, $a0, KcsCsrXchg
    315313  la.pcrel $t0, CfgCsrXchange
    316   addi.w   $t1, $a0, -LOONGARCH_CSR_CPUNUM
     314  addi.w   $t1, $a0, -LOONGARCH_CSR_CPUID
    317315  alsl.d   $t0, $t1, $t0, 3
    318316  move     $a0, $a1
     
    369367
    370368XchgSelNumErr:
    371   addi.d   $a0, $zero, -1
    372   jirl     $zero, $ra, 0
     369  break    0
    373370
    374371BasicCsrXchange:
     
    387384
    388385CfgCsrXchange:
    389   CsrSel = LOONGARCH_CSR_CPUNUM
    390   .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUNUM + 1
     386  CsrSel = LOONGARCH_CSR_CPUID
     387  .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUID + 1
    391388    AsmCsrXChange CsrSel
    392389    CsrSel = CsrSel + 1
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/LoongArch64/Cpucfg.S

    r105670 r108794  
    2121ASM_PFX(AsmCpucfg):
    2222  cpucfg  $t0, $a0
    23   stptr.d $t0, $a1, 0
     23  stptr.w $t0, $a1, 0
    2424
    2525  jirl    $zero, $ra, 0
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/LoongArch64/Csr.c

    r105670 r108794  
    3030  @param[in]  Select   CSR read instruction select values.
    3131
    32   @return     The return value of csrrd instruction, return -1 means Select is out of support.
     32  @return     The return value of csrrd instruction,
     33              if a break exception is triggered, the Select is out of support.
    3334**/
    3435UINTN
     
    4849
    4950  @return     The return value of csrwr instruction, that is, store the old value of
    50               the register, return -1 means Select is out of support.
     51              the register, if a break exception is triggered, the Select is out of support.
    5152**/
    5253UINTN
     
    6869
    6970  @return     The return value of csrxchg instruction, that is, store the old value of
    70               the register, return -1 means Select is out of support.
     71              the register, if a break exception is triggered, the Select is out of support.
    7172**/
    7273UINTN
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/String.c

    r101291 r108794  
    407407  )
    408408{
    409   UINTN  Result;
    410 
    411   if (RETURN_ERROR (StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result))) {
    412     return MAX_UINTN;
     409  UINTN          Result;
     410  RETURN_STATUS  Status;
     411
     412  Status = StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result);
     413  if (Status == RETURN_INVALID_PARAMETER) {
     414    Result = 0;
    413415  }
    414416
     
    456458  )
    457459{
    458   UINT64  Result;
    459 
    460   if (RETURN_ERROR (StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result))) {
    461     return MAX_UINT64;
     460  UINT64         Result;
     461  RETURN_STATUS  Status;
     462
     463  Status = StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result);
     464  if (Status == RETURN_INVALID_PARAMETER) {
     465    Result = 0;
    462466  }
    463467
     
    506510  )
    507511{
    508   UINTN  Result;
    509 
    510   if (RETURN_ERROR (StrHexToUintnS (String, (CHAR16 **)NULL, &Result))) {
    511     return MAX_UINTN;
     512  UINTN          Result;
     513  RETURN_STATUS  Status;
     514
     515  Status = StrHexToUintnS (String, (CHAR16 **)NULL, &Result);
     516  if (Status == RETURN_INVALID_PARAMETER) {
     517    Result = 0;
    512518  }
    513519
     
    556562  )
    557563{
    558   UINT64  Result;
    559 
    560   if (RETURN_ERROR (StrHexToUint64S (String, (CHAR16 **)NULL, &Result))) {
    561     return MAX_UINT64;
     564  UINT64         Result;
     565  RETURN_STATUS  Status;
     566
     567  Status = StrHexToUint64S (String, (CHAR16 **)NULL, &Result);
     568  if (Status == RETURN_INVALID_PARAMETER) {
     569    Result = 0;
    562570  }
    563571
     
    10001008  )
    10011009{
    1002   UINTN  Result;
    1003 
    1004   if (RETURN_ERROR (AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Result))) {
    1005     return MAX_UINTN;
     1010  UINTN          Result;
     1011  RETURN_STATUS  Status;
     1012
     1013  Status = AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Result);
     1014  if (Status == RETURN_INVALID_PARAMETER) {
     1015    Result = 0;
    10061016  }
    10071017
     
    10451055  )
    10461056{
    1047   UINT64  Result;
    1048 
    1049   if (RETURN_ERROR (AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Result))) {
    1050     return MAX_UINT64;
     1057  UINT64         Result;
     1058  RETURN_STATUS  Status;
     1059
     1060  Status = AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Result);
     1061  if (Status == RETURN_INVALID_PARAMETER) {
     1062    Result = 0;
    10511063  }
    10521064
     
    10941106  )
    10951107{
    1096   UINTN  Result;
    1097 
    1098   if (RETURN_ERROR (AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result))) {
    1099     return MAX_UINTN;
     1108  UINTN          Result;
     1109  RETURN_STATUS  Status;
     1110
     1111  Status = AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result);
     1112  if (Status == RETURN_INVALID_PARAMETER) {
     1113    Result = 0;
    11001114  }
    11011115
     
    11431157  )
    11441158{
    1145   UINT64  Result;
    1146 
    1147   if (RETURN_ERROR (AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result))) {
    1148     return MAX_UINT64;
     1159  UINT64         Result;
     1160  RETURN_STATUS  Status;
     1161
     1162  Status = AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result);
     1163  if (Status == RETURN_INVALID_PARAMETER) {
     1164    Result = 0;
    11491165  }
    11501166
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/X86UnitTestHost.c

    r99404 r108794  
    6767  )
    6868{
     69  UINT32  RetEcx;
     70
     71  RetEcx = 0;
     72  switch (Index) {
     73    case 1:
     74      RetEcx |= BIT30; /* RdRand */
     75      break;
     76  }
     77
    6978  if (Eax != NULL) {
    7079    *Eax = 0;
     
    7685
    7786  if (Ecx != NULL) {
    78     *Ecx = 0;
     87    *Ecx = RetEcx;
    7988  }
    8089
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf

    r107874 r108794  
    3333  ZeroMemWrapper.c
    3434  CompareMemWrapper.c
     35  SetMemNWrapper.c
    3536  SetMem64Wrapper.c
    3637  SetMem32Wrapper.c
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLib/SetMemWrapper.c

    r80721 r108794  
    11/** @file
    2   SetMem() and SetMemN() implementation.
     2  SetMem() implementation.
    33
    44  The following BaseMemoryLib instances contain the same copy of this file:
     
    5050  return InternalMemSetMem (Buffer, Length, Value);
    5151}
    52 
    53 /**
    54   Fills a target buffer with a value that is size UINTN, and returns the target buffer.
    55 
    56   This function fills Length bytes of Buffer with the UINTN sized value specified by
    57   Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
    58   bytes of Buffer.
    59 
    60   If Length > 0 and Buffer is NULL, then ASSERT().
    61   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
    62   If Buffer is not aligned on a UINTN boundary, then ASSERT().
    63   If Length is not aligned on a UINTN boundary, then ASSERT().
    64 
    65   @param  Buffer  The pointer to the target buffer to fill.
    66   @param  Length  The number of bytes in Buffer to fill.
    67   @param  Value   The value with which to fill Length bytes of Buffer.
    68 
    69   @return Buffer.
    70 
    71 **/
    72 VOID *
    73 EFIAPI
    74 SetMemN (
    75   OUT VOID  *Buffer,
    76   IN UINTN  Length,
    77   IN UINTN  Value
    78   )
    79 {
    80   if (sizeof (UINTN) == sizeof (UINT64)) {
    81     return SetMem64 (Buffer, Length, (UINT64)Value);
    82   } else {
    83     return SetMem32 (Buffer, Length, (UINT32)Value);
    84   }
    85 }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf

    r80721 r108794  
    3737  ZeroMemWrapper.c
    3838  CompareMemWrapper.c
     39  SetMemNWrapper.c
    3940  SetMem64Wrapper.c
    4041  SetMem32Wrapper.c
     
    4748
    4849[Sources.Ia32]
    49   Ia32/ScanMem64.nasm
    50   Ia32/ScanMem32.nasm
    51   Ia32/ScanMem16.nasm
    52   Ia32/ScanMem8.nasm
    53   Ia32/CompareMem.nasm
    54   Ia32/SetMem64.nasm
    55   Ia32/SetMem32.nasm
    56   Ia32/SetMem16.nasm
    57   Ia32/ZeroMem.nasm
    58   Ia32/SetMem.nasm
    59   Ia32/CopyMem.nasm
    6050  Ia32/ScanMem64.nasm
    6151  Ia32/ScanMem32.nasm
     
    8373  X64/SetMem.nasm
    8474  X64/CopyMem.nasm
    85   X64/ScanMem64.nasm
    86   X64/ScanMem32.nasm
    87   X64/ScanMem16.nasm
    88   X64/ScanMem8.nasm
    89   X64/CompareMem.nasm
    90   X64/SetMem64.nasm
    91   X64/SetMem32.nasm
    92   X64/SetMem16.nasm
    93   X64/ZeroMem.nasm
    94   X64/SetMem.nasm
    95   X64/CopyMem.nasm
    9675  X64/IsZeroBuffer.nasm
    97 
    9876
    9977[LibraryClasses]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c

    r80721 r108794  
    11/** @file
    2   SetMem() and SetMemN() implementation.
     2  SetMem() implementation.
    33
    44  The following BaseMemoryLib instances contain the same copy of this file:
     
    5050  return InternalMemSetMem (Buffer, Length, Value);
    5151}
    52 
    53 /**
    54   Fills a target buffer with a value that is size UINTN, and returns the target buffer.
    55 
    56   This function fills Length bytes of Buffer with the UINTN sized value specified by
    57   Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
    58   bytes of Buffer.
    59 
    60   If Length > 0 and Buffer is NULL, then ASSERT().
    61   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
    62   If Buffer is not aligned on a UINTN boundary, then ASSERT().
    63   If Length is not aligned on a UINTN boundary, then ASSERT().
    64 
    65   @param  Buffer  The pointer to the target buffer to fill.
    66   @param  Length  The number of bytes in Buffer to fill.
    67   @param  Value   The value with which to fill Length bytes of Buffer.
    68 
    69   @return Buffer.
    70 
    71 **/
    72 VOID *
    73 EFIAPI
    74 SetMemN (
    75   OUT VOID  *Buffer,
    76   IN UINTN  Length,
    77   IN UINTN  Value
    78   )
    79 {
    80   if (sizeof (UINTN) == sizeof (UINT64)) {
    81     return SetMem64 (Buffer, Length, (UINT64)Value);
    82   } else {
    83     return SetMem32 (Buffer, Length, (UINT32)Value);
    84   }
    85 }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf

    r99404 r108794  
    3030
    3131[Sources.Ia32]
    32   Ia32/ScanMem64.nasm
    33   Ia32/ScanMem32.nasm
    34   Ia32/ScanMem16.nasm
    35   Ia32/ScanMem8.nasm
    36   Ia32/CompareMem.nasm
    37   Ia32/ZeroMem.nasm
    38   Ia32/SetMem64.nasm
    39   Ia32/SetMem32.nasm
    40   Ia32/SetMem16.nasm
    41   Ia32/SetMem.nasm
    42   Ia32/CopyMem.nasm
    4332  Ia32/ScanMem64.nasm
    4433  Ia32/ScanMem32.nasm
     
    10493  ZeroMemWrapper.c
    10594  CompareMemWrapper.c
     95  SetMemNWrapper.c
    10696  SetMem64Wrapper.c
    10797  SetMem32Wrapper.c
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibOptDxe/SetMemWrapper.c

    r80721 r108794  
    11/** @file
    2   SetMem() and SetMemN() implementation.
     2  SetMem() implementation.
    33
    44  The following BaseMemoryLib instances contain the same copy of this file:
     
    5050  return InternalMemSetMem (Buffer, Length, Value);
    5151}
    52 
    53 /**
    54   Fills a target buffer with a value that is size UINTN, and returns the target buffer.
    55 
    56   This function fills Length bytes of Buffer with the UINTN sized value specified by
    57   Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
    58   bytes of Buffer.
    59 
    60   If Length > 0 and Buffer is NULL, then ASSERT().
    61   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
    62   If Buffer is not aligned on a UINTN boundary, then ASSERT().
    63   If Length is not aligned on a UINTN boundary, then ASSERT().
    64 
    65   @param  Buffer  The pointer to the target buffer to fill.
    66   @param  Length  The number of bytes in Buffer to fill.
    67   @param  Value   The value with which to fill Length bytes of Buffer.
    68 
    69   @return Buffer.
    70 
    71 **/
    72 VOID *
    73 EFIAPI
    74 SetMemN (
    75   OUT VOID  *Buffer,
    76   IN UINTN  Length,
    77   IN UINTN  Value
    78   )
    79 {
    80   if (sizeof (UINTN) == sizeof (UINT64)) {
    81     return SetMem64 (Buffer, Length, (UINT64)Value);
    82   } else {
    83     return SetMem32 (Buffer, Length, (UINT32)Value);
    84   }
    85 }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf

    r80721 r108794  
    2828[Sources]
    2929  MemLibInternals.h
     30  ScanMem64Wrapper.c
     31  ScanMem32Wrapper.c
     32  ScanMem16Wrapper.c
     33  ScanMem8Wrapper.c
     34  ZeroMemWrapper.c
     35  CompareMemWrapper.c
     36  SetMemNWrapper.c
     37  SetMem64Wrapper.c
     38  SetMem32Wrapper.c
     39  SetMem16Wrapper.c
     40  SetMemWrapper.c
     41  CopyMemWrapper.c
     42  IsZeroBufferWrapper.c
     43  MemLibGuid.c
    3044
    3145[Sources.Ia32]
     
    4155  Ia32/SetMem.nasm
    4256  Ia32/CopyMem.nasm
    43   Ia32/ScanMem64.nasm
    44   Ia32/ScanMem32.nasm
    45   Ia32/ScanMem16.nasm
    46   Ia32/ScanMem8.nasm
    47   Ia32/CompareMem.nasm
    48   Ia32/ZeroMem.nasm
    49   Ia32/SetMem64.nasm
    50   Ia32/SetMem32.nasm
    51   Ia32/SetMem16.nasm
    52   Ia32/SetMem.nasm
    53   Ia32/CopyMem.nasm
    5457  Ia32/IsZeroBuffer.nasm
    55   ScanMem64Wrapper.c
    56   ScanMem32Wrapper.c
    57   ScanMem16Wrapper.c
    58   ScanMem8Wrapper.c
    59   ZeroMemWrapper.c
    60   CompareMemWrapper.c
    61   SetMem64Wrapper.c
    62   SetMem32Wrapper.c
    63   SetMem16Wrapper.c
    64   SetMemWrapper.c
    65   CopyMemWrapper.c
    66   IsZeroBufferWrapper.c
    67   MemLibGuid.c
    6858
    6959[Sources.X64]
     
    8070  X64/CopyMem.nasm
    8171  X64/IsZeroBuffer.nasm
    82   ScanMem64Wrapper.c
    83   ScanMem32Wrapper.c
    84   ScanMem16Wrapper.c
    85   ScanMem8Wrapper.c
    86   ZeroMemWrapper.c
    87   CompareMemWrapper.c
    88   SetMem64Wrapper.c
    89   SetMem32Wrapper.c
    90   SetMem16Wrapper.c
    91   SetMemWrapper.c
    92   CopyMemWrapper.c
    93   IsZeroBufferWrapper.c
    94   MemLibGuid.c
    95 
    9672
    9773[Packages]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibOptPei/SetMemWrapper.c

    r80721 r108794  
    11/** @file
    2   SetMem() and SetMemN() implementation.
     2  SetMem() implementation.
    33
    44  The following BaseMemoryLib instances contain the same copy of this file:
     
    5050  return InternalMemSetMem (Buffer, Length, Value);
    5151}
    52 
    53 /**
    54   Fills a target buffer with a value that is size UINTN, and returns the target buffer.
    55 
    56   This function fills Length bytes of Buffer with the UINTN sized value specified by
    57   Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
    58   bytes of Buffer.
    59 
    60   If Length > 0 and Buffer is NULL, then ASSERT().
    61   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
    62   If Buffer is not aligned on a UINTN boundary, then ASSERT().
    63   If Length is not aligned on a UINTN boundary, then ASSERT().
    64 
    65   @param  Buffer  The pointer to the target buffer to fill.
    66   @param  Length  The number of bytes in Buffer to fill.
    67   @param  Value   The value with which to fill Length bytes of Buffer.
    68 
    69   @return Buffer.
    70 
    71 **/
    72 VOID *
    73 EFIAPI
    74 SetMemN (
    75   OUT VOID  *Buffer,
    76   IN UINTN  Length,
    77   IN UINTN  Value
    78   )
    79 {
    80   if (sizeof (UINTN) == sizeof (UINT64)) {
    81     return SetMem64 (Buffer, Length, (UINT64)Value);
    82   } else {
    83     return SetMem32 (Buffer, Length, (UINT32)Value);
    84   }
    85 }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf

    r80721 r108794  
    3434  ZeroMemWrapper.c
    3535  CompareMemWrapper.c
     36  SetMemNWrapper.c
    3637  SetMem64Wrapper.c
    3738  SetMem32Wrapper.c
     
    4344
    4445[Sources.Ia32]
    45   Ia32/ScanMem64.nasm
    46   Ia32/ScanMem32.nasm
    47   Ia32/ScanMem16.nasm
    48   Ia32/ScanMem8.nasm
    49   Ia32/CompareMem.nasm
    50   Ia32/ZeroMem.nasm
    51   Ia32/SetMem64.nasm
    52   Ia32/SetMem32.nasm
    53   Ia32/SetMem16.nasm
    54   Ia32/SetMem.nasm
    55   Ia32/CopyMem.nasm
    5646  Ia32/ScanMem64.nasm
    5747  Ia32/ScanMem32.nasm
     
    7969  X64/SetMem.nasm
    8070  X64/CopyMem.nasm
    81   X64/ScanMem64.nasm
    82   X64/ScanMem32.nasm
    83   X64/ScanMem16.nasm
    84   X64/ScanMem8.nasm
    85   X64/CompareMem.nasm
    86   X64/ZeroMem.nasm
    87   X64/SetMem64.nasm
    88   X64/SetMem32.nasm
    89   X64/SetMem16.nasm
    90   X64/SetMem.nasm
    91   X64/CopyMem.nasm
    9271  X64/IsZeroBuffer.nasm
    9372
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibRepStr/SetMemWrapper.c

    r80721 r108794  
    11/** @file
    2   SetMem() and SetMemN() implementation.
     2  SetMem() implementation.
    33
    44  The following BaseMemoryLib instances contain the same copy of this file:
     
    5050  return InternalMemSetMem (Buffer, Length, Value);
    5151}
    52 
    53 /**
    54   Fills a target buffer with a value that is size UINTN, and returns the target buffer.
    55 
    56   This function fills Length bytes of Buffer with the UINTN sized value specified by
    57   Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
    58   bytes of Buffer.
    59 
    60   If Length > 0 and Buffer is NULL, then ASSERT().
    61   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
    62   If Buffer is not aligned on a UINTN boundary, then ASSERT().
    63   If Length is not aligned on a UINTN boundary, then ASSERT().
    64 
    65   @param  Buffer  The pointer to the target buffer to fill.
    66   @param  Length  The number of bytes in Buffer to fill.
    67   @param  Value   The value with which to fill Length bytes of Buffer.
    68 
    69   @return Buffer.
    70 
    71 **/
    72 VOID *
    73 EFIAPI
    74 SetMemN (
    75   OUT VOID  *Buffer,
    76   IN UINTN  Length,
    77   IN UINTN  Value
    78   )
    79 {
    80   if (sizeof (UINTN) == sizeof (UINT64)) {
    81     return SetMem64 (Buffer, Length, (UINT64)Value);
    82   } else {
    83     return SetMem32 (Buffer, Length, (UINT32)Value);
    84   }
    85 }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf

    r80721 r108794  
    3333  ZeroMemWrapper.c
    3434  CompareMemWrapper.c
     35  SetMemNWrapper.c
    3536  SetMem64Wrapper.c
    3637  SetMem32Wrapper.c
     
    4243
    4344[Sources.Ia32]
    44   Ia32/ScanMem64.nasm
    45   Ia32/ScanMem32.nasm
    46   Ia32/ScanMem16.nasm
    47   Ia32/ScanMem8.nasm
    48   Ia32/CompareMem.nasm
    49   Ia32/ZeroMem.nasm
    50   Ia32/SetMem64.nasm
    51   Ia32/SetMem32.nasm
    52   Ia32/SetMem16.nasm
    53   Ia32/SetMem.nasm
    54   Ia32/CopyMem.nasm
    5545  Ia32/ScanMem64.nasm
    5646  Ia32/ScanMem32.nasm
     
    7868  X64/SetMem.nasm
    7969  X64/CopyMem.nasm
    80   X64/ScanMem64.nasm
    81   X64/ScanMem32.nasm
    82   X64/ScanMem16.nasm
    83   X64/ScanMem8.nasm
    84   X64/CompareMem.nasm
    85   X64/ZeroMem.nasm
    86   X64/SetMem64.nasm
    87   X64/SetMem32.nasm
    88   X64/SetMem16.nasm
    89   X64/SetMem.nasm
    90   X64/CopyMem.nasm
    9170  X64/IsZeroBuffer.nasm
    9271
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibSse2/SetMemWrapper.c

    r80721 r108794  
    11/** @file
    2   SetMem() and SetMemN() implementation.
     2  SetMem() implementation.
    33
    44  The following BaseMemoryLib instances contain the same copy of this file:
     
    5050  return InternalMemSetMem (Buffer, Length, Value);
    5151}
    52 
    53 /**
    54   Fills a target buffer with a value that is size UINTN, and returns the target buffer.
    55 
    56   This function fills Length bytes of Buffer with the UINTN sized value specified by
    57   Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
    58   bytes of Buffer.
    59 
    60   If Length > 0 and Buffer is NULL, then ASSERT().
    61   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
    62   If Buffer is not aligned on a UINTN boundary, then ASSERT().
    63   If Length is not aligned on a UINTN boundary, then ASSERT().
    64 
    65   @param  Buffer  The pointer to the target buffer to fill.
    66   @param  Length  The number of bytes in Buffer to fill.
    67   @param  Value   The value with which to fill Length bytes of Buffer.
    68 
    69   @return Buffer.
    70 
    71 **/
    72 VOID *
    73 EFIAPI
    74 SetMemN (
    75   OUT VOID  *Buffer,
    76   IN UINTN  Length,
    77   IN UINTN  Value
    78   )
    79 {
    80   if (sizeof (UINTN) == sizeof (UINT64)) {
    81     return SetMem64 (Buffer, Length, (UINT64)Value);
    82   } else {
    83     return SetMem32 (Buffer, Length, (UINT32)Value);
    84   }
    85 }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BasePeCoffLib/BasePeCoff.c

    r101291 r108794  
    2525
    2626#include "BasePeCoffLibInternals.h"
     27#include <Library/SafeIntLib.h>
    2728
    2829/**
     
    6970  UINTN                     ReadSize;
    7071  UINT32                    SectionHeaderOffset;
    71   UINT32                    Index;
     72  UINTN                     Index;
    7273  UINT32                    HeaderWithoutDataDir;
    7374  CHAR8                     BufferData;
     
    976977  UINT32                               NumberOfRvaAndSizes;
    977978  UINT32                               TeStrippedOffset;
     979  UINT32                               EndAddress;
    978980
    979981  ASSERT (ImageContext != NULL);
     
    10551057  }
    10561058
     1059  RelocBase    = NULL;
     1060  RelocBaseEnd = NULL;
    10571061  if ((RelocDir != NULL) && (RelocDir->Size > 0)) {
    1058     RelocBase    = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress, TeStrippedOffset);
    1059     RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (
    1060                                                   ImageContext,
    1061                                                   RelocDir->VirtualAddress + RelocDir->Size - 1,
    1062                                                   TeStrippedOffset
    1063                                                   );
     1062    Status = SafeUint32Add (RelocDir->VirtualAddress, (RelocDir->Size - 1), &EndAddress);
     1063    if (!RETURN_ERROR (Status)) {
     1064      RelocBase    = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress, TeStrippedOffset);
     1065      RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (
     1066                                                    ImageContext,
     1067                                                    EndAddress,
     1068                                                    TeStrippedOffset
     1069                                                    );
     1070    }
     1071
    10641072    if ((RelocBase == NULL) || (RelocBaseEnd == NULL) || ((UINTN)RelocBaseEnd < (UINTN)RelocBase)) {
    10651073      ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
     1074      DEBUG ((DEBUG_ERROR, "Relocation block is not valid\n"));
    10661075      return RETURN_LOAD_ERROR;
    10671076    }
    1068   } else {
    1069     //
    1070     // Set base and end to bypass processing below.
    1071     //
    1072     RelocBase = RelocBaseEnd = NULL;
    10731077  }
    10741078
     
    14081412    }
    14091413
    1410     if (Section->SizeOfRawData > 0) {
     1414    if ((Section->SizeOfRawData > 0) && (Base != NULL)) {
    14111415      Status = ImageContext->ImageRead (
    14121416                               ImageContext->Handle,
     
    14251429    //
    14261430
    1427     if (Size < Section->Misc.VirtualSize) {
     1431    if ((Size < Section->Misc.VirtualSize) && (Base != NULL)) {
    14281432      ZeroMem (Base + Size, Section->Misc.VirtualSize - Size);
    14291433    }
     
    17681772  RETURN_STATUS                        Status;
    17691773  PE_COFF_LOADER_IMAGE_CONTEXT         ImageContext;
     1774  UINT32                               EndAddress;
    17701775
    17711776  if ((RelocationData == NULL) || (ImageBase == 0x0) || (VirtImageBase == 0x0)) {
     
    18291834    RelocDir = DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC;
    18301835    if ((RelocDir != NULL) && (RelocDir->Size > 0)) {
    1831       RelocBase    = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0);
    1832       RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (
    1833                                                     &ImageContext,
    1834                                                     RelocDir->VirtualAddress + RelocDir->Size - 1,
    1835                                                     0
    1836                                                     );
     1836      Status = SafeUint32Add (RelocDir->VirtualAddress, (RelocDir->Size - 1), &EndAddress);
     1837      if (!RETURN_ERROR (Status)) {
     1838        RelocBase    = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0);
     1839        RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (
     1840                                                      &ImageContext,
     1841                                                      EndAddress,
     1842                                                      0
     1843                                                      );
     1844      }
    18371845    }
    18381846
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf

    r99404 r108794  
    5959  PeCoffExtraActionLib
    6060  BaseMemoryLib
     61  SafeIntLib
    6162
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderEx.c

    r99404 r108794  
    105105  )
    106106{
    107   if (Machine == IMAGE_FILE_MACHINE_LOONGARCH64) {
     107  /*
     108   * ARM64 and X64 may allow such foreign images to be used when
     109   * a driver implementing EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL is
     110   * present.
     111   */
     112  if ((Machine == IMAGE_FILE_MACHINE_LOONGARCH64) ||
     113      (Machine == IMAGE_FILE_MACHINE_ARM64) ||
     114      (Machine == IMAGE_FILE_MACHINE_X64))
     115  {
    108116    return TRUE;
    109117  }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/AArch64/ArmRng.S

    r101291 r108794  
    99#------------------------------------------------------------------------------
    1010
    11 #include "BaseRngLibInternals.h"
     11#include "ArmRng.h"
    1212
    1313.text
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/AArch64/ArmRng.asm

    r89983 r108794  
    99;------------------------------------------------------------------------------
    1010
    11 #include "BaseRngLibInternals.h"
     11#include "ArmRng.h"
    1212
    1313  EXPORT ArmRndr
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/AArch64/ArmRng.h

    r99404 r108794  
    1111#ifndef ARM_RNG_H_
    1212#define ARM_RNG_H_
     13
     14#include <AArch64/AArch64.h>
    1315
    1416/**
     
    2830  );
    2931
    30 /**
    31   Reads the ID_AA64ISAR0 Register.
    32 
    33   @return The contents of the ID_AA64ISAR0 register.
    34 
    35 **/
    36 UINT64
    37 EFIAPI
    38 ArmReadIdIsar0 (
    39   VOID
    40   );
    41 
    4232#endif /* ARM_RNG_H_ */
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/AArch64/Rndr.c

    r106386 r108794  
    2727#ifndef VBOX
    2828STATIC BOOLEAN  mRndrSupported;
    29 #endif
    30 
    31 //
    32 // Bit mask used to determine if RNDR instruction is supported.
    33 //
    34 #define RNDR_MASK  ((UINT64)MAX_UINT16 << 60U)
     29#else
     30inline BOOLEAN VBoxIsRndrSupported()
     31{
     32  UINT64  Isar0;
     33
     34  Isar0          = ArmReadIdAA64Isar0Reg ();
     35  return !!((Isar0 >> ARM_ID_AA64ISAR0_EL1_RNDR_SHIFT) & ARM_ID_AA64ISAR0_EL1_RNDR_MASK);
     36}
     37#endif
    3538
    3639/**
     
    5861  // MSR. A non-zero value indicates that the processor supports the RNDR instruction.
    5962  //
    60   Isar0 = ArmReadIdIsar0 ();
    61 
    62   mRndrSupported = ((Isar0 & RNDR_MASK) != 0);
     63  Isar0          = ArmReadIdAA64Isar0Reg ();
     64  mRndrSupported = !!((Isar0 >> ARM_ID_AA64ISAR0_EL1_RNDR_SHIFT) & ARM_ID_AA64ISAR0_EL1_RNDR_MASK);
    6365#endif
    6466
     
    150152  return mRndrSupported;
    151153#else
    152   return (ArmReadIdIsar0() & RNDR_MASK) != 0;
     154  return VBoxIsRndrSupported();
    153155#endif
    154156}
     
    181183  }
    182184#else
    183   if (!(ArmReadIdIsar0() & RNDR_MASK)) {
     185  if (!VBoxIsRndrSupported()) {
    184186    return EFI_UNSUPPORTED;
    185187  }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/BaseRngLib.inf

    r105670 r108794  
    3939  AArch64/ArmRng.h
    4040
    41   AArch64/ArmReadIdIsar0.S   | GCC
    4241  AArch64/ArmRng.S           | GCC
    4342
    44   AArch64/ArmReadIdIsar0.asm | MSFT
    4543  AArch64/ArmRng.asm         | MSFT
    4644
     
    5048[Guids.Ia32, Guids.X64]
    5149  gEfiRngAlgorithmSp80090Ctr256Guid
     50
     51[Sources.RISCV64]
     52  Riscv/Rng.c
     53  Riscv/Seed.S               | GCC
    5254
    5355[Packages]
     
    6062  BaseLib
    6163  DebugLib
     64
     65[Pcd.RISCV64]
     66  # Does the CPU support the Zkr extension (for the `Seed` CSR)
     67  gEfiMdePkgTokenSpaceGuid.PcdRiscVFeatureOverride           ## CONSUMES
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/BaseRngLibInternals.h

    r105670 r108794  
    7070  );
    7171
    72 #if defined (MDE_CPU_AARCH64)
    73 
    74 // RNDR, Random Number
    75 #define RNDR  S3_3_C2_C4_0
    76 
    77 #endif
    78 
    7972#endif // BASE_RNGLIB_INTERNALS_H_
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/Rand/RdRand.c

    r105670 r108794  
    33  to provide high-quality random numbers.
    44
     5Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    56Copyright (c) 2023, Arm Limited. All rights reserved.<BR>
     7Copyright (c) 2022, Pedro Falcato. All rights reserved.<BR>
    68Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
    79Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
     
    2325#define RDRAND_MASK  BIT30
    2426
    25 STATIC BOOLEAN  mRdRandSupported;
     27//
     28// Intel SDM says 10 tries is good enough for reliable RDRAND usage.
     29//
     30#define RDRAND_RETRIES  10
     31
     32#define RDRAND_TEST_SAMPLES  8
     33
     34#define RDRAND_MIN_CHANGE  5
     35
     36//
     37// Add a define for native-word RDRAND, just for the test.
     38//
     39#ifdef MDE_CPU_X64
     40#define ASM_RDRAND  AsmRdRand64
     41#else
     42#define ASM_RDRAND  AsmRdRand32
     43#endif
     44
     45/**
     46  Tests RDRAND for broken implementations.
     47
     48  @retval TRUE         RDRAND is reliable (and hopefully safe).
     49  @retval FALSE        RDRAND is unreliable and should be disabled, despite CPUID.
     50
     51**/
     52STATIC
     53BOOLEAN
     54TestRdRand (
     55  VOID
     56  )
     57{
     58  //
     59  // Test for notoriously broken rdrand implementations that always return the same
     60  // value, like the Zen 3 uarch (all-1s) or other several AMD families on suspend/resume (also all-1s).
     61  // Note that this should be expanded to extensively test for other sorts of possible errata.
     62  //
     63
     64  //
     65  // Our algorithm samples rdrand $RDRAND_TEST_SAMPLES times and expects
     66  // a different result $RDRAND_MIN_CHANGE times for reliable RDRAND usage.
     67  //
     68  UINTN   Prev;
     69  UINT8   Idx;
     70  UINT8   TestIteration;
     71  UINT32  Changed;
     72
     73  Changed = 0;
     74
     75  for (TestIteration = 0; TestIteration < RDRAND_TEST_SAMPLES; TestIteration++) {
     76    UINTN  Sample;
     77    //
     78    // Note: We use a retry loop for rdrand. Normal users get this in BaseRng.c
     79    // Any failure to get a random number will assume RDRAND does not work.
     80    //
     81    for (Idx = 0; Idx < RDRAND_RETRIES; Idx++) {
     82      if (ASM_RDRAND (&Sample)) {
     83        break;
     84      }
     85    }
     86
     87    if (Idx == RDRAND_RETRIES) {
     88      DEBUG ((DEBUG_ERROR, "BaseRngLib/x86: CPU BUG: Failed to get an RDRAND random number - disabling\n"));
     89      return FALSE;
     90    }
     91
     92    if (TestIteration != 0) {
     93      Changed += Sample != Prev;
     94    }
     95
     96    Prev = Sample;
     97  }
     98
     99  if (Changed < RDRAND_MIN_CHANGE) {
     100    DEBUG ((DEBUG_ERROR, "BaseRngLib/x86: CPU BUG: RDRAND not reliable - disabling\n"));
     101    return FALSE;
     102  }
     103
     104  return TRUE;
     105}
     106
     107#undef ASM_RDRAND
    26108
    27109/**
     
    42124  )
    43125{
    44   UINT32  RegEcx;
     126  return EFI_SUCCESS;
     127}
     128
     129/**
     130  Generates a 16-bit random number.
     131
     132  @param[out] Rand     Buffer pointer to store the 16-bit random value.
     133
     134  @retval TRUE         Random number generated successfully.
     135  @retval FALSE        Failed to generate the random number.
     136
     137**/
     138BOOLEAN
     139EFIAPI
     140ArchGetRandomNumber16 (
     141  OUT     UINT16  *Rand
     142  )
     143{
     144  return AsmRdRand16 (Rand);
     145}
     146
     147/**
     148  Generates a 32-bit random number.
     149
     150  @param[out] Rand     Buffer pointer to store the 32-bit random value.
     151
     152  @retval TRUE         Random number generated successfully.
     153  @retval FALSE        Failed to generate the random number.
     154
     155**/
     156BOOLEAN
     157EFIAPI
     158ArchGetRandomNumber32 (
     159  OUT     UINT32  *Rand
     160  )
     161{
     162  return AsmRdRand32 (Rand);
     163}
     164
     165/**
     166  Generates a 64-bit random number.
     167
     168  @param[out] Rand     Buffer pointer to store the 64-bit random value.
     169
     170  @retval TRUE         Random number generated successfully.
     171  @retval FALSE        Failed to generate the random number.
     172
     173**/
     174BOOLEAN
     175EFIAPI
     176ArchGetRandomNumber64 (
     177  OUT     UINT64  *Rand
     178  )
     179{
     180  return AsmRdRand64 (Rand);
     181}
     182
     183/**
     184  Checks whether RDRAND is supported.
     185
     186  @retval TRUE         RDRAND is supported.
     187  @retval FALSE        RDRAND is not supported.
     188
     189**/
     190BOOLEAN
     191EFIAPI
     192ArchIsRngSupported (
     193  VOID
     194  )
     195{
     196  BOOLEAN  RdRandSupported;
     197  UINT32   RegEcx;
    45198
    46199  //
     
    49202  //
    50203  AsmCpuid (1, 0, 0, &RegEcx, 0);
    51   ASSERT ((RegEcx & RDRAND_MASK) == RDRAND_MASK);
    52 
    53   mRdRandSupported = ((RegEcx & RDRAND_MASK) == RDRAND_MASK);
    54 
    55   return EFI_SUCCESS;
    56 }
    57 
    58 /**
    59   Generates a 16-bit random number.
    60 
    61   @param[out] Rand     Buffer pointer to store the 16-bit random value.
    62 
    63   @retval TRUE         Random number generated successfully.
    64   @retval FALSE        Failed to generate the random number.
    65 
    66 **/
    67 BOOLEAN
    68 EFIAPI
    69 ArchGetRandomNumber16 (
    70   OUT     UINT16  *Rand
    71   )
    72 {
    73   return AsmRdRand16 (Rand);
    74 }
    75 
    76 /**
    77   Generates a 32-bit random number.
    78 
    79   @param[out] Rand     Buffer pointer to store the 32-bit random value.
    80 
    81   @retval TRUE         Random number generated successfully.
    82   @retval FALSE        Failed to generate the random number.
    83 
    84 **/
    85 BOOLEAN
    86 EFIAPI
    87 ArchGetRandomNumber32 (
    88   OUT     UINT32  *Rand
    89   )
    90 {
    91   return AsmRdRand32 (Rand);
    92 }
    93 
    94 /**
    95   Generates a 64-bit random number.
    96 
    97   @param[out] Rand     Buffer pointer to store the 64-bit random value.
    98 
    99   @retval TRUE         Random number generated successfully.
    100   @retval FALSE        Failed to generate the random number.
    101 
    102 **/
    103 BOOLEAN
    104 EFIAPI
    105 ArchGetRandomNumber64 (
    106   OUT     UINT64  *Rand
    107   )
    108 {
    109   return AsmRdRand64 (Rand);
    110 }
    111 
    112 /**
    113   Checks whether RDRAND is supported.
    114 
    115   @retval TRUE         RDRAND is supported.
    116   @retval FALSE        RDRAND is not supported.
    117 
    118 **/
    119 BOOLEAN
    120 EFIAPI
    121 ArchIsRngSupported (
    122   VOID
    123   )
    124 {
    125   /*
    126      Existing software depends on this always returning TRUE, so for
    127      now hard-code it.
    128 
    129      return mRdRandSupported;
    130   */
    131   return TRUE;
     204
     205  RdRandSupported = ((RegEcx & RDRAND_MASK) == RDRAND_MASK);
     206
     207  if (RdRandSupported) {
     208    RdRandSupported = TestRdRand ();
     209  }
     210
     211  return RdRandSupported;
    132212}
    133213
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

    r80721 r108794  
    3434  BaseLib
    3535  DebugLib
     36  StackCheckLib
    3637
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/DxeRngLib/DxeRngLib.c

    r105670 r108794  
    22 Provides an implementation of the library class RngLib that uses the Rng protocol.
    33
    4  Copyright (c) 2023, Arm Limited. All rights reserved.
     4 Copyright (c) 2023 - 2024, Arm Limited. All rights reserved.
    55 Copyright (c) Microsoft Corporation. All rights reserved.
    66 SPDX-License-Identifier: BSD-2-Clause-Patent
     
    99#include <Uefi.h>
    1010#include <Library/UefiBootServicesTableLib.h>
     11#include <Library/BaseMemoryLib.h>
    1112#include <Library/DebugLib.h>
     13#include <Library/MemoryAllocationLib.h>
    1214#include <Library/RngLib.h>
    1315#include <Protocol/Rng.h>
     16
     17STATIC EFI_RNG_PROTOCOL  *mRngProtocol;
     18STATIC UINTN             mFirstAlgo = MAX_UINTN;
     19
     20typedef struct {
     21  /// Guid of the secure algorithm.
     22  EFI_GUID       *Guid;
     23
     24  /// Algorithm name.
     25  CONST CHAR8    *Name;
     26
     27  /// The algorithm is available for use.
     28  BOOLEAN        Available;
     29} SECURE_RNG_ALGO_ARRAY;
     30
     31//
     32// These represent UEFI SPEC defined algorithms that should be supported by
     33// the RNG protocol and are generally considered secure.
     34//
     35static SECURE_RNG_ALGO_ARRAY  mSecureHashAlgorithms[] = {
     36 #ifdef MDE_CPU_AARCH64
     37  {
     38    &gEfiRngAlgorithmArmRndr, // unspecified SP800-90A DRBG (through RNDR instr.)
     39    "ARM-RNDR",
     40    FALSE,
     41  },
     42 #endif
     43  {
     44    &gEfiRngAlgorithmSp80090Ctr256Guid,  // SP800-90A DRBG CTR using AES-256
     45    "DRBG-CTR",
     46    FALSE,
     47  },
     48  {
     49    &gEfiRngAlgorithmSp80090Hmac256Guid, // SP800-90A DRBG HMAC using SHA-256
     50    "DRBG-HMAC",
     51    FALSE,
     52  },
     53  {
     54    &gEfiRngAlgorithmSp80090Hash256Guid, // SP800-90A DRBG Hash using SHA-256
     55    "DRBG-Hash",
     56    FALSE,
     57  },
     58  {
     59    &gEfiRngAlgorithmRaw, // Raw data from NRBG (or TRNG)
     60    "TRNG",
     61    FALSE,
     62  },
     63};
     64
     65/**
     66  Constructor routine to probe the available secure Rng algorithms.
     67
     68  @param  ImageHandle   The firmware allocated handle for the EFI image.
     69  @param  SystemTable   A pointer to the EFI System Table.
     70
     71  @retval EFI_SUCCESS           Success.
     72  @retval EFI_NOT_FOUND         Not found.
     73  @retval EFI_INVALID_PARAMETER Invalid parameter.
     74**/
     75EFI_STATUS
     76EFIAPI
     77DxeRngLibConstructor (
     78  IN EFI_HANDLE        ImageHandle,
     79  IN EFI_SYSTEM_TABLE  *SystemTable
     80  )
     81{
     82  EFI_STATUS         Status;
     83  UINTN              RngArraySize;
     84  UINTN              RngArrayCnt;
     85  UINT32             Index;
     86  UINT32             Index1;
     87  EFI_RNG_ALGORITHM  *RngArray;
     88
     89  Status = gBS->LocateProtocol (&gEfiRngProtocolGuid, NULL, (VOID **)&mRngProtocol);
     90  if (EFI_ERROR (Status) || (mRngProtocol == NULL)) {
     91    DEBUG ((DEBUG_ERROR, "%a: Could not locate RNG protocol, Status = %r\n", __func__, Status));
     92    return Status;
     93  }
     94
     95  RngArraySize = 0;
     96
     97  Status = mRngProtocol->GetInfo (mRngProtocol, &RngArraySize, NULL);
     98  if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
     99    return Status;
     100  } else if (RngArraySize == 0) {
     101    return EFI_NOT_FOUND;
     102  }
     103
     104  RngArrayCnt = RngArraySize / sizeof (*RngArray);
     105
     106  RngArray = AllocateZeroPool (RngArraySize);
     107  if (RngArray == NULL) {
     108    return EFI_OUT_OF_RESOURCES;
     109  }
     110
     111  Status = mRngProtocol->GetInfo (mRngProtocol, &RngArraySize, RngArray);
     112  if (EFI_ERROR (Status)) {
     113    goto ExitHandler;
     114  }
     115
     116  for (Index = 0; Index < RngArrayCnt; Index++) {
     117    for (Index1 = 0; Index1 < ARRAY_SIZE (mSecureHashAlgorithms); Index1++) {
     118      if (CompareGuid (&RngArray[Index], mSecureHashAlgorithms[Index1].Guid)) {
     119        mSecureHashAlgorithms[Index1].Available = TRUE;
     120        if (mFirstAlgo == MAX_UINTN) {
     121          mFirstAlgo = Index1;
     122        }
     123
     124        break;
     125      }
     126    }
     127  }
     128
     129ExitHandler:
     130  FreePool (RngArray);
     131  return Status;
     132}
    14133
    15134/**
     
    33152  )
    34153{
    35   EFI_STATUS        Status;
    36   EFI_RNG_PROTOCOL  *RngProtocol;
    37 
    38   RngProtocol = NULL;
     154  EFI_STATUS             Status;
     155  UINTN                  Index;
     156  SECURE_RNG_ALGO_ARRAY  *Algo;
    39157
    40158  if (Buffer == NULL) {
     
    43161  }
    44162
    45   Status = gBS->LocateProtocol (&gEfiRngProtocolGuid, NULL, (VOID **)&RngProtocol);
    46   if (EFI_ERROR (Status) || (RngProtocol == NULL)) {
    47     DEBUG ((DEBUG_ERROR, "%a: Could not locate RNG prototocol, Status = %r\n", __func__, Status));
    48     return Status;
    49   }
    50 
    51   Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Ctr256Guid, BufferSize, Buffer);
    52   DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm CTR-256 - Status = %r\n", __func__, Status));
    53   if (!EFI_ERROR (Status)) {
    54     return Status;
    55   }
    56 
    57   Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Hmac256Guid, BufferSize, Buffer);
    58   DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm HMAC-256 - Status = %r\n", __func__, Status));
    59   if (!EFI_ERROR (Status)) {
    60     return Status;
    61   }
    62 
    63   Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Hash256Guid, BufferSize, Buffer);
    64   DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Hash-256 - Status = %r\n", __func__, Status));
    65   if (!EFI_ERROR (Status)) {
    66     return Status;
    67   }
    68 
    69   Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmRaw, BufferSize, Buffer);
    70   DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Raw - Status = %r\n", __func__, Status));
    71   if (!EFI_ERROR (Status)) {
    72     return Status;
    73   }
    74 
    75   // If all the other methods have failed, use the default method from the RngProtocol
    76   Status = RngProtocol->GetRNG (RngProtocol, NULL, BufferSize, Buffer);
    77   DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm default - Status = %r\n", __func__, Status));
    78   if (!EFI_ERROR (Status)) {
    79     return Status;
     163  if (mRngProtocol == NULL) {
     164    return EFI_NOT_FOUND;
     165  }
     166
     167  // Try the first available algorithm.
     168  if (mFirstAlgo != MAX_UINTN) {
     169    Algo   = &mSecureHashAlgorithms[mFirstAlgo];
     170    Status = mRngProtocol->GetRNG (mRngProtocol, Algo->Guid, BufferSize, Buffer);
     171    DEBUG ((
     172      DEBUG_INFO,
     173      "%a: GetRNG algorithm %a - Status = %r\n",
     174      __func__,
     175      Algo->Name,
     176      Status
     177      ));
     178    if (!EFI_ERROR (Status)) {
     179      return Status;
     180    }
     181
     182    Index = mFirstAlgo + 1;
     183  } else {
     184    Index = 0;
     185  }
     186
     187  // Iterate over other available algorithms.
     188  for ( ; Index < ARRAY_SIZE (mSecureHashAlgorithms); Index++) {
     189    Algo = &mSecureHashAlgorithms[Index];
     190    if (!Algo->Available) {
     191      continue;
     192    }
     193
     194    Status = mRngProtocol->GetRNG (mRngProtocol, Algo->Guid, BufferSize, Buffer);
     195    DEBUG ((
     196      DEBUG_INFO,
     197      "%a: GetRNG algorithm %a - Status = %r\n",
     198      __func__,
     199      Algo->Name,
     200      Status
     201      ));
     202    if (!EFI_ERROR (Status)) {
     203      return Status;
     204    }
     205  }
     206
     207  if (PcdGetBool (PcdEnforceSecureRngAlgorithms)) {
     208    // Platform does not permit the use of the default (insecure) algorithm.
     209    Status = EFI_SECURITY_VIOLATION;
     210  } else {
     211    // If all the other methods have failed, use the default method from the RngProtocol
     212    Status = mRngProtocol->GetRNG (mRngProtocol, NULL, BufferSize, Buffer);
     213    DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm default - Status = %r\n", __func__, Status));
     214    if (!EFI_ERROR (Status)) {
     215      return Status;
     216    }
    80217  }
    81218
    82219  // If we get to this point, we have failed
    83   DEBUG ((DEBUG_ERROR, "%a: GetRNG() failed, staus = %r\n", __func__, Status));
     220  DEBUG ((DEBUG_ERROR, "%a: GetRNG() failed, Status = %r\n", __func__, Status));
    84221
    85222  return Status;
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/DxeRngLib/DxeRngLib.inf

    r105670 r108794  
    1616  VERSION_STRING  = 1.0
    1717  LIBRARY_CLASS   = RngLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER
     18  CONSTRUCTOR     = DxeRngLibConstructor
    1819
    1920[Packages]
     
    2526[LibraryClasses]
    2627  DebugLib
     28  MemoryAllocationLib
    2729  UefiBootServicesTableLib
    2830
     
    3840  gEfiRngAlgorithmSp80090Hmac256Guid
    3941  gEfiRngAlgorithmRaw
     42
     43[Guids.AARCH64]
     44  gEfiRngAlgorithmArmRndr
     45
     46[FixedPcd]
     47  gEfiMdePkgTokenSpaceGuid.PcdEnforceSecureRngAlgorithms ## CONSUMES
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf

    r80721 r108794  
    3232  BaseLib
    3333  DebugLib
    34 
     34  StackCheckLib
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/PeiServicesLib/PeiServicesLib.c

    r99404 r108794  
    686686
    687687  FvInfoPpiDescriptor = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
    688   ASSERT (FvInfoPpiDescriptor != NULL);
     688  if (FvInfoPpiDescriptor == NULL) {
     689    ASSERT (FvInfoPpiDescriptor != NULL);
     690    // Need to return here, FV may not be published, but we are out of resources anyway...
     691    return;
     692  }
    689693
    690694  FvInfoPpiDescriptor->Guid  = PpiGuid;
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf

    r80721 r108794  
    3232[LibraryClasses]
    3333  DebugLib
    34 
     34  StackCheckLib
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf

    r89983 r108794  
    3333 DebugLib
    3434 IoLib
     35 UefiBootServicesTableLib
    3536
    3637[Pcd]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf

    r89983 r108794  
    3737  DebugLib
    3838  MmServicesTableLib
     39  StackCheckLib
    3940
    4041[Protocols]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf

    r80721 r108794  
    1717  MODULE_TYPE                    = MM_STANDALONE
    1818  VERSION_STRING                 = 1.0
    19   LIBRARY_CLASS                  = MmServicesTableLib|MM_STANDALONE
     19  LIBRARY_CLASS                  = MmServicesTableLib|MM_STANDALONE MM_CORE_STANDALONE
    2020  PI_SPECIFICATION_VERSION       = 0x00010032
    2121  CONSTRUCTOR                    = StandaloneMmServicesTableLibConstructor
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf

    r80721 r108794  
    3333  DebugLib
    3434  BaseLib
     35  StackCheckLib
    3536
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLib.c

    r99404 r108794  
    234234  Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
    235235  to the debug output device.  If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
    236   PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
    237   DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
     236  PcdDebugPropertyMask is set then CpuBreakpoint() is called. Otherwise, if
     237  DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugPropertyMask is set then
    238238  CpuDeadLoop() is called.  If neither of these bits are set, then this function
    239239  returns immediately after the message is printed to the debug output device.
     
    328328
    329329  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
    330   PcdDebugProperyMask is set.  Otherwise FALSE is returned.
    331 
    332   @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
    333   @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
     330  PcdDebugPropertyMask is set.  Otherwise FALSE is returned.
     331
     332  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is set.
     333  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is clear.
    334334
    335335**/
     
    347347
    348348  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
    349   PcdDebugProperyMask is set.  Otherwise FALSE is returned.
    350 
    351   @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
    352   @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
     349  PcdDebugPropertyMask is set.  Otherwise FALSE is returned.
     350
     351  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is set.
     352  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is clear.
    353353
    354354**/
     
    366366
    367367  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
    368   PcdDebugProperyMask is set.  Otherwise FALSE is returned.
    369 
    370   @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
    371   @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
     368  PcdDebugPropertyMask is set.  Otherwise FALSE is returned.
     369
     370  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is set.
     371  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is clear.
    372372
    373373**/
     
    385385
    386386  This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
    387   PcdDebugProperyMask is set.  Otherwise FALSE is returned.
    388 
    389   @retval  TRUE    The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
    390   @retval  FALSE   The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
     387  PcdDebugPropertyMask is set.  Otherwise FALSE is returned.
     388
     389  @retval  TRUE    The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is set.
     390  @retval  FALSE   The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is clear.
    391391
    392392**/
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c

    r99404 r108794  
    1414
    1515//
    16 // BOOLEAN value to indicate if it is at the post ExitBootServices pahse
     16// BOOLEAN value to indicate if it is at the post ExitBootServices phase
    1717//
    1818BOOLEAN  mPostEBS = FALSE;
     
    3535
    3636**/
     37static
    3738VOID
    3839EFIAPI
    39 ExitBootServicesCallback (
     40UefiDebugLibDebugPortProtocolExitBootServicesCallback (
    4041  EFI_EVENT  Event,
    4142  VOID       *Context
     
    6869              EVT_SIGNAL_EXIT_BOOT_SERVICES,
    6970              TPL_NOTIFY,
    70               ExitBootServicesCallback,
     71              UefiDebugLibDebugPortProtocolExitBootServicesCallback,
    7172              NULL,
    7273              &mExitBootServicesEvent
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDebugLibStdErr/DebugLib.c

    r99404 r108794  
    178178  Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
    179179  to the debug output device.  If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
    180   PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
    181   DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
     180  PcdDebugPropertyMask is set then CpuBreakpoint() is called. Otherwise, if
     181  DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugPropertyMask is set then
    182182  CpuDeadLoop() is called.  If neither of these bits are set, then this function
    183183  returns immediately after the message is printed to the debug output device.
     
    274274
    275275  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
    276   PcdDebugProperyMask is set.  Otherwise FALSE is returned.
    277 
    278   @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
    279   @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
     276  PcdDebugPropertyMask is set.  Otherwise FALSE is returned.
     277
     278  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is set.
     279  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is clear.
    280280
    281281**/
     
    293293
    294294  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
    295   PcdDebugProperyMask is set.  Otherwise FALSE is returned.
    296 
    297   @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
    298   @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
     295  PcdDebugPropertyMask is set.  Otherwise FALSE is returned.
     296
     297  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is set.
     298  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is clear.
    299299
    300300**/
     
    312312
    313313  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
    314   PcdDebugProperyMask is set.  Otherwise FALSE is returned.
    315 
    316   @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
    317   @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
     314  PcdDebugPropertyMask is set.  Otherwise FALSE is returned.
     315
     316  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is set.
     317  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is clear.
    318318
    319319**/
     
    331331
    332332  This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
    333   PcdDebugProperyMask is set.  Otherwise FALSE is returned.
    334 
    335   @retval  TRUE    The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
    336   @retval  FALSE   The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
     333  PcdDebugPropertyMask is set.  Otherwise FALSE is returned.
     334
     335  @retval  TRUE    The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is set.
     336  @retval  FALSE   The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is clear.
    337337
    338338**/
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c

    r99404 r108794  
    270270  // skip preceeding white space
    271271  //
    272   while ((*Str != 0) && *Str == L' ') {
     272  while (*Str == L' ') {
    273273    Str++;
    274274  }
     
    277277  // skip preceeding zeros
    278278  //
    279   while ((*Str != 0) && *Str == L'0') {
     279  while (*Str == L'0') {
    280280    Str++;
    281281  }
     
    389389           );
    390390
    391   StrHexToBytes (DataStr, DataLength * 2, (UINT8 *)(Node + 1), DataLength);
     391  if (Node != NULL) {
     392    StrHexToBytes (DataStr, DataLength * 2, (UINT8 *)(Node + 1), DataLength);
     393  }
     394
    392395  return Node;
    393396}
     
    454457                                     );
    455458
    456   Pci->Function = (UINT8)Strtoi (FunctionStr);
    457   Pci->Device   = (UINT8)Strtoi (DeviceStr);
     459  if (Pci != NULL) {
     460    Pci->Function = (UINT8)Strtoi (FunctionStr);
     461    Pci->Device   = (UINT8)Strtoi (DeviceStr);
     462  }
    458463
    459464  return (EFI_DEVICE_PATH_PROTOCOL *)Pci;
     
    483488                                              );
    484489
    485   Pccard->FunctionNumber = (UINT8)Strtoi (FunctionNumberStr);
     490  if (Pccard != NULL) {
     491    Pccard->FunctionNumber = (UINT8)Strtoi (FunctionNumberStr);
     492  }
    486493
    487494  return (EFI_DEVICE_PATH_PROTOCOL *)Pccard;
     
    515522                                               );
    516523
    517   MemMap->MemoryType = (UINT32)Strtoi (MemoryTypeStr);
    518   Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
    519   Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
     524  if (MemMap != NULL) {
     525    MemMap->MemoryType = (UINT32)Strtoi (MemoryTypeStr);
     526    Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
     527    Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
     528  }
    520529
    521530  return (EFI_DEVICE_PATH_PROTOCOL *)MemMap;
     
    560569                                   );
    561570
    562   StrToGuid (GuidStr, &Vendor->Guid);
    563   StrHexToBytes (DataStr, Length * 2, (UINT8 *)(Vendor + 1), Length);
     571  if (Vendor != NULL) {
     572    StrToGuid (GuidStr, &Vendor->Guid);
     573    StrHexToBytes (DataStr, Length * 2, (UINT8 *)(Vendor + 1), Length);
     574  }
    564575
    565576  return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
     
    608619                                              (UINT16)sizeof (CONTROLLER_DEVICE_PATH)
    609620                                              );
    610   Controller->ControllerNumber = (UINT32)Strtoi (ControllerStr);
     621
     622  if (Controller != NULL) {
     623    Controller->ControllerNumber = (UINT32)Strtoi (ControllerStr);
     624  }
    611625
    612626  return (EFI_DEVICE_PATH_PROTOCOL *)Controller;
     
    638652                                          );
    639653
    640   BmcDp->InterfaceType = (UINT8)Strtoi (InterfaceTypeStr);
    641   WriteUnaligned64 (
    642     (UINT64 *)(&BmcDp->BaseAddress),
    643     StrHexToUint64 (BaseAddressStr)
    644     );
     654  if (BmcDp != NULL) {
     655    BmcDp->InterfaceType = (UINT8)Strtoi (InterfaceTypeStr);
     656    WriteUnaligned64 (
     657      (UINT64 *)(&BmcDp->BaseAddress),
     658      StrHexToUint64 (BaseAddressStr)
     659      );
     660  }
    645661
    646662  return (EFI_DEVICE_PATH_PROTOCOL *)BmcDp;
     
    707723                                     );
    708724
    709   Acpi->HID = EisaIdFromText (HIDStr);
    710   Acpi->UID = (UINT32)Strtoi (UIDStr);
     725  if (Acpi != NULL) {
     726    Acpi->HID = EisaIdFromText (HIDStr);
     727    Acpi->UID = (UINT32)Strtoi (UIDStr);
     728  }
    711729
    712730  return (EFI_DEVICE_PATH_PROTOCOL *)Acpi;
     
    738756                                     );
    739757
    740   Acpi->HID = EFI_PNP_ID (PnPId);
    741   Acpi->UID = (UINT32)Strtoi (UIDStr);
     758  if (Acpi != NULL) {
     759    Acpi->HID = EFI_PNP_ID (PnPId);
     760    Acpi->UID = (UINT32)Strtoi (UIDStr);
     761  }
    742762
    743763  return (EFI_DEVICE_PATH_PROTOCOL *)Acpi;
     
    879899                                              );
    880900
    881   AcpiEx->HID = EisaIdFromText (HIDStr);
    882   AcpiEx->CID = EisaIdFromText (CIDStr);
    883   AcpiEx->UID = (UINT32)Strtoi (UIDStr);
    884 
    885   AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
    886   StrToAscii (HIDSTRStr, &AsciiStr);
    887   StrToAscii (UIDSTRStr, &AsciiStr);
    888   StrToAscii (CIDSTRStr, &AsciiStr);
     901  if (AcpiEx != NULL) {
     902    AcpiEx->HID = EisaIdFromText (HIDStr);
     903    AcpiEx->CID = EisaIdFromText (CIDStr);
     904    AcpiEx->UID = (UINT32)Strtoi (UIDStr);
     905
     906    AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
     907    StrToAscii (HIDSTRStr, &AsciiStr);
     908    StrToAscii (UIDSTRStr, &AsciiStr);
     909    StrToAscii (CIDSTRStr, &AsciiStr);
     910  }
    889911
    890912  return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx;
     
    921943                                                 );
    922944
     945  if (AcpiEx == NULL) {
     946    return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx;
     947  }
     948
    923949  AcpiEx->HID = EisaIdFromText (HIDStr);
    924950  //
    925   // According to UEFI spec, the CID parametr is optional and has a default value of 0.
    926   // So when the CID parametr is not specified or specified as 0 in the text device node.
     951  // According to UEFI spec, the CID parameter is optional and has a default value of 0.
     952  // So when the CID parameter is not specified or specified as 0 in the text device node.
    927953  // Set the CID to 0 in the ACPI extension device path structure.
    928954  //
     
    9761002                                      (UINT16)sizeof (ACPI_ADR_DEVICE_PATH)
    9771003                                      );
    978   ASSERT (AcpiAdr != NULL);
     1004  if (AcpiAdr == NULL) {
     1005    ASSERT (AcpiAdr != NULL);
     1006    return (EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr;
     1007  }
    9791008
    9801009  for (Index = 0; ; Index++) {
     
    9911020                  AcpiAdr
    9921021                  );
    993       ASSERT (AcpiAdr != NULL);
     1022
     1023      if (AcpiAdr == NULL) {
     1024        ASSERT (AcpiAdr != NULL);
     1025        return (EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr;
     1026      }
     1027
    9941028      SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
    9951029    }
     
    10401074                                 (UINT16)sizeof (ATAPI_DEVICE_PATH)
    10411075                                 );
     1076
     1077  if (Atapi == NULL) {
     1078    return (EFI_DEVICE_PATH_PROTOCOL *)Atapi;
     1079  }
    10421080
    10431081  PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
     
    10911129                                 );
    10921130
    1093   Scsi->Pun = (UINT16)Strtoi (PunStr);
    1094   Scsi->Lun = (UINT16)Strtoi (LunStr);
     1131  if (Scsi != NULL) {
     1132    Scsi->Pun = (UINT16)Strtoi (PunStr);
     1133    Scsi->Lun = (UINT16)Strtoi (LunStr);
     1134  }
    10951135
    10961136  return (EFI_DEVICE_PATH_PROTOCOL *)Scsi;
     
    11221162                                         );
    11231163
    1124   Fibre->Reserved = 0;
    1125   Strtoi64 (WWNStr, &Fibre->WWN);
    1126   Strtoi64 (LunStr, &Fibre->Lun);
     1164  if (Fibre != NULL) {
     1165    Fibre->Reserved = 0;
     1166    Strtoi64 (WWNStr, &Fibre->WWN);
     1167    Strtoi64 (LunStr, &Fibre->Lun);
     1168  }
    11271169
    11281170  return (EFI_DEVICE_PATH_PROTOCOL *)Fibre;
     
    11541196                                            );
    11551197
    1156   FibreEx->Reserved = 0;
    1157   Strtoi64 (WWNStr, (UINT64 *)(&FibreEx->WWN));
    1158   Strtoi64 (LunStr, (UINT64 *)(&FibreEx->Lun));
    1159 
    1160   *(UINT64 *)(&FibreEx->WWN) = SwapBytes64 (*(UINT64 *)(&FibreEx->WWN));
    1161   *(UINT64 *)(&FibreEx->Lun) = SwapBytes64 (*(UINT64 *)(&FibreEx->Lun));
     1198  if (FibreEx != NULL) {
     1199    FibreEx->Reserved = 0;
     1200    Strtoi64 (WWNStr, (UINT64 *)(&FibreEx->WWN));
     1201    Strtoi64 (LunStr, (UINT64 *)(&FibreEx->Lun));
     1202
     1203    *(UINT64 *)(&FibreEx->WWN) = SwapBytes64 (*(UINT64 *)(&FibreEx->WWN));
     1204    *(UINT64 *)(&FibreEx->Lun) = SwapBytes64 (*(UINT64 *)(&FibreEx->Lun));
     1205  }
    11621206
    11631207  return (EFI_DEVICE_PATH_PROTOCOL *)FibreEx;
     
    11871231                                        );
    11881232
    1189   F1394DevPath->Reserved = 0;
    1190   F1394DevPath->Guid     = StrHexToUint64 (GuidStr);
     1233  if (F1394DevPath != NULL) {
     1234    F1394DevPath->Reserved = 0;
     1235    F1394DevPath->Guid     = StrHexToUint64 (GuidStr);
     1236  }
    11911237
    11921238  return (EFI_DEVICE_PATH_PROTOCOL *)F1394DevPath;
     
    12181264                                      );
    12191265
    1220   Usb->ParentPortNumber = (UINT8)Strtoi (PortStr);
    1221   Usb->InterfaceNumber  = (UINT8)Strtoi (InterfaceStr);
     1266  if (Usb != NULL) {
     1267    Usb->ParentPortNumber = (UINT8)Strtoi (PortStr);
     1268    Usb->InterfaceNumber  = (UINT8)Strtoi (InterfaceStr);
     1269  }
    12221270
    12231271  return (EFI_DEVICE_PATH_PROTOCOL *)Usb;
     
    12471295                                    );
    12481296
    1249   I2ODevPath->Tid = (UINT32)Strtoi (TIDStr);
     1297  if (I2ODevPath != NULL) {
     1298    I2ODevPath->Tid = (UINT32)Strtoi (TIDStr);
     1299  }
    12501300
    12511301  return (EFI_DEVICE_PATH_PROTOCOL *)I2ODevPath;
     
    12831333                                           );
    12841334
    1285   InfiniBand->ResourceFlags = (UINT32)Strtoi (FlagsStr);
    1286   StrToGuid (GuidStr, (EFI_GUID *)InfiniBand->PortGid);
    1287   Strtoi64 (SidStr, &InfiniBand->ServiceId);
    1288   Strtoi64 (TidStr, &InfiniBand->TargetPortId);
    1289   Strtoi64 (DidStr, &InfiniBand->DeviceId);
     1335  if (InfiniBand != NULL) {
     1336    InfiniBand->ResourceFlags = (UINT32)Strtoi (FlagsStr);
     1337    StrToGuid (GuidStr, (EFI_GUID *)InfiniBand->PortGid);
     1338    Strtoi64 (SidStr, &InfiniBand->ServiceId);
     1339    Strtoi64 (TidStr, &InfiniBand->TargetPortId);
     1340    Strtoi64 (DidStr, &InfiniBand->DeviceId);
     1341  }
    12901342
    12911343  return (EFI_DEVICE_PATH_PROTOCOL *)InfiniBand;
     
    13321384                                   (UINT16)sizeof (VENDOR_DEVICE_PATH)
    13331385                                   );
    1334   CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
     1386
     1387  if (Vendor != NULL) {
     1388    CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
     1389  }
    13351390
    13361391  return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
     
    13571412                                   (UINT16)sizeof (VENDOR_DEVICE_PATH)
    13581413                                   );
    1359   CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
     1414
     1415  if (Vendor != NULL) {
     1416    CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
     1417  }
    13601418
    13611419  return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
     
    13821440                                   (UINT16)sizeof (VENDOR_DEVICE_PATH)
    13831441                                   );
    1384   CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
     1442
     1443  if (Vendor != NULL) {
     1444    CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
     1445  }
    13851446
    13861447  return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
     
    14071468                                   (UINT16)sizeof (VENDOR_DEVICE_PATH)
    14081469                                   );
    1409   CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
     1470
     1471  if (Vendor != NULL) {
     1472    CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
     1473  }
    14101474
    14111475  return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
     
    14351499                                                       );
    14361500
    1437   CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
    1438   if (StrCmp (ValueStr, L"XonXoff") == 0) {
    1439     UartFlowControl->FlowControlMap = 2;
    1440   } else if (StrCmp (ValueStr, L"Hardware") == 0) {
    1441     UartFlowControl->FlowControlMap = 1;
    1442   } else {
    1443     UartFlowControl->FlowControlMap = 0;
     1501  if (UartFlowControl != NULL) {
     1502    CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
     1503    if (StrCmp (ValueStr, L"XonXoff") == 0) {
     1504      UartFlowControl->FlowControlMap = 2;
     1505    } else if (StrCmp (ValueStr, L"Hardware") == 0) {
     1506      UartFlowControl->FlowControlMap = 1;
     1507    } else {
     1508      UartFlowControl->FlowControlMap = 0;
     1509    }
    14441510  }
    14451511
     
    14861552                                     );
    14871553
     1554  if (Sas == NULL) {
     1555    return (EFI_DEVICE_PATH_PROTOCOL *)Sas;
     1556  }
     1557
    14881558  CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
    14891559  Strtoi64 (AddressStr, &Sas->SasAddress);
     
    15811651                                       );
    15821652
     1653  if (SasEx == NULL) {
     1654    return (EFI_DEVICE_PATH_PROTOCOL *)SasEx;
     1655  }
     1656
    15831657  Strtoi64 (AddressStr, &SasAddress);
    15841658  Strtoi64 (LunStr, &Lun);
     
    16641738                                                     );
    16651739
    1666   Nvme->NamespaceId = (UINT32)Strtoi (NamespaceIdStr);
    1667   Uuid              = (UINT8 *)&Nvme->NamespaceUuid;
    1668 
    1669   Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
    1670   while (Index-- != 0) {
    1671     Uuid[Index] = (UINT8)StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-'));
     1740  if (Nvme != NULL) {
     1741    Nvme->NamespaceId = (UINT32)Strtoi (NamespaceIdStr);
     1742    Uuid              = (UINT8 *)&Nvme->NamespaceUuid;
     1743
     1744    Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
     1745    while (Index-- != 0) {
     1746      Uuid[Index] = (UINT8)StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-'));
     1747    }
    16721748  }
    16731749
     
    17001776                                );
    17011777
    1702   Ufs->Pun = (UINT8)Strtoi (PunStr);
    1703   Ufs->Lun = (UINT8)Strtoi (LunStr);
     1778  if (Ufs != NULL) {
     1779    Ufs->Pun = (UINT8)Strtoi (PunStr);
     1780    Ufs->Lun = (UINT8)Strtoi (LunStr);
     1781  }
    17041782
    17051783  return (EFI_DEVICE_PATH_PROTOCOL *)Ufs;
     
    17291807                                      );
    17301808
    1731   Sd->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
     1809  if (Sd != NULL) {
     1810    Sd->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
     1811  }
    17321812
    17331813  return (EFI_DEVICE_PATH_PROTOCOL *)Sd;
     
    17571837                                        );
    17581838
    1759   Emmc->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
     1839  if (Emmc != NULL) {
     1840    Emmc->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
     1841  }
    17601842
    17611843  return (EFI_DEVICE_PATH_PROTOCOL *)Emmc;
     
    17831865                                 );
    17841866
    1785   CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
     1867  if (Vend != NULL) {
     1868    CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
     1869  }
    17861870
    17871871  return (EFI_DEVICE_PATH_PROTOCOL *)Vend;
     
    18141898                                         );
    18151899
    1816   MACDevPath->IfType = (UINT8)Strtoi (IfTypeStr);
    1817 
    1818   Length = sizeof (EFI_MAC_ADDRESS);
    1819   if ((MACDevPath->IfType == 0x01) || (MACDevPath->IfType == 0x00)) {
    1820     Length = 6;
    1821   }
    1822 
    1823   StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);
     1900  if (MACDevPath != NULL) {
     1901    MACDevPath->IfType = (UINT8)Strtoi (IfTypeStr);
     1902
     1903    Length = sizeof (EFI_MAC_ADDRESS);
     1904    if ((MACDevPath->IfType == 0x01) || (MACDevPath->IfType == 0x00)) {
     1905      Length = 6;
     1906    }
     1907
     1908    StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);
     1909  }
    18241910
    18251911  return (EFI_DEVICE_PATH_PROTOCOL *)MACDevPath;
     
    18831969                                        );
    18841970
     1971  if (IPv4 == NULL) {
     1972    return (EFI_DEVICE_PATH_PROTOCOL *)IPv4;
     1973  }
     1974
    18851975  StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL);
    18861976  IPv4->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr);
     
    19392029                                          );
    19402030
     2031  if (IPv6 == NULL) {
     2032    return (EFI_DEVICE_PATH_PROTOCOL *)IPv6;
     2033  }
     2034
    19412035  StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL);
    19422036  IPv6->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr);
     
    19922086                                      (UINT16)sizeof (UART_DEVICE_PATH)
    19932087                                      );
     2088
     2089  if (Uart == NULL) {
     2090    return (EFI_DEVICE_PATH_PROTOCOL *)Uart;
     2091  }
    19942092
    19952093  if (StrCmp (BaudStr, L"DEFAULT") == 0) {
     
    20722170                                        (UINT16)sizeof (USB_CLASS_DEVICE_PATH)
    20732171                                        );
     2172
     2173  if (UsbClass == NULL) {
     2174    return (EFI_DEVICE_PATH_PROTOCOL *)UsbClass;
     2175  }
    20742176
    20752177  VIDStr = GetNextParamStr (&TextDeviceNode);
     
    25142616                                      (UINT16)(sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
    25152617                                      );
    2516   UsbWwid->VendorId        = (UINT16)Strtoi (VIDStr);
    2517   UsbWwid->ProductId       = (UINT16)Strtoi (PIDStr);
    2518   UsbWwid->InterfaceNumber = (UINT16)Strtoi (InterfaceNumStr);
    2519 
    2520   //
    2521   // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
    2522   // Therefore, the '\0' will not be copied.
    2523   //
    2524   CopyMem (
    2525     (UINT8 *)UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
    2526     SerialNumberStr,
    2527     SerialNumberStrLen * sizeof (CHAR16)
    2528     );
     2618
     2619  if (UsbWwid != NULL) {
     2620    UsbWwid->VendorId        = (UINT16)Strtoi (VIDStr);
     2621    UsbWwid->ProductId       = (UINT16)Strtoi (PIDStr);
     2622    UsbWwid->InterfaceNumber = (UINT16)Strtoi (InterfaceNumStr);
     2623
     2624    //
     2625    // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
     2626    // Therefore, the '\0' will not be copied.
     2627    //
     2628    CopyMem (
     2629      (UINT8 *)UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
     2630      SerialNumberStr,
     2631      SerialNumberStrLen * sizeof (CHAR16)
     2632      );
     2633  }
    25292634
    25302635  return (EFI_DEVICE_PATH_PROTOCOL *)UsbWwid;
     
    25542659                                                     );
    25552660
    2556   LogicalUnit->Lun = (UINT8)Strtoi (LunStr);
     2661  if (LogicalUnit != NULL) {
     2662    LogicalUnit->Lun = (UINT8)Strtoi (LunStr);
     2663  }
    25572664
    25582665  return (EFI_DEVICE_PATH_PROTOCOL *)LogicalUnit;
     
    25972704                                                       );
    25982705
     2706  if (ISCSIDevPath == NULL) {
     2707    return (EFI_DEVICE_PATH_PROTOCOL *)ISCSIDevPath;
     2708  }
     2709
    25992710  AsciiStr = ISCSIDevPath->TargetName;
    26002711  StrToAscii (NameStr, &AsciiStr);
     
    26582769                                  );
    26592770
    2660   Vlan->VlanId = (UINT16)Strtoi (VlanStr);
     2771  if (Vlan != NULL) {
     2772    Vlan->VlanId = (UINT16)Strtoi (VlanStr);
     2773  }
    26612774
    26622775  return (EFI_DEVICE_PATH_PROTOCOL *)Vlan;
     
    26852798                                            (UINT16)sizeof (BLUETOOTH_DEVICE_PATH)
    26862799                                            );
    2687   StrHexToBytes (
    2688     BluetoothStr,
    2689     sizeof (BLUETOOTH_ADDRESS) * 2,
    2690     BluetoothDp->BD_ADDR.Address,
    2691     sizeof (BLUETOOTH_ADDRESS)
    2692     );
     2800
     2801  if (BluetoothDp != NULL) {
     2802    StrHexToBytes (
     2803      BluetoothStr,
     2804      sizeof (BLUETOOTH_ADDRESS) * 2,
     2805      BluetoothDp->BD_ADDR.Address,
     2806      sizeof (BLUETOOTH_ADDRESS)
     2807      );
     2808  }
     2809
    26932810  return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothDp;
    26942811}
     
    27192836                                  );
    27202837
    2721   if (NULL != SSIdStr) {
     2838  if ((NULL != SSIdStr) && (NULL != WiFiDp)) {
    27222839    DataLen = StrLen (SSIdStr);
    27232840    if (StrLen (SSIdStr) > 32) {
     
    27582875                                                         );
    27592876
    2760   BluetoothLeDp->Address.Type = (UINT8)Strtoi (BluetoothLeAddrTypeStr);
    2761   StrHexToBytes (
    2762     BluetoothLeAddrStr,
    2763     sizeof (BluetoothLeDp->Address.Address) * 2,
    2764     BluetoothLeDp->Address.Address,
    2765     sizeof (BluetoothLeDp->Address.Address)
    2766     );
     2877  if (BluetoothLeDp != NULL) {
     2878    BluetoothLeDp->Address.Type = (UINT8)Strtoi (BluetoothLeAddrTypeStr);
     2879    StrHexToBytes (
     2880      BluetoothLeAddrStr,
     2881      sizeof (BluetoothLeDp->Address.Address) * 2,
     2882      BluetoothLeDp->Address.Address,
     2883      sizeof (BluetoothLeDp->Address.Address)
     2884      );
     2885  }
     2886
    27672887  return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothLeDp;
    27682888}
     
    28843004                                   );
    28853005
    2886   while (UriLength-- != 0) {
     3006  while (Uri != NULL && UriLength-- != 0) {
    28873007    Uri->Uri[UriLength] = (CHAR8)UriStr[UriLength];
    28883008  }
     
    29393059                                            );
    29403060
     3061  if (Hd == NULL) {
     3062    return (EFI_DEVICE_PATH_PROTOCOL *)Hd;
     3063  }
     3064
    29413065  Hd->PartitionNumber = (UINT32)Strtoi (PartitionStr);
    29423066
     
    29923116                                        );
    29933117
    2994   CDROMDevPath->BootEntry = (UINT32)Strtoi (EntryStr);
    2995   Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
    2996   Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
     3118  if (CDROMDevPath != NULL) {
     3119    CDROMDevPath->BootEntry = (UINT32)Strtoi (EntryStr);
     3120    Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
     3121    Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
     3122  }
    29973123
    29983124  return (EFI_DEVICE_PATH_PROTOCOL *)CDROMDevPath;
     
    30403166                                   );
    30413167
    3042   StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
     3168  if (File != NULL) {
     3169    StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
     3170  }
    30433171
    30443172  return (EFI_DEVICE_PATH_PROTOCOL *)File;
     
    30683196                                            );
    30693197
    3070   StrToGuid (GuidStr, &Media->Protocol);
     3198  if (Media != NULL) {
     3199    StrToGuid (GuidStr, &Media->Protocol);
     3200  }
    30713201
    30723202  return (EFI_DEVICE_PATH_PROTOCOL *)Media;
     
    30963226                                          );
    30973227
    3098   StrToGuid (GuidStr, &Fv->FvName);
     3228  if (Fv != NULL) {
     3229    StrToGuid (GuidStr, &Fv->FvName);
     3230  }
    30993231
    31003232  return (EFI_DEVICE_PATH_PROTOCOL *)Fv;
     
    31243256                                                   );
    31253257
    3126   StrToGuid (GuidStr, &FvFile->FvFileName);
     3258  if (FvFile != NULL) {
     3259    StrToGuid (GuidStr, &FvFile->FvFileName);
     3260  }
    31273261
    31283262  return (EFI_DEVICE_PATH_PROTOCOL *)FvFile;
     
    31543288                                                                   );
    31553289
    3156   Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
    3157   Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
     3290  if (Offset != NULL) {
     3291    Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
     3292    Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
     3293  }
    31583294
    31593295  return (EFI_DEVICE_PATH_PROTOCOL *)Offset;
     
    31913327                                                    );
    31923328
    3193   Strtoi64 (StartingAddrStr, &StartingAddr);
    3194   WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
    3195   Strtoi64 (EndingAddrStr, &EndingAddr);
    3196   WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
    3197   RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
    3198   StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
     3329  if (RamDisk != NULL) {
     3330    Strtoi64 (StartingAddrStr, &StartingAddr);
     3331    WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
     3332    Strtoi64 (EndingAddrStr, &EndingAddr);
     3333    WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
     3334    RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
     3335    StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
     3336  }
    31993337
    32003338  return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
     
    32313369                                            );
    32323370
    3233   Strtoi64 (StartingAddrStr, &StartingAddr);
    3234   WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
    3235   Strtoi64 (EndingAddrStr, &EndingAddr);
    3236   WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
    3237   RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
    3238   CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
     3371  if (RamDisk != NULL) {
     3372    Strtoi64 (StartingAddrStr, &StartingAddr);
     3373    WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
     3374    Strtoi64 (EndingAddrStr, &EndingAddr);
     3375    WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
     3376    RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
     3377    CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
     3378  }
    32393379
    32403380  return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
     
    32713411                                            );
    32723412
    3273   Strtoi64 (StartingAddrStr, &StartingAddr);
    3274   WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
    3275   Strtoi64 (EndingAddrStr, &EndingAddr);
    3276   WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
    3277   RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
    3278   CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
     3413  if (RamDisk != NULL) {
     3414    Strtoi64 (StartingAddrStr, &StartingAddr);
     3415    WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
     3416    Strtoi64 (EndingAddrStr, &EndingAddr);
     3417    WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
     3418    RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
     3419    CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
     3420  }
    32793421
    32803422  return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
     
    33113453                                            );
    33123454
    3313   Strtoi64 (StartingAddrStr, &StartingAddr);
    3314   WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
    3315   Strtoi64 (EndingAddrStr, &EndingAddr);
    3316   WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
    3317   RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
    3318   CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
     3455  if (RamDisk != NULL) {
     3456    Strtoi64 (StartingAddrStr, &StartingAddr);
     3457    WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
     3458    Strtoi64 (EndingAddrStr, &EndingAddr);
     3459    WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
     3460    RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
     3461    CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
     3462  }
    33193463
    33203464  return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
     
    33513495                                            );
    33523496
    3353   Strtoi64 (StartingAddrStr, &StartingAddr);
    3354   WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
    3355   Strtoi64 (EndingAddrStr, &EndingAddr);
    3356   WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
    3357   RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
    3358   CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
     3497  if (RamDisk != NULL) {
     3498    Strtoi64 (StartingAddrStr, &StartingAddr);
     3499    WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
     3500    Strtoi64 (EndingAddrStr, &EndingAddr);
     3501    WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
     3502    RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
     3503    CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
     3504  }
    33593505
    33603506  return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
     
    34043550                                      (UINT16)(sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
    34053551                                      );
     3552
     3553  if (Bbs == NULL) {
     3554    return (EFI_DEVICE_PATH_PROTOCOL *)Bbs;
     3555  }
    34063556
    34073557  if (StrCmp (TypeStr, L"Floppy") == 0) {
     
    34563606                               (UINT16)sizeof (SATA_DEVICE_PATH)
    34573607                               );
     3608
     3609  if (Sata == NULL) {
     3610    return (EFI_DEVICE_PATH_PROTOCOL *)Sata;
     3611  }
     3612
    34583613  Sata->HBAPortNumber = (UINT16)Strtoi (Param1);
    34593614
     
    36573812
    36583813  DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH);
    3659   ASSERT (DevicePath != NULL);
     3814
     3815  if (DevicePath == NULL) {
     3816    ASSERT (DevicePath != NULL);
     3817    return NULL;
     3818  }
     3819
    36603820  SetDevicePathEndNode (DevicePath);
    36613821
    36623822  DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
     3823
     3824  if (DevicePathStr == NULL) {
     3825    return NULL;
     3826  }
    36633827
    36643828  Str = DevicePathStr;
     
    36673831
    36683832    NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
    3669     FreePool (DevicePath);
    3670     FreePool (DeviceNode);
     3833    if (DevicePath != NULL) {
     3834      FreePool (DevicePath);
     3835    }
     3836
     3837    if (DeviceNode != NULL) {
     3838      FreePool (DeviceNode);
     3839    }
     3840
    36713841    DevicePath = NewDevicePath;
    36723842
    36733843    if (IsInstanceEnd) {
    36743844      DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH);
    3675       ASSERT (DeviceNode != NULL);
     3845      if (DeviceNode == NULL) {
     3846        ASSERT (DeviceNode != NULL);
     3847        return NULL;
     3848      }
     3849
    36763850      SetDevicePathEndNode (DeviceNode);
    36773851      DeviceNode->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
    36783852
    36793853      NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
    3680       FreePool (DevicePath);
    3681       FreePool (DeviceNode);
     3854      if (DevicePath != NULL) {
     3855        FreePool (DevicePath);
     3856      }
     3857
     3858      if (DeviceNode != NULL) {
     3859        FreePool (DeviceNode);
     3860      }
     3861
    36823862      DevicePath = NewDevicePath;
    36833863    }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c

    r105670 r108794  
    10041004    // In case no NULL terminator in SerialNumber, create a new one with NULL terminator
    10051005    //
    1006     NewStr = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), SerialNumberStr);
     1006    NewStr = AllocatePool ((Length + 1) * sizeof (CHAR16));
    10071007    ASSERT (NewStr != NULL);
     1008    CopyMem (NewStr, SerialNumberStr, Length * sizeof (CHAR16));
    10081009    NewStr[Length]  = 0;
    10091010    SerialNumberStr = NewStr;
     
    18421843  UriLength = DevicePathNodeLength (Uri) - sizeof (URI_DEVICE_PATH);
    18431844  UriStr    = AllocatePool (UriLength + 1);
    1844   ASSERT (UriStr != NULL);
     1845
     1846  if (UriStr == NULL) {
     1847    ASSERT (UriStr != NULL);
     1848    return;
     1849  }
    18451850
    18461851  CopyMem (UriStr, Uri->Uri, UriLength);
     
    18781883      UefiDevicePathLibCatPrint (
    18791884        Str,
    1880         L"HD(%d,%s,0x%08x,",
     1885        L"HD(%d,%s,0x%08x",
    18811886        Hd->PartitionNumber,
    18821887        L"MBR",
     
    18881893      UefiDevicePathLibCatPrint (
    18891894        Str,
    1890         L"HD(%d,%s,%g,",
     1895        L"HD(%d,%s,%g",
    18911896        Hd->PartitionNumber,
    18921897        L"GPT",
     
    18981903      UefiDevicePathLibCatPrint (
    18991904        Str,
    1900         L"HD(%d,%d,0,",
     1905        L"HD(%d,%d,0",
    19011906        Hd->PartitionNumber,
    19021907        Hd->SignatureType
     
    19051910  }
    19061911
    1907   UefiDevicePathLibCatPrint (Str, L"0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);
     1912  if (DisplayOnly) {
     1913    UefiDevicePathLibCatPrint (Str, L")");
     1914  } else {
     1915    UefiDevicePathLibCatPrint (Str, L",0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);
     1916  }
    19081917}
    19091918
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf

    r80721 r108794  
    3737  DebugLib
    3838  BaseLib
     39  StackCheckLib
    3940
    4041
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c

    r99404 r108794  
    931931  if (Status == EFI_BUFFER_TOO_SMALL) {
    932932    RetVal = AllocateZeroPool (Size);
     933
     934    if (RetVal == NULL) {
     935      return NULL;
     936    }
     937
    933938    Status = FileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);
    934939  }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiLib/Acpi.c

    r99404 r108794  
    221221                                                            NULL
    222222                                                            );
    223       Table = LocateAcpiDsdtFromFadt (Fadt);
     223
     224      if (Fadt != NULL) {
     225        Table = LocateAcpiDsdtFromFadt (Fadt);
     226      } else {
     227        Table = NULL;
     228      }
    224229    } else if (Signature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) {
    225230      ASSERT (PreviousTable == NULL);
     
    235240                                                            NULL
    236241                                                            );
    237       Table = LocateAcpiFacsFromFadt (Fadt);
     242
     243      if (Fadt != NULL) {
     244        Table = LocateAcpiFacsFromFadt (Fadt);
     245      } else {
     246        Table = NULL;
     247      }
    238248    } else {
    239249      Table = ScanTableInSDT (
     
    276286                                                          NULL
    277287                                                          );
    278     Table = LocateAcpiDsdtFromFadt (Fadt);
     288
     289    if (Fadt != NULL) {
     290      Table = LocateAcpiDsdtFromFadt (Fadt);
     291    } else {
     292      Table = NULL;
     293    }
    279294  } else if (Signature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) {
    280295    ASSERT (PreviousTable == NULL);
     
    290305                                                          NULL
    291306                                                          );
    292     Table = LocateAcpiFacsFromFadt (Fadt);
     307
     308    if (Fadt != NULL) {
     309      Table = LocateAcpiFacsFromFadt (Fadt);
     310    } else {
     311      Table = NULL;
     312    }
    293313  } else {
    294314    Table = ScanTableInSDT (
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiLib/Console.c

    r99404 r108794  
    478478  //
    479479  Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16));
    480   ASSERT (Line != NULL);
     480
     481  if (Line == NULL) {
     482    ASSERT (Line != NULL);
     483    return;
     484  }
    481485
    482486  //
     
    514518      UefiLibGetStringWidth (String, TRUE, MaxLength, &Length);
    515519      TmpString = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));
    516       ASSERT (TmpString != NULL);
     520
     521      if (TmpString == NULL) {
     522        ASSERT (TmpString != NULL);
     523        break;
     524      }
     525
    517526      StrnCpyS (TmpString, Length + 1, String, Length - 3);
    518527      StrCatS (TmpString, Length + 1, L"...");
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiLib/UefiLibPrint.c

    r99404 r108794  
    6666
    6767  Buffer = (CHAR16 *)AllocatePool (BufferSize);
    68   ASSERT (Buffer != NULL);
     68
     69  if (Buffer == NULL) {
     70    ASSERT (Buffer != NULL);
     71    return 0;
     72  }
    6973
    7074  Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
     
    200204
    201205  Buffer = (CHAR16 *)AllocatePool (BufferSize);
    202   ASSERT (Buffer != NULL);
     206
     207  if (Buffer == NULL) {
     208    ASSERT (Buffer != NULL);
     209    return 0;
     210  }
    203211
    204212  Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
     
    420428
    421429  Blt = (EFI_IMAGE_OUTPUT *)AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
    422   ASSERT (Blt != NULL);
     430
     431  if (Blt == NULL) {
     432    ASSERT (Blt != NULL);
     433    goto Error;
     434  }
    423435
    424436  Blt->Width  = (UINT16)(HorizontalResolution);
     
    626638
    627639  Buffer = (CHAR16 *)AllocatePool (BufferSize);
    628   ASSERT (Buffer != NULL);
     640
     641  if (Buffer == NULL) {
     642    ASSERT (Buffer != NULL);
     643    return 0;
     644  }
    629645
    630646  PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
     
    704720
    705721  Buffer = (CHAR16 *)AllocatePool (BufferSize);
    706   ASSERT (Buffer != NULL);
     722
     723  if (Buffer == NULL) {
     724    ASSERT (Buffer != NULL);
     725    return 0;
     726  }
    707727
    708728  PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c

    r80721 r108794  
    11/** @file
    2   SetMem() and SetMemN() implementation.
     2  SetMem() implementation.
    33
    44  The following BaseMemoryLib instances contain the same copy of this file:
     
    5050  return InternalMemSetMem (Buffer, Length, Value);
    5151}
    52 
    53 /**
    54   Fills a target buffer with a value that is size UINTN, and returns the target buffer.
    55 
    56   This function fills Length bytes of Buffer with the UINTN sized value specified by
    57   Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
    58   bytes of Buffer.
    59 
    60   If Length > 0 and Buffer is NULL, then ASSERT().
    61   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
    62   If Buffer is not aligned on a UINTN boundary, then ASSERT().
    63   If Length is not aligned on a UINTN boundary, then ASSERT().
    64 
    65   @param  Buffer  The pointer to the target buffer to fill.
    66   @param  Length  The number of bytes in Buffer to fill.
    67   @param  Value   The value with which to fill Length bytes of Buffer.
    68 
    69   @return Buffer.
    70 
    71 **/
    72 VOID *
    73 EFIAPI
    74 SetMemN (
    75   OUT VOID  *Buffer,
    76   IN UINTN  Length,
    77   IN UINTN  Value
    78   )
    79 {
    80   if (sizeof (UINTN) == sizeof (UINT64)) {
    81     return SetMem64 (Buffer, Length, (UINT64)Value);
    82   } else {
    83     return SetMem32 (Buffer, Length, (UINT32)Value);
    84   }
    85 }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf

    r80721 r108794  
    3333  ZeroMemWrapper.c
    3434  CompareMemWrapper.c
     35  SetMemNWrapper.c
    3536  SetMem64Wrapper.c
    3637  SetMem32Wrapper.c
     
    4849  MdePkg/MdePkg.dec
    4950
    50 
    5151[LibraryClasses]
    5252  BaseLib
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c

    r99404 r108794  
    185185
    186186  PciRootBridgeIo = PciSegmentLibSearchForRootBridge (Address);
    187   ASSERT (PciRootBridgeIo != NULL);
     187
     188  if (PciRootBridgeIo == NULL) {
     189    ASSERT (PciRootBridgeIo != NULL);
     190    return 0;
     191  }
    188192
    189193  PciRootBridgeIo->Pci.Read (
     
    224228
    225229  PciRootBridgeIo = PciSegmentLibSearchForRootBridge (Address);
    226   ASSERT (PciRootBridgeIo != NULL);
     230
     231  if (PciRootBridgeIo == NULL) {
     232    ASSERT (PciRootBridgeIo != NULL);
     233    return 0;
     234  }
    227235
    228236  PciRootBridgeIo->Pci.Write (
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiUsbLib/UefiUsbLib.inf

    r80721 r108794  
    66#
    77# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
     8# Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR>
    89#
    910#  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2021  VERSION_STRING                 = 1.0
    2122  LIBRARY_CLASS                  = UefiUsbLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
     23  DESTRUCTOR                     = UefiUsbLibDestructor
    2224
    2325
     
    3840  BaseMemoryLib
    3941  PcdLib
     42  UefiBootServicesTableLib
    4043
    4144[Pcd]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiUsbLib/UefiUsbLibInternal.h

    r99404 r108794  
    66
    77  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
     8  Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR>
    89   SPDX-License-Identifier: BSD-2-Clause-Patent
    910**/
     
    1819#include <Library/DebugLib.h>
    1920#include <Library/PcdLib.h>
     21#include <Library/UefiBootServicesTableLib.h>
    2022
    2123#include <IndustryStandard/Usb.h>
  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiUsbLib/UsbDxeLib.c

    r99404 r108794  
    55
    66  Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
     7  Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR>
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
    89
     
    1011
    1112#include "UefiUsbLibInternal.h"
     13
     14static UINT8                      *mConfigData = NULL;
     15static EFI_USB_DEVICE_DESCRIPTOR  mDeviceDescriptor;
    1216
    1317/**
     
    651655  return Result;
    652656}
     657
     658/**
     659  Global library data initialization.
     660
     661  Library public functions' input is the instance of UsbIo protocol. Check if the global
     662  data relevant to the UsbIo. If not, read the device and update the global data.
     663
     664  @param  UsbIo           The instance of EFI_USB_IO_PROTOCOL.
     665
     666  @retval EFI_SUCCESS     The global data is updated.
     667  @retval EFI_NOT_FOUND   The UsbIo configuration was not found.
     668
     669**/
     670static
     671EFI_STATUS
     672InitUsbConfigDescriptorData (
     673  EFI_USB_IO_PROTOCOL  *UsbIo
     674  )
     675{
     676  EFI_STATUS                 Status;
     677  EFI_USB_DEVICE_DESCRIPTOR  DevDesc;
     678  EFI_USB_CONFIG_DESCRIPTOR  CnfDesc;
     679  UINT8                      ConfigNum;
     680  UINT8                      ConfigValue;
     681  UINT32                     UsbStatus;
     682
     683  //
     684  // Get UsbIo device and configuration descriptors.
     685  //
     686  Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
     687  ASSERT_EFI_ERROR (Status);
     688
     689  Status = UsbIo->UsbGetConfigDescriptor (UsbIo, &CnfDesc);
     690  ASSERT_EFI_ERROR (Status);
     691
     692  if (mConfigData != NULL) {
     693    if (  (CompareMem (&DevDesc, &mDeviceDescriptor, sizeof (EFI_USB_DEVICE_DESCRIPTOR)) == 0)
     694       && (CompareMem (&CnfDesc, mConfigData, sizeof (EFI_USB_CONFIG_DESCRIPTOR)) == 0))
     695    {
     696      return EFI_SUCCESS;
     697    }
     698
     699    gBS->FreePool (mConfigData);
     700    mConfigData = NULL;
     701  }
     702
     703  CopyMem (&mDeviceDescriptor, &DevDesc, sizeof (EFI_USB_DEVICE_DESCRIPTOR));
     704
     705  //
     706  // Examine device with multiple configurations: find configuration index of UsbIo config descriptor.
     707  //
     708  // Use EFI_USB_DEVICE_DESCRIPTOR.NumConfigurations to loop through configuration descriptors, match
     709  // EFI_USB_CONFIG_DESCRIPTOR.ConfigurationValue to the configuration value reported by UsbIo->UsbGetConfigDescriptor.
     710  // The index of the matched configuration is used in wValue of the following GET_DESCRIPTOR request.
     711  //
     712  ConfigValue = CnfDesc.ConfigurationValue;
     713  for (ConfigNum = 0; ConfigNum < DevDesc.NumConfigurations; ConfigNum++) {
     714    Status = UsbGetDescriptor (
     715               UsbIo,
     716               (USB_DESC_TYPE_CONFIG << 8) | ConfigNum,
     717               0,
     718               sizeof (EFI_USB_CONFIG_DESCRIPTOR),
     719               &CnfDesc,
     720               &UsbStatus
     721               );
     722    ASSERT_EFI_ERROR (Status);
     723
     724    if (CnfDesc.ConfigurationValue == ConfigValue) {
     725      break;
     726    }
     727  }
     728
     729  ASSERT (ConfigNum < DevDesc.NumConfigurations);
     730  if (ConfigNum == DevDesc.NumConfigurations) {
     731    return EFI_NOT_FOUND;
     732  }
     733
     734  //
     735  // ConfigNum has zero based index of the configuration that UsbIo belongs to. Use this index to retrieve
     736  // full configuration descriptor data.
     737  //
     738  Status = gBS->AllocatePool (EfiBootServicesData, CnfDesc.TotalLength, (VOID **)&mConfigData);
     739  ASSERT_EFI_ERROR (Status);
     740
     741  Status = UsbGetDescriptor (
     742             UsbIo,
     743             (USB_DESC_TYPE_CONFIG << 8) | ConfigNum,
     744             0,
     745             CnfDesc.TotalLength,
     746             mConfigData,
     747             &UsbStatus
     748             );
     749  ASSERT_EFI_ERROR (Status);
     750
     751  return Status;
     752}
     753
     754/**
     755  Find descriptor of a given type within data area pointed by mConfigData.
     756
     757  The following are the assumptions of the configuration descriptor layout:
     758  - mConfigData is populated with the configuration data that contains USB interface referenced by UsbIo.
     759  - Endpoint may have only one class specific descriptor that immediately follows the endpoint descriptor.
     760
     761  @param[in]  UsbIo             A pointer to the EFI_USB_IO_PROTOCOL instance.
     762  @param[in]  DescType          Type of descriptor to look for.
     763  @param[in]  Setting           Interface alternate setting.
     764  @param[in]  Index             Index of the descriptor. This descriptor index is used to find a specific
     765                                descriptor (only for endpoint descriptors and class specific interface descriptors)
     766                                when several descriptors of the same type are implemented in a device. For other
     767                                descriptor types, a descriptor index of zero must be used.
     768  @param[out]  Data             A pointer to the caller allocated Descriptor.
     769
     770  @retval EFI_SUCCESS           Output parameters were updated successfully.
     771  @retval EFI_UNSUPPORTED       Setting is greater than the number of alternate settings in this interface.
     772  @retval EFI_NOT_FOUND         Index is greater than the number of descriptors of the requested type in this
     773                                interface.
     774**/
     775static
     776EFI_STATUS
     777FindUsbDescriptor (
     778  EFI_USB_IO_PROTOCOL  *UsbIo,
     779  UINT8                DescType,
     780  UINT16               Setting,
     781  UINTN                Index,
     782  VOID                 **Data
     783  )
     784{
     785  EFI_USB_INTERFACE_DESCRIPTOR  IntfDesc;
     786  EFI_STATUS                    Status;
     787  UINT8                         *BufferPtr;
     788  UINT8                         *BufferEnd;
     789  UINT8                         *ConfigEnd;
     790  UINTN                         Idx;
     791
     792  //
     793  // Find the interface descriptor referenced by UsbIo in the current configuration
     794  //
     795  Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IntfDesc);
     796  ASSERT_EFI_ERROR (Status);
     797
     798  ConfigEnd = mConfigData + ((EFI_USB_CONFIG_DESCRIPTOR *)mConfigData)->TotalLength;
     799
     800  for (BufferPtr = mConfigData; BufferPtr < ConfigEnd; BufferPtr += BufferPtr[0]) {
     801    if (BufferPtr[1] == USB_DESC_TYPE_INTERFACE) {
     802      if ((BufferPtr[2] == IntfDesc.InterfaceNumber) && (BufferPtr[3] == (UINT8)Setting)) {
     803        break;
     804      }
     805    }
     806  }
     807
     808  if (BufferPtr >= ConfigEnd) {
     809    return EFI_UNSUPPORTED;
     810  }
     811
     812  //
     813  // Found the beginning of the interface, find the ending
     814  //
     815  for (BufferEnd = BufferPtr + BufferPtr[0]; BufferEnd < ConfigEnd; BufferEnd += BufferEnd[0]) {
     816    if (BufferEnd[1] == USB_DESC_TYPE_INTERFACE) {
     817      break;
     818    }
     819  }
     820
     821  Idx = 0;
     822
     823  if (DescType == USB_DESC_TYPE_INTERFACE) {
     824    *Data = BufferPtr;
     825    return EFI_SUCCESS;
     826  }
     827
     828  if ((DescType == USB_DESC_TYPE_ENDPOINT) || (DescType == USB_DESC_TYPE_CS_ENDPOINT)) {
     829    while (BufferPtr < BufferEnd) {
     830      BufferPtr += BufferPtr[0];
     831      if (BufferPtr[1] == USB_DESC_TYPE_ENDPOINT) {
     832        if (Idx == Index) {
     833          if (DescType == USB_DESC_TYPE_CS_ENDPOINT) {
     834            BufferPtr += BufferPtr[0];
     835            if (BufferPtr[1] != USB_DESC_TYPE_CS_ENDPOINT) {
     836              break;
     837            }
     838          }
     839
     840          *Data = BufferPtr;
     841          return EFI_SUCCESS;
     842        }
     843
     844        Idx++;
     845      }
     846    }
     847  }
     848
     849  if (DescType  == USB_DESC_TYPE_CS_INTERFACE) {
     850    while (BufferPtr < BufferEnd) {
     851      BufferPtr += BufferPtr[0];
     852      if (BufferPtr[1] == USB_DESC_TYPE_CS_INTERFACE) {
     853        if (Idx == Index) {
     854          *Data = BufferPtr;
     855          return EFI_SUCCESS;
     856        }
     857
     858        Idx++;
     859      }
     860    }
     861  }
     862
     863  return EFI_NOT_FOUND;
     864}
     865
     866/**
     867  Retrieve the number of class specific interface descriptors.
     868
     869  @param[in]  Data    A pointer to the USB interface descriptor that may contain class code descriptors.
     870
     871  @retval UINT8       Number of the class code interface descriptors.
     872
     873**/
     874static
     875UINT8
     876FindNumberOfCsInterfaces (
     877  VOID  *Data
     878  )
     879{
     880  UINT8  *Buffer;
     881  UINT8  *ConfigEnd;
     882  UINT8  Index;
     883
     884  Buffer    = Data;
     885  ConfigEnd = mConfigData + ((EFI_USB_CONFIG_DESCRIPTOR *)mConfigData)->TotalLength;
     886
     887  Index = 0;
     888
     889  for (Buffer += Buffer[0]; Buffer < ConfigEnd; Buffer += Buffer[0]) {
     890    if (Buffer[1] == USB_DESC_TYPE_INTERFACE) {
     891      break;
     892    }
     893
     894    if (Buffer[1] == USB_DESC_TYPE_CS_INTERFACE) {
     895      Index++;
     896    }
     897  }
     898
     899  return Index;
     900}
     901
     902/**
     903  Retrieve the interface descriptor details from the interface setting.
     904
     905  This is an extended version of UsbIo->GetInterfaceDescriptor. It returns the interface
     906  descriptor for an alternate setting of the interface without executing SET_INTERFACE
     907  transfer. It also returns the number of class specific interfaces.
     908  AlternateSetting parameter is the zero-based interface descriptor index that is used in USB
     909  interface descriptor as USB_INTERFACE_DESCRIPTOR.AlternateSetting.
     910
     911
     912  @param[in]  This              A pointer to the EFI_USB_IO_PROTOCOL instance.
     913  @param[in]  AlternateSetting  Interface alternate setting.
     914  @param[out]  Descriptor       The caller allocated buffer to return the contents of the Interface descriptor.
     915  @param[out]  CsInterfaceNumber  Number of class specific interfaces for this interface setting.
     916
     917  @retval EFI_SUCCESS           Output parameters were updated successfully.
     918  @retval EFI_INVALID_PARAMETER Descriptor or CsInterfaceNumber is NULL.
     919  @retval EFI_UNSUPPORTED       AlternateSetting is greater than the number of alternate settings in this interface.
     920  @retval EFI_DEVICE_ERROR      Error reading device data.
     921
     922**/
     923EFI_STATUS
     924EFIAPI
     925UsbGetInterfaceDescriptorSetting (
     926  IN  EFI_USB_IO_PROTOCOL           *This,
     927  IN  UINT16                        AlternateSetting,
     928  OUT EFI_USB_INTERFACE_DESCRIPTOR  *Descriptor,
     929  OUT UINTN                         *CsInterfacesNumber
     930  )
     931{
     932  EFI_STATUS  Status;
     933  VOID        *Data;
     934  EFI_TPL     OldTpl;
     935
     936  if ((Descriptor == NULL) || (CsInterfacesNumber == NULL)) {
     937    return EFI_INVALID_PARAMETER;
     938  }
     939
     940  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
     941
     942  Status = InitUsbConfigDescriptorData (This);
     943  if (EFI_ERROR (Status)) {
     944    Status = EFI_DEVICE_ERROR;
     945    goto ON_EXIT;
     946  }
     947
     948  Status = FindUsbDescriptor (This, USB_DESC_TYPE_INTERFACE, AlternateSetting, 0, &Data);
     949  if (EFI_ERROR (Status)) {
     950    goto ON_EXIT;
     951  }
     952
     953  *CsInterfacesNumber = FindNumberOfCsInterfaces (Data);
     954  CopyMem (Descriptor, Data, sizeof (EFI_USB_INTERFACE_DESCRIPTOR));
     955
     956ON_EXIT:
     957  gBS->RestoreTPL (OldTpl);
     958  return Status;
     959}
     960
     961/**
     962  Retrieve the endpoint descriptor from the interface setting.
     963
     964  This is an extended version of UsbIo->GetEndpointDescriptor. It returns the endpoint
     965  descriptor for an alternate setting of a given interface.
     966  AlternateSetting parameter is the zero-based interface descriptor index that is used in USB
     967  interface descriptor as USB_INTERFACE_DESCRIPTOR.AlternateSetting.
     968
     969  Note: The total number of endpoints can be retrieved from the interface descriptor
     970  returned by EDKII_USBIO_EXT_GET_INTERFACE_DESCRIPTOR function.
     971
     972  @param[in]  This              A pointer to the EFI_USB_IO_PROTOCOL instance.
     973  @param[in]  AlternateSetting  Interface alternate setting.
     974  @param[in]  Index             Index of the endpoint to retrieve. The valid range is 0..15.
     975  @param[out]  Descriptor       A pointer to the caller allocated USB Interface Descriptor.
     976
     977  @retval EFI_SUCCESS           Output parameters were updated successfully.
     978  @retval EFI_INVALID_PARAMETER Descriptor is NULL.
     979  @retval EFI_UNSUPPORTED       AlternateSetting is greater than the number of alternate settings in this interface.
     980  @retval EFI_NOT_FOUND         Index is greater than the number of endpoints in this interface.
     981  @retval EFI_DEVICE_ERROR      Error reading device data.
     982
     983**/
     984EFI_STATUS
     985EFIAPI
     986UsbGetEndpointDescriptorSetting (
     987  IN  EFI_USB_IO_PROTOCOL          *This,
     988  IN  UINT16                       AlternateSetting,
     989  IN  UINTN                        Index,
     990  OUT EFI_USB_ENDPOINT_DESCRIPTOR  *Descriptor
     991  )
     992{
     993  EFI_STATUS  Status;
     994  VOID        *Data;
     995  EFI_TPL     OldTpl;
     996
     997  if (Descriptor == NULL) {
     998    return EFI_INVALID_PARAMETER;
     999  }
     1000
     1001  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
     1002
     1003  Status = InitUsbConfigDescriptorData (This);
     1004  if (EFI_ERROR (Status)) {
     1005    Status = EFI_DEVICE_ERROR;
     1006    goto ON_EXIT;
     1007  }
     1008
     1009  Status = FindUsbDescriptor (This, USB_DESC_TYPE_ENDPOINT, AlternateSetting, Index, &Data);
     1010  if (EFI_ERROR (Status)) {
     1011    goto ON_EXIT;
     1012  }
     1013
     1014  CopyMem (Descriptor, Data, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));
     1015
     1016ON_EXIT:
     1017  gBS->RestoreTPL (OldTpl);
     1018  return Status;
     1019}
     1020
     1021/**
     1022  Retrieve class specific interface descriptor.
     1023
     1024  AlternateSetting parameter is the zero-based interface descriptor index that is used in USB
     1025  interface descriptor as USB_INTERFACE_DESCRIPTOR.AlternateSetting.
     1026
     1027  @param[in]  This              A pointer to the EFI_USB_IO_PROTOCOL instance.
     1028  @param[in]  AlternateSetting  Interface alternate setting.
     1029  @param[in]  Index             Zero-based index of the class specific interface.
     1030  @param[in][out]  BufferSize   On input, the size in bytes of the return Descriptor buffer.
     1031                                On output the size of data returned in Descriptor.
     1032  @param[out]  Descriptor       The buffer to return the contents of the class specific interface descriptor. May
     1033                                be NULL with a zero BufferSize in order to determine the size buffer needed.
     1034
     1035  @retval EFI_SUCCESS           Output parameters were updated successfully.
     1036  @retval EFI_INVALID_PARAMETER BufferSize is NULL.
     1037                                Buffer is NULL and *BufferSize is not zero.
     1038  @retval EFI_UNSUPPORTED       AlternateSetting is greater than the number of alternate settings in this interface.
     1039  @retval EFI_NOT_FOUND         Index is greater than the number of class specific interfaces.
     1040  @retval EFI_BUFFER_TOO_SMALL  The BufferSize is too small for the result. BufferSize has been updated with the size
     1041                                needed to complete the request.
     1042  @retval EFI_DEVICE_ERROR      Error reading device data.
     1043
     1044**/
     1045EFI_STATUS
     1046EFIAPI
     1047UsbGetCsInterfaceDescriptor (
     1048  IN  EFI_USB_IO_PROTOCOL  *This,
     1049  IN  UINT16               AlternateSetting,
     1050  IN  UINTN                Index,
     1051  IN OUT UINTN             *BufferSize,
     1052  OUT VOID                 *Buffer
     1053  )
     1054{
     1055  EFI_STATUS  Status;
     1056  VOID        *Data;
     1057  UINT8       DescLength;
     1058  EFI_TPL     OldTpl;
     1059
     1060  if ((BufferSize == NULL) || ((Buffer == NULL) && (*BufferSize != 0))) {
     1061    return EFI_INVALID_PARAMETER;
     1062  }
     1063
     1064  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
     1065
     1066  Status = InitUsbConfigDescriptorData (This);
     1067  if (EFI_ERROR (Status)) {
     1068    Status = EFI_DEVICE_ERROR;
     1069    goto ON_EXIT;
     1070  }
     1071
     1072  Status = FindUsbDescriptor (This, USB_DESC_TYPE_CS_INTERFACE, AlternateSetting, Index, &Data);
     1073  if (EFI_ERROR (Status)) {
     1074    goto ON_EXIT;
     1075  }
     1076
     1077  DescLength = ((UINT8 *)Data)[0];
     1078
     1079  if ((Buffer == NULL) || (DescLength > *BufferSize)) {
     1080    *BufferSize = DescLength;
     1081    Status      = EFI_BUFFER_TOO_SMALL;
     1082    goto ON_EXIT;
     1083  }
     1084
     1085  CopyMem (Buffer, Data, DescLength);
     1086
     1087ON_EXIT:
     1088  gBS->RestoreTPL (OldTpl);
     1089  return Status;
     1090}
     1091
     1092/**
     1093  Retrieve class specific endpoint descriptor.
     1094
     1095  AlternateSetting parameter is the zero-based interface descriptor index that is used in USB
     1096  interface descriptor as USB_INTERFACE_DESCRIPTOR.AlternateSetting.
     1097
     1098  @param[in]  This              A pointer to the EFI_USB_IO_PROTOCOL instance.
     1099  @param[in]  AlternateSetting  Interface alternate setting.
     1100  @param[in]  Index             Zero-based index of the non-zero endpoint.
     1101  @param[in][out]  BufferSize   On input, the size in bytes of the return Descriptor buffer.
     1102                                On output the size of data returned in Descriptor.
     1103  @param[out]  Descriptor       The buffer to return the contents of the class specific endpoint descriptor. May
     1104                                be NULL with a zero BufferSize in order to determine the size buffer needed.
     1105
     1106  @retval EFI_SUCCESS           Output parameters were updated successfully.
     1107  @retval EFI_INVALID_PARAMETER BufferSize is NULL.
     1108                                Buffer is NULL and *BufferSize is not zero.
     1109  @retval EFI_UNSUPPORTED       AlternateSetting is greater than the number of alternate settings in this interface.
     1110  @retval EFI_NOT_FOUND         Index is greater than the number of endpoints in this interface.
     1111                                Endpoint does not have class specific endpoint descriptor.
     1112  @retval EFI_BUFFER_TOO_SMALL  The BufferSize is too small for the result. BufferSize has been updated with the size
     1113                                needed to complete the request.
     1114  @retval EFI_DEVICE_ERROR      Error reading device data.
     1115
     1116**/
     1117EFI_STATUS
     1118EFIAPI
     1119UsbGetCsEndpointDescriptor (
     1120  IN  EFI_USB_IO_PROTOCOL  *This,
     1121  IN  UINT16               AlternateSetting,
     1122  IN  UINTN                Index,
     1123  IN OUT UINTN             *BufferSize,
     1124  OUT VOID                 *Buffer
     1125  )
     1126{
     1127  EFI_STATUS  Status;
     1128  VOID        *Data;
     1129  UINT8       DescLength;
     1130  EFI_TPL     OldTpl;
     1131
     1132  if ((BufferSize == NULL) || ((Buffer == NULL) && (*BufferSize != 0))) {
     1133    return EFI_INVALID_PARAMETER;
     1134  }
     1135
     1136  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
     1137
     1138  Status = InitUsbConfigDescriptorData (This);
     1139  if (EFI_ERROR (Status)) {
     1140    Status = EFI_DEVICE_ERROR;
     1141    goto ON_EXIT;
     1142  }
     1143
     1144  Status = FindUsbDescriptor (This, USB_DESC_TYPE_CS_ENDPOINT, AlternateSetting, Index, &Data);
     1145  if (EFI_ERROR (Status)) {
     1146    goto ON_EXIT;
     1147  }
     1148
     1149  DescLength = ((UINT8 *)Data)[0];
     1150
     1151  if ((Buffer == NULL) || (DescLength > *BufferSize)) {
     1152    *BufferSize = DescLength;
     1153    Status      = EFI_BUFFER_TOO_SMALL;
     1154    goto ON_EXIT;
     1155  }
     1156
     1157  CopyMem (Buffer, Data, DescLength);
     1158
     1159ON_EXIT:
     1160  gBS->RestoreTPL (OldTpl);
     1161  return Status;
     1162}
     1163
     1164/**
     1165  Destructor frees memory which was allocated by the library functions.
     1166
     1167  @param ImageHandle       Handle that identifies the image to be unloaded.
     1168  @param  SystemTable      The system table.
     1169
     1170  @retval EFI_SUCCESS      The image has been unloaded.
     1171
     1172**/
     1173EFI_STATUS
     1174EFIAPI
     1175UefiUsbLibDestructor (
     1176  IN EFI_HANDLE        ImageHandle,
     1177  IN EFI_SYSTEM_TABLE  *SystemTable
     1178  )
     1179{
     1180  if (mConfigData != NULL) {
     1181    gBS->FreePool (mConfigData);
     1182  }
     1183
     1184  return EFI_SUCCESS;
     1185}
Note: See TracChangeset for help on using the changeset viewer.

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