Flutter Engine
zircon::dart::System Class Reference

#include <system.h>

Inheritance diagram for zircon::dart::System:
fml::RefCountedThreadSafe< System > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Static Public Member Functions

static Dart_Handle ChannelCreate (uint32_t options)
 
static Dart_Handle ChannelFromFile (std::string path)
 
static zx_status_t ChannelWrite (fml::RefPtr< Handle > channel, const tonic::DartByteData &data, std::vector< Handle *> handles)
 
static zx_status_t ChannelWriteEtc (fml::RefPtr< Handle > channel, const tonic::DartByteData &data, std::vector< HandleDisposition *> handle_dispositions)
 
static Dart_Handle ChannelQueryAndRead (fml::RefPtr< Handle > channel)
 
static Dart_Handle ChannelQueryAndReadEtc (fml::RefPtr< Handle > channel)
 
static Dart_Handle EventpairCreate (uint32_t options)
 
static Dart_Handle SocketCreate (uint32_t options)
 
static Dart_Handle SocketWrite (fml::RefPtr< Handle > socket, const tonic::DartByteData &data, int options)
 
static Dart_Handle SocketRead (fml::RefPtr< Handle > socket, size_t size)
 
static Dart_Handle VmoCreate (uint64_t size, uint32_t options)
 
static Dart_Handle VmoFromFile (std::string path)
 
static Dart_Handle VmoGetSize (fml::RefPtr< Handle > vmo)
 
static zx_status_t VmoSetSize (fml::RefPtr< Handle > vmo, uint64_t size)
 
static zx_status_t VmoWrite (fml::RefPtr< Handle > vmo, uint64_t offset, const tonic::DartByteData &data)
 
static Dart_Handle VmoRead (fml::RefPtr< Handle > vmo, uint64_t offset, size_t size)
 
static Dart_Handle VmoMap (fml::RefPtr< Handle > vmo)
 
static uint64_t ClockGetMonotonic ()
 
static void RegisterNatives (tonic::DartLibraryNatives *natives)
 
static zx_status_t ConnectToService (std::string path, fml::RefPtr< Handle > channel)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex,
  kNumberOfNativeFields
}
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< System >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual size_t GetAllocationSize () const
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< System >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 29 of file system.h.

Member Function Documentation

◆ ChannelCreate()

Dart_Handle zircon::dart::System::ChannelCreate ( uint32_t  options)
static

Definition at line 192 of file system.cc.

References zircon::dart::Handle::Create(), and tonic::ToDart().

192  {
193  zx_handle_t out0 = 0, out1 = 0;
194  zx_status_t status = zx_channel_create(options, &out0, &out1);
195  if (status != ZX_OK) {
196  return ConstructDartObject(kHandlePairResult, ToDart(status));
197  } else {
198  return ConstructDartObject(kHandlePairResult, ToDart(status),
199  ToDart(Handle::Create(out0)),
200  ToDart(Handle::Create(out1)));
201  }
202 }
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
Dart_Handle ToDart(const T &object)

◆ ChannelFromFile()

Dart_Handle zircon::dart::System::ChannelFromFile ( std::string  path)
static

Definition at line 227 of file system.cc.

References zircon::dart::Handle::Create(), fml::UniqueObject< T, Traits >::get(), fml::UniqueObject< T, Traits >::is_valid(), and tonic::ToDart().

227  {
228  fml::UniqueFD fd = FdFromPath(path);
229  if (!fd.is_valid()) {
230  return ConstructDartObject(kHandleResult, ToDart(ZX_ERR_IO));
231  }
232 
233  // Get channel from fd.
234  zx::channel channel = CloneChannelFromFileDescriptor(fd.get());
235  if (!channel) {
236  return ConstructDartObject(kHandleResult, ToDart(ZX_ERR_IO));
237  }
238 
239  return ConstructDartObject(kHandleResult, ToDart(ZX_OK),
240  ToDart(Handle::Create(channel.release())));
241 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
const T & get() const
Definition: unique_object.h:87
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
bool is_valid() const
Definition: unique_object.h:89
Dart_Handle ToDart(const T &object)

◆ ChannelQueryAndRead()

Dart_Handle zircon::dart::System::ChannelQueryAndRead ( fml::RefPtr< Handle channel)
static

Definition at line 304 of file system.cc.

References FML_DCHECK, and tonic::ToDart().

304  {
305  if (!channel || !channel->is_valid()) {
306  return ConstructDartObject(kReadResult, ToDart(ZX_ERR_BAD_HANDLE));
307  }
308 
309  uint32_t actual_bytes = 0;
310  uint32_t actual_handles = 0;
311 
312  // Query the size of the next message.
313  zx_status_t status = zx_channel_read(channel->handle(), 0, nullptr, nullptr,
314  0, 0, &actual_bytes, &actual_handles);
315  if (status != ZX_ERR_BUFFER_TOO_SMALL) {
316  // An empty message or an error.
317  return ConstructDartObject(kReadResult, ToDart(status));
318  }
319 
320  // Allocate space for the bytes and handles.
321  ByteDataScope bytes(actual_bytes);
322  FML_DCHECK(bytes.is_valid());
323  std::vector<zx_handle_t> handles(actual_handles);
324 
325  // Make the call to actually get the message.
326  status = zx_channel_read(channel->handle(), 0, bytes.data(), handles.data(),
327  bytes.size(), handles.size(), &actual_bytes,
328  &actual_handles);
329  FML_DCHECK(status != ZX_OK || bytes.size() == actual_bytes);
330 
331  bytes.Release();
332 
333  if (status == ZX_OK) {
334  FML_DCHECK(handles.size() == actual_handles);
335 
336  // return a ReadResult object.
337  return ConstructDartObject(kReadResult, ToDart(status), bytes.dart_handle(),
338  ToDart(actual_bytes), MakeHandleList(handles));
339  } else {
340  return ConstructDartObject(kReadResult, ToDart(status));
341  }
342 }
#define FML_DCHECK(condition)
Definition: logging.h:86
Dart_Handle ToDart(const T &object)

◆ ChannelQueryAndReadEtc()

Dart_Handle zircon::dart::System::ChannelQueryAndReadEtc ( fml::RefPtr< Handle channel)
static

Definition at line 344 of file system.cc.

References FML_DCHECK, and tonic::ToDart().

344  {
345  if (!channel || !channel->is_valid()) {
346  return ConstructDartObject(kReadEtcResult, ToDart(ZX_ERR_BAD_HANDLE));
347  }
348 
349  uint32_t actual_bytes = 0;
350  uint32_t actual_handles = 0;
351 
352  // Query the size of the next message.
353  zx_status_t status = zx_channel_read(channel->handle(), 0, nullptr, nullptr,
354  0, 0, &actual_bytes, &actual_handles);
355  if (status != ZX_ERR_BUFFER_TOO_SMALL) {
356  // An empty message or an error.
357  return ConstructDartObject(kReadEtcResult, ToDart(status));
358  }
359 
360  // Allocate space for the bytes and handles.
361  ByteDataScope bytes(actual_bytes);
362  FML_DCHECK(bytes.is_valid());
363  std::vector<zx_handle_info_t> handles(actual_handles);
364 
365  // Make the call to actually get the message.
366  status = zx_channel_read_etc(channel->handle(), 0, bytes.data(),
367  handles.data(), bytes.size(), handles.size(),
368  &actual_bytes, &actual_handles);
369  FML_DCHECK(status != ZX_OK || bytes.size() == actual_bytes);
370 
371  bytes.Release();
372 
373  if (status == ZX_OK) {
374  FML_DCHECK(handles.size() == actual_handles);
375 
376  // return a ReadResult object.
377  return ConstructDartObject(kReadEtcResult, ToDart(status),
378  bytes.dart_handle(), ToDart(actual_bytes),
379  MakeHandleInfoList(handles));
380  } else {
381  return ConstructDartObject(kReadEtcResult, ToDart(status));
382  }
383 }
#define FML_DCHECK(condition)
Definition: logging.h:86
Dart_Handle ToDart(const T &object)

◆ ChannelWrite()

zx_status_t zircon::dart::System::ChannelWrite ( fml::RefPtr< Handle channel,
const tonic::DartByteData data,
std::vector< Handle *>  handles 
)
static

Definition at line 243 of file system.cc.

References tonic::DartByteData::data(), tonic::DartByteData::length_in_bytes(), and tonic::DartByteData::Release().

245  {
246  if (!channel || !channel->is_valid()) {
247  data.Release();
248  return ZX_ERR_BAD_HANDLE;
249  }
250 
251  std::vector<zx_handle_t> zx_handles;
252  for (Handle* handle : handles) {
253  zx_handles.push_back(handle->handle());
254  }
255 
256  zx_status_t status = zx_channel_write(channel->handle(), 0, data.data(),
257  data.length_in_bytes(),
258  zx_handles.data(), zx_handles.size());
259  // Handles are always consumed.
260  for (Handle* handle : handles) {
261  handle->ReleaseHandle();
262  }
263 
264  data.Release();
265  return status;
266 }
const void * data() const
size_t length_in_bytes() const
void Release() const

◆ ChannelWriteEtc()

zx_status_t zircon::dart::System::ChannelWriteEtc ( fml::RefPtr< Handle channel,
const tonic::DartByteData data,
std::vector< HandleDisposition *>  handle_dispositions 
)
static

Definition at line 268 of file system.cc.

References tonic::DartByteData::data(), FML_DCHECK, tonic::DartByteData::length_in_bytes(), and tonic::DartByteData::Release().

271  {
272  if (!channel || !channel->is_valid()) {
273  data.Release();
274  return ZX_ERR_BAD_HANDLE;
275  }
276 
277  std::vector<zx_handle_disposition_t> zx_handle_dispositions;
278  for (HandleDisposition* handle : handle_dispositions) {
279  FML_DCHECK(handle->result() == ZX_OK);
280  zx_handle_dispositions.push_back({.operation = handle->operation(),
281  .handle = handle->handle()->handle(),
282  .type = handle->type(),
283  .rights = handle->rights(),
284  .result = ZX_OK});
285  }
286 
287  zx_status_t status = zx_channel_write_etc(
288  channel->handle(), 0, data.data(), data.length_in_bytes(),
289  zx_handle_dispositions.data(), zx_handle_dispositions.size());
290 
291  for (size_t i = 0; i < handle_dispositions.size(); ++i) {
292  handle_dispositions[i]->set_result(zx_handle_dispositions[i].result);
293 
294  // Handles that are not copied (i.e. moved) are always consumed.
295  if (handle_dispositions[i]->operation() != ZX_HANDLE_OP_DUPLICATE) {
296  handle_dispositions[i]->handle()->ReleaseHandle();
297  }
298  }
299 
300  data.Release();
301  return status;
302 }
const void * data() const
#define FML_DCHECK(condition)
Definition: logging.h:86
GAsyncResult * result
size_t length_in_bytes() const
void Release() const

◆ ClockGetMonotonic()

uint64_t zircon::dart::System::ClockGetMonotonic ( )
static

Definition at line 564 of file system.cc.

564  {
565  return zx_clock_get_monotonic();
566 }

◆ ConnectToService()

zx_status_t zircon::dart::System::ConnectToService ( std::string  path,
fml::RefPtr< Handle channel 
)
static

Definition at line 204 of file system.cc.

References ZX_FS_RIGHT_READABLE, and ZX_FS_RIGHT_WRITABLE.

205  {
206  return fdio_ns_connect(GetNamespace(), path.c_str(),
208  channel->ReleaseHandle());
209 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
#define ZX_FS_RIGHT_WRITABLE
Definition: system.h:24
#define ZX_FS_RIGHT_READABLE
Definition: system.h:22

◆ EventpairCreate()

Dart_Handle zircon::dart::System::EventpairCreate ( uint32_t  options)
static

Definition at line 385 of file system.cc.

References zircon::dart::Handle::Create(), and tonic::ToDart().

385  {
386  zx_handle_t out0 = 0, out1 = 0;
387  zx_status_t status = zx_eventpair_create(0, &out0, &out1);
388  if (status != ZX_OK) {
389  return ConstructDartObject(kHandlePairResult, ToDart(status));
390  } else {
391  return ConstructDartObject(kHandlePairResult, ToDart(status),
392  ToDart(Handle::Create(out0)),
393  ToDart(Handle::Create(out1)));
394  }
395 }
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
Dart_Handle ToDart(const T &object)

◆ RegisterNatives()

void zircon::dart::System::RegisterNatives ( tonic::DartLibraryNatives natives)
static

Definition at line 599 of file system.cc.

References DART_REGISTER_NATIVE_STATIC_, and FOR_EACH_STATIC_BINDING.

599  {
601 }
#define FOR_EACH_STATIC_BINDING(V)
Definition: system.cc:570
void Register(std::initializer_list< Entry > entries)
#define DART_REGISTER_NATIVE_STATIC_(CLASS, METHOD)
Definition: system.cc:594

◆ SocketCreate()

Dart_Handle zircon::dart::System::SocketCreate ( uint32_t  options)
static

Definition at line 397 of file system.cc.

References zircon::dart::Handle::Create(), and tonic::ToDart().

397  {
398  zx_handle_t out0 = 0, out1 = 0;
399  zx_status_t status = zx_socket_create(options, &out0, &out1);
400  if (status != ZX_OK) {
401  return ConstructDartObject(kHandlePairResult, ToDart(status));
402  } else {
403  return ConstructDartObject(kHandlePairResult, ToDart(status),
404  ToDart(Handle::Create(out0)),
405  ToDart(Handle::Create(out1)));
406  }
407 }
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
Dart_Handle ToDart(const T &object)

◆ SocketRead()

Dart_Handle zircon::dart::System::SocketRead ( fml::RefPtr< Handle socket,
size_t  size 
)
static

Definition at line 424 of file system.cc.

References FML_DCHECK, fml::size(), and tonic::ToDart().

424  {
425  if (!socket || !socket->is_valid()) {
426  return ConstructDartObject(kReadResult, ToDart(ZX_ERR_BAD_HANDLE));
427  }
428 
429  ByteDataScope bytes(size);
430  size_t actual;
431  zx_status_t status =
432  zx_socket_read(socket->handle(), 0, bytes.data(), size, &actual);
433  bytes.Release();
434  if (status == ZX_OK) {
435  FML_DCHECK(actual <= size);
436  return ConstructDartObject(kReadResult, ToDart(status), bytes.dart_handle(),
437  ToDart(actual));
438  }
439 
440  return ConstructDartObject(kReadResult, ToDart(status));
441 }
#define FML_DCHECK(condition)
Definition: logging.h:86
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
Dart_Handle ToDart(const T &object)

◆ SocketWrite()

Dart_Handle zircon::dart::System::SocketWrite ( fml::RefPtr< Handle socket,
const tonic::DartByteData data,
int  options 
)
static

Definition at line 409 of file system.cc.

References tonic::DartByteData::data(), tonic::DartByteData::length_in_bytes(), tonic::DartByteData::Release(), and tonic::ToDart().

411  {
412  if (!socket || !socket->is_valid()) {
413  data.Release();
414  return ConstructDartObject(kWriteResult, ToDart(ZX_ERR_BAD_HANDLE));
415  }
416 
417  size_t actual;
418  zx_status_t status = zx_socket_write(socket->handle(), options, data.data(),
419  data.length_in_bytes(), &actual);
420  data.Release();
421  return ConstructDartObject(kWriteResult, ToDart(status), ToDart(actual));
422 }
const void * data() const
size_t length_in_bytes() const
Dart_Handle ToDart(const T &object)
void Release() const

◆ VmoCreate()

Dart_Handle zircon::dart::System::VmoCreate ( uint64_t  size,
uint32_t  options 
)
static

Definition at line 443 of file system.cc.

References zircon::dart::Handle::Create(), and tonic::ToDart().

443  {
444  zx_handle_t vmo = ZX_HANDLE_INVALID;
445  zx_status_t status = zx_vmo_create(size, options, &vmo);
446  if (status != ZX_OK) {
447  return ConstructDartObject(kHandleResult, ToDart(status));
448  } else {
449  return ConstructDartObject(kHandleResult, ToDart(status),
450  ToDart(Handle::Create(vmo)));
451  }
452 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
Dart_Handle ToDart(const T &object)

◆ VmoFromFile()

Dart_Handle zircon::dart::System::VmoFromFile ( std::string  path)
static

Definition at line 454 of file system.cc.

References zircon::dart::Handle::Create(), fml::UniqueObject< T, Traits >::get(), fml::UniqueObject< T, Traits >::is_valid(), and tonic::ToDart().

454  {
455  fml::UniqueFD fd = FdFromPath(path);
456  if (!fd.is_valid())
457  return ConstructDartObject(kFromFileResult, ToDart(ZX_ERR_IO));
458 
459  struct stat stat_struct;
460  if (fstat(fd.get(), &stat_struct) == -1)
461  return ConstructDartObject(kFromFileResult, ToDart(ZX_ERR_IO));
462  zx_handle_t vmo = ZX_HANDLE_INVALID;
463  zx_status_t status = fdio_get_vmo_clone(fd.get(), &vmo);
464  if (status != ZX_OK)
465  return ConstructDartObject(kFromFileResult, ToDart(status));
466 
467  return ConstructDartObject(kFromFileResult, ToDart(status),
468  ToDart(Handle::Create(vmo)),
469  ToDart(stat_struct.st_size));
470 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
const T & get() const
Definition: unique_object.h:87
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
bool is_valid() const
Definition: unique_object.h:89
Dart_Handle ToDart(const T &object)

◆ VmoGetSize()

Dart_Handle zircon::dart::System::VmoGetSize ( fml::RefPtr< Handle vmo)
static

Definition at line 472 of file system.cc.

References fml::size(), and tonic::ToDart().

472  {
473  if (!vmo || !vmo->is_valid()) {
474  return ConstructDartObject(kGetSizeResult, ToDart(ZX_ERR_BAD_HANDLE));
475  }
476 
477  uint64_t size;
478  zx_status_t status = zx_vmo_get_size(vmo->handle(), &size);
479 
480  return ConstructDartObject(kGetSizeResult, ToDart(status), ToDart(size));
481 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
Dart_Handle ToDart(const T &object)

◆ VmoMap()

Dart_Handle zircon::dart::System::VmoMap ( fml::RefPtr< Handle vmo)
static

Definition at line 536 of file system.cc.

References FML_DCHECK, tonic::LogIfError(), fml::size(), and tonic::ToDart().

536  {
537  if (!vmo || !vmo->is_valid())
538  return ConstructDartObject(kMapResult, ToDart(ZX_ERR_BAD_HANDLE));
539 
540  uint64_t size;
541  zx_status_t status = zx_vmo_get_size(vmo->handle(), &size);
542  if (status != ZX_OK)
543  return ConstructDartObject(kMapResult, ToDart(status));
544 
545  uintptr_t mapped_addr;
546  status = zx_vmar_map(zx_vmar_root_self(), ZX_VM_PERM_READ, 0, vmo->handle(),
547  0, size, &mapped_addr);
548  if (status != ZX_OK)
549  return ConstructDartObject(kMapResult, ToDart(status));
550 
551  void* data = reinterpret_cast<void*>(mapped_addr);
552  Dart_Handle object = Dart_NewExternalTypedData(Dart_TypedData_kUint8, data,
553  static_cast<intptr_t>(size));
554  FML_DCHECK(!tonic::LogIfError(object));
555 
556  SizedRegion* r = new SizedRegion(data, size);
557  Dart_NewFinalizableHandle(object, reinterpret_cast<void*>(r),
558  static_cast<intptr_t>(size) + sizeof(*r),
559  System::VmoMapFinalizer);
560 
561  return ConstructDartObject(kMapResult, ToDart(ZX_OK), object);
562 }
#define FML_DCHECK(condition)
Definition: logging.h:86
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
Dart_Handle ToDart(const T &object)
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ VmoRead()

Dart_Handle zircon::dart::System::VmoRead ( fml::RefPtr< Handle vmo,
uint64_t  offset,
size_t  size 
)
static

Definition at line 505 of file system.cc.

References fml::size(), and tonic::ToDart().

507  {
508  if (!vmo || !vmo->is_valid()) {
509  return ConstructDartObject(kReadResult, ToDart(ZX_ERR_BAD_HANDLE));
510  }
511 
512  // TODO: constrain size?
513  ByteDataScope bytes(size);
514  zx_status_t status = zx_vmo_read(vmo->handle(), bytes.data(), offset, size);
515  bytes.Release();
516  if (status == ZX_OK) {
517  return ConstructDartObject(kReadResult, ToDart(status), bytes.dart_handle(),
518  ToDart(size));
519  }
520  return ConstructDartObject(kReadResult, ToDart(status));
521 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
Dart_Handle ToDart(const T &object)

◆ VmoSetSize()

zx_status_t zircon::dart::System::VmoSetSize ( fml::RefPtr< Handle vmo,
uint64_t  size 
)
static

Definition at line 483 of file system.cc.

References fml::size().

483  {
484  if (!vmo || !vmo->is_valid()) {
485  return ZX_ERR_BAD_HANDLE;
486  }
487  return zx_vmo_set_size(vmo->handle(), size);
488 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ VmoWrite()

zx_status_t zircon::dart::System::VmoWrite ( fml::RefPtr< Handle vmo,
uint64_t  offset,
const tonic::DartByteData data 
)
static

Definition at line 490 of file system.cc.

References tonic::DartByteData::data(), tonic::DartByteData::length_in_bytes(), and tonic::DartByteData::Release().

492  {
493  if (!vmo || !vmo->is_valid()) {
494  data.Release();
495  return ZX_ERR_BAD_HANDLE;
496  }
497 
498  zx_status_t status =
499  zx_vmo_write(vmo->handle(), data.data(), offset, data.length_in_bytes());
500 
501  data.Release();
502  return status;
503 }
const void * data() const
size_t length_in_bytes() const
void Release() const

The documentation for this class was generated from the following files: