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:
2 added
11 edited

Legend:

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

  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf

    r105670 r108794  
    2929
    3030[BuildOptions]
    31   MSFT:*_*_*_CC_FLAGS   == /c /EHs /Zi /Od /MT
     31  MSFT:*_*_*_CC_FLAGS   == /c /EHs /Zi /Od /MTd
    3232  GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m32 -malign-double -fno-pie
    3333  GCC:*_*_X64_CC_FLAGS  == -g -c -fshort-wchar -fexceptions -O0 -m64 -fno-pie "-DEFIAPI=__attribute__((ms_abi))"
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.c

    r99404 r108794  
    2828typedef struct {
    2929  UINT32    Signature;
    30   VOID      *AllocatedBufffer;
     30  VOID      *AllocatedBuffer;
    3131  UINTN     TotalPages;
    3232  VOID      *AlignedBuffer;
     
    3434} PAGE_HEAD;
    3535
     36#define POOL_HEAD_PRIVATE_SIGNATURE  SIGNATURE_32 ('P', 'O', 'H', 'D')
     37
     38typedef struct {
     39  UINT32    Signature;
     40  UINT32    TotalSize;
     41} POOL_HEAD;
     42
    3643/**
    3744  Allocates one or more 4KB pages of type EfiBootServicesData.
     
    166173  // We need reserve Alignment pages for PAGE_HEAD, as meta data.
    167174  //
    168   PageHead.Signature        = PAGE_HEAD_PRIVATE_SIGNATURE;
    169   PageHead.TotalPages       = Pages + EFI_SIZE_TO_PAGES (Alignment) * 2;
    170   PageHead.AlignedPages     = Pages;
    171   PageHead.AllocatedBufffer = malloc (EFI_PAGES_TO_SIZE (PageHead.TotalPages));
    172   if (PageHead.AllocatedBufffer == NULL) {
    173     return NULL;
    174   }
    175 
    176   PageHead.AlignedBuffer = (VOID *)(((UINTN)PageHead.AllocatedBufffer + AlignmentMask) & ~AlignmentMask);
    177   if ((UINTN)PageHead.AlignedBuffer - (UINTN)PageHead.AllocatedBufffer < sizeof (PAGE_HEAD)) {
     175  PageHead.Signature       = PAGE_HEAD_PRIVATE_SIGNATURE;
     176  PageHead.TotalPages      = Pages + EFI_SIZE_TO_PAGES (Alignment) * 2;
     177  PageHead.AlignedPages    = Pages;
     178  PageHead.AllocatedBuffer = malloc (EFI_PAGES_TO_SIZE (PageHead.TotalPages));
     179
     180  ASSERT (PageHead.AllocatedBuffer != NULL);
     181
     182  DEBUG_CLEAR_MEMORY (PageHead.AllocatedBuffer, EFI_PAGES_TO_SIZE (PageHead.TotalPages));
     183
     184  PageHead.AlignedBuffer = (VOID *)(((UINTN)PageHead.AllocatedBuffer + AlignmentMask) & ~AlignmentMask);
     185  if ((UINTN)PageHead.AlignedBuffer - (UINTN)PageHead.AllocatedBuffer < sizeof (PAGE_HEAD)) {
    178186    PageHead.AlignedBuffer = (VOID *)((UINTN)PageHead.AlignedBuffer + Alignment);
    179187  }
     
    266274{
    267275  PAGE_HEAD  *PageHeadPtr;
    268 
    269   //
    270   // NOTE: Partial free is not supported. Just keep it.
    271   //
    272   PageHeadPtr = (VOID *)((UINTN)Buffer - sizeof (PAGE_HEAD));
    273   if (PageHeadPtr->Signature != PAGE_HEAD_PRIVATE_SIGNATURE) {
    274     return;
    275   }
    276 
    277   if (PageHeadPtr->AlignedPages != Pages) {
    278     return;
    279   }
    280 
    281   PageHeadPtr->Signature = 0;
    282   free (PageHeadPtr->AllocatedBufffer);
     276  VOID       *AllocatedBuffer;
     277  UINTN      Length;
     278
     279  ASSERT (Buffer != NULL);
     280
     281  PageHeadPtr = ((PAGE_HEAD *)Buffer) - 1;
     282
     283  ASSERT (PageHeadPtr != NULL);
     284  ASSERT (PageHeadPtr->Signature == PAGE_HEAD_PRIVATE_SIGNATURE);
     285  ASSERT (PageHeadPtr->AlignedPages == Pages);
     286  ASSERT (PageHeadPtr->AllocatedBuffer != NULL);
     287
     288  AllocatedBuffer = PageHeadPtr->AllocatedBuffer;
     289  Length          = EFI_PAGES_TO_SIZE (PageHeadPtr->TotalPages);
     290
     291  DEBUG_CLEAR_MEMORY (AllocatedBuffer, Length);
     292
     293  free (AllocatedBuffer);
    283294}
    284295
     
    294305  @return  A pointer to the allocated buffer or NULL if allocation fails.
    295306
    296 **/VOID *
     307**/
     308VOID *
    297309EFIAPI
    298310AllocatePool (
     
    300312  )
    301313{
    302   return malloc (AllocationSize);
     314  POOL_HEAD  *PoolHead;
     315  UINTN      TotalSize;
     316
     317  TotalSize = sizeof (POOL_HEAD) + AllocationSize;
     318  PoolHead  = malloc (TotalSize);
     319  if (PoolHead == NULL) {
     320    return NULL;
     321  }
     322
     323  DEBUG_CLEAR_MEMORY (PoolHead, TotalSize);
     324  PoolHead->Signature = POOL_HEAD_PRIVATE_SIGNATURE;
     325  PoolHead->TotalSize = (UINT32)TotalSize;
     326
     327  return (VOID *)(PoolHead + 1);
    303328}
    304329
     
    366391  VOID  *Buffer;
    367392
    368   Buffer = malloc (AllocationSize);
     393  Buffer = AllocatePool (AllocationSize);
    369394  if (Buffer == NULL) {
    370395    return NULL;
     
    445470  VOID  *Memory;
    446471
    447   Memory = malloc (AllocationSize);
     472  Memory = AllocatePool (AllocationSize);
    448473  if (Memory == NULL) {
    449474    return NULL;
     
    539564  VOID  *NewBuffer;
    540565
    541   NewBuffer = malloc (NewSize);
     566  NewBuffer = AllocatePool (NewSize);
    542567  if ((NewBuffer != NULL) && (OldBuffer != NULL)) {
    543568    memcpy (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
     
    635660  )
    636661{
    637   free (Buffer);
    638 }
     662  POOL_HEAD  *PoolHead;
     663
     664  ASSERT (Buffer != NULL);
     665
     666  PoolHead = ((POOL_HEAD *)Buffer) - 1;
     667
     668  ASSERT (PoolHead != NULL);
     669  ASSERT (PoolHead->Signature == POOL_HEAD_PRIVATE_SIGNATURE);
     670  ASSERT (PoolHead->TotalSize >= sizeof (POOL_HEAD));
     671
     672  DEBUG_CLEAR_MEMORY (PoolHead, PoolHead->TotalSize);
     673  free (PoolHead);
     674}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf

    r85718 r108794  
    1717  VERSION_STRING  = 1.0
    1818  LIBRARY_CLASS   = MemoryAllocationLib|HOST_APPLICATION
     19  LIBRARY_CLASS   = HostMemoryAllocationBelowAddressLib|HOST_APPLICATION
    1920
    2021[Sources]
    2122  MemoryAllocationLibPosix.c
     23  AllocateBelowAddress.c
     24  WinInclude.h
    2225
    2326[Packages]
    2427  MdePkg/MdePkg.dec
     28  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
    2529
    2630[LibraryClasses]
    27   BaseLib
     31  DebugLib
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.cpp

    r105670 r108794  
    1818  #include <Library/BaseLib.h>
    1919  #include <Library/UnitTestLib.h>
     20
     21  //
     22  // If address sanitizer is enabled, then declare the function that is used to
     23  // handle custom long jump implementation.
     24  //
     25 #ifdef __SANITIZE_ADDRESS__
     26  void
     27  __asan_handle_no_return (
     28    );
     29
     30 #endif
    2031
    2132  ///
     
    4859    if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
    4960      UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, LineNumber, Description);
     61
     62      //
     63      // If address sanitizer is enabled, then inform sanitizer that a no return
     64      // function is being called that will reset to a previous stack frame.
     65      // This is required to avoid false positives from the address sanitizer
     66      // due to the use of a custom long jump implementation.
     67      //
     68 #ifdef __SANITIZE_ADDRESS__
     69      __asan_handle_no_return ();
     70 #endif
     71
    5072      LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1);
    5173    } else {
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf

    r105670 r108794  
    3232
    3333[BuildOptions]
    34   MSFT:*_*_*_CC_FLAGS   == /c /EHs /Zi /Od /MT
     34  MSFT:*_*_*_CC_FLAGS   == /c /EHs /Zi /Od /MTd
    3535  GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m32 -malign-double -fno-pie
    3636  GCC:*_*_X64_CC_FLAGS  == -g -c -fshort-wchar -fexceptions -O0 -m64 -fno-pie "-DEFIAPI=__attribute__((ms_abi))"
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c

    r105670 r108794  
    3434  AsciiStrCpyS (
    3535    &UnitTest->FailureMessage[0],
    36     UNIT_TEST_TESTFAILUREMSG_LENGTH,
     36    UNIT_TEST_MAX_STRING_LENGTH,
    3737    FailureMessage
    3838    );
     
    5151{
    5252  UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle;
    53   CHAR8                       LogString[UNIT_TEST_TESTFAILUREMSG_LENGTH];
     53  CHAR8                       LogString[UNIT_TEST_MAX_STRING_LENGTH];
    5454  VA_LIST                     Marker;
    5555
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c

    r99404 r108794  
    382382
    383383  if (UnitTestStatus == UNIT_TEST_PASSED) {
    384     UT_LOG_INFO (
    385       "[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expected assert\n",
     384    snprintf (
     385      TempStr,
     386      sizeof (TempStr),
     387      "[ASSERT PASS] %s:%d: UT_EXPECT_ASSERT_FAILURE(%s) detected expected assert\n",
    386388      FileName,
    387       LineNumber,
     389      (int)LineNumber,
    388390      FunctionCall
    389391      );
     392    UT_LOG_INFO (TempStr);
    390393  }
    391394
    392395  if (UnitTestStatus == UNIT_TEST_SKIPPED) {
    393     UT_LOG_WARNING (
    394       "[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n",
     396    snprintf (
     397      TempStr,
     398      sizeof (TempStr),
     399      "[ASSERT WARN] %s:%d: UT_EXPECT_ASSERT_FAILURE(%s) disabled\n",
    395400      FileName,
    396       LineNumber,
     401      (int)LineNumber,
    397402      FunctionCall
    398403      );
     404    UT_LOG_WARNING (TempStr);
    399405  }
    400406
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c

    r105670 r108794  
    1616#include <Library/PcdLib.h>
    1717
    18 #define UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH  (512)
    19 #define UNIT_TEST_MAX_LOG_BUFFER                SIZE_16KB
     18#define UNIT_TEST_MAX_LOG_BUFFER  SIZE_16KB
    2019
    2120struct _UNIT_TEST_LOG_PREFIX_STRING {
     
    8685             UNIT_TEST_MAX_LOG_BUFFER / sizeof (CHAR8),
    8786             String,
    88              UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH
     87             UNIT_TEST_MAX_STRING_LENGTH
    8988             );
    9089  if (EFI_ERROR (Status)) {
     
    161160{
    162161  UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle;
    163   CHAR8                       NewFormatString[UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH];
    164   CHAR8                       LogString[UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH];
     162  CHAR8                       NewFormatString[UNIT_TEST_MAX_STRING_LENGTH];
     163  CHAR8                       LogString[UNIT_TEST_MAX_STRING_LENGTH];
    165164  CONST CHAR8                 *LogTypePrefix;
    166165  VA_LIST                     Marker;
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c

    r105670 r108794  
    112112  //
    113113  if (UnitTest->Log != NULL) {
    114     print_message ("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description);
    115     print_message ("Log Output Start\n");
    116     print_message ("%s", UnitTest->Log);
    117     print_message ("Log Output End\n");
     114    //
     115    // UnitTest->Log can be a large buffer that is larger than what DEBUG()
     116    // can support. Use printf() directly.
     117    //
     118    printf ("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description);
     119    printf ("Log Output Start\n");
     120    printf (UnitTest->Log);
     121    printf ("Log Output End\n");
    118122  }
    119123
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c

    r105670 r108794  
    132132}
    133133
     134STATIC
     135VOID
     136FreeUnitTestTestEntry (
     137  IN UNIT_TEST_LIST_ENTRY  *TestEntry
     138  )
     139{
     140  if (TestEntry) {
     141    if (TestEntry->UT.Description) {
     142      FreePool (TestEntry->UT.Description);
     143    }
     144
     145    if (TestEntry->UT.Name) {
     146      FreePool (TestEntry->UT.Name);
     147    }
     148
     149    FreePool (TestEntry);
     150  }
     151}
     152
     153STATIC
     154EFI_STATUS
     155FreeUnitTestSuiteEntry (
     156  IN UNIT_TEST_SUITE_LIST_ENTRY  *SuiteEntry
     157  )
     158{
     159  UNIT_TEST_LIST_ENTRY  *TestCase;
     160  UNIT_TEST_LIST_ENTRY  *NextTestCase;
     161  LIST_ENTRY            *TestCaseList;
     162
     163  if (SuiteEntry) {
     164    TestCaseList = &(SuiteEntry->UTS.TestCaseList);
     165    TestCase     = (UNIT_TEST_LIST_ENTRY *)GetFirstNode (TestCaseList);
     166    while (&TestCase->Entry != TestCaseList) {
     167      NextTestCase = (UNIT_TEST_LIST_ENTRY *)GetNextNode (TestCaseList, &TestCase->Entry);
     168      RemoveEntryList (&TestCase->Entry);
     169      FreeUnitTestTestEntry (TestCase);
     170      TestCase = NextTestCase;
     171    }
     172
     173    if (SuiteEntry->UTS.Title) {
     174      FreePool (SuiteEntry->UTS.Title);
     175    }
     176
     177    if (SuiteEntry->UTS.Name) {
     178      FreePool (SuiteEntry->UTS.Name);
     179    }
     180
     181    FreePool (SuiteEntry);
     182  }
     183
     184  return EFI_SUCCESS;
     185}
     186
    134187/**
    135188  Cleanup a test framework.
     
    152205  )
    153206{
    154   // TODO: Finish this function.
    155   return EFI_SUCCESS;
    156 }
    157 
    158 STATIC
    159 EFI_STATUS
    160 FreeUnitTestSuiteEntry (
    161   IN UNIT_TEST_SUITE_LIST_ENTRY  *SuiteEntry
    162   )
    163 {
    164   // TODO: Finish this function.
    165   return EFI_SUCCESS;
    166 }
    167 
    168 STATIC
    169 EFI_STATUS
    170 FreeUnitTestTestEntry (
    171   IN UNIT_TEST_LIST_ENTRY  *TestEntry
    172   )
    173 {
    174   // TODO: Finish this function.
     207  UNIT_TEST_FRAMEWORK         *Framework;
     208  UNIT_TEST_SUITE_LIST_ENTRY  *Suite;
     209  UNIT_TEST_SUITE_LIST_ENTRY  *NextSuite;
     210
     211  Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle;
     212  if (Framework) {
     213    Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetFirstNode (&Framework->TestSuiteList);
     214    while ((LIST_ENTRY *)Suite != &Framework->TestSuiteList) {
     215      NextSuite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite);
     216      RemoveEntryList ((LIST_ENTRY *)Suite);
     217      FreeUnitTestSuiteEntry (Suite);
     218      Suite = NextSuite;
     219    }
     220
     221    if (Framework->Title) {
     222      FreePool (Framework->Title);
     223    }
     224
     225    if (Framework->ShortTitle) {
     226      FreePool (Framework->ShortTitle);
     227    }
     228
     229    if (Framework->VersionString) {
     230      FreePool (Framework->VersionString);
     231    }
     232
     233    FreePool (Framework);
     234  }
     235
    175236  return EFI_SUCCESS;
    176237}
     
    572633    AsciiStrnCpyS (
    573634      &Test->FailureMessage[0],
    574       UNIT_TEST_TESTFAILUREMSG_LENGTH,
     635      UNIT_TEST_MAX_STRING_LENGTH,
    575636      &MatchingTest->FailureMessage[0],
    576       UNIT_TEST_TESTFAILUREMSG_LENGTH
     637      UNIT_TEST_MAX_STRING_LENGTH
    577638      );
    578639
     
    749810      TestSaveData->Result      = UnitTest->Result;
    750811      TestSaveData->FailureType = UnitTest->FailureType;
    751       AsciiStrnCpyS (&TestSaveData->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);
     812      AsciiStrnCpyS (&TestSaveData->FailureMessage[0], UNIT_TEST_MAX_STRING_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_MAX_STRING_LENGTH);
    752813
    753814      //
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