[engine] Migrate fuchsia.io Open functions to Open3 (flutter/engine#56818)
Migrate the use of fuchsia.io open functions to the new open3 replacements (which also requires transitioning from OpenFlags -> Flags). Likewise, we update all uses of the SDK VFS library to use the new set of flags. This work is being done as part of the ongoing io2 migration in https://fxbug.dev/378924259 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
committed by
GitHub
parent
7df25145cc
commit
9d726bb38e
@@ -183,10 +183,8 @@ zx_status_t FdFromPath(const char* path, fml::UniqueFD& fd) {
|
||||
path++;
|
||||
}
|
||||
int raw_fd;
|
||||
if (zx_status_t status = fdio_open_fd_at(
|
||||
dir_fd.get(), path,
|
||||
static_cast<uint32_t>(fuchsia::io::OpenFlags::RIGHT_READABLE),
|
||||
&raw_fd);
|
||||
if (zx_status_t status = fdio_open3_fd_at(
|
||||
dir_fd.get(), path, uint64_t{fuchsia::io::PERM_READABLE}, &raw_fd);
|
||||
status != ZX_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -210,46 +210,42 @@ bool DartComponentController::CreateAndBindNamespace() {
|
||||
dart_outgoing_dir_request_ = dart_outgoing_dir_ptr_.NewRequest();
|
||||
|
||||
fuchsia::io::DirectoryHandle dart_public_dir;
|
||||
// TODO(anmittal): when fixing enumeration using new c++ vfs, make sure that
|
||||
// flutter_public_dir is only accessed once we receive OnOpen Event.
|
||||
// That will prevent FL-175 for public directory
|
||||
fdio_service_connect_at(dart_outgoing_dir_ptr_.channel().get(), "svc",
|
||||
dart_public_dir.NewRequest().TakeChannel().release());
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
{
|
||||
auto request = dart_public_dir.NewRequest().TakeChannel();
|
||||
const zx_status_t status =
|
||||
fdio_open3_at(dart_outgoing_dir_ptr_.channel().get(), "svc",
|
||||
uint64_t{fuchsia::io::PERM_READABLE}, request.release());
|
||||
if (status != ZX_OK) {
|
||||
FML_LOG(ERROR) << "Failed to open /svc in outgoing directory: "
|
||||
<< zx_status_get_string(status);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto composed_service_dir = std::make_unique<vfs::ComposedServiceDir>();
|
||||
composed_service_dir->set_fallback(std::move(dart_public_dir));
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// Clone and check if client is servicing the directory.
|
||||
dart_outgoing_dir_ptr_->Clone(
|
||||
fuchsia::io::OpenFlags::DESCRIBE |
|
||||
fuchsia::io::OpenFlags::CLONE_SAME_RIGHTS,
|
||||
dart_outgoing_dir_ptr_to_check_on_open_.NewRequest());
|
||||
// Request an event from the directory to ensure it is servicing requests.
|
||||
dart_outgoing_dir_ptr_->Open3(
|
||||
".",
|
||||
fuchsia::io::Flags::PROTOCOL_NODE |
|
||||
fuchsia::io::Flags::FLAG_SEND_REPRESENTATION,
|
||||
{}, dart_outgoing_dir_ptr_to_check_on_open_.NewRequest().TakeChannel());
|
||||
|
||||
// Collect our standard set of directories.
|
||||
std::vector<std::string> other_dirs = {"debug", "ctrl"};
|
||||
|
||||
dart_outgoing_dir_ptr_to_check_on_open_.events().OnOpen =
|
||||
[this, other_dirs](zx_status_t status, auto unused) {
|
||||
dart_outgoing_dir_ptr_to_check_on_open_.events().OnRepresentation =
|
||||
[this, other_dirs](auto unused) {
|
||||
dart_outgoing_dir_ptr_to_check_on_open_.Unbind();
|
||||
if (status != ZX_OK) {
|
||||
FML_LOG(ERROR) << "could not bind out directory for dart component("
|
||||
<< label_ << "): " << zx_status_get_string(status);
|
||||
return;
|
||||
}
|
||||
|
||||
// add other directories as RemoteDirs.
|
||||
for (auto& dir_str : other_dirs) {
|
||||
fuchsia::io::DirectoryHandle dir;
|
||||
auto request = dir.NewRequest().TakeChannel();
|
||||
auto status = fdio_open_at(
|
||||
const zx_status_t status = fdio_open3_at(
|
||||
dart_outgoing_dir_ptr_.channel().get(), dir_str.c_str(),
|
||||
static_cast<uint32_t>(fuchsia::io::OpenFlags::DIRECTORY |
|
||||
fuchsia::io::OpenFlags::RIGHT_READABLE),
|
||||
uint64_t{fuchsia::io::Flags::PROTOCOL_DIRECTORY |
|
||||
fuchsia::io::PERM_READABLE},
|
||||
request.release());
|
||||
if (status == ZX_OK) {
|
||||
dart_outgoing_dir_->AddEntry(
|
||||
@@ -283,11 +279,11 @@ bool DartComponentController::CreateAndBindNamespace() {
|
||||
dart_outgoing_dir_->AddEntry("svc", std::move(composed_service_dir));
|
||||
|
||||
if (start_info_.has_outgoing_dir()) {
|
||||
fidl::ServerEnd<fuchsia_io::Directory> server_end{
|
||||
start_info_.mutable_outgoing_dir()->TakeChannel()};
|
||||
dart_outgoing_dir_->Serve(
|
||||
fuchsia::io::OpenFlags::RIGHT_READABLE |
|
||||
fuchsia::io::OpenFlags::RIGHT_WRITABLE |
|
||||
fuchsia::io::OpenFlags::DIRECTORY,
|
||||
start_info_.mutable_outgoing_dir()->TakeChannel());
|
||||
fuchsia_io::wire::kPermReadable | fuchsia_io::wire::kPermWritable,
|
||||
std::move(server_end));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -235,42 +235,45 @@ ComponentV2::ComponentV2(
|
||||
|
||||
// ComponentStartInfo::runtime_dir (optional).
|
||||
if (start_info.has_runtime_dir()) {
|
||||
runtime_dir_->Serve(fuchsia::io::OpenFlags::RIGHT_READABLE |
|
||||
fuchsia::io::OpenFlags::RIGHT_WRITABLE |
|
||||
fuchsia::io::OpenFlags::DIRECTORY,
|
||||
start_info.mutable_runtime_dir()->TakeChannel());
|
||||
fidl::ServerEnd<fuchsia_io::Directory> server_end{
|
||||
start_info.mutable_runtime_dir()->TakeChannel()};
|
||||
runtime_dir_->Serve(
|
||||
fuchsia_io::wire::kPermReadable | fuchsia_io::wire::kPermWritable,
|
||||
std::move(server_end));
|
||||
}
|
||||
|
||||
// ComponentStartInfo::outgoing_dir (optional).
|
||||
if (start_info.has_outgoing_dir()) {
|
||||
outgoing_dir_->Serve(fuchsia::io::OpenFlags::RIGHT_READABLE |
|
||||
fuchsia::io::OpenFlags::RIGHT_WRITABLE |
|
||||
fuchsia::io::OpenFlags::DIRECTORY,
|
||||
start_info.mutable_outgoing_dir()->TakeChannel());
|
||||
fidl::ServerEnd<fuchsia_io::Directory> server_end{
|
||||
start_info.mutable_outgoing_dir()->TakeChannel()};
|
||||
outgoing_dir_->Serve(
|
||||
fuchsia_io::wire::kPermReadable | fuchsia_io::wire::kPermWritable,
|
||||
std::move(server_end));
|
||||
}
|
||||
|
||||
directory_request_ = directory_ptr_.NewRequest();
|
||||
|
||||
fuchsia::io::DirectoryHandle flutter_public_dir;
|
||||
// TODO(anmittal): when fixing enumeration using new c++ vfs, make sure that
|
||||
// flutter_public_dir is only accessed once we receive OnOpen Event.
|
||||
// That will prevent FL-175 for public directory
|
||||
auto request = flutter_public_dir.NewRequest().TakeChannel();
|
||||
fdio_service_connect_at(directory_ptr_.channel().get(), "svc",
|
||||
request.release());
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
{
|
||||
auto request = flutter_public_dir.NewRequest().TakeChannel();
|
||||
const zx_status_t status =
|
||||
fdio_open3_at(directory_ptr_.channel().get(), "svc",
|
||||
uint64_t{fuchsia::io::PERM_READABLE}, request.release());
|
||||
if (status != ZX_OK) {
|
||||
FML_LOG(ERROR) << "Failed to open /svc in outgoing directory: "
|
||||
<< zx_status_get_string(status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto composed_service_dir = std::make_unique<vfs::ComposedServiceDir>();
|
||||
composed_service_dir->set_fallback(std::move(flutter_public_dir));
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// Clone and check if client is servicing the directory.
|
||||
directory_ptr_->Clone(fuchsia::io::OpenFlags::DESCRIBE |
|
||||
fuchsia::io::OpenFlags::CLONE_SAME_RIGHTS,
|
||||
cloned_directory_ptr_.NewRequest());
|
||||
// Request an event from the directory to ensure it is servicing requests.
|
||||
directory_ptr_->Open3(".",
|
||||
fuchsia::io::Flags::PROTOCOL_NODE |
|
||||
fuchsia::io::Flags::FLAG_SEND_REPRESENTATION,
|
||||
{}, cloned_directory_ptr_.NewRequest().TakeChannel());
|
||||
|
||||
// Collect our standard set of directories along with directories that are
|
||||
// included in the cml file to expose.
|
||||
@@ -279,24 +282,18 @@ ComponentV2::ComponentV2(
|
||||
other_dirs.push_back(dir);
|
||||
}
|
||||
|
||||
cloned_directory_ptr_.events().OnOpen = [this, other_dirs](zx_status_t status,
|
||||
auto unused) {
|
||||
cloned_directory_ptr_.events().OnRepresentation = [this,
|
||||
other_dirs](auto unused) {
|
||||
cloned_directory_ptr_.Unbind();
|
||||
if (status != ZX_OK) {
|
||||
FML_LOG(ERROR) << "could not bind out directory for flutter component("
|
||||
<< debug_label_ << "): " << zx_status_get_string(status);
|
||||
return;
|
||||
}
|
||||
|
||||
// add other directories as RemoteDirs.
|
||||
for (auto& dir_str : other_dirs) {
|
||||
fuchsia::io::DirectoryHandle dir;
|
||||
auto request = dir.NewRequest().TakeChannel();
|
||||
auto status = fdio_open_at(
|
||||
directory_ptr_.channel().get(), dir_str.c_str(),
|
||||
static_cast<uint32_t>(fuchsia::io::OpenFlags::DIRECTORY |
|
||||
fuchsia::io::OpenFlags::RIGHT_READABLE),
|
||||
request.release());
|
||||
const zx_status_t status =
|
||||
fdio_open3_at(directory_ptr_.channel().get(), dir_str.c_str(),
|
||||
uint64_t{fuchsia::io::Flags::PROTOCOL_DIRECTORY |
|
||||
fuchsia::io::PERM_READABLE},
|
||||
request.release());
|
||||
if (status == ZX_OK) {
|
||||
outgoing_dir_->AddEntry(
|
||||
dir_str.c_str(),
|
||||
|
||||
@@ -74,16 +74,15 @@ std::unique_ptr<fml::Mapping> LoadFile(int namespace_fd,
|
||||
|
||||
std::unique_ptr<fml::FileMapping> MakeFileMapping(const char* path,
|
||||
bool executable) {
|
||||
auto flags = fuchsia::io::OpenFlags::RIGHT_READABLE;
|
||||
fuchsia::io::Flags flags = fuchsia::io::PERM_READABLE;
|
||||
if (executable) {
|
||||
flags |= fuchsia::io::OpenFlags::RIGHT_EXECUTABLE;
|
||||
flags |= fuchsia::io::PERM_EXECUTABLE;
|
||||
}
|
||||
|
||||
// The returned file descriptor is compatible with standard posix operations
|
||||
// such as close, mmap, etc. We only need to treat open/open_at specially.
|
||||
int fd;
|
||||
const zx_status_t status =
|
||||
fdio_open_fd(path, static_cast<uint32_t>(flags), &fd);
|
||||
const zx_status_t status = fdio_open3_fd(path, uint64_t{flags}, &fd);
|
||||
if (status != ZX_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -103,26 +103,16 @@ MappedResource::~MappedResource() {
|
||||
|
||||
static int OpenFdExec(const std::string& path, int dirfd) {
|
||||
int fd = -1;
|
||||
zx_status_t result;
|
||||
if (dirfd == AT_FDCWD) {
|
||||
// fdio_open_fd_at does not support AT_FDCWD, by design. Use fdio_open_fd
|
||||
// and expect an absolute path for that usage pattern.
|
||||
FML_CHECK(path[0] == '/');
|
||||
result = fdio_open_fd(
|
||||
path.c_str(),
|
||||
static_cast<uint32_t>(fuchsia::io::OpenFlags::RIGHT_READABLE |
|
||||
fuchsia::io::OpenFlags::RIGHT_EXECUTABLE),
|
||||
&fd);
|
||||
} else {
|
||||
FML_CHECK(path[0] != '/');
|
||||
result = fdio_open_fd_at(
|
||||
dirfd, path.c_str(),
|
||||
static_cast<uint32_t>(fuchsia::io::OpenFlags::RIGHT_READABLE |
|
||||
fuchsia::io::OpenFlags::RIGHT_EXECUTABLE),
|
||||
&fd);
|
||||
// fdio_open3_fd_at only allows relative paths
|
||||
const char* path_ptr = path.c_str();
|
||||
if (path_ptr && path_ptr[0] == '/') {
|
||||
++path_ptr;
|
||||
}
|
||||
zx_status_t result = fdio_open3_fd_at(
|
||||
dirfd, path_ptr,
|
||||
uint64_t{fuchsia::io::PERM_READABLE | fuchsia::io::PERM_EXECUTABLE}, &fd);
|
||||
if (result != ZX_OK) {
|
||||
FML_LOG(ERROR) << "fdio_open_fd_at(" << path << ") "
|
||||
FML_LOG(ERROR) << "fdio_open3_fd_at(" << path << ") "
|
||||
<< "failed: " << zx_status_get_string(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -57,43 +57,28 @@ namespace dart_utils {
|
||||
bool VmoFromFilename(const std::string& filename,
|
||||
bool executable,
|
||||
fuchsia::mem::Buffer* buffer) {
|
||||
// Note: the implementation here cannot be shared with VmoFromFilenameAt
|
||||
// because fdio_open_fd_at does not aim to provide POSIX compatibility, and
|
||||
// thus does not handle AT_FDCWD as dirfd.
|
||||
auto flags = fuchsia::io::OpenFlags::RIGHT_READABLE;
|
||||
if (executable) {
|
||||
flags |= fuchsia::io::OpenFlags::RIGHT_EXECUTABLE;
|
||||
}
|
||||
|
||||
int fd;
|
||||
const zx_status_t status =
|
||||
fdio_open_fd(filename.c_str(), static_cast<uint32_t>(flags), &fd);
|
||||
if (status != ZX_OK) {
|
||||
FML_LOG(ERROR) << "fdio_open_fd(\"" << filename << "\", " << std::hex
|
||||
<< static_cast<uint32_t>(flags)
|
||||
<< ") failed: " << zx_status_get_string(status);
|
||||
return false;
|
||||
}
|
||||
bool result = VmoFromFd(fd, executable, buffer);
|
||||
close(fd);
|
||||
return result;
|
||||
return VmoFromFilenameAt(AT_FDCWD, filename, executable, buffer);
|
||||
}
|
||||
|
||||
bool VmoFromFilenameAt(int dirfd,
|
||||
const std::string& filename,
|
||||
bool executable,
|
||||
fuchsia::mem::Buffer* buffer) {
|
||||
auto flags = fuchsia::io::OpenFlags::RIGHT_READABLE;
|
||||
fuchsia::io::Flags flags = fuchsia::io::PERM_READABLE;
|
||||
if (executable) {
|
||||
flags |= fuchsia::io::OpenFlags::RIGHT_EXECUTABLE;
|
||||
flags |= fuchsia::io::PERM_EXECUTABLE;
|
||||
}
|
||||
// fdio_open3_fd_at only allows relative paths
|
||||
const char* path = filename.c_str();
|
||||
if (path && path[0] == '/') {
|
||||
++path;
|
||||
}
|
||||
|
||||
int fd;
|
||||
const zx_status_t status = fdio_open_fd_at(dirfd, filename.c_str(),
|
||||
static_cast<uint32_t>(flags), &fd);
|
||||
const zx_status_t status =
|
||||
fdio_open3_fd_at(dirfd, path, uint64_t{flags}, &fd);
|
||||
if (status != ZX_OK) {
|
||||
FML_LOG(ERROR) << "fdio_open_fd_at(" << dirfd << ", \"" << filename
|
||||
<< "\", " << std::hex << static_cast<uint32_t>(flags)
|
||||
FML_LOG(ERROR) << "fdio_open3_fd_at(" << dirfd << ", \"" << filename
|
||||
<< "\", " << std::hex << uint64_t{flags}
|
||||
<< ") failed: " << zx_status_get_string(status);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
|
||||
namespace dart_utils {
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
class VMServiceObject : public vfs::LazyDir {
|
||||
public:
|
||||
static constexpr const char* kDirName = "DartVM";
|
||||
@@ -24,8 +21,6 @@ class VMServiceObject : public vfs::LazyDir {
|
||||
std::string name) const override;
|
||||
};
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
} // namespace dart_utils
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_VMSERVICE_OBJECT_H_
|
||||
|
||||
Reference in New Issue
Block a user