VirtualBox

Changeset 81063 in vbox


Ignore:
Timestamp:
Sep 27, 2019 9:54:24 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133667
Message:

iprt/win: Fixed method for determining firmware type on win 8.0 and earlier,

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/RTSystemFirmware-win.cpp

    r81062 r81063  
    6767/** Defines the UEFI Globals UUID. */
    6868#define VBOX_UEFI_UUID_GLOBALS L"{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}"
    69 /** Defines an UEFI dummy UUID. */
     69/** Defines an UEFI dummy UUID, see MSDN docs of the API. */
    7070#define VBOX_UEFI_UUID_DUMMY   L"{00000000-0000-0000-0000-000000000000}"
    7171
     
    158158        rtSystemFirmwareGetPrivileges(SE_SYSTEM_ENVIRONMENT_NAME);
    159159
    160         uint8_t fEnabled = 0; /** @todo This type doesn't make sense to bird. */
    161         DWORD cbRet = g_pfnGetFirmwareEnvironmentVariableW(L"", VBOX_UEFI_UUID_GLOBALS, &fEnabled, sizeof(fEnabled));
    162         if (cbRet)
    163         {
    164             Assert(cbRet == sizeof(fEnabled));
    165             *penmFirmwareType = fEnabled ? RTSYSFWTYPE_UEFI : RTSYSFWTYPE_BIOS;
    166             rc = VINF_SUCCESS;
    167         }
    168         else
    169         {
    170             DWORD dwErr = GetLastError();
    171             if (dwErr == ERROR_INVALID_FUNCTION)
    172             {
    173                 *penmFirmwareType = RTSYSFWTYPE_BIOS;
    174                 rc = VINF_SUCCESS;
    175             }
    176             else
    177                 rc = RTErrConvertFromWin32(dwErr);
    178         }
     160        /* On a non-UEFI system (or such a system in legacy boot mode), we will get
     161           back ERROR_INVALID_FUNCTION when querying any firmware variable.  While on a
     162           UEFI system we'll typically get ERROR_ACCESS_DENIED or similar as the dummy
     163           is a non-exising dummy namespace.  See the API docs. */
     164        SetLastError(0);
     165        uint8_t abWhatever[64];
     166        DWORD cbRet = g_pfnGetFirmwareEnvironmentVariableW(L"", VBOX_UEFI_UUID_DUMMY, abWhatever, sizeof(abWhatever));
     167        DWORD dwErr = GetLastError();
     168        *penmFirmwareType = cbRet != 0 || dwErr != ERROR_INVALID_FUNCTION ? RTSYSFWTYPE_UEFI : RTSYSFWTYPE_BIOS;
     169        rc = VINF_SUCCESS;
    179170    }
    180171    return rc;
     
    199190    {
    200191        case RTSYSFWPROP_SECURE_BOOT:
    201         {
    202192            pwszName = L"SecureBoot";
    203193            pValue->enmType = RTSYSFWVALUETYPE_BOOLEAN;
    204194            break;
    205         }
    206195
    207196        default:
     
    210199    }
    211200
     201    /*
     202     * Do type specific query.
     203     */
    212204    if (!g_pfnGetFirmwareEnvironmentVariableW)
    213205        return VERR_NOT_SUPPORTED;
  • trunk/src/VBox/Runtime/testcase/tstRTSystemQueryFirmware.cpp

    r81062 r81063  
    4545    RTTestBanner(hTest);
    4646
     47    /*
     48     * RTSystemFirmwareQueryType
     49     */
    4750    RTTestSub(hTest, "RTSystemFirmwareQueryType");
    48     RTSYSFWTYPE fwType;
    49     int rc = RTSystemFirmwareQueryType(&fwType);
     51    RTSYSFWTYPE enmType = (RTSYSFWTYPE)-42;
     52    int rc = RTSystemFirmwareQueryType(&enmType);
    5053    if (RT_SUCCESS(rc))
    5154    {
    52         switch (fwType)
     55        switch (enmType)
    5356        {
    5457            case RTSYSFWTYPE_BIOS:
    55                 RTTestPrintf(hTest, RTTESTLVL_INFO, "Firmware type: BIOS (Legacy)\n");
     58                RTTestPrintf(hTest, RTTESTLVL_INFO, "  Firmware type: BIOS (Legacy)\n");
    5659                break;
    5760            case RTSYSFWTYPE_UEFI:
    58                 RTTestPrintf(hTest, RTTESTLVL_INFO, "Firmware type: UEFI\n");
     61                RTTestPrintf(hTest, RTTESTLVL_INFO, "  Firmware type: UEFI\n");
    5962                break;
    6063            case RTSYSFWTYPE_UNKNOWN: /* Do not fail on not-implemented platforms. */
    61                 RT_FALL_THROUGH();
     64                RTTestPrintf(hTest, RTTESTLVL_INFO, "  Firmware type: Unknown\n");
     65                break;
    6266            default:
    63                 RTTestPrintf(hTest, RTTESTLVL_INFO, "Unknown firmware type\n");
     67                RTTestFailed(hTest, "RTSystemFirmwareQueryType return invalid type: %d (%#x)", enmType);
    6468                break;
    6569        }
    6670    }
    6771    else if (rc != VERR_NOT_SUPPORTED)
    68         RTTestIFailed("RTSystemFirmwareQueryType failed: %Rrc", rc);
     72        RTTestFailed(hTest, "RTSystemFirmwareQueryType failed: %Rrc", rc);
    6973
     74    /*
     75     * RTSystemFirmwareQueryValue
     76     */
    7077    RTTestSub(hTest, "RTSystemFirmwareQueryValue");
    7178    RTSYSFWVALUE Value;
     
    7481    {
    7582        RTTEST_CHECK(hTest, Value.enmType == RTSYSFWVALUETYPE_BOOLEAN);
    76         RTTestPrintf(hTest, RTTESTLVL_INFO, "Secure Boot enabled: %RTbool\n", Value.u.fVal);
     83        RTTestPrintf(hTest, RTTESTLVL_INFO, "  Secure Boot:   %s\n", Value.u.fVal ? "enabled" : "disabled");
     84        RTSystemFirmwareFreeValue(&Value);
    7785        RTSystemFirmwareFreeValue(&Value);
    7886    }
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