A dext process that ends with its IOPCIDevice session open panics the Mac:
IOUserServer::clientClose sends the provider ClientCrashed(), and
IOPCIBridge::childClientCrashRecoveryGated reads through the NULL range of
the R9700's expansion ROM entry (IOPCIFamily+0x19b5c). With the session
closed first, the recovery is skipped.
fatal_close.h gives every way the process can end itself a close-first
step, in plain code with no signal handler and no system call of its own
(build 259's sigaction was killed by the DriverKit sandbox):
- assert(): __assert_rtn is defined in the dext, so every reference in the
binary and its static library binds to it;
- std::terminate: a terminate handler, set by a constructor and again in
dext_set_pci, before any session can open;
- libc++ hardening: std::__libcpp_verbose_abort, which libc++ lets a
program replace;
- a smashed stack: __stack_chk_fail is defined in the dext, so the
stack-protector calls bind to it.
Each closes the session once (the first thread closes, any other waits for
it), logs one public FATAL event, then calls abort(), so the crash is
still the crash. The close is 259's lock-free close: admission closes, the
open flag is taken, the provider is closed once. BUG(), panic() and
linuxu_fatal() still park the thread and never end the process; no other
abort() call is compiled into the dext.
Hardware faults, libmalloc and FORTIFY aborts (inside libsystem) and an
outside SIGKILL do not pass through this code.
test-pci-call-guards gains a fatal mode: child processes that end by
assert, std::terminate, a libc++ hardening assertion and a real stack
overrun, also with the PCI control lock held elsewhere and on two threads
at once, close the session exactly once and still die of SIGABRT; after a
normal close there is no second Close. Without the close the cases fail.
Build 259 installed fatal-signal handlers with a raw sigaction system call
before opening the PCI session, so that a dying dext would close the
session first. The DriverKit sandbox does not allow that call. It
SIGKILLed the dext on every open, before the session opened, so the GPU
never came up: no compute, no display.
The install, its handler and pci_crash_close.h are removed, with nothing
attempted in their place. A crash-close mechanism has to be one DriverKit
permits; that is separate work. The PCI call validator, the close drain
and everything else from that change stay. test-pci-call-guards keeps
its guard and close-fence cases and drops the crash cases.
The panics of 2026-10-01 (a quarantined dext killed) and 2026-10-06
(build 258.3, 40 s after it attached) are one kernel bug. When a dext
process ends with its IOPCIDevice session open, IOUserServer::clientClose
sends the provider ClientCrashed(), and IOPCIDevice::ClientCrashed_Impl
runs IOPCIBridge::childClientCrashRecoveryGated. Its BAR-restore loop
walks IODeviceMemory and indexes configEntry->ranges[] with
(register - 0x10) >> 2. The R9700's fourth entry (index 3) is its
expansion ROM, register 0x30, so the index is 8, the bridge
prefetchable-window slot, NULL on an endpoint (the ROM is slot 6).
range->start is read through it: ldr w2, [x27] with x27 = 0 at
IOPCIFamily(2.9)+0x19b5c, x22 = 0x30, x23 = 8, x25 = 3, and
x21 = 0x280000, the ROM BAR as read. IOPCIFamily gives every
display-class function with a ROM BAR a ROM range, so any death of this
driver with its session open panics the Mac, whatever it did first.
The 258.3 process died of a fault of its own (an experiment's CPU access
to VRAM past the BAR window, fixed separately), and the kernel bug turned
that into a panic. A session closed before the process ends makes
ClientCrashed_Impl skip the recovery.
pci_crash_close.h: the signals whose default action ends the process
(SIGKILL aside) and that nothing else handles get a handler that closes
the session, then takes the default action: a fault recurs and is
reported as itself, a sent signal is sent again. The close takes no lock
(the failing thread may hold one): admission closes, the open flag is
taken, and the provider is closed once; IOPCIDevice::handleClose turns
bus mastering and memory decode off, as the recovery would have. A dext
links only against DriverKit.framework, which exports no signal call, so
sigaction, sigreturn and kill are the system calls themselves, with the
trampoline ABI of xnu's arm sendsig. The driver logs which signals are
armed, and loudly if the kernel refused one. SIGKILL still cannot be
caught: a dext must never be killed.
The calls themselves (dext_main.mm):
- the memory index and size of each BAR come from GetBARInfo once, right
after Open; a MemoryRead/MemoryWrite is made only with one of those
indices, inside that BAR, aligned, on an open session. Anything else is
a transport fault with its offset, never a kernel call. Register
tokens, the VRAM aperture (BAR0) and dext_copy_bar_memory use that
table; the aperture's out-of-window accesses, silently dropped before,
are now logged and recorded;
- dext_close closes admission, waits up to a second for admitted
operations and for raw calls, then closes and reopens admission; a
refusal (a fault, a reset, accesses that do not leave) is logged
instead of silent. dext_pci_device_present, which reads config space
outside admission, holds the session for its call and asks only an
open session.
test-pci-call-guards compiles dext_main.mm whole against a DriverKit
substitute whose IOPCIDevice flags any call outside the kernel's
contract: invalid memory indices (the ROM's, none), accesses outside the
token, outside the BAR and misaligned, aperture accesses outside BAR0,
and every accessor after Close are refused before a call and recorded;
in-window aperture stores (a CPU-visible VRAM MQD) make exactly one call;
Close waits for an access and a raw config read in flight and admits
nothing meanwhile; child processes dying of SIGSEGV, SIGTRAP, SIGABRT
and SIGTERM, also with the PCI control lock held elsewhere, close the
session exactly once first and still die of that signal. Without each
guard the matching case fails.