VirtualBox

Changeset 40488 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Mar 15, 2012 4:57:11 PM (13 years ago)
Author:
vboxsync
Message:

Additions/VBoxGuest: another drop of the STREAMS-based Solaris code.

Location:
trunk/src/VBox/Additions/common/VBoxGuest
Files:
1 added
3 edited

Legend:

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

    r40325 r40488  
    5151#ifdef TESTCASE  /* Include this last as we . */
    5252# include "testcase/solaris.h"
    53 # include <iprt/test.h>
     53# include "testcase/tstVBoxGuest-solaris.h"
    5454#endif  /* TESTCASE */
    5555
     
    6363/** The module description as seen in 'modinfo'. */
    6464#define DEVICE_DESC              "VirtualBox GstDrv"
     65/** The maximum number of open device nodes we support. */
     66#define MAX_OPEN_NODES           4096
    6567
    6668
     
    6971******************************************************************************/
    7072
    71 static int vboxGuestSolarisOpen(queue_t *pReadQueue, dev_t *pDev, int fFlag,
     73static int vbgr0SolOpen(queue_t *pReadQueue, dev_t *pDev, int fFlag,
    7274                                int fMode, cred_t *pCred);
    73 static int vboxGuestSolarisClose(queue_t *pReadQueue, int fFlag, cred_t *pCred);
    74 static int vboxGuestSolarisWPut(queue_t *pWriteQueue, mblk_t *pMBlk);
    75 
    76 static int vboxGuestSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pArg, void **ppResult);
    77 static int vboxGuestSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd);
    78 static int vboxGuestSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
     75static int vbgr0SolClose(queue_t *pReadQueue, int fFlag, cred_t *pCred);
     76static int vbgr0SolWPut(queue_t *pWriteQueue, mblk_t *pMBlk);
     77
     78static int vbgr0SolGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pArg, void **ppResult);
     79static int vbgr0SolAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd);
     80static int vbgr0SolDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
    7981
    8082
     
    8385******************************************************************************/
    8486
    85 #ifndef TESTCASE  /* I see no value in including these. */
     87#ifndef TESTCASE  /* I see no value in including these in the test. */
    8688
    8789/*
    8890 * mod_info: STREAMS module information.
    8991 */
    90 static struct module_info g_VBoxGuestSolarisModInfo =
     92static struct module_info g_vbgr0SolModInfo =
    9193{
    9294    0x0ffff,                /* module id number */
     
    103105 * the put and service procedures.
    104106 */
    105 static struct qinit g_VBoxGuestSolarisRInit =
     107static struct qinit g_vbgr0SolRInit =
    106108{
    107109    NULL,                /* put */
    108110    NULL,                /* service thread procedure */
    109     vboxGuestSolarisOpen,
    110     vboxGuestSolarisClose,
     111    vbgr0SolOpen,
     112    vbgr0SolClose,
    111113    NULL,                /* reserved */
    112     &g_VBoxGuestSolarisModInfo,
     114    &g_vbgr0SolModInfo,
    113115    NULL                 /* module statistics structure */
    114116};
     
    121123 * hardware pointer drivers to a single virtual pointer.
    122124 */
    123 static struct qinit g_VBoxGuestSolarisWInit =
    124 {
    125     vboxGuestSolarisWPut,
     125static struct qinit g_vbgr0SolWInit =
     126{
     127    vbgr0SolWPut,
    126128    NULL,                   /* service thread procedure */
    127129    NULL,                   /* open */
    128130    NULL,                   /* close */
    129131    NULL,                   /* reserved */
    130     &g_VBoxGuestSolarisModInfo,
     132    &g_vbgr0SolModInfo,
    131133    NULL                    /* module statistics structure */
    132134};
     
    135137 * streamtab: for drivers that support char/block entry points.
    136138 */
    137 static struct streamtab g_VBoxGuestSolarisStreamTab =
    138 {
    139     &g_VBoxGuestSolarisRInit,
    140     &g_VBoxGuestSolarisWInit,
     139static struct streamtab g_vbgr0SolStreamTab =
     140{
     141    &g_vbgr0SolRInit,
     142    &g_vbgr0SolWInit,
    141143    NULL,                   /* MUX rinit */
    142144    NULL                    /* MUX winit */
     
    146148 * cb_ops: for drivers that support char/block entry points.
    147149 */
    148 static struct cb_ops g_VBoxGuestSolarisCbOps =
     150static struct cb_ops g_vbgr0SolCbOps =
    149151{
    150152    nulldev,                /* open */
     
    161163    nochpoll,               /* c poll */
    162164    ddi_prop_op,            /* property ops */
    163     g_VBoxGuestSolarisStreamTab,
     165    g_vbgr0SolStreamTab,
    164166    D_NEW | D_MP,           /* compat. flag */
    165167};
     
    168170 * dev_ops: for driver device operations.
    169171 */
    170 static struct dev_ops g_VBoxGuestSolarisDevOps =
     172static struct dev_ops g_vbgr0SolDevOps =
    171173{
    172174    DEVO_REV,               /* driver build revision */
    173175    0,                      /* ref count */
    174     vboxGuestSolarisGetInfo,
     176    vbgr0SolGetInfo,
    175177    nulldev,                /* identify */
    176178    nulldev,                /* probe */
    177     vboxGuestSolarisAttach,
    178     vboxGuestSolarisDetach,
     179    vbgr0SolAttach,
     180    vbgr0SolDetach,
    179181    nodev,                  /* reset */
    180     &g_VBoxGuestSolarisCbOps,
     182    &g_vbgr0SolCbOps,
    181183    (struct bus_ops *)0,
    182184    nodev                   /* power */
     
    186188 * modldrv: export driver specifics to the kernel.
    187189 */
    188 static struct modldrv g_VBoxGuestSolarisModule =
     190static struct modldrv g_vbgr0SolModule =
    189191{
    190192    &mod_driverops,         /* extern from kernel */
    191193    DEVICE_DESC " " VBOX_VERSION_STRING "r" RT_XSTR(VBOX_SVN_REV),
    192     &g_VBoxGuestSolarisDevOps
     194    &g_vbgr0SolDevOps
    193195};
    194196
     
    196198 * modlinkage: export install/remove/info to the kernel.
    197199 */
    198 static struct modlinkage g_VBoxGuestSolarisModLinkage =
     200static struct modlinkage g_vbgr0SolModLinkage =
    199201{
    200202    MODREV_1,               /* loadable module system revision */
    201     &g_VBoxGuestSolarisModule,
     203    &g_vbgr0SolModule,
    202204    NULL                    /* terminate array of linkage structures */
    203205};
    204206
    205207#else  /* TESTCASE */
    206 static void *g_VBoxGuestSolarisModLinkage;
     208static void *g_vbgr0SolModLinkage;
    207209#endif  /* TESTCASE */
    208210
     
    217219     * user-space. */
    218220    queue_t           *pWriteQueue;
    219     /** Our minor number. */
    220     unsigned           cMinor;
    221221    /* The current greatest horizontal pixel offset on the screen, used for
    222222     * absolute mouse position reporting.
     
    227227     */
    228228    unsigned           cMaxScreenY;
    229 } vboxguest_state_t;
     229} VBGR0STATE, *PVBGR0STATE;
    230230
    231231
     
    236236/** Device handle (we support only one instance). */
    237237static dev_info_t          *g_pDip = NULL;
    238 /** Opaque pointer to file-descriptor states */
    239 static void                *g_pVBoxGuestSolarisState = NULL;
     238/** Array of state structures for open device nodes.  I don't care about
     239 * wasting a few K of memory. */
     240static VBGR0STATE           g_aOpenNodeStates[MAX_OPEN_NODES] /* = { 0 } */;
     241/** Mutex to protect the queue pointers in the node states from being unset
     242 * during an IRQ. */
     243static kmutex_t             g_StateMutex;
    240244/** Device extention & session data association structure. */
    241245static VBOXGUESTDEVEXT      g_DevExt;
     
    255259static size_t               g_cIntrAllocated;
    256260/** The IRQ Mutex */
    257 static kmutex_t             g_IrqMtx;
    258 /** Our global state.
    259  * @todo Make this into an opaque pointer in the device extension structure.
    260  * @todo Can't we make do without all these globals anyway?
    261  */
    262 static vboxguest_state_t   *g_pState;
     261static kmutex_t             g_IrqMutex;
    263262
    264263
     
    291290         * Prevent module autounloading.
    292291         */
    293         pModCtl = mod_getctl(&g_VBoxGuestSolarisModLinkage);
     292        pModCtl = mod_getctl(&g_vbgr0SolModLinkage);
    294293        if (pModCtl)
    295294            pModCtl->mod_loadflags |= MOD_NOAUTOUNLOAD;
    296295        else
    297296            LogRel((DEVICE_NAME ":failed to disable autounloading!\n"));
    298 
    299         rc = ddi_soft_state_init(&g_pVBoxGuestSolarisState, sizeof(vboxguest_state_t), 1);
    300         if (!rc)
    301         {
    302             rc = mod_install(&g_VBoxGuestSolarisModLinkage);
    303             if (rc)
    304                 ddi_soft_state_fini(&g_pVBoxGuestSolarisState);
    305         }
     297        /* Initialise the node state mutex.  This will be taken in the ISR. */
     298        mutex_init(&g_StateMutex, NULL, MUTEX_DRIVER,
     299                   DDI_INTR_PRI(uIntrPriority));
     300        rc = mod_install(&g_vbgr0SolModLinkage);
    306301    }
    307302    else
     
    316311
    317312#ifdef TESTCASE
    318 /* Nothing in these three really worth testing, plus we would have to stub
    319  * around the IPRT log functions. */
     313/** Simple test of the flow through _init. */
     314void test_init(RTTEST hTest)
     315{
     316    RTTestSub(hTest, "Testing _init");
     317    RTTEST_CHECK(hTest, _init() == 0);
     318}
    320319#endif
    321320
     
    327326
    328327    LogFlow((DEVICE_NAME ":_fini\n"));
    329     rc = mod_remove(&g_VBoxGuestSolarisModLinkage);
    330     if (!rc)
    331         ddi_soft_state_fini(&g_pVBoxGuestSolarisState);
     328    rc = mod_remove(&g_vbgr0SolModLinkage);
     329    mutex_destroy(&g_StateMutex);
    332330
    333331    RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
     
    343341{
    344342    LogFlow((DEVICE_NAME ":_info\n"));
    345     return mod_info(&g_VBoxGuestSolarisModLinkage, pModInfo);
    346 }
    347 
     343    return mod_info(&g_vbgr0SolModLinkage, pModInfo);
     344}
     345
     346
     347/******************************************************************************
     348*   Helper routines                                                           *
     349******************************************************************************/
     350
     351/** Calls the kernel IOCtl to report mouse status to the host on behalf of
     352 * an open session. */
     353static int vbgr0SolSetMouseStatus(PVBOXGUESTSESSION pSession, uint32_t fStatus)
     354{
     355    return VBoxGuestCommonIOCtl(VBOXGUEST_IOCTL_SET_MOUSE_STATUS, &g_DevExt,
     356                                pSession, &fStatus, sizeof(fStatus), NULL);
     357}
     358
     359static void vbgr0SolResetSoftState(PVBGR0STATE pState)
     360{
     361    mutex_enter(&g_StateMutex);
     362    RT_ZERO(*pState);
     363    mutex_exit(&g_StateMutex);
     364}
    348365
    349366/******************************************************************************
     
    355372 * handler.
    356373 */
    357 int vboxGuestSolarisOpen(queue_t *pReadQueue, dev_t *pDev, int fFlag, int fMode,
    358                          cred_t *pCred)
     374int vbgr0SolOpen(queue_t *pReadQueue, dev_t *pDev, int fFlag, int fMode,
     375                 cred_t *pCred)
    359376{
    360377    int                 rc;
    361378    PVBOXGUESTSESSION   pSession = NULL;
    362     vboxguest_state_t *pState = NULL;
     379    PVBGR0STATE pState = NULL;
    363380    unsigned cInstance;
    364381
     
    368385
    369386    /*
    370      * Sanity check on the mode parameter.
     387     * Sanity check on the mode parameter - only open as a driver, not a
     388     * module, and we do cloning ourselves.  Note that we start at 1, as minor
     389     * zero was allocated to the file system device node in vbgr0SolAttach
     390     * (see https://blogs.oracle.com/timatworkhomeandinbetween/entry/using_makedevice_in_a_drivers).
    371391     */
    372392    if (fMode)
    373393        return EINVAL;
    374394
    375     for (cInstance = 0; cInstance < 4096; cInstance++)
    376     {
    377         if (    !ddi_get_soft_state(g_pVBoxGuestSolarisState, cInstance) /* faster */
    378             &&  ddi_soft_state_zalloc(g_pVBoxGuestSolarisState, cInstance) == DDI_SUCCESS)
    379         {
    380             pState = ddi_get_soft_state(g_pVBoxGuestSolarisState, cInstance);
     395    for (cInstance = 1; cInstance < MAX_OPEN_NODES; cInstance++)
     396    {
     397        if (ASMAtomicCmpXchgPtr(&g_aOpenNodeStates[cInstance].pWriteQueue,
     398                                WR(pReadQueue), NULL))
     399        {
     400            pState = &g_aOpenNodeStates[cInstance];
    381401            break;
    382402        }
     
    399419        WR(pReadQueue)->q_ptr = (char *)pState;
    400420        pReadQueue->q_ptr = (char *)pState;
    401         pState->pWriteQueue = WR(pReadQueue);
    402         pState->cMinor = cInstance;
    403         g_pState = pState;
    404421        qprocson(pState->pWriteQueue);
    405422        Log((DEVICE_NAME "::Open: pSession=%p pState=%p pid=%d\n", pSession, pState, (int)RTProcSelf()));
     
    408425
    409426    /* Failed, clean up. */
    410     ddi_soft_state_free(g_pVBoxGuestSolarisState, cInstance);
     427    vbgr0SolResetSoftState(pState);
    411428
    412429    LogRel((DEVICE_NAME "::Open: VBoxGuestCreateUserSession failed. rc=%d\n", rc));
     
    419436 * handler.
    420437 */
    421 int vboxGuestSolarisClose(queue_t *pReadQueue, int fFlag, cred_t *pCred)
     438int vbgr0SolClose(queue_t *pReadQueue, int fFlag, cred_t *pCred)
    422439{
    423440    PVBOXGUESTSESSION pSession = NULL;
    424     vboxguest_state_t *pState = (vboxguest_state_t *)pReadQueue->q_ptr;
     441    PVBGR0STATE pState = (PVBGR0STATE)pReadQueue->q_ptr;
    425442
    426443    LogFlow((DEVICE_NAME "::Close pid=%d\n", (int)RTProcSelf()));
     
    435452    qprocsoff(pState->pWriteQueue);
    436453    pState->pWriteQueue = NULL;
    437     g_pState = NULL;
    438454    pReadQueue->q_ptr = NULL;
    439455
     
    441457    pState->pSession = NULL;
    442458    Log((DEVICE_NAME "::Close: pSession=%p pState=%p\n", pSession, pState));
    443     ddi_soft_state_free(g_pVBoxGuestSolarisState, pState->cMinor);
     459    vbgr0SolResetSoftState(pState);
    444460    if (!pSession)
    445461    {
     
    456472
    457473
    458 /* Helper for vboxGuestSolarisWPut. */
    459 static int vboxGuestSolarisDispatchIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk);
     474/* Helper for vbgr0SolWPut. */
     475static int vbgr0SolDispatchIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk);
    460476
    461477/**
     
    463479 * land in our write queue.
    464480 */
    465 int vboxGuestSolarisWPut(queue_t *pWriteQueue, mblk_t *pMBlk)
    466 {
    467     vboxguest_state_t *pState = (vboxguest_state_t *)pWriteQueue->q_ptr;
     481int vbgr0SolWPut(queue_t *pWriteQueue, mblk_t *pMBlk)
     482{
     483    PVBGR0STATE pState = (PVBGR0STATE)pWriteQueue->q_ptr;
    468484   
    469     LogFlowFunc(("\n"));
     485    LogFlowFunc((DEVICE_NAME "::\n"));
    470486    switch (pMBlk->b_datap->db_type)
    471487    {
     
    487503        case M_IOCDATA:
    488504        {
    489             int err = vboxGuestSolarisDispatchIOCtl(pWriteQueue, pMBlk);
     505            int err = vbgr0SolDispatchIOCtl(pWriteQueue, pMBlk);
    490506            if (!err)
    491507                qreply(pWriteQueue, pMBlk);
     
    527543 *                  implemention.
    528544 */
    529 typedef int FNVBOXGUESTSOLARISIOCTL(vboxguest_state_t *pState, int cCmd,
    530                                     void *pvData, size_t cbBuffer,
    531                                     size_t *pcbData, int *prc);
    532 typedef FNVBOXGUESTSOLARISIOCTL *PFNVBOXGUESTSOLARISIOCTL;
    533 
    534 /* Helpers for vboxGuestSolarisDispatchIOCtl. */
    535 static int vboxGuestSolarisHandleIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    536                                        PFNVBOXGUESTSOLARISIOCTL pfnHandler,
    537                                        int cCmd, size_t cbTransparent,
    538                                        enum IOCTLDIRECTION enmDirection);
    539 static int vboxGuestSolarisVUIDIOCtl(vboxguest_state_t *pState, int cCmd,
    540                                      void *pvData, size_t cbBuffer,
    541                                      size_t *pcbData, int *prc);
    542 static int vboxGuestSolarisGuestIOCtl(vboxguest_state_t *pState, int cCmd,
    543                                       void *pvData, size_t cbBuffer,
    544                                       size_t *pcbData, int *prc);
     545typedef int FNVBGR0SOLIOCTL(PVBGR0STATE pState, int cCmd, void *pvData,
     546                            size_t cbBuffer, size_t *pcbData, int *prc);
     547typedef FNVBGR0SOLIOCTL *PFNVBGR0SOLIOCTL;
     548
     549/* Helpers for vbgr0SolDispatchIOCtl. */
     550static int vbgr0SolHandleIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
     551                               PFNVBGR0SOLIOCTL pfnHandler,
     552                               int cCmd, size_t cbTransparent,
     553                               enum IOCTLDIRECTION enmDirection);
     554static int vbgr0SolVUIDIOCtl(PVBGR0STATE pState, int cCmd, void *pvData,
     555                             size_t cbBuffer, size_t *pcbData, int *prc);
     556static int vbgr0SolGuestIOCtl(PVBGR0STATE pState, int cCmd, void *pvData,
     557                              size_t cbBuffer, size_t *pcbData, int *prc);
    545558
    546559/** Table of supported VUID IOCtls. */
     
    555568     * specified for transparent IOCtls. */
    556569    enum IOCTLDIRECTION enmDirection;
    557 } s_aVUIDIOCtlDescriptions[] =
     570} g_aVUIDIOCtlDescriptions[] =
    558571{
    559572   { VUIDGFORMAT,     sizeof(int),                  OUT         },
     
    579592 * @param  pMBlk        pointer to the STREAMS message block structure.
    580593 */
    581 static int vboxGuestSolarisDispatchIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk)
     594static int vbgr0SolDispatchIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk)
    582595{
    583596    struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
     
    586599    enum IOCTLDIRECTION enmDirection;
    587600
    588     LogFlowFunc(("cCmdType=%c, cCmd=%d\n", cCmdType, cCmd));
     601    LogFlowFunc((DEVICE_NAME "::cCmdType=%c, cCmd=%d\n", cCmdType, cCmd));
    589602    switch (cCmdType)
    590603    {
     
    594607            unsigned i;
    595608           
    596             for (i = 0; i < RT_ELEMENTS(s_aVUIDIOCtlDescriptions); ++i)
    597                 if (s_aVUIDIOCtlDescriptions[i].cCmd == cCmd)
     609            for (i = 0; i < RT_ELEMENTS(g_aVUIDIOCtlDescriptions); ++i)
     610                if (g_aVUIDIOCtlDescriptions[i].cCmd == cCmd)
    598611                {
    599                     cbBuffer     = s_aVUIDIOCtlDescriptions[i].cbBuffer;
    600                     enmDirection = s_aVUIDIOCtlDescriptions[i].enmDirection;
    601                     return vboxGuestSolarisHandleIOCtl(pWriteQueue, pMBlk,
    602                                                      vboxGuestSolarisVUIDIOCtl,
    603                                                        cCmd, cbBuffer,
    604                                                        enmDirection);
     612                    cbBuffer     = g_aVUIDIOCtlDescriptions[i].cbBuffer;
     613                    enmDirection = g_aVUIDIOCtlDescriptions[i].enmDirection;
     614                    return vbgr0SolHandleIOCtl(pWriteQueue, pMBlk,
     615                                               vbgr0SolVUIDIOCtl, cCmd,
     616                                               cbBuffer, enmDirection);
    605617                }
    606618            return EINVAL;
    607619        }
    608620        case 'V':
    609             return vboxGuestSolarisHandleIOCtl(pWriteQueue, pMBlk,
    610                                                vboxGuestSolarisGuestIOCtl,
    611                                                cCmd, 0, UNSPECIFIED);
     621            return vbgr0SolHandleIOCtl(pWriteQueue, pMBlk, vbgr0SolGuestIOCtl,
     622                                       cCmd, 0, UNSPECIFIED);
    612623        default:
    613624            return ENOTTY;
     
    616627
    617628
    618 /* Helpers for vboxGuestSolarisHandleIOCtl. */
    619 static int vboxGuestSolarisHandleIOCtlData
    620                (queue_t *pWriteQueue, mblk_t *pMBlk,
    621                 PFNVBOXGUESTSOLARISIOCTL pfnHandler, int cCmd,
    622                 size_t cbTransparent, enum IOCTLDIRECTION enmDirection);
    623 
    624 static int vboxGuestSolarisHandleTransparentIOCtl
    625                 (queue_t *pWriteQueue, mblk_t *pMBlk,
    626                  PFNVBOXGUESTSOLARISIOCTL pfnHandler, int cCmd,
    627                 size_t cbTransparent, enum IOCTLDIRECTION enmDirection);
    628 
    629 static int vboxGuestSolarisHandleIStrIOCtl
    630                 (queue_t *pWriteQueue, mblk_t *pMBlk,
    631                  PFNVBOXGUESTSOLARISIOCTL pfnHandler, int cCmd);
     629/* Helpers for vbgr0SolHandleIOCtl. */
     630static int vbgr0SolHandleIOCtlData(queue_t *pWriteQueue, mblk_t *pMBlk,
     631                                   PFNVBGR0SOLIOCTL pfnHandler, int cCmd,
     632                                   size_t cbTransparent,
     633                                   enum IOCTLDIRECTION enmDirection);
     634
     635static int vbgr0SolHandleTransparentIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
     636                                          PFNVBGR0SOLIOCTL pfnHandler,
     637                                          int cCmd, size_t cbTransparent,
     638                                          enum IOCTLDIRECTION enmDirection);
     639
     640static int vbgr0SolHandleIStrIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
     641                                   PFNVBGR0SOLIOCTL pfnHandler, int cCmd);
    632642
    633643/**
     
    652662 * @param  enmDirection   data transfer direction of the IOCtl.
    653663 */
    654 static int vboxGuestSolarisHandleIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    655                                        PFNVBOXGUESTSOLARISIOCTL pfnHandler,
    656                                        int cCmd, size_t cbTransparent,
    657                                        enum IOCTLDIRECTION enmDirection)
     664static int vbgr0SolHandleIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
     665                               PFNVBGR0SOLIOCTL pfnHandler, int cCmd,
     666                               size_t cbTransparent,
     667                               enum IOCTLDIRECTION enmDirection)
    658668{
    659669    struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
    660     vboxguest_state_t *pState = (vboxguest_state_t *)pWriteQueue->q_ptr;
     670    PVBGR0STATE pState = (PVBGR0STATE)pWriteQueue->q_ptr;
    661671
    662672    if (pMBlk->b_datap->db_type == M_IOCDATA)
    663         return vboxGuestSolarisHandleIOCtlData(pWriteQueue, pMBlk, pfnHandler,
    664                                                cCmd, cbTransparent,
    665                                                enmDirection);
     673        return vbgr0SolHandleIOCtlData(pWriteQueue, pMBlk, pfnHandler, cCmd,
     674                                       cbTransparent, enmDirection);
    666675    else if (pIOCBlk->ioc_count == TRANSPARENT)
    667         return vboxGuestSolarisHandleTransparentIOCtl(pWriteQueue, pMBlk,
    668                                                       pfnHandler, cCmd,
    669                                                       cbTransparent,
    670                                                       enmDirection);
     676        return vbgr0SolHandleTransparentIOCtl(pWriteQueue, pMBlk, pfnHandler,
     677                                              cCmd, cbTransparent,
     678                                              enmDirection);
    671679    else
    672         return vboxGuestSolarisHandleIStrIOCtl(pWriteQueue, pMBlk, pfnHandler,
    673                                                cCmd);
    674 }
    675 
    676 
    677 /**
    678  * Helper for vboxGuestSolarisHandleIOCtl.  This rather complicated-looking
     680        return vbgr0SolHandleIStrIOCtl(pWriteQueue, pMBlk, pfnHandler, cCmd);
     681}
     682
     683
     684/**
     685 * Helper for vbgr0SolHandleIOCtl.  This rather complicated-looking
    679686 * code is basically the standard boilerplate for handling any streams IOCtl
    680687 * additional data, which we currently only use for transparent IOCtls.
    681  * @copydoc vboxGuestSolarisHandleIOCtl
    682  */
    683 static int vboxGuestSolarisHandleIOCtlData(queue_t *pWriteQueue, mblk_t *pMBlk,
    684                                            PFNVBOXGUESTSOLARISIOCTL pfnHandler,
    685                                            int cCmd, size_t cbTransparent,
    686                                            enum IOCTLDIRECTION enmDirection)
     688 * @copydoc vbgr0SolHandleIOCtl
     689 */
     690static int vbgr0SolHandleIOCtlData(queue_t *pWriteQueue, mblk_t *pMBlk,
     691                                   PFNVBGR0SOLIOCTL pfnHandler, int cCmd,
     692                                   size_t cbTransparent,
     693                                   enum IOCTLDIRECTION enmDirection)
    687694{
    688695    struct copyresp *pCopyResp = (struct copyresp *)pMBlk->b_rptr;
    689696    struct iocblk   *pIOCBlk   = (struct iocblk *)pMBlk->b_rptr;
    690     vboxguest_state_t *pState = (vboxguest_state_t *)pWriteQueue->q_ptr;
     697    PVBGR0STATE pState = (PVBGR0STATE)pWriteQueue->q_ptr;
    691698
    692699    if (pCopyResp->cp_rval)
     
    724731
    725732/**
    726  * Helper for vboxGuestSolarisHandleIOCtl.  This rather complicated-looking
     733 * Helper for vbgr0SolHandleIOCtl.  This rather complicated-looking
    727734 * code is basically the standard boilerplate for handling transparent IOCtls,
    728735 * that is, IOCtls which are not re-packed inside STREAMS IOCtls.
    729  * @copydoc vboxGuestSolarisHandleIOCtl
    730  */
    731 int vboxGuestSolarisHandleTransparentIOCtl
    732                 (queue_t *pWriteQueue, mblk_t *pMBlk,
    733                  PFNVBOXGUESTSOLARISIOCTL pfnHandler, int cCmd,
    734                  size_t cbTransparent, enum IOCTLDIRECTION enmDirection)
     736 * @copydoc vbgr0SolHandleIOCtl
     737 */
     738int vbgr0SolHandleTransparentIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
     739                                   PFNVBGR0SOLIOCTL pfnHandler, int cCmd,
     740                                   size_t cbTransparent,
     741                                   enum IOCTLDIRECTION enmDirection)
    735742{
    736743    int err = 0, rc = 0;
    737744    size_t cbData = 0;
    738     vboxguest_state_t *pState = (vboxguest_state_t *)pWriteQueue->q_ptr;
     745    PVBGR0STATE pState = (PVBGR0STATE)pWriteQueue->q_ptr;
    739746
    740747    if (   (enmDirection != NONE && !pMBlk->b_cont)
     
    774781                 
    775782/**
    776  * Helper for vboxGuestSolarisHandleIOCtl.  This rather complicated-looking
     783 * Helper for vbgr0SolHandleIOCtl.  This rather complicated-looking
    777784 * code is basically the standard boilerplate for handling any streams IOCtl.
    778  * @copydoc vboxGuestSolarisHandleIOCtl
    779  */
    780 static int vboxGuestSolarisHandleIStrIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    781                                            PFNVBOXGUESTSOLARISIOCTL pfnHandler,
    782                                            int cCmd)
     785 * @copydoc vbgr0SolHandleIOCtl
     786 */
     787static int vbgr0SolHandleIStrIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
     788                                   PFNVBGR0SOLIOCTL pfnHandler, int cCmd)
    783789{
    784790    struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
    785     vboxguest_state_t *pState = (vboxguest_state_t *)pWriteQueue->q_ptr;
     791    PVBGR0STATE pState = (PVBGR0STATE)pWriteQueue->q_ptr;
    786792    uint_t cbBuffer = pIOCBlk->ioc_count;
    787793    void *pvData = NULL;
     
    808814/**
    809815 * Handle a VUID input device IOCtl.
    810  * @copydoc FNVBOXGUESTSOLARISIOCTL
    811  */
    812 static int vboxGuestSolarisVUIDIOCtl(vboxguest_state_t *pState, int cCmd,
    813                                      void *pvData, size_t cbBuffer,
    814                                      size_t *pcbData, int *prc)
    815 {
    816     LogFlowFunc((": " /* no '\n' */));
     816 * @copydoc FNVBGR0SOLIOCTL
     817 */
     818static int vbgr0SolVUIDIOCtl(PVBGR0STATE pState, int cCmd, void *pvData,
     819                             size_t cbBuffer, size_t *pcbData, int *prc)
     820{
     821    LogFlowFunc((DEVICE_NAME ":: " /* no '\n' */));
    817822    switch (cCmd)
    818823    {
     
    851856        {
    852857            Ms_screen_resolution *pResolution = (Ms_screen_resolution *)pvData;
     858            int rc;
     859
    853860            LogFlowFunc(("MSIOSRESOLUTION\n"));
    854861            AssertReturn(cbBuffer >= sizeof(Ms_screen_resolution), EINVAL);
    855862            pState->cMaxScreenX = pResolution->width  - 1;
    856863            pState->cMaxScreenY = pResolution->height - 1;
    857             return 0;
     864            /* Note: we don't disable this again until session close. */
     865            rc = vbgr0SolSetMouseStatus(pState->pSession,
     866                                          VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
     867                                        | VMMDEV_MOUSE_NEW_PROTOCOL);
     868            if (RT_SUCCESS(rc))
     869                return 0;
     870            pState->cMaxScreenX = 0;
     871            pState->cMaxScreenY = 0;
     872            return ENODEV;
    858873        }
    859874        case MSIOBUTTONS:
     
    887902/**
    888903 * Handle a VBoxGuest IOCtl.
    889  * @copydoc FNVBOXGUESTSOLARISIOCTL
    890  */
    891 static int vboxGuestSolarisGuestIOCtl(vboxguest_state_t *pState, int cCmd,
    892                                       void *pvData, size_t cbBuffer,
    893                                       size_t *pcbData, int *prc)
     904 * @copydoc FNVBGR0SOLIOCTL
     905 */
     906static int vbgr0SolGuestIOCtl(PVBGR0STATE pState, int cCmd, void *pvData,
     907                              size_t cbBuffer, size_t *pcbData, int *prc)
    894908{
    895909    int rc = VBoxGuestCommonIOCtl(cCmd, &g_DevExt, pState->pSession, pvData, cbBuffer, pcbData);
     
    923937 * @return  corresponding solaris error code.
    924938 */
    925 int vboxGuestSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd,
    926                             void *pvArg, void **ppvResult)
     939int vbgr0SolGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg,
     940                    void **ppvResult)
    927941{
    928942    int rc = DDI_SUCCESS;
     
    949963
    950964
    951 /* Helpers for vboxGuestSolarisAttach and vboxGuestSolarisDetach. */
    952 static int vboxGuestSolarisAddIRQ(dev_info_t *pDip);
    953 static void vboxGuestSolarisRemoveIRQ(dev_info_t *pDip);
     965/* Helpers for vbgr0SolAttach and vbgr0SolDetach. */
     966static int vbgr0SolAddIRQ(dev_info_t *pDip);
     967static void vbgr0SolRemoveIRQ(dev_info_t *pDip);
    954968
    955969/**
     
    961975 * @return  corresponding solaris error code.
    962976 */
    963 int vboxGuestSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
     977int vbgr0SolAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
    964978{
    965979    LogFlow((DEVICE_NAME "::Attach\n"));
     
    10101024                             * Add IRQ of VMMDev.
    10111025                             */
    1012                             rc = vboxGuestSolarisAddIRQ(pDip);
     1026                            rc = vbgr0SolAddIRQ(pDip);
    10131027                            if (rc == DDI_SUCCESS)
    10141028                            {
     
    10421056                                else
    10431057                                    LogRel((DEVICE_NAME "::Attach: VBoxGuestInitDevExt failed.\n"));
    1044                                 vboxGuestSolarisRemoveIRQ(pDip);
     1058                                vbgr0SolRemoveIRQ(pDip);
    10451059                            }
    10461060                            else
    1047                                 LogRel((DEVICE_NAME "::Attach: vboxGuestSolarisAddIRQ failed.\n"));
     1061                                LogRel((DEVICE_NAME "::Attach: vbgr0SolAddIRQ failed.\n"));
    10481062                            ddi_regs_map_free(&g_PciMMIOHandle);
    10491063                        }
     
    10841098 * @return  corresponding solaris error code.
    10851099 */
    1086 int vboxGuestSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
     1100int vbgr0SolDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
    10871101{
    10881102    LogFlow((DEVICE_NAME "::Detach\n"));
     
    10911105        case DDI_DETACH:
    10921106        {
    1093             vboxGuestSolarisRemoveIRQ(pDip);
     1107            vbgr0SolRemoveIRQ(pDip);
    10941108            ddi_regs_map_free(&g_PciIOHandle);
    10951109            ddi_regs_map_free(&g_PciMMIOHandle);
     
    11121126
    11131127
    1114 /* Interrupt service routine installed by vboxGuestSolarisAddIRQ. */
    1115 static uint_t vboxGuestSolarisISR(char *Arg /* Actually caddr_t. */);
     1128/* Interrupt service routine installed by vbgr0SolAddIRQ. */
     1129static uint_t vbgr0SolISR(char *Arg /* Actually caddr_t. */);
    11161130
    11171131/**
     
    11211135 * @param   pDip     Pointer to the device info structure.
    11221136 */
    1123 static int vboxGuestSolarisAddIRQ(dev_info_t *pDip)
     1137static int vbgr0SolAddIRQ(dev_info_t *pDip)
    11241138{
    11251139    int IntrType = 0, rc;
     
    11581172                            {
    11591173                                /* Initialize the mutex. */
    1160                                 mutex_init(&g_IrqMtx, NULL, MUTEX_DRIVER, DDI_INTR_PRI(uIntrPriority));
     1174                                mutex_init(&g_IrqMutex, NULL, MUTEX_DRIVER, DDI_INTR_PRI(uIntrPriority));
    11611175
    11621176                                /* Assign interrupt handler functions and enable interrupts. */
    11631177                                for (i = 0; i < IntrAllocated; i++)
    11641178                                {
    1165                                     rc = ddi_intr_add_handler(g_pIntr[i], (ddi_intr_handler_t *)vboxGuestSolarisISR,
     1179                                    rc = ddi_intr_add_handler(g_pIntr[i], (ddi_intr_handler_t *)vbgr0SolISR,
    11661180                                                            NULL /* No Private Data */, NULL);
    11671181                                    if (rc == DDI_SUCCESS)
     
    12161230 * @param   pDip     Pointer to the device info structure.
    12171231 */
    1218 static void vboxGuestSolarisRemoveIRQ(dev_info_t *pDip)
     1232static void vbgr0SolRemoveIRQ(dev_info_t *pDip)
    12191233{
    12201234    unsigned i;
     
    12321246    }
    12331247    RTMemFree(g_pIntr);
    1234     mutex_destroy(&g_IrqMtx);
     1248    mutex_destroy(&g_IrqMutex);
    12351249}
    12361250
     
    12421256 * @returns DDI_INTR_CLAIMED if it's our interrupt, DDI_INTR_UNCLAIMED if it isn't.
    12431257 */
    1244 static uint_t vboxGuestSolarisISR(char *Arg /* Actually caddr_t. */)
     1258static uint_t vbgr0SolISR(char *Arg /* Actually caddr_t. */)
    12451259{
    12461260    bool fOurIRQ;
    12471261
    12481262    LogFlow((DEVICE_NAME "::ISR:\n"));
    1249     mutex_enter(&g_IrqMtx);
     1263    mutex_enter(&g_IrqMutex);
    12501264    fOurIRQ = VBoxGuestCommonISR(&g_DevExt);
    1251     mutex_exit(&g_IrqMtx);
     1265    mutex_exit(&g_IrqMutex);
    12521266    return fOurIRQ ? DDI_INTR_CLAIMED : DDI_INTR_UNCLAIMED;
    12531267}
     
    12551269
    12561270/* Helper for VBoxGuestNativeISRMousePollEvent. */
    1257 static void VBoxGuestVUIDPutAbsEvent(ushort_t cEvent, int cValue);
     1271static void vbgr0SolVUIDPutAbsEvent(PVBGR0STATE pState, ushort_t cEvent,
     1272                                    int cValue);
    12581273
    12591274/**
     
    12771292    if (RT_SUCCESS(rc))
    12781293    {
    1279         int cMaxScreenX  = g_pState->cMaxScreenX;
    1280         int cMaxScreenY  = g_pState->cMaxScreenY;
    1281 
    1282         VBoxGuestVUIDPutAbsEvent(LOC_X_ABSOLUTE,
    1283                                    pReq->pointerXPos * cMaxScreenX
    1284                                  / VMMDEV_MOUSE_RANGE_MAX);
    1285         VBoxGuestVUIDPutAbsEvent(LOC_Y_ABSOLUTE,
    1286                                    pReq->pointerYPos * cMaxScreenY
    1287                                  / VMMDEV_MOUSE_RANGE_MAX);
     1294        unsigned i;
     1295
     1296        mutex_enter(&g_StateMutex);
     1297        for (i = 1; i < MAX_OPEN_NODES; ++i)
     1298        {
     1299            int cMaxScreenX  = g_aOpenNodeStates[i].cMaxScreenX;
     1300            int cMaxScreenY  = g_aOpenNodeStates[i].cMaxScreenY;
     1301
     1302            if (!cMaxScreenX || !cMaxScreenY)
     1303                continue;
     1304            vbgr0SolVUIDPutAbsEvent(&g_aOpenNodeStates[i], LOC_X_ABSOLUTE,
     1305                                       pReq->pointerXPos * cMaxScreenX
     1306                                     / VMMDEV_MOUSE_RANGE_MAX);
     1307            vbgr0SolVUIDPutAbsEvent(&g_aOpenNodeStates[i], LOC_Y_ABSOLUTE,
     1308                                       pReq->pointerYPos * cMaxScreenY
     1309                                     / VMMDEV_MOUSE_RANGE_MAX);
     1310        }
     1311        mutex_exit(&g_StateMutex);
    12881312    }
    12891313    VbglGRFree(&pReq->header);
     
    12911315
    12921316
    1293 void VBoxGuestVUIDPutAbsEvent(ushort_t cEvent, int cValue)
    1294 {
    1295     queue_t *pReadQueue = RD(g_pState->pWriteQueue);
     1317void vbgr0SolVUIDPutAbsEvent(PVBGR0STATE pState, ushort_t cEvent,
     1318                              int cValue)
     1319{
     1320    queue_t *pReadQueue = RD(pState->pWriteQueue);
    12961321    mblk_t *pMBlk = allocb(sizeof(Firm_event, BPRI_HI));
    12971322    Firm_event *pEvent;
  • trunk/src/VBox/Additions/common/VBoxGuest/testcase/solaris.h

    r40430 r40488  
    298298#define cmn_err(...) do {} while(0)
    299299#define allocb(...) NULL
    300 #define ddi_soft_state_init(...) 0
    301 #define ddi_soft_state_fini(...) do {} while(0)
    302 #define mod_install(...) 0
    303300#define mod_remove(...) 0
    304301#define mod_info(...) 0
     
    307304#define RTR0Init(...) VINF_SUCCESS
    308305#define RTR0Term(...) do {} while(0)
     306#define RTLogCreate(...) VINF_SUCCESS
     307#define RTLogRelSetDefaultInstance(...) do {} while(0)
     308#define RTLogDestroy(...) do {} while(0)
    309309#define VBoxGuestCreateKernelSession(...) VINF_SUCCESS
    310310#define VBoxGuestCreateUserSession(...) VINF_SUCCESS
     
    357357
    358358static modctl_t s_ModCtl;
    359 
    360 #define mod_getctl(...) (&s_ModCtl)
     359static void **s_pvLinkage;
     360
     361static inline modctl_t *mod_getctl(void **linkage)
     362{
     363    s_pvLinkage = linkage;
     364    return s_pvLinkage ? &s_ModCtl : NULL;
     365}
     366
     367#define mod_install(linkage) (s_pvLinkage && ((linkage) == s_pvLinkage) ? 0 : EINVAL)
    361368
    362369#define QREADR          0x00000010
     
    366373/* API stubs with controllable logic */
    367374
    368 void *s_pSoftState[256];
    369 void *s_pInstSoftState;
    370 
    371 static void testSetInstSoftState(void *pInst, unsigned cAllocated)
    372 {
    373     unsigned i;
    374     Assert(cAllocated < RT_ELEMENTS(s_pSoftState));
    375     s_pInstSoftState = pInst;
    376     RT_ZERO(s_pSoftState);
    377     for (i = 0; i < cAllocated; ++i)
    378         s_pSoftState[i] = (void *)1;
    379 }
    380 
    381 #define ddi_get_soft_state(a, c) \
    382     (c < RT_ELEMENTS(s_pSoftState) ? s_pSoftState[c] : NULL)
    383 #define ddi_soft_state_zalloc(a, c) \
    384     (  c < RT_ELEMENTS(s_pSoftState) && (s_pSoftState[c] = s_pInstSoftState) \
    385      ? DDI_SUCCESS : DDI_FAILURE)
    386 #define ddi_soft_state_free(a, c) \
    387     (c < RT_ELEMENTS(s_pSoftState) ? s_pSoftState[c] = NULL : NULL)
    388 
    389375#endif  /* ___VBoxGuestTestCaseSolaris_h */
  • trunk/src/VBox/Additions/common/VBoxGuest/testcase/tstVBoxGuest-solaris.cpp

    r40311 r40488  
    1717 */
    1818
    19 #include <iprt/test.h>
     19#include "tstVBoxGuest-solaris.h"
    2020
    2121int main()
     
    2626        return rc;
    2727    RTTestBanner(hTest);
     28    test_init(hTest);
    2829
    2930    /*
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