manymouse icon indicating copy to clipboard operation
manymouse copied to clipboard

MacOS 14.7 (Sonoma) reports no mice detected, IOHIDDeviceOpen() failing.

Open mittonk opened this issue 11 months ago • 3 comments

% ./detect_mice 
No mice detected!
% uname -a
Darwin mittonk-air21.local 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:49:46 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T8103 arm64

Not sure if this is an Apple OS change, or just my machine's permissions.

IOHIDDeviceOpen() is failing:

Process 96016 launched: '/Users/mittonk/play/manymouse/detect_mice' (arm64)
2025-01-16 12:19:32.013972-0500 detect_mice[96016:6540662] [default] 0x100000891: TCC deny IOHIDDeviceOpen
2025-01-16 12:19:32.014226-0500 detect_mice[96016:6540662] [default] 0x100000891: TCC deny IOHIDDeviceOpen
Process 96016 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100002fa0 detect_mice`config_hidmanager(dict=2 key/value pairs) at macosx_hidmanager.c:284:29
   281          MouseStruct *mouse = &mice[i];
   282          IOHIDDeviceRef dev = mouse->device;
   283          IOReturn status = IOHIDDeviceOpen(dev, HIDOPS);
-> 284          if (IOHIDDeviceOpen(dev, HIDOPS) != kIOReturnSuccess)
   285          {
   286              mouse->device = NULL;  /* oh well. */
   287              mouse->logical = -1;
Target 0: (detect_mice) stopped.
(lldb) p status
(IOReturn) -536870174
(lldb) p/x status
(IOReturn) 0xe00002e2

mittonk avatar Jan 16 '25 17:01 mittonk

default	12:46:53.970341-0500	detect_mice	[0x6000027d8000] activating connection: mach=true listener=false peer=false name=com.apple.tccd.system
default	12:46:53.971476-0500	tccd	AUTHREQ_ATTRIBUTION: msgID=96206.1, attribution={responsible={TCCDProcess: identifier=com.apple.Terminal, pid=882, auid=501, euid=501, responsible_path=/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal, binary_path=/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal}, requesting={TCCDProcess: identifier=detect_mice, pid=96206, auid=501, euid=501, binary_path=/Users/mittonk/play/manymouse/detect_mice}, },
default	12:46:53.989008-0500	detect_mice	[0x6000027d8000] invalidated after the last release of the connection object
error	12:46:53.989659-0500	detect_mice	0x100000891: TCC deny IOHIDDeviceOpen
error	12:46:53.989763-0500	detect_mice	0x100000891: TCC deny IOHIDDeviceOpen
default	12:46:53.989779-0500	detect_mice	[0x152e06540] activating connection: mach=true listener=false peer=false name=com.apple.gamepolicyd.app
error	12:46:53.989783-0500	detect_mice	0x100000891: TCC deny IOHIDDeviceOpen

mittonk avatar Jan 16 '25 17:01 mittonk

OK, I see two parts:

  1. "Input Monitoring" privileges need to be enabled for detect_mice in System Settings.
  2. Getting my head around the TCC sandbox rules, but running through lldb finds mice:
mittonk@mittonk-air21 manymouse % lldb detect_mice 
(lldb) target create "detect_mice"
Current executable set to '/Users/mittonk/play/manymouse/detect_mice' (arm64).
(lldb) r
Process 96322 launched: '/Users/mittonk/play/manymouse/detect_mice' (arm64)
ManyMouse driver: Mac OS X 10.5+ HID Manager
#0: Apple Internal Keyboard / Trackpad
Process 96322 exited with status = 0 (0x00000000) 
(lldb) q

mittonk@mittonk-air21 manymouse % ./detect_mice 
No mice detected!

mittonk avatar Jan 16 '25 17:01 mittonk

Giving "Input Monitoring" privileges to Terminal makes these command-line tests work as expected.

At least a workaround, maybe the whole solution.

mittonk avatar Jan 16 '25 18:01 mittonk