os2: fix using uuid as process handle for darwin, once it goes zombie it changes

This commit is contained in:
Laytan Laats
2024-08-23 20:24:06 +02:00
parent b3f22133f3
commit c2a7c29ce8
+5 -13
View File
@@ -263,13 +263,10 @@ _process_open :: proc(pid: int, flags: Process_Open_Flags) -> (process: Process,
return return
} }
// XOR fold the UUID so it fits the handle, I think this is enough to verify pid uniqueness. // Using the start time as the handle, there is no pidfd or anything on Darwin.
#assert(size_of(uintptr) == size_of(u64)) // There is a uuid, but once a process becomes a zombie it changes...
a := intrinsics.unaligned_load((^u64)(&rusage.ri_uuid)) process.handle = uintptr(rusage.ri_proc_start_abstime)
b := intrinsics.unaligned_load((^u64)(&rusage.ri_uuid[8])) process.pid = int(pid)
process.handle = uintptr(a ~ b)
process.pid = int(pid)
return return
} }
@@ -279,12 +276,7 @@ _process_handle_still_valid :: proc(p: Process) -> Error {
return _get_platform_error() return _get_platform_error()
} }
// XOR fold the UUID so it fits the handle, I think this is enough to verify pid uniqueness. handle := uintptr(rusage.ri_proc_start_abstime)
#assert(size_of(uintptr) == size_of(u64))
a := intrinsics.unaligned_load((^u64)(&rusage.ri_uuid))
b := intrinsics.unaligned_load((^u64)(&rusage.ri_uuid[8]))
handle := uintptr(a ~ b)
if p.handle != handle { if p.handle != handle {
return posix.Errno.ESRCH return posix.Errno.ESRCH
} }