VirtualBox

Changeset 87207 in vbox


Ignore:
Timestamp:
Jan 8, 2021 9:42:52 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142160
Message:

VUSBUrb.cpp: Try clean up some old old hack (r25945, ++). bugref:9899

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/VUSBUrb.cpp

    r84360 r87207  
    944944             */
    945945            uint8_t *pbData = (uint8_t *)(pExtra->pMsg + 1);
    946             if (&pExtra->pbCur[pUrb->cbData] > &pbData[pSetup->wLength])
     946            if ((uintptr_t)&pExtra->pbCur[pUrb->cbData] > (uintptr_t)&pbData[pSetup->wLength])
    947947            {
    948                 if (!pSetup->wLength) /* happens during iPhone detection with iTunes (correct?) */
     948                /* In the device -> host direction, the device never returns more data than
     949                   what was requested (wLength).  So, we can just cap cbData. */
     950                ssize_t const cbLeft = &pbData[pSetup->wLength] - pExtra->pbCur;
     951                if (pSetup->bmRequestType & VUSB_DIR_TO_HOST)
    949952                {
    950                     Log(("%s: vusbUrbSubmitCtrl: pSetup->wLength == 0!! (iPhone)\n", pUrb->pszDesc));
     953                    LogFlow(("%s: vusbUrbSubmitCtrl: Adjusting DATA request: %d -> %d\n", pUrb->pszDesc, pUrb->cbData, cbLeft));
     954                    pUrb->cbData = cbLeft >= 0 ? (uint32_t)cbLeft : 0;
     955                }
     956                /* In the host -> direction it's undefined what happens if the host provides
     957                   more data than what wLength inidicated.  However, in 2007, iPhone detection
     958                   via iTunes would issue wLength=0 but provide a data URB which we needed to
     959                   pass on to the device anyway, so we'll just quietly adjust wLength if it's
     960                   zero and get on with the work.
     961
     962                   What confuses me (bird) here, though, is that we've already sent the SETUP
     963                   URB to the device when we received it, and all we end up doing is an
     964                   unnecessary memcpy and completing the URB, but never actually sending the
     965                   data to the device.  So, I guess this stuff is still a little iffy.
     966
     967                   Note! We currently won't be doing any resizing, as we've disabled resizing
     968                         in general.
     969                   P.S.  We used to have a very strange (pUrb->cbData % pSetup->wLength) == 0
     970                         thing too that joined the pUrb->cbData adjusting above. */
     971                else if (   pSetup->wLength == 0
     972                         && pUrb->cbData <= pExtra->cbMax)
     973                {
     974                    Log(("%s: vusbUrbSubmitCtrl: pAdjusting wLength: %u -> %u (iPhone hack)\n",
     975                         pUrb->pszDesc, pSetup->wLength, pUrb->cbData));
    951976                    pSetup->wLength = pUrb->cbData;
    952                 }
    953 
    954                 /* Variable length data transfers */
    955                 if (    (pSetup->bmRequestType & VUSB_DIR_TO_HOST)
    956                     ||  pSetup->wLength == 0
    957                     ||  (pUrb->cbData % pSetup->wLength) == 0)  /* magic which need explaining... */
    958                 {
    959                     uint8_t *pbEnd = pbData + pSetup->wLength;
    960                     int cbLeft = pbEnd - pExtra->pbCur;
    961                     LogFlow(("%s: vusbUrbSubmitCtrl: Var DATA, pUrb->cbData %d -> %d\n", pUrb->pszDesc, pUrb->cbData, cbLeft));
    962                     pUrb->cbData = cbLeft;
     977                    Assert(cbLeft >= (ssize_t)pUrb->cbData);
    963978                }
    964979                else
    965980                {
    966                     Log(("%s: vusbUrbSubmitCtrl: Stall at data stage!!\n", pUrb->pszDesc));
     981                    Log(("%s: vusbUrbSubmitCtrl: Stall at data stage!! wLength=%u cbData=%d cbMax=%d cbLeft=%dz\n",
     982                         pUrb->pszDesc, pSetup->wLength, pUrb->cbData, pExtra->cbMax, cbLeft));
    967983                    vusbMsgStall(pUrb);
    968984                    break;
     
    9921008            {
    9931009                /* get data for sending when completed. */
     1010                AssertStmt((ssize_t)pUrb->cbData <= pExtra->cbMax - (pExtra->pbCur - pbData), /* paranoia: checked above */
     1011                           pUrb->cbData = pExtra->cbMax - (uint32_t)RT_MIN(pExtra->pbCur - pbData, pExtra->cbMax));
    9941012                memcpy(pExtra->pbCur, pUrb->abData, pUrb->cbData);
    9951013
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