VirtualBox

Ignore:
Timestamp:
May 3, 2024 12:33:29 PM (9 months ago)
Author:
vboxsync
Message:

Devices/USB/USBProxyDevice-darwin.cpp: Resolve IOServiceAuthorize() dynamically because it is not exposed in older versions of macOS, bugref:10684

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/darwin/USBProxyDevice-darwin.cpp

    r104502 r104503  
    5151#include <iprt/assert.h>
    5252#include <iprt/critsect.h>
     53#include <iprt/ldr.h>
    5354#include <iprt/list.h>
    5455#include <iprt/mem.h>
     
    6667/** An experiment... */
    6768//#define USE_LOW_LATENCY_API 1
    68 /** Some older SDKs we build with don't know about this. */
    69 #define OSX_kIOServiceInteractionAllowed 0x00000001
    7069
    7170
     
    7574/** Forward declaration of the Darwin interface structure. */
    7675typedef struct USBPROXYIFOSX *PUSBPROXYIFOSX;
     76
     77
     78/** @name IOKitLib declarations and definitions for IOServiceAuthorize() which is not available in all SDKs.
     79 * @{  */
     80/** IOServiceAuthorize in IOKit. */
     81typedef kern_return_t (* PFNIOSERVICEAUTHORIZE)(io_service_t, uint32_t options);
     82
     83#ifndef kIOServiceInteractionAllowed
     84# define kIOServiceInteractionAllowed 0x00000001
     85#endif
     86/** @} */
    7787
    7888
     
    281291 * Not worth cleaning up.  */
    282292static mach_port_t  g_MasterPort = MACH_PORT_NULL;
     293/** Pointer to the IOServiceAuthorize() method. */
     294static PFNIOSERVICEAUTHORIZE g_pfnIOServiceAuthorize = NULL;
    283295
    284296
     
    294306    RT_NOREF(pvUser1);
    295307
    296     int rc;
     308    RTLDRMOD hMod = NIL_RTLDRMOD;
     309    int rc = RTLdrLoadEx("/System/Library/Frameworks/IOKit.framework/Versions/Current/IOKit", &hMod, RTLDRLOAD_FLAGS_NO_SUFFIX | RTLDRLOAD_FLAGS_NO_UNLOAD,
     310                         NULL);
     311    if (RT_SUCCESS(rc))
     312    {
     313        rc = RTLdrGetSymbol(hMod, "IOServiceAuthorize", (void **)&g_pfnIOServiceAuthorize);
     314        if (RT_FAILURE(rc))
     315            LogRel(("USB: Failed to resolve IOServiceAuthorize(), capturing USB devices might not work (%Rrc)\n", rc));
     316        RTLdrClose(hMod);
     317    }
     318
    297319    RT_GCC_NO_WARN_DEPRECATED_BEGIN
    298320    kern_return_t krc = IOMasterPort(MACH_PORT_NULL, &g_MasterPort);  /* Deprecated since 12.0. */
     
    12221244     * Ask for authorization (which only works with the com.apple.vm.device-access entitlement).
    12231245     */
    1224     irc = IOServiceAuthorize(USBDevice, OSX_kIOServiceInteractionAllowed);
    1225     if (irc != kIOReturnSuccess)
    1226         LogRel(("Failed to get device authorization, capturing the device might now work: irc=%#x\n", irc));
     1246    if (g_pfnIOServiceAuthorize)
     1247    {
     1248        irc = g_pfnIOServiceAuthorize(USBDevice, kIOServiceInteractionAllowed);
     1249        if (irc != kIOReturnSuccess)
     1250            LogRel(("USB: Failed to get authorization for device '%s', capturing the device might now work: irc=%#x\n",
     1251                    pszAddress, irc));
     1252    }
    12271253
    12281254    /*
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