| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/process/process_handle.h" | 5 #include "base/process/process_handle.h" |
| 6 | 6 |
| 7 #include <magenta/process.h> | 7 #include <magenta/process.h> |
| 8 #include <magenta/syscalls.h> | 8 #include <magenta/syscalls.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 | 13 |
| 14 ProcessId GetCurrentProcId() { | 14 ProcessId GetCurrentProcId() { |
| 15 return GetProcId(GetCurrentProcessHandle()); | 15 return GetProcId(GetCurrentProcessHandle()); |
| 16 } | 16 } |
| 17 | 17 |
| 18 ProcessHandle GetCurrentProcessHandle() { | 18 ProcessHandle GetCurrentProcessHandle() { |
| 19 // Note that mx_process_self() returns a real handle, and ownership is not | 19 // Note that mx_process_self() returns a real handle, and ownership is not |
| 20 // transferred to the caller (i.e. this should never be closed). | 20 // transferred to the caller (i.e. this should never be closed). |
| 21 return mx_process_self(); | 21 return mx_process_self(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 ProcessId GetProcId(ProcessHandle process) { | 24 ProcessId GetProcId(ProcessHandle process) { |
| 25 mx_info_handle_basic_t basic; | 25 mx_info_handle_basic_t basic; |
| 26 mx_status_t status = mx_object_get_info(process, MX_INFO_HANDLE_BASIC, &basic, | 26 mx_status_t status = mx_object_get_info(process, MX_INFO_HANDLE_BASIC, &basic, |
| 27 sizeof(basic), nullptr, nullptr); | 27 sizeof(basic), nullptr, nullptr); |
| 28 if (status != NO_ERROR) { | 28 if (status != MX_OK) { |
| 29 DLOG(ERROR) << "mx_object_get_info failed: " << status; | 29 DLOG(ERROR) << "mx_object_get_info failed: " << status; |
| 30 return MX_KOID_INVALID; | 30 return MX_KOID_INVALID; |
| 31 } | 31 } |
| 32 return basic.koid; | 32 return basic.koid; |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace base | 35 } // namespace base |
| OLD | NEW |