Changeset 4818 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Sep 15, 2007 10:04:05 AM (17 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
r4817 r4818 466 466 * Buffered or unbuffered? 467 467 */ 468 PSUPREQHDR pHdr; 469 user_addr_t pUser = 0; 468 470 void *pvPageBuf = NULL; 469 PSUPREQHDR pHdr; 470 uint32_t cb = IOCPARM_LEN(iCmd); 471 if (cb) 471 uint32_t cbReq = IOCPARM_LEN(iCmd); 472 if ((IOC_DIRMASK & iCmd) == IOC_INOUT) 472 473 { 473 474 pHdr = (PSUPREQHDR)pData; 474 if (RT_UNLIKELY(cb < sizeof(*pHdr)))475 { 476 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: cb =%#x < %#x; iCmd=%#lx\n", cb, (int)sizeof(*pHdr), iCmd));475 if (RT_UNLIKELY(cbReq < sizeof(*pHdr))) 476 { 477 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: cbReq=%#x < %#x; iCmd=%#lx\n", cbReq, (int)sizeof(*pHdr), iCmd)); 477 478 return EINVAL; 478 479 } … … 482 483 return EINVAL; 483 484 } 484 if (RT_UNLIKELY(RT_MAX(pHdr->cbIn, pHdr->cbOut) != cb)) 485 { 486 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: max(%#x,%#x) != %#x; iCmd=%#lx\n", pHdr->cbIn, pHdr->cbOut, cb, iCmd)); 485 if (RT_UNLIKELY( RT_MAX(pHdr->cbIn, pHdr->cbOut) != cbReq 486 || pHdr->cbIn < sizeof(*pHdr) 487 || pHdr->cbOut < sizeof(*pHdr))) 488 { 489 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: max(%#x,%#x) != %#x; iCmd=%#lx\n", pHdr->cbIn, pHdr->cbOut, cbReq, iCmd)); 487 490 return EINVAL; 488 491 } 489 492 } 490 else 493 else if ((IOC_DIRMASK & iCmd) == IOC_VOID && !cbReq) 491 494 { 492 495 /* … … 494 497 */ 495 498 SUPREQHDR Hdr; 496 int rc = copyin((const user_addr_t)pData, &Hdr, sizeof(Hdr)); 499 pUser = (user_addr_t)*(void **)pData; 500 int rc = copyin(pUser, &Hdr, sizeof(Hdr)); 497 501 if (RT_UNLIKELY(rc)) 498 502 { 499 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyin(%l x,Hdr,) -> %#x; iCmd=%#lx\n", pData, rc, iCmd));503 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyin(%llx,Hdr,) -> %#x; iCmd=%#lx\n", (unsigned long long)pUser, rc, iCmd)); 500 504 return rc; 501 505 } … … 505 509 return EINVAL; 506 510 } 507 cb = RT_MAX(Hdr.cbIn, Hdr.cbOut); 508 if (RT_UNLIKELY(cb < sizeof(Hdr) || cb > _1M*16)) 511 cbReq = RT_MAX(Hdr.cbIn, Hdr.cbOut); 512 if (RT_UNLIKELY( Hdr.cbIn < sizeof(Hdr) 513 || Hdr.cbOut < sizeof(Hdr) 514 || cbReq > _1M*16)) 509 515 { 510 516 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: max(%#x,%#x); iCmd=%#lx\n", Hdr.cbIn, Hdr.cbOut, iCmd)); … … 515 521 * Allocate buffer and copy in the data. 516 522 */ 517 pHdr = (PSUPREQHDR)RTMemTmpAlloc(cb );523 pHdr = (PSUPREQHDR)RTMemTmpAlloc(cbReq); 518 524 if (!pHdr) 519 pvPageBuf = pHdr = (PSUPREQHDR)IOMallocAligned(RT_ALIGN_Z(cb , PAGE_SIZE), 8);525 pvPageBuf = pHdr = (PSUPREQHDR)IOMallocAligned(RT_ALIGN_Z(cbReq, PAGE_SIZE), 8); 520 526 if (RT_UNLIKELY(!pHdr)) 521 527 { 522 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: failed to allocate buffer of %d bytes; iCmd=%#lx\n", cb , iCmd));528 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: failed to allocate buffer of %d bytes; iCmd=%#lx\n", cbReq, iCmd)); 523 529 return ENOMEM; 524 530 } 525 rc = copyin( (const user_addr_t)pData, pHdr, Hdr.cbIn);531 rc = copyin(pUser, pHdr, Hdr.cbIn); 526 532 if (RT_UNLIKELY(rc)) 527 533 { 528 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyin(%lx,,%#x) -> %#x; iCmd=%#lx\n", pData, Hdr.cbIn, rc, iCmd)); 534 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyin(%llx,%p,%#x) -> %#x; iCmd=%#lx\n", 535 (unsigned long long)pUser, pHdr, Hdr.cbIn, rc, iCmd)); 529 536 if (pvPageBuf) 530 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cb , PAGE_SIZE));537 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE)); 531 538 else 532 539 RTMemTmpFree(pHdr); … … 534 541 } 535 542 } 543 else 544 { 545 dprintf(("VBoxDrvDarwinIOCtlSlow: huh? cbReq=%#x iCmd=%#lx\n", cbReq, iCmd)); 546 return EINVAL; 547 } 536 548 537 549 /* … … 544 556 * If not buffered, copy back the buffer before returning. 545 557 */ 546 if ( !IOCPARM_LEN(iCmd))558 if (pUser) 547 559 { 548 560 uint32_t cbOut = pHdr->cbOut; 549 if (cbOut > cb )561 if (cbOut > cbReq) 550 562 { 551 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cb , iCmd));552 cbOut = cb ;563 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, iCmd)); 564 cbOut = cbReq; 553 565 } 554 rc = copyout(pHdr, (user_addr_t)pData, cbOut);566 rc = copyout(pHdr, pUser, cbOut); 555 567 if (RT_UNLIKELY(rc)) 556 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyout(,%p,%#x) -> %d; uCmd=%#lx!\n", pData, cbOut, rc, iCmd)); 568 OSDBGPRINT(("VBoxDrvDarwinIOCtlSlow: copyout(%p,%llx,%#x) -> %d; uCmd=%#lx!\n", 569 pHdr, (unsigned long long)pUser, cbOut, rc, iCmd)); 557 570 558 571 /* cleanup */ 559 572 if (pvPageBuf) 560 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cb , PAGE_SIZE));573 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE)); 561 574 else 562 575 RTMemTmpFree(pHdr); … … 568 581 * The request failed, just clean up. 569 582 */ 570 if ( !IOCPARM_LEN(iCmd))583 if (pUser) 571 584 { 572 585 if (pvPageBuf) 573 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cb , PAGE_SIZE));586 IOFreeAligned(pvPageBuf, RT_ALIGN_Z(cbReq, PAGE_SIZE)); 574 587 else 575 588 RTMemTmpFree(pHdr); -
trunk/src/VBox/HostDrivers/Support/testcase/tstPin.cpp
r4071 r4818 42 42 if (!rc) 43 43 { 44 /* 45 * Simple test. 46 */ 47 void *pv; 48 int rc = SUPPageAlloc(1, &pv); 49 AssertRC(rc); 50 RTPrintf("pv=%p\n", pv); 51 SUPPAGE aPages[1]; 52 rc = SUPPageLock(pv, 1, &aPages[0]); 53 RTPrintf("rc=%d aPages[0]=%RHp\n", rc, pv, aPages[0]); 54 RTThreadSleep(1500); 55 #if 0 56 RTPrintf("Unlocking...\n"); 57 RTThreadSleep(250); 58 rc = SUPPageUnlock(pv); 59 RTPrintf("rc=%d\n", rc); 60 RTThreadSleep(1500); 61 #endif 62 63 /* 64 * More extensive. 65 */ 44 66 static struct 45 67 { … … 169 191 SUPPageFree(pv, BIG_SIZEPP >> PAGE_SHIFT); 170 192 } 171 172 193 rc = SUPTerm(); 173 194 RTPrintf("SUPTerm -> rc=%d\n", rc);
Note:
See TracChangeset
for help on using the changeset viewer.