VirtualBox

Changeset 6434 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 22, 2008 7:10:54 AM (17 years ago)
Author:
vboxsync
Message:

Solaris vboxadd: Generic request wrapper and cleanups.

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

Legend:

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

    r6422 r6434  
    664664
    665665
     666/** @def IOCPARM_LEN
     667 * Gets the length from the ioctl number.
     668 * This is normally defined by sys/ioccom.h on BSD systems...
     669 */
     670#ifndef IOCPARM_LEN
     671# define IOCPARM_LEN(Code)                      (((Code) >> 16) & IOCPARM_MASK)
     672#endif
     673
     674
    666675/**
    667676 * Driver ioctl, an alternate entry point for this character driver.
     
    722731#endif /* USE_SESSION_HASH */
    723732
    724     /** @todo r=bird: This is not the way I told you to implement this. Just do it exactly like the support
    725      * driver, i.e. the request is just a fixed size header containing the buffer pointer and size of the
    726      * real request (SUPREQHDR). Trying to save the extra ddi_copyin isn't worth the effort and inflexibility. */
    727 #if 0
    728733    /*
    729734     * Read and validate the request wrapper.
     
    732737    if (IOCPARM_LEN(Cmd) != sizeof(ReqWrap))
    733738    {
    734         Log((DEVICE_NAME ": VBoxAddSolarisIOCtl: bad request %#x\n", Cmd));
     739        Log((DEVICE_NAME ": VBoxAddSolarisIOCtl: bad request %#x size=%d expected=%d\n", Cmd, IOCPARM_LEN(Cmd), sizeof(ReqWrap)));
    735740        return ENOTTY;
    736741    }
    737742
    738     rc = ddi_copyin((void *)pArg, &ReqWrap, sizeof(ReqWrap), Mode);
     743    int rc = ddi_copyin((void *)pArg, &ReqWrap, sizeof(ReqWrap), Mode);
    739744    if (RT_UNLIKELY(rc))
    740745    {
     
    742747        return EINVAL;
    743748    }
    744 
    745749    if (ReqWrap.u32Magic != VBGLBIGREQ_MAGIC)
    746750    {
     
    755759    }
    756760
    757 #else
    758     uint32_t cbBuf = 0;
    759     int rc = 0;
    760     int requestType = 0;
    761     if (VBOXGUEST_IOCTL_NUMBER(Cmd) == VBOXGUEST_IOCTL_NUMBER(VBOXGUEST_IOCTL_VMMREQUEST(0)))
    762     {
    763         cbBuf = sizeof(VMMDevRequestHeader);
    764         requestType = 1;
    765         LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_VMMREQUEST %#x", Cmd));
    766     }
    767 #ifdef VBOX_HGCM
    768     else if (VBOXGUEST_IOCTL_NUMBER(Cmd) == VBOXGUEST_IOCTL_NUMBER(VBOXGUEST_IOCTL_HGCM_CALL(0)))
    769     {
    770         cbBuf = sizeof(VBoxGuestHGCMCallInfo);
    771         requestType = 2;
    772         LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_HGCM_CALL %#x", Cmd));
    773     }
    774 #endif /* VBOX_HGCM */
    775     else if (VBOXGUEST_IOCTL_NUMBER(Cmd) == VBOXGUEST_IOCTL_NUMBER(VBOXGUEST_IOCTL_LOG(0)))
    776     {
    777         cbBuf = VBOXGUEST_IOCTL_SIZE(Cmd);
    778         LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_LOG Cmd=%#x cbBuf=%d", Cmd, cbBuf));
    779         char *pszLogMsg = RTMemTmpAlloc(cbBuf);
    780         if (RT_UNLIKELY(!pszLogMsg))
    781         {
    782             LogRel((DEVICE_NAME ":RTMemAlloc failed to alloc %d bytes\n", cbBuf));
    783             return ENOMEM;
    784         }
    785         rc = ddi_copyin((void *)pArg, pszLogMsg, cbBuf, Mode);
    786         if (RT_UNLIKELY(rc))
    787             LogRel((DEVICE_NAME ":ddi_copyin failed. rc=%d\n", rc));
    788         else
    789 /** @todo r=bird: this should be handled by generic code and not here so it works 100% the same everywhere. */
    790             Log(("%.*s", cbBuf, pszLogMsg));
    791         RTMemTmpFree(pszLogMsg);
    792         return rc;
    793     }
    794     else
    795     {
    796         switch (Cmd)
    797         {
    798             case VBOXGUEST_IOCTL_GETVMMDEVPORT:
    799                 cbBuf = sizeof(VBoxGuestPortInfo);
    800                 LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_GETVMMDEVPORT"));
    801                 break;
    802 
    803             case VBOXGUEST_IOCTL_WAITEVENT:
    804                 cbBuf = sizeof(VBoxGuestWaitEventInfo);
    805                 LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_WAITEVENT"));
    806                 break;
    807 
    808             case VBOXGUEST_IOCTL_CTL_FILTER_MASK:
    809                 cbBuf = sizeof(VBoxGuestFilterMaskInfo);
    810                 LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_CTL_FILTER_MASK"));
    811                 break;
    812 
    813 #ifdef VBOX_HGCM
    814             case VBOXGUEST_IOCTL_HGCM_CONNECT:
    815                 cbBuf = sizeof(VBoxGuestHGCMConnectInfo);
    816                 LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_HGCM_CONNECT"));
    817                 break;
    818 
    819             case VBOXGUEST_IOCTL_HGCM_DISCONNECT:
    820                 cbBuf = sizeof(VBoxGuestHGCMDisconnectInfo);
    821                 LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_HGCM_DISCONNECT"));
    822                 break;
    823 
    824             case VBOXGUEST_IOCTL_CLIPBOARD_CONNECT:
    825                 cbBuf = sizeof(uint32_t);
    826                 LogFlow((DEVICE_NAME ":VBOXGUEST_IOCTL_CLIPBOARD_CONNECT"));
    827                 break;
    828 #endif /* VBOX_HGCM */
    829 
    830             default:
    831             {
    832                 LogRel((DEVICE_NAME ":VBoxAddSolarisIOCtl: Unkown request %d\n", Cmd));
    833                 return VERR_NOT_SUPPORTED;
    834             }
    835         }
    836     }
    837 
    838     /*
    839      * Read the header.
    840      */
    841     if (requestType == 1)
    842     {
    843         VMMDevRequestHeader Hdr;
    844         rc = ddi_copyin((void *)pArg, &Hdr, sizeof(Hdr), Mode);
    845         if (RT_UNLIKELY(rc))
    846         {
    847             Log((DEVICE_NAME ":VBoxAddSolarisIOCtl: ddi_copyin failed to read header pArg=%p Cmd=%d. rc=%d.\n", pArg, Cmd, rc));
    848             return EINVAL;
    849         }
    850 
    851         cbBuf = Hdr.size;
    852         if (RT_UNLIKELY(cbBuf < sizeof(Hdr)))
    853         {
    854             Log((DEVICE_NAME ":VBoxAddSolarisIOCtl: Invalid request size (%d) in header.\n", cbBuf));
    855             return EINVAL;
    856         }
    857     }
    858     else if (requestType == 2)
    859     {
    860         VBoxGuestHGCMCallInfo Hdr;
    861         rc = ddi_copyin((void *)pArg, &Hdr, sizeof(Hdr), Mode);
    862         if (RT_UNLIKELY(rc))
    863         {
    864             Log((DEVICE_NAME ":VBoxAddSolarisIOCtl: ddi_copyin failed to read header pArg=%p Cmd=%d. rc=%d.\n", pArg, Cmd, rc));
    865             return EINVAL;
    866         }
    867 
    868         if (RT_UNLIKELY(Hdr.cParms <= 0))
    869         {
    870             Log((DEVICE_NAME ":VBoxAddSolarisIOCtl: Invalid request size. cParms=%d in HCGM call info header.\n", Hdr.cParms));
    871             return EINVAL;
    872         }
    873         cbBuf += Hdr.cParms * sizeof(HGCMFunctionParameter);
    874     }
    875 #endif
    876 
    877761    /*
    878762     * Read the request.
    879763     */
    880 #if 0
    881     void *pvBuf = RTMemTmpAlloc(ReqWrap.cbData);
    882 #else
     764    uint32_t cbBuf = ReqWrap.cbData;
    883765    void *pvBuf = RTMemTmpAlloc(cbBuf);
    884 #endif
    885766    if (RT_UNLIKELY(!pvBuf))
    886767    {
     
    889770    }
    890771
    891 #if 0
    892     rc = ddi_copyin((void *)pArg, (void *)(uintptr_t)ReqWrap.pvData, ReqWrap.cbData, Mode);
    893 #else
    894     rc = ddi_copyin((void *)pArg, pvBuf, cbBuf, Mode);
    895 #endif
     772    rc = ddi_copyin((void *)(uintptr_t)ReqWrap.pvDataR3, pvBuf, ReqWrap.cbData, Mode);
    896773    if (RT_UNLIKELY(rc))
    897774    {
     
    900777        return EFAULT;
    901778    }
    902     if (RT_UNLIKELY(cbBuf != 0 && !VALID_PTR(pvBuf)))
     779    if (RT_UNLIKELY(   cbBuf != 0
     780                    && !VALID_PTR(pvBuf)))
    903781    {
    904782        RTMemTmpFree(pvBuf);
    905783        Log((DEVICE_NAME ":VBoxAddSolarisIOCtl: pvBuf invalid pointer %p\n", pvBuf));
     784        return EINVAL;
    906785    }
    907786    Log((DEVICE_NAME ":VBoxAddSolarisIOCtl: pSession=%p pid=%d.\n", pSession, (int)RTProcSelf()));
     
    919798            cbDataReturned = cbBuf;
    920799        }
    921 #if 0
    922         rc = ddi_copyout(pvBuf, (void *)(uintptr_t)ReqWrap.pvData, cbDataReturned, Mode);
    923 #else
    924         rc = ddi_copyout(pvBuf, (void *)pArg, cbDataReturned, Mode);
    925 #endif
     800        rc = ddi_copyout(pvBuf, (void *)(uintptr_t)ReqWrap.pvDataR3, cbDataReturned, Mode);
    926801        if (RT_UNLIKELY(rc))
    927802        {
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp

    r6425 r6434  
    3737# include <sys/types.h>
    3838# include <sys/stat.h>
     39# include <errno.h>
    3940# include <stdio.h>
    4041# include <stdlib.h>
     
    174175    return RTErrConvertFromOS2(rc);
    175176
    176 #elif defined(RT_OS_SOLARIS) && 0
     177#elif defined(RT_OS_SOLARIS)
    177178    VBGLBIGREQ Hdr;
    178179    Hdr.u32Magic = VBGLBIGREQ_MAGIC;
    179180    Hdr.cbData = cbData;
    180     Hdr.pvData = pvData;
    181     Assert(_IOC_SIZE(iFunction) == sizeof(Hdr));
    182 
    183     int rc = ioctl((int)File, iFunction, &Hdr);
     181    Hdr.pvDataR3 = pvData;
     182
     183    int rc = ioctl((int)g_File, iFunction, &Hdr);
    184184    if (rc == -1)
    185185        rc = errno;
    186186    return rc;
    187187
    188     /* PORTME */
    189188#else
    190189    /* Default implementation (linux, solaris). */
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