Changeset 6040 in vbox
- Timestamp:
- Dec 10, 2007 1:39:01 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-solaris.c
r6036 r6040 37 37 #include <iprt/initterm.h> 38 38 #include <iprt/process.h> 39 #include <iprt/mem.h> 39 40 40 41 … … 60 61 static int VBoxAddSolarisRead(dev_t Dev, struct uio *pUio, cred_t *pCred); 61 62 static int VBoxAddSolarisWrite(dev_t Dev, struct uio *pUio, cred_t *pCred); 62 static int VBoxAddSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg s, int mode, cred_t *pCred, int *pVal);63 static int VBoxAddSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg, int mode, cred_t *pCred, int *pVal); 63 64 64 65 static int VBoxAddSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd); … … 305 306 if (rc == DDI_SUCCESS) 306 307 { 307 pState->uIOPortBase = (uint ptr_t)baseAddr;308 pState->uIOPortBase = (uint16_t)*baseAddr; 308 309 rc = ddi_regs_map_setup(pDip, 1, &baseAddr, 0, pState->cbMMIO, &deviceAttr, &pState->PciHandle); 309 310 if (rc == DDI_SUCCESS) … … 528 529 } 529 530 531 /** @def IOCPARM_LEN 532 * Gets the length from the ioctl number. 533 * This is normally defined by sys/ioccom.h on BSD systems... 534 */ 535 #ifndef IOCPARM_LEN 536 # define IOCPARM_LEN(x) ( ((x) >> 16) & IOCPARM_MASK ) 537 #endif 530 538 531 539 /** … … 541 549 * @return corresponding solaris error code. 542 550 */ 543 static int VBoxAddSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg s, int Mode, cred_t *pCred, int *pVal)551 static int VBoxAddSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg, int Mode, cred_t *pCred, int *pVal) 544 552 { 545 553 VBA_LOGCONT("VBoxAddSolarisIOCtl\n"); 546 return DDI_SUCCESS; 554 555 /** @todo use the faster way to find pSession (using the soft state) */ 556 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 557 const RTPROCESS Process = RTProcSelf(); 558 const unsigned iHash = SESSION_HASH(Process); 559 PVBOXGUESTSESSION pSession; 560 561 /* 562 * Find the session. 563 */ 564 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 565 pSession = g_apSessionHashTab[iHash]; 566 if (pSession && pSession->Process != Process) 567 { 568 do pSession = pSession->pNextHash; 569 while (pSession && pSession->Process != Process); 570 } 571 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 572 if (!pSession) 573 { 574 VBA_LOGNOTE("VBoxAddSolarisIOCtl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d iCmd=%#x\n", 575 (int)Process, Cmd); 576 return EINVAL; 577 } 578 579 /** @todo I'll remove this size check after testing. */ 580 uint32_t cbBuf = 0; 581 if ( Cmd >= VBOXGUEST_IOCTL_VMMREQUEST(0) 582 && Cmd <= VBOXGUEST_IOCTL_VMMREQUEST(0xfff)) 583 cbBuf = sizeof(VMMDevRequestHeader); 584 #ifdef VBOX_HGCM 585 else if ( Cmd >= VBOXGUEST_IOCTL_HGCM_CALL(0) 586 && Cmd <= VBOXGUEST_IOCTL_HGCM_CALL(0xfff)) 587 cbBuf = sizeof(VBoxGuestHGCMCallInfo); 588 #endif /* VBOX_HGCM */ 589 else 590 { 591 switch (Cmd) 592 { 593 case VBOXGUEST_IOCTL_GETVMMDEVPORT: 594 cbBuf = sizeof(VBoxGuestPortInfo); 595 break; 596 597 case VBOXGUEST_IOCTL_WAITEVENT: 598 cbBuf = sizeof(VBoxGuestWaitEventInfo); 599 break; 600 601 case VBOXGUEST_IOCTL_CTL_FILTER_MASK: 602 cbBuf = sizeof(VBoxGuestFilterMaskInfo); 603 break; 604 605 #ifdef VBOX_HGCM 606 case VBOXGUEST_IOCTL_HGCM_CONNECT: 607 cbBuf = sizeof(VBoxGuestHGCMConnectInfo); 608 break; 609 610 case VBOXGUEST_IOCTL_HGCM_DISCONNECT: 611 cbBuf = sizeof(VBoxGuestHGCMDisconnectInfo); 612 break; 613 614 case VBOXGUEST_IOCTL_CLIPBOARD_CONNECT: 615 cbBuf = sizeof(uint32_t); 616 break; 617 #endif /* VBOX_HGCM */ 618 619 default: 620 { 621 VBA_LOGNOTE("VBoxAddSolarisIOCtl: Unkown request %d\n", Cmd); 622 return VERR_NOT_SUPPORTED; 623 } 624 } 625 } 626 627 if (RT_UNLIKELY(cbBuf != IOCPARM_LEN(Cmd))) 628 { 629 VBA_LOGNOTE("VBoxAddSolarisIOCtl: buffer size mismatch. size=%d expected=%d.\n", IOCPARM_LEN(Cmd), cbBuf); 630 return EINVAL; 631 } 632 633 void *pvBuf = RTMemTmpAlloc(cbBuf); 634 if (RT_UNLIKELY(!pvBuf)) 635 { 636 VBA_LOGNOTE("VBoxAddSolarisIOCtl: buffer size mismatch size=%d expected=%d.\n", IOCPARM_LEN(Cmd), cbBuf); 637 return ENOMEM; 638 } 639 640 int rc = ddi_copyin((void *)pArg, pvBuf, cbBuf, Mode); 641 if (RT_UNLIKELY(rc)) 642 { 643 RTMemTmpFree(pvBuf); 644 VBA_LOGNOTE("VBoxAddSolarisIOCtl: ddi_copyin failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd, rc); 645 return EFAULT; 646 } 647 648 size_t cbDataReturned; 649 rc = VBoxGuestCommonIOCtl(Cmd, &g_DevExt, pSession, pvBuf, cbBuf, &cbDataReturned); 650 if (RT_LIKELY(!rc)) 651 { 652 if (RT_UNLIKELY(cbDataReturned > cbBuf)) 653 { 654 VBA_LOGNOTE("VBoxAddSolarisIOCtl: too much output data %d expected %d\n", cbDataReturned, cbBuf); 655 cbDataReturned = cbBuf; 656 } 657 rc = ddi_copyout(pvBuf, (void *)pArg, cbDataReturned, Mode); 658 if (RT_UNLIKELY(rc)) 659 { 660 VBA_LOGNOTE("VBoxAddSolarisIOCtl: ddi_copyout failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd, rc); 661 rc = EFAULT; 662 } 663 } 664 else 665 { 666 VBA_LOGNOTE("VBoxAddSolarisIOCtl: VBoxGuestCommonIOCtl failed. rc=%d\n", rc); 667 rc = EFAULT; 668 } 669 *pVal = rc; 670 RTMemTmpFree(pvBuf); 671 return rc; 547 672 } 548 673
Note:
See TracChangeset
for help on using the changeset viewer.