xref: /aosp_15_r20/external/cronet/base/process/process_handle_fuchsia.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/process/process_handle.h"
6 
7 #include <lib/zx/process.h>
8 #include <zircon/process.h>
9 
10 #include "base/fuchsia/koid.h"
11 #include "base/logging.h"
12 
13 namespace base {
14 
GetCurrentProcId()15 ProcessId GetCurrentProcId() {
16   return GetProcId(GetCurrentProcessHandle());
17 }
18 
GetCurrentProcessHandle()19 ProcessHandle GetCurrentProcessHandle() {
20   // Note that zx_process_self() returns a real handle, and ownership is not
21   // transferred to the caller (i.e. this should never be closed).
22   return zx_process_self();
23 }
24 
GetProcId(ProcessHandle process)25 ProcessId GetProcId(ProcessHandle process) {
26   return GetKoid(*zx::unowned_process(process)).value_or(ZX_KOID_INVALID);
27 }
28 
29 }  // namespace base
30