Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: SIGILL/SIGSEGV when exiting process #142

Closed
SomberNight opened this issue Aug 4, 2022 · 3 comments · Fixed by #150
Closed

macOS: SIGILL/SIGSEGV when exiting process #142

SomberNight opened this issue Aug 4, 2022 · 3 comments · Fixed by #150

Comments

@SomberNight
Copy link
Contributor

On macOS, when using hidapi in a thread other than the main thread, during shutdown of the python process, the application segfaults. AFAICS, depending on the macOS version, it might be a SIGILL or a SIGSEGV.

I've tested on macOS 10.15.3, 11.3, and 12.5, and all exhibit the issue.
Also tested on recent Ubuntu and Win10, both look unaffected.

All recent hidapi releases are affected since 0.11.0 (so last one that works well is 0.10.1).

Simple test case script:

import threading
import hid

def f():
  e = hid.enumerate(0,0)
  print(e)

t = threading.Thread(target=f)
t.start()
t.join()

After running script, OS crash reporter window pops up:

macOS crash reporter. "Python quit unexpectedly"

pic1

#128 and #130 look potentially related.


user@users-iMac tmp % python3 -m venv env
user@users-iMac tmp % source env/bin/activate
(env) user@users-iMac tmp % pip install --upgrade pip setuptools wheel
[... SNIP ...]
Successfully installed pip-22.2.2 setuptools-63.4.1 wheel-0.37.1
(env) user@users-iMac tmp % python3 --version
Python 3.9.11
(env) user@users-iMac tmp % pip freeze --all
pip==22.2.2
setuptools==63.4.1
wheel==0.37.1
(env) user@users-iMac tmp % sw_vers
ProductName:	macOS
ProductVersion:	12.5
BuildVersion:	21G72
(env) user@users-iMac tmp % cat f2.py     
import threading

import hid


def f():
  #import hid
  e = hid.enumerate(0,0)
  print(e)


t = threading.Thread(target=f)
t.start()
t.join()

hidapi 0.10.1 works well
(env) user@users-iMac tmp % pip install "hidapi==0.10.1"
Collecting hidapi==0.10.1
  Using cached hidapi-0.10.1-cp39-cp39-macosx_10_9_x86_64.whl (45 kB)
Requirement already satisfied: setuptools>=19.0 in ./env/lib/python3.9/site-packages (from hidapi==0.10.1) (63.4.1)
Installing collected packages: hidapi
Successfully installed hidapi-0.10.1

(env) user@users-iMac tmp % python3 f2.py
[{'path': b'IOService:/AppleACPIPlatformExpert/[... SNIP ...], 'usage_page': 1, 'usage': 1, 'interface_number': 0}]

(env) user@users-iMac tmp % pip uninstall hidapi
Found existing installation: hidapi 0.10.1
Uninstalling hidapi-0.10.1:
  Would remove:
    /Users/user/wspace/tmp/env/lib/python3.9/site-packages/hid.cpython-39-darwin.so
    /Users/user/wspace/tmp/env/lib/python3.9/site-packages/hidapi-0.10.1.dist-info/*
Proceed (Y/n)? Y
  Successfully uninstalled hidapi-0.10.1

With hidapi 0.11.0+, note the zsh: illegal hardware instruction line

hidapi==0.11.0
(env) user@users-iMac tmp % pip install "hidapi==0.11.0"
Collecting hidapi==0.11.0
  Using cached hidapi-0.11.0-cp39-cp39-macosx_10_9_x86_64.whl (48 kB)
Requirement already satisfied: setuptools>=19.0 in ./env/lib/python3.9/site-packages (from hidapi==0.11.0) (63.4.1)
Installing collected packages: hidapi
Successfully installed hidapi-0.11.0

(env) user@users-iMac tmp % python3 f2.py               
[{'path': b'IOService:/AppleACPIPlatformExpert/[... SNIP ...], 'usage_page': 1, 'usage': 1, 'interface_number': 0}]
zsh: illegal hardware instruction  python3 f2.py

(env) user@users-iMac tmp % pip uninstall hidapi        
Found existing installation: hidapi 0.11.0
[... SNIP ...]
  Successfully uninstalled hidapi-0.11.0
hidapi==0.11.0.post2
(env) user@users-iMac tmp % pip install "hidapi==0.11.0.post2"
Collecting hidapi==0.11.0.post2
  Downloading hidapi-0.11.0.post2-cp39-cp39-macosx_10_9_x86_64.whl (48 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.3/48.3 kB 1.6 MB/s eta 0:00:00
Requirement already satisfied: setuptools>=19.0 in ./env/lib/python3.9/site-packages (from hidapi==0.11.0.post2) (63.4.1)
Installing collected packages: hidapi
Successfully installed hidapi-0.11.0.post2

(env) user@users-iMac tmp % python3 f2.py                     
[{'path': b'IOService:/AppleACPIPlatformExpert/[... SNIP ...], 'usage_page': 1, 'usage': 1, 'interface_number': 0}]
zsh: illegal hardware instruction  python3 f2.py

(env) user@users-iMac tmp % pip uninstall hidapi              
Found existing installation: hidapi 0.11.0.post2
[... SNIP ...]
  Successfully uninstalled hidapi-0.11.0.post2
hidapi==0.11.2
(env) user@users-iMac tmp % pip install "hidapi==0.11.2"      
Collecting hidapi==0.11.2
  Using cached hidapi-0.11.2-cp39-cp39-macosx_10_9_x86_64.whl (57 kB)
Requirement already satisfied: setuptools>=19.0 in ./env/lib/python3.9/site-packages (from hidapi==0.11.2) (63.4.1)
Installing collected packages: hidapi
Successfully installed hidapi-0.11.2

(env) user@users-iMac tmp % python3 f2.py               
[{'path': b'DevSrvsID:4294967951', 'vendor_id': 33006, [... SNIP ...], 'usage_page': 1, 'usage': 6, 'interface_number': 0}]
zsh: illegal hardware instruction  python3 f2.py

(env) user@users-iMac tmp % pip uninstall hidapi        
Found existing installation: hidapi 0.11.2
[... SNIP ...]
  Successfully uninstalled hidapi-0.11.2
hidapi==0.12.0.post2
(env) user@users-iMac tmp % pip install "hidapi==0.12.0.post2"
Collecting hidapi==0.12.0.post2
  Using cached hidapi-0.12.0.post2-cp39-cp39-macosx_10_9_x86_64.whl (57 kB)
Requirement already satisfied: setuptools>=19.0 in ./env/lib/python3.9/site-packages (from hidapi==0.12.0.post2) (63.4.1)
Installing collected packages: hidapi
Successfully installed hidapi-0.12.0.post2

(env) user@users-iMac tmp % python3 f2.py                     
[{'path': b'DevSrvsID:4294967951', 'vendor_id': 33006, [... SNIP ...], 'usage_page': 1, 'usage': 6, 'interface_number': 0}]
zsh: illegal hardware instruction  python3 f2.py
(env) user@users-iMac tmp % 
@mcuee
Copy link

mcuee commented May 10, 2023

@SomberNight

Have you tried the latest cython-hidapi which uses hidapi 0.13.1 release?

@SomberNight
Copy link
Contributor Author

I have just tested with hidapi==0.13.1 on a x86_64 macOS 12.5 vm. Can still reproduce.

shell history/commands
user@users-iMac tmp % python3 -m venv env 
user@users-iMac tmp % source env/bin/activate 
(env) user@users-iMac tmp % pip install --upgrade pip setuptools wheel
[... SNIP ...]
Successfully installed pip-23.1.2 setuptools-67.7.2 wheel-0.40.0
(env) user@users-iMac tmp % python3 --version
Python 3.9.11
(env) user@users-iMac tmp % pip freeze --all
pip==23.1.2
setuptools==67.7.2
wheel==0.40.0
(env) user@users-iMac tmp % sw_vers
ProductName:	macOS
ProductVersion:	12.5
BuildVersion:	21G72
(env) user@users-iMac tmp % cat f2.py 
import threading
import hid

def f():
  e = hid.enumerate(0,0)
  print(e)

t = threading.Thread(target=f)
t.start()
t.join()

(env) user@users-iMac tmp % pip install hidapi==0.13.1
Collecting hidapi==0.13.1
  Downloading hidapi-0.13.1-cp39-cp39-macosx_10_9_x86_64.whl (60 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.4/60.4 kB 294.7 kB/s eta 0:00:00
Requirement already satisfied: setuptools>=19.0 in ./env/lib/python3.9/site-packages (from hidapi==0.13.1) (67.7.2)
Installing collected packages: hidapi
Successfully installed hidapi-0.13.1

(env) user@users-iMac tmp % python3 f2.py 
[{'path': b'DevSrvsID:4294967958', 'vendor_id': 33006, [... SNIP ...], 'usage_page': 1, 'usage': 1, 'interface_number': 0}]
zsh: illegal hardware instruction  python3 f2.py

(env) user@users-iMac tmp % 

And btw here is the "report" from the macOS built-in crash reporter that it wants to send to the mothership (Apple):

OS-level crash report
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               Python [993]
Path:                  /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python
Identifier:            org.python.python
Version:               3.9.11 (3.9.11)
Code Type:             X86-64 (Native)
Parent Process:        zsh [470]
Responsible:           Terminal [379]
User ID:               501

Date/Time:             2023-05-10 13:45:13.7426 +0000
OS Version:            macOS 12.5 (21G72)
Report Version:        12
Anonymous UUID:        D3F5C0EB-FD0F-4864-8733-5551B8EBCCC7


Time Awake Since Boot: 820 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 4 Illegal instruction: 4
Terminating Process:   exc handler [993]

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   CoreFoundation                	    0x7ff80d45761e _CFAssertMismatchedTypeID + 110
1   CoreFoundation                	    0x7ff80d33fa35 CFRunLoopRemoveSource + 670
2   IOKit                         	    0x7ff80fb793d5 IOHIDDeviceUnscheduleFromRunLoop + 108
3   IOKit                         	    0x7ff80fb7d66e __IOHIDManagerDeviceApplier + 556
4   CoreFoundation                	    0x7ff80d2e9cf2 __CFSetApplyFunction_block_invoke + 18
5   CoreFoundation                	    0x7ff80d2e9b5f CFBasicHashApply + 119
6   CoreFoundation                	    0x7ff80d2e9aa9 CFSetApplyFunction + 131
7   IOKit                         	    0x7ff80fb7c116 __ApplyToDevices + 105
8   IOKit                         	    0x7ff80fb7c206 IOHIDManagerUnscheduleFromRunLoop + 75
9   IOKit                         	    0x7ff80fb7c160 IOHIDManagerClose + 34
10  hid.cpython-39-darwin.so      	       0x109569807 hid_exit + 23
11  hid.cpython-39-darwin.so      	       0x10956962d __pyx_pw_11cfunc_dot_to_py_27__Pyx_CFunc_int_______to_py_1wrap + 13
12  Python                        	       0x1098d8adc _PyObject_Call + 140
13  Python                        	       0x1099ae989 _PyEval_EvalFrameDefault + 27321
14  Python                        	       0x1099b1b03 _PyEval_EvalCode + 2611
15  Python                        	       0x1098d8cb1 _PyFunction_Vectorcall + 289
16  Python                        	       0x1098d8415 _PyObject_FastCallDictTstate + 293
17  Python                        	       0x1098d8f98 _PyObject_Call_Prepend + 152
18  Python                        	       0x1099314e7 slot_tp_call + 167
19  Python                        	       0x1098d85b7 _PyObject_MakeTpCall + 359
20  Python                        	       0x1099b0e9c call_function + 876
21  Python                        	       0x1099ae34b _PyEval_EvalFrameDefault + 25723
22  Python                        	       0x1098d8d28 function_code_fastcall + 104
23  Python                        	       0x1098dadb2 method_vectorcall + 274
24  Python                        	       0x109a515b1 atexit_callfuncs + 113
25  Python                        	       0x1099f4d4e Py_FinalizeEx + 78
26  Python                        	       0x109a172b0 Py_RunMain + 2240
27  Python                        	       0x109a1758f pymain_main + 223
28  Python                        	       0x109a1778b Py_BytesMain + 43
29  dyld                          	       0x10bda652e start + 462

Thread 1:
0   libsystem_pthread.dylib       	    0x7ff80d254f48 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib       	    0x7ff80d254f48 start_wqthread + 0


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000049  rbx: 0x00007ff80d664f20  rcx: 0xde8e4da50f0c0034  rdx: 0x0000000000000000
  rdi: 0x0000000000000000  rsi: 0x00007ff80d665e58  rbp: 0x00007ff7b6b00880  rsp: 0x00007ff7b6b00750
   r8: 0x00007ff7b6b004b0   r9: 0x00007ff80d665e58  r10: 0x0000000000000000  r11: 0x00007ff7b6b007a8
  r12: 0x00007ff7b6b00760  r13: 0x0000600000e04300  r14: 0x0000000000000000  r15: 0x000000000000002b
  rip: 0x00007ff80d45761e  rfl: 0x0000000000010202  cr2: 0x0000000109931440
  
Logical CPU:     1
Error Code:      0x00000000 
Trap Number:     6

Thread 0 instruction stream:
  10 01 00 00 49 89 f6 49-89 ff e8 07 41 f9 ff 48  ....I..I....A..H
  89 c3 48 85 c0 4c 8d 25-2c d2 20 00 49 0f 44 dc  ..H..L.%,. .I.D.
  4c 89 f7 e8 ee 40 f9 ff-48 85 c0 49 0f 44 c4 48  [email protected]
  89 04 24 48 8d 15 22 e8-20 00 4c 8d a5 e0 fe ff  ..$H..". .L.....
  ff be ff 00 00 00 4c 89-e7 4c 89 f9 49 89 d8 4d  ......L..L..I..M
  89 f1 31 c0 e8 6f a4 00-00 4c 89 25 f2 c3 55 41  ..1..o...L.%..UA
 [0f]0b 90 48 8d 05 31 e8-20 00 48 89 05 e1 c3 55  ...H..1. .H....U	<==
  41 0f 0b 48 8d 05 4c ea-20 00 48 89 05 d1 c3 55  A..H..L. .H....U
  41 0f 0b 48 8d 05 3c ea-20 00 48 89 05 c1 c3 55  A..H..<. .H....U
  41 0f 0b 48 8d 05 2c ea-20 00 48 89 05 b1 c3 55  A..H..,. .H....U
  41 0f 0b 48 8d 05 7c e9-20 00 48 89 05 a1 c3 55  A..H..|. .H....U
  41 0f 0b 48 8d 05 6c e9-20 00 48 89 05 91 c3 55  A..H..l. .H....U

Binary Images:
    0x7ff80d2a0000 -     0x7ff80d7a0fff com.apple.CoreFoundation (6.9) <32d2d187-4e52-376e-bc07-245a48c37e2b> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
    0x7ff80fb3b000 -     0x7ff80fbf0fff com.apple.framework.IOKit (2.0.2) <e9f24202-6a37-30c2-8431-8ba7cc02812f> /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
       0x10955e000 -        0x10956dfff hid.cpython-39-darwin.so (*) <eabdb5f7-5637-3d10-b443-00b105e714dc> /Users/USER/*/hid.cpython-39-darwin.so
       0x109899000 -        0x109b01fff org.python.python (3.9.11, (c) 2001-2021 Python Software Foundation.) <ef9cc1f4-5991-3213-9a9e-e68c578b6c1b> /Library/Frameworks/Python.framework/Versions/3.9/Python
       0x10bda1000 -        0x10be0cfff dyld (*) <f71fb3ca-5fcc-3577-9457-b047888a46d1> /usr/lib/dyld
    0x7ff80d253000 -     0x7ff80d25efff libsystem_pthread.dylib (*) <f32b6d06-b156-3da0-b086-a31cf011362b> /usr/lib/system/libsystem_pthread.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=834.5M resident=0K(0%) swapped_out_or_unallocated=834.5M(100%)
Writable regions: Total=568.3M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=568.3M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Activity Tracing                   256K        1 
Kernel Alloc Once                    8K        1 
MALLOC                           166.7M       30 
MALLOC guard page                   16K        4 
MALLOC_LARGE (reserved)            256K        2         reserved VM address space (unallocated)
MALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)
STACK GUARD                         12K        3 
Stack                             17.0M        3 
VM_ALLOCATE                          8K        2 
__DATA                            15.6M      238 
__DATA_CONST                      10.9M      143 
__DATA_DIRTY                       485K       85 
__FONT_DATA                          4K        1 
__LINKEDIT                       646.5M       12 
__OBJC_RO                         82.8M        1 
__OBJC_RW                         3200K        2 
__TEXT                           188.1M      254 
__UNICODE                          592K        1 
dyld private memory               1024K        1 
mapped file                         48K        1 
shared memory                       12K        2 
===========                     =======  ======= 
TOTAL                              1.5G      788 
TOTAL, minus reserved VM space     1.1G      788 



-----------
Full Report
-----------

{"app_name":"Python","timestamp":"2023-05-10 13:45:13.00 +0000","app_version":"3.9.11","slice_uuid":"3b22d1c8-4c14-325f-af90-727271966b20","build_version":"3.9.11","platform":1,"bundleID":"org.python.python","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 12.5 (21G72)","incident_id":"8F73114C-1041-4AFC-9C46-3D3718C2D1C1","name":"Python"}
{
  "uptime" : 820,
  "procLaunch" : "2023-05-10 13:45:13.3416 +0000",
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "iMac11,3",
  "procStartAbsTime" : 821029939408,
  "coalitionID" : 409,
  "osVersion" : {
    "train" : "macOS 12.5",
    "build" : "21G72",
    "releaseType" : "User"
  },
  "captureTime" : "2023-05-10 13:45:13.7426 +0000",
  "incident" : "8F73114C-1041-4AFC-9C46-3D3718C2D1C1",
  "bug_type" : "309",
  "pid" : 993,
  "procExitAbsTime" : 821430243919,
  "cpuType" : "X86-64",
  "procName" : "Python",
  "procPath" : "\/Library\/Frameworks\/Python.framework\/Versions\/3.9\/Resources\/Python.app\/Contents\/MacOS\/Python",
  "bundleInfo" : {"CFBundleShortVersionString":"3.9.11","CFBundleVersion":"3.9.11","CFBundleIdentifier":"org.python.python"},
  "storeInfo" : {"deviceIdentifierForVendor":"83F84732-2536-55A8-BD15-34CD646C5203","thirdParty":true},
  "parentProc" : "zsh",
  "parentPid" : 470,
  "coalitionName" : "com.apple.Terminal",
  "crashReporterKey" : "D3F5C0EB-FD0F-4864-8733-5551B8EBCCC7",
  "responsiblePid" : 379,
  "responsibleProc" : "Terminal",
  "sip" : "enabled",
  "isCorpse" : 1,
  "exception" : {"codes":"0x0000000000000001, 0x0000000000000000","rawCodes":[1,0],"type":"EXC_BAD_INSTRUCTION","signal":"SIGILL"},
  "termination" : {"flags":0,"code":4,"namespace":"SIGNAL","indicator":"Illegal instruction: 4","byProc":"exc handler","byPid":993},
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 0,
  "threads" : [{"triggered":true,"id":9922,"instructionState":{"instructionStream":{"bytes":[16,1,0,0,73,137,246,73,137,255,232,7,65,249,255,72,137,195,72,133,192,76,141,37,44,210,32,0,73,15,68,220,76,137,247,232,238,64,249,255,72,133,192,73,15,68,196,72,137,4,36,72,141,21,34,232,32,0,76,141,165,224,254,255,255,190,255,0,0,0,76,137,231,76,137,249,73,137,216,77,137,241,49,192,232,111,164,0,0,76,137,37,242,195,85,65,15,11,144,72,141,5,49,232,32,0,72,137,5,225,195,85,65,15,11,72,141,5,76,234,32,0,72,137,5,209,195,85,65,15,11,72,141,5,60,234,32,0,72,137,5,193,195,85,65,15,11,72,141,5,44,234,32,0,72,137,5,177,195,85,65,15,11,72,141,5,124,233,32,0,72,137,5,161,195,85,65,15,11,72,141,5,108,233,32,0,72,137,5,145,195,85],"offset":96}},"threadState":{"r13":{"value":105553130963712},"rax":{"value":73},"rflags":{"value":66050},"cpu":{"value":1},"r14":{"value":0},"rsi":{"value":140703353429592,"symbolLocation":7160,"symbol":"_XMLPlistAppendDataUsingBase64.__CFPLDataEncodeTable"},"r8":{"value":140701898638512},"cr2":{"value":4455601216},"rdx":{"value":0},"r10":{"value":0},"r9":{"value":140703353429592,"symbolLocation":7160,"symbol":"_XMLPlistAppendDataUsingBase64.__CFPLDataEncodeTable"},"r15":{"value":43},"rbx":{"value":140703353425696,"symbolLocation":3264,"symbol":"_XMLPlistAppendDataUsingBase64.__CFPLDataEncodeTable"},"trap":{"value":6},"err":{"value":0},"r11":{"value":140701898639272},"rip":{"value":140703351272990,"matchesCrashFrame":1},"rbp":{"value":140701898639488},"rsp":{"value":140701898639184},"r12":{"value":140701898639200},"rcx":{"value":16036840694430302260},"flavor":"x86_THREAD_STATE","rdi":{"value":0}},"queue":"com.apple.main-thread","frames":[{"imageOffset":1799710,"symbol":"_CFAssertMismatchedTypeID","symbolLocation":110,"imageIndex":0},{"imageOffset":653877,"symbol":"CFRunLoopRemoveSource","symbolLocation":670,"imageIndex":0},{"imageOffset":254933,"symbol":"IOHIDDeviceUnscheduleFromRunLoop","symbolLocation":108,"imageIndex":1},{"imageOffset":271982,"symbol":"__IOHIDManagerDeviceApplier","symbolLocation":556,"imageIndex":1},{"imageOffset":302322,"symbol":"__CFSetApplyFunction_block_invoke","symbolLocation":18,"imageIndex":0},{"imageOffset":301919,"symbol":"CFBasicHashApply","symbolLocation":119,"imageIndex":0},{"imageOffset":301737,"symbol":"CFSetApplyFunction","symbolLocation":131,"imageIndex":0},{"imageOffset":266518,"symbol":"__ApplyToDevices","symbolLocation":105,"imageIndex":1},{"imageOffset":266758,"symbol":"IOHIDManagerUnscheduleFromRunLoop","symbolLocation":75,"imageIndex":1},{"imageOffset":266592,"symbol":"IOHIDManagerClose","symbolLocation":34,"imageIndex":1},{"imageOffset":47111,"symbol":"hid_exit","symbolLocation":23,"imageIndex":2},{"imageOffset":46637,"symbol":"__pyx_pw_11cfunc_dot_to_py_27__Pyx_CFunc_int_______to_py_1wrap","symbolLocation":13,"imageIndex":2},{"imageOffset":260828,"symbol":"_PyObject_Call","symbolLocation":140,"imageIndex":3},{"imageOffset":1137033,"symbol":"_PyEval_EvalFrameDefault","symbolLocation":27321,"imageIndex":3},{"imageOffset":1149699,"symbol":"_PyEval_EvalCode","symbolLocation":2611,"imageIndex":3},{"imageOffset":261297,"symbol":"_PyFunction_Vectorcall","symbolLocation":289,"imageIndex":3},{"imageOffset":259093,"symbol":"_PyObject_FastCallDictTstate","symbolLocation":293,"imageIndex":3},{"imageOffset":262040,"symbol":"_PyObject_Call_Prepend","symbolLocation":152,"imageIndex":3},{"imageOffset":623847,"symbol":"slot_tp_call","symbolLocation":167,"imageIndex":3},{"imageOffset":259511,"symbol":"_PyObject_MakeTpCall","symbolLocation":359,"imageIndex":3},{"imageOffset":1146524,"symbol":"call_function","symbolLocation":876,"imageIndex":3},{"imageOffset":1135435,"symbol":"_PyEval_EvalFrameDefault","symbolLocation":25723,"imageIndex":3},{"imageOffset":261416,"symbol":"function_code_fastcall","symbolLocation":104,"imageIndex":3},{"imageOffset":269746,"symbol":"method_vectorcall","symbolLocation":274,"imageIndex":3},{"imageOffset":1803697,"symbol":"atexit_callfuncs","symbolLocation":113,"imageIndex":3},{"imageOffset":1424718,"symbol":"Py_FinalizeEx","symbolLocation":78,"imageIndex":3},{"imageOffset":1565360,"symbol":"Py_RunMain","symbolLocation":2240,"imageIndex":3},{"imageOffset":1566095,"symbol":"pymain_main","symbolLocation":223,"imageIndex":3},{"imageOffset":1566603,"symbol":"Py_BytesMain","symbolLocation":43,"imageIndex":3},{"imageOffset":21806,"symbol":"start","symbolLocation":462,"imageIndex":4}]},{"id":9925,"frames":[{"imageOffset":8008,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":5}]},{"id":9926,"frames":[{"imageOffset":8008,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":5}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 140703349473280,
    "CFBundleShortVersionString" : "6.9",
    "CFBundleIdentifier" : "com.apple.CoreFoundation",
    "size" : 5246976,
    "uuid" : "32d2d187-4e52-376e-bc07-245a48c37e2b",
    "path" : "\/System\/Library\/Frameworks\/CoreFoundation.framework\/Versions\/A\/CoreFoundation",
    "name" : "CoreFoundation",
    "CFBundleVersion" : "1866"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 140703392051200,
    "CFBundleShortVersionString" : "2.0.2",
    "CFBundleIdentifier" : "com.apple.framework.IOKit",
    "size" : 745472,
    "uuid" : "e9f24202-6a37-30c2-8431-8ba7cc02812f",
    "path" : "\/System\/Library\/Frameworks\/IOKit.framework\/Versions\/A\/IOKit",
    "name" : "IOKit"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 4451590144,
    "size" : 65536,
    "uuid" : "eabdb5f7-5637-3d10-b443-00b105e714dc",
    "path" : "\/Users\/USER\/*\/hid.cpython-39-darwin.so",
    "name" : "hid.cpython-39-darwin.so"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 4454977536,
    "CFBundleShortVersionString" : "3.9.11, (c) 2001-2021 Python Software Foundation.",
    "CFBundleIdentifier" : "org.python.python",
    "size" : 2527232,
    "uuid" : "ef9cc1f4-5991-3213-9a9e-e68c578b6c1b",
    "path" : "\/Library\/Frameworks\/Python.framework\/Versions\/3.9\/Python",
    "name" : "Python",
    "CFBundleVersion" : "3.9.11"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 4493807616,
    "size" : 442368,
    "uuid" : "f71fb3ca-5fcc-3577-9457-b047888a46d1",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  },
  {
    "source" : "P",
    "arch" : "x86_64",
    "base" : 140703349157888,
    "size" : 49152,
    "uuid" : "f32b6d06-b156-3da0-b086-a31cf011362b",
    "path" : "\/usr\/lib\/system\/libsystem_pthread.dylib",
    "name" : "libsystem_pthread.dylib"
  }
],
  "sharedCache" : {
  "base" : 140703345901568,
  "size" : 19331678208,
  "uuid" : "df0706d4-ffba-39da-b512-d71c0baa3300"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=834.5M resident=0K(0%) swapped_out_or_unallocated=834.5M(100%)\nWritable regions: Total=568.3M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=568.3M(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nActivity Tracing                   256K        1 \nKernel Alloc Once                    8K        1 \nMALLOC                           166.7M       30 \nMALLOC guard page                   16K        4 \nMALLOC_LARGE (reserved)            256K        2         reserved VM address space (unallocated)\nMALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)\nSTACK GUARD                         12K        3 \nStack                             17.0M        3 \nVM_ALLOCATE                          8K        2 \n__DATA                            15.6M      238 \n__DATA_CONST                      10.9M      143 \n__DATA_DIRTY                       485K       85 \n__FONT_DATA                          4K        1 \n__LINKEDIT                       646.5M       12 \n__OBJC_RO                         82.8M        1 \n__OBJC_RW                         3200K        2 \n__TEXT                           188.1M      254 \n__UNICODE                          592K        1 \ndyld private memory               1024K        1 \nmapped file                         48K        1 \nshared memory                       12K        2 \n===========                     =======  ======= \nTOTAL                              1.5G      788 \nTOTAL, minus reserved VM space     1.1G      788 \n",
  "legacyInfo" : {
  "threadTriggered" : {
    "queue" : "com.apple.main-thread"
  }
},
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "60da5e84ab0ca017dace9abf",
      "factorPackIds" : {

      },
      "deploymentId" : 240000008
    },
    {
      "rolloutId" : "6112e14f37f5d11121dcd519",
      "factorPackIds" : {
        "SIRI_TEXT_TO_SPEECH" : "634710168e8be655c1316aaa"
      },
      "deploymentId" : 240000231
    }
  ],
  "experiments" : [
    {
      "treatmentId" : "6dd670af-0633-45e4-ae5f-122ae4df02be",
      "experimentId" : "64406ba83deb637ac8a04419",
      "deploymentId" : 900000005
    }
  ]
}
}

Model: iMac11,3, BootROM VirtualBox, 4 processors, Unknown, 2.81 GHz, 8 GB, SMC 2.3f35
Graphics: Display, 3 MB
Display: spdisplays_display, 1024 x 768 (XGA - eXtended Graphics Array), Main, MirrorOff, Online
Memory Module: Bank 0/DIMM 0, 8 GB, DRAM, 1600 MHz, innotek GmbH, -
Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
Network Service: Ethernet, Ethernet, en0
Serial ATA Device: VBOX HARDDISK, 107.37 GB
Serial ATA Device: VBOX CD-ROM
USB Device: USB30Bus
USB Device: USB Tablet
USB Device: USB Keyboard
Thunderbolt Bus: 

SomberNight added a commit to SomberNight/cython-hidapi that referenced this issue May 10, 2023
fixes trezor#142
fixes trezor#148

note trezor#148 (comment) :
> HIDAPI on macOS has an additional issue regarding thread-safety.
> I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause.
> Looks like on macOS hid_init/hid_exit needs to be called in the same thread,
> which is an additional restriction compared to other platforms.
@mcuee
Copy link

mcuee commented May 11, 2023

I can confirm the reproducer crashes under my Mac Mini M1 (2020 model) running latest macOS Ventura 13.3.1.

And with PR #150, it no longer crashes.

prusnak pushed a commit that referenced this issue May 11, 2023
fixes #142
fixes #148

note #148 (comment) :
> HIDAPI on macOS has an additional issue regarding thread-safety.
> I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause.
> Looks like on macOS hid_init/hid_exit needs to be called in the same thread,
> which is an additional restriction compared to other platforms.
SomberNight added a commit to spesmilo/electrum that referenced this issue May 30, 2023
Was added in 752b37a,
due to upstream issue trezor/cython-hidapi#142,
which should now be fixed in 0.14.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants