| 6 |
| 7 | #include <zircon/process.h> |
| 8 | #include <zircon/status.h> |
| 9 | #include <zircon/syscalls.h> |
| 10 |
| 11 | #include "base/logging.h" |
| 12 |
| 13 | namespace base { |
| 14 |
| 15 | ProcessId GetCurrentProcId() { |
| 16 | return GetProcId(GetCurrentProcessHandle()); |
| 17 | } |
| 18 |
| 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 |
| 25 | ProcessId GetProcId(ProcessHandle process) { |
| 26 | zx_info_handle_basic_t basic; |
| 27 | zx_status_t status = zx_object_get_info(process, ZX_INFO_HANDLE_BASIC, &basic, |
| 28 | sizeof(basic), nullptr, nullptr); |
| 29 | if (status != ZX_OK) { |
| 30 | DLOG(ERROR) << "zx_object_get_info failed: " |
| 31 | << zx_status_get_string(status); |
| 32 | return ZX_KOID_INVALID; |
| 33 | } |
| 34 | return basic.koid; |
| 35 | } |
| 36 |
| 37 | } // namespace base |
| 38 |