From c2a7c29ce89e907893c9baf6b855331ad5213a7e Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Fri, 23 Aug 2024 20:24:06 +0200 Subject: [PATCH] os2: fix using uuid as process handle for darwin, once it goes zombie it changes --- core/os/os2/process_posix_darwin.odin | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/core/os/os2/process_posix_darwin.odin b/core/os/os2/process_posix_darwin.odin index ace7a4fa2..648c4d389 100644 --- a/core/os/os2/process_posix_darwin.odin +++ b/core/os/os2/process_posix_darwin.odin @@ -263,13 +263,10 @@ _process_open :: proc(pid: int, flags: Process_Open_Flags) -> (process: Process, return } - // XOR fold the UUID so it fits the handle, I think this is enough to verify pid uniqueness. - #assert(size_of(uintptr) == size_of(u64)) - a := intrinsics.unaligned_load((^u64)(&rusage.ri_uuid)) - b := intrinsics.unaligned_load((^u64)(&rusage.ri_uuid[8])) - process.handle = uintptr(a ~ b) - - process.pid = int(pid) + // Using the start time as the handle, there is no pidfd or anything on Darwin. + // There is a uuid, but once a process becomes a zombie it changes... + process.handle = uintptr(rusage.ri_proc_start_abstime) + process.pid = int(pid) return } @@ -279,12 +276,7 @@ _process_handle_still_valid :: proc(p: Process) -> Error { return _get_platform_error() } - // XOR fold the UUID so it fits the handle, I think this is enough to verify pid uniqueness. - #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) - + handle := uintptr(rusage.ri_proc_start_abstime) if p.handle != handle { return posix.Errno.ESRCH }