VirtualBox

Ignore:
Timestamp:
Apr 2, 2018 5:11:37 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
121646
Message:

DevVGA,VBoxC: Code cleanup in progress. bugref:9094

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp

    r71590 r71619  
    6666#include <iprt/string.h>
    6767
     68#include <VBox/AssertGuest.h>
    6869#include <VBox/err.h>
    6970#define LOG_GROUP LOG_GROUP_HGSMI
     
    491492 *
    492493 */
    493 static int hgsmiHostHeapLock (HGSMIINSTANCE *pIns)
    494 {
    495     int rc = RTCritSectEnter (&pIns->hostHeapCritSect);
     494static int hgsmiHostHeapLock(HGSMIINSTANCE *pIns)
     495{
     496    int rc = RTCritSectEnter(&pIns->hostHeapCritSect);
    496497    AssertRC (rc);
    497498    return rc;
    498499}
    499500
    500 static void hgsmiHostHeapUnlock (HGSMIINSTANCE *pIns)
    501 {
    502     int rc = RTCritSectLeave (&pIns->hostHeapCritSect);
     501static void hgsmiHostHeapUnlock(HGSMIINSTANCE *pIns)
     502{
     503    int rc = RTCritSectLeave(&pIns->hostHeapCritSect);
    503504    AssertRC (rc);
    504505}
     
    961962};
    962963
    963 int HGSMIHostHeapSetup(PHGSMIINSTANCE pIns,
    964                        HGSMIOFFSET    offHeap,
    965                        HGSMISIZE      cbHeap)
     964int HGSMIHostHeapSetup(PHGSMIINSTANCE pIns, HGSMIOFFSET RT_UNTRUSTED_GUEST offHeap, HGSMISIZE RT_UNTRUSTED_GUEST cbHeap)
    966965{
    967966    LogFlowFunc(("pIns %p, offHeap 0x%08X, cbHeap = 0x%08X\n", pIns, offHeap, cbHeap));
    968967
    969     int rc = VINF_SUCCESS;
    970 
     968    /*
     969     * Validate input.
     970     */
    971971    AssertPtrReturn(pIns, VERR_INVALID_PARAMETER);
    972972
    973     if (   offHeap >= pIns->area.cbArea
    974         || cbHeap > pIns->area.cbArea
    975         || offHeap > pIns->area.cbArea - cbHeap)
    976     {
    977         AssertLogRelMsgFailed(("offHeap 0x%08X, cbHeap = 0x%08X, pIns->area.cbArea 0x%08X\n",
    978                                offHeap, cbHeap, pIns->area.cbArea));
    979         rc = VERR_INVALID_PARAMETER;
    980     }
    981     else
    982     {
    983         rc = hgsmiHostHeapLock (pIns);
    984 
    985         if (RT_SUCCESS (rc))
    986         {
    987             if (pIns->hostHeap.cRefs)
    988             {
    989                 AssertLogRelMsgFailed(("HGSMI[%s]: host heap setup ignored. %d allocated.\n",
    990                                        pIns->pszName, pIns->hostHeap.cRefs));
    991                 /* It is possible to change the heap only if there is no pending allocations. */
    992                 rc = VERR_ACCESS_DENIED;
    993             }
    994             else
    995             {
    996                 rc = HGSMIAreaInitialize(&pIns->hostHeap.area, pIns->area.pu8Base + offHeap, cbHeap, offHeap);
    997                 if (RT_SUCCESS(rc))
    998                 {
    999                     rc = HGSMIMAInit(&pIns->hostHeap.u.ma, &pIns->hostHeap.area, NULL, 0, 0, &g_hgsmiEnv);
    1000                 }
    1001 
    1002                 if (RT_SUCCESS(rc))
    1003                 {
    1004                     pIns->hostHeap.u32HeapType = HGSMI_HEAP_TYPE_MA;
    1005                 }
    1006                 else
    1007                 {
    1008                     HGSMIAreaClear(&pIns->hostHeap.area);
    1009                 }
    1010             }
    1011 
    1012             hgsmiHostHeapUnlock (pIns);
    1013         }
    1014     }
     973    ASSERT_GUEST_LOGREL_MSG_RETURN(   offHeap <  pIns->area.cbArea
     974                                   && cbHeap  <= pIns->area.cbArea
     975                                   && offHeap <= pIns->area.cbArea - cbHeap,
     976                                   ("Heap: %#x LB %#x; Area: %#x LB %#x\n", offHeap, cbHeap, pIns->area.offBase, pIns->area.cbArea),
     977                                   VERR_INVALID_PARAMETER);
     978    RT_UNTRUSTED_VALIDATED_FENCE();
     979
     980
     981    /*
     982     * Lock the heap and do the job.
     983     */
     984    int rc = hgsmiHostHeapLock(pIns);
     985    AssertReturn(rc, rc);
     986
     987    /* It is possible to change the heap only if there is no pending allocations. */
     988    ASSERT_GUEST_LOGREL_MSG_STMT_RETURN(pIns->hostHeap.cRefs == 0,
     989                                        ("HGSMI[%s]: host heap setup ignored. %d allocated.\n", pIns->pszName, pIns->hostHeap.cRefs),
     990                                        hgsmiHostHeapUnlock(pIns),
     991                                        VERR_ACCESS_DENIED);
     992    rc = HGSMIAreaInitialize(&pIns->hostHeap.area, pIns->area.pu8Base + offHeap, cbHeap, offHeap);
     993    if (RT_SUCCESS(rc))
     994    {
     995        rc = HGSMIMAInit(&pIns->hostHeap.u.ma, &pIns->hostHeap.area, NULL, 0, 0, &g_hgsmiEnv);
     996        if (RT_SUCCESS(rc))
     997            pIns->hostHeap.u32HeapType = HGSMI_HEAP_TYPE_MA;
     998        else
     999            HGSMIAreaClear(&pIns->hostHeap.area);
     1000    }
     1001
     1002    hgsmiHostHeapUnlock(pIns);
    10151003
    10161004    LogFlowFunc(("rc = %Rrc\n", rc));
    1017 
    10181005    return rc;
    10191006}
     
    15211508
    15221509
     1510/**
     1511 * Checks if @a offBuffer is within the area of this instance.
     1512 *
     1513 * This is for use in input validations.
     1514 *
     1515 * @returns true / false.
     1516 * @param   pIns        The instance.
     1517 * @param   offBuffer   The buffer offset to check.
     1518 */
     1519bool HGSMIIsOffsetValid(PHGSMIINSTANCE pIns, HGSMIOFFSET offBuffer)
     1520{
     1521    return pIns
     1522        && offBuffer - pIns->area.offBase < pIns->area.cbArea;
     1523}
     1524
     1525
     1526/**
     1527 * Returns the area offset for use in logging and assertion messages.
     1528 */
     1529HGSMIOFFSET HGSMIGetAreaOffset(PHGSMIINSTANCE pIns)
     1530{
     1531    return pIns ? pIns->area.offBase : ~(HGSMIOFFSET)0;
     1532}
     1533
     1534
     1535/**
     1536 * Returns the area size for use in logging and assertion messages.
     1537 */
     1538HGSMIOFFSET HGSMIGetAreaSize(PHGSMIINSTANCE pIns)
     1539{
     1540    return pIns ? pIns->area.cbArea : 0;
     1541}
     1542
     1543
    15231544void *HGSMIContext (PHGSMIINSTANCE pIns)
    15241545{
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