VirtualBox

Changeset 49012 in vbox


Ignore:
Timestamp:
Oct 9, 2013 3:36:39 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
89754
Message:

OS X host: leds sync: fixed SEGFAULT when cached device was detached physically.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp

    r48978 r49012  
    2222*******************************************************************************/
    2323#define LOG_GROUP LOG_GROUP_GUI
    24 //#define VBOX_WITH_KBD_LEDS_SYNC
     24#define VBOX_WITH_KBD_LEDS_SYNC
    2525
    2626#include "DarwinKeyboard.h"
     
    292292#ifdef VBOX_WITH_KBD_LEDS_SYNC
    293293/* HID LEDs synchronization data: LED states. */
    294 typedef struct VBoxHidLeds_t {
     294typedef struct VBoxKbdState_t {
    295295    bool             fNumLockOn;
    296296    bool             fCapsLockOn;
    297297    bool             fScrollLockOn;
    298 } VBoxHidLeds_t;
     298    bool             fAttached;
     299} VBoxKbdState_t;
    299300
    300301/* HID LEDs synchronization data: IOKit specific data. */
     
    302303    IOHIDManagerRef     hidManagerRef;
    303304    IOHIDDeviceRef     *hidDevicesCollection;
    304     VBoxHidLeds_t      *hidLedsCollection;
     305    VBoxKbdState_t      *hidLedsCollection;
    305306    CFIndex             cDevices;
    306307    CFMachPortRef       pTapRef;
     
    309310
    310311/* A *sync* between IOKit and Carbon callbacks. */
    311 static VBoxHidLeds_t *g_LastTouchedState;
     312static VBoxKbdState_t *g_LastTouchedState;
    312313#endif // !VBOX_WITH_KBD_LEDS_SYNC
    313314
     
    13791380}
    13801381
     1382static void darwinHidRemovalCallback(void *pData, IOReturn unused, void *unused1)
     1383{
     1384    (void)unused;
     1385    (void)unused1;
     1386
     1387    VBoxKbdState_t *pState = (VBoxKbdState_t *)pData;
     1388
     1389    if (pState)
     1390    {
     1391        pState->fAttached = false;
     1392    }
     1393}
     1394
    13811395/** IOKit key press callback. Triggered before Carbon callback. */
    13821396static void darwinHidInputCallback(void *pData, IOReturn unused, void *unused1, IOHIDValueRef valueRef)
     
    13951409                {
    13961410                    Log2(("A modifier key has been pressed\n"));
    1397                     g_LastTouchedState = (VBoxHidLeds_t *)pData;
     1411                    g_LastTouchedState = (VBoxKbdState_t *)pData;
    13981412                }
    13991413
     
    15571571                        if (hidsState->hidDevicesCollection)
    15581572                        {
    1559                             hidsState->hidLedsCollection = (VBoxHidLeds_t *)malloc((size_t)hidsState->cDevices * sizeof(VBoxHidLeds_t));
     1573                            hidsState->hidLedsCollection = (VBoxKbdState_t *)malloc((size_t)hidsState->cDevices * sizeof(VBoxKbdState_t));
    15601574                            if (hidsState->hidLedsCollection)
    15611575                            {
     
    15851599                                            }
    15861600
     1601                                            /* Mark a device as currently attached. If device will be removed (physically)
     1602                                             * before current state is applied (by DarwinHidDevicesApplyAndReleaseLedsState()), we mark
     1603                                             * it as detached one in a removal callback. We cannot access device which was detached
     1604                                             * because IOKit released the resources and this will trigger a SEGFAULT. */
     1605                                            hidsState->hidLedsCollection[i].fAttached = true;
     1606
     1607                                            /* Register per-device removal callback */
     1608                                            IOHIDDeviceRegisterRemovalCallback(hidsState->hidDevicesCollection[i], darwinHidRemovalCallback, (void *)&hidsState->hidLedsCollection[i]);
     1609
    15871610                                            /* Register per-device input callback */
    15881611                                            IOHIDDeviceRegisterInputValueCallback(hidsState->hidDevicesCollection[i], darwinHidInputCallback, (void *)&hidsState->hidLedsCollection[i]);
     
    16571680            {
    16581681                /* Cycle through supported devices only. */
    1659                 if (IOHIDDeviceConformsTo(hidsState->hidDevicesCollection[i], kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)
     1682                if (hidsState->hidLedsCollection[i].fAttached
     1683                 && IOHIDDeviceConformsTo(hidsState->hidDevicesCollection[i], kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)
    16601684                 && darwinHidDeviceSupported(hidsState->hidDevicesCollection[i]))
    16611685                {
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