Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,14 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle_disposition.dart
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle_waiter.dart
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.h
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_disposition.cc
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_disposition.h
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.cc
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.h
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/natives.cc
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/fuchsia/dart-pkg/zircon/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ source_set("zircon") {
sources = [
"sdk_ext/handle.cc",
"sdk_ext/handle.h",
"sdk_ext/handle_disposition.cc",
"sdk_ext/handle_disposition.h",
"sdk_ext/handle_waiter.cc",
"sdk_ext/handle_waiter.h",
"sdk_ext/natives.cc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of zircon;

// ignore_for_file: native_function_body_in_non_sdk_code
// ignore_for_file: public_member_api_docs

@pragma('vm:entry-point')
class HandleDisposition extends NativeFieldWrapperClass2 {
@pragma('vm:entry-point')
HandleDisposition(int operation, Handle handle, int type, int rights) {
_constructor(operation, handle, type, rights);
}

void _constructor(int operation, Handle handle, int type, int rights)
native 'HandleDisposition_constructor';

int get operation native 'HandleDisposition_operation';
Handle get handle native 'HandleDisposition_handle';
int get type native 'HandleDisposition_type';
int get rights native 'HandleDisposition_rights';
int get result native 'HandleDisposition_result';

@override
String toString() =>
'HandleDisposition(operation=$operation, handle=$handle, type=$type, rights=$rights, result=$result)';
}
47 changes: 47 additions & 0 deletions shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,49 @@ class ReadResult extends _Result {
'ReadResult(status=$status, bytes=$_bytes, numBytes=$_numBytes, handles=$_handles)';
}

@pragma('vm:entry-point')
class HandleInfo {
final Handle handle;
final int type;
final int rights;

@pragma('vm:entry-point')
const HandleInfo(this.handle, this.type, this.rights);

@override
String toString() =>
'HandleInfo(handle=$handle, type=$type, rights=$rights)';
}

@pragma('vm:entry-point')
class ReadEtcResult extends _Result {
final ByteData? _bytes;
final int? _numBytes;
final List<HandleInfo>? _handleInfos;

ByteData get bytes => _bytes!;
int get numBytes => _numBytes!;
List<HandleInfo> get handleInfos => _handleInfos!;

@pragma('vm:entry-point')
const ReadEtcResult(final int status, [this._bytes, this._numBytes, this._handleInfos])
: super(status);

/// Returns the bytes as a Uint8List. If status != OK this will throw
/// an exception.
Uint8List bytesAsUint8List() {
return _bytes!.buffer.asUint8List(_bytes!.offsetInBytes, _numBytes!);
}

/// Returns the bytes as a String. If status != OK this will throw
/// an exception.
String bytesAsUTF8String() => utf8.decode(bytesAsUint8List());

@override
String toString() =>
'ReadEtcResult(status=$status, bytes=$_bytes, numBytes=$_numBytes, handleInfos=$_handleInfos)';
}

@pragma('vm:entry-point')
class WriteResult extends _Result {
final int? _numBytes;
Expand Down Expand Up @@ -161,8 +204,12 @@ class System extends NativeFieldWrapperClass2 {
native 'System_ConnectToService';
static int channelWrite(Handle channel, ByteData data, List<Handle> handles)
native 'System_ChannelWrite';
static int channelWriteEtc(Handle channel, ByteData data, List<HandleDisposition> handleDispositions)
native 'System_ChannelWriteEtc';
static ReadResult channelQueryAndRead(Handle channel)
native 'System_ChannelQueryAndRead';
static ReadEtcResult channelQueryAndReadEtc(Handle channel)
native 'System_ChannelQueryAndReadEtc';

// Eventpair operations.
static HandlePairResult eventpairCreate([int options = 0])
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import 'dart:nativewrappers';
import 'dart:typed_data';

part 'src/handle.dart';
part 'src/handle_disposition.dart';
part 'src/handle_waiter.dart';
part 'src/system.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "handle_disposition.h"

#include <algorithm>

#include "third_party/tonic/dart_binding_macros.h"
#include "third_party/tonic/dart_class_library.h"

using tonic::ToDart;

namespace zircon {
namespace dart {

IMPLEMENT_WRAPPERTYPEINFO(zircon, HandleDisposition);

void HandleDisposition_constructor(Dart_NativeArguments args) {
DartCallConstructor(&HandleDisposition::create, args);
}

fml::RefPtr<HandleDisposition> HandleDisposition::create(
zx_handle_op_t operation,
fml::RefPtr<dart::Handle> handle,
zx_obj_type_t type,
zx_rights_t rights) {
return fml::MakeRefCounted<HandleDisposition>(operation, handle, type, rights,
ZX_OK);
}

// clang-format: off

#define FOR_EACH_STATIC_BINDING(V) V(HandleDisposition, create)

#define FOR_EACH_BINDING(V) \
V(HandleDisposition, operation) \
V(HandleDisposition, handle) \
V(HandleDisposition, type) \
V(HandleDisposition, rights) \
V(HandleDisposition, result)

// clang-format: on

// Tonic is missing a comma.
#define DART_REGISTER_NATIVE_STATIC_(CLASS, METHOD) \
DART_REGISTER_NATIVE_STATIC(CLASS, METHOD),

FOR_EACH_STATIC_BINDING(DART_NATIVE_CALLBACK_STATIC)
FOR_EACH_BINDING(DART_NATIVE_NO_UI_CHECK_CALLBACK)

void HandleDisposition::RegisterNatives(tonic::DartLibraryNatives* natives) {
natives->Register({{"HandleDisposition_constructor",
HandleDisposition_constructor, 5, true},
FOR_EACH_STATIC_BINDING(DART_REGISTER_NATIVE_STATIC_)
FOR_EACH_BINDING(DART_REGISTER_NATIVE)});
}

} // namespace dart
} // namespace zircon
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_HANDLE_DISPOSITION_H_
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_HANDLE_DISPOSITION_H_

#include <zircon/syscalls.h>

#include <vector>

#include "flutter/fml/memory/ref_counted.h"
#include "handle.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/tonic/dart_library_natives.h"
#include "third_party/tonic/dart_wrappable.h"

namespace zircon {
namespace dart {
/**
* HandleDisposition is the native peer of a Dart object (HandleDisposition
* in dart:zircon) that holds a Handle and additional properties.
*/
class HandleDisposition : public fml::RefCountedThreadSafe<HandleDisposition>,
public tonic::DartWrappable {
DEFINE_WRAPPERTYPEINFO();
FML_FRIEND_REF_COUNTED_THREAD_SAFE(HandleDisposition);
FML_FRIEND_MAKE_REF_COUNTED(HandleDisposition);

public:
static void RegisterNatives(tonic::DartLibraryNatives* natives);

static fml::RefPtr<HandleDisposition> create(zx_handle_op_t operation,
fml::RefPtr<dart::Handle> handle,
zx_obj_type_t type,
zx_rights_t rights);

zx_handle_op_t operation() const { return operation_; }
fml::RefPtr<dart::Handle> handle() const { return handle_; }
zx_obj_type_t type() const { return type_; }
zx_rights_t rights() const { return rights_; }
zx_status_t result() const { return result_; }
void set_result(zx_status_t result) { result_ = result; }

private:
explicit HandleDisposition(zx_handle_op_t operation,
fml::RefPtr<dart::Handle> handle,
zx_obj_type_t type,
zx_rights_t rights,
zx_status_t result)
: operation_(operation),
handle_(handle),
type_(type),
rights_(rights),
result_(result) {}

void RetainDartWrappableReference() const override { AddRef(); }

void ReleaseDartWrappableReference() const override { Release(); }

zx_handle_op_t operation_;
fml::RefPtr<dart::Handle> handle_;
zx_obj_type_t type_;
zx_rights_t rights_;
zx_status_t result_;
};

} // namespace dart
} // namespace zircon

#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_HANDLE_DISPOSITION_H_
2 changes: 2 additions & 0 deletions shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/natives.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>

#include "handle.h"
#include "handle_disposition.h"
#include "handle_waiter.h"
#include "system.h"
#include "third_party/dart/runtime/include/dart_api.h"
Expand All @@ -32,6 +33,7 @@ static tonic::DartLibraryNatives* g_natives;

tonic::DartLibraryNatives* InitNatives() {
tonic::DartLibraryNatives* natives = new tonic::DartLibraryNatives();
HandleDisposition::RegisterNatives(natives);
HandleWaiter::RegisterNatives(natives);
Handle::RegisterNatives(natives);
System::RegisterNatives(natives);
Expand Down
Loading