Skip to content

Commit

Permalink
Allow access to a zircon handle's koid (flutter#20087)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sanjayc77 and Sanjay Chouksey authored Jul 28, 2020
1 parent 16d241b commit a10774e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)';

Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class Handle : public fml::RefCountedThreadSafe<Handle>,

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<HandleWaiter> AsyncWait(zx_signals_t signals,
Expand Down
12 changes: 12 additions & 0 deletions shell/platform/fuchsia/dart-pkg/zircon/test/handle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

0 comments on commit a10774e

Please sign in to comment.