Flutter Engine
 
Loading...
Searching...
No Matches
vmo.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "vmo.h"
6
7#include <fcntl.h>
8#include <sys/stat.h>
9
10#include <fuchsia/io/cpp/fidl.h>
11#include <fuchsia/mem/cpp/fidl.h>
12#include <lib/fdio/directory.h>
13#include <lib/fdio/io.h>
14#include <zircon/status.h>
15
16#include <ios>
17
18#include "flutter/fml/logging.h"
19
20namespace {
21
22bool VmoFromFd(int fd, bool executable, fuchsia::mem::Buffer* buffer) {
23 if (!buffer) {
24 FML_LOG(FATAL) << "Invalid buffer pointer";
25 }
26
27 struct stat stat_struct;
28 if (fstat(fd, &stat_struct) == -1) {
29 FML_LOG(ERROR) << "fstat failed: " << strerror(errno);
30 return false;
31 }
32
33 zx_handle_t result = ZX_HANDLE_INVALID;
34 zx_status_t status;
35 if (executable) {
36 status = fdio_get_vmo_exec(fd, &result);
37 } else {
38 status = fdio_get_vmo_copy(fd, &result);
39 }
40
41 if (status != ZX_OK) {
42 FML_LOG(ERROR) << (executable ? "fdio_get_vmo_exec" : "fdio_get_vmo_copy")
43 << " failed: " << zx_status_get_string(status);
44 return false;
45 }
46
47 buffer->vmo = zx::vmo(result);
48 buffer->size = stat_struct.st_size;
49
50 return true;
51}
52
53} // namespace
54
55namespace dart_utils {
56
57bool VmoFromFilename(const std::string& filename,
58 bool executable,
59 fuchsia::mem::Buffer* buffer) {
60 return VmoFromFilenameAt(AT_FDCWD, filename, executable, buffer);
61}
62
63bool VmoFromFilenameAt(int dirfd,
64 const std::string& filename,
65 bool executable,
66 fuchsia::mem::Buffer* buffer) {
67 fuchsia::io::Flags flags = fuchsia::io::PERM_READABLE;
68 if (executable) {
69 flags |= fuchsia::io::PERM_EXECUTABLE;
70 }
71 // fdio_open3_fd_at only allows relative paths
72 const char* path = filename.c_str();
73 if (path && path[0] == '/') {
74 ++path;
75 }
76 int fd;
77 const zx_status_t status =
78 fdio_open3_fd_at(dirfd, path, uint64_t{flags}, &fd);
79 if (status != ZX_OK) {
80 FML_LOG(ERROR) << "fdio_open3_fd_at(" << dirfd << ", \"" << filename
81 << "\", " << std::hex << uint64_t{flags}
82 << ") failed: " << zx_status_get_string(status);
83 return false;
84 }
85 bool result = VmoFromFd(fd, executable, buffer);
86 close(fd);
87 return result;
88}
89
90zx_status_t IsSizeValid(const fuchsia::mem::Buffer& buffer, bool* is_valid) {
91 size_t vmo_size;
92 zx_status_t status = buffer.vmo.get_size(&vmo_size);
93 if (status == ZX_OK) {
94 *is_valid = vmo_size >= buffer.size;
95 } else {
96 *is_valid = false;
97 }
98 return status;
99}
100
101} // namespace dart_utils
#define FML_LOG(severity)
Definition logging.h:101
bool VmoFromFilenameAt(int dirfd, const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition vmo.cc:63
bool VmoFromFilename(const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition vmo.cc:57
zx_status_t IsSizeValid(const fuchsia::mem::Buffer &buffer, bool *is_valid)
Definition vmo.cc:90
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98