Changeset 68472 in vbox for trunk/src/VBox/GuestHost/OpenGL/util
- Timestamp:
- Aug 18, 2017 3:31:04 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
r68458 r68472 39 39 #include <iprt/thread.h> 40 40 41 #if 1 /** @todo Try use the Vbgl interface instead of talking directly to the driver? */ 42 # include <VBox/VBoxGuest.h> 43 #else 44 # include <VBox/VBoxGuestLib.h> 45 #endif 41 #include <VBox/VBoxGuestLib.h> 46 42 #include <VBox/HostServices/VBoxCrOpenGLSvc.h> 47 43 … … 180 176 CRNetCloseFuncList *close_list; 181 177 #ifdef RT_OS_WINDOWS 182 HANDLE hGuestDrv;183 178 LPDIRECTDRAW pDirectDraw; 184 #else185 int iGuestDrv;186 179 #endif 187 180 #ifdef IN_GUEST … … 588 581 * @param cbData Data size 589 582 */ 590 /** @todo use vbglR3DoIOCtl here instead */ 591 static int crVBoxHGCMCall(CRConnection *conn, void *pvData, unsigned cbData) 583 static int crVBoxHGCMCall(CRConnection *conn, VBoxGuestHGCMCallInfo *pData, unsigned cbData) 592 584 { 593 585 #ifdef IN_GUEST … … 595 587 RT_NOREF(conn); 596 588 # else 589 int rc; 597 590 PCRVBOXHGSMI_CLIENT pClient = g_crvboxhgcm.bHgsmiOn ? _crVBoxHGSMIClientGet(conn) : NULL; 598 591 if (pClient) 599 { 600 return VBoxCrHgsmiCtlConCall(pClient->pHgsmi, (struct VBoxGuestHGCMCallInfo *)pvData, cbData); 601 } 592 rc = VBoxCrHgsmiCtlConCall(pClient->pHgsmi, pData, cbData); 602 593 else 603 594 # endif 604 { 605 # ifdef RT_OS_WINDOWS 606 DWORD cbReturned, lerr; 607 608 if (DeviceIoControl (g_crvboxhgcm.hGuestDrv, 609 VBOXGUEST_IOCTL_HGCM_CALL(cbData), 610 pvData, cbData, 611 pvData, cbData, 612 &cbReturned, 613 NULL)) 614 { 615 return VINF_SUCCESS; 616 } 617 lerr=GetLastError(); 618 crDebug("vboxCall failed with %x\n", lerr); 619 /*On windows if we exceed max buffer len, we only get ERROR_GEN_FAILURE, and parms.hdr.result isn't changed. 620 *Before every call here we set it to VERR_WRONG_ORDER, so checking it here as well. 621 */ 622 if (ERROR_GEN_FAILURE==lerr && VERR_WRONG_ORDER==((VBoxGuestHGCMCallInfo*)pvData)->result) 623 { 624 return VERR_OUT_OF_RANGE; 625 } 626 else 627 { 628 return VERR_NOT_SUPPORTED; 629 } 630 # else 631 int rc; 632 # if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) 633 VBGLBIGREQ Hdr; 634 Hdr.u32Magic = VBGLBIGREQ_MAGIC; 635 Hdr.cbData = cbData; 636 Hdr.pvDataR3 = pvData; 637 # if HC_ARCH_BITS == 32 638 Hdr.u32Padding = 0; 639 # endif 640 rc = ioctl(g_crvboxhgcm.iGuestDrv, VBOXGUEST_IOCTL_HGCM_CALL(cbData), &Hdr); 641 # else 642 rc = ioctl(g_crvboxhgcm.iGuestDrv, VBOXGUEST_IOCTL_HGCM_CALL(cbData), pvData); 643 # endif 644 # ifdef RT_OS_LINUX 645 if (rc == 0) 646 # else 647 if (rc >= 0) 648 # endif 649 { 650 return VINF_SUCCESS; 651 } 652 # ifdef RT_OS_LINUX 653 if (rc >= 0) /* positive values are negated VBox error status codes. */ 654 { 655 crWarning("vboxCall failed with VBox status code %d\n", -rc); 656 if (rc==VINF_INTERRUPTED) 657 { 658 RTMSINTERVAL sl; 659 int i; 660 661 for (i=0, sl=50; i<6; i++, sl=sl*2) 595 { 596 rc = VbglR3HGCMCall(pData, cbData); 597 if (RT_SUCCESS(rc)) 598 { /* likely */ } 599 else 600 { 601 crWarning("vboxCall failed with VBox status code %Rrc\n", rc); 602 # if 1//ndef RT_OS_WINDOWS 603 if (rc == VERR_INTERRUPTED) 662 604 { 663 RTThreadSleep(sl); 664 rc = ioctl(g_crvboxhgcm.iGuestDrv, VBOXGUEST_IOCTL_HGCM_CALL(cbData), pvData); 665 if (rc==0) 605 /* Not sure why we're doing the sleep stuff here. The original coder didn't 606 bother to mention why he thought it necessary. :-( */ 607 RTMSINTERVAL msSleep; 608 int i; 609 for (i = 0, msSleep = 50; i < 6; i++, msSleep = msSleep * 2) 666 610 { 667 crWarning("vboxCall retry(%i) succeeded", i+1); 668 return VINF_SUCCESS; 669 } 670 else if (rc==VINF_INTERRUPTED) 671 { 672 continue; 673 } 674 else 675 { 676 crWarning("vboxCall retry(%i) failed with VBox status code %d", i+1, -rc); 677 break; 611 RTThreadSleep(msSleep); 612 rc = VbglR3HGCMCall(pData, cbData); 613 if (rc != VERR_INTERRUPTED) 614 { 615 if (RT_SUCCESS(rc)) 616 crWarning("vboxCall retry(%i) succeeded", i + 1); 617 else 618 crWarning("vboxCall retry(%i) failed with VBox status code %Rrc", i + 1, rc); 619 break; 620 } 678 621 } 679 622 } 680 }681 return -rc;682 }683 else684 623 # endif 685 crWarning("vboxCall failed with %x\n", errno); 686 return VERR_NOT_SUPPORTED; 687 # endif /*#ifdef RT_OS_WINDOWS*/ 688 } 624 } 625 } 626 return rc; 689 627 690 628 #else /* IN_GUEST */ 691 RT_NOREF(conn, p vData, cbData);629 RT_NOREF(conn, pData, cbData); 692 630 crError("crVBoxHGCMCall called on host side!"); 693 631 CRASSERT(FALSE); … … 766 704 parms.pBuffer.u.Pointer.u.linearAddr = (uintptr_t) buf; 767 705 768 rc = crVBoxHGCMCall(conn, &parms , sizeof(parms));706 rc = crVBoxHGCMCall(conn, &parms.hdr, sizeof(parms)); 769 707 callRes = parms.hdr.result; 770 708 } … … 780 718 parms.pBuffer.u.Pointer.u.linearAddr = (uintptr_t) buf; 781 719 782 rc = crVBoxHGCMCall(conn, &parms , sizeof(parms));720 rc = crVBoxHGCMCall(conn, &parms.hdr, sizeof(parms)); 783 721 callRes = parms.hdr.result; 784 722 } … … 819 757 parms.cbBuffer.u.value32 = 0; 820 758 821 rc = crVBoxHGCMCall(conn, &parms , sizeof(parms));759 rc = crVBoxHGCMCall(conn, &parms.hdr, sizeof(parms)); 822 760 823 761 if (RT_FAILURE(rc) || RT_FAILURE(parms.hdr.result)) … … 863 801 parms.cbWriteback.u.value32 = 0; 864 802 865 rc = crVBoxHGCMCall(conn, &parms , sizeof(parms));803 rc = crVBoxHGCMCall(conn, &parms.hdr, sizeof(parms)); 866 804 867 805 #if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS) … … 896 834 crDebug("SHCRGL_GUEST_FN_WRITE_BUFFER, offset=%u, size=%u", wbParms.ui32Offset.u.value32, wbParms.pBuffer.u.Pointer.size); 897 835 898 rc = crVBoxHGCMCall(conn, &wbParms , sizeof(wbParms));836 rc = crVBoxHGCMCall(conn, &wbParms.hdr, sizeof(wbParms)); 899 837 if (RT_FAILURE(rc) || RT_FAILURE(wbParms.hdr.result)) 900 838 { … … 918 856 crMemcpy(&wrbParms.cbWriteback, &parms.cbWriteback, sizeof(HGCMFunctionParameter)); 919 857 920 rc = crVBoxHGCMCall(conn, &wrbParms , sizeof(wrbParms));858 rc = crVBoxHGCMCall(conn, &wrbParms.hdr, sizeof(wrbParms)); 921 859 922 860 /*bit of hack to reuse code below*/ … … 1051 989 parms.cbBuffer.u.value32 = 0; 1052 990 1053 rc = crVBoxHGCMCall(conn, &parms , sizeof(parms));991 rc = crVBoxHGCMCall(conn, &parms.hdr, sizeof(parms)); 1054 992 1055 993 if (RT_FAILURE(rc) || RT_FAILURE(parms.hdr.result)) … … 1252 1190 parms.vMinor.u.value32 = CR_PROTOCOL_VERSION_MINOR; 1253 1191 1254 rc = crVBoxHGCMCall(conn, &parms , sizeof(parms));1192 rc = crVBoxHGCMCall(conn, &parms.hdr, sizeof(parms)); 1255 1193 1256 1194 if (RT_SUCCESS(rc)) … … 1284 1222 caps.Caps.u.value32 = 0; 1285 1223 1286 rc = crVBoxHGCMCall(conn, &caps , sizeof(caps));1224 rc = crVBoxHGCMCall(conn, &caps.hdr, sizeof(caps)); 1287 1225 1288 1226 if (RT_SUCCESS(rc)) … … 1316 1254 parms.u64PID.u.value64 = pid; 1317 1255 1318 rc = crVBoxHGCMCall(conn, &parms , sizeof(parms));1256 rc = crVBoxHGCMCall(conn, &parms.hdr, sizeof(parms)); 1319 1257 1320 1258 if (RT_FAILURE(rc) || RT_FAILURE(parms.hdr.result)) … … 1332 1270 * Servers go through crVBoxHGCMAccept; 1333 1271 */ 1334 /*@todo use vbglR3Something here */1335 1272 static int crVBoxHGCMDoConnect( CRConnection *conn ) 1336 1273 { 1337 1274 #ifdef IN_GUEST 1338 VBoxGuestHGCMConnectInfo info; 1339 1340 #ifdef RT_OS_WINDOWS 1341 DWORD cbReturned; 1342 1275 int rc; 1343 1276 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1344 1345 if (g_crvboxhgcm.hGuestDrv == INVALID_HANDLE_VALUE) 1346 { 1347 /* open VBox guest driver */ 1348 g_crvboxhgcm.hGuestDrv = CreateFile(VBOXGUEST_DEVICE_NAME, 1349 GENERIC_READ | GENERIC_WRITE, 1350 FILE_SHARE_READ | FILE_SHARE_WRITE, 1351 NULL, 1352 OPEN_EXISTING, 1353 FILE_ATTRIBUTE_NORMAL, 1354 NULL); 1355 1356 /* @todo check if we could rollback to softwareopengl */ 1357 if (g_crvboxhgcm.hGuestDrv == INVALID_HANDLE_VALUE) 1358 { 1359 crWarning("could not open VBox Guest Additions driver! rc = %d\n", GetLastError()); 1360 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1361 return FALSE; 1362 } 1363 } 1364 #else 1365 VBOXCRHGSMIPROFILE_FUNC_PROLOGUE(); 1366 if (g_crvboxhgcm.iGuestDrv == INVALID_HANDLE_VALUE) 1367 { 1368 g_crvboxhgcm.iGuestDrv = open(VBOXGUEST_USER_DEVICE_NAME, O_RDWR, 0); 1369 if (g_crvboxhgcm.iGuestDrv == INVALID_HANDLE_VALUE) 1370 { 1371 crDebug("could not open Guest Additions kernel module! rc = %d\n", errno); 1372 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1373 return FALSE; 1374 } 1375 } 1376 #endif 1377 1378 memset (&info, 0, sizeof (info)); 1379 info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing; 1380 strcpy (info.Loc.u.host.achName, "VBoxSharedCrOpenGL"); 1381 1382 #ifdef RT_OS_WINDOWS 1383 if (DeviceIoControl(g_crvboxhgcm.hGuestDrv, 1384 VBOXGUEST_IOCTL_HGCM_CONNECT, 1385 &info, sizeof (info), 1386 &info, sizeof (info), 1387 &cbReturned, 1388 NULL)) 1389 #elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) 1390 VBGLBIGREQ Hdr; 1391 Hdr.u32Magic = VBGLBIGREQ_MAGIC; 1392 Hdr.cbData = sizeof(info); 1393 Hdr.pvDataR3 = &info; 1394 # if HC_ARCH_BITS == 32 1395 Hdr.u32Padding = 0; 1396 # endif 1397 if (ioctl(g_crvboxhgcm.iGuestDrv, VBOXGUEST_IOCTL_HGCM_CONNECT, &Hdr) >= 0) 1398 #else 1399 if (ioctl(g_crvboxhgcm.iGuestDrv, VBOXGUEST_IOCTL_HGCM_CONNECT, &info, sizeof (info)) == 0) 1400 #endif 1401 { 1402 if (info.result == VINF_SUCCESS) 1403 { 1404 int rc; 1405 conn->u32ClientID = info.u32ClientID; 1277 rc = VbglR3InitUser(); 1278 if (RT_SUCCESS(rc)) 1279 { 1280 uint32_t idClient; 1281 rc = VbglR3HGCMConnect("VBoxSharedCrOpenGL", &idClient); 1282 if (RT_SUCCESS(rc)) 1283 { 1284 conn->u32ClientID = idClient; 1406 1285 crDebug("HGCM connect was successful: client id =0x%x\n", conn->u32ClientID); 1407 1286 … … 1419 1298 if (RT_FAILURE(rc)) 1420 1299 { 1421 WARN(("crVBoxHGCMSetPID failed % d", rc));1300 WARN(("crVBoxHGCMSetPID failed %Rrc", rc)); 1422 1301 return FALSE; 1423 1302 } … … 1428 1307 if (RT_FAILURE(rc)) 1429 1308 { 1430 WARN(("VBoxCrHgsmiCtlConGetHostCaps failed % d", rc));1309 WARN(("VBoxCrHgsmiCtlConGetHostCaps failed %Rrc", rc)); 1431 1310 g_crvboxhgcm.u32HostCaps = 0; 1432 1311 } … … 1434 1313 /* host may not support it, ignore any failures */ 1435 1314 g_crvboxhgcm.fHostCapsInitialized = true; 1436 rc = VINF_SUCCESS;1437 1315 } 1438 1316 … … 1445 1323 1446 1324 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1447 return RT_SUCCESS(rc); 1448 } 1449 crDebug("HGCM connect failed with rc=0x%x\n", info.result); 1450 1451 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1452 return FALSE; 1453 } 1454 #ifdef RT_OS_WINDOWS 1455 { 1456 DWORD winEr = GetLastError(); 1457 crDebug("IOCTL for HGCM connect failed with rc=0x%x\n", winEr); 1458 } 1459 #else 1460 crDebug("IOCTL for HGCM connect failed with rc=0x%x\n", errno); 1461 #endif 1325 return TRUE; 1326 } 1327 1328 crDebug("HGCM connect failed: %Rrc\n", rc); 1329 VbglR3Term(); 1330 } 1331 else 1332 crDebug("Failed to initialize VbglR3 library: %Rrc\n", rc); 1333 1462 1334 VBOXCRHGSMIPROFILE_FUNC_EPILOGUE(); 1463 1335 return FALSE; 1464 1336 1465 #else /*#ifdef IN_GUEST*/1337 #else /* !IN_GUEST */ 1466 1338 crError("crVBoxHGCMDoConnect called on host side!"); 1467 1339 CRASSERT(FALSE); 1468 1340 return FALSE; 1469 #endif 1341 #endif /* !IN_GUEST */ 1470 1342 } 1471 1343 … … 1507 1379 static void crVBoxHGCMDoDisconnect( CRConnection *conn ) 1508 1380 { 1509 #ifdef IN_GUEST1510 VBoxGuestHGCMDisconnectInfo info;1511 # ifdef RT_OS_WINDOWS1512 DWORD cbReturned;1513 # endif1514 #endif1515 1381 bool fHasActiveCons = false; 1516 1382 … … 1529 1395 if (conn->u32ClientID) 1530 1396 { 1531 memset (&info, 0, sizeof (info)); 1532 info.u32ClientID = conn->u32ClientID; 1533 1534 # ifdef RT_OS_WINDOWS 1535 if ( !DeviceIoControl(g_crvboxhgcm.hGuestDrv, 1536 VBOXGUEST_IOCTL_HGCM_DISCONNECT, 1537 &info, sizeof (info), 1538 &info, sizeof (info), 1539 &cbReturned, 1540 NULL) ) 1541 { 1542 crDebug("Disconnect failed with %x\n", GetLastError()); 1543 } 1544 # elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) 1545 VBGLBIGREQ Hdr; 1546 Hdr.u32Magic = VBGLBIGREQ_MAGIC; 1547 Hdr.cbData = sizeof(info); 1548 Hdr.pvDataR3 = &info; 1549 # if HC_ARCH_BITS == 32 1550 Hdr.u32Padding = 0; 1551 # endif 1552 if (ioctl(g_crvboxhgcm.iGuestDrv, VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Hdr) >= 0) 1553 # else 1554 if (ioctl(g_crvboxhgcm.iGuestDrv, VBOXGUEST_IOCTL_HGCM_DISCONNECT, &info, sizeof (info)) < 0) 1555 { 1556 crDebug("Disconnect failed with %x\n", errno); 1557 } 1558 # endif 1559 1397 int rc = VbglR3HGCMDisconnect(conn->u32ClientID); 1398 if (RT_FAILURE(rc)) 1399 crDebug("Disconnect failed with %Rrc\n", rc); 1560 1400 conn->u32ClientID = 0; 1561 } 1562 1563 /* close guest additions driver*/ 1564 if (!fHasActiveCons) 1565 { 1566 # ifdef RT_OS_WINDOWS 1567 CloseHandle(g_crvboxhgcm.hGuestDrv); 1568 g_crvboxhgcm.hGuestDrv = INVALID_HANDLE_VALUE; 1569 # else 1570 close(g_crvboxhgcm.iGuestDrv); 1571 g_crvboxhgcm.iGuestDrv = INVALID_HANDLE_VALUE; 1572 # endif 1401 1402 VbglR3Term(); 1573 1403 } 1574 1404 #endif /* IN_GUEST */ … … 2362 2192 2363 2193 #ifdef RT_OS_WINDOWS 2364 g_crvboxhgcm.hGuestDrv = INVALID_HANDLE_VALUE;2365 2194 g_crvboxhgcm.pDirectDraw = NULL; 2366 #else2367 g_crvboxhgcm.iGuestDrv = INVALID_HANDLE_VALUE;2368 2195 #endif 2369 2196
Note:
See TracChangeset
for help on using the changeset viewer.