VirtualBox

Changeset 81063 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
Sep 27, 2019 9:54:24 PM (6 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,

File:
1 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;
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