mach_msg_trap SIGILL crashes when using Accessibility API

I am working on an open source Mac app that depends on the Accessibility API. I've noticed occasional crashes when calling the AXUIElementCopyAttributeValue and AXUIElementCopyAttributeValues functions

very similar crash logs:

pastebin.com/QuF86Fp4
pastebin.com/QrxyVuRu
pastebin.com/Nceyk6vZ
pastebin.com/m7bLxqe1
pastebin.com/BNtjxd3N
pastebin.com/RHYabPRL

Here is my part of the source code (and the accessibility api wrapper library I am depending on).

https://github.com/dexterleng/vimac/blob/master/ViMac-Swift/Services/QueryWindowService.swift
https://github.com/tmandry/AXSwift/blob/master/Sources/UIElement.swift
What makes you think Accessibility is in play here? I downloaded your first crash report and this is what I see:

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


Looking at thread 0, I see this:

Code Block
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 dexterleng.vimac … 0x10dbed000 + 22607
1 dexterleng.vimac … 0x10dbed000 + 44634
2 dexterleng.vimac … 0x10dbed000 + 14835
3 dexterleng.vimac … 0x10dbed000 + 122735
4 org.cocoapods.RxSwift … closure #1 in ObservableType.subscribe(onNext:onError:onCompleted:onDisposed:) + 361


This clearly indicates you’re crashing in your own code. You should symbolicate that log to find out where (see Adding Identifiable Symbol Names to a Crash Report).

ps I see you calling Accessibility on thread 2, but that’s not the thread that crashed.

Having said that, I don’t think it’s a great idea to be calling Accessibility APIs from a secondary thread. Most of Apple’s UI frameworks are only safe to use from the main thread. I’m not sure if that applies to Accessibility, but it’s not something I’d risk.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
@eskimo misinterpreted the crash logs :/

Here is the supposed source of error [1]. Do you have any clues as to what can cause a SIGILL? From what I can see I am not working with any lower level things that would cause this issue.

[1] https://github.com/dexterleng/vimac/blob/930d63373d17ed9c6bc2e4120e6698d220c97499/ViMac-Swift/ViewControllers/HintModeViewController.swift#L136

Code Block
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0  dexterleng.vimac        0x000000010dbf284f HintModeViewController.onLetterKeyDown(event:) (in Vimac) (HintModeViewController.swift:83)
1  dexterleng.vimac        0x000000010dbf7e5a partial apply for closure #1 in HintModeViewController.observeLetterKeyDown() (in Vimac) (<compiler-generated>:0)
2  dexterleng.vimac        0x000000010dbf09f3 partial apply for closure #2 in HintModeInputListener.observeSpaceKey(onEvent:) (in Vimac) (<compiler-generated>:0)
3  dexterleng.vimac        0x000000010dc0af6f thunk for @escaping @callee_guaranteed (@guaranteed NSEvent) -> () (in Vimac) (<compiler-generated>:0)
4  org.cocoapods.RxSwift      0x000000010de8d859 closure #1 in ObservableType.subscribe(onNext:onError:onCompleted:onDisposed:) + 361
5  org.cocoapods.RxSwift      0x000000010de8dab5 partial apply for closure #1 in ObservableType.subscribe(onNext:onError:onCompleted:onDisposed:) + 53
6  org.cocoapods.RxSwift      0x000000010de3de93 AnonymousObserver.onCore(_:) + 35
7  org.cocoapods.RxSwift      0x000000010de90457 ObserverBase.on(_:) + 167
8  org.cocoapods.RxSwift      0x000000010de905f0 protocol witness for ObserverType.on(_:) in conformance ObserverBase<A> + 16
9  org.cocoapods.RxSwift      0x000000010deb10d3 Sink.forwardOn(_:) + 99
10 org.cocoapods.RxSwift      0x000000010de7bbe8 FilterSink.on(_:) + 440
11 org.cocoapods.RxSwift      0x000000010de7bd30 protocol witness for ObserverType.on(_:) in conformance FilterSink<A> + 16
12 org.cocoapods.RxSwift      0x000000010de909a3 partial apply + 67
13 org.cocoapods.RxSwift      0x000000010deadb41 partial apply for thunk for @escaping @callee_guaranteed (@in_guaranteed Event<A>) -> () + 17
14 org.cocoapods.RxSwift      0x000000010deac80d ShareReplay1WhileConnectedConnection.on(_:) + 109
15 org.cocoapods.RxSwift      0x000000010dead347 protocol witness for ObserverType.on(_:) in conformance ShareWhileConnectedConnection<A> + 23
16 org.cocoapods.RxSwift      0x000000010deb10d3 Sink.forwardOn(_:) + 99
17 org.cocoapods.RxSwift      0x000000010de68b94 AnonymousObservableSink.on(_:) + 228
18 org.cocoapods.RxSwift      0x000000010de68dc0 protocol witness for ObserverType.on(_:) in conformance AnonymousObservableSink<A> + 16
19 org.cocoapods.RxSwift      0x000000010de909a3 partial apply + 67
20 org.cocoapods.RxSwift      0x000000010de3dfc1 AnyObserver.on(_:) + 33
21 org.cocoapods.RxSwift      0x000000010de90776 ObserverType.onNext(_:) + 166
22 dexterleng.vimac        0x000000010dbf81b4 closure #1 in closure #1 in variable initialization expression of InputListener.events (in Vimac) (InputListener.swift:11)
23 dexterleng.vimac        0x000000010dbf81ec thunk for @escaping @callee_guaranteed (@guaranteed NSEvent) -> (@owned NSEvent?) (in Vimac) (<compiler-generated>:0)
24 com.apple.AppKit        0x00007fff36c3f982 _NSSendEventToObservers + 323
25 com.apple.AppKit        0x00007fff36c3e446 -[NSApplication(NSEvent) sendEvent:] + 82
26 com.apple.AppKit        0x00007fff36a8b5bf -[NSApplication run] + 707
27 com.apple.AppKit        0x00007fff36a5d396 NSApplicationMain + 777
28 dexterleng.vimac        0x000000010dbeec69 main (in Vimac) (AppDelegate.swift:19)
29 libdyld.dylib          0x00007fff73895cc9 start + 1


misinterpreted the crash logs :/

Fair enough.

From what I can see I am not working with any lower level things that
would cause this issue.

If you're on Intel, a Swift runtime trap will generate a SIGILL. Try this: Write a tiny test app that force unwraps a nil value. It’ll crash with SIGILL just like this.

Note For future reference, Understanding the Exception Types in a Crash Report

Do you have any clues as to what can cause a SIGILL?

Do you have an Apple crash report for this? If so, can you post it here? Use the text attachment button so it doesn’t clog up the timeline.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
@eskimo

Nope, I don't have a crash report, but I figured out the cause. It is indeed the force unwrap! (from a race condition). Thanks!
mach_msg_trap SIGILL crashes when using Accessibility API
 
 
Q