summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp')
-rw-r--r--src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp b/src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp
index e76eb5f8..f3b568f7 100644
--- a/src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp
+++ b/src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp
@@ -50,6 +50,7 @@
#include <iprt/assert.h>
#include <iprt/critsect.h>
+#include <iprt/ldr.h>
#include <iprt/list.h>
#include <iprt/mem.h>
#include <iprt/once.h>
@@ -74,6 +75,17 @@
typedef struct USBPROXYIFOSX *PUSBPROXYIFOSX;
+/** @name IOKitLib declarations and definitions for IOServiceAuthorize() which is not available in all SDKs.
+ * @{ */
+/** IOServiceAuthorize in IOKit. */
+typedef kern_return_t (* PFNIOSERVICEAUTHORIZE)(io_service_t, uint32_t options);
+
+#ifndef kIOServiceInteractionAllowed
+# define kIOServiceInteractionAllowed 0x00000001
+#endif
+/** @} */
+
+
/**
* A low latency isochronous buffer.
*
@@ -278,6 +290,8 @@ static CFStringRef g_pRunLoopMode = NULL;
/** The IO Master Port.
* Not worth cleaning up. */
static mach_port_t g_MasterPort = MACH_PORT_NULL;
+/** Pointer to the IOServiceAuthorize() method. */
+static PFNIOSERVICEAUTHORIZE g_pfnIOServiceAuthorize = NULL;
/**
@@ -291,7 +305,17 @@ static DECLCALLBACK(int32_t) usbProxyDarwinInitOnce(void *pvUser1)
{
RT_NOREF(pvUser1);
- int rc;
+ RTLDRMOD hMod = NIL_RTLDRMOD;
+ int rc = RTLdrLoadEx("/System/Library/Frameworks/IOKit.framework/Versions/Current/IOKit", &hMod, RTLDRLOAD_FLAGS_NO_SUFFIX | RTLDRLOAD_FLAGS_NO_UNLOAD,
+ NULL);
+ if (RT_SUCCESS(rc))
+ {
+ rc = RTLdrGetSymbol(hMod, "IOServiceAuthorize", (void **)&g_pfnIOServiceAuthorize);
+ if (RT_FAILURE(rc))
+ LogRel(("USB: Failed to resolve IOServiceAuthorize(), capturing USB devices might not work (%Rrc)\n", rc));
+ RTLdrClose(hMod);
+ }
+
kern_return_t krc = IOMasterPort(MACH_PORT_NULL, &g_MasterPort);
if (krc == KERN_SUCCESS)
{
@@ -1215,6 +1239,17 @@ static DECLCALLBACK(int) usbProxyDarwinOpen(PUSBPROXYDEV pProxyDev, const char *
}
/*
+ * Ask for authorization (which only works with the com.apple.vm.device-access entitlement).
+ */
+ if (g_pfnIOServiceAuthorize)
+ {
+ irc = g_pfnIOServiceAuthorize(USBDevice, kIOServiceInteractionAllowed);
+ if (irc != kIOReturnSuccess)
+ LogRel(("USB: Failed to get authorization for device '%s', capturing the device might not work: irc=%#x\n",
+ pszAddress, irc));
+ }
+
+ /*
* Create a plugin interface for the device and query its IOUSBDeviceInterface.
*/
SInt32 Score = 0;