lihaoyun6 / AirBattery

Get the battery usage of all your devices on your Mac and put them on the Dock / Menu Bar / Widget! && 在Mac上获取你所有设备的电量信息并显示在Dock / 状态栏 / 小组件上!
https://lihaoyun6.github.io/airbattery/
GNU Affero General Public License v3.0
903 stars 26 forks source link

Crash at startup when AMFI had been previously off #24

Open xezrunner opened 1 month ago

xezrunner commented 1 month ago

The app crashes at startup on my MacBook Air M1 running macOS 14.5 Sonoma (release).

Here's the crash report:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               AirBattery [1574]
Path:                  /Applications/AirBattery.app/Contents/MacOS/AirBattery
Identifier:            com.lihaoyun6.AirBattery
Version:               1.3.3 (133)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2024-06-04 10:37:11.6617 +0200
OS Version:            macOS 14.5 (23F79)
Report Version:        12
Anonymous UUID:        B6980112-2EDE-7EAE-5D42-03E272CA5445

Time Awake Since Boot: 230 seconds

System Integrity Protection: disabled

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

Exception Type:        EXC_GUARD (SIGKILL)
Exception Codes:       GUARD_TYPE_MACH_PORT
Exception Codes:       0x0000000000005d1b, 0x0000000000000000

Termination Reason:    Namespace GUARD, Code 2305845208236973339 

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib                 0x1922ee0a4 _kernelrpc_mach_port_deallocate_trap + 8
1   libsystem_kernel.dylib                 0x1922ef52c mach_port_deallocate + 28
2   AirBattery                             0x10415db50 getPowerState() + 332
3   AirBattery                             0x10416120c one-time initialization function for status + 12
4   libdispatch.dylib                      0x19217e3e8 _dispatch_client_callout + 20
5   libdispatch.dylib                      0x19217fc68 _dispatch_once_callout + 32
6   AirBattery                             0x10414dc30 static AirBatteryModel.writeData() + 1332
7   AirBattery                             0x10413ff94 AppDelegate.applicationDidFinishLaunching(_:) + 1200
8   AirBattery                             0x104140944 @objc AppDelegate.applicationWillFinishLaunching(_:) + 124
9   SwiftUI                                0x1bf22d99c 0x1bdca0000 + 22600092
10  SwiftUI                                0x1bf22dc1c 0x1bdca0000 + 22600732
11  CoreFoundation                         0x192403144 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
12  CoreFoundation                         0x1924973d8 ___CFXRegistrationPost_block_invoke + 88
13  CoreFoundation                         0x192497320 _CFXRegistrationPost + 440
14  CoreFoundation                         0x1923d1678 _CFXNotificationPost + 768
15  Foundation                             0x1934ee4e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
16  AppKit                                 0x195c74410 -[NSApplication _postDidFinishNotification] + 284
17  AppKit                                 0x195c741c0 -[NSApplication _sendFinishLaunchingNotification] + 172
18  AppKit                                 0x195c72714 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 504
19  AppKit                                 0x195c72310 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 492
20  Foundation                             0x193517374 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 316
21  Foundation                             0x193517168 _NSAppleEventManagerGenericHandler + 80
22  AE                                     0x19942c9c4 0x199421000 + 47556
23  AE                                     0x19942c2ec 0x199421000 + 45804
24  AE                                     0x1994258a8 aeProcessAppleEvent + 488
25  HIToolbox                              0x19cbc002c AEProcessAppleEvent + 68
26  AppKit                                 0x195c6c074 _DPSNextEvent + 1440
27  AppKit                                 0x196461808 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700
28  AppKit                                 0x195c5f09c -[NSApplication run] + 476
29  AppKit                                 0x195c362e0 NSApplicationMain + 880
30  SwiftUI                                0x1bddaa474 0x1bdca0000 + 1090676
31  SwiftUI                                0x1be513e88 0x1bdca0000 + 8863368
32  SwiftUI                                0x1be90eeb8 0x1bdca0000 + 13037240
33  AirBattery                             0x10414253c main + 40
34  dyld                                   0x191fa60e0 start + 2360

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

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

Thread 3:
0   libsystem_pthread.dylib                0x192329d20 start_wqthread + 0

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x000000000000000f   x1: 0x0000000000005d1b   x2: 0x0000001800001513   x3: 0x0000070700005d1b
    x4: 0x00000b0000000000   x5: 0x0000070700000000   x6: 0x000000000000002c   x7: 0x0000000000000000
    x8: 0x00000001fa173920   x9: 0x0000000000004003  x10: 0x0000000000002300  x11: 0x00000000c163a085
   x12: 0x00000000000007fb  x13: 0x00000000000007fd  x14: 0x00000000c183a88d  x15: 0x000000000000008d
   x16: 0xffffffffffffffee  x17: 0x0000000204519b48  x18: 0x0000000000000000  x19: 0x0000000000005d1b
   x20: 0x0000000000000203  x21: 0x0000000000000000  x22: 0x0000600000830f00  x23: 0xeb00000000726961
   x24: 0x000060000227a100  x25: 0x00000001fa7d7498  x26: 0x0000000000000001  x27: 0x000000010417e000
   x28: 0x000000010417d000   fp: 0x000000016bcdda60   lr: 0x00000001922ef52c
    sp: 0x000000016bcdda50   pc: 0x00000001922ee0a4 cpsr: 0x80001000
   far: 0x0000000000000000  esr: 0x56000080  Address size fault

Binary Images:
       0x1045d8000 -        0x1045e3fff libobjc-trampolines.dylib (*) <9381bd6d-84a5-3c72-b3b8-88428afa4782> /usr/lib/libobjc-trampolines.dylib
       0x10477c000 -        0x1047bffff org.sparkle-project.Sparkle (2.6.2) <387c652c-43e0-3ed4-8d24-25f881186cbf> /Applications/AirBattery.app/Contents/Frameworks/Sparkle.framework/Versions/B/Sparkle
       0x104120000 -        0x104177fff com.lihaoyun6.AirBattery (1.3.3) <06e63eb7-e290-3f3c-8bf1-b03f3c141623> /Applications/AirBattery.app/Contents/MacOS/AirBattery
       0x1922ed000 -        0x192327ffb libsystem_kernel.dylib (*) <9b8b53f9-e2b6-36df-98e9-28d8fca732f2> /usr/lib/system/libsystem_kernel.dylib
       0x19217a000 -        0x1921c1fff libdispatch.dylib (*) <502762ee-7aa7-306c-9dbd-88981a86bb78> /usr/lib/system/libdispatch.dylib
       0x1bdca0000 -        0x1bf983fff com.apple.SwiftUI (5.5.8) <71c9cc70-1a85-396b-a92a-c893fe8bd541> /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
       0x192390000 -        0x192868fff com.apple.CoreFoundation (6.9) <84b539d5-22c9-3f8c-84c8-903e9c7b8d29> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
       0x1934e5000 -        0x194142fff com.apple.Foundation (6.9) <99e0292d-7873-3968-9c9c-5955638689a5> /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
       0x195c32000 -        0x196f6efff com.apple.AppKit (6.9) <61f710be-9132-3cc2-883d-066365fba1ad> /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
       0x199421000 -        0x199494ff7 com.apple.AE (944) <3b96540c-5db5-3880-bc50-a759b87f6638> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE
       0x19cb7d000 -        0x19ce40fff com.apple.HIToolbox (2.1.1) <7db6c397-563f-3756-908c-e25b019a1848> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox
       0x191fa0000 -        0x192028a17 dyld (*) <37bbc384-0755-31c7-a808-0ed49e44dd8e> /usr/lib/dyld
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???
       0x192328000 -        0x192334fff libsystem_pthread.dylib (*) <386b0fc1-7873-3328-8e71-43269fd1b2c7> /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=1.1G resident=0K(0%) swapped_out_or_unallocated=1.1G(100%)
Writable regions: Total=1.1G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.1G(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Accelerate framework               128K        1 
Activity Tracing                   256K        1 
AttributeGraph Data               1024K        1 
ColorSync                          544K       26 
CoreAnimation                       80K        5 
CoreGraphics                        48K        3 
CoreUI image data                  304K        4 
Foundation                          16K        1 
Kernel Alloc Once                   32K        1 
MALLOC                             1.1G       45 
MALLOC guard page                  288K       18 
STACK GUARD                       56.1M        4 
Stack                             9808K        4 
VM_ALLOCATE                         48K        3 
__AUTH                            2065K      331 
__AUTH_CONST                      28.1M      527 
__CTF                               824        1 
__DATA                            11.2M      513 
__DATA_CONST                      27.8M      534 
__DATA_DIRTY                      1733K      174 
__FONT_DATA                          4K        1 
__INFO_FILTER                         8        1 
__LINKEDIT                       533.8M        4 
__OBJC_RO                         71.9M        1 
__OBJC_RW                         2199K        1 
__TEXT                           630.8M      551 
dyld private memory                272K        1 
mapped file                      159.8M       20 
shared memory                      864K       14 
===========                     =======  ======= 
TOTAL                              2.6G     2791 
xezrunner commented 3 days ago

It appears that this crash is related to AMFI being off even once on an installation.

Re-enabling AMFI and SIP, as well as fully cleaning the install does not resolve the crash.

lihaoyun6 commented 3 days ago

It seems that starting from macOS 12, Apple changed some codes about mach_port in the kernel. Same problem has been raised in both the Mozilla and the Chromium community, but I have not seen any explanation or fix so far😢

But I saw this on Reddit. If you need to bypass this issue with AMFI turned off, you can do this: https://www.reddit.com/r/MacOS/comments/tf2hyf/comment/i3hovxz/

xezrunner commented 3 days ago

It seems that starting from macOS 12, Apple changed some codes about mach_port in the kernel. Same problem has been raised in both the Mozilla and the Chromium community, but I have not seen any explanation or fix so far😢

But I saw this on Reddit. If you need to bypass this issue with AMFI turned off, you can do this: https://www.reddit.com/r/MacOS/comments/tf2hyf/comment/i3hovxz/

I also found these instructions while trying to find a solution to this. I already had ipc_control_port_options=0 in my boot args, so I'm not sure if that's related, or broken in recent versions of macOS.

Other apps that also stopped working without AMFI would start working again when re-enabling AMFI and SIP. BatFi however would keep having broken behavior - either a crash, or the app/driver no longer reporting battery info.

I will probably be able to test this further in the near-future, will add logs if nobody else does it sooner.