VirtualBox

Changeset 91396 in vbox for trunk/src/VBox/Main/src-all


Ignore:
Timestamp:
Sep 27, 2021 1:40:35 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
147076
Message:

Main: Add IUefiVariableStore interface to manage the content of the UEFI variable store for secure boot support, bugref:9580

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/NvramStoreImpl.cpp

    r91346 r91396  
    2424#else
    2525# include "MachineImpl.h"
     26# include "AutoStateDep.h"
    2627#endif
     28#include "UefiVariableStoreImpl.h"
    2729
    2830#include "AutoCaller.h"
     
    9496#else
    9597    /** The Machine object owning this NVRAM store. */
    96     Machine * const         pParent;
     98    Machine * const                    pParent;
    9799    /** The peer NVRAM store object. */
    98     ComObjPtr<NvramStore>   pPeer;
     100    ComObjPtr<NvramStore>              pPeer;
     101    /** The UEFI variable store. */
     102    const ComObjPtr<UefiVariableStore> pUefiVarStore;
    99103#endif
    100104
     
    299303
    300304    return S_OK;
     305}
     306
     307
     308HRESULT NvramStore::getUefiVariableStore(ComPtr<IUefiVariableStore> &aUefiVarStore)
     309{
     310#ifndef VBOX_COM_INPROC
     311    /* the machine needs to be mutable */
     312    AutoMutableStateDependency adep(m->pParent);
     313    if (FAILED(adep.rc())) return adep.rc();
     314
     315    /* We need a write lock because of the lazy initialization. */
     316    AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
     317
     318    /* Check if we have to create the UEFI variabel store object */
     319    HRESULT hrc = S_OK;
     320    if (!m->pUefiVarStore)
     321    {
     322        /* Load the NVRAM file first if it isn't already. */
     323        if (!m->bd->mapNvram.size())
     324        {
     325            int vrc = i_loadStore();
     326            if (RT_FAILURE(vrc))
     327                hrc = setError(E_FAIL, tr("Loading the NVRAM store failed (%Rrc)\n"), vrc);
     328        }
     329
     330        if (SUCCEEDED(hrc))
     331        {
     332            NvramStoreIter it = m->bd->mapNvram.find("efi/nvram");
     333            if (it != m->bd->mapNvram.end())
     334            {
     335                RTVFSFILE hVfsFileNvram = it->second;
     336                RTVFS hVfsEfiVarStore;
     337                int vrc = RTEfiVarStoreOpenAsVfs(hVfsFileNvram, 0 /*fMntFlags*/, 0 /*fVarStoreFlags*/, &hVfsEfiVarStore,
     338                                                 NULL /*pErrInfo*/);
     339                if (RT_SUCCESS(vrc))
     340                {
     341                    unconst(m->pUefiVarStore).createObject();
     342                    m->pUefiVarStore->init(this, m->pParent, hVfsEfiVarStore);
     343                }
     344                else
     345                    hrc = setError(E_FAIL, tr("Opening the UEFI variable store failed (%Rrc)."), vrc);
     346            }
     347            else
     348                hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The UEFI NVRAM file is not existing for this machine."));
     349        }
     350    }
     351
     352    if (SUCCEEDED(hrc))
     353        m->pUefiVarStore.queryInterfaceTo(aUefiVarStore.asOutParam());
     354
     355    return hrc;
     356#else
     357    NOREF(aUefiVarStore);
     358    return E_NOTIMPL;
     359#endif
     360}
     361
     362
     363HRESULT NvramStore::initUefiVariableStore(ULONG aSize)
     364{
     365    NOREF(aSize);
     366    return E_NOTIMPL;
    301367}
    302368
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