Changeset 71619 in vbox for trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp
- Timestamp:
- Apr 2, 2018 5:11:37 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 121646
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp
r71590 r71619 66 66 #include <iprt/string.h> 67 67 68 #include <VBox/AssertGuest.h> 68 69 #include <VBox/err.h> 69 70 #define LOG_GROUP LOG_GROUP_HGSMI … … 491 492 * 492 493 */ 493 static int hgsmiHostHeapLock 494 { 495 int rc = RTCritSectEnter 494 static int hgsmiHostHeapLock(HGSMIINSTANCE *pIns) 495 { 496 int rc = RTCritSectEnter(&pIns->hostHeapCritSect); 496 497 AssertRC (rc); 497 498 return rc; 498 499 } 499 500 500 static void hgsmiHostHeapUnlock 501 { 502 int rc = RTCritSectLeave 501 static void hgsmiHostHeapUnlock(HGSMIINSTANCE *pIns) 502 { 503 int rc = RTCritSectLeave(&pIns->hostHeapCritSect); 503 504 AssertRC (rc); 504 505 } … … 961 962 }; 962 963 963 int HGSMIHostHeapSetup(PHGSMIINSTANCE pIns, 964 HGSMIOFFSET offHeap, 965 HGSMISIZE cbHeap) 964 int HGSMIHostHeapSetup(PHGSMIINSTANCE pIns, HGSMIOFFSET RT_UNTRUSTED_GUEST offHeap, HGSMISIZE RT_UNTRUSTED_GUEST cbHeap) 966 965 { 967 966 LogFlowFunc(("pIns %p, offHeap 0x%08X, cbHeap = 0x%08X\n", pIns, offHeap, cbHeap)); 968 967 969 int rc = VINF_SUCCESS; 970 968 /* 969 * Validate input. 970 */ 971 971 AssertPtrReturn(pIns, VERR_INVALID_PARAMETER); 972 972 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); 1015 1003 1016 1004 LogFlowFunc(("rc = %Rrc\n", rc)); 1017 1018 1005 return rc; 1019 1006 } … … 1521 1508 1522 1509 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 */ 1519 bool 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 */ 1529 HGSMIOFFSET 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 */ 1538 HGSMIOFFSET HGSMIGetAreaSize(PHGSMIINSTANCE pIns) 1539 { 1540 return pIns ? pIns->area.cbArea : 0; 1541 } 1542 1543 1523 1544 void *HGSMIContext (PHGSMIINSTANCE pIns) 1524 1545 {
Note:
See TracChangeset
for help on using the changeset viewer.