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 Dart_Handle ChannelQueryAndRead (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 ClockGet (uint32_t clock_id)
 
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,
  kWrapperInfoIndex,
  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 28 of file system.h.

Member Function Documentation

◆ ChannelCreate()

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

Definition at line 167 of file system.cc.

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

167  {
168  zx_handle_t out0 = 0, out1 = 0;
169  zx_status_t status = zx_channel_create(options, &out0, &out1);
170  if (status != ZX_OK) {
171  return ConstructDartObject(kHandlePairResult, ToDart(status));
172  } else {
173  return ConstructDartObject(kHandlePairResult, ToDart(status),
174  ToDart(Handle::Create(out0)),
175  ToDart(Handle::Create(out1)));
176  }
177 }
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:50
Dart_Handle ToDart(const T &object)

◆ ChannelFromFile()

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

Definition at line 202 of file system.cc.

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

202  {
203  fml::UniqueFD fd = FdFromPath(path);
204  if (!fd.is_valid()) {
205  return ConstructDartObject(kHandleResult, ToDart(ZX_ERR_IO));
206  }
207 
208  // Get channel from fd.
209  zx::channel channel = CloneChannelFromFileDescriptor(fd.get());
210  if (!channel) {
211  return ConstructDartObject(kHandleResult, ToDart(ZX_ERR_IO));
212  }
213 
214  return ConstructDartObject(kHandleResult, ToDart(ZX_OK),
215  ToDart(Handle::Create(channel.release())));
216 }
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:50
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 243 of file system.cc.

References FML_DCHECK, and tonic::ToDart().

243  {
244  if (!channel || !channel->is_valid()) {
245  return ConstructDartObject(kReadResult, ToDart(ZX_ERR_BAD_HANDLE));
246  }
247 
248  uint32_t actual_bytes = 0;
249  uint32_t actual_handles = 0;
250 
251  // Query the size of the next message.
252  zx_status_t status = zx_channel_read(channel->handle(), 0, nullptr, nullptr,
253  0, 0, &actual_bytes, &actual_handles);
254  if (status != ZX_ERR_BUFFER_TOO_SMALL) {
255  // An empty message or an error.
256  return ConstructDartObject(kReadResult, ToDart(status));
257  }
258 
259  // Allocate space for the bytes and handles.
260  ByteDataScope bytes(actual_bytes);
261  FML_DCHECK(bytes.is_valid());
262  std::vector<zx_handle_t> handles(actual_handles);
263 
264  // Make the call to actually get the message.
265  status = zx_channel_read(channel->handle(), 0, bytes.data(), handles.data(),
266  bytes.size(), handles.size(), &actual_bytes,
267  &actual_handles);
268  FML_DCHECK(status != ZX_OK || bytes.size() == actual_bytes);
269 
270  bytes.Release();
271 
272  if (status == ZX_OK) {
273  FML_DCHECK(handles.size() == actual_handles);
274 
275  // return a ReadResult object.
276  return ConstructDartObject(kReadResult, ToDart(status), bytes.dart_handle(),
277  ToDart(actual_bytes), MakeHandleList(handles));
278  } else {
279  return ConstructDartObject(kReadResult, ToDart(status));
280  }
281 }
#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 218 of file system.cc.

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

220  {
221  if (!channel || !channel->is_valid()) {
222  data.Release();
223  return ZX_ERR_BAD_HANDLE;
224  }
225 
226  std::vector<zx_handle_t> zx_handles;
227  for (Handle* handle : handles) {
228  zx_handles.push_back(handle->handle());
229  }
230 
231  zx_status_t status = zx_channel_write(channel->handle(), 0, data.data(),
232  data.length_in_bytes(),
233  zx_handles.data(), zx_handles.size());
234  // Handles are always consumed.
235  for (Handle* handle : handles) {
236  handle->ReleaseHandle();
237  }
238 
239  data.Release();
240  return status;
241 }
const void * data() const
size_t length_in_bytes() const
void Release() const

◆ ClockGet()

uint64_t zircon::dart::System::ClockGet ( uint32_t  clock_id)
static

Definition at line 462 of file system.cc.

462  {
463  zx_time_t result = 0;
464  zx_clock_get(clock_id, &result);
465  return result;
466 }

◆ ConnectToService()

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

Definition at line 179 of file system.cc.

References ZX_FS_RIGHT_READABLE, and ZX_FS_RIGHT_WRITABLE.

180  {
181  return fdio_ns_connect(GetNamespace(), path.c_str(),
183  channel->ReleaseHandle());
184 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
#define ZX_FS_RIGHT_WRITABLE
Definition: system.h:23
#define ZX_FS_RIGHT_READABLE
Definition: system.h:21

◆ EventpairCreate()

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

Definition at line 283 of file system.cc.

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

283  {
284  zx_handle_t out0 = 0, out1 = 0;
285  zx_status_t status = zx_eventpair_create(0, &out0, &out1);
286  if (status != ZX_OK) {
287  return ConstructDartObject(kHandlePairResult, ToDart(status));
288  } else {
289  return ConstructDartObject(kHandlePairResult, ToDart(status),
290  ToDart(Handle::Create(out0)),
291  ToDart(Handle::Create(out1)));
292  }
293 }
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:50
Dart_Handle ToDart(const T &object)

◆ RegisterNatives()

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

Definition at line 497 of file system.cc.

References DART_REGISTER_NATIVE_STATIC_, and FOR_EACH_STATIC_BINDING.

497  {
499 }
#define FOR_EACH_STATIC_BINDING(V)
Definition: system.cc:470
void Register(std::initializer_list< Entry > entries)
#define DART_REGISTER_NATIVE_STATIC_(CLASS, METHOD)
Definition: system.cc:492

◆ SocketCreate()

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

Definition at line 295 of file system.cc.

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

295  {
296  zx_handle_t out0 = 0, out1 = 0;
297  zx_status_t status = zx_socket_create(options, &out0, &out1);
298  if (status != ZX_OK) {
299  return ConstructDartObject(kHandlePairResult, ToDart(status));
300  } else {
301  return ConstructDartObject(kHandlePairResult, ToDart(status),
302  ToDart(Handle::Create(out0)),
303  ToDart(Handle::Create(out1)));
304  }
305 }
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:50
Dart_Handle ToDart(const T &object)

◆ SocketRead()

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

Definition at line 322 of file system.cc.

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

322  {
323  if (!socket || !socket->is_valid()) {
324  return ConstructDartObject(kReadResult, ToDart(ZX_ERR_BAD_HANDLE));
325  }
326 
327  ByteDataScope bytes(size);
328  size_t actual;
329  zx_status_t status =
330  zx_socket_read(socket->handle(), 0, bytes.data(), size, &actual);
331  bytes.Release();
332  if (status == ZX_OK) {
333  FML_DCHECK(actual <= size);
334  return ConstructDartObject(kReadResult, ToDart(status), bytes.dart_handle(),
335  ToDart(actual));
336  }
337 
338  return ConstructDartObject(kReadResult, ToDart(status));
339 }
#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 307 of file system.cc.

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

309  {
310  if (!socket || !socket->is_valid()) {
311  data.Release();
312  return ConstructDartObject(kWriteResult, ToDart(ZX_ERR_BAD_HANDLE));
313  }
314 
315  size_t actual;
316  zx_status_t status = zx_socket_write(socket->handle(), options, data.data(),
317  data.length_in_bytes(), &actual);
318  data.Release();
319  return ConstructDartObject(kWriteResult, ToDart(status), ToDart(actual));
320 }
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 341 of file system.cc.

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

341  {
342  zx_handle_t vmo = ZX_HANDLE_INVALID;
343  zx_status_t status = zx_vmo_create(size, options, &vmo);
344  if (status != ZX_OK) {
345  return ConstructDartObject(kHandleResult, ToDart(status));
346  } else {
347  return ConstructDartObject(kHandleResult, ToDart(status),
348  ToDart(Handle::Create(vmo)));
349  }
350 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:50
Dart_Handle ToDart(const T &object)

◆ VmoFromFile()

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

Definition at line 352 of file system.cc.

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

352  {
353  fml::UniqueFD fd = FdFromPath(path);
354  if (!fd.is_valid())
355  return ConstructDartObject(kFromFileResult, ToDart(ZX_ERR_IO));
356 
357  struct stat stat_struct;
358  if (fstat(fd.get(), &stat_struct) == -1)
359  return ConstructDartObject(kFromFileResult, ToDart(ZX_ERR_IO));
360  zx_handle_t vmo = ZX_HANDLE_INVALID;
361  zx_status_t status = fdio_get_vmo_clone(fd.get(), &vmo);
362  if (status != ZX_OK)
363  return ConstructDartObject(kFromFileResult, ToDart(status));
364 
365  return ConstructDartObject(kFromFileResult, ToDart(status),
366  ToDart(Handle::Create(vmo)),
367  ToDart(stat_struct.st_size));
368 }
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:50
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 370 of file system.cc.

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

370  {
371  if (!vmo || !vmo->is_valid()) {
372  return ConstructDartObject(kGetSizeResult, ToDart(ZX_ERR_BAD_HANDLE));
373  }
374 
375  uint64_t size;
376  zx_status_t status = zx_vmo_get_size(vmo->handle(), &size);
377 
378  return ConstructDartObject(kGetSizeResult, ToDart(status), ToDart(size));
379 }
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 434 of file system.cc.

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

434  {
435  if (!vmo || !vmo->is_valid())
436  return ConstructDartObject(kMapResult, ToDart(ZX_ERR_BAD_HANDLE));
437 
438  uint64_t size;
439  zx_status_t status = zx_vmo_get_size(vmo->handle(), &size);
440  if (status != ZX_OK)
441  return ConstructDartObject(kMapResult, ToDart(status));
442 
443  uintptr_t mapped_addr;
444  status = zx_vmar_map(zx_vmar_root_self(), ZX_VM_PERM_READ, 0, vmo->handle(),
445  0, size, &mapped_addr);
446  if (status != ZX_OK)
447  return ConstructDartObject(kMapResult, ToDart(status));
448 
449  void* data = reinterpret_cast<void*>(mapped_addr);
450  Dart_Handle object = Dart_NewExternalTypedData(Dart_TypedData_kUint8, data,
451  static_cast<intptr_t>(size));
452  FML_DCHECK(!tonic::LogIfError(object));
453 
454  SizedRegion* r = new SizedRegion(data, size);
455  Dart_NewFinalizableHandle(object, reinterpret_cast<void*>(r),
456  static_cast<intptr_t>(size) + sizeof(*r),
457  System::VmoMapFinalizer);
458 
459  return ConstructDartObject(kMapResult, ToDart(ZX_OK), object);
460 }
#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 403 of file system.cc.

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

405  {
406  if (!vmo || !vmo->is_valid()) {
407  return ConstructDartObject(kReadResult, ToDart(ZX_ERR_BAD_HANDLE));
408  }
409 
410  // TODO: constrain size?
411  ByteDataScope bytes(size);
412  zx_status_t status = zx_vmo_read(vmo->handle(), bytes.data(), offset, size);
413  bytes.Release();
414  if (status == ZX_OK) {
415  return ConstructDartObject(kReadResult, ToDart(status), bytes.dart_handle(),
416  ToDart(size));
417  }
418  return ConstructDartObject(kReadResult, ToDart(status));
419 }
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 381 of file system.cc.

References fml::size().

381  {
382  if (!vmo || !vmo->is_valid()) {
383  return ZX_ERR_BAD_HANDLE;
384  }
385  return zx_vmo_set_size(vmo->handle(), size);
386 }
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 388 of file system.cc.

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

390  {
391  if (!vmo || !vmo->is_valid()) {
392  data.Release();
393  return ZX_ERR_BAD_HANDLE;
394  }
395 
396  zx_status_t status =
397  zx_vmo_write(vmo->handle(), data.data(), offset, data.length_in_bytes());
398 
399  data.Release();
400  return status;
401 }
const void * data() const
size_t length_in_bytes() const
void Release() const

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