From 442e4d82fccf7660838c32ef90c051072afbe97e Mon Sep 17 00:00:00 2001 From: Sanjay Chouksey Date: Tue, 28 Jul 2020 16:32:17 -0700 Subject: [PATCH] Allow access to a zircon handle's koid (flutter/engine#20087) A zircon handle is associated with a koid, kernal object identifier. Whereas the handle can be duplicated, koid is unique. Two distinct handles can point to the same kernal object, if their koids are the same. This change adds access to koid for a Handle object. Test: Adds a unittest for koid Co-authored-by: Sanjay Chouksey --- .../fuchsia/dart-pkg/zircon/lib/src/handle.dart | 2 ++ .../fuchsia/dart-pkg/zircon/sdk_ext/handle.cc | 1 + .../fuchsia/dart-pkg/zircon/sdk_ext/handle.h | 7 +++++++ .../fuchsia/dart-pkg/zircon/test/handle_test.dart | 12 ++++++++++++ 4 files changed, 22 insertions(+) diff --git a/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart b/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart index 99b18d7113..2e78559bc5 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart +++ b/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart @@ -22,6 +22,8 @@ class Handle extends NativeFieldWrapperClass2 { int get handle native 'Handle_handle'; + int get koid native 'Handle_koid'; + @override String toString() => 'Handle($handle)'; diff --git a/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc b/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc index e2d4fafd38..44de9867f9 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc +++ b/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc @@ -151,6 +151,7 @@ void Handle::ScheduleCallback(tonic::DartPersistentValue callback, #define FOR_EACH_BINDING(V) \ V(Handle, handle) \ + V(Handle, koid) \ V(Handle, is_valid) \ V(Handle, Close) \ V(Handle, AsyncWait) \ diff --git a/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.h b/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.h index cd2b4c7740..42d91506b1 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.h +++ b/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.h @@ -51,6 +51,13 @@ class Handle : public fml::RefCountedThreadSafe, zx_handle_t handle() const { return handle_; } + zx_koid_t koid() const { + zx_info_handle_basic_t info; + zx_status_t status = zx_object_get_info( + handle_, ZX_INFO_HANDLE_BASIC, &info, sizeof(info), nullptr, nullptr); + return status == ZX_OK ? info.koid : ZX_KOID_INVALID; + } + zx_status_t Close(); fml::RefPtr AsyncWait(zx_signals_t signals, diff --git a/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/test/handle_test.dart b/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/test/handle_test.dart index fc0ce8d63f..8051ae2025 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/test/handle_test.dart +++ b/engine/src/flutter/shell/platform/fuchsia/dart-pkg/zircon/test/handle_test.dart @@ -24,4 +24,16 @@ void main() { final Handle duplicate = handle.duplicate(ZX.RIGHT_SAME_RIGHTS); expect(duplicate.isValid, isFalse); }); + + test('handle and its duplicate have same koid', () { + final HandlePairResult pair = System.eventpairCreate(); + expect(pair.status, equals(ZX.OK)); + expect(pair.first.isValid, isTrue); + expect(pair.second.isValid, isTrue); + + final Handle duplicate = pair.first.duplicate(ZX.RIGHT_SAME_RIGHTS); + expect(duplicate.isValid, isTrue); + + expect(pair.first.koid, duplicate.koid); + }); }