VirtualBox

Ignore:
Timestamp:
Feb 9, 2012 3:37:11 PM (13 years ago)
Author:
vboxsync
Message:

VMM,VMMDev: Page sharing cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/VMMDev/VMMDev.cpp

    r39892 r40054  
    55
    66/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    687687}
    688688
     689#ifdef VBOX_WITH_PAGE_SHARING
     690
     691/**
     692 * Handles VMMDevReq_RegisterSharedModule.
     693 *
     694 * @returns VBox status code that the guest should see.
     695 * @param   pDevIns         The VMMDev device instance.
     696 * @param   pReq            Pointer to the request.
     697 */
     698static int vmmdevReqHandler_RegisterSharedModule(PPDMDEVINS pDevIns, VMMDevSharedModuleRegistrationRequest *pReq)
     699{
     700    /*
     701     * Basic input validation (more done by GMM).
     702     */
     703    AssertMsgReturn(pReq->header.size >= sizeof(VMMDevSharedModuleRegistrationRequest),
     704                    ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
     705    AssertMsgReturn(pReq->header.size == RT_UOFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[pReq->cRegions]),
     706                    ("%u cRegions=%u\n", pReq->header.size, pReq->cRegions), VERR_INVALID_PARAMETER);
     707
     708    AssertReturn(memchr(pReq->szName, '\0', sizeof(pReq->szName)), VERR_INVALID_PARAMETER);
     709    AssertReturn(memchr(pReq->szVersion, '\0', sizeof(pReq->szVersion)), VERR_INVALID_PARAMETER);
     710
     711    /*
     712     * Forward the request to the VMM.
     713     */
     714    return PGMR3SharedModuleRegister(PDMDevHlpGetVM(pDevIns), pReq->enmGuestOS, pReq->szName, pReq->szVersion,
     715                                     pReq->GCBaseAddr, pReq->cbModule, pReq->cRegions, pReq->aRegions);
     716}
     717
     718/**
     719 * Handles VMMDevReq_UnregisterSharedModule.
     720 *
     721 * @returns VBox status code that the guest should see.
     722 * @param   pDevIns         The VMMDev device instance.
     723 * @param   pReq            Pointer to the request.
     724 */
     725static int vmmdevReqHandler_UnregisterSharedModule(PPDMDEVINS pDevIns, VMMDevSharedModuleUnregistrationRequest *pReq)
     726{
     727    /*
     728     * Basic input validation.
     729     */
     730    AssertMsgReturn(pReq->header.size == sizeof(VMMDevSharedModuleUnregistrationRequest),
     731                    ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
     732
     733    AssertReturn(memchr(pReq->szName, '\0', sizeof(pReq->szName)), VERR_INVALID_PARAMETER);
     734    AssertReturn(memchr(pReq->szVersion, '\0', sizeof(pReq->szVersion)), VERR_INVALID_PARAMETER);
     735
     736    /*
     737     * Forward the request to the VMM.
     738     */
     739    return PGMR3SharedModuleUnregister(PDMDevHlpGetVM(pDevIns), pReq->szName, pReq->szVersion,
     740                                       pReq->GCBaseAddr, pReq->cbModule);
     741}
     742
     743/**
     744 * Handles VMMDevReq_CheckSharedModules.
     745 *
     746 * @returns VBox status code that the guest should see.
     747 * @param   pDevIns         The VMMDev device instance.
     748 * @param   pReq            Pointer to the request.
     749 */
     750static int vmmdevReqHandler_CheckSharedModules(PPDMDEVINS pDevIns, VMMDevSharedModuleCheckRequest *pReq)
     751{
     752    AssertMsgReturn(pReq->header.size == sizeof(VMMDevSharedModuleCheckRequest),
     753                    ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
     754    return PGMR3SharedModuleCheckAll(PDMDevHlpGetVM(pDevIns));
     755}
     756
     757/**
     758 * Handles VMMDevReq_GetPageSharingStatus.
     759 *
     760 * @returns VBox status code that the guest should see.
     761 * @param   pThis           The VMMDev instance data.
     762 * @param   pReq            Pointer to the request.
     763 */
     764static int vmmdevReqHandler_GetPageSharingStatus(VMMDevState *pThis, VMMDevPageSharingStatusRequest *pReq)
     765{
     766    AssertMsgReturn(pReq->header.size == sizeof(VMMDevPageSharingStatusRequest),
     767                    ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
     768
     769    pReq->fEnabled = false;
     770    int rc = pThis->pDrv->pfnIsPageFusionEnabled(pThis->pDrv, &pReq->fEnabled);
     771    if (RT_FAILURE(rc))
     772        pReq->fEnabled = false;
     773    return VINF_SUCCESS;
     774}
     775
     776
     777/**
     778 * Handles VMMDevReq_DebugIsPageShared.
     779 *
     780 * @returns VBox status code that the guest should see.
     781 * @param   pDevIns         The VMMDev device instance.
     782 * @param   pReq            Pointer to the request.
     783 */
     784static int vmmdevReqHandler_DebugIsPageShared(PPDMDEVINS pDevIns, VMMDevPageIsSharedRequest *pReq)
     785{
     786    AssertMsgReturn(pReq->header.size == sizeof(VMMDevPageIsSharedRequest),
     787                    ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
     788
     789#ifdef DEBUG
     790    return PGMR3SharedModuleGetPageState(PDMDevHlpGetVM(pDevIns), pReq->GCPtrPage, &pReq->fShared, &pReq->uPageFlags);
     791#else
     792    return VERR_NOT_IMPLEMENTED;
     793#endif
     794}
     795
     796#endif /* VBOX_WITH_PAGE_SHARING */
     797
    689798/**
    690799 * Port I/O Handler for the generic request interface
    691800 * @see FNIOMIOPORTOUT for details.
    692801 *
    693  * @todo Too long, suggest doing the request copying here and moving the
    694  *       switch into a different function (or better case -> functions), and
    695  *       looing the gotos.
     802 * @todo This function is too long!!  All new request SHALL be implemented as
     803 *       functions called from the switch!  When making changes, please move the
     804 *       relevant cases into functions.
    696805 */
    697806static DECLCALLBACK(int) vmmdevRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
     
    21622271#ifdef VBOX_WITH_PAGE_SHARING
    21632272        case VMMDevReq_RegisterSharedModule:
    2164         {
    2165             VMMDevSharedModuleRegistrationRequest *pReqModule = (VMMDevSharedModuleRegistrationRequest *)pRequestHeader;
    2166 
    2167             if (    pRequestHeader->size < sizeof(VMMDevSharedModuleRegistrationRequest)
    2168                 ||  pRequestHeader->size != RT_UOFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[pReqModule->cRegions]))
    2169             {
    2170                 pRequestHeader->rc = VERR_INVALID_PARAMETER;
    2171             }
    2172             else
    2173             {
    2174                 pRequestHeader->rc = PGMR3SharedModuleRegister(PDMDevHlpGetVM(pDevIns), pReqModule->enmGuestOS, pReqModule->szName, pReqModule->szVersion,
    2175                                                                pReqModule->GCBaseAddr, pReqModule->cbModule,
    2176                                                                pReqModule->cRegions, pReqModule->aRegions);
    2177             }
    2178             break;
    2179         }
     2273            pRequestHeader->rc = vmmdevReqHandler_RegisterSharedModule(pDevIns,
     2274                                     (VMMDevSharedModuleRegistrationRequest *)pRequestHeader);
     2275            break;
    21802276
    21812277        case VMMDevReq_UnregisterSharedModule:
    2182         {
    2183             VMMDevSharedModuleUnregistrationRequest *pReqModule = (VMMDevSharedModuleUnregistrationRequest *)pRequestHeader;
    2184 
    2185             if (pRequestHeader->size != sizeof(VMMDevSharedModuleUnregistrationRequest))
    2186             {
    2187                 pRequestHeader->rc = VERR_INVALID_PARAMETER;
    2188             }
    2189             else
    2190             {
    2191                 pRequestHeader->rc = PGMR3SharedModuleUnregister(PDMDevHlpGetVM(pDevIns), pReqModule->szName, pReqModule->szVersion,
    2192                                                                  pReqModule->GCBaseAddr, pReqModule->cbModule);
    2193             }
    2194             break;
    2195         }
     2278            pRequestHeader->rc = vmmdevReqHandler_UnregisterSharedModule(pDevIns,
     2279                                     (VMMDevSharedModuleUnregistrationRequest *)pRequestHeader);
     2280            break;
    21962281
    21972282        case VMMDevReq_CheckSharedModules:
    2198         {
    2199             VMMDevSharedModuleCheckRequest *pReqModule = (VMMDevSharedModuleCheckRequest *)pRequestHeader;
    2200 
    2201             if (pRequestHeader->size != sizeof(VMMDevSharedModuleCheckRequest))
    2202                 pRequestHeader->rc = VERR_INVALID_PARAMETER;
    2203             else
    2204                 pRequestHeader->rc = PGMR3SharedModuleCheckAll(PDMDevHlpGetVM(pDevIns));
    2205             break;
    2206         }
     2283            pRequestHeader->rc = vmmdevReqHandler_CheckSharedModules(pDevIns,
     2284                                     (VMMDevSharedModuleCheckRequest *)pRequestHeader);
     2285            break;
    22072286
    22082287        case VMMDevReq_GetPageSharingStatus:
    2209         {
    2210             VMMDevPageSharingStatusRequest *pReqStatus = (VMMDevPageSharingStatusRequest *)pRequestHeader;
    2211 
    2212             if (pRequestHeader->size != sizeof(VMMDevPageSharingStatusRequest))
    2213             {
    2214                 pRequestHeader->rc = VERR_INVALID_PARAMETER;
    2215             }
    2216             else
    2217             {
    2218                 pReqStatus->fEnabled = false;
    2219                 pThis->pDrv->pfnIsPageFusionEnabled(pThis->pDrv, &pReqStatus->fEnabled);
    2220                 pRequestHeader->rc = VINF_SUCCESS;
    2221             }
    2222             break;
    2223         }
     2288            pRequestHeader->rc = vmmdevReqHandler_GetPageSharingStatus(pThis,
     2289                                     (VMMDevPageSharingStatusRequest *)pRequestHeader);
     2290            break;
    22242291
    22252292        case VMMDevReq_DebugIsPageShared:
    2226         {
    2227 # ifdef DEBUG
    2228             VMMDevPageIsSharedRequest *pReq = (VMMDevPageIsSharedRequest *)pRequestHeader;
    2229 
    2230             if (pRequestHeader->size != sizeof(VMMDevPageIsSharedRequest))
    2231             {
    2232                 pRequestHeader->rc = VERR_INVALID_PARAMETER;
    2233             }
    2234             else
    2235             {
    2236                 pRequestHeader->rc = PGMR3SharedModuleGetPageState(PDMDevHlpGetVM(pDevIns), pReq->GCPtrPage, &pReq->fShared, &pReq->uPageFlags);
    2237             }
    2238 # else
    2239             pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
    2240 # endif
    2241             break;
    2242         }
    2243 
    2244 #endif
     2293            pRequestHeader->rc = vmmdevReqHandler_DebugIsPageShared(pDevIns, (VMMDevPageIsSharedRequest *)pRequestHeader);
     2294            break;
     2295
     2296#endif /* VBOX_WITH_PAGE_SHARING */
    22452297
    22462298#ifdef DEBUG
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