VirtualBox

Changeset 52023 in vbox


Ignore:
Timestamp:
Jul 14, 2014 9:00:18 PM (11 years ago)
Author:
vboxsync
Message:

pdmifs.h,DrvBlock,DrvVD: Add methods to allocate and free I/O buffer memory to PDMIBLOCK and PDMIMEDIA. DrvVD decides how to allocate the memory based on the setup

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmifs.h

    r51836 r52023  
    11361136     */
    11371137    DECLR3CALLBACKMEMBER(int, pfnDiscard,(PPDMIBLOCK pInterface, PCRTRANGE paRanges, unsigned cRanges));
     1138
     1139    /**
     1140     * Allocate buffer memory which is suitable for I/O and might have special proerties for secure
     1141     * environments (non-pageable memory for sensitive data which should not end up on the disk).
     1142     *
     1143     * @returns VBox status code.
     1144     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1145     * @param   cb              Amount of memory to allocate.
     1146     * @param   ppvNew          Where to store the pointer to the buffer on success.
     1147     */
     1148    DECLR3CALLBACKMEMBER(int, pfnIoBufAlloc, (PPDMIBLOCK pInterface, size_t cb, void **ppvNew));
     1149
     1150    /**
     1151     * Free memory allocated with PDMIBLOCK::pfnIoBufAlloc().
     1152     *
     1153     * @returns VBox status code.
     1154     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1155     * @param   pv              Pointer to the memory to free.
     1156     * @param   cb              Amount of bytes given in PDMIBLOCK::pfnIoBufAlloc().
     1157     */
     1158    DECLR3CALLBACKMEMBER(int, pfnIoBufFree, (PPDMIBLOCK pInterface, void *pv, size_t cb));
     1159
    11381160} PDMIBLOCK;
    11391161/** PDMIBLOCK interface ID. */
    1140 #define PDMIBLOCK_IID                           "5e7123dd-8cdf-4a6e-97a5-ab0c68d7e850"
     1162#define PDMIBLOCK_IID                           "4e804e8e-3c01-4f20-98d9-a30ece8ec9f5"
    11411163
    11421164
     
    14941516    DECLR3CALLBACKMEMBER(int, pfnDiscard,(PPDMIMEDIA pInterface, PCRTRANGE paRanges, unsigned cRanges));
    14951517
     1518    /**
     1519     * Allocate buffer memory which is suitable for I/O and might have special proerties for secure
     1520     * environments (non-pageable memory for sensitive data which should not end up on the disk).
     1521     *
     1522     * @returns VBox status code.
     1523     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1524     * @param   cb              Amount of memory to allocate.
     1525     * @param   ppvNew          Where to store the pointer to the buffer on success.
     1526     */
     1527    DECLR3CALLBACKMEMBER(int, pfnIoBufAlloc, (PPDMIMEDIA pInterface, size_t cb, void **ppvNew));
     1528
     1529    /**
     1530     * Free memory allocated with PDMIMEDIA::pfnIoBufAlloc().
     1531     *
     1532     * @returns VBox status code.
     1533     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1534     * @param   pv              Pointer to the memory to free.
     1535     * @param   cb              Amount of bytes given in PDMIMEDIA::pfnIoBufAlloc().
     1536     */
     1537    DECLR3CALLBACKMEMBER(int, pfnIoBufFree, (PPDMIMEDIA pInterface, void *pv, size_t cb));
     1538
    14961539} PDMIMEDIA;
    14971540/** PDMIMEDIA interface ID. */
    1498 #define PDMIMEDIA_IID                           "ec385d21-7aa9-42ca-8cfb-e1388297fa52"
     1541#define PDMIMEDIA_IID                           "b4acf420-c9e3-4333-9ed5-e86f6b2d5f1a"
    14991542
    15001543
  • trunk/src/VBox/Devices/Storage/DrvBlock.cpp

    r47829 r52023  
    310310}
    311311
     312/** @copydoc PDMIBLOCK::pfnIoBufAlloc */
     313static DECLCALLBACK(int) drvblockIoBufAlloc(PPDMIBLOCK pInterface, size_t cb, void **ppvNew)
     314{
     315    PDRVBLOCK pThis = PDMIBLOCK_2_DRVBLOCK(pInterface);
     316
     317    return pThis->pDrvMedia->pfnIoBufAlloc(pThis->pDrvMedia, cb, ppvNew);
     318}
     319
     320/** @copydoc PDMIBLOCK::pfnIoBufFree */
     321static DECLCALLBACK(int) drvblockIoBufFree(PPDMIBLOCK pInterface, void *pv, size_t cb)
     322{
     323    PDRVBLOCK pThis = PDMIBLOCK_2_DRVBLOCK(pInterface);
     324
     325    return pThis->pDrvMedia->pfnIoBufFree(pThis->pDrvMedia, pv, cb);
     326}
     327
    312328/* -=-=-=-=- IBlockAsync -=-=-=-=- */
    313329
     
    873889    pThis->IBlock.pfnGetType                = drvblockGetType;
    874890    pThis->IBlock.pfnGetUuid                = drvblockGetUuid;
     891    pThis->IBlock.pfnIoBufAlloc             = drvblockIoBufAlloc;
     892    pThis->IBlock.pfnIoBufFree              = drvblockIoBufFree;
    875893
    876894    /* IBlockBios. */
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r51923 r52023  
    3737#include <iprt/pipe.h>
    3838#include <iprt/system.h>
     39#include <iprt/memsafer.h>
    3940
    4041#ifdef VBOX_WITH_INIP
     
    18571858}
    18581859
     1860/** @copydoc PDMIMEDIA::pfnIoBufAlloc */
     1861static DECLCALLBACK(int) drvvdIoBufAlloc(PPDMIMEDIA pInterface, size_t cb, void **ppvNew)
     1862{
     1863    LogFlowFunc(("\n"));
     1864    int rc = VINF_SUCCESS;
     1865    void *pvNew = NULL;
     1866    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     1867
     1868    /* Configured encryption requires locked down memory. */
     1869    if (pThis->pCfgCrypto)
     1870        pvNew = RTMemSaferAllocZ(cb);
     1871    else
     1872    {
     1873        cb = RT_ALIGN_Z(cb, _4K);
     1874        pvNew = RTMemPageAlloc(cb);
     1875    }
     1876
     1877    if (RT_LIKELY(pvNew))
     1878        *ppvNew = pvNew;
     1879    else
     1880        rc = VERR_NO_MEMORY;
     1881
     1882    LogFlowFunc(("returns %Rrc\n", rc));
     1883    return rc;
     1884}
     1885
     1886/** @copydoc PDMIMEDIA::pfnIoBufFree */
     1887static DECLCALLBACK(int) drvvdIoBufFree(PPDMIMEDIA pInterface, void *pv, size_t cb)
     1888{
     1889    LogFlowFunc(("\n"));
     1890    int rc = VINF_SUCCESS;
     1891    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     1892
     1893    if (pThis->pCfgCrypto)
     1894        RTMemSaferFree(pv, cb);
     1895    else
     1896    {
     1897        cb = RT_ALIGN_Z(cb, _4K);
     1898        RTMemPageFree(pv, cb);
     1899    }
     1900
     1901    LogFlowFunc(("returns %Rrc\n", rc));
     1902    return rc;
     1903}
     1904
     1905
    18591906/*******************************************************************************
    18601907*   Async Media interface methods                                              *
     
    23872434    pThis->IMedia.pfnGetUuid             = drvvdGetUuid;
    23882435    pThis->IMedia.pfnDiscard             = drvvdDiscard;
     2436    pThis->IMedia.pfnIoBufAlloc          = drvvdIoBufAlloc;
     2437    pThis->IMedia.pfnIoBufFree           = drvvdIoBufFree;
    23892438
    23902439    /* IMediaAsync */
Note: See TracChangeset for help on using the changeset viewer.

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