VirtualBox

Changeset 16852 in vbox


Ignore:
Timestamp:
Feb 17, 2009 3:36:26 PM (16 years ago)
Author:
vboxsync
Message:

Windows guest additions: detect the emulated PS/2 mouse in the VBoxMouse.sys.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/MouseFilter/VBoxMouse.cpp

    r13837 r16852  
    119119    volatile LONG fVBGLInitFailed;
    120120    volatile LONG fHostInformed;
     121    volatile LONG fHostMouseFound;
    121122} VBoxGlobalContext;
    122123
    123 VBoxGlobalContext g_ctx = { 0, FALSE, FALSE, FALSE };
    124 
    125 BOOLEAN vboxIsVBGLInited (void)
     124static VBoxGlobalContext g_ctx = { 0, FALSE, FALSE, FALSE, FALSE };
     125
     126static BOOLEAN vboxIsVBGLInited (void)
    126127{
    127128   return InterlockedCompareExchange (&g_ctx.fVBGLInited, TRUE, TRUE) == TRUE;
    128129}
    129130
    130 BOOLEAN vboxIsVBGLInitFailed (void)
     131static BOOLEAN vboxIsVBGLInitFailed (void)
    131132{
    132133   return InterlockedCompareExchange (&g_ctx.fVBGLInitFailed, TRUE, TRUE) == TRUE;
    133134}
    134135
    135 BOOLEAN vboxIsHostInformed (void)
    136 {
    137    return InterlockedCompareExchange (&g_ctx.fVBGLInitFailed, TRUE, TRUE) == TRUE;
    138 }
    139 
    140 void vboxDeviceAdded (PDEVICE_EXTENSION devExt)
     136static BOOLEAN vboxIsHostInformed (void)
     137{
     138   return InterlockedCompareExchange (&g_ctx.fHostInformed, TRUE, TRUE) == TRUE;
     139}
     140
     141static BOOLEAN vboxIsHostMouseFound (void)
     142{
     143   return InterlockedCompareExchange (&g_ctx.fHostMouseFound, TRUE, TRUE) == TRUE;
     144}
     145
     146static void vboxDeviceAdded (PDEVICE_EXTENSION devExt)
    141147{
    142148    LONG c = InterlockedIncrement (&g_ctx.cDevicesStarted);
     
    155161                InterlockedExchange (&g_ctx.fVBGLInited, TRUE);
    156162                dprintf(("VBoxMouse::vboxDeviceStarted: guest library initialization OK\n"));
    157 
    158                 /* Mark the first device as the Host one, that is the emulated mouse.
    159                  * For this device the filter will query absolute mouse coords from the host.
    160                  * @todo: Better would be to query the device information and detect the emulated device.
    161                  */
    162                 devExt->HostMouse = TRUE;
    163163            }
    164164            else
     
    169169        }
    170170    }
    171 }
    172 
    173 void vboxDeviceRemoved (PDEVICE_EXTENSION devExt)
     171    if (!vboxIsHostMouseFound ())
     172    {
     173        WCHAR wszProperty[512];
     174        ULONG ResultLength = 0;
     175        wszProperty[0] = 0;
     176        NTSTATUS status = IoGetDeviceProperty(devExt->PDO, DevicePropertyDeviceDescription,
     177                                              sizeof (wszProperty),
     178                                              &wszProperty,
     179                                              &ResultLength);
     180        dprintf(("VBoxMouse::vboxDeviceAdded: looking for host mouse: %ls Len is %d, status %x\n",
     181                 wszProperty, ResultLength, status));
     182
     183        if (status == STATUS_SUCCESS)
     184        {
     185            UNICODE_STRING MicrosoftPS2Mouse;
     186            RtlInitUnicodeString (&MicrosoftPS2Mouse, L"Microsoft PS/2 Mouse");
     187            UNICODE_STRING DeviceDescription;
     188            RtlInitUnicodeString (&DeviceDescription, wszProperty);
     189
     190            if (RtlCompareUnicodeString (&DeviceDescription, &MicrosoftPS2Mouse, TRUE) == 0)
     191            {
     192                /* Mark the PS/2 device as the Host one, that is the emulated mouse.
     193                 * For this device the filter will query absolute mouse coords from the host.
     194                 */
     195                InterlockedExchange (&g_ctx.fHostMouseFound, TRUE);
     196                devExt->HostMouse = TRUE;
     197                dprintf(("VBoxMouse::vboxDeviceAdded: host mouse found.\n"));
     198            }
     199        }
     200    }
     201}
     202
     203static void vboxDeviceRemoved (PDEVICE_EXTENSION devExt)
    174204{
    175205    dprintf(("VBoxMouse::vboxDeviceRemoved\n"));
    176206
    177     LONG c = InterlockedIncrement (&g_ctx.cDevicesStarted);
     207    /* Save the allocated request pointer and clear the devExt. */
     208    VMMDevReqMouseStatus *reqSC = (VMMDevReqMouseStatus *)InterlockedExchangePointer (&devExt->reqSC, NULL);
     209
     210    if (devExt->HostMouse && vboxIsHostInformed ())
     211    {
     212        // tell the VMM that from now on we can't handle absolute coordinates anymore
     213        VMMDevReqMouseStatus *req = NULL;
     214
     215        int vboxRC = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_SetMouseStatus);
     216
     217        if (RT_SUCCESS(vboxRC))
     218        {
     219            req->mouseFeatures = 0;
     220            req->pointerXPos = 0;
     221            req->pointerYPos = 0;
     222
     223            vboxRC = VbglGRPerform (&req->header);
     224
     225            if (RT_FAILURE(vboxRC) || RT_FAILURE(req->header.rc))
     226            {
     227                dprintf(("VBoxMouse::vboxDeviceRemoved: ERROR communicating new mouse capabilities to VMMDev.\n"
     228                         "rc = %d, VMMDev rc = %Rrc\n", vboxRC, req->header.rc));
     229            }
     230
     231            VbglGRFree (&req->header);
     232        }
     233        else
     234        {
     235            dprintf(("VBoxMouse::vboxDeviceRemoved: the request allocation has failed.\n"));
     236        }
     237   
     238        InterlockedExchange (&g_ctx.fHostInformed, FALSE);
     239    }
     240
     241    if (reqSC)
     242    {
     243        VbglGRFree (&reqSC->header);
     244    }
     245
     246    LONG c = InterlockedDecrement (&g_ctx.cDevicesStarted);
    178247
    179248    if (c == 0)
     
    184253            InterlockedExchange (&g_ctx.fVBGLInitFailed, TRUE);
    185254
    186             /* Save the allocated request pointer and clear the devExt. */
    187             VMMDevReqMouseStatus *reqSC = devExt->reqSC;
    188             devExt->reqSC = NULL;
    189 
    190             // tell the VMM that from now on we can't handle absolute coordinates anymore
    191             VMMDevReqMouseStatus *req = NULL;
    192 
    193             int vboxRC = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_SetMouseStatus);
    194 
    195             if (RT_SUCCESS(vboxRC))
    196             {
    197                 req->mouseFeatures = 0;
    198                 req->pointerXPos = 0;
    199                 req->pointerYPos = 0;
    200 
    201                 vboxRC = VbglGRPerform (&req->header);
    202 
    203                 if (RT_FAILURE(vboxRC) || RT_FAILURE(req->header.rc))
    204                 {
    205                     dprintf(("VBoxMouse::vboxDeviceRemoved: ERROR communicating new mouse capabilities to VMMDev.\n"
    206                              "rc = %d, VMMDev rc = %Rrc\n", vboxRC, req->header.rc));
    207                 }
    208 
    209                 VbglGRFree (&req->header);
    210             }
    211 
    212             if (reqSC)
    213             {
    214                 VbglGRFree (&reqSC->header);
    215             }
    216 
    217255            VbglTerminate ();
    218256
    219257            /* The VBGL is now in the not initialized state. */
    220             InterlockedExchange (&g_ctx.fHostInformed, FALSE);
    221258            InterlockedExchange (&g_ctx.fVBGLInited, FALSE);
    222259            InterlockedExchange (&g_ctx.fVBGLInitFailed, FALSE);
     
    225262}
    226263
    227 void vboxInformHost (PDEVICE_EXTENSION devExt)
     264static void vboxInformHost (PDEVICE_EXTENSION devExt)
    228265{
    229266    dprintf (("VBoxMouse::vboxInformHost: %p\n", devExt));
     
    231268    if (vboxIsVBGLInited ())
    232269    {
    233         if (!vboxIsHostInformed ())
     270        if (devExt->HostMouse && !vboxIsHostInformed ())
    234271        {
    235272            VMMDevReqMouseStatus *req = NULL;
     
    269306            if (RT_SUCCESS(vboxRC))
    270307            {
    271                 devExt->reqSC = req;
     308                InterlockedExchangePointer (&devExt->reqSC, req);
    272309                dumpDevExt (devExt);
    273310            }
     
    297334
    298335    dprintf(("VBoxMouse::AddDevice Driver %p, PDO %p\n", Driver, PDO));
     336
     337#ifdef LOG_ENABLED
     338    WCHAR wszProperty[512];
     339    ULONG ResultLength = 0;
     340    wszProperty[0] = 0;
     341    status = IoGetDeviceProperty(PDO, DevicePropertyDeviceDescription,
     342                                 sizeof (wszProperty),
     343                                 &wszProperty,
     344                                 &ResultLength);
     345    if (status == STATUS_SUCCESS)
     346    {
     347        dprintf(("VBoxMouse::AddDevice %ls Len is %d\n", wszProperty, ResultLength));
     348    }
     349#endif /* LOG_ENABLED */
    299350
    300351    status = IoCreateDevice(Driver,
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