| Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
| Scott Graham | b4638ab4 | 2017-05-24 23:20:21 | [diff] [blame] | 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 | |
| Wez | faa8f7a | 2021-05-11 21:10:09 | [diff] [blame] | 7 | #include <lib/zx/process.h> |
| Scott Graham | fe0e9f46 | 2017-09-18 21:25:04 | [diff] [blame] | 8 | #include <zircon/process.h> |
| Scott Graham | b4638ab4 | 2017-05-24 23:20:21 | [diff] [blame] | 9 | |
| Wez | faa8f7a | 2021-05-11 21:10:09 | [diff] [blame] | 10 | #include "base/fuchsia/koid.h" |
| Scott Graham | b4638ab4 | 2017-05-24 23:20:21 | [diff] [blame] | 11 | #include "base/logging.h" |
| 12 | |
| 13 | namespace base { |
| 14 | |
| 15 | ProcessId GetCurrentProcId() { |
| 16 | return GetProcId(GetCurrentProcessHandle()); |
| 17 | } |
| 18 | |
| 19 | ProcessHandle GetCurrentProcessHandle() { |
| Scott Graham | fe0e9f46 | 2017-09-18 21:25:04 | [diff] [blame] | 20 | // Note that zx_process_self() returns a real handle, and ownership is not |
| Scott Graham | b4638ab4 | 2017-05-24 23:20:21 | [diff] [blame] | 21 | // transferred to the caller (i.e. this should never be closed). |
| Scott Graham | fe0e9f46 | 2017-09-18 21:25:04 | [diff] [blame] | 22 | return zx_process_self(); |
| Scott Graham | b4638ab4 | 2017-05-24 23:20:21 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | ProcessId GetProcId(ProcessHandle process) { |
| Wez | faa8f7a | 2021-05-11 21:10:09 | [diff] [blame] | 26 | return GetKoid(*zx::unowned_process(process)).value_or(ZX_KOID_INVALID); |
| Scott Graham | b4638ab4 | 2017-05-24 23:20:21 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | } // namespace base |