mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(process): preserve Darwin snapshot and cleanup failures (#12100)
* fix(process): preserve Darwin opening snapshot failures * fix(process): retain the exact Darwin helper cleanup owner Transfer the failed helper-root capability across repeated prepare failures. Reuse that same owner for retirement and reader close so stale cleanup cannot remove a replacement helper. Co-authored-by: Anandumv <anandumv@gmail.com> Co-authored-by: nextjohnp7 <nextjohnp7@gmail.com> * test(process): isolate retained cleanup and compiler acknowledgements --------- Co-authored-by: Anandumv <anandumv@gmail.com> Co-authored-by: nextjohnp7 <nextjohnp7@gmail.com>
This commit is contained in:
6 files changed
+216
-53
No files matched your search
@@ -47,14 +47,14 @@ typealias ProcessTableSysctlCall = (
|
||||
_ size: inout Int
|
||||
) -> Int32
|
||||
|
||||
private func readProcessSnapshot() -> ProcessSnapshot {
|
||||
readProcessSnapshot { mib, output, size in
|
||||
sysctl(&mib, u_int(mib.count), output, &size, nil, 0)
|
||||
}
|
||||
private func systemProcessTableSysctl(
|
||||
_ mib: inout [Int32], _ output: UnsafeMutableRawPointer?, _ size: inout Int
|
||||
) -> Int32 {
|
||||
sysctl(&mib, u_int(mib.count), output, &size, nil, 0)
|
||||
}
|
||||
|
||||
func readProcessSnapshot(
|
||||
sysctlCall: ProcessTableSysctlCall
|
||||
sysctlCall: ProcessTableSysctlCall = systemProcessTableSysctl
|
||||
) -> ProcessSnapshot {
|
||||
for _ in 0..<3 {
|
||||
var mib = [CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0]
|
||||
@@ -306,15 +306,21 @@ private func readRunToken(pid: Int32, pointerSize: Int) -> RunTokenObservation {
|
||||
)
|
||||
}
|
||||
|
||||
func readRunTokens(pids: [Int32]) -> [RunTokenObservation] {
|
||||
let before = readProcessSnapshot()
|
||||
func readRunTokens(
|
||||
pids: [Int32], sysctlCall: ProcessTableSysctlCall = systemProcessTableSysctl
|
||||
) -> [RunTokenObservation] {
|
||||
let before = readProcessSnapshot(sysctlCall: sysctlCall)
|
||||
// A later snapshot cannot establish the identity that opened the bracket.
|
||||
if let failure = before.failure {
|
||||
return pids.map { unavailable(pid: $0, reason: failure) }
|
||||
}
|
||||
let observations = pids.map { pid -> RunTokenObservation in
|
||||
guard let metadata = before.metadata[pid] else {
|
||||
return unavailable(pid: pid, reason: before.failure ?? "process_not_in_snapshot")
|
||||
return unavailable(pid: pid, reason: "process_not_in_snapshot")
|
||||
}
|
||||
return readRunToken(pid: pid, pointerSize: metadata.pointerSize)
|
||||
}
|
||||
let after = readProcessSnapshot()
|
||||
let after = readProcessSnapshot(sysctlCall: sysctlCall)
|
||||
return zip(pids, observations).map { pid, observation in
|
||||
guard let initial = before.metadata[pid], let current = after.metadata[pid] else {
|
||||
return unavailable(pid: pid, reason: after.failure ?? "process_not_in_snapshot")
|
||||
|
||||
Reference in new issue
Block a user