Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Read a vnode's device number by bit pattern when looking for holders

Lakr7d22444d600f
diff --git a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleActivity.swift b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleActivity.swift
index 7ed95f89..1d66e821 100644
--- a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleActivity.swift
+++ b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleActivity.swift
@@ -71,7 +71,10 @@ public enum VPhoneBundleActivity {
let got = proc_pidfdinfo(pid, fd.proc_fd, PROC_PIDFDVNODEINFO, &info, Int32(MemoryLayout<vnode_fdinfo>.size))
guard got == Int32(MemoryLayout<vnode_fdinfo>.size) else { continue }
let st = info.pvi.vi_stat
- if targets.contains(FileID(device: dev_t(st.vst_dev), inode: ino_t(st.vst_ino))) {
+ // vst_dev is unsigned and dev_t signed: devfs can be numbered past
+ // Int32.max (0xC6B21E7F on macOS 27), and every process holds
+ // /dev/null, so a plain conversion traps on any scan.
+ if targets.contains(FileID(device: dev_t(bitPattern: st.vst_dev), inode: ino_t(st.vst_ino))) {
return true
}
}
diff --git a/VPhoneKit/VPhoneCoreKitTests/Bundle/BundleActivityTests.swift b/VPhoneKit/VPhoneCoreKitTests/Bundle/BundleActivityTests.swift
index 6bad38df..e3f0df83 100644
--- a/VPhoneKit/VPhoneCoreKitTests/Bundle/BundleActivityTests.swift
+++ b/VPhoneKit/VPhoneCoreKitTests/Bundle/BundleActivityTests.swift
@@ -37,6 +37,15 @@ struct BundleActivityTests {
#expect(!VPhoneBundleActivity.processesHolding([disk]).contains(getpid()))
}
+ @Test func `finds a holder on a device numbered past Int32.max`() throws {
+ // /dev is such a device on macOS 27; the scan must match it, not trap.
+ let null = URL(fileURLWithPath: "/dev/null")
+ let fd = open(null.path, O_RDONLY)
+ try #require(fd >= 0)
+ defer { close(fd) }
+ #expect(VPhoneBundleActivity.processesHolding([null]).contains(getpid()))
+ }
+
@Test func `a missing file has no holders`() {
let missing = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
#expect(VPhoneBundleActivity.processesHolding([missing]).isEmpty)