VirtualBox

Changeset 68812 in vbox


Ignore:
Timestamp:
Sep 21, 2017 3:43:12 PM (7 years ago)
Author:
vboxsync
Message:

VBoxGuest/solaris: Use ldi_ioctl instead of VBoxGuestIDC. ldi_open_by_name and ldi_close calls the open & close entry points with the FKLYR flag set, in which case we'll be creating a kernel session rather than a user one. Adjusted vgdrvSolarisIOCtl to handle kernel sessions.

Location:
trunk/src/VBox/Additions/common/VBoxGuest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-solaris.c

    r68793 r68812  
    483483/**
    484484 * User context entry points
    485  */
    486 static int vgdrvSolarisOpen(dev_t *pDev, int fFlag, int fType, cred_t *pCred)
     485 *
     486 * @remarks fFlags are the flags passed to open() or to ldi_open_by_name.  In
     487 *          the latter case the FKLYR flag is added to indicate that the caller
     488 *          is a kernel component rather than user land.
     489 */
     490static int vgdrvSolarisOpen(dev_t *pDev, int fFlags, int fType, cred_t *pCred)
    487491{
    488492    int                 rc;
     
    517521     * Create a new session.
    518522     */
    519     rc = VGDrvCommonCreateUserSession(&g_DevExt, &pSession);
     523    if (!(fFlags & FKLYR))
     524        rc = VGDrvCommonCreateUserSession(&g_DevExt, &pSession);
     525    else
     526        rc = VGDrvCommonCreateKernelSession(&g_DevExt, &pSession);
    520527    if (RT_SUCCESS(rc))
    521528    {
    522         pState->pvProcRef = proc_ref();
     529        if (!(fFlags & FKLYR))
     530            pState->pvProcRef = proc_ref();
     531        else
     532            pState->pvProcRef = NULL;
    523533        pState->pSession = pSession;
    524534        *pDev = makedevice(getmajor(*pDev), iOpenInstance);
     
    547557    }
    548558
    549     proc_unref(pState->pvProcRef);
     559    if (pState->pvProcRef != NULL)
     560    {
     561        proc_unref(pState->pvProcRef);
     562        pState->pvProcRef = NULL;
     563    }
    550564    pSession = pState->pSession;
    551565    pState->pSession = NULL;
     
    561575     * Close the session.
    562576     */
    563     VGDrvCommonCloseSession(&g_DevExt, pSession);
     577    if (pSession)
     578        VGDrvCommonCloseSession(&g_DevExt, pSession);
    564579    return 0;
    565580}
     
    591606    return 0;
    592607}
     608
     609
     610/** @def IOCPARM_LEN
     611 * Gets the length from the ioctl number.
     612 * This is normally defined by sys/ioccom.h on BSD systems...
     613 */
     614#ifndef IOCPARM_LEN
     615# define IOCPARM_LEN(x)     ( ((x) >> 16) & IOCPARM_MASK )
     616#endif
    593617
    594618
     
    633657    }
    634658
     659    /*
     660     * It's kind of simple if this is a kernel session, take slow path if user land.
     661     */
     662    if (pSession->R0Process == NIL_RTR0PROCESS)
     663    {
     664        if (IOCPARM_LEN(iCmd) == sizeof(VBGLREQHDR))
     665        {
     666            PVBGLREQHDR pHdr = (PVBGLREQHDR)iArgs;
     667            int rc;
     668            if (iCmd != VBGL_IOCTL_IDC_DISCONNECT)
     669                rc =VGDrvCommonIoCtl(iCmd, &g_DevExt, pSession, pHdr, RT_MAX(pHdr->cbIn, pHdr->cbOut));
     670            else
     671            {
     672                pState->pSession = NULL;
     673                rc = VGDrvCommonIoCtl(iCmd, &g_DevExt, pSession, pHdr, RT_MAX(pHdr->cbIn, pHdr->cbOut));
     674                if (RT_FAILURE(rc))
     675                    pState->pSession = pSession;
     676            }
     677            return rc;
     678        }
     679    }
     680
    635681    return vgdrvSolarisIOCtlSlow(pSession, iCmd, Mode, iArgs);
    636682}
    637 
    638 
    639 /** @def IOCPARM_LEN
    640  * Gets the length from the ioctl number.
    641  * This is normally defined by sys/ioccom.h on BSD systems...
    642  */
    643 #ifndef IOCPARM_LEN
    644 # define IOCPARM_LEN(x)     ( ((x) >> 16) & IOCPARM_MASK )
    645 #endif
    646683
    647684
     
    755792
    756793
     794#if 0
    757795/**
    758796 * @note This code is duplicated on other platforms with variations, so please
     
    797835    return rc;
    798836}
    799 
     837#endif
    800838
    801839
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibIdc-solaris.cpp

    r68793 r68812  
    4141    ldi_handle_t hDev   = NULL;
    4242    ldi_ident_t  hIdent = ldi_ident_from_anon();
    43     /* Note! ldi_open_by_name actually opens the device and ends up creating a useless user session.
    44              Wonder if there is any way to detect ldi_open_by_name and do I/O controls via hDev... */
    45     int rc = ldi_open_by_name(VBOXGUEST_DEVICE_NAME, FREAD, kcred, &hDev, hIdent);
     43    int rc = ldi_open_by_name((char *)VBOXGUEST_DEVICE_NAME, FREAD, kcred, &hDev, hIdent);
    4644    ldi_ident_release(hIdent);
    4745    if (rc == 0)
    4846    {
    49         rc = VBoxGuestIDC(NULL, VBGL_IOCTL_IDC_CONNECT, &pReq->Hdr, sizeof(*pReq));
     47        pHandle->s.hDev = hDev;
     48        rc = VbglR0IdcCallRaw(pHandle, VBGL_IOCTL_IDC_CONNECT, &pReq->Hdr, sizeof(*pReq));
    5049        if (RT_SUCCESS(rc) && RT_SUCCESS(pReq->Hdr.rc))
    51         {
    52             pHandle->s.hDev = hDev;
    5350            return VINF_SUCCESS;
    54         }
    5551        ldi_close(hDev, FREAD, kcred);
    5652    }
     
    6460int VBOXCALL vbglR0IdcNativeClose(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCDISCONNECT pReq)
    6561{
    66     int rc = VBoxGuestIDC(pHandle->s.pvSession, VBGL_IOCTL_IDC_DISCONNECT, &pReq->Hdr, sizeof(*pReq));
     62    int rc = VbglR0IdcCallRaw(pHandle, VBGL_IOCTL_IDC_DISCONNECT, &pReq->Hdr, sizeof(*pReq));
    6763    if (RT_SUCCESS(rc) && RT_SUCCESS(pReq->Hdr.rc))
    6864    {
     
    8581DECLR0VBGL(int) VbglR0IdcCallRaw(PVBGLIDCHANDLE pHandle, uintptr_t uReq, PVBGLREQHDR pReqHdr, uint32_t cbReq)
    8682{
     83#if 0
    8784    return VBoxGuestIDC(pHandle->s.pvSession, uReq, pReqHdr, cbReq);
     85#else
     86    int iIgn;
     87    int rc = ldi_ioctl(pHandle->s.hDev, uReq, (intptr_t)pReqHdr, FKIOCTL | FNATIVE, kcred, &iIgn);
     88    if (rc == 0)
     89        return VINF_SUCCESS;
     90    return RTErrConvertFromErrno(rc);
     91#endif
    8892}
    8993
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette