Index: trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp	(revision 49786)
+++ trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp	(revision 49787)
@@ -39,5 +39,5 @@
 # include <iprt/err.h>
 # include <iprt/semaphore.h>
-# include <VBox/usblib.h>
+# include <VBox/sup.h>
 #endif
 
@@ -1270,5 +1270,8 @@
     IOReturn      rc = kIOReturnError;
 
-    USBLibResumeBuiltInKeyboard();
+    /* Try to resume built-in keyboard. Abort if failed in order to avoid GUI freezes. */
+    int rc1 = SUPR3ResumeBuiltinKeyboard();
+    if (RT_FAILURE(rc1))
+        return rc1;
 
     valueRef = IOHIDValueCreateWithIntegerValue(kCFAllocatorDefault, element, 0, (fEnabled) ? 1 : 0);
@@ -1294,5 +1297,8 @@
     CFIndex       integerValue;
 
-    USBLibResumeBuiltInKeyboard();
+    /* Try to resume built-in keyboard. Abort if failed in order to avoid GUI freezes. */
+    int rc1 = SUPR3ResumeBuiltinKeyboard();
+    if (RT_FAILURE(rc1))
+        return rc1;
 
     rc = IOHIDDeviceGetValue(hidDevice, element, &valueRef);
@@ -1915,6 +1921,4 @@
     VBoxHidsState_t *pHidState;
 
-    USBLibInit();
-
     pHidState = (VBoxHidsState_t *)malloc(sizeof(VBoxHidsState_t));
     AssertReturn(pHidState, NULL);
@@ -2058,6 +2062,4 @@
     free(pHidState);
 
-    USBLibTerm();
-
     return rc2;
 #else /* !VBOX_WITH_KBD_LEDS_SYNC */
Index: trunk/src/VBox/HostDrivers/Support/SUPDrv.c
===================================================================
--- trunk/src/VBox/HostDrivers/Support/SUPDrv.c	(revision 49786)
+++ trunk/src/VBox/HostDrivers/Support/SUPDrv.c	(revision 49787)
@@ -139,4 +139,5 @@
                                                   RTCPUID idCpu, uint8_t idApic, uint64_t iTick);
 static void                 supdrvGipInitCpu(PSUPGLOBALINFOPAGE pGip, PSUPGIPCPU pCpu, uint64_t u64NanoTS);
+static int                  supdrvIOCtl_ResumeBuiltinKbd(void);
 
 
@@ -1904,4 +1905,12 @@
         }
 
+        case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_RESUME_BUILTIN_KBD):
+        {
+            /* validate */
+            REQ_CHECK_SIZES(SUP_IOCTL_RESUME_BUILTIN_KBD);
+
+            pReqHdr->rc = supdrvIOCtl_ResumeBuiltinKbd();
+            return 0;
+        }
 
         default:
@@ -6140,2 +6149,17 @@
 }
 
+/**
+ * Resume built-in keyboard on MacBook Air and Pro hosts.
+ * If there is no built-in keyboard device, return success anyway.
+ *
+ * @returns 0 on Mac OS X platform, VERR_NOT_IMPLEMENTED on the other ones.
+ */
+static int supdrvIOCtl_ResumeBuiltinKbd(void)
+{
+#if defined(RT_OS_DARWIN)
+    return supdrvDarwinResumeBuiltinKbd();
+#else
+    return VERR_NOT_IMPLEMENTED;
+#endif
+}
+
Index: trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h
===================================================================
--- trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h	(revision 49786)
+++ trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h	(revision 49787)
@@ -194,5 +194,5 @@
  *          - Remove RTSpinlockReleaseNoInts.
  */
-#define SUPDRV_IOC_VERSION                              0x001a0006
+#define SUPDRV_IOC_VERSION                              0x001a0007
 
 /** SUP_IOCTL_COOKIE. */
@@ -1438,4 +1438,15 @@
 /** @} */
 
+/** @name SUP_IOCTL_RESUME_BUILTIN_KBD
+ * Resume built-in keyboard (make sense on MacBook Air/Pro hosts only).
+ *
+ * @{
+ */
+#define SUP_IOCTL_RESUME_BUILTIN_KBD                    SUP_CTL_CODE_SIZE(35, SUP_IOCTL_RESUME_BUILTIN_KBD_SIZE)
+#define SUP_IOCTL_RESUME_BUILTIN_KBD_SIZE               sizeof(SUPREQHDR)
+#define SUP_IOCTL_RESUME_BUILTIN_KBD_SIZE_IN            sizeof(SUPREQHDR)
+#define SUP_IOCTL_RESUME_BUILTIN_KBD_SIZE_OUT           sizeof(SUPREQHDR)
+/** @} */
+
 
 #pragma pack()                          /* paranoia */
Index: trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h
===================================================================
--- trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h	(revision 49786)
+++ trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h	(revision 49787)
@@ -749,4 +749,7 @@
 #endif /* SUPDRV_WITH_MSR_PROBER */
 
+#if defined(RT_OS_DARWIN)
+int VBOXCALL    supdrvDarwinResumeBuiltinKbd(void);
+#endif
 
 /*******************************************************************************
Index: trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
===================================================================
--- trunk/src/VBox/HostDrivers/Support/SUPLib.cpp	(revision 49786)
+++ trunk/src/VBox/HostDrivers/Support/SUPLib.cpp	(revision 49787)
@@ -2133,2 +2133,25 @@
 }
 
+
+SUPR3DECL(int) SUPR3ResumeBuiltinKeyboard(void)
+{
+#ifdef RT_OS_DARWIN
+    /*
+     * Issue IOCtl to the SUPDRV kernel module.
+     */
+    SUPREQHDR Req;
+    Req.u32Cookie       = g_u32Cookie;
+    Req.u32SessionCookie= g_u32SessionCookie;
+    Req.cbIn            = SUP_IOCTL_RESUME_BUILTIN_KBD_SIZE_IN;
+    Req.cbOut           = SUP_IOCTL_RESUME_BUILTIN_KBD_SIZE_OUT;
+    Req.fFlags          = SUPREQHDR_FLAGS_DEFAULT;
+    Req.rc              = VERR_INTERNAL_ERROR;
+    int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_RESUME_BUILTIN_KBD, &Req, SUP_IOCTL_RESUME_BUILTIN_KBD_SIZE);
+    if (RT_SUCCESS(rc))
+        rc = Req.rc;
+    return rc;
+#else /* !RT_OS_DARWIN */
+    return VERR_NOT_SUPPORTED;
+#endif
+}
+
Index: trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
===================================================================
--- trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp	(revision 49786)
+++ trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp	(revision 49787)
@@ -67,4 +67,5 @@
 #include <IOKit/pwr_mgt/RootDomain.h>
 #include <IOKit/IODeviceTreeSupport.h>
+#include <IOKit/usb/IOUSBHIDDriver.h>
 
 #ifdef VBOX_WITH_HOST_VMX
@@ -1143,4 +1144,34 @@
 
 
+/**
+ * Resume built-in keyboard on MacBook Air and Pro hosts.
+ * If there is no built-in keyboard device, return success anyway.
+ */
+int VBOXCALL    supdrvDarwinResumeBuiltinKbd(void)
+{
+    /*
+     * AppleUSBTCKeyboard KEXT is responsible for built-in keyboard management.
+     * We resume keyboard by accessing to its IOService. */
+    OSDictionary *pDictionary = IOService::serviceMatching("AppleUSBTCKeyboard");
+    if (pDictionary)
+    {
+        OSIterator     *pIter;
+        IOUSBHIDDriver *pDriver;
+
+        pIter = IOService::getMatchingServices(pDictionary);
+        if (pIter)
+        {
+            while ((pDriver = (IOUSBHIDDriver *)pIter->getNextObject()))
+                pDriver->SuspendPort(false, 0);
+
+            pIter->release();
+        }
+        pDictionary->release();
+    }
+
+    return 0;
+}
+
+
 
 /**
Index: trunk/src/VBox/HostDrivers/VBoxUSB/darwin/USBLib-darwin.cpp
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxUSB/darwin/USBLib-darwin.cpp	(revision 49786)
+++ trunk/src/VBox/HostDrivers/VBoxUSB/darwin/USBLib-darwin.cpp	(revision 49787)
@@ -190,20 +190,2 @@
 }
 
-USBLIB_DECL(void) USBLibResumeBuiltInKeyboard(void)
-{
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
-    kern_return_t kr = IOConnectMethodStructureIStructureO(g_Connection,
-                                                           VBOXUSBMETHOD_RESUME_BUILTIN_KBD,
-                                                           0,
-                                                           NULL,
-                                                           NULL,
-                                                           NULL);
-#else  /* 10.5 and later */
-    kern_return_t kr = IOConnectCallStructMethod(g_Connection,
-                                                 VBOXUSBMETHOD_RESUME_BUILTIN_KBD,
-                                                 NULL, 0,
-                                                 NULL, NULL);
-#endif /* 10.5 and later */
-    AssertMsg(kr == kIOReturnSuccess, ("kr=%#x\n", kr));
-    NOREF(kr);
-}
Index: trunk/src/VBox/HostDrivers/VBoxUSB/darwin/VBoxUSB.cpp
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxUSB/darwin/VBoxUSB.cpp	(revision 49786)
+++ trunk/src/VBox/HostDrivers/VBoxUSB/darwin/VBoxUSB.cpp	(revision 49787)
@@ -60,5 +60,4 @@
 #include <IOKit/usb/IOUSBInterface.h>
 #include <IOKit/usb/IOUSBUserClient.h>
-#include <IOKit/usb/IOUSBHIDDriver.h>
 
 /* private: */
@@ -141,5 +140,4 @@
     IOReturn addFilter(PUSBFILTER pFilter, PVBOXUSBADDFILTEROUT pOut, IOByteCount cbFilter, IOByteCount *pcbOut);
     IOReturn removeFilter(uintptr_t *puId, int *prc, IOByteCount cbIn, IOByteCount *pcbOut);
-    IOReturn resumeBuiltInKbd(void *unused1, void *unused2, IOByteCount unused3, IOByteCount *unused4, void *unused5, void *unused6);
     /** @} */
 
@@ -790,12 +788,4 @@
             sizeof(int)                                             /* count1 - size of the output (rc) */
         },
-        /* [VBOXUSBMETHOD_RESUME_BUILTIN_KBD] = */
-        {
-            (IOService *)0,                                         /* object */
-            (IOMethod)&org_virtualbox_VBoxUSBClient::resumeBuiltInKbd, /* func */
-            kIOUCScalarIScalarO,                                    /* flags - scalar input (count0) and scalar output (count1) */
-            0,                                                      /* count0 - # of input parameters */
-            0                                                       /* count1 - # of output parameters */
-        },
     };
 
@@ -903,40 +893,4 @@
 }
 
-IOReturn
-org_virtualbox_VBoxUSBClient::resumeBuiltInKbd(void *unused1, void *unused2, IOByteCount unused3, IOByteCount *unused4, void *unused5, void *unused6)
-{
-    (void)unused1;
-    (void)unused2;
-    (void)unused3;
-    (void)unused4;
-    (void)unused5;
-    (void)unused6;
-
-    OSDictionary *pDictionary;
-
-    VBOXUSB_LOCK();
-
-    pDictionary = IOService::serviceMatching("AppleUSBTCKeyboard");
-    if (pDictionary)
-    {
-        OSIterator     *pIter;
-        IOUSBHIDDriver *pDriver;
-
-        pIter = IOService::getMatchingServices(pDictionary);
-        if (pIter)
-        {
-            while ((pDriver = (IOUSBHIDDriver *)pIter->getNextObject()))
-                pDriver->SuspendPort(false, 0);
-
-            pIter->release();
-        }
-
-        pDictionary->release();
-    }
-
-    VBOXUSB_UNLOCK();
-
-    return kIOReturnSuccess;
-}
 
 /**
Index: trunk/src/VBox/HostDrivers/VBoxUSB/darwin/VBoxUSBInterface.h
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxUSB/darwin/VBoxUSBInterface.h	(revision 49786)
+++ trunk/src/VBox/HostDrivers/VBoxUSB/darwin/VBoxUSBInterface.h	(revision 49787)
@@ -30,6 +30,4 @@
     /** org_virtualbox_VBoxUSBClient::removeFilter */
     VBOXUSBMETHOD_REMOVE_FILTER,
-    /** org_virtualbox_VBoxUSBClient::resumeBuiltInKbd */
-    VBOXUSBMETHOD_RESUME_BUILTIN_KBD,
     /** End/max. */
     VBOXUSBMETHOD_END
