1 // Copyright 2021 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/fuchsia/koid.h" 6 7 #include "base/fuchsia/fuchsia_logging.h" 8 9 namespace base { 10 11 namespace { 12 GetBasicInfo(const zx::object_base & handle)13std::optional<zx_info_handle_basic_t> GetBasicInfo( 14 const zx::object_base& handle) { 15 zx_info_handle_basic_t basic; 16 zx_status_t status = handle.get_info(ZX_INFO_HANDLE_BASIC, &basic, 17 sizeof(basic), nullptr, nullptr); 18 if (status != ZX_OK) { 19 ZX_DLOG(ERROR, status) << "zx_object_get_info"; 20 return {}; 21 } 22 23 return basic; 24 } 25 26 } // namespace 27 GetKoid(const zx::object_base & handle)28std::optional<zx_koid_t> GetKoid(const zx::object_base& handle) { 29 auto basic_info = GetBasicInfo(handle); 30 if (!basic_info) 31 return {}; 32 return basic_info->koid; 33 } 34 GetRelatedKoid(const zx::object_base & handle)35std::optional<zx_koid_t> GetRelatedKoid(const zx::object_base& handle) { 36 auto basic_info = GetBasicInfo(handle); 37 if (!basic_info) 38 return {}; 39 return basic_info->related_koid; 40 } 41 42 } // namespace base 43